@@ -82,7 +82,8 @@ class EnumClass extends BindingType {
8282 /// See [scanForDuplicates] and [writeUniqueMembers] .
8383 final Set <EnumConstant > uniqueMembers = {};
8484
85- /// Returns a string to declare the enum member and any documentation it may have had.
85+ /// Returns a string to declare the enum member and any documentation it may
86+ /// have had.
8687 String formatValue (EnumConstant ec) {
8788 final buffer = StringBuffer ();
8889 final enumValueName = namer.makeUnique (ec.name);
@@ -100,8 +101,9 @@ class EnumClass extends BindingType {
100101 ///
101102 /// Since all enum values in Dart are distinct, these duplicates do not
102103 /// get their own values in Dart. Rather, they are aliases of the original
103- /// value. For example, if a native enum has 2 constants with a value of 10, only
104- /// one enum value will be generated in Dart, and the other will be set equal to it.
104+ /// value. For example, if a native enum has 2 constants with a value of 10,
105+ /// only one enum value will be generated in Dart, and the other will be set
106+ /// equal to it.
105107 void scanForDuplicates () {
106108 uniqueMembers.clear ();
107109 uniqueToDuplicates.clear ();
@@ -126,13 +128,14 @@ class EnumClass extends BindingType {
126128 ///
127129 /// Eg, C: `apple = 1` , Dart: `apple(1)`
128130 void writeUniqueMembers (StringBuffer s) {
129- s.writeAll (uniqueMembers.map (formatValue), " ,\n " );
131+ s.writeAll (uniqueMembers.map (formatValue), ' ,\n ' );
130132 if (uniqueMembers.isNotEmpty) s.write (';\n ' );
131133 }
132134
133135 /// Writes alias declarations for all members with duplicate values.
134136 ///
135- /// Eg, C: `banana = 10, yellow_fruit = 10` . Dart: `static const yellow_fruit = banana` .
137+ /// Eg, C: `banana = 10, yellow_fruit = 10` .
138+ /// Dart: `static const yellow_fruit = banana` .
136139 void writeDuplicateMembers (StringBuffer s) {
137140 if (duplicateToOriginal.isEmpty) return ;
138141 for (final entry in duplicateToOriginal.entries) {
@@ -143,48 +146,49 @@ class EnumClass extends BindingType {
143146 final originalName = enumNames[original]! ;
144147 enumNames[duplicate] = duplicateName;
145148 if (duplicate.dartDoc != null ) {
146- s.write (" $depth /// " );
147- s.writeAll (duplicate.dartDoc! .split (" \n " ), " \n $depth /// " );
148- s.write (" \n " );
149+ s.write (' $depth /// ' );
150+ s.writeAll (duplicate.dartDoc! .split (' \n ' ), ' \n $depth /// ' );
151+ s.write (' \n ' );
149152 }
150- s.write (" ${depth }static const $duplicateName = $originalName ;\n " );
153+ s.write (' ${depth }static const $duplicateName = $originalName ;\n ' );
151154 }
152155 }
153156
154157 /// Writes the constructor for the enum.
155158 ///
156159 /// Always accepts an integer value to match the native value.
157160 void writeConstructor (StringBuffer s) {
158- s.write (" ${depth }final int value;\n " );
159- s.write (" ${depth }const $name (this.value);\n " );
161+ s.write (' ${depth }final int value;\n ' );
162+ s.write (' ${depth }const $name (this.value);\n ' );
160163 }
161164
162165 /// Overrides [Enum.toString] so all aliases are included, if any.
163166 ///
164- /// If a native enum has two members with the same value, they are functionally
165- /// identical, and should be represented as such. This method overrides [toString]
166- /// to include all duplicate members in the same message.
167+ /// If a native enum has two members with the same value, they are
168+ /// functionally identical, and should be represented as such. This method
169+ /// overrides [toString] to include all duplicate members in the same message.
167170 void writeToStringOverride (StringBuffer s) {
168171 if (duplicateToOriginal.isEmpty) return ;
169- s.write (" $depth @override\n " );
170- s.write (" ${depth }String toString() {\n " );
172+ s.write (' $depth @override\n ' );
173+ s.write (' ${depth }String toString() {\n ' );
171174 for (final entry in uniqueToDuplicates.entries) {
172- // [!] All enum values were given a name when their declarations were generated
175+ // [!] All enum values were given a name when their declarations were
176+ // generated.
173177 final unique = entry.key;
174178 final originalName = enumNames[unique]! ;
175179 final duplicates = entry.value;
176180 if (duplicates.isEmpty) continue ;
177181 final allDuplicates = [
178182 for (final duplicate in [unique] + duplicates)
179- " $name .${enumNames [duplicate ]!}" ,
180- ].join (", " );
183+ ' $name .${enumNames [duplicate ]!}' ,
184+ ].join (', ' );
181185 s.write (
182186 '$depth $depth '
183187 'if (this == $originalName ) return "$allDuplicates ";\n ' ,
184188 );
185189 }
186- s.write (" ${depth * 2 }return super.toString();\n " );
187- s.write (" $depth }" );
190+ s.write (' ${depth * 2 }return super.toString();\n ' );
191+ s.write (' $depth }' );
188192 }
189193
190194 /// Writes the DartDoc string for this enum.
@@ -194,23 +198,24 @@ class EnumClass extends BindingType {
194198 }
195199 }
196200
197- /// Writes a sealed class when no members exist, because Dart enums cannot be empty.
201+ /// Writes a sealed class when no members exist, because Dart enums cannot be
202+ /// empty.
198203 void writeEmptyEnum (StringBuffer s) {
199- s.write (" sealed class $name { }\n " );
204+ s.write (' sealed class $name { }\n ' );
200205 }
201206
202207 /// Writes a static function that maps integers to enum values.
203208 void writeFromValue (StringBuffer s) {
204- s.write (" ${depth }static $name fromValue(int value) => switch (value) {\n " );
209+ s.write (' ${depth }static $name fromValue(int value) => switch (value) {\n ' );
205210 for (final member in uniqueMembers) {
206211 final memberName = enumNames[member]! ;
207- s.write (" $depth $depth ${member .value } => $memberName ,\n " );
212+ s.write (' $depth $depth ${member .value } => $memberName ,\n ' );
208213 }
209214 s.write (
210215 '$depth ${depth }_ => '
211216 'throw ArgumentError("Unknown value for $name : \$ value"),\n ' ,
212217 );
213- s.write (" $depth };\n " );
218+ s.write (' $depth };\n ' );
214219 }
215220
216221 bool get _isBuiltIn =>
@@ -220,7 +225,7 @@ class EnumClass extends BindingType {
220225 BindingString toBindingString (Writer w) {
221226 final s = StringBuffer ();
222227 if (_isBuiltIn) {
223- return BindingString (type: BindingStringType .enum_, string: '' );
228+ return const BindingString (type: BindingStringType .enum_, string: '' );
224229 }
225230 scanForDuplicates ();
226231
@@ -230,13 +235,13 @@ class EnumClass extends BindingType {
230235 } else {
231236 s.write ('enum $name {\n ' );
232237 writeUniqueMembers (s);
233- s.write (" \n " );
238+ s.write (' \n ' );
234239 writeDuplicateMembers (s);
235- s.write (" \n " );
240+ s.write (' \n ' );
236241 writeConstructor (s);
237- s.write (" \n " );
242+ s.write (' \n ' );
238243 writeFromValue (s);
239- s.write (" \n " );
244+ s.write (' \n ' );
240245 writeToStringOverride (s);
241246 s.write ('}\n\n ' );
242247 }
@@ -284,7 +289,7 @@ class EnumClass extends BindingType {
284289 String value, {
285290 required bool objCRetain,
286291 }) =>
287- " $value .value" ;
292+ ' $value .value' ;
288293
289294 @override
290295 String convertFfiDartTypeToDartType (
@@ -293,7 +298,7 @@ class EnumClass extends BindingType {
293298 required bool objCRetain,
294299 String ? objCEnclosingClass,
295300 }) =>
296- " ${getDartType (w )}.fromValue($value )" ;
301+ ' ${getDartType (w )}.fromValue($value )' ;
297302}
298303
299304/// Represents a single value in an enum.
0 commit comments