-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
[pigeon] Relocates generator classes and updates imports #2985
Conversation
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.
Initial restricting LGTM. (Eventually we'll want to revisit things like C++ and ObjC being two generators, and probably the sink creation location.)
import 'generator_tools.dart'; | ||
import 'pigeon_lib.dart' show Error; | ||
import 'pigeon_lib.dart' show Error, PigeonOptions, lineReader, openSink; |
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.
We should ideally move these two utility methods to a utility file, and find somewhere for the other things to live, so we don't have circular includes. Than can be done later though.
import 'generator_tools.dart'; | ||
import 'pigeon_lib.dart' show Error; | ||
import 'pigeon_lib.dart' show Error, PigeonOptions, lineReader, openSink; |
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.
The reason that the Generator was in the place it was previously is that it was keeping PigeonOptions
out of the generator files. The idea being that the generators are cleaner/safer/easier-to-maintain if they only have access to the options designated for them instead of giving them every single option. The idea of the Generator
was more of an adapter of the public functions in the generator files which were the actual generators.
If you wanted to retain that organization it's going to be more difficult if you move the Generator implementations to the generator files. You'll have to make Generator generic:
abstract class Generator<T> {
void generate(StringSink sink, T options, Root root);
List<Error> validate(T options, Root root);
}
Then when you store adapters between PigeonOptions and the input that the Generator needs where you store all your generators.
/// Adapts a Generator to PigeonOptions
class GeneratorAdapter {
GeneratorAdapter({this.generate, this.shouldGenerate, this.validate});
void Function(StringSink sink, PigeonOptions options, Root root) generate;
IOSink? Function(PigeonOptions options) shouldGenerate;
List<Error> Function(PigeonOptions options, Root root) validate;
}
var generator = Generator();
generators.add(GeneratorAdapter(
GeneratorAdapter(
generate:(sink, options, root) => generator.generate(sink, options.fooOptions, root),
shouldGenerate:(options) => _openSink(options.fooOut),
validate:(options, root) => generator.validate(options.fooOptions, root)));
The benefits being:
- it makes the Generator API more simple
- it separates the idea of generating code and adapting it to the PigeonOptions format
- it keeps PigeonOptions out of the generator files
How do you like that?
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.
Sonofabitch, late comment. For architecture questions can you guys touch base first. I didn't really have an opportunity to react to 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.
We can revert+retract if this is an issue. I didn't expect putting the generator classes in the generator files to be controversial.
The idea of the
Generator
was more of an adapter of the public functions in the generator files which were the actual generators.
This is why naming is important; I didn't expect that in a package where the most important conceptual thing are generators that the Generator
class wasn't intended to represent a generator.
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.
Yea, it should have been "_Generator" but was made public to help with testing. We don't need to retract. I think separating the adapter and the generator makes everything tidier and easier to maintain but we can do that in a different PR. I think having a Generator abstract class that people follow along in the generator files makes it a bit easier conceptually instead of having loose functions, so that is an improvement.
@@ -340,7 +342,8 @@ Iterable<String> _lineReader(String path) sync* { | |||
} | |||
} | |||
|
|||
IOSink? _openSink(String? output) { | |||
/// Creates IOSink. |
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.
I think there is more to be said here if we want to make this public =)
…tter#2985)" This reverts commit 3b5ae00.
Relocates generator classes and updates imports. Initial set up for flutter/flutter#117416