@@ -82,7 +82,8 @@ class EnumClass extends BindingType {
82
82
/// See [scanForDuplicates] and [writeUniqueMembers] .
83
83
final Set <EnumConstant > uniqueMembers = {};
84
84
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.
86
87
String formatValue (EnumConstant ec) {
87
88
final buffer = StringBuffer ();
88
89
final enumValueName = namer.makeUnique (ec.name);
@@ -100,8 +101,9 @@ class EnumClass extends BindingType {
100
101
///
101
102
/// Since all enum values in Dart are distinct, these duplicates do not
102
103
/// 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.
105
107
void scanForDuplicates () {
106
108
uniqueMembers.clear ();
107
109
uniqueToDuplicates.clear ();
@@ -126,13 +128,14 @@ class EnumClass extends BindingType {
126
128
///
127
129
/// Eg, C: `apple = 1` , Dart: `apple(1)`
128
130
void writeUniqueMembers (StringBuffer s) {
129
- s.writeAll (uniqueMembers.map (formatValue), " ,\n " );
131
+ s.writeAll (uniqueMembers.map (formatValue), ' ,\n ' );
130
132
if (uniqueMembers.isNotEmpty) s.write (';\n ' );
131
133
}
132
134
133
135
/// Writes alias declarations for all members with duplicate values.
134
136
///
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` .
136
139
void writeDuplicateMembers (StringBuffer s) {
137
140
if (duplicateToOriginal.isEmpty) return ;
138
141
for (final entry in duplicateToOriginal.entries) {
@@ -143,48 +146,49 @@ class EnumClass extends BindingType {
143
146
final originalName = enumNames[original]! ;
144
147
enumNames[duplicate] = duplicateName;
145
148
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 ' );
149
152
}
150
- s.write (" ${depth }static const $duplicateName = $originalName ;\n " );
153
+ s.write (' ${depth }static const $duplicateName = $originalName ;\n ' );
151
154
}
152
155
}
153
156
154
157
/// Writes the constructor for the enum.
155
158
///
156
159
/// Always accepts an integer value to match the native value.
157
160
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 ' );
160
163
}
161
164
162
165
/// Overrides [Enum.toString] so all aliases are included, if any.
163
166
///
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.
167
170
void writeToStringOverride (StringBuffer s) {
168
171
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 ' );
171
174
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.
173
177
final unique = entry.key;
174
178
final originalName = enumNames[unique]! ;
175
179
final duplicates = entry.value;
176
180
if (duplicates.isEmpty) continue ;
177
181
final allDuplicates = [
178
182
for (final duplicate in [unique] + duplicates)
179
- " $name .${enumNames [duplicate ]!}" ,
180
- ].join (", " );
183
+ ' $name .${enumNames [duplicate ]!}' ,
184
+ ].join (', ' );
181
185
s.write (
182
186
'$depth $depth '
183
187
'if (this == $originalName ) return "$allDuplicates ";\n ' ,
184
188
);
185
189
}
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 }' );
188
192
}
189
193
190
194
/// Writes the DartDoc string for this enum.
@@ -194,23 +198,24 @@ class EnumClass extends BindingType {
194
198
}
195
199
}
196
200
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.
198
203
void writeEmptyEnum (StringBuffer s) {
199
- s.write (" sealed class $name { }\n " );
204
+ s.write (' sealed class $name { }\n ' );
200
205
}
201
206
202
207
/// Writes a static function that maps integers to enum values.
203
208
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 ' );
205
210
for (final member in uniqueMembers) {
206
211
final memberName = enumNames[member]! ;
207
- s.write (" $depth $depth ${member .value } => $memberName ,\n " );
212
+ s.write (' $depth $depth ${member .value } => $memberName ,\n ' );
208
213
}
209
214
s.write (
210
215
'$depth ${depth }_ => '
211
216
'throw ArgumentError("Unknown value for $name : \$ value"),\n ' ,
212
217
);
213
- s.write (" $depth };\n " );
218
+ s.write (' $depth };\n ' );
214
219
}
215
220
216
221
bool get _isBuiltIn =>
@@ -220,7 +225,7 @@ class EnumClass extends BindingType {
220
225
BindingString toBindingString (Writer w) {
221
226
final s = StringBuffer ();
222
227
if (_isBuiltIn) {
223
- return BindingString (type: BindingStringType .enum_, string: '' );
228
+ return const BindingString (type: BindingStringType .enum_, string: '' );
224
229
}
225
230
scanForDuplicates ();
226
231
@@ -230,13 +235,13 @@ class EnumClass extends BindingType {
230
235
} else {
231
236
s.write ('enum $name {\n ' );
232
237
writeUniqueMembers (s);
233
- s.write (" \n " );
238
+ s.write (' \n ' );
234
239
writeDuplicateMembers (s);
235
- s.write (" \n " );
240
+ s.write (' \n ' );
236
241
writeConstructor (s);
237
- s.write (" \n " );
242
+ s.write (' \n ' );
238
243
writeFromValue (s);
239
- s.write (" \n " );
244
+ s.write (' \n ' );
240
245
writeToStringOverride (s);
241
246
s.write ('}\n\n ' );
242
247
}
@@ -284,7 +289,7 @@ class EnumClass extends BindingType {
284
289
String value, {
285
290
required bool objCRetain,
286
291
}) =>
287
- " $value .value" ;
292
+ ' $value .value' ;
288
293
289
294
@override
290
295
String convertFfiDartTypeToDartType (
@@ -293,7 +298,7 @@ class EnumClass extends BindingType {
293
298
required bool objCRetain,
294
299
String ? objCEnclosingClass,
295
300
}) =>
296
- " ${getDartType (w )}.fromValue($value )" ;
301
+ ' ${getDartType (w )}.fromValue($value )' ;
297
302
}
298
303
299
304
/// Represents a single value in an enum.
0 commit comments