-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[pigeon] Adds Dart implementation of ProxyApi #6043
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
Changes from 38 commits
6e385f1
abc026a
870cec3
0c69e1d
eb14522
155469f
3a45694
6350353
5cfcb3a
4ce1e21
22c3065
a14485e
360dd7a
ea9f7c3
33b2e07
6c79879
c8db9c8
b414381
00db939
54c7ac2
d05bebf
dfb7e45
8015a9a
2dac15d
36bbca1
afa62e8
1cd4d95
b08d017
fc3df6f
0caa963
1c61c51
cb2e654
12d9c7d
8abdb3f
1d2c549
c0aa558
1f0c6ce
7f1f70e
2b04aa5
94106ae
796d336
dcbd085
358b6d7
0138563
ea338c8
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 |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| import 'package:collection/collection.dart' show ListEquality; | ||
| import 'package:meta/meta.dart'; | ||
| import 'generator_tools.dart'; | ||
| import 'pigeon_lib.dart'; | ||
|
|
||
| typedef _ListEquals = bool Function(List<Object?>, List<Object?>); | ||
|
|
@@ -177,6 +178,46 @@ class AstProxyApi extends Api { | |
| (ApiField field) => !field.isAttached, | ||
| ); | ||
|
|
||
| /// A list of AstProxyApis where each `extends` the API that follows it. | ||
| Iterable<AstProxyApi> get allSuperClasses => recursiveGetSuperClassApisChain( | ||
| this, | ||
| ); | ||
|
|
||
| /// All ProxyApis this API `implements` and all the interfaces those APIs | ||
| /// `implements`. | ||
| Iterable<AstProxyApi> get apisOfInterfaces => | ||
| recursiveFindAllInterfaceApis(this); | ||
|
|
||
| /// All methods inherited from interfaces and the interfaces of interfaces. | ||
| Iterable<Method> flutterMethodsFromInterfaces() sync* { | ||
| for (final AstProxyApi proxyApi in apisOfInterfaces) { | ||
| yield* proxyApi.methods; | ||
| } | ||
| } | ||
|
|
||
| /// A list of Flutter methods inherited from the ProxyApi that this ProxyApi | ||
| /// `extends`. | ||
| /// | ||
| /// This also recursively checks the ProxyApi that the super class `extends` | ||
| /// and so on. | ||
| /// | ||
| /// This also includes methods that super classes inherited from interfaces | ||
| /// with `implements`. | ||
| Iterable<Method> flutterMethodsFromSuperClasses() sync* { | ||
| for (final AstProxyApi proxyApi in allSuperClasses.toList().reversed) { | ||
| yield* proxyApi.flutterMethods; | ||
| } | ||
| if (superClass != null) { | ||
| final Set<AstProxyApi> interfaceApisFromSuperClasses = | ||
| recursiveFindAllInterfaceApis( | ||
| superClass!.associatedProxyApi!, | ||
| ); | ||
| for (final AstProxyApi proxyApi in interfaceApisFromSuperClasses) { | ||
| yield* proxyApi.methods; | ||
| } | ||
| } | ||
| } | ||
|
Contributor
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 don't know if performance really matters here, but ideally these methods would only ever be ran once, and the data stored on the class.
Contributor
Author
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. Since some of the fields of
Contributor
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. Doesn't the code that associates the api's make copies? Maybe I'm looking in the wrong place.
Contributor
Author
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. Unless I'm missing something, a new api is not created: https://github.com/flutter/packages/blob/main/packages/pigeon/lib/pigeon_lib.dart#L1297 and https://github.com/flutter/packages/blob/main/packages/pigeon/lib/pigeon_lib.dart#L1337. Only But even so, as long as the fields are mutable, it could cause a bug in the future if a contributor uses the method. I do think we should probably restructure the AST with immutable classes in the future. Mutable data classes can end up being a foot-gun.
Contributor
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. Can you add a todo for this and tag me in it? |
||
|
|
||
| @override | ||
| String toString() { | ||
| return '(ProxyApi name:$name methods:$methods field:$fields ' | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.