Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add tests and some minor validatation improvements
  • Loading branch information
bparrishMines committed Feb 2, 2024
commit afa62e8756accc48350aa9a83f45252e72807c26
4 changes: 4 additions & 0 deletions packages/pigeon/lib/dart/templates.dart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you see these templates changing much in the future? I get a bit nervous thinking about adding logic into this later. Just based on doing that with previously written pigeon code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't expect these to have many changes in the future. And if they do, it shouldn't be changes that require adding logic when generating them. This should at least be true for InstanceManager, InstanceManagerApi, and ProxyApiBaseClass. I expect all of these to always be basic templates.

However, ProxyApiBaseCodec could require logic later to solve some complex issues, but I don't have any plans for it yet.

Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import '../generator_tools.dart';

/// Creates the `InstanceManager` with the passed string values.
Expand Down
66 changes: 44 additions & 22 deletions packages/pigeon/lib/dart_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,9 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger;
final Set<AstProxyApi> interfacesApis = recursiveFindAllInterfaceApis(api);

// All methods inherited from interfaces and the interfaces of interfaces.
final List<Method> interfacesMethods = <Method>[];
final List<Method> flutterMethodsFromInterfaces = <Method>[];
for (final AstProxyApi proxyApi in interfacesApis) {
interfacesMethods.addAll(proxyApi.methods);
flutterMethodsFromInterfaces.addAll(proxyApi.methods);
}

