-
Notifications
You must be signed in to change notification settings - Fork 33
Add ability to seal enum classes in Dart #81
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
base: main
Are you sure you want to change the base?
Conversation
|
Thanks @jerel. Can you rebase for the CI? |
f2bf7d5 to
b595a33
Compare
e76e2df to
638a451
Compare
|
@ma2bd I've rebased and CI checks are passing. |
| pub c_style: bool, | ||
| // Generate sealed class if `true` or abstract class if `false` | ||
| pub sealed: bool, | ||
| // If `sealed_enums` is true then the listed names will be abstract, |
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.
Do you mean "If sealed is true" etc?
| self | ||
| } | ||
|
|
||
| /// Generate abstract or sealed classes for data enums based on `with_sealed_enums` |
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.
nit: typo: extra space "enums based"
| self.output_enum_container(name, variants)?; | ||
| } else if (self.generator.config.enums.sealed | ||
| && !self.generator.config.enums.output_type.contains_key(name)) | ||
| || self.generator.config.enums.output_type.get(name) == Some(&"sealed") |
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.
Looks like we're not using output_type as much when the value is not "enum" or "sealed", right?
Summary
In a project we have a need to generate sealed classes in Dart but fall back to abstract classes in some cases. This PR adds the ability to configure enum generation by creating an EnumConfig struct and optionally specifying a map of types which should use the specified behavior.
I don't know if this fits into your vision for this project but I figured I'd open this PR and see what you thought as it would be nice to keep parity with this main project.
Test Plan
The default is to generate all code exactly as it has been in the past. The new sealed behavior has to be opted in to.