Skip to content
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] Adds Dart implementation of ProxyApi #6043

Merged
merged 45 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6e385f1
update ast
bparrishMines Jan 10, 2024
abc026a
constructor extend method and make required default to true
bparrishMines Jan 10, 2024
870cec3
Merge branch 'main' of github.com:flutter/packages into pigeon_wrappe…
bparrishMines Jan 10, 2024
0c69e1d
use helper method
bparrishMines Jan 10, 2024
eb14522
fix some validation and add tests
bparrishMines Jan 12, 2024
155469f
change required to isRequired
bparrishMines Jan 12, 2024
3a45694
improve docs
bparrishMines Jan 12, 2024
6350353
fix lint errors and hide ProxyApi
bparrishMines Jan 12, 2024
5cfcb3a
Merge branch 'main' of github.com:flutter/packages into pigeon_wrappe…
bparrishMines Jan 12, 2024
4ce1e21
add hide comment
bparrishMines Jan 12, 2024
22c3065
test for recursive looks
bparrishMines Jan 12, 2024
a14485e
fix tools version
bparrishMines Jan 12, 2024
360dd7a
review comments
bparrishMines Jan 23, 2024
ea9f7c3
switch to a method that looks for matching prefix
bparrishMines Jan 24, 2024
33b2e07
avoid loops
bparrishMines Jan 24, 2024
6c79879
Merge branch 'main' of github.com:flutter/packages into pigeon_wrappe…
bparrishMines Jan 24, 2024
c8db9c8
fix test
bparrishMines Jan 24, 2024
b414381
change superClass and interfaces to TypeDeclarations
bparrishMines Jan 25, 2024
00db939
Merge branch 'main' of github.com:flutter/packages into pigeon_wrappe…
bparrishMines Jan 25, 2024
54c7ac2
add deps
bparrishMines Jan 25, 2024
d05bebf
add proxyapi ast helper gen methods
bparrishMines Jan 27, 2024
dfb7e45
Merge branch 'main' of github.com:flutter/packages into pigeon_wrappe…
bparrishMines Jan 30, 2024
8015a9a
implementation of proxyapis stuff for dart
bparrishMines Jan 31, 2024
2dac15d
add proxy api base class
bparrishMines Jan 31, 2024
36bbca1
add documentation
bparrishMines Feb 2, 2024
afa62e8
add tests and some minor validatation improvements
bparrishMines Feb 2, 2024
1cd4d95
add tests actually
bparrishMines Feb 2, 2024
b08d017
generate test api file
bparrishMines Feb 2, 2024
fc3df6f
method improvements
bparrishMines Feb 2, 2024
0caa963
add protected for more methods
bparrishMines Feb 2, 2024
1c61c51
improvement of docs
bparrishMines Feb 2, 2024
cb2e654
change enum name
bparrishMines Feb 4, 2024
12d9c7d
dont gen method without apis
bparrishMines Feb 4, 2024
8abdb3f
Merge branch 'main' of github.com:flutter/packages into pigeon_wrappe…
bparrishMines Feb 4, 2024
1d2c549
Merge branch 'main' of github.com:flutter/packages into pigeon_wrappe…
bparrishMines Feb 27, 2024
c0aa558
fix class name generation without underscore
bparrishMines Feb 27, 2024
1f0c6ce
change to indexMap and fix extra space
bparrishMines Feb 27, 2024
7f1f70e
review comments and regen
bparrishMines Feb 27, 2024
2b04aa5
`Merge branch 'main' of github.com:flutter/packages into pigeon_wrapp…
bparrishMines Feb 27, 2024
94106ae
Merge branch 'main' of github.com:flutter/packages into pigeon_wrappe…
bparrishMines Feb 28, 2024
796d336
move methods
bparrishMines Feb 28, 2024
dcbd085
Merge branch 'main' of github.com:flutter/packages into pigeon_wrappe…
bparrishMines Feb 28, 2024
358b6d7
Merge branch 'main' of github.com:flutter/packages into pigeon_wrappe…
bparrishMines Mar 5, 2024
0138563
Merge branch 'main' of github.com:flutter/packages into pigeon_wrappe…
bparrishMines Mar 14, 2024
ea338c8
Merge branch 'main' of github.com:flutter/packages into pigeon_wrappe…
bparrishMines Mar 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 17.2.0

* [dart] Adds implementation for `@ProxyApi`.

## 17.1.3

* [objc] Fixes double prefixes added to enum names.
Expand Down
127 changes: 127 additions & 0 deletions packages/pigeon/lib/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,133 @@ class AstProxyApi extends Api {
(ApiField field) => !field.isAttached,
);

/// A list of AstProxyApis where each `extends` the API that follows it.
///
/// Returns an empty list if this api does not extend a ProxyApi.
///
/// This method assumes the super classes of each ProxyApi doesn't create a
/// loop. Throws a [ArgumentError] if a loop is found.
///
/// This method also assumes that all super classes are ProxyApis. Otherwise,
/// throws an [ArgumentError].
Iterable<AstProxyApi> allSuperClasses() {
final List<AstProxyApi> superClassChain = <AstProxyApi>[];

if (superClass != null && !superClass!.isProxyApi) {
throw ArgumentError(
'Could not find a ProxyApi for super class: ${superClass!.baseName}',
);
}

AstProxyApi? currentProxyApi = superClass?.associatedProxyApi;
while (currentProxyApi != null) {
if (superClassChain.contains(currentProxyApi)) {
throw ArgumentError(
'Loop found when processing super classes for a ProxyApi: '
'$name, ${superClassChain.map((AstProxyApi api) => api.name)}',
);
}

superClassChain.add(currentProxyApi);

if (currentProxyApi.superClass != null &&
!currentProxyApi.superClass!.isProxyApi) {
throw ArgumentError(
'Could not find a ProxyApi for super class: '
'${currentProxyApi.superClass!.baseName}',
);
}

currentProxyApi = currentProxyApi.superClass?.associatedProxyApi;
}

return superClassChain;
}

/// All ProxyApis this API `implements` and all the interfaces those APIs
/// `implements`.
Iterable<AstProxyApi> apisOfInterfaces() => _recursiveFindAllInterfaceApis();

/// 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 =
superClass!.associatedProxyApi!._recursiveFindAllInterfaceApis();
for (final AstProxyApi proxyApi in interfaceApisFromSuperClasses) {
yield* proxyApi.methods;
}
}
}

/// Whether the api has a method that callbacks to Dart to add a new instance
/// to the InstanceManager.
///
/// This is possible as long as no callback methods are required to
/// instantiate the class.
bool hasCallbackConstructor() {
return flutterMethods
.followedBy(flutterMethodsFromSuperClasses())
.followedBy(flutterMethodsFromInterfaces())
.every((Method method) => !method.isRequired);
}

// Recursively search for all the interfaces apis from a list of names of
// interfaces.
//
// This method assumes that all interfaces are ProxyApis and an api doesn't
// contains itself as an interface. Otherwise, throws an [ArgumentError].
Set<AstProxyApi> _recursiveFindAllInterfaceApis([
Set<AstProxyApi> seenApis = const <AstProxyApi>{},
]) {
final Set<AstProxyApi> allInterfaces = <AstProxyApi>{};

allInterfaces.addAll(
interfaces.map(
(TypeDeclaration type) {
if (!type.isProxyApi) {
throw ArgumentError(
'Could not find a valid ProxyApi for an interface: $type',
);
} else if (seenApis.contains(type.associatedProxyApi)) {
throw ArgumentError(
'A ProxyApi cannot be a super class of itself: ${type.baseName}',
);
}
return type.associatedProxyApi!;
},
),
);

// Adds the current api since it would be invalid for it to be an interface
// of itself.
final Set<AstProxyApi> newSeenApis = <AstProxyApi>{...seenApis, this};

for (final AstProxyApi interfaceApi in <AstProxyApi>{...allInterfaces}) {
allInterfaces.addAll(
interfaceApi._recursiveFindAllInterfaceApis(newSeenApis),
);
}

return allInterfaces;
}

@override
String toString() {
return '(ProxyApi name:$name methods:$methods field:$fields '
Expand Down
Loading