Skip to content

Commit 64850a2

Browse files
committed
generator
1 parent ccf104d commit 64850a2

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

protoc_plugin/lib/src/enum_generator.dart

+23-23
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ class EnumGenerator extends ProtobufContainer {
110110
out.println('@$coreImportPrefix.Deprecated(\'This enum is deprecated\')');
111111
}
112112
out.addAnnotatedBlock(
113-
'class $classname extends $protobufImportPrefix.ProtobufEnum {',
113+
'enum $classname implements $protobufImportPrefix.ProtobufEnum {',
114114
'}\n', [
115115
NamedLocation(
116-
name: classname, fieldPathSegment: fieldPath, start: 'class '.length)
116+
name: classname, fieldPathSegment: fieldPath, start: 'enum '.length)
117117
], () {
118118
// -----------------------------------------------------------------
119119
// Define enum types.
@@ -137,16 +137,14 @@ class EnumGenerator extends ProtobufContainer {
137137
'@$coreImportPrefix.Deprecated(\'This enum value is deprecated\')');
138138
}
139139

140-
out.printlnAnnotated(
141-
'static const $classname $name = '
142-
'$classname._(${val.number}, $conditionalValName);',
143-
[
144-
NamedLocation(
145-
name: name,
146-
fieldPathSegment: fieldPathSegment,
147-
start: 'static const $classname '.length)
148-
]);
140+
out.printlnAnnotated('$name(${val.number}, $conditionalValName),', [
141+
NamedLocation(
142+
name: name, fieldPathSegment: fieldPathSegment, start: 0)
143+
]);
144+
out.println();
149145
}
146+
out.println(';');
147+
150148
if (_aliases.isNotEmpty) {
151149
out.println();
152150
for (var i = 0; i < _aliases.length; i++) {
@@ -164,27 +162,29 @@ class EnumGenerator extends ProtobufContainer {
164162
]);
165163
}
166164
}
167-
out.println();
168165

169-
out.println('static const $coreImportPrefix.List<$classname> values ='
170-
' <$classname> [');
171-
for (final val in _canonicalValues) {
172-
final name = dartNames[val.name];
173-
out.println(' $name,');
174-
}
175-
out.println('];');
176166
out.println();
177-
178167
out.println(
179168
'static final $coreImportPrefix.Map<$coreImportPrefix.int, $classname> _byValue ='
180169
' $protobufImportPrefix.ProtobufEnum.initByValue(values);');
181170
out.println('static $classname? valueOf($coreImportPrefix.int value) =>'
182171
' _byValue[value];');
183-
out.println();
184172

173+
out.println();
174+
out.println('@$coreImportPrefix.override');
175+
out.println('final $coreImportPrefix.int value;');
176+
out.println();
177+
out.println('@$coreImportPrefix.override');
178+
out.println('final $coreImportPrefix.String name;');
179+
out.println();
180+
out.println('const $classname(this.value, this.name);');
181+
out.println();
185182
out.println(
186-
'const $classname._($coreImportPrefix.int v, $coreImportPrefix.String n) '
187-
': super(v, n);');
183+
"/// Returns this enum's [name] or the [value] if names are not"
184+
' represented.');
185+
out.println('@$coreImportPrefix.override');
186+
out.println("$coreImportPrefix.String toString() => name == '' ? "
187+
'value.toString() : name;');
188188
});
189189
}
190190

protoc_plugin/lib/src/file_generator.dart

-1
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,6 @@ class FileGenerator extends ProtobufContainer {
644644
// Generated code. Do not modify.
645645
// source: ${descriptor.name}
646646
//
647-
// @dart = 2.12
648647
''');
649648
ignorelines.forEach(out.println);
650649
out.println('');

0 commit comments

Comments
 (0)