// A list of Flutter methods inherited from the ProxyApi that this ProxyApi
Expand All @@ -531,17 +531,17 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger;
//
// This also includes methods that super classes inherited from interfaces
// with `implements`.
final List<Method> superClassFlutterMethods = <Method>[];
final List<Method> flutterMethodsFromSuperClasses = <Method>[];
for (final AstProxyApi proxyApi in superClassApisChain.reversed) {
superClassFlutterMethods.addAll(proxyApi.flutterMethods);
flutterMethodsFromSuperClasses.addAll(proxyApi.flutterMethods);
}
if (api.superClass != null) {
final Set<AstProxyApi> superClassInterfacesApis =
final Set<AstProxyApi> interfaceApisFromSuperClasses =
recursiveFindAllInterfaceApis(
api.superClass!.associatedProxyApi!,
);
for (final AstProxyApi proxyApi in superClassInterfacesApis) {
superClassFlutterMethods.addAll(proxyApi.methods);
for (final AstProxyApi proxyApi in interfaceApisFromSuperClasses) {
flutterMethodsFromSuperClasses.addAll(proxyApi.methods);
}
}

Expand All @@ -568,18 +568,18 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger;
codecInstanceName: codecInstanceName,
superClassApi: api.superClass?.associatedProxyApi,
unattachedFields: api.unattachedFields,
declaredAndInheritedFlutterMethods: superClassFlutterMethods
.followedBy(interfacesMethods)
.followedBy(api.flutterMethods),
flutterMethodsFromSuperClasses: flutterMethodsFromSuperClasses,
flutterMethodsFromInterfaces: flutterMethodsFromInterfaces,
declaredFlutterMethods: api.flutterMethods,
))
..constructors.add(
_proxyApiDetachedConstructor(
apiName: api.name,
superClassApi: api.superClass?.associatedProxyApi,
unattachedFields: api.unattachedFields,
declaredAndInheritedFlutterMethods: superClassFlutterMethods
.followedBy(interfacesMethods)
.followedBy(api.flutterMethods),
flutterMethodsFromSuperClasses: flutterMethodsFromSuperClasses,
flutterMethodsFromInterfaces: flutterMethodsFromInterfaces,
declaredFlutterMethods: api.flutterMethods,
),
)
..fields.addAll(<cb.Field>[
Expand All @@ -606,8 +606,8 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger;
codecName: codecName,
unattachedFields: api.unattachedFields,
hasCallbackConstructor: api.methods
.followedBy(superClassFlutterMethods)
.followedBy(interfacesMethods)
.followedBy(flutterMethodsFromSuperClasses)
.followedBy(flutterMethodsFromInterfaces)
.every((Method method) => !method.isRequired),
),
)
Expand All @@ -629,7 +629,7 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger;
))
..methods.add(_proxyApiCopyMethod(
flutterMethods: api.flutterMethods,
superClassFlutterMethods: superClassFlutterMethods,
flutterMethodsFromSuperClasses: flutterMethodsFromSuperClasses,
apiName: api.name,
unattachedFields: api.unattachedFields,
interfacesApis: interfacesApis,
Expand Down Expand Up @@ -1010,7 +1010,9 @@ if (${_varNamePrefix}replyList == null) {
required String codecInstanceName,
required AstProxyApi? superClassApi,
required Iterable<ApiField> unattachedFields,
required Iterable<Method> declaredAndInheritedFlutterMethods,
required Iterable<Method> flutterMethodsFromSuperClasses,
required Iterable<Method> flutterMethodsFromInterfaces,
required Iterable<Method> declaredFlutterMethods,
}) sync* {
final cb.Parameter binaryMessengerParameter = cb.Parameter(
(cb.ParameterBuilder builder) => builder
Expand Down Expand Up @@ -1052,14 +1054,23 @@ if (${_varNamePrefix}replyList == null) {
..toThis = true
..required = !field.type.isNullable,
),
for (final Method method in declaredAndInheritedFlutterMethods)
for (final Method method in flutterMethodsFromSuperClasses)
cb.Parameter(
(cb.ParameterBuilder builder) => builder
..name = method.name
..named = true
..toSuper = true
..required = method.isRequired,
),
for (final Method method in flutterMethodsFromInterfaces
.followedBy(declaredFlutterMethods))
cb.Parameter(
(cb.ParameterBuilder builder) => builder
..name = method.name
..named = true
..toThis = true
..required = method.isRequired,
),
...constructor.parameters.mapIndexed(
(int index, NamedType parameter) => cb.Parameter(
(cb.ParameterBuilder builder) => builder
Expand Down Expand Up @@ -1132,7 +1143,9 @@ if (${_varNamePrefix}replyList == null) {
required String apiName,
required AstProxyApi? superClassApi,
required Iterable<ApiField> unattachedFields,
required Iterable<Method> declaredAndInheritedFlutterMethods,
required Iterable<Method> flutterMethodsFromSuperClasses,
required Iterable<Method> flutterMethodsFromInterfaces,
required Iterable<Method> declaredFlutterMethods,
}) {
final cb.Parameter binaryMessengerParameter = cb.Parameter(
(cb.ParameterBuilder builder) => builder
Expand Down Expand Up @@ -1166,14 +1179,23 @@ if (${_varNamePrefix}replyList == null) {
..toThis = true
..required = !field.type.isNullable,
),
for (final Method method in declaredAndInheritedFlutterMethods)
for (final Method method in flutterMethodsFromSuperClasses)
cb.Parameter(
(cb.ParameterBuilder builder) => builder
..name = method.name
..named = true
..toSuper = true
..required = method.isRequired,
),
for (final Method method in flutterMethodsFromInterfaces
.followedBy(declaredFlutterMethods))
cb.Parameter(
(cb.ParameterBuilder builder) => builder
..name = method.name
..named = true
..toThis = true
..required = method.isRequired,
),
])
..initializers.addAll(<cb.Code>[
if (superClassApi != null)
Expand Down Expand Up @@ -1741,7 +1763,7 @@ if (${_varNamePrefix}replyList == null) {
/// from the base ProxyApi class.
cb.Method _proxyApiCopyMethod({
required Iterable<Method> flutterMethods,
required Iterable<Method> superClassFlutterMethods,
required Iterable<Method> flutterMethodsFromSuperClasses,
required String apiName,
required Iterable<ApiField> unattachedFields,
required Iterable<AstProxyApi> interfacesApis,
Expand All @@ -1762,7 +1784,7 @@ if (${_varNamePrefix}replyList == null) {
_instanceManagerVarName: cb.refer(_instanceManagerVarName),
for (final ApiField field in unattachedFields)
field.name: cb.refer(field.name),
for (final Method method in superClassFlutterMethods)
for (final Method method in flutterMethodsFromSuperClasses)
method.name: cb.refer(method.name),
for (final AstProxyApi proxyApi in interfacesApis)
for (final Method method in proxyApi.methods)
Expand Down
8 changes: 4 additions & 4 deletions packages/pigeon/lib/pigeon_lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1029,10 +1029,10 @@ List<Error> _validateProxyApi(
}

// Validate this api isn't used as an interface and contains anything except
// Flutter methods.
final bool isValidInterfaceProxyApi = api.hostMethods.isEmpty &&
api.constructors.isEmpty &&
api.fields.isEmpty;
// Flutter methods or a static host method.
final bool isValidInterfaceProxyApi = api.constructors.isEmpty &&
api.fields.where((ApiField field) => !field.isStatic).isEmpty &&
api.hostMethods.where((Method method) => !method.isStatic).isEmpty;
if (!isValidInterfaceProxyApi) {
final Iterable<String> interfaceNames = proxyApi.interfaces.map(
(TypeDeclaration type) => type.baseName,
Expand Down