-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate actuall enums
#931
base: master
Are you sure you want to change the base?
Changes from 4 commits
64850a2
96d7cad
2689dd1
382993b
2b145be
d660015
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,10 +110,10 @@ class EnumGenerator extends ProtobufContainer { | |
out.println('@$coreImportPrefix.Deprecated(\'This enum is deprecated\')'); | ||
} | ||
out.addAnnotatedBlock( | ||
'class $classname extends $protobufImportPrefix.ProtobufEnum {', | ||
'enum $classname implements $protobufImportPrefix.ProtobufEnum {', | ||
'}\n', [ | ||
NamedLocation( | ||
name: classname, fieldPathSegment: fieldPath, start: 'class '.length) | ||
name: classname, fieldPathSegment: fieldPath, start: 'enum '.length) | ||
], () { | ||
// ----------------------------------------------------------------- | ||
// Define enum types. | ||
|
@@ -137,16 +137,14 @@ class EnumGenerator extends ProtobufContainer { | |
'@$coreImportPrefix.Deprecated(\'This enum value is deprecated\')'); | ||
} | ||
|
||
out.printlnAnnotated( | ||
'static const $classname $name = ' | ||
'$classname._(${val.number}, $conditionalValName);', | ||
[ | ||
NamedLocation( | ||
name: name, | ||
fieldPathSegment: fieldPathSegment, | ||
start: 'static const $classname '.length) | ||
]); | ||
out.printlnAnnotated('$name(${val.number}, $conditionalValName),', [ | ||
NamedLocation( | ||
name: name, fieldPathSegment: fieldPathSegment, start: 0) | ||
]); | ||
out.println(); | ||
} | ||
out.println(';'); | ||
|
||
if (_aliases.isNotEmpty) { | ||
out.println(); | ||
for (var i = 0; i < _aliases.length; i++) { | ||
|
@@ -164,27 +162,29 @@ class EnumGenerator extends ProtobufContainer { | |
]); | ||
} | ||
} | ||
out.println(); | ||
|
||
out.println('static const $coreImportPrefix.List<$classname> values =' | ||
' <$classname> ['); | ||
for (final val in _canonicalValues) { | ||
final name = dartNames[val.name]; | ||
out.println(' $name,'); | ||
} | ||
out.println('];'); | ||
out.println(); | ||
|
||
out.println( | ||
'static final $coreImportPrefix.Map<$coreImportPrefix.int, $classname> _byValue =' | ||
' $protobufImportPrefix.ProtobufEnum.initByValue(values);'); | ||
out.println('static $classname? valueOf($coreImportPrefix.int value) =>' | ||
' _byValue[value];'); | ||
out.println(); | ||
|
||
out.println(); | ||
out.println('@$coreImportPrefix.override'); | ||
out.println('final $coreImportPrefix.int value;'); | ||
out.println(); | ||
out.println('@$coreImportPrefix.override'); | ||
out.println('final $coreImportPrefix.String name;'); | ||
out.println(); | ||
out.println('const $classname(this.value, this.name);'); | ||
out.println(); | ||
out.println( | ||
'const $classname._($coreImportPrefix.int v, $coreImportPrefix.String n) ' | ||
': super(v, n);'); | ||
"/// Returns this enum's [name] or the [value] if names are not" | ||
' represented.'); | ||
out.println('@$coreImportPrefix.override'); | ||
out.println("$coreImportPrefix.String toString() => name == '' ? " | ||
'value.toString() : name;'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to generate a "custom" This method is designed to be 100% compatible, but it might be better to return |
||
}); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -644,7 +644,6 @@ class FileGenerator extends ProtobufContainer { | |
// Generated code. Do not modify. | ||
// source: ${descriptor.name} | ||
// | ||
// @dart = 2.12 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've removed all of them, since they would mess up the enum files and I don't think they serve any purpose. |
||
'''); | ||
ignorelines.forEach(out.println); | ||
out.println(''); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
// Generated code. Do not modify. | ||
// source: dart_options.proto | ||
// | ||
// @dart = 2.12 | ||
|
||
// ignore_for_file: annotate_overrides, camel_case_types, comment_references | ||
// ignore_for_file: constant_identifier_names, library_prefixes | ||
|
@@ -13,6 +12,8 @@ import 'dart:core' as $core; | |
|
||
import 'package:protobuf/protobuf.dart' as $pb; | ||
|
||
export 'package:protobuf/protobuf.dart' show GeneratedMessageGenericExtensions; | ||
|
||
/// A mixin that can be used in the 'with' clause of the generated Dart class | ||
/// for a proto message. | ||
class DartMixin extends $pb.GeneratedMessage { | ||
|
@@ -171,7 +172,7 @@ class Imports extends $pb.GeneratedMessage { | |
/// so the generated code may contain errors. Therefore, running dartanalyzer | ||
/// on the generated file is a good idea. | ||
@$pb.TagNumber(1) | ||
$core.List<DartMixin> get mixins => $_getList(0); | ||
$pb.PbList<DartMixin> get mixins => $_getList(0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why this change. I assume the files have not been regenerated in the past. |
||
} | ||
|
||
class Dart_options { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are tests that require testing both options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out this has to be
dart -Dprotobuf.omit_enum_names=true test --use-data-isolate-strategy
(changed it in 2b145be)See dart-lang/test#1794 (comment)
Unfortunately this is much slower. It might be best to change the tests that depend on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: I've introduced the test tag
tests_omit_enum_names
. (d660015)