Generate actual enums#931
Conversation
|
|
||
| run-tests: protos | ||
| dart test | ||
| dart test && dart -Dprotobuf.omit_enum_names=true test |
There was a problem hiding this comment.
There are tests that require testing both options.
There was a problem hiding this comment.
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.
Update: I've introduced the test tag tests_omit_enum_names. (d660015)
| ' represented.'); | ||
| out.println('@$coreImportPrefix.override'); | ||
| out.println("$coreImportPrefix.String toString() => name == '' ? " | ||
| 'value.toString() : name;'); |
There was a problem hiding this comment.
I had to generate a "custom" toString method for each enum, since the default enum toString takes priority over the one from ProtobufEnum.
This method is designed to be 100% compatible, but it might be better to return Enum.name (super.toString()) instead of name.
| // Generated code. Do not modify. | ||
| // source: ${descriptor.name} | ||
| // | ||
| // @dart = 2.12 |
There was a problem hiding this comment.
I've removed all of them, since they would mess up the enum files and I don't think they serve any purpose.
| /// 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.
I'm not sure why this change. I assume the files have not been regenerated in the past.
commit 382993b Author: fischerscode <github@maaeps.de> Date: Sat May 11 03:49:05 2024 +0200 tests commit 2689dd1 Author: fischerscode <github@maaeps.de> Date: Sat May 11 03:48:53 2024 +0200 also test protobuf.omit_enum_names=true commit 96d7cad Author: fischerscode <github@maaeps.de> Date: Sat May 11 03:48:38 2024 +0200 regenerate commit 64850a2 Author: fischerscode <github@maaeps.de> Date: Sat May 11 03:47:46 2024 +0200 generator
This PR changes the enum generation to generate actual enums.
I think sooner or later this is a necessary step to take full advantage of dart`s features.
#862 Also motivates this change.
I tried to keep everything as compatible as possible. I think my implementation should be fully compatible. (Except of sup-typing generated enums. But I think nobody has done this.)
I've grouped my changes into four commits to simplify reviewing this PR.
Close #862