[jnigen] Make Visitor constructable inline - #3521
Conversation
Package publishingIf you have publishing permissions, you can use the links below to publish the changes after merging this PR.
Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation. |
PR HealthChangelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs. This check can be disabled by tagging the PR with API leaks ✔️The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
This check can be disabled by tagging the PR with Breaking changes ✔️
This check can be disabled by tagging the PR with |
| abstract class Visitor { | ||
| const Visitor(); | ||
|
|
||
| factory Visitor.callback({ |
There was a problem hiding this comment.
It's unfortunate this has to be called callback.
Does it work to just call it Visitor(...)? I guess not because the subclasses written by users need to call the parent constructor and it's weird if that one cannot be called Visitor(...).
How about Visitor.inline() or Visitor.fromCallbacks(...), Visitor.concrete(...), Visitor.implementation(...)
Or we should consider making the default constructor not the default name. E.g. that makes the inline visitors more pretty and the custom subclasses slightly less pretty.
class MyVisitor extends Visitor
MyVisitor(...):super.base();Side note. I feel we should make a decision whether we want users to subclass or implement visitor. It should either be a base class (non-implementable) or interface class (non-extendible).
If it's only implementable and not extendible, then we don't need a default constructor for sub classes.
There was a problem hiding this comment.
The downside of making it only implementable is that users have to override every method. That's not a big deal for JNIgen's visitors, but FFIgen will have heaps of visit methods. I've gone with the super.base() option.
| @@ -15,6 +15,15 @@ abstract class _Element { | |||
| /// Users can extend this class to create custom visitors that modify the AST | |||
| /// before code generation. | |||
| abstract class Visitor { | |||
This pattern was suggested for the new FFIgen visitor API, but it would also be handy to have on the JNIgen API.