From 6e385f12be56cbc83092aa036efaff03a9c02bb0 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 10 Jan 2024 16:23:58 -0500 Subject: [PATCH 01/32] update ast --- packages/pigeon/CHANGELOG.md | 4 + packages/pigeon/lib/ast.dart | 213 ++++++- packages/pigeon/lib/cpp_generator.dart | 35 +- packages/pigeon/lib/dart_generator.dart | 22 +- packages/pigeon/lib/generator.dart | 105 +++- packages/pigeon/lib/generator_tools.dart | 100 ++++ packages/pigeon/lib/java_generator.dart | 20 +- packages/pigeon/lib/kotlin_generator.dart | 19 +- packages/pigeon/lib/objc_generator.dart | 16 +- packages/pigeon/lib/pigeon_lib.dart | 560 +++++++++++++++++- packages/pigeon/lib/swift_generator.dart | 20 +- packages/pigeon/pubspec.yaml | 2 +- packages/pigeon/test/cpp_generator_test.dart | 88 ++- packages/pigeon/test/dart_generator_test.dart | 170 +++--- .../pigeon/test/generator_tools_test.dart | 27 +- packages/pigeon/test/java_generator_test.dart | 87 ++- .../pigeon/test/kotlin_generator_test.dart | 96 +-- packages/pigeon/test/objc_generator_test.dart | 193 ++++-- packages/pigeon/test/pigeon_lib_test.dart | 8 +- .../pigeon/test/swift_generator_test.dart | 84 ++- 20 files changed, 1481 insertions(+), 388 deletions(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 6e05728aa341..a0dbe6f8c8a3 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,7 @@ +## 16.0.1 + +* Adds ProxyApi to AST generation. + ## 16.0.0 * [java] Adds `VoidResult` type for `Void` returns. diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index 9d79a781afbd..7b0e32511fae 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -29,7 +29,10 @@ class Method extends Node { required this.name, required this.returnType, required this.parameters, + required this.location, + this.required = false, this.isAsynchronous = false, + this.isStatic = false, this.offset, this.objcSelector = '', this.swiftFunction = '', @@ -68,6 +71,18 @@ class Method extends Node { /// For example: [" List of documentation comments, separated by line.", ...] List documentationComments; + /// Where the implementation of this method is located, host or Flutter. + ApiLocation location; + + /// Whether this method is required to be implemented. + /// + /// This flag is typically used to determine whether a callback method for + /// a `ProxyApi` is nullable or not. + bool required; + + /// Whether this is a static method of a ProxyApi. + bool isStatic; + @override String toString() { final String objcSelectorStr = @@ -78,29 +93,185 @@ class Method extends Node { } } -/// Represents a collection of [Method]s that are hosted on a given [location]. -class Api extends Node { +/// Represents a collection of [Method]s that are implemented on the platform +/// side. +class AstHostApi extends Api { + /// Parametric constructor for [AstHostApi]. + AstHostApi({ + required super.name, + required super.methods, + super.documentationComments = const [], + this.dartHostTestHandler, + }); + + /// The name of the Dart test interface to generate to help with testing. + String? dartHostTestHandler; + + @override + String toString() { + return '(HostApi name:$name methods:$methods documentationComments:$documentationComments dartHostTestHandler:$dartHostTestHandler)'; + } +} + +/// Represents a collection of [Method]s that are hosted on the Flutter side. +class AstFlutterApi extends Api { + /// Parametric constructor for [AstFlutterApi]. + AstFlutterApi({ + required super.name, + required super.methods, + super.documentationComments = const [], + }); + + @override + String toString() { + return '(FlutterApi name:$name methods:$methods documentationComments:$documentationComments)'; + } +} + +/// Represents an API that wraps a native class. +class AstProxyApi extends Api { + /// Parametric constructor for [AstProxyApi]. + AstProxyApi({ + required super.name, + required super.methods, + super.documentationComments = const [], + required this.constructors, + required this.fields, + this.superClassName, + this.interfacesNames = const {}, + }); + + /// List of constructors inside the API. + final List constructors; + + /// List of fields inside the API. + List fields; + + /// Name of the class this class considers the super class. + final String? superClassName; + + /// Name of the classes this class considers to be implemented. + final Set interfacesNames; + + /// Methods implemented in the host platform language. + Iterable get hostMethods => methods.where( + (Method method) => method.location == ApiLocation.host, + ); + + /// Methods implemented in Flutter. + Iterable get flutterMethods => methods.where( + (Method method) => method.location == ApiLocation.flutter, + ); + + /// All fields that are attached. + /// + /// See [attached]. + Iterable get attachedFields => fields.where( + (Field field) => field.isAttached, + ); + + /// All fields that are not attached. + /// + /// See [attached]. + Iterable get unattachedFields => fields.where( + (Field field) => !field.isAttached, + ); + + @override + String toString() { + return '(ProxyApi name:$name methods:$methods documentationComments:$documentationComments superClassName:$superClassName interfacesNames:$interfacesNames)'; + } +} + +/// Represents a constructor for an API. +class Constructor extends Node { + /// Parametric constructor for [Constructor]. + Constructor({ + required this.name, + required this.parameters, + this.offset, + this.swiftFunction = '', + this.documentationComments = const [], + }); + + /// The name of the method. + String name; + + /// The parameters passed into the [Constructor]. + List parameters; + + /// The offset in the source file where the field appears. + int? offset; + + /// An override for the generated swift function signature (ex. "divideNumber(_:by:)"). + String swiftFunction; + + /// List of documentation comments, separated by line. + /// + /// Lines should not include the comment marker itself, but should include any + /// leading whitespace, so that any indentation in the original comment is preserved. + /// For example: [" List of documentation comments, separated by line.", ...] + List documentationComments; + + @override + String toString() { + final String swiftFunctionStr = + swiftFunction.isEmpty ? '' : ' swiftFunction:$swiftFunction'; + return '(Constructor name:$name parameters:$parameters $swiftFunctionStr documentationComments:$documentationComments)'; + } +} + +/// Represents a field of an API. +class Field extends NamedType { + /// Constructor for [Field]. + Field({ + required super.name, + required super.type, + super.offset, + super.documentationComments, + this.isAttached = false, + this.isStatic = false, + }) : assert(!isStatic || isAttached); + + /// Whether this is an attached field for a [AstProxyApi]. + /// + /// See [attached]. + final bool isAttached; + + /// Whether this is a static field of a [AstProxyApi]. + /// + /// A static field must also be attached. See [attached]. + final bool isStatic; + + /// Returns a copy of [Parameter] instance with new attached [TypeDeclaration]. + @override + Field copyWithType(TypeDeclaration type) { + return Field( + name: name, + type: type, + offset: offset, + documentationComments: documentationComments, + isAttached: isAttached, + isStatic: isStatic, + ); + } +} + +/// Represents a collection of [Method]s. +sealed class Api extends Node { /// Parametric constructor for [Api]. Api({ required this.name, - required this.location, required this.methods, - this.dartHostTestHandler, this.documentationComments = const [], }); /// The name of the API. String name; - /// Where the API's implementation is located, host or Flutter. - ApiLocation location; - /// List of methods inside the API. List methods; - /// The name of the Dart test interface to generate to help with testing. - String? dartHostTestHandler; - /// List of documentation comments, separated by line. /// /// Lines should not include the comment marker itself, but should include any @@ -110,7 +281,7 @@ class Api extends Node { @override String toString() { - return '(Api name:$name location:$location methods:$methods documentationComments:$documentationComments)'; + return '(Api name:$name methods:$methods documentationComments:$documentationComments)'; } } @@ -123,6 +294,7 @@ class TypeDeclaration { required this.isNullable, this.associatedEnum, this.associatedClass, + this.associatedProxyApi, this.typeArguments = const [], }); @@ -132,6 +304,7 @@ class TypeDeclaration { isNullable = false, associatedEnum = null, associatedClass = null, + associatedProxyApi = null, typeArguments = const []; /// The base name of the [TypeDeclaration] (ex 'Foo' to 'Foo?'). @@ -158,6 +331,12 @@ class TypeDeclaration { /// Associated [Class], if any. final Class? associatedClass; + /// Associated [AstProxyApi], if any. + final AstProxyApi? associatedProxyApi; + + /// Whether the [TypeDeclaration] has an [associatedProxyApi]. + bool get isProxyApi => associatedProxyApi != null; + @override int get hashCode { // This has to be implemented because TypeDeclaration is used as a Key to a @@ -207,11 +386,21 @@ class TypeDeclaration { ); } + /// Returns duplicated `TypeDeclaration` with attached `associatedProxyApi` value. + TypeDeclaration copyWithProxyApi(AstProxyApi proxyApiDefinition) { + return TypeDeclaration( + baseName: baseName, + isNullable: isNullable, + associatedProxyApi: proxyApiDefinition, + typeArguments: typeArguments, + ); + } + @override String toString() { final String typeArgumentsStr = typeArguments.isEmpty ? '' : 'typeArguments:$typeArguments'; - return '(TypeDeclaration baseName:$baseName isNullable:$isNullable$typeArgumentsStr isEnum:$isEnum isClass:$isClass)'; + return '(TypeDeclaration baseName:$baseName isNullable:$isNullable$typeArgumentsStr isEnum:$isEnum isClass:$isClass isProxyApi:$isProxyApi)'; } } diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index 5247f424052e..2ec8ccd00833 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -175,7 +175,7 @@ class CppHeaderGenerator extends StructuredGenerator { indent, anEnum.documentationComments, _docCommentSpec); indent.write('enum class ${anEnum.name} '); indent.addScoped('{', '};', () { - enumerate(anEnum.members, (int index, final EnumMember member) { + enumerate(anEnum.members, (int index, EnumMember member) { addDocumentationComments( indent, member.documentationComments, _docCommentSpec); indent.writeln( @@ -191,14 +191,21 @@ class CppHeaderGenerator extends StructuredGenerator { Indent indent, { required String dartPackageName, }) { - final bool hasHostApi = root.apis.any((Api api) => - api.methods.isNotEmpty && api.location == ApiLocation.host); - final bool hasFlutterApi = root.apis.any((Api api) => - api.methods.isNotEmpty && api.location == ApiLocation.flutter); + final bool hasHostApi = root.apis + .whereType() + .any((Api api) => api.methods.isNotEmpty); + final bool hasFlutterApi = root.apis + .whereType() + .any((Api api) => api.methods.isNotEmpty); _writeFlutterError(indent); if (hasHostApi) { - _writeErrorOr(indent, friends: root.apis.map((Api api) => api.name)); + _writeErrorOr( + indent, + friends: root.apis + .where((Api api) => api is AstFlutterApi || api is AstHostApi) + .map((Api api) => api.name), + ); } if (hasFlutterApi) { // Nothing yet. @@ -291,7 +298,8 @@ class CppHeaderGenerator extends StructuredGenerator { indent.writeln('friend class ${friend.name};'); } } - for (final Api api in root.apis) { + for (final Api api in root.apis + .where((Api api) => api is AstFlutterApi || api is AstHostApi)) { // TODO(gaaclarke): Find a way to be more precise with our // friendships. indent.writeln('friend class ${api.name};'); @@ -317,10 +325,9 @@ class CppHeaderGenerator extends StructuredGenerator { CppOptions generatorOptions, Root root, Indent indent, - Api api, { + AstFlutterApi api, { required String dartPackageName, }) { - assert(api.location == ApiLocation.flutter); if (getCodecClasses(api, root).isNotEmpty) { _writeCodec(generatorOptions, root, indent, api); } @@ -370,10 +377,9 @@ class CppHeaderGenerator extends StructuredGenerator { CppOptions generatorOptions, Root root, Indent indent, - Api api, { + AstHostApi api, { required String dartPackageName, }) { - assert(api.location == ApiLocation.host); if (getCodecClasses(api, root).isNotEmpty) { _writeCodec(generatorOptions, root, indent, api); } @@ -778,6 +784,7 @@ class CppSourceGenerator extends StructuredGenerator { final Iterable<_IndexedField> indexedFields = indexMap( getFieldsInSerializationOrder(classDefinition), (int index, NamedType field) => _IndexedField(index, field)); + final Iterable<_IndexedField> nullableFields = indexedFields .where((_IndexedField field) => field.field.type.isNullable); final Iterable<_IndexedField> nonNullableFields = indexedFields @@ -823,10 +830,9 @@ class CppSourceGenerator extends StructuredGenerator { CppOptions generatorOptions, Root root, Indent indent, - Api api, { + AstFlutterApi api, { required String dartPackageName, }) { - assert(api.location == ApiLocation.flutter); if (getCodecClasses(api, root).isNotEmpty) { _writeCodec(generatorOptions, root, indent, api); } @@ -937,10 +943,9 @@ class CppSourceGenerator extends StructuredGenerator { CppOptions generatorOptions, Root root, Indent indent, - Api api, { + AstHostApi api, { required String dartPackageName, }) { - assert(api.location == ApiLocation.host); if (getCodecClasses(api, root).isNotEmpty) { _writeCodec(generatorOptions, root, indent, api); } diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 52e2d0e68d95..b8601458e2dc 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -312,12 +312,11 @@ $resultAt != null DartOptions generatorOptions, Root root, Indent indent, - Api api, { + AstFlutterApi api, { String Function(Method)? channelNameFunc, bool isMockHandler = false, required String dartPackageName, }) { - assert(api.location == ApiLocation.flutter); String codecName = _standardMessageCodec; if (getCodecClasses(api, root).isNotEmpty) { codecName = _getCodecName(api); @@ -488,10 +487,9 @@ $resultAt != null DartOptions generatorOptions, Root root, Indent indent, - Api api, { + AstHostApi api, { required String dartPackageName, }) { - assert(api.location == ApiLocation.host); String codecName = _standardMessageCodec; if (getCodecClasses(api, root).isNotEmpty) { codecName = _getCodecName(api); @@ -640,13 +638,11 @@ if (${_varNamePrefix}replyList == null) { relativeDartPath.replaceFirst(RegExp(r'^.*/lib/'), ''); indent.writeln("import 'package:$dartOutputPackageName/$path';"); } - for (final Api api in root.apis) { - if (api.location == ApiLocation.host && api.dartHostTestHandler != null) { - final Api mockApi = Api( + for (final AstHostApi api in root.apis.whereType()) { + if (api.dartHostTestHandler != null) { + final AstFlutterApi mockApi = AstFlutterApi( name: api.dartHostTestHandler!, methods: api.methods, - location: ApiLocation.flutter, - dartHostTestHandler: api.dartHostTestHandler, documentationComments: api.documentationComments, ); writeFlutterApi( @@ -696,10 +692,10 @@ if (${_varNamePrefix}replyList == null) { Indent indent, { required String dartPackageName, }) { - final bool hasHostApi = root.apis.any((Api api) => - api.methods.isNotEmpty && api.location == ApiLocation.host); - final bool hasFlutterApi = root.apis.any((Api api) => - api.methods.isNotEmpty && api.location == ApiLocation.flutter); + final bool hasHostApi = + root.apis.any((Api api) => api.methods.isNotEmpty && api is AstHostApi); + final bool hasFlutterApi = root.apis + .any((Api api) => api.methods.isNotEmpty && api is AstFlutterApi); if (hasHostApi) { _writeCreateConnectionError(indent); diff --git a/packages/pigeon/lib/generator.dart b/packages/pigeon/lib/generator.dart index 1bd083078745..3711fd28dbe3 100644 --- a/packages/pigeon/lib/generator.dart +++ b/packages/pigeon/lib/generator.dart @@ -63,6 +63,24 @@ abstract class StructuredGenerator extends Generator { dartPackageName: dartPackageName, ); + if (root.apis.any((Api api) => api is AstProxyApi)) { + writeInstanceManager( + generatorOptions, + root, + indent, + dartPackageName: dartPackageName, + ); + + writeInstanceManagerApi( + generatorOptions, + root, + indent, + dartPackageName: dartPackageName, + ); + + writeProxyApiBaseCodec(generatorOptions, root, indent); + } + writeEnums( generatorOptions, root, @@ -224,22 +242,31 @@ abstract class StructuredGenerator extends Generator { required String dartPackageName, }) { for (final Api api in root.apis) { - if (api.location == ApiLocation.host) { - writeHostApi( - generatorOptions, - root, - indent, - api, - dartPackageName: dartPackageName, - ); - } else if (api.location == ApiLocation.flutter) { - writeFlutterApi( - generatorOptions, - root, - indent, - api, - dartPackageName: dartPackageName, - ); + switch (api) { + case AstHostApi(): + writeHostApi( + generatorOptions, + root, + indent, + api, + dartPackageName: dartPackageName, + ); + case AstFlutterApi(): + writeFlutterApi( + generatorOptions, + root, + indent, + api, + dartPackageName: dartPackageName, + ); + case AstProxyApi(): + writeProxyApi( + generatorOptions, + root, + indent, + api, + dartPackageName: dartPackageName, + ); } } } @@ -249,7 +276,7 @@ abstract class StructuredGenerator extends Generator { T generatorOptions, Root root, Indent indent, - Api api, { + AstFlutterApi api, { required String dartPackageName, }); @@ -258,7 +285,49 @@ abstract class StructuredGenerator extends Generator { T generatorOptions, Root root, Indent indent, - Api api, { + AstHostApi api, { required String dartPackageName, }); + + /// Writes the implementation of an `InstanceManager` to [indent]. + void writeInstanceManager( + T generatorOptions, + Root root, + Indent indent, { + required String dartPackageName, + }) {} + + /// Writes the implementation of the API for the `InstanceManager` to + /// [indent]. + void writeInstanceManagerApi( + T generatorOptions, + Root root, + Indent indent, { + required String dartPackageName, + }) {} + + /// Writes the base codec to be used by all ProxyApis. + /// + /// This codec should use `128` as the identifier for objects that exist in + /// an `InstanceManager`. The write implementation should convert an instance + /// to an identifier. The read implementation should covert the identifier + /// to an instance. + /// + /// This will serve as the default codec for all ProxyApis. If a ProxyApi + /// needs to create its own codec (it has methods/fields/constructor that use + /// a data class) it should extend this codec and not `StandardMessageCodec`. + void writeProxyApiBaseCodec( + T generatorOptions, + Root root, + Indent indent, + ) {} + + /// Writes a single Proxy Api to [indent]. + void writeProxyApi( + T generatorOptions, + Root root, + Indent indent, + AstProxyApi api, { + required String dartPackageName, + }) {} } diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index ba32f720a2a0..4fba3835620e 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -282,6 +282,24 @@ String getGeneratedCodeWarning() { /// String to be printed after `getGeneratedCodeWarning()'s warning`. const String seeAlsoWarning = 'See also: https://pub.dev/packages/pigeon'; +/// Prefix for utility classes generated for ProxyApis. +/// +/// This lowers the chances of variable name collisions with user defined +/// parameters. +const String classNamePrefix = 'Pigeon_'; + +/// Name for the generated InstanceManager for ProxyApis. +/// +/// This lowers the chances of variable name collisions with user defined +/// parameters. +const String instanceManagerClassName = '${classNamePrefix}InstanceManager'; + +/// Prefix for class member names not defined by the user. +/// +/// This lowers the chances of variable name collisions with user defined +/// parameters. +const String classMemberNamePrefix = 'pigeon_'; + /// Collection of keys used in dictionaries across generators. class Keys { /// The key in the result hash for the 'result' value. @@ -588,6 +606,88 @@ String? deducePackageName(String mainDartFile) { } } +/// Recursively search for all the interfaces apis from a list of names of +/// interfaces. +/// +/// This method assumes that all interfaces names can be found in +/// [allProxyApis]. Otherwise, throws an [ArgumentError]. +Set recursiveFindAllInterfacesApis( + AstProxyApi api, + Iterable allProxyApis, +) { + final Set interfacesApis = {}; + + for (final AstProxyApi proxyApi in allProxyApis) { + if (api.interfacesNames.contains(proxyApi.name)) { + interfacesApis.add(proxyApi); + } + } + + if (interfacesApis.length != api.interfacesNames.length) { + throw ArgumentError( + 'Could not find a ProxyApi for every interface name: ' + '${api.interfacesNames}, ${allProxyApis.map((Api api) => api.name)}', + ); + } + + for (final AstProxyApi proxyApi in Set.from(interfacesApis)) { + interfacesApis.addAll( + recursiveFindAllInterfacesApis(proxyApi, allProxyApis), + ); + } + + return interfacesApis; +} + +/// Creates a list of ProxyApis where each `extends` the ProxyApi that follows +/// it. +/// +/// Returns an empty list if [proxyApi] 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 class names can be found in +/// [allProxyApis]. Otherwise, throws an [ArgumentError]. +List recursiveGetSuperClassApisChain( + AstProxyApi proxyApi, + Iterable allProxyApis, +) { + final List proxyApis = []; + + String? currentProxyApiName = proxyApi.superClassName; + while (currentProxyApiName != null) { + if (proxyApis.length > allProxyApis.length) { + final Iterable apiNames = proxyApis.map( + (AstProxyApi api) => api.name, + ); + throw ArgumentError( + 'Loop found when processing super classes for a ProxyApi: ' + '${proxyApi.name},${apiNames.join(',')}', + ); + } + + AstProxyApi? nextProxyApi; + for (final AstProxyApi node in allProxyApis) { + if (currentProxyApiName == node.name) { + nextProxyApi = node; + proxyApis.add(node); + } + } + + if (nextProxyApi == null) { + throw ArgumentError( + 'Could not find a ProxyApi for every super class name: ' + '$currentProxyApiName, ${allProxyApis.map((Api api) => api.name)}', + ); + } + + currentProxyApiName = nextProxyApi.superClassName; + } + + return proxyApis; +} + /// Enum to specify api type when generating code. enum ApiType { /// Flutter api. diff --git a/packages/pigeon/lib/java_generator.dart b/packages/pigeon/lib/java_generator.dart index 43b42c40e909..0758071e9435 100644 --- a/packages/pigeon/lib/java_generator.dart +++ b/packages/pigeon/lib/java_generator.dart @@ -400,7 +400,7 @@ class JavaGenerator extends StructuredGenerator { JavaOptions generatorOptions, Root root, Indent indent, - Api api, { + AstFlutterApi api, { required String dartPackageName, }) { /// Returns an argument name that can be used in a context where it is possible to collide @@ -414,7 +414,6 @@ class JavaGenerator extends StructuredGenerator { return '${_getArgumentName(count, argument)}Arg'; } - assert(api.location == ApiLocation.flutter); if (getCodecClasses(api, root).isNotEmpty) { _writeCodec(indent, api, root); } @@ -556,9 +555,9 @@ class JavaGenerator extends StructuredGenerator { required String dartPackageName, }) { if (root.apis.any((Api api) => - api.location == ApiLocation.host && + api is AstHostApi && api.methods.any((Method it) => it.isAsynchronous) || - api.location == ApiLocation.flutter)) { + api is AstFlutterApi)) { indent.newln(); _writeResultInterfaces(indent); } @@ -577,10 +576,9 @@ class JavaGenerator extends StructuredGenerator { JavaOptions generatorOptions, Root root, Indent indent, - Api api, { + AstHostApi api, { required String dartPackageName, }) { - assert(api.location == ApiLocation.host); if (getCodecClasses(api, root).isNotEmpty) { _writeCodec(indent, api, root); } @@ -979,10 +977,12 @@ protected static ArrayList wrapError(@NonNull Throwable exception) { Indent indent, { required String dartPackageName, }) { - final bool hasHostApi = root.apis.any((Api api) => - api.methods.isNotEmpty && api.location == ApiLocation.host); - final bool hasFlutterApi = root.apis.any((Api api) => - api.methods.isNotEmpty && api.location == ApiLocation.flutter); + final bool hasHostApi = root.apis + .whereType() + .any((Api api) => api.methods.isNotEmpty); + final bool hasFlutterApi = root.apis + .whereType() + .any((Api api) => api.methods.isNotEmpty); indent.newln(); _writeErrorClass(indent); diff --git a/packages/pigeon/lib/kotlin_generator.dart b/packages/pigeon/lib/kotlin_generator.dart index 88ffb487406e..78337cc2cb14 100644 --- a/packages/pigeon/lib/kotlin_generator.dart +++ b/packages/pigeon/lib/kotlin_generator.dart @@ -307,7 +307,7 @@ class KotlinGenerator extends StructuredGenerator { required String dartPackageName, }) { if (root.apis.any((Api api) => - api.location == ApiLocation.host && + api is AstHostApi && api.methods.any((Method it) => it.isAsynchronous))) { indent.newln(); } @@ -325,10 +325,9 @@ class KotlinGenerator extends StructuredGenerator { KotlinOptions generatorOptions, Root root, Indent indent, - Api api, { + AstFlutterApi api, { required String dartPackageName, }) { - assert(api.location == ApiLocation.flutter); final bool isCustomCodec = getCodecClasses(api, root).isNotEmpty; if (isCustomCodec) { _writeCodec(indent, api, root); @@ -448,11 +447,9 @@ class KotlinGenerator extends StructuredGenerator { KotlinOptions generatorOptions, Root root, Indent indent, - Api api, { + AstHostApi api, { required String dartPackageName, }) { - assert(api.location == ApiLocation.host); - final String apiName = api.name; final bool isCustomCodec = getCodecClasses(api, root).isNotEmpty; @@ -742,10 +739,12 @@ class KotlinGenerator extends StructuredGenerator { Indent indent, { required String dartPackageName, }) { - final bool hasHostApi = root.apis.any((Api api) => - api.methods.isNotEmpty && api.location == ApiLocation.host); - final bool hasFlutterApi = root.apis.any((Api api) => - api.methods.isNotEmpty && api.location == ApiLocation.flutter); + final bool hasHostApi = root.apis + .whereType() + .any((Api api) => api.methods.isNotEmpty); + final bool hasFlutterApi = root.apis + .whereType() + .any((Api api) => api.methods.isNotEmpty); if (hasHostApi) { _writeWrapResult(indent); diff --git a/packages/pigeon/lib/objc_generator.dart b/packages/pigeon/lib/objc_generator.dart index 903957d083c2..bc26495e650b 100644 --- a/packages/pigeon/lib/objc_generator.dart +++ b/packages/pigeon/lib/objc_generator.dart @@ -617,10 +617,9 @@ class ObjcSourceGenerator extends StructuredGenerator { ObjcOptions generatorOptions, Root root, Indent indent, - Api api, { + AstFlutterApi api, { required String dartPackageName, }) { - assert(api.location == ApiLocation.flutter); final String apiName = _className(generatorOptions.prefix, api.name); _writeCodecAndGetter(generatorOptions, root, indent, api); @@ -649,10 +648,9 @@ class ObjcSourceGenerator extends StructuredGenerator { ObjcOptions generatorOptions, Root root, Indent indent, - Api api, { + AstHostApi api, { required String dartPackageName, }) { - assert(api.location == ApiLocation.host); final String apiName = _className(generatorOptions.prefix, api.name); _writeCodecAndGetter(generatorOptions, root, indent, api); @@ -702,10 +700,12 @@ class ObjcSourceGenerator extends StructuredGenerator { Indent indent, { required String dartPackageName, }) { - final bool hasHostApi = root.apis.any((Api api) => - api.methods.isNotEmpty && api.location == ApiLocation.host); - final bool hasFlutterApi = root.apis.any((Api api) => - api.methods.isNotEmpty && api.location == ApiLocation.flutter); + final bool hasHostApi = root.apis + .whereType() + .any((Api api) => api.methods.isNotEmpty); + final bool hasFlutterApi = root.apis + .whereType() + .any((Api api) => api.methods.isNotEmpty); if (hasHostApi) { _writeWrapError(indent); diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index e114af93caa4..2b3bda5f7ca1 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -39,9 +39,44 @@ class _Asynchronous { const _Asynchronous(); } +class _Attached { + const _Attached(); +} + +class _Static { + const _Static(); +} + /// Metadata to annotate a Api method as asynchronous const Object async = _Asynchronous(); +/// Metadata to annotate the field of a ProxyApi as an Attached Field. +/// +/// Attached fields provide a synchronous [AstProxyApi] instance as a field +/// for another [AstProxyApi]. +/// +/// Attached fields: +/// * Must be nonnull. +/// * Must be a ProxyApi type. +/// * Must be a ProxyApi that contains any fields. +/// * Must be a ProxyApi that does not have a required Flutter method. +/// +/// Example generated code: +/// +/// ```dart +/// class MyProxyApi { +/// final MyOtherProxyApi myField = __pigeon_myField(). +/// } +/// ``` +/// +/// The field provides access to the value synchronously, but the native +/// instance is stored in the native `InstanceManager` asynchronously. Similar +/// to how constructors are implemented. +const Object attached = _Attached(); + +/// Metadata to annotate an method or an Attached Field of a ProxyApi as static. +const Object static = _Static(); + /// Metadata annotation used to configure how Pigeon will generate code. class ConfigurePigeon { /// Constructor for ConfigurePigeon. @@ -88,6 +123,30 @@ class FlutterApi { const FlutterApi(); } +/// Metadata to annotate a Pigeon API that wraps a native class. +/// +/// The abstract class with this annotation groups a collection of Dart↔host +/// constructors, fields, methods and host↔Dart methods used to wrap a native +/// class. +/// +/// The generated Dart class acts as a proxy to a native type and +/// maintains instances automatically with an `InstanceManager`. The generated +/// host language class implements methods to interact with class instances +/// or static methods. +class ProxyApi { + /// Parametric constructor for [ProxyApi]. + const ProxyApi({this.superClass}); + + /// The proxy api that is a super class to this one. + /// + /// This provides an alternative to calling `extends` on a class since this + /// requires calling the super class constructor. + /// + /// Note that using this instead of `extends` can cause unexpected conflicts + /// with inherited method names. + final Type? superClass; +} + /// Metadata to annotation methods to control the selector used for objc output. /// The number of components in the provided selector must match the number of /// arguments in the annotated method. @@ -787,7 +846,16 @@ List _validateAst(Root root, String source) { } } } + for (final Api api in root.apis) { + if (api is AstProxyApi) { + result.addAll(_validateProxyApi( + api, + source, + customClasses: customClasses.toSet(), + proxyApis: root.apis.whereType().toSet(), + )); + } for (final Method method in api.methods) { for (final Parameter param in method.parameters) { if (param.type.baseName.isEmpty) { @@ -809,7 +877,7 @@ List _validateAst(Root root, String source) { lineNumber: _calculateLineNumberNullable(source, param.offset), )); } - if (api.location == ApiLocation.flutter) { + if (api is AstFlutterApi) { if (!param.isPositional) { result.add(Error( message: @@ -847,7 +915,7 @@ List _validateAst(Root root, String source) { } } if (method.taskQueueType != TaskQueueType.serial && - api.location != ApiLocation.host) { + method.location == ApiLocation.flutter) { result.add(Error( message: 'Unsupported TaskQueue specification on ${method.name}', lineNumber: _calculateLineNumberNullable(source, method.offset), @@ -859,6 +927,275 @@ List _validateAst(Root root, String source) { return result; } +List _validateProxyApi( + AstProxyApi api, + String source, { + required Set customClasses, + required Set proxyApis, +}) { + final List result = []; + + bool isDataClass(NamedType type) => + customClasses.contains(type.type.baseName); + bool isProxyApi(NamedType type) => proxyApis.any( + (AstProxyApi api) => api.name == type.type.baseName, + ); + Error unsupportedDataClassError(NamedType type) { + return Error( + message: 'ProxyApis do not support data classes: ${type.type.baseName}.', + lineNumber: _calculateLineNumberNullable(source, type.offset), + ); + } + + // Validate super class is another ProxyApi + final String? superClassName = api.superClassName; + if (api.superClassName != null && + !proxyApis.any((AstProxyApi api) => api.name == superClassName)) { + result.add(Error( + message: + 'Super class of ${api.name} is not marked as a @ProxyApi: $superClassName', + )); + } + + // Validate all interfaces are other ProxyApis + for (final String interfaceName in api.interfacesNames) { + if (!proxyApis.any((AstProxyApi api) => api.name == interfaceName)) { + result.add(Error( + message: + 'Interface of ${api.name} is not marked as a @ProxyApi: $interfaceName', + )); + } + } + + List? superClassChain; + try { + superClassChain = recursiveGetSuperClassApisChain(api, proxyApis); + } catch (error) { + result.add(Error(message: error.toString())); + } + + // Validate that the api does not inherit a non attached field from its super class. + if (superClassChain != null && + superClassChain.isNotEmpty && + superClassChain.first.unattachedFields.isNotEmpty) { + result.add(Error( + message: + 'Non attached fields can not be inherited. Non attached field found for parent class ${api.unattachedFields.first.name}', + lineNumber: _calculateLineNumberNullable( + source, + api.unattachedFields.first.offset, + ), + )); + } + + for (final AstProxyApi proxyApi in proxyApis) { + // Validate this api is not used as an attached field while either: + // 1. Having an unattached field. + // 2. Having a required Flutter method. + final bool hasUnattachedField = api.unattachedFields.isNotEmpty; + final bool hasRequiredFlutterMethod = + api.flutterMethods.any((Method method) => method.required); + if (hasUnattachedField || hasRequiredFlutterMethod) { + for (final Field field in proxyApi.attachedFields) { + if (field.type.baseName == api.name) { + if (hasUnattachedField) { + result.add(Error( + message: + 'ProxyApis with fields can not be used as attached fields: ${field.name}', + lineNumber: _calculateLineNumberNullable( + source, + field.offset, + ), + )); + } + if (hasRequiredFlutterMethod) { + result.add(Error( + message: + 'ProxyApis with required callback methods can not be used as attached fields: ${field.name}', + lineNumber: _calculateLineNumberNullable( + source, + field.offset, + ), + )); + } + } + } + } + + // 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; + if (!isValidInterfaceProxyApi) { + for (final String interfaceName in proxyApi.interfacesNames) { + if (interfaceName == api.name) { + result.add(Error( + message: + 'ProxyApis used as interfaces can only have callback methods: ${proxyApi.name}', + )); + } + } + } + } + + // Validate constructor parameters + for (final Constructor constructor in api.constructors) { + for (final Parameter parameter in constructor.parameters) { + if (isDataClass(parameter)) { + result.add(unsupportedDataClassError(parameter)); + } + + if (api.fields.any((Field field) => field.name == parameter.name) || + api.flutterMethods + .any((Method method) => method.name == parameter.name)) { + result.add(Error( + message: + 'Parameter names must not share a name with a field or callback method in constructor "${constructor.name}" in API: "${api.name}"', + lineNumber: _calculateLineNumberNullable(source, parameter.offset), + )); + } + + if (parameter.type.baseName.isEmpty) { + result.add(Error( + message: + 'Parameters must specify their type in constructor "${constructor.name}" in API: "${api.name}"', + lineNumber: _calculateLineNumberNullable(source, parameter.offset), + )); + } else if (parameter.name.startsWith('__pigeon_')) { + result.add(Error( + message: + 'Parameter name must not begin with "__pigeon_" in constructor "${constructor.name}" in API: "${api.name}"', + lineNumber: _calculateLineNumberNullable(source, parameter.offset), + )); + } else if (parameter.name == 'pigeonChannelCodec') { + result.add(Error( + message: + 'Parameter name must not be "pigeonChannelCodec" in constructor "${constructor.name}" in API: "${api.name}"', + lineNumber: _calculateLineNumberNullable(source, parameter.offset), + )); + } else if (parameter.name.startsWith(classNamePrefix)) { + result.add(Error( + message: + 'Parameter name must not begin with "$classNamePrefix" in constructor "${constructor.name}" in API: "${api.name}"', + lineNumber: _calculateLineNumberNullable(source, parameter.offset), + )); + } else if (parameter.name.startsWith(classMemberNamePrefix)) { + result.add(Error( + message: + 'Parameter name must not begin with "$classMemberNamePrefix" in constructor "${constructor.name}" in API: "${api.name}"', + lineNumber: _calculateLineNumberNullable(source, parameter.offset), + )); + } + } + if (constructor.swiftFunction.isNotEmpty) { + final RegExp signatureRegex = + RegExp('\\w+ *\\((\\w+:){${constructor.parameters.length}}\\)'); + if (!signatureRegex.hasMatch(constructor.swiftFunction)) { + result.add(Error( + message: + 'Invalid constructor signature, expected ${constructor.parameters.length} parameters.', + lineNumber: _calculateLineNumberNullable(source, constructor.offset), + )); + } + } + } + + // Validate method parameters + for (final Method method in api.methods) { + for (final Parameter parameter in method.parameters) { + if (isDataClass(parameter)) { + result.add(unsupportedDataClassError(parameter)); + } + + if (parameter.name.startsWith(classNamePrefix)) { + result.add(Error( + message: + 'Parameter name must not begin with "$classNamePrefix" in method "${method.name}" in API: "${api.name}"', + lineNumber: _calculateLineNumberNullable(source, parameter.offset), + )); + } else if (parameter.name.startsWith(classMemberNamePrefix)) { + result.add(Error( + message: + 'Parameter name must not begin with "$classMemberNamePrefix" in method "${method.name}" in API: "${api.name}"', + lineNumber: _calculateLineNumberNullable(source, parameter.offset), + )); + } + } + + if (method.location == ApiLocation.flutter && method.isStatic) { + result.add(Error( + message: 'Static callback methods are not supported: ${method.name}.', + lineNumber: _calculateLineNumberNullable(source, method.offset), + )); + } + } + + // Validate fields + for (final Field field in api.fields) { + if (isDataClass(field)) { + result.add(unsupportedDataClassError(field)); + } else if (field.isStatic) { + if (!isProxyApi(field)) { + result.add(Error( + message: + 'Static fields are considered attached fields and must be a ProxyApi: ${field.type.baseName}.', + lineNumber: _calculateLineNumberNullable(source, field.offset), + )); + } else if (field.type.isNullable) { + result.add(Error( + message: + 'Static fields are considered attached fields and must not be nullable: ${field.type.baseName}.', + lineNumber: _calculateLineNumberNullable(source, field.offset), + )); + } + } else if (field.isAttached) { + if (!isProxyApi(field)) { + result.add(Error( + message: + 'Attached fields must be a ProxyApi: ${field.type.baseName}.', + lineNumber: _calculateLineNumberNullable(source, field.offset), + )); + } + if (field.type.isNullable) { + result.add(Error( + message: + 'Attached fields must not be nullable: ${field.type.baseName}.', + lineNumber: _calculateLineNumberNullable(source, field.offset), + )); + } + } + + if (field.name.startsWith('__pigeon_')) { + result.add(Error( + message: + 'Field name must not begin with "__pigeon_" in API: "${api.name}"', + lineNumber: _calculateLineNumberNullable(source, field.offset), + )); + } else if (field.name == 'pigeonChannelCodec') { + result.add(Error( + message: + 'Field name must not be "pigeonChannelCodec" in API: "${api.name}"', + lineNumber: _calculateLineNumberNullable(source, field.offset), + )); + } else if (field.name.startsWith(classNamePrefix)) { + result.add(Error( + message: + 'Field name must not begin with "$classNamePrefix" in API: "${api.name}"', + lineNumber: _calculateLineNumberNullable(source, field.offset), + )); + } else if (field.name.startsWith(classMemberNamePrefix)) { + result.add(Error( + message: + 'Field name must not begin with "$classMemberNamePrefix" in API: "${api.name}"', + lineNumber: _calculateLineNumberNullable(source, field.offset), + )); + } + } + + return result; +} + class _FindInitializer extends dart_ast_visitor.RecursiveAstVisitor { dart_ast.Expression? initializer; @override @@ -927,6 +1264,10 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { !referencedEnums .map((Enum e) => e.name) .contains(element.key.baseName) && + !_apis + .whereType() + .map((AstProxyApi e) => e.name) + .contains(element.key.baseName) && !validTypes.contains(element.key.baseName) && !element.key.isVoid && element.key.baseName != 'dynamic' && @@ -943,7 +1284,9 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { for (final Class classDefinition in referencedClasses) { final List fields = []; for (final NamedType field in classDefinition.fields) { - fields.add(field.copyWithType(_attachClassesAndEnums(field.type))); + fields.add(field.copyWithType( + _attachClassesEnumsAndProxyApis(field.type), + )); } classDefinition.fields = fields; } @@ -952,10 +1295,31 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { for (final Method func in api.methods) { final List paramList = []; for (final Parameter param in func.parameters) { - paramList.add(param.copyWithType(_attachClassesAndEnums(param.type))); + paramList.add(param.copyWithType( + _attachClassesEnumsAndProxyApis(param.type), + )); } func.parameters = paramList; - func.returnType = _attachClassesAndEnums(func.returnType); + func.returnType = _attachClassesEnumsAndProxyApis(func.returnType); + } + if (api is AstProxyApi) { + for (final Constructor constructor in api.constructors) { + final List paramList = []; + for (final Parameter param in constructor.parameters) { + paramList.add( + param.copyWithType(_attachClassesEnumsAndProxyApis(param.type)), + ); + } + constructor.parameters = paramList; + } + + final List fieldList = []; + for (final Field field in api.fields) { + fieldList.add(field.copyWithType( + _attachClassesEnumsAndProxyApis(field.type), + )); + } + api.fields = fieldList; } } @@ -968,15 +1332,21 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { ); } - TypeDeclaration _attachClassesAndEnums(TypeDeclaration type) { + TypeDeclaration _attachClassesEnumsAndProxyApis(TypeDeclaration type) { final Enum? assocEnum = _enums.firstWhereOrNull( (Enum enumDefinition) => enumDefinition.name == type.baseName); final Class? assocClass = _classes.firstWhereOrNull( (Class classDefinition) => classDefinition.name == type.baseName); + final AstProxyApi? assocProxyApi = + _apis.whereType().firstWhereOrNull( + (Api apiDefinition) => apiDefinition.name == type.baseName, + ); if (assocClass != null) { return type.copyWithClass(assocClass); } else if (assocEnum != null) { return type.copyWithEnum(assocEnum); + } else if (assocProxyApi != null) { + return type.copyWithProxyApi(assocProxyApi); } return type; } @@ -1003,6 +1373,8 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { return expression.value!; } else if (expression is dart_ast.BooleanLiteral) { return expression.value; + } else if (expression is dart_ast.SimpleIdentifier) { + return expression.name; } else if (expression is dart_ast.ListLiteral) { final List list = []; for (final dart_ast.CollectionElement element in expression.elements) { @@ -1016,6 +1388,19 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { } } return list; + } else if (expression is dart_ast.SetOrMapLiteral) { + final Set set = {}; + for (final dart_ast.CollectionElement element in expression.elements) { + if (element is dart_ast.Expression) { + set.add(_expressionToMap(element)); + } else { + _errors.add(Error( + message: 'expected Expression but found $element', + lineNumber: _calculateLineNumber(source, element.offset), + )); + } + } + return set; } else { _errors.add(Error( message: @@ -1081,19 +1466,57 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { } } } - _currentApi = Api( + + _currentApi = AstHostApi( name: node.name.lexeme, - location: ApiLocation.host, methods: [], dartHostTestHandler: dartHostTestHandler, documentationComments: _documentationCommentsParser(node.documentationComment?.tokens), ); } else if (_hasMetadata(node.metadata, 'FlutterApi')) { - _currentApi = Api( + _currentApi = AstFlutterApi( + name: node.name.lexeme, + methods: [], + documentationComments: + _documentationCommentsParser(node.documentationComment?.tokens), + ); + } else if (_hasMetadata(node.metadata, 'ProxyApi')) { + final dart_ast.Annotation proxyApiAnnotation = node.metadata.firstWhere( + (dart_ast.Annotation element) => element.name.name == 'ProxyApi', + ); + + final Map annotationMap = {}; + for (final dart_ast.Expression expression + in proxyApiAnnotation.arguments!.arguments) { + if (expression is dart_ast.NamedExpression) { + annotationMap[expression.name.label.name] = + _expressionToMap(expression.expression); + } + } + + final String? superClassName = annotationMap['superClass'] as String?; + if (superClassName != null && node.extendsClause != null) { + _errors.add( + Error( + message: + 'ProxyApis should either set the super class in the annotation OR use extends: ("${node.name.lexeme}").', + lineNumber: _calculateLineNumber(source, node.offset), + ), + ); + } + + _currentApi = AstProxyApi( name: node.name.lexeme, - location: ApiLocation.flutter, methods: [], + constructors: [], + fields: [], + superClassName: + superClassName ?? node.extendsClause?.superclass.name2.lexeme, + interfacesNames: node.implementsClause?.interfaces + .map((dart_ast.NamedType type) => type.name2.lexeme) + .toSet() ?? + {}, documentationComments: _documentationCommentsParser(node.documentationComment?.tokens), ); @@ -1204,6 +1627,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { final List arguments = parameters.parameters.map(formalParameterToPigeonParameter).toList(); final bool isAsynchronous = _hasMetadata(node.metadata, 'async'); + final bool isStatic = _hasMetadata(node.metadata, 'static'); final String objcSelector = _findMetadata(node.metadata, 'ObjCSelector') ?.arguments ?.arguments @@ -1243,6 +1667,13 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { typeAnnotationsToTypeArguments(returnType.typeArguments), isNullable: returnType.question != null), parameters: arguments, + required: true, + isStatic: isStatic, + location: switch (_currentApi!) { + AstHostApi() => ApiLocation.host, + AstProxyApi() => ApiLocation.host, + AstFlutterApi() => ApiLocation.flutter, + }, isAsynchronous: isAsynchronous, objcSelector: objcSelector, swiftFunction: swiftFunction, @@ -1298,8 +1729,8 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { @override Object? visitFieldDeclaration(dart_ast.FieldDeclaration node) { + final dart_ast.TypeAnnotation? type = node.fields.type; if (_currentClass != null) { - final dart_ast.TypeAnnotation? type = node.fields.type; if (node.isStatic) { _errors.add(Error( message: @@ -1335,6 +1766,88 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { message: 'Expected a named type but found "$node".', lineNumber: _calculateLineNumber(source, node.offset))); } + } else if (_currentApi is AstProxyApi) { + final bool isStatic = _hasMetadata(node.metadata, 'static'); + if (type is dart_ast.GenericFunctionType) { + final List parameters = type.parameters.parameters + .map(formalParameterToPigeonParameter) + .toList(); + final String swiftFunction = + _findMetadata(node.metadata, 'SwiftFunction') + ?.arguments + ?.arguments + .first + .asNullable() + ?.value ?? + ''; + final dart_ast.ArgumentList? taskQueueArguments = + _findMetadata(node.metadata, 'TaskQueue')?.arguments; + final String? taskQueueTypeName = taskQueueArguments == null + ? null + : getFirstChildOfType(taskQueueArguments) + ?.expression + .asNullable() + ?.name; + final TaskQueueType taskQueueType = + _stringToEnum(TaskQueueType.values, taskQueueTypeName) ?? + TaskQueueType.serial; + + // Methods without named return types aren't supported. + final dart_ast.TypeAnnotation returnType = type.returnType!; + returnType as dart_ast.NamedType; + + _currentApi!.methods.add( + Method( + name: node.fields.variables[0].name.lexeme, + returnType: TypeDeclaration( + baseName: _getNamedTypeQualifiedName(returnType), + typeArguments: + typeAnnotationsToTypeArguments(returnType.typeArguments), + isNullable: returnType.question != null, + ), + location: ApiLocation.flutter, + required: type.question == null, + isStatic: isStatic, + parameters: parameters, + isAsynchronous: _hasMetadata(node.metadata, 'async'), + swiftFunction: swiftFunction, + offset: node.offset, + taskQueueType: taskQueueType, + documentationComments: + _documentationCommentsParser(node.documentationComment?.tokens), + ), + ); + } else if (type is dart_ast.NamedType) { + final _FindInitializer findInitializerVisitor = _FindInitializer(); + node.visitChildren(findInitializerVisitor); + if (findInitializerVisitor.initializer != null) { + _errors.add(Error( + message: + 'Initialization isn\'t supported for fields in ProxyApis ("$node"), just use nullable types with no initializer (example "int? x;").', + lineNumber: _calculateLineNumber(source, node.offset))); + } else { + final dart_ast.TypeArgumentList? typeArguments = type.typeArguments; + (_currentApi as AstProxyApi?)!.fields.add( + Field( + type: TypeDeclaration( + baseName: _getNamedTypeQualifiedName(type), + isNullable: type.question != null, + typeArguments: typeAnnotationsToTypeArguments( + typeArguments, + ), + ), + name: node.fields.variables[0].name.lexeme, + isAttached: + _hasMetadata(node.metadata, 'attached') || isStatic, + isStatic: isStatic, + offset: node.offset, + documentationComments: _documentationCommentsParser( + node.documentationComment?.tokens, + ), + ), + ); + } + } } else if (_currentApi != null) { _errors.add(Error( message: 'Fields aren\'t supported in Pigeon API classes ("$node").', @@ -1346,7 +1859,30 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { @override Object? visitConstructorDeclaration(dart_ast.ConstructorDeclaration node) { - if (_currentApi != null) { + if (_currentApi is AstProxyApi) { + final dart_ast.FormalParameterList parameters = node.parameters; + final List arguments = + parameters.parameters.map(formalParameterToPigeonParameter).toList(); + final String swiftFunction = _findMetadata(node.metadata, 'SwiftFunction') + ?.arguments + ?.arguments + .first + .asNullable() + ?.value ?? + ''; + + (_currentApi as AstProxyApi?)!.constructors.add( + Constructor( + name: node.name?.lexeme ?? '', + parameters: arguments, + swiftFunction: swiftFunction, + offset: node.offset, + documentationComments: _documentationCommentsParser( + node.documentationComment?.tokens, + ), + ), + ); + } else if (_currentApi != null) { _errors.add(Error( message: 'Constructors aren\'t supported in API classes ("$node").', lineNumber: _calculateLineNumber(source, node.offset))); diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index ae869426e620..cd2b36880530 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -236,7 +236,7 @@ import FlutterMacOS required String dartPackageName, }) { if (root.apis.any((Api api) => - api.location == ApiLocation.host && + api is AstHostApi && api.methods.any((Method it) => it.isAsynchronous))) { indent.newln(); } @@ -256,11 +256,9 @@ import FlutterMacOS SwiftOptions generatorOptions, Root root, Indent indent, - Api api, { + AstFlutterApi api, { required String dartPackageName, }) { - assert(api.location == ApiLocation.flutter); - /// Returns an argument name that can be used in a context where it is possible to collide. String getEnumSafeArgumentExpression( Root root, int count, NamedType argument) { @@ -380,11 +378,9 @@ import FlutterMacOS SwiftOptions generatorOptions, Root root, Indent indent, - Api api, { + AstHostApi api, { required String dartPackageName, }) { - assert(api.location == ApiLocation.host); - final String apiName = api.name; final bool isCustomCodec = getCodecClasses(api, root).isNotEmpty; @@ -802,10 +798,12 @@ private func nilOrValue(_ value: Any?) -> T? { Indent indent, { required String dartPackageName, }) { - final bool hasHostApi = root.apis.any((Api api) => - api.methods.isNotEmpty && api.location == ApiLocation.host); - final bool hasFlutterApi = root.apis.any((Api api) => - api.methods.isNotEmpty && api.location == ApiLocation.flutter); + final bool hasHostApi = root.apis + .whereType() + .any((Api api) => api.methods.isNotEmpty); + final bool hasFlutterApi = root.apis + .whereType() + .any((Api api) => api.methods.isNotEmpty); if (hasHostApi) { _writeWrapResult(indent); diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index c820df9256f8..865a4ed151d7 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -2,7 +2,7 @@ name: pigeon description: Code generator tool to make communication between Flutter and the host platform type-safe and easier. repository: https://github.com/flutter/packages/tree/main/packages/pigeon issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+pigeon%22 -version: 16.0.0 # This must match the version in lib/generator_tools.dart +version: 16.0.1 # This must match the version in lib/generator_tools.dart environment: sdk: ">=3.0.0 <4.0.0" diff --git a/packages/pigeon/test/cpp_generator_test.dart b/packages/pigeon/test/cpp_generator_test.dart index cbd290b42fa3..af7865815d3a 100644 --- a/packages/pigeon/test/cpp_generator_test.dart +++ b/packages/pigeon/test/cpp_generator_test.dart @@ -25,7 +25,7 @@ final Enum emptyEnum = Enum( void main() { test('gen one api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', parameters: [ @@ -37,6 +37,8 @@ void main() { ), name: 'input') ], + required: true, + location: ApiLocation.host, returnType: TypeDeclaration( baseName: 'Output', isNullable: false, @@ -101,7 +103,7 @@ void main() { test('naming follows style', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', parameters: [ @@ -113,6 +115,7 @@ void main() { ), name: 'someInput') ], + location: ApiLocation.host, returnType: TypeDeclaration( baseName: 'Output', isNullable: false, @@ -179,9 +182,10 @@ void main() { test('FlutterError fields are private with public accessors', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: const TypeDeclaration( @@ -230,9 +234,10 @@ void main() { test('Error field is private with public accessors', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: const TypeDeclaration( @@ -273,9 +278,10 @@ void main() { test('Spaces before {', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -350,9 +356,10 @@ void main() { test('include blocks follow style', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: const TypeDeclaration( @@ -423,9 +430,10 @@ void main() { test('namespaces follows style', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: const TypeDeclaration( @@ -478,9 +486,10 @@ void main() { test('data classes handle nullable fields', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -661,9 +670,10 @@ void main() { test('data classes handle non-nullable fields', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -804,9 +814,10 @@ void main() { test('host nullable return types map correctly', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'returnNullableBool', + location: ApiLocation.host, parameters: [], returnType: const TypeDeclaration( baseName: 'bool', @@ -815,6 +826,7 @@ void main() { ), Method( name: 'returnNullableInt', + location: ApiLocation.host, parameters: [], returnType: const TypeDeclaration( baseName: 'int', @@ -823,6 +835,7 @@ void main() { ), Method( name: 'returnNullableString', + location: ApiLocation.host, parameters: [], returnType: const TypeDeclaration( baseName: 'String', @@ -831,6 +844,7 @@ void main() { ), Method( name: 'returnNullableList', + location: ApiLocation.host, parameters: [], returnType: const TypeDeclaration( baseName: 'List', @@ -845,6 +859,7 @@ void main() { ), Method( name: 'returnNullableMap', + location: ApiLocation.host, parameters: [], returnType: const TypeDeclaration( baseName: 'Map', @@ -863,6 +878,7 @@ void main() { ), Method( name: 'returnNullableDataClass', + location: ApiLocation.host, parameters: [], returnType: TypeDeclaration( baseName: 'ReturnData', @@ -921,9 +937,10 @@ void main() { test('host non-nullable return types map correctly', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'returnBool', + location: ApiLocation.host, parameters: [], returnType: const TypeDeclaration( baseName: 'bool', @@ -932,6 +949,7 @@ void main() { ), Method( name: 'returnInt', + location: ApiLocation.host, parameters: [], returnType: const TypeDeclaration( baseName: 'int', @@ -940,6 +958,7 @@ void main() { ), Method( name: 'returnString', + location: ApiLocation.host, parameters: [], returnType: const TypeDeclaration( baseName: 'String', @@ -948,6 +967,7 @@ void main() { ), Method( name: 'returnList', + location: ApiLocation.host, parameters: [], returnType: const TypeDeclaration( baseName: 'List', @@ -962,6 +982,7 @@ void main() { ), Method( name: 'returnMap', + location: ApiLocation.host, parameters: [], returnType: const TypeDeclaration( baseName: 'Map', @@ -980,6 +1001,7 @@ void main() { ), Method( name: 'returnDataClass', + location: ApiLocation.host, parameters: [], returnType: TypeDeclaration( baseName: 'ReturnData', @@ -1024,9 +1046,10 @@ void main() { test('host nullable arguments map correctly', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( name: 'aBool', @@ -1179,9 +1202,10 @@ void main() { test('host non-nullable arguments map correctly', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( name: 'aBool', @@ -1329,9 +1353,10 @@ void main() { test('flutter nullable arguments map correctly', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( name: 'aBool', @@ -1488,9 +1513,10 @@ void main() { test('flutter non-nullable arguments map correctly', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( name: 'aBool', @@ -1621,9 +1647,10 @@ void main() { test('host API argument extraction uses references', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( name: 'anArg', @@ -1661,9 +1688,10 @@ void main() { test('enum argument', () { final Root root = Root( apis: [ - Api(name: 'Bar', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Bar', methods: [ Method( name: 'bar', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1705,13 +1733,13 @@ void main() { final Root root = Root( apis: [ - Api( + AstFlutterApi( name: 'Api', - location: ApiLocation.flutter, documentationComments: [comments[count++]], methods: [ Method( name: 'method', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), documentationComments: [comments[count++]], parameters: [ @@ -1785,12 +1813,12 @@ void main() { test("doesn't create codecs if no custom datatypes", () { final Root root = Root( apis: [ - Api( + AstFlutterApi( name: 'Api', - location: ApiLocation.flutter, methods: [ Method( name: 'method', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1827,9 +1855,10 @@ void main() { test('creates custom codecs if custom datatypes present', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -1884,9 +1913,10 @@ void main() { test('Does not send unwrapped EncodableLists', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( name: 'aBool', @@ -1966,15 +1996,17 @@ void main() { test('does not keep unowned references in async handlers', () { final Root root = Root(apis: [ - Api(name: 'HostApi', location: ApiLocation.host, methods: [ + AstHostApi(name: 'HostApi', methods: [ Method( name: 'noop', + location: ApiLocation.host, parameters: [], returnType: const TypeDeclaration.voidDeclaration(), isAsynchronous: true, ), Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: const TypeDeclaration( @@ -1988,15 +2020,17 @@ void main() { isAsynchronous: true, ), ]), - Api(name: 'FlutterApi', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'FlutterApi', methods: [ Method( name: 'noop', + location: ApiLocation.flutter, parameters: [], returnType: const TypeDeclaration.voidDeclaration(), isAsynchronous: true, ), Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: const TypeDeclaration( @@ -2038,12 +2072,12 @@ void main() { test('connection error contains channel name', () { final Root root = Root( apis: [ - Api( + AstFlutterApi( name: 'Api', - location: ApiLocation.flutter, methods: [ Method( name: 'method', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( diff --git a/packages/pigeon/test/dart_generator_test.dart b/packages/pigeon/test/dart_generator_test.dart index 83a6556c7fab..884dabf5f683 100644 --- a/packages/pigeon/test/dart_generator_test.dart +++ b/packages/pigeon/test/dart_generator_test.dart @@ -85,9 +85,10 @@ void main() { test('gen one host api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -137,9 +138,10 @@ void main() { test('host multiple args', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'add', + location: ApiLocation.host, parameters: [ Parameter( name: 'x', @@ -170,9 +172,10 @@ void main() { test('flutter multiple args', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'add', + location: ApiLocation.flutter, parameters: [ Parameter( name: 'x', @@ -305,9 +308,10 @@ void main() { test('flutterApi', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -358,9 +362,10 @@ void main() { test('host void', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -398,9 +403,10 @@ void main() { test('flutter void return', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -441,9 +447,10 @@ void main() { test('flutter void argument', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [], returnType: TypeDeclaration( baseName: 'Output', @@ -477,9 +484,10 @@ void main() { test('flutter enum argument with enum class', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -531,9 +539,10 @@ void main() { test('primitive enum host', () { final Root root = Root(apis: [ - Api(name: 'Bar', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Bar', methods: [ Method( name: 'bar', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -567,9 +576,10 @@ void main() { test('flutter non-nullable enum argument with enum class', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -620,9 +630,10 @@ void main() { test('host void argument', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [], returnType: TypeDeclaration( baseName: 'Output', @@ -655,42 +666,40 @@ void main() { test('mock dart handler', () { final Root root = Root(apis: [ - Api( - name: 'Api', + AstHostApi(name: 'Api', dartHostTestHandler: 'ApiMock', methods: [ + Method( + name: 'doSomething', location: ApiLocation.host, - dartHostTestHandler: 'ApiMock', - methods: [ - Method( - name: 'doSomething', - parameters: [ - Parameter( - type: TypeDeclaration( - baseName: 'Input', - isNullable: false, - associatedClass: emptyClass, - ), - name: '') - ], - returnType: TypeDeclaration( - baseName: 'Output', - isNullable: false, - associatedClass: emptyClass, - ), - ), - Method( - name: 'voidReturner', - parameters: [ - Parameter( - type: TypeDeclaration( - baseName: 'Input', - isNullable: false, - associatedClass: emptyClass, - ), - name: '') - ], - returnType: const TypeDeclaration.voidDeclaration(), - ) - ]) + parameters: [ + Parameter( + type: TypeDeclaration( + baseName: 'Input', + isNullable: false, + associatedClass: emptyClass, + ), + name: '') + ], + returnType: TypeDeclaration( + baseName: 'Output', + isNullable: false, + associatedClass: emptyClass, + ), + ), + Method( + name: 'voidReturner', + location: ApiLocation.host, + parameters: [ + Parameter( + type: TypeDeclaration( + baseName: 'Input', + isNullable: false, + associatedClass: emptyClass, + ), + name: '') + ], + returnType: const TypeDeclaration.voidDeclaration(), + ) + ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( @@ -748,9 +757,10 @@ void main() { test('gen one async Flutter Api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -803,9 +813,10 @@ void main() { test('gen one async Flutter Api with void return', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -853,9 +864,10 @@ void main() { test('gen one async Host Api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -906,9 +918,10 @@ void main() { test('async host void argument', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [], returnType: TypeDeclaration( baseName: 'Output', @@ -1027,9 +1040,10 @@ void main() { test('host generics argument', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1061,9 +1075,10 @@ void main() { test('flutter generics argument with void return', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1095,9 +1110,10 @@ void main() { test('host generics return', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -1129,9 +1145,10 @@ void main() { test('flutter generics argument non void return', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -1173,9 +1190,10 @@ void main() { test('return nullable host', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration( baseName: 'int', isNullable: true, @@ -1202,9 +1220,10 @@ void main() { test('return nullable collection host', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration( baseName: 'List', isNullable: true, @@ -1236,9 +1255,10 @@ void main() { test('return nullable async host', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration( baseName: 'int', isNullable: true, @@ -1266,9 +1286,10 @@ void main() { test('return nullable flutter', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration( baseName: 'int', isNullable: true, @@ -1295,9 +1316,10 @@ void main() { test('return nullable async flutter', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration( baseName: 'int', isNullable: true, @@ -1325,9 +1347,10 @@ void main() { test('platform error for return nil on nonnull', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration( baseName: 'int', isNullable: false, @@ -1356,9 +1379,10 @@ void main() { test('nullable argument host', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1388,9 +1412,10 @@ void main() { test('nullable argument flutter', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1420,9 +1445,10 @@ void main() { test('named argument flutter', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1502,13 +1528,13 @@ name: foobar final Root root = Root( apis: [ - Api( + AstFlutterApi( name: 'Api', - location: ApiLocation.flutter, documentationComments: [comments[count++]], methods: [ Method( name: 'method', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), documentationComments: [comments[count++]], parameters: [ @@ -1577,12 +1603,12 @@ name: foobar test("doesn't create codecs if no custom datatypes", () { final Root root = Root( apis: [ - Api( + AstFlutterApi( name: 'Api', - location: ApiLocation.flutter, methods: [ Method( name: 'method', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1615,9 +1641,10 @@ name: foobar test('creates custom codecs if custom datatypes present', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -1668,13 +1695,13 @@ name: foobar test('host test code handles enums', () { final Root root = Root( apis: [ - Api( + AstHostApi( name: 'Api', - location: ApiLocation.host, dartHostTestHandler: 'ApiMock', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1721,9 +1748,10 @@ name: foobar test('connection error contains channel name', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'method', + location: ApiLocation.host, parameters: [], returnType: const TypeDeclaration(baseName: 'Output', isNullable: false), diff --git a/packages/pigeon/test/generator_tools_test.dart b/packages/pigeon/test/generator_tools_test.dart index 4570ac633aaa..8264496d3343 100644 --- a/packages/pigeon/test/generator_tools_test.dart +++ b/packages/pigeon/test/generator_tools_test.dart @@ -78,10 +78,10 @@ void main() { }); test('get codec classes from argument type arguments', () { - final Api api = - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + final AstFlutterApi api = AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -123,10 +123,10 @@ void main() { }); test('get codec classes from return value type arguments', () { - final Api api = - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + final AstFlutterApi api = AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -168,10 +168,10 @@ void main() { }); test('get codec classes from all arguments', () { - final Api api = - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + final AstFlutterApi api = AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -216,9 +216,10 @@ void main() { test('getCodecClasses: nested type arguments', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'foo', + location: ApiLocation.flutter, parameters: [ Parameter( name: 'x', @@ -272,12 +273,12 @@ void main() { test('getCodecClasses: with Object', () { final Root root = Root(apis: [ - Api( + AstFlutterApi( name: 'Api1', - location: ApiLocation.flutter, methods: [ Method( name: 'foo', + location: ApiLocation.flutter, parameters: [ Parameter( name: 'x', @@ -311,12 +312,12 @@ void main() { test('getCodecClasses: unique entries', () { final Root root = Root(apis: [ - Api( + AstFlutterApi( name: 'Api1', - location: ApiLocation.flutter, methods: [ Method( name: 'foo', + location: ApiLocation.flutter, parameters: [ Parameter( name: 'x', @@ -330,12 +331,12 @@ void main() { ) ], ), - Api( + AstHostApi( name: 'Api2', - location: ApiLocation.host, methods: [ Method( name: 'foo', + location: ApiLocation.host, parameters: [ Parameter( name: 'x', diff --git a/packages/pigeon/test/java_generator_test.dart b/packages/pigeon/test/java_generator_test.dart index cba2d702255c..97cbfe8b4d09 100644 --- a/packages/pigeon/test/java_generator_test.dart +++ b/packages/pigeon/test/java_generator_test.dart @@ -123,9 +123,10 @@ void main() { test('gen one host api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -265,9 +266,10 @@ void main() { test('gen one flutter api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -318,9 +320,10 @@ void main() { test('gen host void api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -359,9 +362,10 @@ void main() { test('gen flutter void return api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -403,9 +407,10 @@ void main() { test('gen host void argument api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [], returnType: TypeDeclaration( baseName: 'Output', @@ -440,9 +445,10 @@ void main() { test('gen flutter void argument api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [], returnType: TypeDeclaration( baseName: 'Output', @@ -578,9 +584,10 @@ void main() { test('gen one async Host Api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -639,9 +646,10 @@ void main() { test('gen one async Flutter Api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -745,9 +753,10 @@ void main() { test('primitive enum host', () { final Root root = Root(apis: [ - Api(name: 'Bar', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Bar', methods: [ Method( name: 'bar', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -875,9 +884,10 @@ void main() { test('host generics argument', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -910,9 +920,10 @@ void main() { test('flutter generics argument', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -945,9 +956,10 @@ void main() { test('host generics return', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -977,9 +989,10 @@ void main() { test('flutter generics return', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -1010,9 +1023,10 @@ void main() { test('flutter int return', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration(baseName: 'int', isNullable: false), parameters: [], @@ -1041,9 +1055,10 @@ void main() { test('host multiple args', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'add', + location: ApiLocation.host, parameters: [ Parameter( name: 'x', @@ -1082,9 +1097,10 @@ void main() { test('if host argType is Object not cast', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'objectTest', + location: ApiLocation.host, parameters: [ Parameter( name: 'x', @@ -1110,9 +1126,10 @@ void main() { test('flutter multiple args', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'add', + location: ApiLocation.flutter, parameters: [ Parameter( name: 'x', @@ -1152,9 +1169,10 @@ void main() { test('flutter single args', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'send', + location: ApiLocation.flutter, parameters: [ Parameter( name: 'x', @@ -1184,9 +1202,10 @@ void main() { test('return nullable host', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration( baseName: 'int', isNullable: true, @@ -1213,9 +1232,10 @@ void main() { test('return nullable host async', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration( baseName: 'int', isNullable: true, @@ -1244,9 +1264,10 @@ void main() { test('nullable argument host', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1277,9 +1298,10 @@ void main() { test('nullable argument flutter', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1313,9 +1335,10 @@ void main() { test('background platform channel', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1415,13 +1438,13 @@ void main() { final Root root = Root( apis: [ - Api( + AstFlutterApi( name: 'api', - location: ApiLocation.flutter, documentationComments: [comments[count++]], methods: [ Method( name: 'method', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), documentationComments: [comments[count++]], parameters: [ @@ -1496,12 +1519,12 @@ void main() { test("doesn't create codecs if no custom datatypes", () { final Root root = Root( apis: [ - Api( + AstFlutterApi( name: 'Api', - location: ApiLocation.flutter, methods: [ Method( name: 'method', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1535,9 +1558,10 @@ void main() { test('creates custom codecs if custom datatypes present', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -1587,8 +1611,7 @@ void main() { }); test('creates api error class for custom errors', () { - final Api api = - Api(name: 'Api', location: ApiLocation.host, methods: []); + final Api api = AstHostApi(name: 'Api', methods: []); final Root root = Root( apis: [api], classes: [], @@ -1610,12 +1633,12 @@ void main() { test('connection error contains channel name', () { final Root root = Root( apis: [ - Api( + AstFlutterApi( name: 'Api', - location: ApiLocation.flutter, methods: [ Method( name: 'method', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( diff --git a/packages/pigeon/test/kotlin_generator_test.dart b/packages/pigeon/test/kotlin_generator_test.dart index f51c68b32bcc..e680e3ac66d2 100644 --- a/packages/pigeon/test/kotlin_generator_test.dart +++ b/packages/pigeon/test/kotlin_generator_test.dart @@ -140,9 +140,10 @@ void main() { test('primitive enum host', () { final Root root = Root(apis: [ - Api(name: 'Bar', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Bar', methods: [ Method( name: 'bar', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -176,9 +177,10 @@ void main() { test('gen one host api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -405,9 +407,10 @@ void main() { test('gen one flutter api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -462,9 +465,10 @@ void main() { test('gen host void api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -505,9 +509,10 @@ void main() { test('gen flutter void return api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -550,9 +555,10 @@ void main() { test('gen host void argument api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [], returnType: TypeDeclaration( baseName: 'Output', @@ -590,9 +596,10 @@ void main() { test('gen flutter void argument api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [], returnType: TypeDeclaration( baseName: 'Output', @@ -732,9 +739,10 @@ void main() { test('gen one async Host Api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -790,9 +798,10 @@ void main() { test('gen one async Flutter Api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -979,9 +988,10 @@ void main() { test('host generics argument', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1015,9 +1025,10 @@ void main() { test('flutter generics argument', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1051,9 +1062,10 @@ void main() { test('host generics return', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -1084,9 +1096,10 @@ void main() { test('flutter generics return', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -1116,9 +1129,10 @@ void main() { test('host multiple args', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'add', + location: ApiLocation.host, parameters: [ Parameter( name: 'x', @@ -1159,9 +1173,10 @@ void main() { test('flutter multiple args', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'add', + location: ApiLocation.flutter, parameters: [ Parameter( name: 'x', @@ -1203,9 +1218,10 @@ void main() { test('return nullable host', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration( baseName: 'int', isNullable: true, @@ -1232,9 +1248,10 @@ void main() { test('return nullable host async', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration( baseName: 'int', isNullable: true, @@ -1262,9 +1279,10 @@ void main() { test('nullable argument host', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1298,9 +1316,10 @@ void main() { test('nullable argument flutter', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1333,9 +1352,10 @@ void main() { test('nonnull fields', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -1389,13 +1409,13 @@ void main() { final Root root = Root( apis: [ - Api( + AstFlutterApi( name: 'api', - location: ApiLocation.flutter, documentationComments: [comments[count++]], methods: [ Method( name: 'method', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), documentationComments: [comments[count++]], parameters: [ @@ -1470,12 +1490,12 @@ void main() { test("doesn't create codecs if no custom datatypes", () { final Root root = Root( apis: [ - Api( + AstFlutterApi( name: 'Api', - location: ApiLocation.flutter, methods: [ Method( name: 'method', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1509,9 +1529,10 @@ void main() { test('creates custom codecs if custom datatypes present', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -1563,10 +1584,11 @@ void main() { test('creates api error class for custom errors', () { final Method method = Method( name: 'doSomething', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: []); - final Api api = Api( - name: 'SomeApi', location: ApiLocation.host, methods: [method]); + final AstHostApi api = + AstHostApi(name: 'SomeApi', methods: [method]); final Root root = Root( apis: [api], classes: [], @@ -1593,12 +1615,12 @@ void main() { test('connection error contains channel name', () { final Root root = Root( apis: [ - Api( + AstFlutterApi( name: 'Api', - location: ApiLocation.flutter, methods: [ Method( name: 'method', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1639,12 +1661,12 @@ void main() { test('gen host uses default error class', () { final Root root = Root( apis: [ - Api( + AstHostApi( name: 'Api', - location: ApiLocation.host, methods: [ Method( name: 'method', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1678,12 +1700,12 @@ void main() { test('gen flutter uses default error class', () { final Root root = Root( apis: [ - Api( + AstFlutterApi( name: 'Api', - location: ApiLocation.flutter, methods: [ Method( name: 'method', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1717,12 +1739,12 @@ void main() { test('gen host uses error class', () { final Root root = Root( apis: [ - Api( + AstHostApi( name: 'Api', - location: ApiLocation.host, methods: [ Method( name: 'method', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1759,12 +1781,12 @@ void main() { test('gen flutter uses error class', () { final Root root = Root( apis: [ - Api( + AstFlutterApi( name: 'Api', - location: ApiLocation.flutter, methods: [ Method( name: 'method', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( diff --git a/packages/pigeon/test/objc_generator_test.dart b/packages/pigeon/test/objc_generator_test.dart index f77f186ac8df..267747e1e913 100644 --- a/packages/pigeon/test/objc_generator_test.dart +++ b/packages/pigeon/test/objc_generator_test.dart @@ -188,9 +188,10 @@ void main() { test('primitive enum host', () { final Root root = Root(apis: [ - Api(name: 'Bar', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Bar', methods: [ Method( name: 'bar', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -251,9 +252,10 @@ void main() { test('validate nullable primitive enum', () { final Root root = Root(apis: [ - Api(name: 'Bar', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Bar', methods: [ Method( name: 'bar', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -328,9 +330,10 @@ void main() { test('gen one api header', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -383,9 +386,10 @@ void main() { test('gen one api source', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -656,9 +660,10 @@ void main() { test('prefix nested class header', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -711,9 +716,10 @@ void main() { test('prefix nested class source', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -766,9 +772,10 @@ void main() { test('gen flutter api header', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -821,9 +828,10 @@ void main() { test('gen flutter api source', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -872,9 +880,10 @@ void main() { test('gen host void header', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -913,9 +922,10 @@ void main() { test('gen host void source', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -956,9 +966,10 @@ void main() { test('gen flutter void return header', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -997,9 +1008,10 @@ void main() { test('gen flutter void return source', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -1039,9 +1051,10 @@ void main() { test('gen host void arg header', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [], returnType: TypeDeclaration( baseName: 'Output', @@ -1076,9 +1089,10 @@ void main() { test('gen host void arg source', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [], returnType: TypeDeclaration( baseName: 'Output', @@ -1113,9 +1127,10 @@ void main() { test('gen flutter void arg header', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [], returnType: TypeDeclaration( baseName: 'Output', @@ -1153,9 +1168,10 @@ void main() { test('gen flutter void arg source', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [], returnType: TypeDeclaration( baseName: 'Output', @@ -1281,9 +1297,10 @@ void main() { test('gen map argument with object', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1317,9 +1334,10 @@ void main() { test('async void (input) HostApi header', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -1367,9 +1385,10 @@ void main() { test('async output(input) HostApi header', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -1421,9 +1440,10 @@ void main() { test('async output(void) HostApi header', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [], returnType: TypeDeclaration( baseName: 'Output', @@ -1462,9 +1482,10 @@ void main() { test('async void (void) HostApi header', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [], returnType: const TypeDeclaration.voidDeclaration(), isAsynchronous: true) @@ -1493,9 +1514,10 @@ void main() { test('async output(input) HostApi source', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -1547,9 +1569,10 @@ void main() { test('async void (input) HostApi source', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -1597,9 +1620,10 @@ void main() { test('async void (void) HostApi source', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [], returnType: const TypeDeclaration.voidDeclaration(), isAsynchronous: true) @@ -1628,9 +1652,10 @@ void main() { test('async output(void) HostApi source', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [], returnType: TypeDeclaration( baseName: 'Output', @@ -1755,9 +1780,10 @@ void main() { test('host generics argument', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1818,9 +1844,10 @@ void main() { test('flutter generics argument', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1878,9 +1905,10 @@ void main() { test('host nested generic argument', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1926,9 +1954,10 @@ void main() { test('host generics return', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -1983,9 +2012,10 @@ void main() { test('flutter generics return', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -2040,9 +2070,10 @@ void main() { test('host multiple args', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'add', + location: ApiLocation.host, parameters: [ Parameter( name: 'x', @@ -2110,9 +2141,10 @@ void main() { test('host multiple args async', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'add', + location: ApiLocation.host, parameters: [ Parameter( name: 'x', @@ -2180,9 +2212,10 @@ void main() { test('flutter multiple args', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'add', + location: ApiLocation.flutter, parameters: [ Parameter( name: 'x', @@ -2245,25 +2278,48 @@ void main() { Root getDivideRoot(ApiLocation location) => Root( apis: [ - Api(name: 'Api', location: location, methods: [ - Method( - name: 'divide', - objcSelector: 'divideValue:by:', - parameters: [ - Parameter( - type: const TypeDeclaration( - baseName: 'int', isNullable: false), - name: 'x', - ), - Parameter( - type: const TypeDeclaration( - baseName: 'int', isNullable: false), - name: 'y', - ), - ], - returnType: const TypeDeclaration( - baseName: 'double', isNullable: false)) - ]) + switch (location) { + ApiLocation.host => AstHostApi(name: 'Api', methods: [ + Method( + name: 'divide', + location: location, + objcSelector: 'divideValue:by:', + parameters: [ + Parameter( + type: const TypeDeclaration( + baseName: 'int', isNullable: false), + name: 'x', + ), + Parameter( + type: const TypeDeclaration( + baseName: 'int', isNullable: false), + name: 'y', + ), + ], + returnType: const TypeDeclaration( + baseName: 'double', isNullable: false)) + ]), + ApiLocation.flutter => AstFlutterApi(name: 'Api', methods: [ + Method( + name: 'divide', + location: location, + objcSelector: 'divideValue:by:', + parameters: [ + Parameter( + type: const TypeDeclaration( + baseName: 'int', isNullable: false), + name: 'x', + ), + Parameter( + type: const TypeDeclaration( + baseName: 'int', isNullable: false), + name: 'y', + ), + ], + returnType: const TypeDeclaration( + baseName: 'double', isNullable: false)) + ]), + } ], classes: [], enums: [], @@ -2378,9 +2434,10 @@ void main() { test('return nullable flutter header', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration( baseName: 'int', isNullable: true, @@ -2414,9 +2471,10 @@ void main() { test('return nullable flutter source', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration( baseName: 'int', isNullable: true, @@ -2447,9 +2505,10 @@ void main() { test('return nullable host header', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration( baseName: 'int', isNullable: true, @@ -2480,9 +2539,10 @@ void main() { test('nullable argument host', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -2537,9 +2597,10 @@ void main() { test('nullable argument flutter', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -2593,9 +2654,10 @@ void main() { test('background platform channel', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration( baseName: 'int', isNullable: true, @@ -2644,13 +2706,13 @@ void main() { final Root root = Root( apis: [ - Api( + AstFlutterApi( name: 'api', - location: ApiLocation.flutter, documentationComments: [comments[count++]], methods: [ Method( name: 'method', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), documentationComments: [comments[count++]], parameters: [ @@ -2725,12 +2787,12 @@ void main() { test("doesn't create codecs if no custom datatypes", () { final Root root = Root( apis: [ - Api( + AstFlutterApi( name: 'Api', - location: ApiLocation.flutter, methods: [ Method( name: 'method', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -2767,9 +2829,10 @@ void main() { test('creates custom codecs if custom datatypes present', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -2825,12 +2888,12 @@ void main() { test('connection error contains channel name', () { final Root root = Root( apis: [ - Api( + AstFlutterApi( name: 'Api', - location: ApiLocation.flutter, methods: [ Method( name: 'method', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( diff --git a/packages/pigeon/test/pigeon_lib_test.dart b/packages/pigeon/test/pigeon_lib_test.dart index 5d60f92bf69d..7998733664ab 100644 --- a/packages/pigeon/test/pigeon_lib_test.dart +++ b/packages/pigeon/test/pigeon_lib_test.dart @@ -313,7 +313,7 @@ abstract class AFlutterApi { expect(results.errors.length, equals(0)); expect(results.root.apis.length, equals(1)); expect(results.root.apis[0].name, equals('AFlutterApi')); - expect(results.root.apis[0].location, equals(ApiLocation.flutter)); + expect(results.root.apis[0], isA()); }); test('void host api', () { @@ -370,8 +370,10 @@ abstract class ApiWithMockDartClass { final ParseResults results = parseSource(code); expect(results.errors.length, equals(0)); expect(results.root.apis.length, equals(1)); - expect(results.root.apis[0].dartHostTestHandler, - equals('ApiWithMockDartClassMock')); + expect( + (results.root.apis[0] as AstHostApi).dartHostTestHandler, + equals('ApiWithMockDartClassMock'), + ); }); test('only visible from nesting', () { diff --git a/packages/pigeon/test/swift_generator_test.dart b/packages/pigeon/test/swift_generator_test.dart index 4c07b784eb74..e43dc8efed62 100644 --- a/packages/pigeon/test/swift_generator_test.dart +++ b/packages/pigeon/test/swift_generator_test.dart @@ -84,9 +84,10 @@ void main() { test('primitive enum host', () { final Root root = Root(apis: [ - Api(name: 'Bar', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Bar', methods: [ Method( name: 'bar', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -120,9 +121,10 @@ void main() { test('gen one host api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -248,9 +250,10 @@ void main() { test('gen one flutter api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -302,9 +305,10 @@ void main() { test('gen host void api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -343,9 +347,10 @@ void main() { test('gen flutter void return api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -385,9 +390,10 @@ void main() { test('gen host void argument api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [], returnType: TypeDeclaration( baseName: 'Output', @@ -423,9 +429,10 @@ void main() { test('gen flutter void argument api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [], returnType: TypeDeclaration( baseName: 'Output', @@ -560,9 +567,10 @@ void main() { test('gen one async Host Api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -615,9 +623,10 @@ void main() { test('gen one async Flutter Api', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -798,9 +807,10 @@ void main() { test('host generics argument', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -833,9 +843,10 @@ void main() { test('flutter generics argument', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -868,9 +879,10 @@ void main() { test('host generics return', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -901,9 +913,10 @@ void main() { test('flutter generics return', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -936,9 +949,10 @@ void main() { test('host multiple args', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'add', + location: ApiLocation.host, parameters: [ Parameter( name: 'x', @@ -979,9 +993,10 @@ void main() { test('flutter multiple args', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'add', + location: ApiLocation.flutter, parameters: [ Parameter( name: 'x', @@ -1023,9 +1038,10 @@ void main() { test('return nullable host', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration( baseName: 'int', isNullable: true, @@ -1052,9 +1068,10 @@ void main() { test('return nullable host async', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration( baseName: 'int', isNullable: true, @@ -1085,9 +1102,10 @@ void main() { test('nullable argument host', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.host, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1121,9 +1139,10 @@ void main() { test('nullable argument flutter', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doit', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1156,9 +1175,10 @@ void main() { test('nonnull fields', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.host, parameters: [ Parameter( type: TypeDeclaration( @@ -1210,13 +1230,13 @@ void main() { final Root root = Root( apis: [ - Api( + AstFlutterApi( name: 'api', - location: ApiLocation.flutter, documentationComments: [comments[count++]], methods: [ Method( name: 'method', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), documentationComments: [comments[count++]], parameters: [ @@ -1287,12 +1307,12 @@ void main() { test("doesn't create codecs if no custom datatypes", () { final Root root = Root( apis: [ - Api( + AstFlutterApi( name: 'Api', - location: ApiLocation.flutter, methods: [ Method( name: 'method', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( @@ -1325,9 +1345,10 @@ void main() { test('creates custom codecs if custom datatypes present', () { final Root root = Root(apis: [ - Api(name: 'Api', location: ApiLocation.flutter, methods: [ + AstFlutterApi(name: 'Api', methods: [ Method( name: 'doSomething', + location: ApiLocation.flutter, parameters: [ Parameter( type: TypeDeclaration( @@ -1379,9 +1400,10 @@ void main() { test('swift function signature', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'set', + location: ApiLocation.host, parameters: [ Parameter( type: const TypeDeclaration( @@ -1422,9 +1444,10 @@ void main() { test('swift function signature with same name argument', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'set', + location: ApiLocation.host, parameters: [ Parameter( type: const TypeDeclaration( @@ -1458,9 +1481,10 @@ void main() { test('swift function signature with no arguments', () { final Root root = Root( apis: [ - Api(name: 'Api', location: ApiLocation.host, methods: [ + AstHostApi(name: 'Api', methods: [ Method( name: 'clear', + location: ApiLocation.host, parameters: [], swiftFunction: 'removeAll()', returnType: const TypeDeclaration.voidDeclaration(), @@ -1486,12 +1510,12 @@ void main() { test('connection error contains channel name', () { final Root root = Root( apis: [ - Api( + AstFlutterApi( name: 'Api', - location: ApiLocation.flutter, methods: [ Method( name: 'method', + location: ApiLocation.flutter, returnType: const TypeDeclaration.voidDeclaration(), parameters: [ Parameter( From abc026ad21bad0a91b532a786aba133f0ea293a6 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 10 Jan 2024 17:21:38 -0500 Subject: [PATCH 02/32] constructor extend method and make required default to true --- packages/pigeon/lib/ast.dart | 38 +++++++++-------------------- packages/pigeon/lib/pigeon_lib.dart | 1 - 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index 7b0e32511fae..db663f18bf38 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -30,7 +30,7 @@ class Method extends Node { required this.returnType, required this.parameters, required this.location, - this.required = false, + this.required = true, this.isAsynchronous = false, this.isStatic = false, this.offset, @@ -184,34 +184,18 @@ class AstProxyApi extends Api { } /// Represents a constructor for an API. -class Constructor extends Node { +class Constructor extends Method { /// Parametric constructor for [Constructor]. Constructor({ - required this.name, - required this.parameters, - this.offset, - this.swiftFunction = '', - this.documentationComments = const [], - }); - - /// The name of the method. - String name; - - /// The parameters passed into the [Constructor]. - List parameters; - - /// The offset in the source file where the field appears. - int? offset; - - /// An override for the generated swift function signature (ex. "divideNumber(_:by:)"). - String swiftFunction; - - /// List of documentation comments, separated by line. - /// - /// Lines should not include the comment marker itself, but should include any - /// leading whitespace, so that any indentation in the original comment is preserved. - /// For example: [" List of documentation comments, separated by line.", ...] - List documentationComments; + required super.name, + required super.parameters, + super.offset, + super.swiftFunction = '', + super.documentationComments = const [], + }) : super( + returnType: const TypeDeclaration.voidDeclaration(), + location: ApiLocation.host, + ); @override String toString() { diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 2b3bda5f7ca1..ca268c809eab 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -1667,7 +1667,6 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { typeAnnotationsToTypeArguments(returnType.typeArguments), isNullable: returnType.question != null), parameters: arguments, - required: true, isStatic: isStatic, location: switch (_currentApi!) { AstHostApi() => ApiLocation.host, From 0c69e1dc171a03343b5ced995be5faa305dbcfd3 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 10 Jan 2024 17:50:08 -0500 Subject: [PATCH 03/32] use helper method --- packages/pigeon/lib/pigeon_lib.dart | 167 ++++++++++++++-------------- 1 file changed, 86 insertions(+), 81 deletions(-) diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index ca268c809eab..9791622b8a3c 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -1766,87 +1766,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { lineNumber: _calculateLineNumber(source, node.offset))); } } else if (_currentApi is AstProxyApi) { - final bool isStatic = _hasMetadata(node.metadata, 'static'); - if (type is dart_ast.GenericFunctionType) { - final List parameters = type.parameters.parameters - .map(formalParameterToPigeonParameter) - .toList(); - final String swiftFunction = - _findMetadata(node.metadata, 'SwiftFunction') - ?.arguments - ?.arguments - .first - .asNullable() - ?.value ?? - ''; - final dart_ast.ArgumentList? taskQueueArguments = - _findMetadata(node.metadata, 'TaskQueue')?.arguments; - final String? taskQueueTypeName = taskQueueArguments == null - ? null - : getFirstChildOfType(taskQueueArguments) - ?.expression - .asNullable() - ?.name; - final TaskQueueType taskQueueType = - _stringToEnum(TaskQueueType.values, taskQueueTypeName) ?? - TaskQueueType.serial; - - // Methods without named return types aren't supported. - final dart_ast.TypeAnnotation returnType = type.returnType!; - returnType as dart_ast.NamedType; - - _currentApi!.methods.add( - Method( - name: node.fields.variables[0].name.lexeme, - returnType: TypeDeclaration( - baseName: _getNamedTypeQualifiedName(returnType), - typeArguments: - typeAnnotationsToTypeArguments(returnType.typeArguments), - isNullable: returnType.question != null, - ), - location: ApiLocation.flutter, - required: type.question == null, - isStatic: isStatic, - parameters: parameters, - isAsynchronous: _hasMetadata(node.metadata, 'async'), - swiftFunction: swiftFunction, - offset: node.offset, - taskQueueType: taskQueueType, - documentationComments: - _documentationCommentsParser(node.documentationComment?.tokens), - ), - ); - } else if (type is dart_ast.NamedType) { - final _FindInitializer findInitializerVisitor = _FindInitializer(); - node.visitChildren(findInitializerVisitor); - if (findInitializerVisitor.initializer != null) { - _errors.add(Error( - message: - 'Initialization isn\'t supported for fields in ProxyApis ("$node"), just use nullable types with no initializer (example "int? x;").', - lineNumber: _calculateLineNumber(source, node.offset))); - } else { - final dart_ast.TypeArgumentList? typeArguments = type.typeArguments; - (_currentApi as AstProxyApi?)!.fields.add( - Field( - type: TypeDeclaration( - baseName: _getNamedTypeQualifiedName(type), - isNullable: type.question != null, - typeArguments: typeAnnotationsToTypeArguments( - typeArguments, - ), - ), - name: node.fields.variables[0].name.lexeme, - isAttached: - _hasMetadata(node.metadata, 'attached') || isStatic, - isStatic: isStatic, - offset: node.offset, - documentationComments: _documentationCommentsParser( - node.documentationComment?.tokens, - ), - ), - ); - } - } + _addProxyApiField(type, node); } else if (_currentApi != null) { _errors.add(Error( message: 'Fields aren\'t supported in Pigeon API classes ("$node").', @@ -1919,6 +1839,91 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { } return node.name2.lexeme; } + + void _addProxyApiField( + dart_ast.TypeAnnotation? type, + dart_ast.FieldDeclaration node, + ) { + final bool isStatic = _hasMetadata(node.metadata, 'static'); + if (type is dart_ast.GenericFunctionType) { + final List parameters = type.parameters.parameters + .map(formalParameterToPigeonParameter) + .toList(); + final String swiftFunction = _findMetadata(node.metadata, 'SwiftFunction') + ?.arguments + ?.arguments + .first + .asNullable() + ?.value ?? + ''; + final dart_ast.ArgumentList? taskQueueArguments = + _findMetadata(node.metadata, 'TaskQueue')?.arguments; + final String? taskQueueTypeName = taskQueueArguments == null + ? null + : getFirstChildOfType(taskQueueArguments) + ?.expression + .asNullable() + ?.name; + final TaskQueueType taskQueueType = + _stringToEnum(TaskQueueType.values, taskQueueTypeName) ?? + TaskQueueType.serial; + + // Methods without named return types aren't supported. + final dart_ast.TypeAnnotation returnType = type.returnType!; + returnType as dart_ast.NamedType; + + _currentApi!.methods.add( + Method( + name: node.fields.variables[0].name.lexeme, + returnType: TypeDeclaration( + baseName: _getNamedTypeQualifiedName(returnType), + typeArguments: + typeAnnotationsToTypeArguments(returnType.typeArguments), + isNullable: returnType.question != null, + ), + location: ApiLocation.flutter, + required: type.question == null, + isStatic: isStatic, + parameters: parameters, + isAsynchronous: _hasMetadata(node.metadata, 'async'), + swiftFunction: swiftFunction, + offset: node.offset, + taskQueueType: taskQueueType, + documentationComments: + _documentationCommentsParser(node.documentationComment?.tokens), + ), + ); + } else if (type is dart_ast.NamedType) { + final _FindInitializer findInitializerVisitor = _FindInitializer(); + node.visitChildren(findInitializerVisitor); + if (findInitializerVisitor.initializer != null) { + _errors.add(Error( + message: + 'Initialization isn\'t supported for fields in ProxyApis ("$node"), just use nullable types with no initializer (example "int? x;").', + lineNumber: _calculateLineNumber(source, node.offset))); + } else { + final dart_ast.TypeArgumentList? typeArguments = type.typeArguments; + (_currentApi as AstProxyApi?)!.fields.add( + Field( + type: TypeDeclaration( + baseName: _getNamedTypeQualifiedName(type), + isNullable: type.question != null, + typeArguments: typeAnnotationsToTypeArguments( + typeArguments, + ), + ), + name: node.fields.variables[0].name.lexeme, + isAttached: _hasMetadata(node.metadata, 'attached') || isStatic, + isStatic: isStatic, + offset: node.offset, + documentationComments: _documentationCommentsParser( + node.documentationComment?.tokens, + ), + ), + ); + } + } + } } int? _calculateLineNumberNullable(String contents, int? offset) { From eb14522bf8252e1e82b2cb95b94bb116ef70b31a Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:20:20 -0500 Subject: [PATCH 04/32] fix some validation and add tests --- packages/pigeon/lib/generator_tools.dart | 13 ++ packages/pigeon/lib/pigeon_lib.dart | 31 ++-- packages/pigeon/test/pigeon_lib_test.dart | 212 ++++++++++++++++++++++ 3 files changed, 240 insertions(+), 16 deletions(-) diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 4fba3835620e..7fa2f967cf9a 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -437,6 +437,19 @@ Map> getReferencedTypes( } references.addMany(_getTypeArguments(method.returnType), method.offset); } + if (api is AstProxyApi) { + for (final Constructor constructor in api.constructors) { + for (final NamedType parameter in constructor.parameters) { + references.addMany( + _getTypeArguments(parameter.type), + parameter.offset, + ); + } + } + for (final Field field in api.fields) { + references.addMany(_getTypeArguments(field.type), field.offset); + } + } } final Set referencedTypeNames = diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 9791622b8a3c..1e69a4818415 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -974,34 +974,34 @@ List _validateProxyApi( result.add(Error(message: error.toString())); } - // Validate that the api does not inherit a non attached field from its super class. - if (superClassChain != null && - superClassChain.isNotEmpty && - superClassChain.first.unattachedFields.isNotEmpty) { + // Validate that the api does not inherit an unattached field from its super class. + final AstProxyApi? directSuperClass = superClassChain?.firstOrNull; + if (directSuperClass != null && + directSuperClass.unattachedFields.isNotEmpty) { result.add(Error( message: - 'Non attached fields can not be inherited. Non attached field found for parent class ${api.unattachedFields.first.name}', + 'Unattached fields can not be inherited. Unattached field found for parent class: ${directSuperClass.unattachedFields.first.name}', lineNumber: _calculateLineNumberNullable( source, - api.unattachedFields.first.offset, + directSuperClass.unattachedFields.first.offset, ), )); } + final bool hasUnattachedField = api.unattachedFields.isNotEmpty; + final bool hasRequiredFlutterMethod = + api.flutterMethods.any((Method method) => method.required); for (final AstProxyApi proxyApi in proxyApis) { // Validate this api is not used as an attached field while either: // 1. Having an unattached field. // 2. Having a required Flutter method. - final bool hasUnattachedField = api.unattachedFields.isNotEmpty; - final bool hasRequiredFlutterMethod = - api.flutterMethods.any((Method method) => method.required); if (hasUnattachedField || hasRequiredFlutterMethod) { for (final Field field in proxyApi.attachedFields) { if (field.type.baseName == api.name) { if (hasUnattachedField) { result.add(Error( message: - 'ProxyApis with fields can not be used as attached fields: ${field.name}', + 'ProxyApis with unattached fields can not be used as attached fields: ${field.name}', lineNumber: _calculateLineNumberNullable( source, field.offset, @@ -1032,7 +1032,7 @@ List _validateProxyApi( if (interfaceName == api.name) { result.add(Error( message: - 'ProxyApis used as interfaces can only have callback methods: ${proxyApi.name}', + 'ProxyApis used as interfaces can only have callback methods: `${proxyApi.name}` implements `${api.name}`', )); } } @@ -1139,28 +1139,27 @@ List _validateProxyApi( if (!isProxyApi(field)) { result.add(Error( message: - 'Static fields are considered attached fields and must be a ProxyApi: ${field.type.baseName}.', + 'Static fields are considered attached fields and must be a ProxyApi: ${field.type.baseName}', lineNumber: _calculateLineNumberNullable(source, field.offset), )); } else if (field.type.isNullable) { result.add(Error( message: - 'Static fields are considered attached fields and must not be nullable: ${field.type.baseName}.', + 'Static fields are considered attached fields and must not be nullable: ${field.type.baseName}?', lineNumber: _calculateLineNumberNullable(source, field.offset), )); } } else if (field.isAttached) { if (!isProxyApi(field)) { result.add(Error( - message: - 'Attached fields must be a ProxyApi: ${field.type.baseName}.', + message: 'Attached fields must be a ProxyApi: ${field.type.baseName}', lineNumber: _calculateLineNumberNullable(source, field.offset), )); } if (field.type.isNullable) { result.add(Error( message: - 'Attached fields must not be nullable: ${field.type.baseName}.', + 'Attached fields must not be nullable: ${field.type.baseName}?', lineNumber: _calculateLineNumberNullable(source, field.offset), )); } diff --git a/packages/pigeon/test/pigeon_lib_test.dart b/packages/pigeon/test/pigeon_lib_test.dart index 7998733664ab..54d9034ebdb7 100644 --- a/packages/pigeon/test/pigeon_lib_test.dart +++ b/packages/pigeon/test/pigeon_lib_test.dart @@ -8,6 +8,7 @@ import 'dart:io'; import 'package:pigeon/ast.dart'; import 'package:pigeon/generator_tools.dart'; import 'package:pigeon/pigeon_lib.dart'; +import 'package:test/expect.dart'; import 'package:test/test.dart'; class _ValidatorGeneratorAdapter implements GeneratorAdapter { @@ -1354,4 +1355,215 @@ abstract class Api { expect(results.errors[0].message, contains('FlutterApi method parameters must not be optional')); }); + + test('simple parse ProxyApi', () { + const String code = ''' +@ProxyApi() +abstract class MyClass { + MyClass(); + late String aField; + late void Function() aCallbackMethod; + void aMethod(); +} +'''; + final ParseResults parseResult = parseSource(code); + expect(parseResult.errors.length, equals(0)); + final Root root = parseResult.root; + expect(root.apis.length, equals(1)); + + final AstProxyApi proxyApi = root.apis.single as AstProxyApi; + expect(proxyApi.name, equals('MyClass')); + expect(proxyApi.constructors.single.name, equals('')); + expect(proxyApi.methods.length, equals(2)); + + for (final Method method in proxyApi.methods) { + if (method.location == ApiLocation.host) { + expect(method.name, equals('aMethod')); + } else if (method.location == ApiLocation.flutter) { + expect(method.name, equals('aCallbackMethod')); + } + } + }); + + group('ProxyApi validation', () { + test('error with using data class', () { + const String code = ''' +class DataClass { + late int input; +} + +@ProxyApi() +abstract class MyClass { + MyClass(DataClass input); +} +'''; + final ParseResults parseResult = parseSource(code); + expect(parseResult.errors.length, equals(1)); + expect( + parseResult.errors.single.message, + contains('ProxyApis do not support data classes'), + ); + }); + + test('super class must be proxy api', () { + const String code = ''' +class DataClass { + late int input; +} + +@ProxyApi() +abstract class MyClass extends DataClass { + void aMethod(); +} +'''; + final ParseResults parseResult = parseSource(code); + expect(parseResult.errors, isNotEmpty); + expect( + parseResult.errors[0].message, + contains('Super class of MyClass is not marked as a @ProxyApi'), + ); + }); + + test('interface must be proxy api', () { + const String code = ''' +class DataClass { + late int input; +} + +@ProxyApi() +abstract class MyClass implements DataClass { + void aMethod(); +} +'''; + final ParseResults parseResult = parseSource(code); + expect(parseResult.errors, isNotEmpty); + expect( + parseResult.errors[0].message, + contains('Interface of MyClass is not marked as a @ProxyApi'), + ); + }); + + test('unattached fields can not be inherited', () { + const String code = ''' +@ProxyApi() +abstract class MyClass extends MyOtherClass { } + +@ProxyApi() +abstract class MyOtherClass { + late int aField; +} +'''; + final ParseResults parseResult = parseSource(code); + expect(parseResult.errors, isNotEmpty); + expect( + parseResult.errors[0].message, + contains( + 'Unattached fields can not be inherited. Unattached field found for parent class: aField', + ), + ); + }); + + test( + 'api is not used as an attached field while having an unattached field', + () { + const String code = ''' +@ProxyApi() +abstract class MyClass { + @attached + late MyOtherClass anAttachedField; +} + +@ProxyApi() +abstract class MyOtherClass { + late int aField; +} +'''; + final ParseResults parseResult = parseSource(code); + expect(parseResult.errors, isNotEmpty); + expect( + parseResult.errors[0].message, + contains( + 'ProxyApis with unattached fields can not be used as attached fields: anAttachedField', + ), + ); + }); + + test( + 'api is not used as an attached field while having a required Flutter method', + () { + const String code = ''' +@ProxyApi() +abstract class MyClass { + @attached + late MyOtherClass anAttachedField; +} + +@ProxyApi() +abstract class MyOtherClass { + late void Function() aCallbackMethod; +} +'''; + final ParseResults parseResult = parseSource(code); + expect(parseResult.errors, isNotEmpty); + expect( + parseResult.errors[0].message, + contains( + 'ProxyApis with required callback methods can not be used as attached fields: anAttachedField', + ), + ); + }); + + test('interfaces can only have callback methods', () { + const String code = ''' +@ProxyApi() +abstract class MyClass implements MyOtherClass { +} + +@ProxyApi() +abstract class MyOtherClass { + MyOtherClass(); +} +'''; + final ParseResults parseResult = parseSource(code); + expect(parseResult.errors, isNotEmpty); + expect( + parseResult.errors[0].message, + contains( + 'ProxyApis used as interfaces can only have callback methods: `MyClass` implements `MyOtherClass`', + ), + ); + }); + + test('attached fields must be a ProxyApi', () { + const String code = ''' +@ProxyApi() +abstract class MyClass { + @attached + late int aField; +} +'''; + final ParseResults parseResult = parseSource(code); + expect(parseResult.errors, isNotEmpty); + expect( + parseResult.errors[0].message, + contains('Attached fields must be a ProxyApi: int'), + ); + }); + + test('attached fields must not be nullable', () { + const String code = ''' +@ProxyApi() +abstract class MyClass { + @attached + late MyClass? aField; +} +'''; + final ParseResults parseResult = parseSource(code); + expect(parseResult.errors, isNotEmpty); + expect( + parseResult.errors[0].message, + contains('Attached fields must not be nullable: MyClass?'), + ); + }); + }); } From 155469f6e6ee6bae60aa1ef6718836e1ae323115 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:23:59 -0500 Subject: [PATCH 05/32] change required to isRequired --- packages/pigeon/lib/ast.dart | 4 ++-- packages/pigeon/lib/pigeon_lib.dart | 4 ++-- packages/pigeon/test/cpp_generator_test.dart | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index db663f18bf38..cb1166a04c0d 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -30,7 +30,7 @@ class Method extends Node { required this.returnType, required this.parameters, required this.location, - this.required = true, + this.isRequired = true, this.isAsynchronous = false, this.isStatic = false, this.offset, @@ -78,7 +78,7 @@ class Method extends Node { /// /// This flag is typically used to determine whether a callback method for /// a `ProxyApi` is nullable or not. - bool required; + bool isRequired; /// Whether this is a static method of a ProxyApi. bool isStatic; diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 1e69a4818415..e58f0cb94bbf 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -990,7 +990,7 @@ List _validateProxyApi( final bool hasUnattachedField = api.unattachedFields.isNotEmpty; final bool hasRequiredFlutterMethod = - api.flutterMethods.any((Method method) => method.required); + api.flutterMethods.any((Method method) => method.isRequired); for (final AstProxyApi proxyApi in proxyApis) { // Validate this api is not used as an attached field while either: // 1. Having an unattached field. @@ -1881,7 +1881,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { isNullable: returnType.question != null, ), location: ApiLocation.flutter, - required: type.question == null, + isRequired: type.question == null, isStatic: isStatic, parameters: parameters, isAsynchronous: _hasMetadata(node.metadata, 'async'), diff --git a/packages/pigeon/test/cpp_generator_test.dart b/packages/pigeon/test/cpp_generator_test.dart index af7865815d3a..861ba5082b46 100644 --- a/packages/pigeon/test/cpp_generator_test.dart +++ b/packages/pigeon/test/cpp_generator_test.dart @@ -37,7 +37,7 @@ void main() { ), name: 'input') ], - required: true, + isRequired: true, location: ApiLocation.host, returnType: TypeDeclaration( baseName: 'Output', From 3a45694ab9b1458c10357946e033623a1a77e4d9 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:37:51 -0500 Subject: [PATCH 06/32] improve docs --- packages/pigeon/lib/cpp_generator.dart | 3 +-- packages/pigeon/lib/pigeon_lib.dart | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index 2ec8ccd00833..419695b4ed2b 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -175,7 +175,7 @@ class CppHeaderGenerator extends StructuredGenerator { indent, anEnum.documentationComments, _docCommentSpec); indent.write('enum class ${anEnum.name} '); indent.addScoped('{', '};', () { - enumerate(anEnum.members, (int index, EnumMember member) { + enumerate(anEnum.members, (int index, final EnumMember member) { addDocumentationComments( indent, member.documentationComments, _docCommentSpec); indent.writeln( @@ -784,7 +784,6 @@ class CppSourceGenerator extends StructuredGenerator { final Iterable<_IndexedField> indexedFields = indexMap( getFieldsInSerializationOrder(classDefinition), (int index, NamedType field) => _IndexedField(index, field)); - final Iterable<_IndexedField> nullableFields = indexedFields .where((_IndexedField field) => field.field.type.isNullable); final Iterable<_IndexedField> nonNullableFields = indexedFields diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index e58f0cb94bbf..5de9cdb5492f 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -52,14 +52,14 @@ const Object async = _Asynchronous(); /// Metadata to annotate the field of a ProxyApi as an Attached Field. /// -/// Attached fields provide a synchronous [AstProxyApi] instance as a field -/// for another [AstProxyApi]. +/// Attached fields provide a synchronous [ProxyApi] instance as a field for +/// another [ProxyApi]. /// /// Attached fields: /// * Must be nonnull. -/// * Must be a ProxyApi type. -/// * Must be a ProxyApi that contains any fields. -/// * Must be a ProxyApi that does not have a required Flutter method. +/// * Must be a ProxyApi (a class annotated with `@ProxyApi()`). +/// * Must not contain any unattached fields. +/// * Must not have a required callback Flutter method. /// /// Example generated code: /// @@ -74,7 +74,10 @@ const Object async = _Asynchronous(); /// to how constructors are implemented. const Object attached = _Attached(); -/// Metadata to annotate an method or an Attached Field of a ProxyApi as static. +/// Metadata to annotate a field of a ProxyApi as static. +/// +/// Static fields are the same as [attached] fields except the field is static +/// and not attached to any instance of the ProxyApi. const Object static = _Static(); /// Metadata annotation used to configure how Pigeon will generate code. @@ -129,10 +132,10 @@ class FlutterApi { /// constructors, fields, methods and host↔Dart methods used to wrap a native /// class. /// -/// The generated Dart class acts as a proxy to a native type and -/// maintains instances automatically with an `InstanceManager`. The generated -/// host language class implements methods to interact with class instances -/// or static methods. +/// The generated Dart class acts as a proxy to a native type and maintains +/// instances automatically with an `InstanceManager`. The generated host +/// language class implements methods to interact with class instances or static +/// methods. class ProxyApi { /// Parametric constructor for [ProxyApi]. const ProxyApi({this.superClass}); From 635035349ae25edc321b74a11e247caaa2ffc6db Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 12 Jan 2024 12:46:21 -0500 Subject: [PATCH 07/32] fix lint errors and hide ProxyApi --- packages/pigeon/lib/pigeon.dart | 2 +- packages/pigeon/test/cpp_generator_test.dart | 1 - packages/pigeon/test/pigeon_lib_test.dart | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/pigeon/lib/pigeon.dart b/packages/pigeon/lib/pigeon.dart index 7f2fb7505fa8..e92619076c0b 100644 --- a/packages/pigeon/lib/pigeon.dart +++ b/packages/pigeon/lib/pigeon.dart @@ -9,5 +9,5 @@ export 'dart_generator.dart' show DartOptions; export 'java_generator.dart' show JavaOptions; export 'kotlin_generator.dart' show KotlinOptions; export 'objc_generator.dart' show ObjcOptions; -export 'pigeon_lib.dart'; +export 'pigeon_lib.dart' hide ProxyApi; export 'swift_generator.dart' show SwiftOptions; diff --git a/packages/pigeon/test/cpp_generator_test.dart b/packages/pigeon/test/cpp_generator_test.dart index 861ba5082b46..42aa28c5361a 100644 --- a/packages/pigeon/test/cpp_generator_test.dart +++ b/packages/pigeon/test/cpp_generator_test.dart @@ -37,7 +37,6 @@ void main() { ), name: 'input') ], - isRequired: true, location: ApiLocation.host, returnType: TypeDeclaration( baseName: 'Output', diff --git a/packages/pigeon/test/pigeon_lib_test.dart b/packages/pigeon/test/pigeon_lib_test.dart index 54d9034ebdb7..34516e8c0dea 100644 --- a/packages/pigeon/test/pigeon_lib_test.dart +++ b/packages/pigeon/test/pigeon_lib_test.dart @@ -8,7 +8,6 @@ import 'dart:io'; import 'package:pigeon/ast.dart'; import 'package:pigeon/generator_tools.dart'; import 'package:pigeon/pigeon_lib.dart'; -import 'package:test/expect.dart'; import 'package:test/test.dart'; class _ValidatorGeneratorAdapter implements GeneratorAdapter { From 4ce1e2146c73b257b7a4bfae0c230cfbfe6167da Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 12 Jan 2024 12:49:33 -0500 Subject: [PATCH 08/32] add hide comment --- packages/pigeon/lib/pigeon.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/pigeon/lib/pigeon.dart b/packages/pigeon/lib/pigeon.dart index e92619076c0b..a2c6026e3117 100644 --- a/packages/pigeon/lib/pigeon.dart +++ b/packages/pigeon/lib/pigeon.dart @@ -9,5 +9,7 @@ export 'dart_generator.dart' show DartOptions; export 'java_generator.dart' show JavaOptions; export 'kotlin_generator.dart' show KotlinOptions; export 'objc_generator.dart' show ObjcOptions; +// TODO(bparrishMines): Remove hide once implementation of the api is finished +// for Dart and one host language. export 'pigeon_lib.dart' hide ProxyApi; export 'swift_generator.dart' show SwiftOptions; From 22c30651d56303d3cddbb6270567051c8623b10f Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 12 Jan 2024 12:53:51 -0500 Subject: [PATCH 09/32] test for recursive looks --- .../pigeon/test/generator_tools_test.dart | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/packages/pigeon/test/generator_tools_test.dart b/packages/pigeon/test/generator_tools_test.dart index 8264496d3343..c747eeda30b6 100644 --- a/packages/pigeon/test/generator_tools_test.dart +++ b/packages/pigeon/test/generator_tools_test.dart @@ -373,4 +373,97 @@ void main() { expect(dartPackageName, 'pigeon'); }); + + test('recursiveGetSuperClassApisChain', () { + final AstProxyApi api = AstProxyApi( + name: 'Api', + methods: [], + constructors: [], + fields: [], + superClassName: 'Api2', + ); + final AstProxyApi superClassApi = AstProxyApi( + name: 'Api2', + methods: [], + constructors: [], + fields: [], + superClassName: 'Api3', + ); + final AstProxyApi superClassOfSuperClassApi = AstProxyApi( + name: 'Api3', + methods: [], + constructors: [], + fields: [], + ); + + final List apiChain = recursiveGetSuperClassApisChain( + api, + [superClassOfSuperClassApi, api, superClassApi], + ); + + expect( + apiChain, + containsAllInOrder([ + superClassApi, + superClassOfSuperClassApi, + ]), + ); + }); + + test('recursiveFindAllInterfacesApis', () { + final AstProxyApi api = AstProxyApi( + name: 'Api', + methods: [], + constructors: [], + fields: [], + interfacesNames: {'Api2', 'Api3'}, + ); + final AstProxyApi interfaceApi = AstProxyApi( + name: 'Api2', + methods: [], + constructors: [], + fields: [], + interfacesNames: {'Api4', 'Api5'}, + ); + final AstProxyApi interfaceApi2 = AstProxyApi( + name: 'Api3', + methods: [], + constructors: [], + fields: [], + interfacesNames: {'Api5'}, + ); + final AstProxyApi interfaceOfInterfaceApi = AstProxyApi( + name: 'Api4', + methods: [], + constructors: [], + fields: [], + ); + final AstProxyApi interfaceOfInterfaceApi2 = AstProxyApi( + name: 'Api5', + methods: [], + constructors: [], + fields: [], + ); + + final Set allInterfaces = recursiveFindAllInterfacesApis( + api, + [ + api, + interfaceApi, + interfaceApi2, + interfaceOfInterfaceApi, + interfaceOfInterfaceApi2, + ], + ); + + expect( + allInterfaces, + containsAll([ + interfaceApi, + interfaceApi2, + interfaceOfInterfaceApi, + interfaceOfInterfaceApi2, + ]), + ); + }); } From a14485edce2ce114de73cc79ebffb2e7e5e47b9d Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 12 Jan 2024 13:06:15 -0500 Subject: [PATCH 10/32] fix tools version --- packages/pigeon/lib/generator_tools.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 7fa2f967cf9a..43d26c388b44 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -13,7 +13,7 @@ import 'ast.dart'; /// The current version of pigeon. /// /// This must match the version in pubspec.yaml. -const String pigeonVersion = '16.0.0'; +const String pigeonVersion = '16.0.1'; /// Read all the content from [stdin] to a String. String readStdin() { From 360dd7a2073dd5aa598728cf6985c3d37de2a2e9 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 23 Jan 2024 18:23:05 -0500 Subject: [PATCH 11/32] review comments --- packages/pigeon/lib/ast.dart | 36 +++++++++++-------- packages/pigeon/lib/generator_tools.dart | 2 +- packages/pigeon/lib/pigeon_lib.dart | 26 +++++++------- .../pigeon/test/generator_tools_test.dart | 16 ++++----- 4 files changed, 44 insertions(+), 36 deletions(-) diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index cb1166a04c0d..51bcd215cccf 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -145,7 +145,7 @@ class AstProxyApi extends Api { final List constructors; /// List of fields inside the API. - List fields; + List fields; /// Name of the class this class considers the super class. final String? superClassName; @@ -166,20 +166,22 @@ class AstProxyApi extends Api { /// All fields that are attached. /// /// See [attached]. - Iterable get attachedFields => fields.where( - (Field field) => field.isAttached, + Iterable get attachedFields => fields.where( + (ApiField field) => field.isAttached, ); /// All fields that are not attached. /// /// See [attached]. - Iterable get unattachedFields => fields.where( - (Field field) => !field.isAttached, + Iterable get unattachedFields => fields.where( + (ApiField field) => !field.isAttached, ); @override String toString() { - return '(ProxyApi name:$name methods:$methods documentationComments:$documentationComments superClassName:$superClassName interfacesNames:$interfacesNames)'; + return '(ProxyApi name:$name methods:$methods field:$fields ' + 'documentationComments:$documentationComments ' + 'superClassName:$superClassName interfacesNames:$interfacesNames)'; } } @@ -206,9 +208,9 @@ class Constructor extends Method { } /// Represents a field of an API. -class Field extends NamedType { - /// Constructor for [Field]. - Field({ +class ApiField extends NamedType { + /// Constructor for [ApiField]. + ApiField({ required super.name, required super.type, super.offset, @@ -229,8 +231,8 @@ class Field extends NamedType { /// Returns a copy of [Parameter] instance with new attached [TypeDeclaration]. @override - Field copyWithType(TypeDeclaration type) { - return Field( + ApiField copyWithType(TypeDeclaration type) { + return ApiField( name: name, type: type, offset: offset, @@ -239,6 +241,12 @@ class Field extends NamedType { isStatic: isStatic, ); } + + @override + String toString() { + return '(Field name:$name type:$type isAttached:$isAttached ' + 'isStatic:$isStatic documentationComments:$documentationComments)'; + } } /// Represents a collection of [Method]s. @@ -315,12 +323,12 @@ class TypeDeclaration { /// Associated [Class], if any. final Class? associatedClass; - /// Associated [AstProxyApi], if any. - final AstProxyApi? associatedProxyApi; - /// Whether the [TypeDeclaration] has an [associatedProxyApi]. bool get isProxyApi => associatedProxyApi != null; + /// Associated [AstProxyApi], if any. + final AstProxyApi? associatedProxyApi; + @override int get hashCode { // This has to be implemented because TypeDeclaration is used as a Key to a diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 43d26c388b44..65f07b342450 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -446,7 +446,7 @@ Map> getReferencedTypes( ); } } - for (final Field field in api.fields) { + for (final ApiField field in api.fields) { references.addMany(_getTypeArguments(field.type), field.offset); } } diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 5de9cdb5492f..7b60e526b2f4 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -999,7 +999,7 @@ List _validateProxyApi( // 1. Having an unattached field. // 2. Having a required Flutter method. if (hasUnattachedField || hasRequiredFlutterMethod) { - for (final Field field in proxyApi.attachedFields) { + for (final ApiField field in proxyApi.attachedFields) { if (field.type.baseName == api.name) { if (hasUnattachedField) { result.add(Error( @@ -1049,7 +1049,7 @@ List _validateProxyApi( result.add(unsupportedDataClassError(parameter)); } - if (api.fields.any((Field field) => field.name == parameter.name) || + if (api.fields.any((ApiField field) => field.name == parameter.name) || api.flutterMethods .any((Method method) => method.name == parameter.name)) { result.add(Error( @@ -1135,7 +1135,7 @@ List _validateProxyApi( } // Validate fields - for (final Field field in api.fields) { + for (final ApiField field in api.fields) { if (isDataClass(field)) { result.add(unsupportedDataClassError(field)); } else if (field.isStatic) { @@ -1287,7 +1287,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { final List fields = []; for (final NamedType field in classDefinition.fields) { fields.add(field.copyWithType( - _attachClassesEnumsAndProxyApis(field.type), + _attachAssociatedDefinition(field.type), )); } classDefinition.fields = fields; @@ -1298,27 +1298,27 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { final List paramList = []; for (final Parameter param in func.parameters) { paramList.add(param.copyWithType( - _attachClassesEnumsAndProxyApis(param.type), + _attachAssociatedDefinition(param.type), )); } func.parameters = paramList; - func.returnType = _attachClassesEnumsAndProxyApis(func.returnType); + func.returnType = _attachAssociatedDefinition(func.returnType); } if (api is AstProxyApi) { for (final Constructor constructor in api.constructors) { final List paramList = []; for (final Parameter param in constructor.parameters) { paramList.add( - param.copyWithType(_attachClassesEnumsAndProxyApis(param.type)), + param.copyWithType(_attachAssociatedDefinition(param.type)), ); } constructor.parameters = paramList; } - final List fieldList = []; - for (final Field field in api.fields) { + final List fieldList = []; + for (final ApiField field in api.fields) { fieldList.add(field.copyWithType( - _attachClassesEnumsAndProxyApis(field.type), + _attachAssociatedDefinition(field.type), )); } api.fields = fieldList; @@ -1334,7 +1334,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { ); } - TypeDeclaration _attachClassesEnumsAndProxyApis(TypeDeclaration type) { + TypeDeclaration _attachAssociatedDefinition(TypeDeclaration type) { final Enum? assocEnum = _enums.firstWhereOrNull( (Enum enumDefinition) => enumDefinition.name == type.baseName); final Class? assocClass = _classes.firstWhereOrNull( @@ -1512,7 +1512,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { name: node.name.lexeme, methods: [], constructors: [], - fields: [], + fields: [], superClassName: superClassName ?? node.extendsClause?.superclass.name2.lexeme, interfacesNames: node.implementsClause?.interfaces @@ -1906,7 +1906,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { } else { final dart_ast.TypeArgumentList? typeArguments = type.typeArguments; (_currentApi as AstProxyApi?)!.fields.add( - Field( + ApiField( type: TypeDeclaration( baseName: _getNamedTypeQualifiedName(type), isNullable: type.question != null, diff --git a/packages/pigeon/test/generator_tools_test.dart b/packages/pigeon/test/generator_tools_test.dart index c747eeda30b6..bec70e52c5ad 100644 --- a/packages/pigeon/test/generator_tools_test.dart +++ b/packages/pigeon/test/generator_tools_test.dart @@ -379,21 +379,21 @@ void main() { name: 'Api', methods: [], constructors: [], - fields: [], + fields: [], superClassName: 'Api2', ); final AstProxyApi superClassApi = AstProxyApi( name: 'Api2', methods: [], constructors: [], - fields: [], + fields: [], superClassName: 'Api3', ); final AstProxyApi superClassOfSuperClassApi = AstProxyApi( name: 'Api3', methods: [], constructors: [], - fields: [], + fields: [], ); final List apiChain = recursiveGetSuperClassApisChain( @@ -415,34 +415,34 @@ void main() { name: 'Api', methods: [], constructors: [], - fields: [], + fields: [], interfacesNames: {'Api2', 'Api3'}, ); final AstProxyApi interfaceApi = AstProxyApi( name: 'Api2', methods: [], constructors: [], - fields: [], + fields: [], interfacesNames: {'Api4', 'Api5'}, ); final AstProxyApi interfaceApi2 = AstProxyApi( name: 'Api3', methods: [], constructors: [], - fields: [], + fields: [], interfacesNames: {'Api5'}, ); final AstProxyApi interfaceOfInterfaceApi = AstProxyApi( name: 'Api4', methods: [], constructors: [], - fields: [], + fields: [], ); final AstProxyApi interfaceOfInterfaceApi2 = AstProxyApi( name: 'Api5', methods: [], constructors: [], - fields: [], + fields: [], ); final Set allInterfaces = recursiveFindAllInterfacesApis( From ea9f7c3c1f8771382403ebc4d205e453f9406918 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 24 Jan 2024 13:41:28 -0500 Subject: [PATCH 12/32] switch to a method that looks for matching prefix --- packages/pigeon/lib/pigeon_lib.dart | 126 ++++++++++++++-------------- 1 file changed, 62 insertions(+), 64 deletions(-) diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 7b60e526b2f4..fc890be6d27f 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -867,18 +867,18 @@ List _validateAst(Root root, String source) { 'Parameters must specify their type in method "${method.name}" in API: "${api.name}"', lineNumber: _calculateLineNumberNullable(source, param.offset), )); - } else if (param.name.startsWith('__pigeon_')) { - result.add(Error( - message: - 'Parameter name must not begin with "__pigeon_" in method "${method.name}" in API: "${api.name}"', - lineNumber: _calculateLineNumberNullable(source, param.offset), - )); - } else if (param.name == 'pigeonChannelCodec') { - result.add(Error( - message: - 'Parameter name must not be "pigeonChannelCodec" in method "${method.name}" in API: "${api.name}"', - lineNumber: _calculateLineNumberNullable(source, param.offset), - )); + } else { + final String? matchingPrefix = _findMatchingPrefixOrNull( + method.name, + prefixes: ['__pigeon_', 'pigeonChannelCodec'], + ); + if (matchingPrefix != null) { + result.add(Error( + message: + 'Parameter name must not begin with "$matchingPrefix" in method "${method.name} in API: "${api.name}"', + lineNumber: _calculateLineNumberNullable(source, param.offset), + )); + } } if (api is AstFlutterApi) { if (!param.isPositional) { @@ -1065,30 +1065,23 @@ List _validateProxyApi( 'Parameters must specify their type in constructor "${constructor.name}" in API: "${api.name}"', lineNumber: _calculateLineNumberNullable(source, parameter.offset), )); - } else if (parameter.name.startsWith('__pigeon_')) { - result.add(Error( - message: - 'Parameter name must not begin with "__pigeon_" in constructor "${constructor.name}" in API: "${api.name}"', - lineNumber: _calculateLineNumberNullable(source, parameter.offset), - )); - } else if (parameter.name == 'pigeonChannelCodec') { - result.add(Error( - message: - 'Parameter name must not be "pigeonChannelCodec" in constructor "${constructor.name}" in API: "${api.name}"', - lineNumber: _calculateLineNumberNullable(source, parameter.offset), - )); - } else if (parameter.name.startsWith(classNamePrefix)) { - result.add(Error( - message: - 'Parameter name must not begin with "$classNamePrefix" in constructor "${constructor.name}" in API: "${api.name}"', - lineNumber: _calculateLineNumberNullable(source, parameter.offset), - )); - } else if (parameter.name.startsWith(classMemberNamePrefix)) { - result.add(Error( - message: - 'Parameter name must not begin with "$classMemberNamePrefix" in constructor "${constructor.name}" in API: "${api.name}"', - lineNumber: _calculateLineNumberNullable(source, parameter.offset), - )); + } else { + final String? matchingPrefix = _findMatchingPrefixOrNull( + parameter.name, + prefixes: [ + '__pigeon_', + 'pigeonChannelCodec', + classNamePrefix, + classMemberNamePrefix, + ], + ); + if (matchingPrefix != null) { + result.add(Error( + message: + 'Parameter name must not begin with "$matchingPrefix" in constructor "${constructor.name} in API: "${api.name}"', + lineNumber: _calculateLineNumberNullable(source, parameter.offset), + )); + } } } if (constructor.swiftFunction.isNotEmpty) { @@ -1111,16 +1104,17 @@ List _validateProxyApi( result.add(unsupportedDataClassError(parameter)); } - if (parameter.name.startsWith(classNamePrefix)) { - result.add(Error( - message: - 'Parameter name must not begin with "$classNamePrefix" in method "${method.name}" in API: "${api.name}"', - lineNumber: _calculateLineNumberNullable(source, parameter.offset), - )); - } else if (parameter.name.startsWith(classMemberNamePrefix)) { + final String? matchingPrefix = _findMatchingPrefixOrNull( + parameter.name, + prefixes: [ + classNamePrefix, + classMemberNamePrefix, + ], + ); + if (matchingPrefix != null) { result.add(Error( message: - 'Parameter name must not begin with "$classMemberNamePrefix" in method "${method.name}" in API: "${api.name}"', + 'Parameter name must not begin with "$matchingPrefix" in method "${method.name} in API: "${api.name}"', lineNumber: _calculateLineNumberNullable(source, parameter.offset), )); } @@ -1168,28 +1162,19 @@ List _validateProxyApi( } } - if (field.name.startsWith('__pigeon_')) { - result.add(Error( - message: - 'Field name must not begin with "__pigeon_" in API: "${api.name}"', - lineNumber: _calculateLineNumberNullable(source, field.offset), - )); - } else if (field.name == 'pigeonChannelCodec') { - result.add(Error( - message: - 'Field name must not be "pigeonChannelCodec" in API: "${api.name}"', - lineNumber: _calculateLineNumberNullable(source, field.offset), - )); - } else if (field.name.startsWith(classNamePrefix)) { - result.add(Error( - message: - 'Field name must not begin with "$classNamePrefix" in API: "${api.name}"', - lineNumber: _calculateLineNumberNullable(source, field.offset), - )); - } else if (field.name.startsWith(classMemberNamePrefix)) { + final String? matchingPrefix = _findMatchingPrefixOrNull( + field.name, + prefixes: [ + '__pigeon_', + 'pigeonChannelCodec', + classNamePrefix, + classMemberNamePrefix, + ], + ); + if (matchingPrefix != null) { result.add(Error( message: - 'Field name must not begin with "$classMemberNamePrefix" in API: "${api.name}"', + 'Field name must not begin with "$matchingPrefix" in API: "${api.name}"', lineNumber: _calculateLineNumberNullable(source, field.offset), )); } @@ -1198,6 +1183,19 @@ List _validateProxyApi( return result; } +String? _findMatchingPrefixOrNull( + String value, { + required List prefixes, +}) { + for (final String prefix in prefixes) { + if (value.startsWith(prefix)) { + return prefix; + } + } + + return null; +} + class _FindInitializer extends dart_ast_visitor.RecursiveAstVisitor { dart_ast.Expression? initializer; @override From 33b2e07f91e131c3d625521d1839defff2901e1f Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 24 Jan 2024 14:10:20 -0500 Subject: [PATCH 13/32] avoid loops --- packages/pigeon/lib/generator_tools.dart | 11 +++++-- .../pigeon/test/generator_tools_test.dart | 31 +++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 65f07b342450..be1a8bd6d92a 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -623,7 +623,8 @@ String? deducePackageName(String mainDartFile) { /// interfaces. /// /// This method assumes that all interfaces names can be found in -/// [allProxyApis]. Otherwise, throws an [ArgumentError]. +/// [allProxyApis] and an api doesn't contains itself as an interface. +/// Otherwise, throws an [ArgumentError]. Set recursiveFindAllInterfacesApis( AstProxyApi api, Iterable allProxyApis, @@ -638,14 +639,18 @@ Set recursiveFindAllInterfacesApis( if (interfacesApis.length != api.interfacesNames.length) { throw ArgumentError( - 'Could not find a ProxyApi for every interface name: ' + 'Could not find a valid ProxyApi for every interface name: ' '${api.interfacesNames}, ${allProxyApis.map((Api api) => api.name)}', ); } + // This removes the current api since it would be invalid for it to be a + // super class of itself. + final Set allProxyApisWithoutCurrent = + Set.from(allProxyApis)..remove(api); for (final AstProxyApi proxyApi in Set.from(interfacesApis)) { interfacesApis.addAll( - recursiveFindAllInterfacesApis(proxyApi, allProxyApis), + recursiveFindAllInterfacesApis(proxyApi, allProxyApisWithoutCurrent), ); } diff --git a/packages/pigeon/test/generator_tools_test.dart b/packages/pigeon/test/generator_tools_test.dart index bec70e52c5ad..344a98cd79f4 100644 --- a/packages/pigeon/test/generator_tools_test.dart +++ b/packages/pigeon/test/generator_tools_test.dart @@ -466,4 +466,35 @@ void main() { ]), ); }); + + test( + 'recursiveFindAllInterfacesApis throws error if api recursively implements itself', + () { + final AstProxyApi a = AstProxyApi( + name: 'A', + methods: [], + constructors: [], + fields: [], + interfacesNames: {'B'}, + ); + final AstProxyApi b = AstProxyApi( + name: 'B', + methods: [], + constructors: [], + fields: [], + interfacesNames: {'C'}, + ); + final AstProxyApi c = AstProxyApi( + name: 'C', + methods: [], + constructors: [], + fields: [], + interfacesNames: {'A'}, + ); + + expect( + () => recursiveFindAllInterfacesApis(a, [a, b, c]), + throwsArgumentError, + ); + }); } From c8db9c8bf0218f14a0d4e188fee9233b70873ec9 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 24 Jan 2024 14:15:31 -0500 Subject: [PATCH 14/32] fix test --- packages/pigeon/test/dart_generator_test.dart | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/pigeon/test/dart_generator_test.dart b/packages/pigeon/test/dart_generator_test.dart index 63ca9c2a4a3b..4c96bd7d74af 100644 --- a/packages/pigeon/test/dart_generator_test.dart +++ b/packages/pigeon/test/dart_generator_test.dart @@ -1778,15 +1778,16 @@ name: foobar test('generate wrapResponse if is generating tests', () { final Root root = Root( apis: [ - Api( + AstHostApi( name: 'Api', - location: ApiLocation.host, dartHostTestHandler: 'ApiMock', methods: [ Method( - name: 'foo', - returnType: const TypeDeclaration.voidDeclaration(), - parameters: []) + name: 'foo', + location: ApiLocation.host, + returnType: const TypeDeclaration.voidDeclaration(), + parameters: [], + ) ]) ], classes: [], From b414381729ebc16d50a063f668051e1010821121 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 25 Jan 2024 16:33:21 -0500 Subject: [PATCH 15/32] change superClass and interfaces to TypeDeclarations --- packages/pigeon/lib/ast.dart | 11 +- packages/pigeon/lib/generator_tools.dart | 109 +++++++------- packages/pigeon/lib/pigeon_lib.dart | 139 ++++++++++-------- packages/pigeon/pubspec.yaml | 2 +- .../pigeon/test/generator_tools_test.dart | 101 ++++++++----- 5 files changed, 208 insertions(+), 154 deletions(-) diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index 51bcd215cccf..0c48faa45456 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -137,8 +137,8 @@ class AstProxyApi extends Api { super.documentationComments = const [], required this.constructors, required this.fields, - this.superClassName, - this.interfacesNames = const {}, + this.superClass, + this.interfaces = const {}, }); /// List of constructors inside the API. @@ -148,10 +148,10 @@ class AstProxyApi extends Api { List fields; /// Name of the class this class considers the super class. - final String? superClassName; + TypeDeclaration? superClass; /// Name of the classes this class considers to be implemented. - final Set interfacesNames; + Set interfaces; /// Methods implemented in the host platform language. Iterable get hostMethods => methods.where( @@ -181,7 +181,7 @@ class AstProxyApi extends Api { String toString() { return '(ProxyApi name:$name methods:$methods field:$fields ' 'documentationComments:$documentationComments ' - 'superClassName:$superClassName interfacesNames:$interfacesNames)'; + 'superClassName:$superClass interfacesNames:$interfaces)'; } } @@ -428,6 +428,7 @@ class NamedType extends Node { final List documentationComments; /// Returns a copy of [NamedType] instance with new attached [TypeDeclaration]. + @mustBeOverridden NamedType copyWithType(TypeDeclaration type) { return NamedType( name: name, diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 6f478dc39888..b9aec2b27994 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -622,39 +622,43 @@ String? deducePackageName(String mainDartFile) { /// Recursively search for all the interfaces apis from a list of names of /// interfaces. /// -/// This method assumes that all interfaces names can be found in -/// [allProxyApis] and an api doesn't contains itself as an interface. -/// Otherwise, throws an [ArgumentError]. -Set recursiveFindAllInterfacesApis( - AstProxyApi api, - Iterable allProxyApis, -) { - final Set interfacesApis = {}; - - for (final AstProxyApi proxyApi in allProxyApis) { - if (api.interfacesNames.contains(proxyApi.name)) { - interfacesApis.add(proxyApi); - } - } +/// This method assumes that all interfaces are ProxyApis and an api doesn't +/// contains itself as an interface. Otherwise, throws an [ArgumentError]. +Set recursiveFindAllInterfaceApis( + AstProxyApi api, { + Set seenApis = const {}, +}) { + final Set allInterfaces = {}; + + allInterfaces.addAll( + api.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!; + }, + ), + ); - if (interfacesApis.length != api.interfacesNames.length) { - throw ArgumentError( - 'Could not find a valid ProxyApi for every interface name: ' - '${api.interfacesNames}, ${allProxyApis.map((Api api) => api.name)}', - ); - } + // Adds the current api since it would be invalid for it to be an interface + // of itself. + final Set newSeenApis = {...seenApis, api}; - // This removes the current api since it would be invalid for it to be a - // super class of itself. - final Set allProxyApisWithoutCurrent = - Set.from(allProxyApis)..remove(api); - for (final AstProxyApi proxyApi in Set.from(interfacesApis)) { - interfacesApis.addAll( - recursiveFindAllInterfacesApis(proxyApi, allProxyApisWithoutCurrent), - ); + for (final AstProxyApi interfaceApi in {...allInterfaces}) { + allInterfaces.addAll(recursiveFindAllInterfaceApis( + interfaceApi, + seenApis: newSeenApis, + )); } - return interfacesApis; + return allInterfaces; } /// Creates a list of ProxyApis where each `extends` the ProxyApi that follows @@ -665,45 +669,40 @@ Set recursiveFindAllInterfacesApis( /// 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 class names can be found in -/// [allProxyApis]. Otherwise, throws an [ArgumentError]. -List recursiveGetSuperClassApisChain( - AstProxyApi proxyApi, - Iterable allProxyApis, -) { - final List proxyApis = []; +/// This method also assumes that all super classes are ProxyApis. Otherwise, +/// throws an [ArgumentError]. +List recursiveGetSuperClassApisChain(AstProxyApi api) { + final List superClassChain = []; - String? currentProxyApiName = proxyApi.superClassName; - while (currentProxyApiName != null) { - if (proxyApis.length > allProxyApis.length) { - final Iterable apiNames = proxyApis.map( - (AstProxyApi api) => api.name, - ); + if (api.superClass != null && !api.superClass!.isProxyApi) { + throw ArgumentError( + 'Could not find a ProxyApi for super class: ${api.superClass!.baseName}', + ); + } + + AstProxyApi? currentProxyApi = api.superClass?.associatedProxyApi; + while (currentProxyApi != null) { + if (superClassChain.contains(currentProxyApi)) { throw ArgumentError( 'Loop found when processing super classes for a ProxyApi: ' - '${proxyApi.name},${apiNames.join(',')}', + '${api.name}, ${superClassChain.map((AstProxyApi api) => api.name)}', ); } - AstProxyApi? nextProxyApi; - for (final AstProxyApi node in allProxyApis) { - if (currentProxyApiName == node.name) { - nextProxyApi = node; - proxyApis.add(node); - } - } + superClassChain.add(currentProxyApi); - if (nextProxyApi == null) { + if (currentProxyApi.superClass != null && + !currentProxyApi.superClass!.isProxyApi) { throw ArgumentError( - 'Could not find a ProxyApi for every super class name: ' - '$currentProxyApiName, ${allProxyApis.map((Api api) => api.name)}', + 'Could not find a ProxyApi for super class: ' + '${currentProxyApi.superClass!.baseName}', ); } - currentProxyApiName = nextProxyApi.superClassName; + currentProxyApi = currentProxyApi.superClass?.associatedProxyApi; } - return proxyApis; + return superClassChain; } /// Enum to specify api type when generating code. diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index d5193f223ac1..187aa3466b2a 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -951,35 +951,24 @@ List _validateProxyApi( ); } - // Validate super class is another ProxyApi - final String? superClassName = api.superClassName; - if (api.superClassName != null && - !proxyApis.any((AstProxyApi api) => api.name == superClassName)) { - result.add(Error( - message: - 'Super class of ${api.name} is not marked as a @ProxyApi: $superClassName', - )); - } + AstProxyApi? directSuperClass; - // Validate all interfaces are other ProxyApis - for (final String interfaceName in api.interfacesNames) { - if (!proxyApis.any((AstProxyApi api) => api.name == interfaceName)) { - result.add(Error( - message: - 'Interface of ${api.name} is not marked as a @ProxyApi: $interfaceName', - )); + // Validate direct super class is another ProxyApi + if (api.superClass != null) { + directSuperClass = proxyApis.firstWhereOrNull( + (AstProxyApi proxyApi) => proxyApi.name == api.superClass?.baseName, + ); + if (directSuperClass == null) { + result.add( + Error( + message: 'Super class of ${api.name} is not marked as a @ProxyApi: ' + '${api.superClass?.baseName}', + ), + ); } } - List? superClassChain; - try { - superClassChain = recursiveGetSuperClassApisChain(api, proxyApis); - } catch (error) { - result.add(Error(message: error.toString())); - } - // Validate that the api does not inherit an unattached field from its super class. - final AstProxyApi? directSuperClass = superClassChain?.firstOrNull; if (directSuperClass != null && directSuperClass.unattachedFields.isNotEmpty) { result.add(Error( @@ -992,6 +981,19 @@ List _validateProxyApi( )); } + // Validate all interfaces are other ProxyApis + final Iterable interfaceNames = api.interfaces.map( + (TypeDeclaration type) => type.baseName, + ); + for (final String interfaceName in interfaceNames) { + if (!proxyApis.any((AstProxyApi api) => api.name == interfaceName)) { + result.add(Error( + message: + 'Interface of ${api.name} is not marked as a @ProxyApi: $interfaceName', + )); + } + } + final bool hasUnattachedField = api.unattachedFields.isNotEmpty; final bool hasRequiredFlutterMethod = api.flutterMethods.any((Method method) => method.isRequired); @@ -1032,7 +1034,10 @@ List _validateProxyApi( api.constructors.isEmpty && api.fields.isEmpty; if (!isValidInterfaceProxyApi) { - for (final String interfaceName in proxyApi.interfacesNames) { + final Iterable interfaceNames = proxyApi.interfaces.map( + (TypeDeclaration type) => type.baseName, + ); + for (final String interfaceName in interfaceNames) { if (interfaceName == api.name) { result.add(Error( message: @@ -1283,44 +1288,34 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { } } for (final Class classDefinition in referencedClasses) { - final List fields = []; - for (final NamedType field in classDefinition.fields) { - fields.add(field.copyWithType( - _attachAssociatedDefinition(field.type), - )); - } - classDefinition.fields = fields; + classDefinition.fields = _attachAssociatedDefinitions( + classDefinition.fields, + ); } for (final Api api in _apis) { for (final Method func in api.methods) { - final List paramList = []; - for (final Parameter param in func.parameters) { - paramList.add(param.copyWithType( - _attachAssociatedDefinition(param.type), - )); - } - func.parameters = paramList; + func.parameters = _attachAssociatedDefinitions(func.parameters); func.returnType = _attachAssociatedDefinition(func.returnType); } if (api is AstProxyApi) { for (final Constructor constructor in api.constructors) { - final List paramList = []; - for (final Parameter param in constructor.parameters) { - paramList.add( - param.copyWithType(_attachAssociatedDefinition(param.type)), - ); - } - constructor.parameters = paramList; + constructor.parameters = _attachAssociatedDefinitions( + constructor.parameters, + ); } - final List fieldList = []; - for (final ApiField field in api.fields) { - fieldList.add(field.copyWithType( - _attachAssociatedDefinition(field.type), - )); + api.fields = _attachAssociatedDefinitions(api.fields); + + if (api.superClass != null) { + api.superClass = _attachAssociatedDefinition(api.superClass!); + } + + final Set newInterfaceSet = {}; + for (final TypeDeclaration interface in api.interfaces) { + newInterfaceSet.add(_attachAssociatedDefinition(interface)); } - api.fields = fieldList; + api.interfaces = newInterfaceSet; } } @@ -1352,6 +1347,16 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { return type; } + List _attachAssociatedDefinitions(Iterable types) { + final List result = []; + for (final NamedType type in types) { + result.add( + type.copyWithType(_attachAssociatedDefinition(type.type)) as T, + ); + } + return result; + } + Object _expressionToMap(dart_ast.Expression expression) { if (expression is dart_ast.MethodInvocation) { final Map result = {}; @@ -1497,6 +1502,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { } final String? superClassName = annotationMap['superClass'] as String?; + TypeDeclaration? superClass; if (superClassName != null && node.extendsClause != null) { _errors.add( Error( @@ -1505,6 +1511,27 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { lineNumber: _calculateLineNumber(source, node.offset), ), ); + } else if (superClassName != null) { + superClass = TypeDeclaration( + baseName: superClassName, + isNullable: false, + ); + } else if (node.extendsClause != null) { + superClass = TypeDeclaration( + baseName: node.extendsClause!.superclass.name2.lexeme, + isNullable: false, + ); + } + + final Set interfaces = {}; + if (node.implementsClause != null) { + for (final dart_ast.NamedType type + in node.implementsClause!.interfaces) { + interfaces.add(TypeDeclaration( + baseName: type.name2.lexeme, + isNullable: false, + )); + } } _currentApi = AstProxyApi( @@ -1512,12 +1539,8 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { methods: [], constructors: [], fields: [], - superClassName: - superClassName ?? node.extendsClause?.superclass.name2.lexeme, - interfacesNames: node.implementsClause?.interfaces - .map((dart_ast.NamedType type) => type.name2.lexeme) - .toSet() ?? - {}, + superClass: superClass, + interfaces: interfaces, documentationComments: _documentationCommentsParser(node.documentationComment?.tokens), ); diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index 1f001eae6cb5..e077f7d81324 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -11,7 +11,7 @@ dependencies: analyzer: ">=5.13.0 <7.0.0" args: ^2.1.0 collection: ^1.15.0 - meta: ^1.7.0 + meta: ^1.9.0 path: ^1.8.0 yaml: ^3.1.1 diff --git a/packages/pigeon/test/generator_tools_test.dart b/packages/pigeon/test/generator_tools_test.dart index 344a98cd79f4..6b43b93eecc5 100644 --- a/packages/pigeon/test/generator_tools_test.dart +++ b/packages/pigeon/test/generator_tools_test.dart @@ -375,31 +375,36 @@ void main() { }); test('recursiveGetSuperClassApisChain', () { - final AstProxyApi api = AstProxyApi( - name: 'Api', + final AstProxyApi superClassOfSuperClassApi = AstProxyApi( + name: 'Api3', methods: [], constructors: [], fields: [], - superClassName: 'Api2', ); final AstProxyApi superClassApi = AstProxyApi( name: 'Api2', methods: [], constructors: [], fields: [], - superClassName: 'Api3', + superClass: TypeDeclaration( + baseName: 'Api3', + isNullable: false, + associatedProxyApi: superClassOfSuperClassApi, + ), ); - final AstProxyApi superClassOfSuperClassApi = AstProxyApi( - name: 'Api3', + final AstProxyApi api = AstProxyApi( + name: 'Api', methods: [], constructors: [], fields: [], + superClass: TypeDeclaration( + baseName: 'Api2', + isNullable: false, + associatedProxyApi: superClassApi, + ), ); - final List apiChain = recursiveGetSuperClassApisChain( - api, - [superClassOfSuperClassApi, api, superClassApi], - ); + final List apiChain = recursiveGetSuperClassApisChain(api); expect( apiChain, @@ -411,50 +416,69 @@ void main() { }); test('recursiveFindAllInterfacesApis', () { - final AstProxyApi api = AstProxyApi( - name: 'Api', + final AstProxyApi interfaceOfInterfaceApi2 = AstProxyApi( + name: 'Api5', methods: [], constructors: [], fields: [], - interfacesNames: {'Api2', 'Api3'}, ); - final AstProxyApi interfaceApi = AstProxyApi( - name: 'Api2', + final AstProxyApi interfaceOfInterfaceApi = AstProxyApi( + name: 'Api4', methods: [], constructors: [], fields: [], - interfacesNames: {'Api4', 'Api5'}, ); final AstProxyApi interfaceApi2 = AstProxyApi( name: 'Api3', methods: [], constructors: [], fields: [], - interfacesNames: {'Api5'}, + interfaces: { + TypeDeclaration( + baseName: 'Api5', + isNullable: false, + associatedProxyApi: interfaceOfInterfaceApi2, + ), + }, ); - final AstProxyApi interfaceOfInterfaceApi = AstProxyApi( - name: 'Api4', + final AstProxyApi interfaceApi = AstProxyApi( + name: 'Api2', methods: [], constructors: [], fields: [], + interfaces: { + TypeDeclaration( + baseName: 'Api4', + isNullable: false, + associatedProxyApi: interfaceOfInterfaceApi, + ), + TypeDeclaration( + baseName: 'Api5', + isNullable: false, + associatedProxyApi: interfaceOfInterfaceApi2, + ), + }, ); - final AstProxyApi interfaceOfInterfaceApi2 = AstProxyApi( - name: 'Api5', + final AstProxyApi api = AstProxyApi( + name: 'Api', methods: [], constructors: [], fields: [], + interfaces: { + TypeDeclaration( + baseName: 'Api2', + isNullable: false, + associatedProxyApi: interfaceApi, + ), + TypeDeclaration( + baseName: 'Api3', + isNullable: false, + associatedProxyApi: interfaceApi2, + ), + }, ); - final Set allInterfaces = recursiveFindAllInterfacesApis( - api, - [ - api, - interfaceApi, - interfaceApi2, - interfaceOfInterfaceApi, - interfaceOfInterfaceApi2, - ], - ); + final Set allInterfaces = recursiveFindAllInterfaceApis(api); expect( allInterfaces, @@ -475,25 +499,32 @@ void main() { methods: [], constructors: [], fields: [], - interfacesNames: {'B'}, ); final AstProxyApi b = AstProxyApi( name: 'B', methods: [], constructors: [], fields: [], - interfacesNames: {'C'}, ); final AstProxyApi c = AstProxyApi( name: 'C', methods: [], constructors: [], fields: [], - interfacesNames: {'A'}, ); + a.interfaces = { + TypeDeclaration(baseName: 'B', isNullable: false, associatedProxyApi: b), + }; + b.interfaces = { + TypeDeclaration(baseName: 'C', isNullable: false, associatedProxyApi: c), + }; + c.interfaces = { + TypeDeclaration(baseName: 'A', isNullable: false, associatedProxyApi: a), + }; + expect( - () => recursiveFindAllInterfacesApis(a, [a, b, c]), + () => recursiveFindAllInterfaceApis(a), throwsArgumentError, ); }); From 54c7ac2e65b45c7a8d85b6af2970ececdbda7dda Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 25 Jan 2024 17:40:50 -0500 Subject: [PATCH 16/32] add deps --- packages/pigeon/pubspec.yaml | 2 ++ script/configs/allowed_unpinned_deps.yaml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index e077f7d81324..8ad64e843eee 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -10,7 +10,9 @@ environment: dependencies: analyzer: ">=5.13.0 <7.0.0" args: ^2.1.0 + code_builder: ^4.10.0 collection: ^1.15.0 + dart_style: ^2.3.4 meta: ^1.9.0 path: ^1.8.0 yaml: ^3.1.1 diff --git a/script/configs/allowed_unpinned_deps.yaml b/script/configs/allowed_unpinned_deps.yaml index fe4c138b0a63..84ff94a1101b 100644 --- a/script/configs/allowed_unpinned_deps.yaml +++ b/script/configs/allowed_unpinned_deps.yaml @@ -25,9 +25,11 @@ - build_config - build_runner - build_test +- code_builder - collection - convert - crypto +- dart_style - fake_async - ffi - gcloud From d05bebffa4aeab25735015876e01f9b608cfaf71 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 26 Jan 2024 19:13:26 -0500 Subject: [PATCH 17/32] add proxyapi ast helper gen methods --- packages/pigeon/lib/dart/templates.dart | 391 +++++++++++++ packages/pigeon/lib/dart_generator.dart | 711 ++++++++++++++++++++++- packages/pigeon/lib/generator_tools.dart | 48 +- 3 files changed, 1135 insertions(+), 15 deletions(-) create mode 100644 packages/pigeon/lib/dart/templates.dart diff --git a/packages/pigeon/lib/dart/templates.dart b/packages/pigeon/lib/dart/templates.dart new file mode 100644 index 000000000000..bcc152f13fa4 --- /dev/null +++ b/packages/pigeon/lib/dart/templates.dart @@ -0,0 +1,391 @@ +import '../generator_tools.dart'; + +/// Creates the `InstanceManager` with the passed string values. +String instanceManagerTemplate({ + required String proxyApiBaseClassName, + required List allProxyApiNames, +}) { + //const String proxyApiBaseClassName = '${classNamePrefix}ProxyApiBaseClass'; + + final Iterable apiHandlerSetUps = allProxyApiNames.map( + (String name) { + return '$name.${classMemberNamePrefix}setUpMessageHandlers(${classMemberNamePrefix}instanceManager: instanceManager);'; + }, + ); + + return ''' +/// Maintains instances used to communicate with the native objects they +/// represent. +/// +/// Added instances are stored as weak references and their copies are stored +/// as strong references to maintain access to their variables and callback +/// methods. Both are stored with the same identifier. +/// +/// When a weak referenced instance becomes inaccessible, +/// [onWeakReferenceRemoved] is called with its associated identifier. +/// +/// If an instance is retrieved and has the possibility to be used, +/// (e.g. calling [getInstanceWithWeakReference]) a copy of the strong reference +/// is added as a weak reference with the same identifier. This prevents a +/// scenario where the weak referenced instance was released and then later +/// returned by the host platform. +class $instanceManagerClassName { + /// Constructs a [$instanceManagerClassName]. + $instanceManagerClassName({required void Function(int) onWeakReferenceRemoved}) { + this.onWeakReferenceRemoved = (int identifier) { + _weakInstances.remove(identifier); + onWeakReferenceRemoved(identifier); + }; + _finalizer = Finalizer(this.onWeakReferenceRemoved); + } + + // Identifiers are locked to a specific range to avoid collisions with objects + // created simultaneously by the host platform. + // Host uses identifiers >= 2^16 and Dart is expected to use values n where, + // 0 <= n < 2^16. + static const int _maxDartCreatedIdentifier = 65536; + + /// The default [$instanceManagerClassName] used by ProxyApis. + /// + /// On creation, this manager makes a call to clear the native + /// InstanceManager. This is to prevent identifier conflicts after a host + /// restart. + static final $instanceManagerClassName instance = _initInstance(); + + // Expando is used because it doesn't prevent its keys from becoming + // inaccessible. This allows the manager to efficiently retrieve an identifier + // of an instance without holding a strong reference to that instance. + // + // It also doesn't use `==` to search for identifiers, which would lead to an + // infinite loop when comparing an object to its copy. (i.e. which was caused + // by calling instanceManager.getIdentifier() inside of `==` while this was a + // HashMap). + final Expando _identifiers = Expando(); + final Map> _weakInstances = + >{}; + final Map _strongInstances = {}; + late final Finalizer _finalizer; + int _nextIdentifier = 0; + + /// Called when a weak referenced instance is removed by [removeWeakReference] + /// or becomes inaccessible. + late final void Function(int) onWeakReferenceRemoved; + + static $instanceManagerClassName _initInstance() { + WidgetsFlutterBinding.ensureInitialized(); + final _${instanceManagerClassName}Api api = _${instanceManagerClassName}Api(); + // Clears the native `$instanceManagerClassName` on the initial use of the Dart one. + api.clear(); + final $instanceManagerClassName instanceManager = $instanceManagerClassName( + onWeakReferenceRemoved: (int identifier) { + api.removeStrongReference(identifier); + }, + ); + _${instanceManagerClassName}Api.setUpMessageHandlers(instanceManager: instanceManager); + ${apiHandlerSetUps.join('\n\t\t')} + return instanceManager; + } + + /// Adds a new instance that was instantiated by Dart. + /// + /// In other words, Dart wants to add a new instance that will represent + /// an object that will be instantiated on the host platform. + /// + /// Throws assertion error if the instance has already been added. + /// + /// Returns the randomly generated id of the [instance] added. + int addDartCreatedInstance($proxyApiBaseClassName instance) { + final int identifier = _nextUniqueIdentifier(); + _addInstanceWithIdentifier(instance, identifier); + return identifier; + } + + /// Removes the instance, if present, and call [onWeakReferenceRemoved] with + /// its identifier. + /// + /// Returns the identifier associated with the removed instance. Otherwise, + /// `null` if the instance was not found in this manager. + /// + /// This does not remove the strong referenced instance associated with + /// [instance]. This can be done with [remove]. + int? removeWeakReference($proxyApiBaseClassName instance) { + final int? identifier = getIdentifier(instance); + if (identifier == null) { + return null; + } + + _identifiers[instance] = null; + _finalizer.detach(instance); + onWeakReferenceRemoved(identifier); + + return identifier; + } + + /// Removes [identifier] and its associated strongly referenced instance, if + /// present, from the manager. + /// + /// Returns the strong referenced instance associated with [identifier] before + /// it was removed. Returns `null` if [identifier] was not associated with + /// any strong reference. + /// + /// This does not remove the weak referenced instance associated with + /// [identifier]. This can be done with [removeWeakReference]. + T? remove(int identifier) { + return _strongInstances.remove(identifier) as T?; + } + + /// Retrieves the instance associated with identifier. + /// + /// The value returned is chosen from the following order: + /// + /// 1. A weakly referenced instance associated with identifier. + /// 2. If the only instance associated with identifier is a strongly + /// referenced instance, a copy of the instance is added as a weak reference + /// with the same identifier. Returning the newly created copy. + /// 3. If no instance is associated with identifier, returns null. + /// + /// This method also expects the host `InstanceManager` to have a strong + /// reference to the instance the identifier is associated with. + T? getInstanceWithWeakReference(int identifier) { + final $proxyApiBaseClassName? weakInstance = _weakInstances[identifier]?.target; + + if (weakInstance == null) { + final $proxyApiBaseClassName? strongInstance = _strongInstances[identifier]; + if (strongInstance != null) { + final $proxyApiBaseClassName copy = strongInstance.${classMemberNamePrefix}copy(); + _identifiers[copy] = identifier; + _weakInstances[identifier] = WeakReference<$proxyApiBaseClassName>(copy); + _finalizer.attach(copy, identifier, detach: copy); + return copy as T; + } + return strongInstance as T?; + } + + return weakInstance as T; + } + + /// Retrieves the identifier associated with instance. + int? getIdentifier($proxyApiBaseClassName instance) { + return _identifiers[instance]; + } + + /// Adds a new instance that was instantiated by the host platform. + /// + /// In other words, the host platform wants to add a new instance that + /// represents an object on the host platform. Stored with [identifier]. + /// + /// Throws assertion error if the instance or its identifier has already been + /// added. + /// + /// Returns unique identifier of the [instance] added. + void addHostCreatedInstance($proxyApiBaseClassName instance, int identifier) { + _addInstanceWithIdentifier(instance, identifier); + } + + void _addInstanceWithIdentifier($proxyApiBaseClassName instance, int identifier) { + assert(!containsIdentifier(identifier)); + assert(getIdentifier(instance) == null); + assert(identifier >= 0); + + _identifiers[instance] = identifier; + _weakInstances[identifier] = WeakReference<$proxyApiBaseClassName>(instance); + _finalizer.attach(instance, identifier, detach: instance); + + final $proxyApiBaseClassName copy = instance.${classMemberNamePrefix}copy(); + _identifiers[copy] = identifier; + _strongInstances[identifier] = copy; + } + + /// Whether this manager contains the given [identifier]. + bool containsIdentifier(int identifier) { + return _weakInstances.containsKey(identifier) || + _strongInstances.containsKey(identifier); + } + + int _nextUniqueIdentifier() { + late int identifier; + do { + identifier = _nextIdentifier; + _nextIdentifier = (_nextIdentifier + 1) % _maxDartCreatedIdentifier; + } while (containsIdentifier(identifier)); + return identifier; + } +} +'''; +} + +/// Creates the `InstanceManagerApi` with the passed string values. +String instanceManagerApiTemplate({ + required String dartPackageName, + required String pigeonChannelCodecVarName, +}) { + const String apiName = '${instanceManagerClassName}Api'; + + final String removeStrongReferenceName = makeChannelNameWithStrings( + apiName: apiName, + methodName: 'removeStrongReference', + dartPackageName: dartPackageName, + ); + + final String clearName = makeChannelNameWithStrings( + apiName: apiName, + methodName: 'clear', + dartPackageName: dartPackageName, + ); + + return ''' +/// Generated API for managing the Dart and native `$instanceManagerClassName`s. +class _$apiName { + /// Constructor for [_$apiName ]. + _$apiName({BinaryMessenger? binaryMessenger}) + : _binaryMessenger = binaryMessenger; + + final BinaryMessenger? _binaryMessenger; + + static const MessageCodec $pigeonChannelCodecVarName = + StandardMessageCodec(); + + static void setUpMessageHandlers({ + BinaryMessenger? binaryMessenger, + $instanceManagerClassName? instanceManager, + }) { + const String channelName = + r'$removeStrongReferenceName'; + final BasicMessageChannel channel = BasicMessageChannel( + channelName, + $pigeonChannelCodecVarName, + binaryMessenger: binaryMessenger, + ); + channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for \$channelName was null.', + ); + final int? identifier = message as int?; + assert( + identifier != null, + r'Argument for \$channelName, expected non-null int.', + ); + (instanceManager ?? $instanceManagerClassName.instance).remove(identifier!); + return; + }); + } + + Future removeStrongReference(int identifier) async { + const String channelName = + r'$removeStrongReferenceName'; + final BasicMessageChannel channel = BasicMessageChannel( + channelName, + $pigeonChannelCodecVarName, + binaryMessenger: _binaryMessenger, + ); + final List? replyList = + await channel.send(identifier) as List?; + if (replyList == null) { + throw _createConnectionError(channelName); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return; + } + } + + /// Clear the native `$instanceManagerClassName`. + /// + /// This is typically called after a hot restart. + Future clear() async { + const String channelName = + r'$clearName'; + final BasicMessageChannel channel = BasicMessageChannel( + channelName, + $pigeonChannelCodecVarName, + binaryMessenger: _binaryMessenger, + ); + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { + throw _createConnectionError(channelName); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return; + } + } +}'''; +} + +const String proxyApiBaseClass = ''' +/// An immutable object that serves as the base class for all ProxyApis and +/// can provide functional copies of itself. +/// +/// All implementers are expected to be [immutable] as defined by the annotation +/// and override [${classMemberNamePrefix}copy] returning an instance of itself. +@immutable +abstract class $_proxyApiBaseClassName { + /// Construct a [$_proxyApiBaseClassName]. + $_proxyApiBaseClassName({ + this.$_proxyApiBaseClassMessengerVarName, + $instanceManagerClassName? $_proxyApiBaseClassInstanceManagerVarName, + }) : $_proxyApiBaseClassInstanceManagerVarName = + $_proxyApiBaseClassInstanceManagerVarName ?? $instanceManagerClassName.instance; + + /// Sends and receives binary data across the Flutter platform barrier. + /// + /// If it is null, the default BinaryMessenger will be used, which routes to + /// the host platform. + final BinaryMessenger? $_proxyApiBaseClassMessengerVarName; + + /// Maintains instances stored to communicate with native language objects. + final $instanceManagerClassName $_proxyApiBaseClassInstanceManagerVarName; + + /// Instantiates and returns a functionally identical object to oneself. + /// + /// Outside of tests, this method should only ever be called by + /// [$instanceManagerClassName]. + /// + /// Subclasses should always override their parent's implementation of this + /// method. + @protected + $_proxyApiBaseClassName ${classMemberNamePrefix}copy(); +} +'''; + +const String proxyApiCodec = ''' +class $_proxyApiCodecName extends StandardMessageCodec { + const $_proxyApiCodecName(this.instanceManager); + final $instanceManagerClassName instanceManager; + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is $_proxyApiBaseClassName) { + buffer.putUint8(128); + writeValue(buffer, instanceManager.getIdentifier(value)); + } else { + super.writeValue(buffer, value); + } + } + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + case 128: + return instanceManager + .getInstanceWithWeakReference(readValue(buffer)! as int); + default: + return super.readValueOfType(type, buffer); + } + } +} +'''; + +const String _proxyApiBaseClassName = '${classNamePrefix}ProxyApiBaseClass'; +const String _proxyApiBaseClassMessengerVarName = + '${classMemberNamePrefix}binaryMessenger'; +const String _proxyApiBaseClassInstanceManagerVarName = + '${classMemberNamePrefix}instanceManager'; +const String _proxyApiCodecName = '_${classNamePrefix}ProxyApiBaseCodec'; diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 8cdea012554b..c3dce2ce2ca2 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:code_builder/code_builder.dart' as cb; +import 'package:collection/collection.dart' as collection; import 'package:path/path.dart' as path; import 'ast.dart'; @@ -18,6 +20,10 @@ const String _docCommentPrefix = '///'; /// user defined parameters. const String _varNamePrefix = '__pigeon_'; +/// Name of the `InstanceManager` variable for a ProxyApi class; +const String _instanceManagerVarName = + '${classMemberNamePrefix}instanceManager'; + /// Name of field used for host API codec. const String _pigeonChannelCodec = 'pigeonChannelCodec'; @@ -94,7 +100,10 @@ class DartGenerator extends StructuredGenerator { indent.writeln('// ${getGeneratedCodeWarning()}'); indent.writeln('// $seeAlsoWarning'); indent.writeln( - '// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers', + '// ignore_for_file: public_member_api_docs, non_constant_identifier_names, ' + 'avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, ' + 'omit_local_variable_types, unused_shown_name, unnecessary_import, ' + 'no_leading_underscores_for_local_identifiers, camel_case_types', ); indent.newln(); } @@ -111,9 +120,16 @@ class DartGenerator extends StructuredGenerator { "import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List;", ); indent.newln(); + + final bool hasProxyApi = root.apis.any((Api api) => api is AstProxyApi); indent.writeln( - "import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer;"); + "import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer${hasProxyApi ? ' immutable, protected' : ''};"); indent.writeln("import 'package:flutter/services.dart';"); + if (hasProxyApi) { + indent.writeln( + "import 'package:flutter/widgets.dart' show WidgetsFlutterBinding;", + ); + } } @override @@ -434,6 +450,686 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; }); } + Iterable _proxyApiConstructors( + Iterable constructors, { + required String apiName, + required String dartPackageName, + required String codecName, + required String codecInstanceName, + required AstProxyApi? superClassApi, + required Iterable unattachedFields, + required Iterable superClassFlutterMethods, + required Iterable interfacesMethods, + required Iterable flutterMethods, + }) { + final cb.Parameter binaryMessengerParameter = cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = '${classMemberNamePrefix}binaryMessenger' + ..named = true + ..toSuper = true, + ); + final cb.Parameter instanceManagerParameter = cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = _instanceManagerVarName + ..named = true + ..toSuper = true, + ); + return [ + // All constructors for this api defined in the pigeon file. + ...constructors.map( + (Constructor constructor) => cb.Constructor( + (cb.ConstructorBuilder builder) { + final String channelName = makeChannelNameWithStrings( + apiName: apiName, + methodName: constructor.name.isNotEmpty + ? constructor.name + : '${classMemberNamePrefix}defaultConstructor', + dartPackageName: dartPackageName, + ); + builder + ..name = constructor.name.isNotEmpty ? constructor.name : null + ..docs.addAll(asDocumentationComments( + constructor.documentationComments, + _docCommentSpec, + )) + ..optionalParameters.addAll( + [ + binaryMessengerParameter, + instanceManagerParameter, + for (final ApiField field in unattachedFields) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = field.name + ..named = true + ..toThis = true + ..required = !field.type.isNullable, + ), + for (final Method method in superClassFlutterMethods + .followedBy(interfacesMethods) + .followedBy(flutterMethods)) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = method.name + ..named = true + ..toSuper = true + ..required = method.isRequired, + ), + ...constructor.parameters.mapIndexed( + (int index, NamedType parameter) => cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = _getParameterName(index, parameter) + ..type = _refer(parameter.type) + ..named = true + ..required = !parameter.type.isNullable, + ), + ) + ], + ) + ..initializers.addAll( + [ + if (superClassApi != null) + const cb.Code('super.${classMemberNamePrefix}detached()') + ], + ) + ..body = cb.Block( + (cb.BlockBuilder builder) { + final StringBuffer messageCallSink = StringBuffer(); + _writeHostMethodMessageCall( + Indent(messageCallSink), + channelName: channelName, + parameters: [ + Parameter( + name: '${_varNamePrefix}instanceIdentifier', + type: const TypeDeclaration( + baseName: 'int', + isNullable: false, + ), + ), + ...unattachedFields.map( + (ApiField field) => Parameter( + name: field.name, + type: field.type, + ), + ), + ...constructor.parameters, + ], + returnType: const TypeDeclaration.voidDeclaration(), + ); + builder.statements.addAll([ + const cb.Code( + 'final int ${_varNamePrefix}instanceIdentifier = $_instanceManagerVarName.addDartCreatedInstance(this);', + ), + cb.Code('final $codecName $_pigeonChannelCodec =\n' + ' $codecInstanceName;'), + cb.Code( + 'final BinaryMessenger? ${_varNamePrefix}binaryMessenger = ${binaryMessengerParameter.name};', + ), + const cb.Code('() async {'), + cb.Code(messageCallSink.toString()), + const cb.Code('}();'), + ]); + }, + ); + }, + ), + ), + // The detached constructor present for every ProxyApi. This constructor + // doesn't include a host method call to create a new native class + // instance. It is mainly used when the native side once to create a Dart + // instance and when the `InstanceManager` wants to create a copy for + // garbage collection. + cb.Constructor( + (cb.ConstructorBuilder builder) => builder + ..name = '${classMemberNamePrefix}detached' + ..docs.addAll([ + '/// Constructs $apiName without creating the associated native object.', + '///', + '/// This should only be used by subclasses created by this library or to', + '/// create copies for an [$instanceManagerClassName].', + ]) + ..optionalParameters.addAll([ + binaryMessengerParameter, + instanceManagerParameter, + for (final ApiField field in unattachedFields) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = field.name + ..named = true + ..toThis = true + ..required = !field.type.isNullable, + ), + for (final Method method in superClassFlutterMethods + .followedBy(interfacesMethods) + .followedBy(flutterMethods)) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = method.name + ..named = true + ..toSuper = true + ..required = method.isRequired, + ), + ]) + ..initializers.addAll([ + if (superClassApi != null) + const cb.Code('super.${classMemberNamePrefix}detached()'), + ]), + ), + ]; + } + + Iterable _proxyApiFields({ + required Iterable unattachedFields, + required Iterable attachedFields, + required String apiName, + required String dartPackageName, + required String codecInstanceName, + required String codecName, + required Iterable interfacesApis, + required Iterable flutterMethods, + required bool referencesCodecInstance, + }) { + return [ + if (referencesCodecInstance) + cb.Field( + (cb.FieldBuilder builder) => builder + ..name = codecInstanceName + ..type = cb.refer(codecName) + ..late = true + ..modifier = cb.FieldModifier.final$ + ..assignment = cb.Code('$codecName($_instanceManagerVarName)'), + ), + for (final ApiField field in unattachedFields) + cb.Field( + (cb.FieldBuilder builder) => builder + ..name = field.name + ..type = cb.refer(_addGenericTypesNullable(field.type)) + ..modifier = cb.FieldModifier.final$ + ..docs.addAll(asDocumentationComments( + field.documentationComments, + _docCommentSpec, + )), + ), + for (final Method method in flutterMethods) + cb.Field( + (cb.FieldBuilder builder) => builder + ..name = method.name + ..modifier = cb.FieldModifier.final$ + ..docs.addAll(asDocumentationComments( + [ + ...method.documentationComments, + ...[ + if (method.documentationComments.isNotEmpty) '', + 'Dart:', + 'For the associated Native object to be automatically garbage collected,', + "it is required that the implementation of this `Function` doesn't have a", + 'strong reference to the encapsulating class instance. When this `Function`', + 'references a non-local variable, it is strongly recommended to access it', + 'from a `WeakReference`:', + '', + '```dart', + 'final WeakReference weakMyVariable = WeakReference(myVariable);', + 'final $apiName instance = $apiName(', + ' ${method.name}: ($apiName ${classMemberNamePrefix}instance, ...) {', + ' print(weakMyVariable?.target);', + ' },', + ');', + '```', + '', + 'Alternatively, `$instanceManagerClassName.removeWeakReference` can be used to', + 'release the associated Native object manually.', + ], + ], + _docCommentSpec, + )) + ..type = cb.FunctionType( + (cb.FunctionTypeBuilder builder) => builder + ..returnType = _refer( + method.returnType, + asFuture: method.isAsynchronous, + ) + ..isNullable = !method.isRequired + ..requiredParameters.addAll([ + cb.refer('$apiName ${classMemberNamePrefix}instance'), + ...method.parameters.mapIndexed( + (int index, NamedType parameter) { + return cb.refer( + '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', + ); + }, + ), + ]), + ), + ), + for (final AstProxyApi proxyApi in interfacesApis) + for (final Method method in proxyApi.methods) + cb.Field( + (cb.FieldBuilder builder) => builder + ..name = method.name + ..modifier = cb.FieldModifier.final$ + ..annotations.add(cb.refer('override')) + ..docs.addAll(asDocumentationComments( + method.documentationComments, + _docCommentSpec, + )) + ..type = cb.FunctionType( + (cb.FunctionTypeBuilder builder) => builder + ..returnType = _refer( + method.returnType, + asFuture: method.isAsynchronous, + ) + ..isNullable = !method.isRequired + ..requiredParameters.addAll([ + cb.refer( + '${proxyApi.name} ${classMemberNamePrefix}instance', + ), + ...method.parameters.mapIndexed( + (int index, NamedType parameter) { + return cb.refer( + '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', + ); + }, + ), + ]), + ), + ), + for (final ApiField field in attachedFields) + cb.Field( + (cb.FieldBuilder builder) => builder + ..name = field.name + ..type = cb.refer(_addGenericTypesNullable(field.type)) + ..modifier = cb.FieldModifier.final$ + ..static = field.isStatic + ..late = !field.isStatic + ..docs.addAll(asDocumentationComments( + field.documentationComments, + _docCommentSpec, + )) + ..assignment = cb.Code('$_varNamePrefix${field.name}()'), + ), + ]; + } + + Iterable _proxyApiMethods({ + required Iterable hostMethods, + required Iterable flutterMethods, + required Iterable superClassFlutterMethods, + required String apiName, + required String dartPackageName, + required String codecInstanceName, + required String codecName, + required Iterable unattachedFields, + required Iterable attachedFields, + required Iterable interfacesApis, + required bool hasCallbackConstructor, + }) { + return [ + // Flutter methods message handler `*setUpMessageHandlers()` + cb.Method.returnsVoid( + (cb.MethodBuilder builder) => builder + ..name = '${classMemberNamePrefix}setUpMessageHandlers' + ..returns = cb.refer('void') + ..static = true + ..optionalParameters.addAll([ + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = '${classMemberNamePrefix}clearHandlers' + ..type = cb.refer('bool') + ..named = true + ..defaultTo = const cb.Code('false'), + ), + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = '${classMemberNamePrefix}binaryMessenger' + ..named = true + ..type = cb.refer('BinaryMessenger?'), + ), + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = _instanceManagerVarName + ..named = true + ..type = cb.refer('$instanceManagerClassName?'), + ), + if (hasCallbackConstructor) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = '${classMemberNamePrefix}newInstance' + ..named = true + ..type = cb.FunctionType( + (cb.FunctionTypeBuilder builder) => builder + ..returnType = cb.refer(apiName) + ..isNullable = true + ..requiredParameters.addAll( + unattachedFields.mapIndexed( + (int index, ApiField field) { + return cb.refer( + '${_addGenericTypesNullable(field.type)} ${_getParameterName(index, field)}', + ); + }, + ), + ), + ), + ), + for (final Method method in flutterMethods) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = method.name + ..type = cb.FunctionType( + (cb.FunctionTypeBuilder builder) => builder + ..returnType = _refer( + method.returnType, + asFuture: method.isAsynchronous, + ) + ..isNullable = true + ..requiredParameters.addAll([ + cb.refer('$apiName ${classMemberNamePrefix}instance'), + ...method.parameters.mapIndexed( + (int index, NamedType parameter) { + return cb.refer( + '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', + ); + }, + ), + ]), + ), + ), + ]) + ..body = cb.Block.of([ + cb.Code( + 'final $codecName $_pigeonChannelCodec = $codecName($_instanceManagerVarName ?? $instanceManagerClassName.instance);', + ), + const cb.Code( + 'final BinaryMessenger? binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', + ), + if (hasCallbackConstructor) + ...cb.Block((cb.BlockBuilder builder) { + final StringBuffer messageHandlerSink = StringBuffer(); + const String methodName = '${classMemberNamePrefix}newInstance'; + _writeFlutterMethodMessageHandler( + Indent(messageHandlerSink), + name: methodName, + parameters: [ + Parameter( + name: '${classMemberNamePrefix}instanceIdentifier', + type: const TypeDeclaration( + baseName: 'int', + isNullable: false, + ), + ), + ...unattachedFields.map( + (ApiField field) => + Parameter(name: field.name, type: field.type), + ), + ], + returnType: const TypeDeclaration.voidDeclaration(), + channelName: makeChannelNameWithStrings( + apiName: apiName, + methodName: methodName, + dartPackageName: dartPackageName, + ), + isMockHandler: false, + isAsynchronous: false, + nullHandlerExpression: + '${classMemberNamePrefix}clearHandlers', + onCreateApiCall: ( + String methodName, + Iterable parameters, + Iterable safeArgumentNames, + ) { + final String argsAsNamedParams = map2( + parameters, + safeArgumentNames, + (Parameter parameter, String safeArgName) { + return '${parameter.name}: $safeArgName,\n'; + }, + ).skip(1).join(); + return '($_instanceManagerVarName ?? $instanceManagerClassName.instance)\n' + ' .addHostCreatedInstance(\n' + ' $methodName?.call(${safeArgumentNames.skip(1).join(',')}) ??\n' + ' $apiName.${classMemberNamePrefix}detached(' + ' ${classMemberNamePrefix}binaryMessenger: ${classMemberNamePrefix}binaryMessenger,\n' + ' $_instanceManagerVarName: $_instanceManagerVarName,\n' + ' $argsAsNamedParams\n' + ' ),\n' + ' ${safeArgumentNames.first},\n' + ')'; + }, + ); + builder.statements.add(cb.Code(messageHandlerSink.toString())); + }).statements, + for (final Method method in flutterMethods) + ...cb.Block((cb.BlockBuilder builder) { + final StringBuffer messageHandlerSink = StringBuffer(); + _writeFlutterMethodMessageHandler( + Indent(messageHandlerSink), + name: method.name, + parameters: [ + Parameter( + name: '${classMemberNamePrefix}instance', + type: TypeDeclaration( + baseName: apiName, + isNullable: false, + ), + ), + ...method.parameters, + ], + returnType: TypeDeclaration( + baseName: method.returnType.baseName, + isNullable: + !method.isRequired || method.returnType.isNullable, + typeArguments: method.returnType.typeArguments, + associatedEnum: method.returnType.associatedEnum, + associatedClass: method.returnType.associatedClass, + associatedProxyApi: method.returnType.associatedProxyApi, + ), + channelName: makeChannelNameWithStrings( + apiName: apiName, + methodName: method.name, + dartPackageName: dartPackageName, + ), + isMockHandler: false, + isAsynchronous: method.isAsynchronous, + nullHandlerExpression: + '${classMemberNamePrefix}clearHandlers', + onCreateApiCall: ( + String methodName, + Iterable parameters, + Iterable safeArgumentNames, + ) { + final String nullability = method.isRequired ? '' : '?'; + return '($methodName ?? ${safeArgumentNames.first}.$methodName)$nullability.call(${safeArgumentNames.join(',')})'; + }, + ); + builder.statements.add(cb.Code(messageHandlerSink.toString())); + }).statements, + ]), + ), + for (final ApiField field in attachedFields) + cb.Method( + (cb.MethodBuilder builder) { + final String type = _addGenericTypesNullable(field.type); + const String instanceName = '${_varNamePrefix}instance'; + const String identifierInstanceName = + '${_varNamePrefix}instanceIdentifier'; + builder + ..name = '$_varNamePrefix${field.name}' + ..static = field.isStatic + ..returns = cb.refer(type) + ..body = cb.Block( + (cb.BlockBuilder builder) { + final StringBuffer messageCallSink = StringBuffer(); + _writeHostMethodMessageCall( + Indent(messageCallSink), + channelName: makeChannelNameWithStrings( + apiName: apiName, + methodName: field.name, + dartPackageName: dartPackageName, + ), + parameters: [ + if (!field.isStatic) + Parameter( + name: 'this', + type: TypeDeclaration( + baseName: apiName, + isNullable: false, + ), + ), + Parameter( + name: identifierInstanceName, + type: const TypeDeclaration( + baseName: 'int', + isNullable: false, + ), + ), + ], + returnType: const TypeDeclaration.voidDeclaration(), + ); + builder.statements.addAll([ + if (!field.isStatic) ...[ + cb.Code( + 'final $type $instanceName = $type.${classMemberNamePrefix}detached(\n' + ' pigeon_binaryMessenger: pigeon_binaryMessenger,\n' + ' pigeon_instanceManager: pigeon_instanceManager,\n' + ');', + ), + cb.Code('final $codecName $_pigeonChannelCodec =\n' + ' $codecInstanceName;'), + const cb.Code( + 'final BinaryMessenger? ${_varNamePrefix}binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', + ), + const cb.Code( + 'final int $identifierInstanceName = $_instanceManagerVarName.addDartCreatedInstance($instanceName);', + ), + ] else ...[ + cb.Code( + 'final $type $instanceName = $type.${classMemberNamePrefix}detached();', + ), + cb.Code( + 'final $codecName $_pigeonChannelCodec = $codecName($instanceManagerClassName.instance);', + ), + const cb.Code( + 'final BinaryMessenger ${_varNamePrefix}binaryMessenger = ServicesBinding.instance.defaultBinaryMessenger;', + ), + const cb.Code( + 'final int $identifierInstanceName = $instanceManagerClassName.instance.addDartCreatedInstance($instanceName);', + ), + ], + const cb.Code('() async {'), + cb.Code(messageCallSink.toString()), + const cb.Code('}();'), + const cb.Code('return $instanceName;'), + ]); + }, + ); + }, + ), + for (final Method method in hostMethods) + cb.Method( + (cb.MethodBuilder builder) => builder + ..name = method.name + ..static = method.isStatic + ..modifier = cb.MethodModifier.async + ..docs.addAll(asDocumentationComments( + method.documentationComments, + _docCommentSpec, + )) + ..returns = _refer(method.returnType, asFuture: true) + ..requiredParameters.addAll( + method.parameters.mapIndexed( + (int index, NamedType parameter) => cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = _getParameterName(index, parameter) + ..type = cb.refer( + _addGenericTypesNullable(parameter.type), + ), + ), + ), + ) + ..optionalParameters.addAll([ + if (method.isStatic) ...[ + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = '${classMemberNamePrefix}binaryMessenger' + ..type = cb.refer('BinaryMessenger?') + ..named = true, + ), + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = _instanceManagerVarName + ..type = cb.refer('$instanceManagerClassName?'), + ), + ], + ]) + ..body = cb.Block( + (cb.BlockBuilder builder) { + final StringBuffer messageCallSink = StringBuffer(); + _writeHostMethodMessageCall( + Indent(messageCallSink), + channelName: makeChannelNameWithStrings( + apiName: apiName, + methodName: method.name, + dartPackageName: dartPackageName, + ), + parameters: [ + if (!method.isStatic) + Parameter( + name: 'this', + type: TypeDeclaration( + baseName: apiName, + isNullable: false, + ), + ), + ...method.parameters, + ], + returnType: method.returnType, + ); + builder.statements.addAll([ + if (!method.isStatic) + cb.Code('final $codecName $_pigeonChannelCodec =\n' + ' $codecInstanceName;') + else + cb.Code( + 'final $codecName $_pigeonChannelCodec = $codecName($_instanceManagerVarName ?? $instanceManagerClassName.instance);', + ), + const cb.Code( + 'final BinaryMessenger? ${_varNamePrefix}binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', + ), + cb.Code(messageCallSink.toString()), + ]); + }, + ), + ), + cb.Method( + (cb.MethodBuilder builder) => builder + ..name = '${classMemberNamePrefix}copy' + ..returns = cb.refer(apiName) + ..annotations.add(cb.refer('override')) + ..body = cb.Block.of([ + cb + .refer('$apiName.${classMemberNamePrefix}detached') + .call( + [], + { + '${classMemberNamePrefix}binaryMessenger': + cb.refer('${classMemberNamePrefix}binaryMessenger'), + _instanceManagerVarName: cb.refer(_instanceManagerVarName), + for (final ApiField field in unattachedFields) + field.name: cb.refer(field.name), + for (final Method method in superClassFlutterMethods) + method.name: cb.refer(method.name), + for (final AstProxyApi proxyApi in interfacesApis) + for (final Method method in proxyApi.methods) + method.name: cb.refer(method.name), + for (final Method method in flutterMethods) + method.name: cb.refer(method.name), + }, + ) + .returned + .statement, + ]), + ), + ]; + } + /// Generates Dart source code for test support libraries based on the given AST /// represented by [root], outputting the code to [sink]. [sourceOutPath] is the /// path of the generated dart code to be tested. [testOutPath] is where the @@ -678,7 +1374,8 @@ if (${_varNamePrefix}replyList == null) { required bool isMockHandler, required bool isAsynchronous, String nullHandlerExpression = 'api == null', - String Function(String methodName, Iterable safeArgumentNames) + String Function(String methodName, Iterable parameters, + Iterable safeArgumentNames) onCreateApiCall = _createFlutterApiMethodCall, }) { indent.write(''); @@ -745,7 +1442,7 @@ if (${_varNamePrefix}replyList == null) { final String name = _getSafeArgumentName(index, field); return '${field.isNamed ? '${field.name}: ' : ''}$name${field.type.isNullable ? '' : '!'}'; }); - call = onCreateApiCall(name, argNames); + call = onCreateApiCall(name, parameters, argNames); } indent.writeScoped('try {', '} ', () { if (returnType.isVoid) { @@ -787,12 +1484,18 @@ if (${_varNamePrefix}replyList == null) { static String _createFlutterApiMethodCall( String methodName, + Iterable parameters, Iterable safeArgumentNames, ) { return 'api.$methodName(${safeArgumentNames.join(', ')})'; } } +cb.Reference _refer(TypeDeclaration type, {bool asFuture = false}) { + final String symbol = _addGenericTypesNullable(type); + return cb.refer(asFuture ? 'Future<$symbol>' : symbol); +} + String _escapeForDartSingleQuotedString(String raw) { return raw .replaceAll(r'\', r'\\') diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index b9aec2b27994..b5d9cb46b816 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -164,9 +164,22 @@ class Indent { } } -/// Create the generated channel name for a [func] on a [api]. -String makeChannelName(Api api, Method func, String dartPackageName) { - return 'dev.flutter.pigeon.$dartPackageName.${api.name}.${func.name}'; +/// Create the generated channel name for a [method] on an [api]. +String makeChannelName(Api api, Method method, String dartPackageName) { + return makeChannelNameWithStrings( + apiName: api.name, + methodName: method.name, + dartPackageName: dartPackageName, + ); +} + +/// Create the generated channel name for a method on an api. +String makeChannelNameWithStrings({ + required String apiName, + required String methodName, + required String dartPackageName, +}) { + return 'dev.flutter.pigeon.$dartPackageName.$apiName.$methodName'; } // TODO(tarrinneal): Determine whether HostDataType is needed. @@ -541,6 +554,23 @@ void addDocumentationComments( DocumentCommentSpecification commentSpec, { List generatorComments = const [], }) { + asDocumentationComments( + comments, + commentSpec, + generatorComments: generatorComments, + ).forEach(indent.writeln); +} + +/// Formats documentation comments and adds them to current Indent. +/// +/// The [comments] list is meant for comments written in the input dart file. +/// The [generatorComments] list is meant for comments added by the generators. +/// Include white space for all tokens when called, no assumptions are made. +Iterable asDocumentationComments( + Iterable comments, + DocumentCommentSpecification commentSpec, { + List generatorComments = const [], +}) sync* { final List allComments = [ ...comments, if (comments.isNotEmpty && generatorComments.isNotEmpty) '', @@ -549,24 +579,20 @@ void addDocumentationComments( String currentLineOpenToken = commentSpec.openCommentToken; if (allComments.length > 1) { if (commentSpec.closeCommentToken != '') { - indent.writeln(commentSpec.openCommentToken); + yield commentSpec.openCommentToken; currentLineOpenToken = commentSpec.blockContinuationToken; } for (String line in allComments) { if (line.isNotEmpty && line[0] != ' ') { line = ' $line'; } - indent.writeln( - '$currentLineOpenToken$line', - ); + yield '$currentLineOpenToken$line'; } if (commentSpec.closeCommentToken != '') { - indent.writeln(commentSpec.closeCommentToken); + yield commentSpec.closeCommentToken; } } else if (allComments.length == 1) { - indent.writeln( - '$currentLineOpenToken${allComments.first}${commentSpec.closeCommentToken}', - ); + yield '$currentLineOpenToken${allComments.first}${commentSpec.closeCommentToken}'; } } From 8015a9a97148df0966edaca888c637e95aa84ae9 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 31 Jan 2024 15:19:05 -0500 Subject: [PATCH 18/32] implementation of proxyapis stuff for dart --- packages/pigeon/lib/dart/templates.dart | 6 +- packages/pigeon/lib/dart_generator.dart | 1589 +++++++++++++---------- 2 files changed, 914 insertions(+), 681 deletions(-) diff --git a/packages/pigeon/lib/dart/templates.dart b/packages/pigeon/lib/dart/templates.dart index bcc152f13fa4..fe56d16f4fbe 100644 --- a/packages/pigeon/lib/dart/templates.dart +++ b/packages/pigeon/lib/dart/templates.dart @@ -3,10 +3,8 @@ import '../generator_tools.dart'; /// Creates the `InstanceManager` with the passed string values. String instanceManagerTemplate({ required String proxyApiBaseClassName, - required List allProxyApiNames, + required Iterable allProxyApiNames, }) { - //const String proxyApiBaseClassName = '${classNamePrefix}ProxyApiBaseClass'; - final Iterable apiHandlerSetUps = allProxyApiNames.map( (String name) { return '$name.${classMemberNamePrefix}setUpMessageHandlers(${classMemberNamePrefix}instanceManager: instanceManager);'; @@ -357,7 +355,7 @@ abstract class $_proxyApiBaseClassName { } '''; -const String proxyApiCodec = ''' +const String proxyApiBaseCodec = ''' class $_proxyApiCodecName extends StandardMessageCodec { const $_proxyApiCodecName(this.instanceManager); final $instanceManagerClassName instanceManager; diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index c3dce2ce2ca2..1dc1b54f2d45 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -4,9 +4,11 @@ import 'package:code_builder/code_builder.dart' as cb; import 'package:collection/collection.dart' as collection; +import 'package:dart_style/dart_style.dart'; import 'package:path/path.dart' as path; import 'ast.dart'; +import 'dart/templates.dart'; import 'functional.dart'; import 'generator.dart'; import 'generator_tools.dart'; @@ -450,696 +452,202 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; }); } - Iterable _proxyApiConstructors( - Iterable constructors, { - required String apiName, + @override + void writeInstanceManager( + DartOptions generatorOptions, + Root root, + Indent indent, { required String dartPackageName, - required String codecName, - required String codecInstanceName, - required AstProxyApi? superClassApi, - required Iterable unattachedFields, - required Iterable superClassFlutterMethods, - required Iterable interfacesMethods, - required Iterable flutterMethods, }) { - final cb.Parameter binaryMessengerParameter = cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = '${classMemberNamePrefix}binaryMessenger' - ..named = true - ..toSuper = true, - ); - final cb.Parameter instanceManagerParameter = cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = _instanceManagerVarName - ..named = true - ..toSuper = true, - ); - return [ - // All constructors for this api defined in the pigeon file. - ...constructors.map( - (Constructor constructor) => cb.Constructor( - (cb.ConstructorBuilder builder) { - final String channelName = makeChannelNameWithStrings( - apiName: apiName, - methodName: constructor.name.isNotEmpty - ? constructor.name - : '${classMemberNamePrefix}defaultConstructor', - dartPackageName: dartPackageName, - ); - builder - ..name = constructor.name.isNotEmpty ? constructor.name : null - ..docs.addAll(asDocumentationComments( - constructor.documentationComments, - _docCommentSpec, - )) - ..optionalParameters.addAll( - [ - binaryMessengerParameter, - instanceManagerParameter, - for (final ApiField field in unattachedFields) - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = field.name - ..named = true - ..toThis = true - ..required = !field.type.isNullable, - ), - for (final Method method in superClassFlutterMethods - .followedBy(interfacesMethods) - .followedBy(flutterMethods)) - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = method.name - ..named = true - ..toSuper = true - ..required = method.isRequired, - ), - ...constructor.parameters.mapIndexed( - (int index, NamedType parameter) => cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = _getParameterName(index, parameter) - ..type = _refer(parameter.type) - ..named = true - ..required = !parameter.type.isNullable, - ), - ) - ], - ) - ..initializers.addAll( - [ - if (superClassApi != null) - const cb.Code('super.${classMemberNamePrefix}detached()') - ], - ) - ..body = cb.Block( - (cb.BlockBuilder builder) { - final StringBuffer messageCallSink = StringBuffer(); - _writeHostMethodMessageCall( - Indent(messageCallSink), - channelName: channelName, - parameters: [ - Parameter( - name: '${_varNamePrefix}instanceIdentifier', - type: const TypeDeclaration( - baseName: 'int', - isNullable: false, - ), - ), - ...unattachedFields.map( - (ApiField field) => Parameter( - name: field.name, - type: field.type, - ), - ), - ...constructor.parameters, - ], - returnType: const TypeDeclaration.voidDeclaration(), - ); - builder.statements.addAll([ - const cb.Code( - 'final int ${_varNamePrefix}instanceIdentifier = $_instanceManagerVarName.addDartCreatedInstance(this);', - ), - cb.Code('final $codecName $_pigeonChannelCodec =\n' - ' $codecInstanceName;'), - cb.Code( - 'final BinaryMessenger? ${_varNamePrefix}binaryMessenger = ${binaryMessengerParameter.name};', - ), - const cb.Code('() async {'), - cb.Code(messageCallSink.toString()), - const cb.Code('}();'), - ]); - }, - ); - }, - ), + indent.writeln( + instanceManagerTemplate( + proxyApiBaseClassName: '${classMemberNamePrefix}ProxyApiBaseClass', + allProxyApiNames: root.apis + .whereType() + .map((AstProxyApi api) => api.name), ), - // The detached constructor present for every ProxyApi. This constructor - // doesn't include a host method call to create a new native class - // instance. It is mainly used when the native side once to create a Dart - // instance and when the `InstanceManager` wants to create a copy for - // garbage collection. - cb.Constructor( - (cb.ConstructorBuilder builder) => builder - ..name = '${classMemberNamePrefix}detached' - ..docs.addAll([ - '/// Constructs $apiName without creating the associated native object.', - '///', - '/// This should only be used by subclasses created by this library or to', - '/// create copies for an [$instanceManagerClassName].', - ]) - ..optionalParameters.addAll([ - binaryMessengerParameter, - instanceManagerParameter, - for (final ApiField field in unattachedFields) - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = field.name - ..named = true - ..toThis = true - ..required = !field.type.isNullable, - ), - for (final Method method in superClassFlutterMethods - .followedBy(interfacesMethods) - .followedBy(flutterMethods)) - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = method.name - ..named = true - ..toSuper = true - ..required = method.isRequired, - ), - ]) - ..initializers.addAll([ - if (superClassApi != null) - const cb.Code('super.${classMemberNamePrefix}detached()'), - ]), + ); + } + + @override + void writeInstanceManagerApi( + DartOptions generatorOptions, + Root root, + Indent indent, { + required String dartPackageName, + }) { + indent.writeln( + instanceManagerApiTemplate( + dartPackageName: dartPackageName, + pigeonChannelCodecVarName: _pigeonChannelCodec, ), - ]; + ); } - Iterable _proxyApiFields({ - required Iterable unattachedFields, - required Iterable attachedFields, - required String apiName, + @override + void writeProxyApiBaseCodec( + DartOptions generatorOptions, + Root root, + Indent indent, + ) { + indent.writeln(proxyApiBaseCodec); + } + + @override + void writeProxyApi( + DartOptions generatorOptions, + Root root, + Indent indent, + AstProxyApi api, { required String dartPackageName, - required String codecInstanceName, - required String codecName, - required Iterable interfacesApis, - required Iterable flutterMethods, - required bool referencesCodecInstance, }) { - return [ - if (referencesCodecInstance) - cb.Field( - (cb.FieldBuilder builder) => builder - ..name = codecInstanceName - ..type = cb.refer(codecName) - ..late = true - ..modifier = cb.FieldModifier.final$ - ..assignment = cb.Code('$codecName($_instanceManagerVarName)'), - ), - for (final ApiField field in unattachedFields) - cb.Field( - (cb.FieldBuilder builder) => builder - ..name = field.name - ..type = cb.refer(_addGenericTypesNullable(field.type)) - ..modifier = cb.FieldModifier.final$ - ..docs.addAll(asDocumentationComments( - field.documentationComments, - _docCommentSpec, - )), - ), - for (final Method method in flutterMethods) - cb.Field( - (cb.FieldBuilder builder) => builder - ..name = method.name - ..modifier = cb.FieldModifier.final$ - ..docs.addAll(asDocumentationComments( - [ - ...method.documentationComments, - ...[ - if (method.documentationComments.isNotEmpty) '', - 'Dart:', - 'For the associated Native object to be automatically garbage collected,', - "it is required that the implementation of this `Function` doesn't have a", - 'strong reference to the encapsulating class instance. When this `Function`', - 'references a non-local variable, it is strongly recommended to access it', - 'from a `WeakReference`:', - '', - '```dart', - 'final WeakReference weakMyVariable = WeakReference(myVariable);', - 'final $apiName instance = $apiName(', - ' ${method.name}: ($apiName ${classMemberNamePrefix}instance, ...) {', - ' print(weakMyVariable?.target);', - ' },', - ');', - '```', - '', - 'Alternatively, `$instanceManagerClassName.removeWeakReference` can be used to', - 'release the associated Native object manually.', - ], - ], - _docCommentSpec, - )) - ..type = cb.FunctionType( - (cb.FunctionTypeBuilder builder) => builder - ..returnType = _refer( - method.returnType, - asFuture: method.isAsynchronous, - ) - ..isNullable = !method.isRequired - ..requiredParameters.addAll([ - cb.refer('$apiName ${classMemberNamePrefix}instance'), - ...method.parameters.mapIndexed( - (int index, NamedType parameter) { - return cb.refer( - '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', - ); - }, - ), - ]), + const String codecName = '_${classNamePrefix}ProxyApiBaseCodec'; + + // Each api has a private codec instance used by every host method, + // constructor, or non-static field. + final String codecInstanceName = '${_varNamePrefix}codec${api.name}'; + + // A list of ProxyApis where each `extends` the API that follows it. + final List superClassApisChain = + recursiveGetSuperClassApisChain( + api, + ); + + // All ProxyApis this API `implements` and all the interfaces those APIs + // `implements`. + final Set interfacesApis = recursiveFindAllInterfaceApis(api); + + // All methods inherited from interfaces and the interfaces of interfaces. + final List interfacesMethods = []; + for (final AstProxyApi proxyApi in interfacesApis) { + interfacesMethods.addAll(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`. + final List superClassFlutterMethods = []; + for (final AstProxyApi proxyApi in superClassApisChain.reversed) { + superClassFlutterMethods.addAll(proxyApi.flutterMethods); + } + if (api.superClass != null) { + final Set superClassInterfacesApis = + recursiveFindAllInterfaceApis( + api.superClass!.associatedProxyApi!, + ); + for (final AstProxyApi proxyApi in superClassInterfacesApis) { + superClassFlutterMethods.addAll(proxyApi.methods); + } + } + + // Ast class used by code_builder to generate the code. + final cb.Class proxyApi = cb.Class( + (cb.ClassBuilder builder) => builder + ..name = api.name + ..extend = api.superClass != null + ? cb.refer(api.superClass!.baseName) + : cb.refer('${classNamePrefix}ProxyApiBaseClass') + ..implements.addAll( + api.interfaces.map( + (TypeDeclaration type) => cb.refer(type.baseName), + ), + ) + ..docs.addAll( + asDocumentationComments(api.documentationComments, _docCommentSpec), + ) + ..constructors.addAll(_proxyApiConstructors( + api.constructors, + apiName: api.name, + dartPackageName: dartPackageName, + codecName: codecName, + codecInstanceName: codecInstanceName, + superClassApi: api.superClass?.associatedProxyApi, + unattachedFields: api.unattachedFields, + declaredAndInheritedFlutterMethods: superClassFlutterMethods + .followedBy(interfacesMethods) + .followedBy(api.flutterMethods), + )) + ..constructors.add( + _proxyApiDetachedConstructor( + apiName: api.name, + superClassApi: api.superClass?.associatedProxyApi, + unattachedFields: api.unattachedFields, + declaredAndInheritedFlutterMethods: superClassFlutterMethods + .followedBy(interfacesMethods) + .followedBy(api.flutterMethods), + ), + ) + ..fields.addAll([ + if (api.methods.isNotEmpty || + api.constructors.isNotEmpty || + api.attachedFields.any((ApiField field) => !field.isStatic)) + _proxyApiCodecInstanceField( + codecInstanceName: codecInstanceName, + codecName: codecName, ), - ), - for (final AstProxyApi proxyApi in interfacesApis) - for (final Method method in proxyApi.methods) - cb.Field( - (cb.FieldBuilder builder) => builder - ..name = method.name - ..modifier = cb.FieldModifier.final$ - ..annotations.add(cb.refer('override')) - ..docs.addAll(asDocumentationComments( - method.documentationComments, - _docCommentSpec, - )) - ..type = cb.FunctionType( - (cb.FunctionTypeBuilder builder) => builder - ..returnType = _refer( - method.returnType, - asFuture: method.isAsynchronous, - ) - ..isNullable = !method.isRequired - ..requiredParameters.addAll([ - cb.refer( - '${proxyApi.name} ${classMemberNamePrefix}instance', - ), - ...method.parameters.mapIndexed( - (int index, NamedType parameter) { - return cb.refer( - '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', - ); - }, - ), - ]), - ), + ]) + ..fields.addAll(_proxyApiUnattachedFields(api.unattachedFields)) + ..fields.addAll(_proxyApiFlutterMethodFields( + api.flutterMethods, + apiName: api.name, + )) + ..fields.addAll(_proxyApiInterfaceApiFields(interfacesApis)) + ..fields.addAll(_proxyApiattachedFields(api.attachedFields)) + ..methods.add( + _proxyApiSetUpMessageHandlerMethod( + flutterMethods: api.flutterMethods, + apiName: api.name, + dartPackageName: dartPackageName, + codecName: codecName, + unattachedFields: api.unattachedFields, + hasCallbackConstructor: api.methods + .followedBy(superClassFlutterMethods) + .followedBy(interfacesMethods) + .every((Method method) => !method.isRequired), ), - for (final ApiField field in attachedFields) - cb.Field( - (cb.FieldBuilder builder) => builder - ..name = field.name - ..type = cb.refer(_addGenericTypesNullable(field.type)) - ..modifier = cb.FieldModifier.final$ - ..static = field.isStatic - ..late = !field.isStatic - ..docs.addAll(asDocumentationComments( - field.documentationComments, - _docCommentSpec, - )) - ..assignment = cb.Code('$_varNamePrefix${field.name}()'), - ), - ]; + ) + ..methods.addAll( + _proxyApiAttachedFieldMethods( + api.attachedFields, + apiName: api.name, + dartPackageName: dartPackageName, + codecInstanceName: codecInstanceName, + codecName: codecName, + ), + ) + ..methods.addAll(_proxyApiHostMethods( + api.hostMethods, + apiName: api.name, + dartPackageName: dartPackageName, + codecInstanceName: codecInstanceName, + codecName: codecName, + )) + ..methods.add(_proxyApiCopyMethod( + flutterMethods: api.flutterMethods, + superClassFlutterMethods: superClassFlutterMethods, + apiName: api.name, + unattachedFields: api.unattachedFields, + interfacesApis: interfacesApis, + )), + ); + + final cb.DartEmitter emitter = cb.DartEmitter(useNullSafetySyntax: true); + indent.write(DartFormatter().format('${proxyApi.accept(emitter)}')); } - Iterable _proxyApiMethods({ - required Iterable hostMethods, - required Iterable flutterMethods, - required Iterable superClassFlutterMethods, - required String apiName, + /// Generates Dart source code for test support libraries based on the given AST + /// represented by [root], outputting the code to [sink]. [sourceOutPath] is the + /// path of the generated dart code to be tested. [testOutPath] is where the + /// test code will be generated. + void generateTest( + DartOptions generatorOptions, + Root root, + StringSink sink, { required String dartPackageName, - required String codecInstanceName, - required String codecName, - required Iterable unattachedFields, - required Iterable attachedFields, - required Iterable interfacesApis, - required bool hasCallbackConstructor, - }) { - return [ - // Flutter methods message handler `*setUpMessageHandlers()` - cb.Method.returnsVoid( - (cb.MethodBuilder builder) => builder - ..name = '${classMemberNamePrefix}setUpMessageHandlers' - ..returns = cb.refer('void') - ..static = true - ..optionalParameters.addAll([ - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = '${classMemberNamePrefix}clearHandlers' - ..type = cb.refer('bool') - ..named = true - ..defaultTo = const cb.Code('false'), - ), - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = '${classMemberNamePrefix}binaryMessenger' - ..named = true - ..type = cb.refer('BinaryMessenger?'), - ), - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = _instanceManagerVarName - ..named = true - ..type = cb.refer('$instanceManagerClassName?'), - ), - if (hasCallbackConstructor) - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = '${classMemberNamePrefix}newInstance' - ..named = true - ..type = cb.FunctionType( - (cb.FunctionTypeBuilder builder) => builder - ..returnType = cb.refer(apiName) - ..isNullable = true - ..requiredParameters.addAll( - unattachedFields.mapIndexed( - (int index, ApiField field) { - return cb.refer( - '${_addGenericTypesNullable(field.type)} ${_getParameterName(index, field)}', - ); - }, - ), - ), - ), - ), - for (final Method method in flutterMethods) - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = method.name - ..type = cb.FunctionType( - (cb.FunctionTypeBuilder builder) => builder - ..returnType = _refer( - method.returnType, - asFuture: method.isAsynchronous, - ) - ..isNullable = true - ..requiredParameters.addAll([ - cb.refer('$apiName ${classMemberNamePrefix}instance'), - ...method.parameters.mapIndexed( - (int index, NamedType parameter) { - return cb.refer( - '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', - ); - }, - ), - ]), - ), - ), - ]) - ..body = cb.Block.of([ - cb.Code( - 'final $codecName $_pigeonChannelCodec = $codecName($_instanceManagerVarName ?? $instanceManagerClassName.instance);', - ), - const cb.Code( - 'final BinaryMessenger? binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', - ), - if (hasCallbackConstructor) - ...cb.Block((cb.BlockBuilder builder) { - final StringBuffer messageHandlerSink = StringBuffer(); - const String methodName = '${classMemberNamePrefix}newInstance'; - _writeFlutterMethodMessageHandler( - Indent(messageHandlerSink), - name: methodName, - parameters: [ - Parameter( - name: '${classMemberNamePrefix}instanceIdentifier', - type: const TypeDeclaration( - baseName: 'int', - isNullable: false, - ), - ), - ...unattachedFields.map( - (ApiField field) => - Parameter(name: field.name, type: field.type), - ), - ], - returnType: const TypeDeclaration.voidDeclaration(), - channelName: makeChannelNameWithStrings( - apiName: apiName, - methodName: methodName, - dartPackageName: dartPackageName, - ), - isMockHandler: false, - isAsynchronous: false, - nullHandlerExpression: - '${classMemberNamePrefix}clearHandlers', - onCreateApiCall: ( - String methodName, - Iterable parameters, - Iterable safeArgumentNames, - ) { - final String argsAsNamedParams = map2( - parameters, - safeArgumentNames, - (Parameter parameter, String safeArgName) { - return '${parameter.name}: $safeArgName,\n'; - }, - ).skip(1).join(); - return '($_instanceManagerVarName ?? $instanceManagerClassName.instance)\n' - ' .addHostCreatedInstance(\n' - ' $methodName?.call(${safeArgumentNames.skip(1).join(',')}) ??\n' - ' $apiName.${classMemberNamePrefix}detached(' - ' ${classMemberNamePrefix}binaryMessenger: ${classMemberNamePrefix}binaryMessenger,\n' - ' $_instanceManagerVarName: $_instanceManagerVarName,\n' - ' $argsAsNamedParams\n' - ' ),\n' - ' ${safeArgumentNames.first},\n' - ')'; - }, - ); - builder.statements.add(cb.Code(messageHandlerSink.toString())); - }).statements, - for (final Method method in flutterMethods) - ...cb.Block((cb.BlockBuilder builder) { - final StringBuffer messageHandlerSink = StringBuffer(); - _writeFlutterMethodMessageHandler( - Indent(messageHandlerSink), - name: method.name, - parameters: [ - Parameter( - name: '${classMemberNamePrefix}instance', - type: TypeDeclaration( - baseName: apiName, - isNullable: false, - ), - ), - ...method.parameters, - ], - returnType: TypeDeclaration( - baseName: method.returnType.baseName, - isNullable: - !method.isRequired || method.returnType.isNullable, - typeArguments: method.returnType.typeArguments, - associatedEnum: method.returnType.associatedEnum, - associatedClass: method.returnType.associatedClass, - associatedProxyApi: method.returnType.associatedProxyApi, - ), - channelName: makeChannelNameWithStrings( - apiName: apiName, - methodName: method.name, - dartPackageName: dartPackageName, - ), - isMockHandler: false, - isAsynchronous: method.isAsynchronous, - nullHandlerExpression: - '${classMemberNamePrefix}clearHandlers', - onCreateApiCall: ( - String methodName, - Iterable parameters, - Iterable safeArgumentNames, - ) { - final String nullability = method.isRequired ? '' : '?'; - return '($methodName ?? ${safeArgumentNames.first}.$methodName)$nullability.call(${safeArgumentNames.join(',')})'; - }, - ); - builder.statements.add(cb.Code(messageHandlerSink.toString())); - }).statements, - ]), - ), - for (final ApiField field in attachedFields) - cb.Method( - (cb.MethodBuilder builder) { - final String type = _addGenericTypesNullable(field.type); - const String instanceName = '${_varNamePrefix}instance'; - const String identifierInstanceName = - '${_varNamePrefix}instanceIdentifier'; - builder - ..name = '$_varNamePrefix${field.name}' - ..static = field.isStatic - ..returns = cb.refer(type) - ..body = cb.Block( - (cb.BlockBuilder builder) { - final StringBuffer messageCallSink = StringBuffer(); - _writeHostMethodMessageCall( - Indent(messageCallSink), - channelName: makeChannelNameWithStrings( - apiName: apiName, - methodName: field.name, - dartPackageName: dartPackageName, - ), - parameters: [ - if (!field.isStatic) - Parameter( - name: 'this', - type: TypeDeclaration( - baseName: apiName, - isNullable: false, - ), - ), - Parameter( - name: identifierInstanceName, - type: const TypeDeclaration( - baseName: 'int', - isNullable: false, - ), - ), - ], - returnType: const TypeDeclaration.voidDeclaration(), - ); - builder.statements.addAll([ - if (!field.isStatic) ...[ - cb.Code( - 'final $type $instanceName = $type.${classMemberNamePrefix}detached(\n' - ' pigeon_binaryMessenger: pigeon_binaryMessenger,\n' - ' pigeon_instanceManager: pigeon_instanceManager,\n' - ');', - ), - cb.Code('final $codecName $_pigeonChannelCodec =\n' - ' $codecInstanceName;'), - const cb.Code( - 'final BinaryMessenger? ${_varNamePrefix}binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', - ), - const cb.Code( - 'final int $identifierInstanceName = $_instanceManagerVarName.addDartCreatedInstance($instanceName);', - ), - ] else ...[ - cb.Code( - 'final $type $instanceName = $type.${classMemberNamePrefix}detached();', - ), - cb.Code( - 'final $codecName $_pigeonChannelCodec = $codecName($instanceManagerClassName.instance);', - ), - const cb.Code( - 'final BinaryMessenger ${_varNamePrefix}binaryMessenger = ServicesBinding.instance.defaultBinaryMessenger;', - ), - const cb.Code( - 'final int $identifierInstanceName = $instanceManagerClassName.instance.addDartCreatedInstance($instanceName);', - ), - ], - const cb.Code('() async {'), - cb.Code(messageCallSink.toString()), - const cb.Code('}();'), - const cb.Code('return $instanceName;'), - ]); - }, - ); - }, - ), - for (final Method method in hostMethods) - cb.Method( - (cb.MethodBuilder builder) => builder - ..name = method.name - ..static = method.isStatic - ..modifier = cb.MethodModifier.async - ..docs.addAll(asDocumentationComments( - method.documentationComments, - _docCommentSpec, - )) - ..returns = _refer(method.returnType, asFuture: true) - ..requiredParameters.addAll( - method.parameters.mapIndexed( - (int index, NamedType parameter) => cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = _getParameterName(index, parameter) - ..type = cb.refer( - _addGenericTypesNullable(parameter.type), - ), - ), - ), - ) - ..optionalParameters.addAll([ - if (method.isStatic) ...[ - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = '${classMemberNamePrefix}binaryMessenger' - ..type = cb.refer('BinaryMessenger?') - ..named = true, - ), - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = _instanceManagerVarName - ..type = cb.refer('$instanceManagerClassName?'), - ), - ], - ]) - ..body = cb.Block( - (cb.BlockBuilder builder) { - final StringBuffer messageCallSink = StringBuffer(); - _writeHostMethodMessageCall( - Indent(messageCallSink), - channelName: makeChannelNameWithStrings( - apiName: apiName, - methodName: method.name, - dartPackageName: dartPackageName, - ), - parameters: [ - if (!method.isStatic) - Parameter( - name: 'this', - type: TypeDeclaration( - baseName: apiName, - isNullable: false, - ), - ), - ...method.parameters, - ], - returnType: method.returnType, - ); - builder.statements.addAll([ - if (!method.isStatic) - cb.Code('final $codecName $_pigeonChannelCodec =\n' - ' $codecInstanceName;') - else - cb.Code( - 'final $codecName $_pigeonChannelCodec = $codecName($_instanceManagerVarName ?? $instanceManagerClassName.instance);', - ), - const cb.Code( - 'final BinaryMessenger? ${_varNamePrefix}binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', - ), - cb.Code(messageCallSink.toString()), - ]); - }, - ), - ), - cb.Method( - (cb.MethodBuilder builder) => builder - ..name = '${classMemberNamePrefix}copy' - ..returns = cb.refer(apiName) - ..annotations.add(cb.refer('override')) - ..body = cb.Block.of([ - cb - .refer('$apiName.${classMemberNamePrefix}detached') - .call( - [], - { - '${classMemberNamePrefix}binaryMessenger': - cb.refer('${classMemberNamePrefix}binaryMessenger'), - _instanceManagerVarName: cb.refer(_instanceManagerVarName), - for (final ApiField field in unattachedFields) - field.name: cb.refer(field.name), - for (final Method method in superClassFlutterMethods) - method.name: cb.refer(method.name), - for (final AstProxyApi proxyApi in interfacesApis) - for (final Method method in proxyApi.methods) - method.name: cb.refer(method.name), - for (final Method method in flutterMethods) - method.name: cb.refer(method.name), - }, - ) - .returned - .statement, - ]), - ), - ]; - } - - /// Generates Dart source code for test support libraries based on the given AST - /// represented by [root], outputting the code to [sink]. [sourceOutPath] is the - /// path of the generated dart code to be tested. [testOutPath] is where the - /// test code will be generated. - void generateTest( - DartOptions generatorOptions, - Root root, - StringSink sink, { - required String dartPackageName, - required String dartOutputPackageName, + required String dartOutputPackageName, }) { final Indent indent = Indent(sink); final String sourceOutPath = generatorOptions.sourceOutPath ?? ''; @@ -1489,6 +997,733 @@ if (${_varNamePrefix}replyList == null) { ) { return 'api.$methodName(${safeArgumentNames.join(', ')})'; } + + Iterable _proxyApiConstructors( + Iterable constructors, { + required String apiName, + required String dartPackageName, + required String codecName, + required String codecInstanceName, + required AstProxyApi? superClassApi, + required Iterable unattachedFields, + required Iterable declaredAndInheritedFlutterMethods, + }) sync* { + final cb.Parameter binaryMessengerParameter = cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = '${classMemberNamePrefix}binaryMessenger' + ..named = true + ..toSuper = true, + ); + final cb.Parameter instanceManagerParameter = cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = _instanceManagerVarName + ..named = true + ..toSuper = true, + ); + for (final Constructor constructor in constructors) { + yield cb.Constructor( + (cb.ConstructorBuilder builder) { + final String channelName = makeChannelNameWithStrings( + apiName: apiName, + methodName: constructor.name.isNotEmpty + ? constructor.name + : '${classMemberNamePrefix}defaultConstructor', + dartPackageName: dartPackageName, + ); + builder + ..name = constructor.name.isNotEmpty ? constructor.name : null + ..docs.addAll(asDocumentationComments( + constructor.documentationComments, + _docCommentSpec, + )) + ..optionalParameters.addAll( + [ + binaryMessengerParameter, + instanceManagerParameter, + for (final ApiField field in unattachedFields) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = field.name + ..named = true + ..toThis = true + ..required = !field.type.isNullable, + ), + for (final Method method in declaredAndInheritedFlutterMethods) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = method.name + ..named = true + ..toSuper = true + ..required = method.isRequired, + ), + ...constructor.parameters.mapIndexed( + (int index, NamedType parameter) => cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = _getParameterName(index, parameter) + ..type = _refer(parameter.type) + ..named = true + ..required = !parameter.type.isNullable, + ), + ) + ], + ) + ..initializers.addAll( + [ + if (superClassApi != null) + const cb.Code('super.${classMemberNamePrefix}detached()') + ], + ) + ..body = cb.Block( + (cb.BlockBuilder builder) { + final StringBuffer messageCallSink = StringBuffer(); + _writeHostMethodMessageCall( + Indent(messageCallSink), + channelName: channelName, + parameters: [ + Parameter( + name: '${_varNamePrefix}instanceIdentifier', + type: const TypeDeclaration( + baseName: 'int', + isNullable: false, + ), + ), + ...unattachedFields.map( + (ApiField field) => Parameter( + name: field.name, + type: field.type, + ), + ), + ...constructor.parameters, + ], + returnType: const TypeDeclaration.voidDeclaration(), + ); + + builder.statements.addAll([ + const cb.Code( + 'final int ${_varNamePrefix}instanceIdentifier = $_instanceManagerVarName.addDartCreatedInstance(this);', + ), + cb.Code('final $codecName $_pigeonChannelCodec =\n' + ' $codecInstanceName;'), + cb.Code( + 'final BinaryMessenger? ${_varNamePrefix}binaryMessenger = ${binaryMessengerParameter.name};', + ), + const cb.Code('() async {'), + cb.Code(messageCallSink.toString()), + const cb.Code('}();'), + ]); + }, + ); + }, + ); + } + } + + /// The detached constructor present for every ProxyApi. + /// + /// This constructor doesn't include a host method call to create a new native + /// class instance. It is mainly used when the native side once to create a + /// Dart instance and when the `InstanceManager` wants to create a copy for + /// garbage collection. + cb.Constructor _proxyApiDetachedConstructor({ + required String apiName, + required AstProxyApi? superClassApi, + required Iterable unattachedFields, + required Iterable declaredAndInheritedFlutterMethods, + }) { + final cb.Parameter binaryMessengerParameter = cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = '${classMemberNamePrefix}binaryMessenger' + ..named = true + ..toSuper = true, + ); + final cb.Parameter instanceManagerParameter = cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = _instanceManagerVarName + ..named = true + ..toSuper = true, + ); + return cb.Constructor( + (cb.ConstructorBuilder builder) => builder + ..name = '${classMemberNamePrefix}detached' + ..docs.addAll([ + '/// Constructs $apiName without creating the associated native object.', + '///', + '/// This should only be used by subclasses created by this library or to', + '/// create copies for an [$instanceManagerClassName].', + ]) + ..optionalParameters.addAll([ + binaryMessengerParameter, + instanceManagerParameter, + for (final ApiField field in unattachedFields) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = field.name + ..named = true + ..toThis = true + ..required = !field.type.isNullable, + ), + for (final Method method in declaredAndInheritedFlutterMethods) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = method.name + ..named = true + ..toSuper = true + ..required = method.isRequired, + ), + ]) + ..initializers.addAll([ + if (superClassApi != null) + const cb.Code('super.${classMemberNamePrefix}detached()'), + ]), + ); + } + + cb.Field _proxyApiCodecInstanceField({ + required String codecInstanceName, + required String codecName, + }) { + return cb.Field( + (cb.FieldBuilder builder) => builder + ..name = codecInstanceName + ..type = cb.refer(codecName) + ..late = true + ..modifier = cb.FieldModifier.final$ + ..assignment = cb.Code('$codecName($_instanceManagerVarName)'), + ); + } + + Iterable _proxyApiUnattachedFields( + Iterable fields) sync* { + for (final ApiField field in fields) { + yield cb.Field( + (cb.FieldBuilder builder) => builder + ..name = field.name + ..type = cb.refer(_addGenericTypesNullable(field.type)) + ..modifier = cb.FieldModifier.final$ + ..docs.addAll(asDocumentationComments( + field.documentationComments, + _docCommentSpec, + )), + ); + } + } + + Iterable _proxyApiFlutterMethodFields( + Iterable methods, { + required String apiName, + }) sync* { + for (final Method method in methods) { + yield cb.Field( + (cb.FieldBuilder builder) => builder + ..name = method.name + ..modifier = cb.FieldModifier.final$ + ..docs.addAll(asDocumentationComments( + [ + ...method.documentationComments, + ...[ + if (method.documentationComments.isNotEmpty) '', + 'Dart:', + 'For the associated Native object to be automatically garbage collected,', + "it is required that the implementation of this `Function` doesn't have a", + 'strong reference to the encapsulating class instance. When this `Function`', + 'references a non-local variable, it is strongly recommended to access it', + 'from a `WeakReference`:', + '', + '```dart', + 'final WeakReference weakMyVariable = WeakReference(myVariable);', + 'final $apiName instance = $apiName(', + ' ${method.name}: ($apiName ${classMemberNamePrefix}instance, ...) {', + ' print(weakMyVariable?.target);', + ' },', + ');', + '```', + '', + 'Alternatively, `$instanceManagerClassName.removeWeakReference` can be used to', + 'release the associated Native object manually.', + ], + ], + _docCommentSpec, + )) + ..type = cb.FunctionType( + (cb.FunctionTypeBuilder builder) => builder + ..returnType = _refer( + method.returnType, + asFuture: method.isAsynchronous, + ) + ..isNullable = !method.isRequired + ..requiredParameters.addAll([ + cb.refer('$apiName ${classMemberNamePrefix}instance'), + ...method.parameters.mapIndexed( + (int index, NamedType parameter) { + return cb.refer( + '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', + ); + }, + ), + ]), + ), + ); + } + } + + Iterable _proxyApiInterfaceApiFields( + Iterable apis, + ) sync* { + for (final AstProxyApi proxyApi in apis) { + for (final Method method in proxyApi.methods) { + yield cb.Field( + (cb.FieldBuilder builder) => builder + ..name = method.name + ..modifier = cb.FieldModifier.final$ + ..annotations.add(cb.refer('override')) + ..docs.addAll(asDocumentationComments( + method.documentationComments, + _docCommentSpec, + )) + ..type = cb.FunctionType( + (cb.FunctionTypeBuilder builder) => builder + ..returnType = _refer( + method.returnType, + asFuture: method.isAsynchronous, + ) + ..isNullable = !method.isRequired + ..requiredParameters.addAll([ + cb.refer( + '${proxyApi.name} ${classMemberNamePrefix}instance', + ), + ...method.parameters.mapIndexed( + (int index, NamedType parameter) { + return cb.refer( + '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', + ); + }, + ), + ]), + ), + ); + } + } + } + + Iterable _proxyApiattachedFields(Iterable fields) sync* { + for (final ApiField field in fields) { + yield cb.Field( + (cb.FieldBuilder builder) => builder + ..name = field.name + ..type = cb.refer(_addGenericTypesNullable(field.type)) + ..modifier = cb.FieldModifier.final$ + ..static = field.isStatic + ..late = !field.isStatic + ..docs.addAll(asDocumentationComments( + field.documentationComments, + _docCommentSpec, + )) + ..assignment = cb.Code('$_varNamePrefix${field.name}()'), + ); + } + } + + cb.Method _proxyApiSetUpMessageHandlerMethod({ + required Iterable flutterMethods, + required String apiName, + required String dartPackageName, + required String codecName, + required Iterable unattachedFields, + required bool hasCallbackConstructor, + }) { + return cb.Method.returnsVoid( + (cb.MethodBuilder builder) => builder + ..name = '${classMemberNamePrefix}setUpMessageHandlers' + ..returns = cb.refer('void') + ..static = true + ..optionalParameters.addAll([ + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = '${classMemberNamePrefix}clearHandlers' + ..type = cb.refer('bool') + ..named = true + ..defaultTo = const cb.Code('false'), + ), + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = '${classMemberNamePrefix}binaryMessenger' + ..named = true + ..type = cb.refer('BinaryMessenger?'), + ), + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = _instanceManagerVarName + ..named = true + ..type = cb.refer('$instanceManagerClassName?'), + ), + if (hasCallbackConstructor) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = '${classMemberNamePrefix}newInstance' + ..named = true + ..type = cb.FunctionType( + (cb.FunctionTypeBuilder builder) => builder + ..returnType = cb.refer(apiName) + ..isNullable = true + ..requiredParameters.addAll( + unattachedFields.mapIndexed( + (int index, ApiField field) { + return cb.refer( + '${_addGenericTypesNullable(field.type)} ${_getParameterName(index, field)}', + ); + }, + ), + ), + ), + ), + for (final Method method in flutterMethods) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = method.name + ..type = cb.FunctionType( + (cb.FunctionTypeBuilder builder) => builder + ..returnType = _refer( + method.returnType, + asFuture: method.isAsynchronous, + ) + ..isNullable = true + ..requiredParameters.addAll([ + cb.refer('$apiName ${classMemberNamePrefix}instance'), + ...method.parameters.mapIndexed( + (int index, NamedType parameter) { + return cb.refer( + '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', + ); + }, + ), + ]), + ), + ), + ]) + ..body = cb.Block.of([ + cb.Code( + 'final $codecName $_pigeonChannelCodec = $codecName($_instanceManagerVarName ?? $instanceManagerClassName.instance);', + ), + const cb.Code( + 'final BinaryMessenger? binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', + ), + if (hasCallbackConstructor) + ...cb.Block((cb.BlockBuilder builder) { + final StringBuffer messageHandlerSink = StringBuffer(); + const String methodName = '${classMemberNamePrefix}newInstance'; + _writeFlutterMethodMessageHandler( + Indent(messageHandlerSink), + name: methodName, + parameters: [ + Parameter( + name: '${classMemberNamePrefix}instanceIdentifier', + type: const TypeDeclaration( + baseName: 'int', + isNullable: false, + ), + ), + ...unattachedFields.map( + (ApiField field) { + return Parameter(name: field.name, type: field.type); + }, + ), + ], + returnType: const TypeDeclaration.voidDeclaration(), + channelName: makeChannelNameWithStrings( + apiName: apiName, + methodName: methodName, + dartPackageName: dartPackageName, + ), + isMockHandler: false, + isAsynchronous: false, + nullHandlerExpression: '${classMemberNamePrefix}clearHandlers', + onCreateApiCall: ( + String methodName, + Iterable parameters, + Iterable safeArgumentNames, + ) { + final String argsAsNamedParams = map2( + parameters, + safeArgumentNames, + (Parameter parameter, String safeArgName) { + return '${parameter.name}: $safeArgName,\n'; + }, + ).skip(1).join(); + return '($_instanceManagerVarName ?? $instanceManagerClassName.instance)\n' + ' .addHostCreatedInstance(\n' + ' $methodName?.call(${safeArgumentNames.skip(1).join(',')}) ??\n' + ' $apiName.${classMemberNamePrefix}detached(' + ' ${classMemberNamePrefix}binaryMessenger: ${classMemberNamePrefix}binaryMessenger,\n' + ' $_instanceManagerVarName: $_instanceManagerVarName,\n' + ' $argsAsNamedParams\n' + ' ),\n' + ' ${safeArgumentNames.first},\n' + ')'; + }, + ); + builder.statements.add(cb.Code(messageHandlerSink.toString())); + }).statements, + for (final Method method in flutterMethods) + ...cb.Block((cb.BlockBuilder builder) { + final StringBuffer messageHandlerSink = StringBuffer(); + _writeFlutterMethodMessageHandler( + Indent(messageHandlerSink), + name: method.name, + parameters: [ + Parameter( + name: '${classMemberNamePrefix}instance', + type: TypeDeclaration( + baseName: apiName, + isNullable: false, + ), + ), + ...method.parameters, + ], + returnType: TypeDeclaration( + baseName: method.returnType.baseName, + isNullable: + !method.isRequired || method.returnType.isNullable, + typeArguments: method.returnType.typeArguments, + associatedEnum: method.returnType.associatedEnum, + associatedClass: method.returnType.associatedClass, + associatedProxyApi: method.returnType.associatedProxyApi, + ), + channelName: makeChannelNameWithStrings( + apiName: apiName, + methodName: method.name, + dartPackageName: dartPackageName, + ), + isMockHandler: false, + isAsynchronous: method.isAsynchronous, + nullHandlerExpression: '${classMemberNamePrefix}clearHandlers', + onCreateApiCall: ( + String methodName, + Iterable parameters, + Iterable safeArgumentNames, + ) { + final String nullability = method.isRequired ? '' : '?'; + return '($methodName ?? ${safeArgumentNames.first}.$methodName)$nullability.call(${safeArgumentNames.join(',')})'; + }, + ); + builder.statements.add(cb.Code(messageHandlerSink.toString())); + }).statements, + ]), + ); + } + + Iterable _proxyApiAttachedFieldMethods( + Iterable fields, { + required String apiName, + required String dartPackageName, + required String codecInstanceName, + required String codecName, + }) sync* { + for (final ApiField field in fields) { + yield cb.Method( + (cb.MethodBuilder builder) { + final String type = _addGenericTypesNullable(field.type); + const String instanceName = '${_varNamePrefix}instance'; + const String identifierInstanceName = + '${_varNamePrefix}instanceIdentifier'; + builder + ..name = '$_varNamePrefix${field.name}' + ..static = field.isStatic + ..returns = cb.refer(type) + ..body = cb.Block( + (cb.BlockBuilder builder) { + final StringBuffer messageCallSink = StringBuffer(); + _writeHostMethodMessageCall( + Indent(messageCallSink), + channelName: makeChannelNameWithStrings( + apiName: apiName, + methodName: field.name, + dartPackageName: dartPackageName, + ), + parameters: [ + if (!field.isStatic) + Parameter( + name: 'this', + type: TypeDeclaration( + baseName: apiName, + isNullable: false, + ), + ), + Parameter( + name: identifierInstanceName, + type: const TypeDeclaration( + baseName: 'int', + isNullable: false, + ), + ), + ], + returnType: const TypeDeclaration.voidDeclaration(), + ); + builder.statements.addAll([ + if (!field.isStatic) ...[ + cb.Code( + 'final $type $instanceName = $type.${classMemberNamePrefix}detached(\n' + ' pigeon_binaryMessenger: pigeon_binaryMessenger,\n' + ' pigeon_instanceManager: pigeon_instanceManager,\n' + ');', + ), + cb.Code('final $codecName $_pigeonChannelCodec =\n' + ' $codecInstanceName;'), + const cb.Code( + 'final BinaryMessenger? ${_varNamePrefix}binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', + ), + const cb.Code( + 'final int $identifierInstanceName = $_instanceManagerVarName.addDartCreatedInstance($instanceName);', + ), + ] else ...[ + cb.Code( + 'final $type $instanceName = $type.${classMemberNamePrefix}detached();', + ), + cb.Code( + 'final $codecName $_pigeonChannelCodec = $codecName($instanceManagerClassName.instance);', + ), + const cb.Code( + 'final BinaryMessenger ${_varNamePrefix}binaryMessenger = ServicesBinding.instance.defaultBinaryMessenger;', + ), + const cb.Code( + 'final int $identifierInstanceName = $instanceManagerClassName.instance.addDartCreatedInstance($instanceName);', + ), + ], + const cb.Code('() async {'), + cb.Code(messageCallSink.toString()), + const cb.Code('}();'), + const cb.Code('return $instanceName;'), + ]); + }, + ); + }, + ); + } + } + + Iterable _proxyApiHostMethods( + Iterable methods, { + required String apiName, + required String dartPackageName, + required String codecInstanceName, + required String codecName, + }) sync* { + for (final Method method in methods) { + assert(method.location == ApiLocation.host); + yield cb.Method( + (cb.MethodBuilder builder) => builder + ..name = method.name + ..static = method.isStatic + ..modifier = cb.MethodModifier.async + ..docs.addAll(asDocumentationComments( + method.documentationComments, + _docCommentSpec, + )) + ..returns = _refer(method.returnType, asFuture: true) + ..requiredParameters.addAll( + method.parameters.mapIndexed( + (int index, NamedType parameter) => cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = _getParameterName(index, parameter) + ..type = cb.refer( + _addGenericTypesNullable(parameter.type), + ), + ), + ), + ) + ..optionalParameters.addAll([ + if (method.isStatic) ...[ + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = '${classMemberNamePrefix}binaryMessenger' + ..type = cb.refer('BinaryMessenger?') + ..named = true, + ), + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = _instanceManagerVarName + ..type = cb.refer('$instanceManagerClassName?'), + ), + ], + ]) + ..body = cb.Block( + (cb.BlockBuilder builder) { + final StringBuffer messageCallSink = StringBuffer(); + _writeHostMethodMessageCall( + Indent(messageCallSink), + channelName: makeChannelNameWithStrings( + apiName: apiName, + methodName: method.name, + dartPackageName: dartPackageName, + ), + parameters: [ + if (!method.isStatic) + Parameter( + name: 'this', + type: TypeDeclaration( + baseName: apiName, + isNullable: false, + ), + ), + ...method.parameters, + ], + returnType: method.returnType, + ); + builder.statements.addAll([ + if (!method.isStatic) + cb.Code('final $codecName $_pigeonChannelCodec =\n' + ' $codecInstanceName;') + else + cb.Code( + 'final $codecName $_pigeonChannelCodec = $codecName($_instanceManagerVarName ?? $instanceManagerClassName.instance);', + ), + const cb.Code( + 'final BinaryMessenger? ${_varNamePrefix}binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', + ), + cb.Code(messageCallSink.toString()), + ]); + }, + ), + ); + } + } + + cb.Method _proxyApiCopyMethod({ + required Iterable flutterMethods, + required Iterable superClassFlutterMethods, + required String apiName, + required Iterable unattachedFields, + required Iterable interfacesApis, + }) { + return cb.Method( + (cb.MethodBuilder builder) => builder + ..name = '${classMemberNamePrefix}copy' + ..returns = cb.refer(apiName) + ..annotations.add(cb.refer('override')) + ..body = cb.Block.of([ + cb + .refer('$apiName.${classMemberNamePrefix}detached') + .call( + [], + { + '${classMemberNamePrefix}binaryMessenger': + cb.refer('${classMemberNamePrefix}binaryMessenger'), + _instanceManagerVarName: cb.refer(_instanceManagerVarName), + for (final ApiField field in unattachedFields) + field.name: cb.refer(field.name), + for (final Method method in superClassFlutterMethods) + method.name: cb.refer(method.name), + for (final AstProxyApi proxyApi in interfacesApis) + for (final Method method in proxyApi.methods) + method.name: cb.refer(method.name), + for (final Method method in flutterMethods) + method.name: cb.refer(method.name), + }, + ) + .returned + .statement, + ]), + ); + } } cb.Reference _refer(TypeDeclaration type, {bool asFuture = false}) { From 2dac15de2f86dd19d87294cd98263d5628b03d3b Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 31 Jan 2024 17:03:17 -0500 Subject: [PATCH 19/32] add proxy api base class --- packages/pigeon/lib/dart_generator.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 1dc1b54f2d45..a17c387f46be 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -459,6 +459,8 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; Indent indent, { required String dartPackageName, }) { + indent.writeln(proxyApiBaseClass); + indent.writeln( instanceManagerTemplate( proxyApiBaseClassName: '${classMemberNamePrefix}ProxyApiBaseClass', From 36bbca1d23da40610b87d2b10c1bcf8e0f5e8224 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 2 Feb 2024 12:30:02 -0500 Subject: [PATCH 20/32] add documentation --- packages/pigeon/lib/dart/templates.dart | 8 ++++ packages/pigeon/lib/dart_generator.dart | 58 +++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/packages/pigeon/lib/dart/templates.dart b/packages/pigeon/lib/dart/templates.dart index fe56d16f4fbe..14d25d57dc94 100644 --- a/packages/pigeon/lib/dart/templates.dart +++ b/packages/pigeon/lib/dart/templates.dart @@ -319,6 +319,9 @@ class _$apiName { }'''; } +/// The base class for all ProxyApis. +/// +/// All Dart classes generated as a ProxyApi extends this one. const String proxyApiBaseClass = ''' /// An immutable object that serves as the base class for all ProxyApis and /// can provide functional copies of itself. @@ -355,6 +358,11 @@ abstract class $_proxyApiBaseClassName { } '''; +/// The base codec for ProxyApis. +/// +/// All generated Dart proxy apis should use this codec or extend it. This codec +/// adds support to convert instances to their corresponding identifier from an +/// `InstanceManager` and vice versa. const String proxyApiBaseCodec = ''' class $_proxyApiCodecName extends StandardMessageCodec { const $_proxyApiCodecName(this.instanceManager); diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index a17c387f46be..a26c27f66599 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -597,7 +597,7 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; apiName: api.name, )) ..fields.addAll(_proxyApiInterfaceApiFields(interfacesApis)) - ..fields.addAll(_proxyApiattachedFields(api.attachedFields)) + ..fields.addAll(_proxyApiAttachedFields(api.attachedFields)) ..methods.add( _proxyApiSetUpMessageHandlerMethod( flutterMethods: api.flutterMethods, @@ -1000,6 +1000,8 @@ if (${_varNamePrefix}replyList == null) { return 'api.$methodName(${safeArgumentNames.join(', ')})'; } + /// Converts Constructors from the pigeon AST to a `code_builder` Constructor + /// for a ProxyApi. Iterable _proxyApiConstructors( Iterable constructors, { required String apiName, @@ -1125,7 +1127,7 @@ if (${_varNamePrefix}replyList == null) { /// This constructor doesn't include a host method call to create a new native /// class instance. It is mainly used when the native side once to create a /// Dart instance and when the `InstanceManager` wants to create a copy for - /// garbage collection. + /// automatic garbage collection. cb.Constructor _proxyApiDetachedConstructor({ required String apiName, required AstProxyApi? superClassApi, @@ -1180,6 +1182,7 @@ if (${_varNamePrefix}replyList == null) { ); } + /// A private Field of the base codec. cb.Field _proxyApiCodecInstanceField({ required String codecInstanceName, required String codecName, @@ -1194,8 +1197,11 @@ if (${_varNamePrefix}replyList == null) { ); } + /// Converts unattached constructors from the pigeon AST to `code_builder` + /// Fields. Iterable _proxyApiUnattachedFields( - Iterable fields) sync* { + Iterable fields, + ) sync* { for (final ApiField field in fields) { yield cb.Field( (cb.FieldBuilder builder) => builder @@ -1210,6 +1216,10 @@ if (${_varNamePrefix}replyList == null) { } } + /// Converts Flutter methods from the pigeon AST to `code_builder` Fields. + /// + /// Flutter methods of a ProxyApi are set as an anonymous function of a class + /// instance, so this converts methods to a `Function` type field instance. Iterable _proxyApiFlutterMethodFields( Iterable methods, { required String apiName, @@ -1268,6 +1278,14 @@ if (${_varNamePrefix}replyList == null) { } } + /// Converts the Flutter methods from the pigeon AST to `code_builder` Fields. + /// + /// Flutter methods of a ProxyApi are set as an anonymous function of a class + /// instance, so this converts methods to a `Function` type field instance. + /// + /// This is similar to [_proxyApiFlutterMethodFields] except all the methods are + /// inherited from apis that are being implemented (following the `implements` + /// keyword). Iterable _proxyApiInterfaceApiFields( Iterable apis, ) sync* { @@ -1307,7 +1325,17 @@ if (${_varNamePrefix}replyList == null) { } } - Iterable _proxyApiattachedFields(Iterable fields) sync* { + /// Converts attached Fields from the pigeon AST to `code_builder` Field. + /// + /// Attached fields are set lazily by calling a private method that returns + /// it. + /// + /// Example Output: + /// + /// ```dart + /// final MyOtherProxyApiClass value = _pigeon_value(); + /// ``` + Iterable _proxyApiAttachedFields(Iterable fields) sync* { for (final ApiField field in fields) { yield cb.Field( (cb.FieldBuilder builder) => builder @@ -1325,6 +1353,14 @@ if (${_varNamePrefix}replyList == null) { } } + /// Creates the static `setUpMessageHandlers` method for a ProxyApi. + /// + /// This method handles setting the message handler for every un-inherited + /// Flutter method. + /// + /// This also adds a handler to receive a call from the platform to + /// instantiate a new Dart instance if [hasCallbackConstructor] is set to + /// true. cb.Method _proxyApiSetUpMessageHandlerMethod({ required Iterable flutterMethods, required String apiName, @@ -1513,6 +1549,11 @@ if (${_varNamePrefix}replyList == null) { ); } + /// Converts attached fields from the pigeon AST to `code_builder` fields. + /// + /// These private methods are used to lazily instantiate attached fields. The + /// instance is created and returned synchronously while the native instance + /// is created synchronously. This is similar to how constructors work. Iterable _proxyApiAttachedFieldMethods( Iterable fields, { required String apiName, @@ -1602,6 +1643,10 @@ if (${_varNamePrefix}replyList == null) { } } + /// Converts host methods from pigeon AST to `code_builder` AST. + /// + /// This creates methods like a HostApi except that it includes the calling + /// instance if the method is not static. Iterable _proxyApiHostMethods( Iterable methods, { required String apiName, @@ -1689,6 +1734,11 @@ if (${_varNamePrefix}replyList == null) { } } + /// Creates the copy method for a ProxyApi. + /// + /// This method returns a copy of the instance with all the Flutter methods + /// and unattached fields passed to the new instance. This method is inherited + /// from the base ProxyApi class. cb.Method _proxyApiCopyMethod({ required Iterable flutterMethods, required Iterable superClassFlutterMethods, From afa62e8756accc48350aa9a83f45252e72807c26 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 2 Feb 2024 13:36:33 -0500 Subject: [PATCH 21/32] add tests and some minor validatation improvements --- packages/pigeon/lib/dart/templates.dart | 4 ++ packages/pigeon/lib/dart_generator.dart | 66 ++++++++++++++++--------- packages/pigeon/lib/pigeon_lib.dart | 8 +-- 3 files changed, 52 insertions(+), 26 deletions(-) diff --git a/packages/pigeon/lib/dart/templates.dart b/packages/pigeon/lib/dart/templates.dart index 14d25d57dc94..3459fcd5c242 100644 --- a/packages/pigeon/lib/dart/templates.dart +++ b/packages/pigeon/lib/dart/templates.dart @@ -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. diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index a26c27f66599..d00cfea4c2ee 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -520,9 +520,9 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; final Set interfacesApis = recursiveFindAllInterfaceApis(api); // All methods inherited from interfaces and the interfaces of interfaces. - final List interfacesMethods = []; + final List flutterMethodsFromInterfaces = []; 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 @@ -531,17 +531,17 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; // // This also includes methods that super classes inherited from interfaces // with `implements`. - final List superClassFlutterMethods = []; + final List flutterMethodsFromSuperClasses = []; for (final AstProxyApi proxyApi in superClassApisChain.reversed) { - superClassFlutterMethods.addAll(proxyApi.flutterMethods); + flutterMethodsFromSuperClasses.addAll(proxyApi.flutterMethods); } if (api.superClass != null) { - final Set superClassInterfacesApis = + final Set 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); } } @@ -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([ @@ -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), ), ) @@ -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, @@ -1010,7 +1010,9 @@ if (${_varNamePrefix}replyList == null) { required String codecInstanceName, required AstProxyApi? superClassApi, required Iterable unattachedFields, - required Iterable declaredAndInheritedFlutterMethods, + required Iterable flutterMethodsFromSuperClasses, + required Iterable flutterMethodsFromInterfaces, + required Iterable declaredFlutterMethods, }) sync* { final cb.Parameter binaryMessengerParameter = cb.Parameter( (cb.ParameterBuilder builder) => builder @@ -1052,7 +1054,7 @@ 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 @@ -1060,6 +1062,15 @@ if (${_varNamePrefix}replyList == null) { ..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 @@ -1132,7 +1143,9 @@ if (${_varNamePrefix}replyList == null) { required String apiName, required AstProxyApi? superClassApi, required Iterable unattachedFields, - required Iterable declaredAndInheritedFlutterMethods, + required Iterable flutterMethodsFromSuperClasses, + required Iterable flutterMethodsFromInterfaces, + required Iterable declaredFlutterMethods, }) { final cb.Parameter binaryMessengerParameter = cb.Parameter( (cb.ParameterBuilder builder) => builder @@ -1166,7 +1179,7 @@ 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 @@ -1174,6 +1187,15 @@ if (${_varNamePrefix}replyList == null) { ..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([ if (superClassApi != null) @@ -1741,7 +1763,7 @@ if (${_varNamePrefix}replyList == null) { /// from the base ProxyApi class. cb.Method _proxyApiCopyMethod({ required Iterable flutterMethods, - required Iterable superClassFlutterMethods, + required Iterable flutterMethodsFromSuperClasses, required String apiName, required Iterable unattachedFields, required Iterable interfacesApis, @@ -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) diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 187aa3466b2a..65cabf04ef37 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -1029,10 +1029,10 @@ List _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 interfaceNames = proxyApi.interfaces.map( (TypeDeclaration type) => type.baseName, From 1cd4d95b65661863f11270005801882792a33806 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 2 Feb 2024 13:43:35 -0500 Subject: [PATCH 22/32] add tests actually --- packages/pigeon/pigeons/proxy_api_tests.dart | 471 ++++++++ packages/pigeon/test/dart/proxy_api_test.dart | 1014 +++++++++++++++++ 2 files changed, 1485 insertions(+) create mode 100644 packages/pigeon/pigeons/proxy_api_tests.dart create mode 100644 packages/pigeon/test/dart/proxy_api_test.dart diff --git a/packages/pigeon/pigeons/proxy_api_tests.dart b/packages/pigeon/pigeons/proxy_api_tests.dart new file mode 100644 index 000000000000..c09eebd8239d --- /dev/null +++ b/packages/pigeon/pigeons/proxy_api_tests.dart @@ -0,0 +1,471 @@ +// 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 'package:pigeon/pigeon.dart'; +// TODO(bparrishMines): Remove this import when ProxyApi has an implementation +// for at least one host language. +import 'package:pigeon/pigeon_lib.dart'; + +enum AnEnum { + one, + two, + three, +} + +/// The core interface that each host language plugin must implement in +/// platform_test integration tests. +@ProxyApi() +abstract class ProxyApiTestClass extends ProxyApiSuperClass + implements ProxyApiInterface { + ProxyApiTestClass( + // ignore: avoid_unused_constructor_parameters + bool boolParam, + // ignore: avoid_unused_constructor_parameters + int intParam, + // ignore: avoid_unused_constructor_parameters + double doubleParam, + // ignore: avoid_unused_constructor_parameters + String stringParam, + // ignore: avoid_unused_constructor_parameters + Uint8List aUint8ListParam, + // ignore: avoid_unused_constructor_parameters + List listParam, + // ignore: avoid_unused_constructor_parameters + Map mapParam, + // ignore: avoid_unused_constructor_parameters + AnEnum enumParam, + // ignore: avoid_unused_constructor_parameters + ProxyApiSuperClass proxyApiParam, + // ignore: avoid_unused_constructor_parameters + bool? nullableBoolParam, + // ignore: avoid_unused_constructor_parameters + int? nullableIntParam, + // ignore: avoid_unused_constructor_parameters + double? nullableDoubleParam, + // ignore: avoid_unused_constructor_parameters + String? nullableStringParam, + // ignore: avoid_unused_constructor_parameters + Uint8List? nullableUint8ListParam, + // ignore: avoid_unused_constructor_parameters + List? nullableListParam, + // ignore: avoid_unused_constructor_parameters + Map? nullableMapParam, + // ignore: avoid_unused_constructor_parameters + AnEnum? nullableEnumParam, + // ignore: avoid_unused_constructor_parameters + ProxyApiSuperClass? nullableProxyApiParam, + ); + + late bool aBool; + late int anInt; + late double aDouble; + late String aString; + late Uint8List aUint8List; + late List aList; + late Map aMap; + late AnEnum anEnum; + late ProxyApiSuperClass aProxyApi; + + late bool? aNullableBool; + late int? aNullableInt; + late double? aNullableDouble; + late String? aNullableString; + late Uint8List? aNullableUint8List; + late List? aNullableList; + late Map? aNullableMap; + late AnEnum? aNullableEnum; + late ProxyApiSuperClass? aNullableProxyApi; + + @attached + late ProxyApiSuperClass attachedField; + + @static + late ProxyApiSuperClass staticAttachedField; + + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic calling. + late void Function()? flutterNoop; + + /// Responds with an error from an async function returning a value. + late Object? Function()? flutterThrowError; + + /// Responds with an error from an async void function. + late void Function()? flutterThrowErrorFromVoid; + + // ========== Non-nullable argument/return type tests ========== + + /// Returns the passed boolean, to test serialization and deserialization. + late bool Function(bool aBool)? flutterEchoBool; + + /// Returns the passed int, to test serialization and deserialization. + late int Function(int anInt)? flutterEchoInt; + + /// Returns the passed double, to test serialization and deserialization. + late double Function(double aDouble)? flutterEchoDouble; + + /// Returns the passed string, to test serialization and deserialization. + late String Function(String aString)? flutterEchoString; + + /// Returns the passed byte list, to test serialization and deserialization. + late Uint8List Function(Uint8List aList)? flutterEchoUint8List; + + /// Returns the passed list, to test serialization and deserialization. + late List Function(List aList)? flutterEchoList; + + /// Returns the passed list with ProxyApis, to test serialization and + /// deserialization. + late List Function(List aList)? + flutterEchoProxyApiList; + + /// Returns the passed map, to test serialization and deserialization. + late Map Function(Map aMap)? + flutterEchoMap; + + /// Returns the passed map with ProxyApis, to test serialization and + /// deserialization. + late Map Function( + Map aMap)? flutterEchoProxyApiMap; + + /// Returns the passed enum to test serialization and deserialization. + late AnEnum Function(AnEnum anEnum)? flutterEchoEnum; + + /// Returns the passed ProxyApi to test serialization and deserialization. + late ProxyApiSuperClass Function(ProxyApiSuperClass aProxyApi)? + flutterEchoProxyApi; + + // ========== Nullable argument/return type tests ========== + + /// Returns the passed boolean, to test serialization and deserialization. + late bool? Function(bool? aBool)? flutterEchoNullableBool; + + /// Returns the passed int, to test serialization and deserialization. + late int? Function(int? anInt)? flutterEchoNullableInt; + + /// Returns the passed double, to test serialization and deserialization. + late double? Function(double? aDouble)? flutterEchoNullableDouble; + + /// Returns the passed string, to test serialization and deserialization. + late String? Function(String? aString)? flutterEchoNullableString; + + /// Returns the passed byte list, to test serialization and deserialization. + late Uint8List? Function(Uint8List? aList)? flutterEchoNullableUint8List; + + /// Returns the passed list, to test serialization and deserialization. + late List? Function(List? aList)? flutterEchoNullableList; + + /// Returns the passed map, to test serialization and deserialization. + late Map? Function(Map? aMap)? + flutterEchoNullableMap; + + /// Returns the passed enum to test serialization and deserialization. + late AnEnum? Function(AnEnum? anEnum)? flutterEchoNullableEnum; + + /// Returns the passed ProxyApi to test serialization and deserialization. + late ProxyApiSuperClass? Function(ProxyApiSuperClass? aProxyApi)? + flutterEchoNullableProxyApi; + + // ========== Async tests ========== + // These are minimal since async FlutterApi only changes Dart generation. + // Currently they aren't integration tested, but having them here ensures + // analysis coverage. + + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic asynchronous calling. + @async + late void Function()? flutterNoopAsync; + + /// Returns the passed in generic Object asynchronously. + @async + late String Function(String aString)? flutterEchoAsyncString; + + // ========== Synchronous host method tests ========== + + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic calling. + void noop(); + + /// Returns an error, to test error handling. + Object? throwError(); + + /// Returns an error from a void function, to test error handling. + void throwErrorFromVoid(); + + /// Returns a Flutter error, to test error handling. + Object? throwFlutterError(); + + /// Returns passed in int. + int echoInt(int anInt); + + /// Returns passed in double. + double echoDouble(double aDouble); + + /// Returns the passed in boolean. + bool echoBool(bool aBool); + + /// Returns the passed in string. + String echoString(String aString); + + /// Returns the passed in Uint8List. + Uint8List echoUint8List(Uint8List aUint8List); + + /// Returns the passed in generic Object. + Object echoObject(Object anObject); + + /// Returns the passed list, to test serialization and deserialization. + List echoList(List aList); + + /// Returns the passed list with ProxyApis, to test serialization and + /// deserialization. + List echoProxyApiList( + List aList, + ); + + /// Returns the passed map, to test serialization and deserialization. + Map echoMap(Map aMap); + + /// Returns the passed map with ProxyApis, to test serialization and + /// deserialization. + Map echoProxyApiMap( + Map aMap, + ); + + /// Returns the passed enum to test serialization and deserialization. + AnEnum echoEnum(AnEnum anEnum); + + /// Returns the passed ProxyApi to test serialization and deserialization. + ProxyApiSuperClass echoProxyApi(ProxyApiSuperClass aProxyApi); + + // ========== Synchronous host nullable method tests ========== + + /// Returns passed in int. + int? echoNullableInt(int? aNullableInt); + + /// Returns passed in double. + double? echoNullableDouble(double? aNullableDouble); + + /// Returns the passed in boolean. + bool? echoNullableBool(bool? aNullableBool); + + /// Returns the passed in string. + String? echoNullableString(String? aNullableString); + + /// Returns the passed in Uint8List. + Uint8List? echoNullableUint8List(Uint8List? aNullableUint8List); + + /// Returns the passed in generic Object. + Object? echoNullableObject(Object? aNullableObject); + + /// Returns the passed list, to test serialization and deserialization. + List? echoNullableList(List? aNullableList); + + /// Returns the passed map, to test serialization and deserialization. + Map? echoNullableMap(Map? aNullableMap); + + AnEnum? echoNullableEnum(AnEnum? aNullableEnum); + + /// Returns the passed ProxyApi to test serialization and deserialization. + ProxyApiSuperClass? echoNullableProxyApi( + ProxyApiSuperClass? aNullableProxyApi, + ); + + // ========== Asynchronous method tests ========== + + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic asynchronous calling. + @async + void noopAsync(); + + /// Returns passed in int asynchronously. + @async + int echoAsyncInt(int anInt); + + /// Returns passed in double asynchronously. + @async + double echoAsyncDouble(double aDouble); + + /// Returns the passed in boolean asynchronously. + @async + bool echoAsyncBool(bool aBool); + + /// Returns the passed string asynchronously. + @async + String echoAsyncString(String aString); + + /// Returns the passed in Uint8List asynchronously. + @async + Uint8List echoAsyncUint8List(Uint8List aUint8List); + + /// Returns the passed in generic Object asynchronously. + @async + Object echoAsyncObject(Object anObject); + + /// Returns the passed list, to test asynchronous serialization and deserialization. + @async + List echoAsyncList(List aList); + + /// Returns the passed map, to test asynchronous serialization and deserialization. + @async + Map echoAsyncMap(Map aMap); + + /// Returns the passed enum, to test asynchronous serialization and deserialization. + @async + AnEnum echoAsyncEnum(AnEnum anEnum); + + /// Responds with an error from an async function returning a value. + @async + Object? throwAsyncError(); + + /// Responds with an error from an async void function. + @async + void throwAsyncErrorFromVoid(); + + /// Responds with a Flutter error from an async function returning a value. + @async + Object? throwAsyncFlutterError(); + + /// Returns passed in int asynchronously. + @async + int? echoAsyncNullableInt(int? anInt); + + /// Returns passed in double asynchronously. + @async + double? echoAsyncNullableDouble(double? aDouble); + + /// Returns the passed in boolean asynchronously. + @async + bool? echoAsyncNullableBool(bool? aBool); + + /// Returns the passed string asynchronously. + @async + String? echoAsyncNullableString(String? aString); + + /// Returns the passed in Uint8List asynchronously. + @async + Uint8List? echoAsyncNullableUint8List(Uint8List? aUint8List); + + /// Returns the passed in generic Object asynchronously. + @async + Object? echoAsyncNullableObject(Object? anObject); + + /// Returns the passed list, to test asynchronous serialization and deserialization. + @async + List? echoAsyncNullableList(List? aList); + + /// Returns the passed map, to test asynchronous serialization and deserialization. + @async + Map? echoAsyncNullableMap(Map? aMap); + + /// Returns the passed enum, to test asynchronous serialization and deserialization. + @async + AnEnum? echoAsyncNullableEnum(AnEnum? anEnum); + + // ========== Static method test ========== + + @static + void staticNoop(); + + @static + String echoStaticString(String aString); + + @static + @async + void staticAsyncNoop(); + + // ========== Flutter methods test wrappers ========== + + @async + void callFlutterNoop(); + + @async + Object? callFlutterThrowError(); + + @async + void callFlutterThrowErrorFromVoid(); + + @async + bool callFlutterEchoBool(bool aBool); + + @async + int callFlutterEchoInt(int anInt); + + @async + double callFlutterEchoDouble(double aDouble); + + @async + String callFlutterEchoString(String aString); + + @async + Uint8List callFlutterEchoUint8List(Uint8List aUint8List); + + @async + List callFlutterEchoList(List aList); + + @async + List callFlutterEchoProxyApiList( + List aList); + + @async + Map callFlutterEchoMap(Map aMap); + + @async + Map callFlutterEchoProxyApiMap( + Map aMap); + + @async + AnEnum callFlutterEchoEnum(AnEnum anEnum); + + @async + ProxyApiSuperClass callFlutterEchoProxyApi(ProxyApiSuperClass aProxyApi); + + @async + bool? callFlutterEchoNullableBool(bool? aBool); + + @async + int? callFlutterEchoNullableInt(int? anInt); + + @async + double? callFlutterEchoNullableDouble(double? aDouble); + + @async + String? callFlutterEchoNullableString(String? aString); + + @async + Uint8List? callFlutterEchoNullableUint8List(Uint8List? aUint8List); + + @async + List? callFlutterEchoNullableList(List? aList); + + @async + Map? callFlutterEchoNullableMap( + Map? aMap, + ); + + @async + AnEnum? callFlutterEchoNullableEnum(AnEnum? anEnum); + + @async + ProxyApiSuperClass? callFlutterEchoNullableProxyApi( + ProxyApiSuperClass? aProxyApi, + ); + + @async + void callFlutterNoopAsync(); + + @async + String callFlutterEchoAsyncString(String aString); +} + +/// ProxyApi to serve as a super class to the core ProxyApi interface. +@ProxyApi() +abstract class ProxyApiSuperClass { + ProxyApiSuperClass(); + + void aSuperMethod(); +} + +/// ProxyApi to serve as an interface to the core ProxyApi interface. +@ProxyApi() +abstract class ProxyApiInterface { + late void Function()? anInterfaceMethod; +} diff --git a/packages/pigeon/test/dart/proxy_api_test.dart b/packages/pigeon/test/dart/proxy_api_test.dart new file mode 100644 index 000000000000..081b3ab843bd --- /dev/null +++ b/packages/pigeon/test/dart/proxy_api_test.dart @@ -0,0 +1,1014 @@ +// 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 'package:pigeon/ast.dart'; +import 'package:pigeon/dart_generator.dart'; +import 'package:test/test.dart'; + +const String DEFAULT_PACKAGE_NAME = 'test_package'; + +void main() { + group('ProxyApi', () { + test('one api', () { + final Root root = Root(apis: [ + AstProxyApi(name: 'Api', constructors: [ + Constructor(name: 'name', parameters: [ + Parameter( + type: const TypeDeclaration( + baseName: 'Input', + isNullable: false, + ), + name: 'input', + ), + ]), + ], fields: [ + ApiField( + name: 'someField', + type: const TypeDeclaration( + baseName: 'int', + isNullable: false, + ), + ) + ], methods: [ + Method( + name: 'doSomething', + location: ApiLocation.host, + parameters: [ + Parameter( + type: const TypeDeclaration( + baseName: 'Input', + isNullable: false, + ), + name: 'input', + ) + ], + returnType: const TypeDeclaration( + baseName: 'String', + isNullable: false, + ), + ), + Method( + name: 'doSomethingElse', + location: ApiLocation.flutter, + parameters: [ + Parameter( + type: const TypeDeclaration( + baseName: 'Input', + isNullable: false, + ), + name: 'input', + ) + ], + returnType: const TypeDeclaration( + baseName: 'String', + isNullable: false, + ), + isRequired: false, + ), + ]) + ], classes: [], enums: []); + final StringBuffer sink = StringBuffer(); + const DartGenerator generator = DartGenerator(); + generator.generate( + const DartOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + final String collapsedCode = _collapseNewlineAndIndentation(code); + + // Instance Manager + expect(code, contains(r'class Pigeon_InstanceManager')); + expect(code, contains(r'class _Pigeon_InstanceManagerApi')); + + // Base Api class + expect( + code, + contains(r'abstract class Pigeon_ProxyApiBaseClass'), + ); + + // Codec and class + expect(code, contains('class _Pigeon_ProxyApiBaseCodec')); + expect(code, contains(r'class Api extends Pigeon_ProxyApiBaseClass')); + + // Constructors + expect( + collapsedCode, + contains( + r'Api.name({ super.pigeon_binaryMessenger, super.pigeon_instanceManager, required this.someField, this.doSomethingElse, required Input input, })', + ), + ); + expect( + code, + contains( + r'Api.pigeon_detached', + ), + ); + + // Field + expect(code, contains('final int someField;')); + + // Dart -> Host method + expect(code, contains('Future doSomething(Input input)')); + + // Host -> Dart method + expect(code, contains(r'static void pigeon_setUpMessageHandlers({')); + expect( + collapsedCode, + contains( + 'final String Function( Api pigeon_instance, Input input, )? doSomethingElse;', + ), + ); + + // Copy method + expect(code, contains(r'Api pigeon_copy(')); + }); + + group('inheritance', () { + test('extends', () { + final AstProxyApi api2 = AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ); + final Root root = Root(apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [], + methods: [], + superClass: TypeDeclaration( + baseName: 'Api2', + isNullable: false, + associatedProxyApi: api2, + ), + ), + api2, + ], classes: [], enums: []); + final StringBuffer sink = StringBuffer(); + const DartGenerator generator = DartGenerator(); + generator.generate( + const DartOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + final String collapsedCode = _collapseNewlineAndIndentation(code); + expect(code, contains(r'class Api extends Api2')); + expect( + collapsedCode, + contains( + r'Api.pigeon_detached({ super.pigeon_binaryMessenger, super.pigeon_instanceManager, }) : super.pigeon_detached();', + ), + ); + }); + + test('implements', () { + final AstProxyApi api2 = AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ); + final Root root = Root(apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [], + methods: [], + interfaces: { + TypeDeclaration( + baseName: 'Api2', + isNullable: false, + associatedProxyApi: api2, + ) + }, + ), + api2, + ], classes: [], enums: []); + final StringBuffer sink = StringBuffer(); + const DartGenerator generator = DartGenerator(); + generator.generate( + const DartOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + expect( + code, + contains( + r'class Api extends Pigeon_ProxyApiBaseClass implements Api2', + ), + ); + }); + + test('implements 2 ProxyApis', () { + final AstProxyApi api2 = AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ); + final AstProxyApi api3 = AstProxyApi( + name: 'Api3', + constructors: [], + fields: [], + methods: [], + ); + final Root root = Root(apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [], + methods: [], + interfaces: { + TypeDeclaration( + baseName: 'Api2', + isNullable: false, + associatedProxyApi: api2, + ), + TypeDeclaration( + baseName: 'Api3', + isNullable: false, + associatedProxyApi: api2, + ), + }, + ), + api2, + api3, + ], classes: [], enums: []); + final StringBuffer sink = StringBuffer(); + const DartGenerator generator = DartGenerator(); + generator.generate( + const DartOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + expect( + code, + contains( + r'class Api extends Pigeon_ProxyApiBaseClass implements Api2, Api3', + ), + ); + }); + + test('implements inherits flutter methods', () { + final AstProxyApi api2 = AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [ + Method( + name: 'aFlutterMethod', + returnType: const TypeDeclaration.voidDeclaration(), + parameters: [], + location: ApiLocation.flutter, + ), + Method( + name: 'aNullableFlutterMethod', + returnType: const TypeDeclaration.voidDeclaration(), + parameters: [], + location: ApiLocation.flutter, + isRequired: false, + ), + ], + ); + final Root root = Root(apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [], + methods: [], + interfaces: { + TypeDeclaration( + baseName: 'Api2', + isNullable: false, + associatedProxyApi: api2, + ) + }, + ), + api2, + ], classes: [], enums: []); + final StringBuffer sink = StringBuffer(); + const DartGenerator generator = DartGenerator(); + generator.generate( + const DartOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + final String collapsedCode = _collapseNewlineAndIndentation(code); + expect( + code, + contains( + r'class Api extends Pigeon_ProxyApiBaseClass implements Api2', + ), + ); + expect( + collapsedCode, + contains( + r'Api.pigeon_detached({ super.pigeon_binaryMessenger, ' + r'super.pigeon_instanceManager, ' + r'required this.aFlutterMethod, ' + r'this.aNullableFlutterMethod, })', + ), + ); + }); + }); + + group('Constructors', () { + test('empty name and no params constructor', () { + final Root root = Root( + apis: [ + AstProxyApi(name: 'Api', constructors: [ + Constructor( + name: '', + parameters: [], + ) + ], fields: [], methods: []), + ], + classes: [], + enums: [], + ); + final StringBuffer sink = StringBuffer(); + const DartGenerator generator = DartGenerator(); + generator.generate( + const DartOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + final String collapsedCode = _collapseNewlineAndIndentation(code); + expect(code, contains('class Api')); + expect( + collapsedCode, + contains( + r'Api({ super.pigeon_binaryMessenger, ' + r'super.pigeon_instanceManager, })', + ), + ); + expect( + collapsedCode, + contains( + r"const String __pigeon_channelName = 'dev.flutter.pigeon.test_package.Api.pigeon_defaultConstructor';", + ), + ); + expect( + collapsedCode, + contains( + r'__pigeon_channel .send([__pigeon_instanceIdentifier])', + ), + ); + }); + + test('multiple params constructor', () { + final Enum anEnum = Enum( + name: 'AnEnum', + members: [EnumMember(name: 'one')], + ); + final Root root = Root( + apis: [ + AstProxyApi(name: 'Api', constructors: [ + Constructor( + name: 'name', + parameters: [ + Parameter( + type: const TypeDeclaration( + isNullable: false, + baseName: 'int', + ), + name: 'validType', + ), + Parameter( + type: TypeDeclaration( + isNullable: false, + baseName: 'AnEnum', + associatedEnum: anEnum, + ), + name: 'enumType', + ), + Parameter( + type: const TypeDeclaration( + isNullable: false, + baseName: 'Api2', + ), + name: 'proxyApiType', + ), + Parameter( + type: const TypeDeclaration( + isNullable: true, + baseName: 'int', + ), + name: 'nullableValidType', + ), + Parameter( + type: TypeDeclaration( + isNullable: true, + baseName: 'AnEnum', + associatedEnum: anEnum, + ), + name: 'nullableEnumType', + ), + Parameter( + type: const TypeDeclaration( + isNullable: true, + baseName: 'Api2', + ), + name: 'nullableProxyApiType', + ), + ], + ) + ], fields: [], methods: []), + AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ), + ], + classes: [], + enums: [anEnum], + ); + final StringBuffer sink = StringBuffer(); + const DartGenerator generator = DartGenerator(); + generator.generate( + const DartOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + final String collapsedCode = _collapseNewlineAndIndentation(code); + expect(code, contains('class Api')); + expect( + collapsedCode, + contains( + r'Api.name({ super.pigeon_binaryMessenger, ' + r'super.pigeon_instanceManager, ' + r'required int validType, ' + r'required AnEnum enumType, ' + r'required Api2 proxyApiType, ' + r'int? nullableValidType, ' + r'AnEnum? nullableEnumType, ' + r'Api2? nullableProxyApiType, })', + ), + ); + expect( + collapsedCode, + contains( + r'__pigeon_channel.send([ ' + r'__pigeon_instanceIdentifier, ' + r'validType, enumType.index, proxyApiType, ' + r'nullableValidType, nullableEnumType?.index, nullableProxyApiType ])', + ), + ); + }); + }); + + group('Fields', () { + test('constructor with fields', () { + final Enum anEnum = Enum( + name: 'AnEnum', + members: [EnumMember(name: 'one')], + ); + final Root root = Root( + apis: [ + AstProxyApi( + name: 'Api', + constructors: [ + Constructor( + name: 'name', + parameters: [], + ) + ], + fields: [ + ApiField( + type: const TypeDeclaration( + isNullable: false, + baseName: 'int', + ), + name: 'validType', + ), + ApiField( + type: TypeDeclaration( + isNullable: false, + baseName: 'AnEnum', + associatedEnum: anEnum, + ), + name: 'enumType', + ), + ApiField( + type: const TypeDeclaration( + isNullable: false, + baseName: 'Api2', + ), + name: 'proxyApiType', + ), + ApiField( + type: const TypeDeclaration( + isNullable: true, + baseName: 'int', + ), + name: 'nullableValidType', + ), + ApiField( + type: TypeDeclaration( + isNullable: true, + baseName: 'AnEnum', + associatedEnum: anEnum, + ), + name: 'nullableEnumType', + ), + ApiField( + type: const TypeDeclaration( + isNullable: true, + baseName: 'Api2', + ), + name: 'nullableProxyApiType', + ), + ], + methods: [], + ), + AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ), + ], + classes: [], + enums: [anEnum], + ); + final StringBuffer sink = StringBuffer(); + const DartGenerator generator = DartGenerator(); + generator.generate( + const DartOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + final String collapsedCode = _collapseNewlineAndIndentation(code); + expect(code, contains('class Api')); + expect( + collapsedCode, + contains( + r'Api.name({ super.pigeon_binaryMessenger, ' + r'super.pigeon_instanceManager, ' + r'required this.validType, ' + r'required this.enumType, ' + r'required this.proxyApiType, ' + r'this.nullableValidType, ' + r'this.nullableEnumType, ' + r'this.nullableProxyApiType, })', + ), + ); + expect( + collapsedCode, + contains( + r'__pigeon_channel.send([ ' + r'__pigeon_instanceIdentifier, ' + r'validType, enumType.index, proxyApiType, ' + r'nullableValidType, nullableEnumType?.index, nullableProxyApiType ])', + ), + ); + expect( + code, + contains(r'final int validType;'), + ); + expect( + code, + contains(r'final AnEnum enumType;'), + ); + expect( + code, + contains(r'final Api2 proxyApiType;'), + ); + expect( + code, + contains(r'final int? nullableValidType;'), + ); + expect( + code, + contains(r'final AnEnum? nullableEnumType;'), + ); + expect( + code, + contains(r'final Api2? nullableProxyApiType;'), + ); + }); + + test('attached field', () { + final AstProxyApi api2 = AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ); + final Root root = Root( + apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [ + ApiField( + name: 'aField', + isAttached: true, + type: TypeDeclaration( + baseName: 'Api2', + isNullable: false, + associatedProxyApi: api2, + ), + ), + ], + methods: [], + ), + api2, + ], + classes: [], + enums: [], + ); + final StringBuffer sink = StringBuffer(); + const DartGenerator generator = DartGenerator(); + generator.generate( + const DartOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + expect(code, contains('class Api')); + expect(code, contains(r'late final Api2 aField = __pigeon_aField();')); + expect(code, contains(r'Api2 __pigeon_aField()')); + }); + + test('static attached field', () { + final AstProxyApi api2 = AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ); + final Root root = Root( + apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [ + ApiField( + name: 'aField', + isStatic: true, + isAttached: true, + type: TypeDeclaration( + baseName: 'Api2', + isNullable: false, + associatedProxyApi: api2, + ), + ), + ], + methods: [], + ), + api2, + ], + classes: [], + enums: [], + ); + final StringBuffer sink = StringBuffer(); + const DartGenerator generator = DartGenerator(); + generator.generate( + const DartOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + expect(code, contains('class Api')); + expect( + code, contains(r'static final Api2 aField = __pigeon_aField();')); + expect(code, contains(r'static Api2 __pigeon_aField()')); + }); + }); + + group('Host methods', () { + test('multiple params method', () { + final Enum anEnum = Enum( + name: 'AnEnum', + members: [EnumMember(name: 'one')], + ); + final Root root = Root( + apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [], + methods: [ + Method( + name: 'doSomething', + location: ApiLocation.host, + parameters: [ + Parameter( + type: const TypeDeclaration( + isNullable: false, + baseName: 'int', + ), + name: 'validType', + ), + Parameter( + type: TypeDeclaration( + isNullable: false, + baseName: 'AnEnum', + associatedEnum: anEnum, + ), + name: 'enumType', + ), + Parameter( + type: const TypeDeclaration( + isNullable: false, + baseName: 'Api2', + ), + name: 'proxyApiType', + ), + Parameter( + type: const TypeDeclaration( + isNullable: true, + baseName: 'int', + ), + name: 'nullableValidType', + ), + Parameter( + type: TypeDeclaration( + isNullable: true, + baseName: 'AnEnum', + associatedEnum: anEnum, + ), + name: 'nullableEnumType', + ), + Parameter( + type: const TypeDeclaration( + isNullable: true, + baseName: 'Api2', + ), + name: 'nullableProxyApiType', + ), + ], + returnType: const TypeDeclaration.voidDeclaration(), + ), + ], + ), + AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ), + ], + classes: [], + enums: [anEnum], + ); + final StringBuffer sink = StringBuffer(); + const DartGenerator generator = DartGenerator(); + generator.generate( + const DartOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + final String collapsedCode = _collapseNewlineAndIndentation(code); + expect(code, contains('class Api')); + expect( + collapsedCode, + contains( + r'Future doSomething( int validType, AnEnum enumType, ' + r'Api2 proxyApiType, int? nullableValidType, ' + r'AnEnum? nullableEnumType, Api2? nullableProxyApiType, )', + ), + ); + expect( + collapsedCode, + contains( + r'await __pigeon_channel.send([ this, validType, ' + r'enumType.index, proxyApiType, nullableValidType, ' + r'nullableEnumType?.index, nullableProxyApiType ])', + ), + ); + }); + + test('static method', () { + final Root root = Root( + apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [], + methods: [ + Method( + name: 'doSomething', + location: ApiLocation.host, + isStatic: true, + parameters: [], + returnType: const TypeDeclaration.voidDeclaration(), + ), + ], + ), + ], + classes: [], + enums: [], + ); + final StringBuffer sink = StringBuffer(); + const DartGenerator generator = DartGenerator(); + generator.generate( + const DartOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + final String collapsedCode = _collapseNewlineAndIndentation(code); + expect(code, contains('class Api')); + expect( + collapsedCode, + contains( + r'static Future doSomething({ BinaryMessenger? pigeon_binaryMessenger, ' + r'Pigeon_InstanceManager? pigeon_instanceManager, })', + ), + ); + expect( + collapsedCode, + contains(r'await __pigeon_channel.send(null)'), + ); + }); + }); + + group('Flutter methods', () { + test('multiple params flutter method', () { + final Enum anEnum = Enum( + name: 'AnEnum', + members: [EnumMember(name: 'one')], + ); + final Root root = Root(apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [], + methods: [ + Method( + name: 'doSomething', + location: ApiLocation.flutter, + isRequired: false, + parameters: [ + Parameter( + type: const TypeDeclaration( + isNullable: false, + baseName: 'int', + ), + name: 'validType', + ), + Parameter( + type: TypeDeclaration( + isNullable: false, + baseName: 'AnEnum', + associatedEnum: anEnum, + ), + name: 'enumType', + ), + Parameter( + type: const TypeDeclaration( + isNullable: false, + baseName: 'Api2', + ), + name: 'proxyApiType', + ), + Parameter( + type: const TypeDeclaration( + isNullable: true, + baseName: 'int', + ), + name: 'nullableValidType', + ), + Parameter( + type: TypeDeclaration( + isNullable: true, + baseName: 'AnEnum', + associatedEnum: anEnum, + ), + name: 'nullableEnumType', + ), + Parameter( + type: const TypeDeclaration( + isNullable: true, + baseName: 'Api2', + ), + name: 'nullableProxyApiType', + ), + ], + returnType: const TypeDeclaration.voidDeclaration(), + ), + ]) + ], classes: [], enums: [ + anEnum + ]); + final StringBuffer sink = StringBuffer(); + const DartGenerator generator = DartGenerator(); + generator.generate( + const DartOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + final String collapsedCode = _collapseNewlineAndIndentation(code); + expect(code, contains('class Api')); + expect( + collapsedCode, + contains( + r'final void Function( Api pigeon_instance, int validType, ' + r'AnEnum enumType, Api2 proxyApiType, int? nullableValidType, ' + r'AnEnum? nullableEnumType, Api2? nullableProxyApiType, )? ' + r'doSomething;', + ), + ); + expect( + collapsedCode, + contains( + r'void Function( Api pigeon_instance, int validType, AnEnum enumType, ' + r'Api2 proxyApiType, int? nullableValidType, ' + r'AnEnum? nullableEnumType, Api2? nullableProxyApiType, )? ' + r'doSomething'), + ); + expect( + code, + contains(r'final Api? arg_pigeon_instance = (args[0] as Api?);'), + ); + expect( + code, + contains(r'final int? arg_validType = (args[1] as int?);'), + ); + expect( + collapsedCode, + contains( + r'final AnEnum? arg_enumType = args[2] == null ? ' + r'null : AnEnum.values[args[2]! as int];', + ), + ); + expect( + code, + contains(r'final Api2? arg_proxyApiType = (args[3] as Api2?);'), + ); + expect( + code, + contains(r'final int? arg_nullableValidType = (args[4] as int?);'), + ); + expect( + collapsedCode, + contains( + r'final AnEnum? arg_nullableEnumType = args[5] == null ? ' + r'null : AnEnum.values[args[5]! as int];', + ), + ); + expect( + collapsedCode, + contains( + r'(doSomething ?? arg_pigeon_instance!.doSomething)?.call( arg_pigeon_instance!, ' + r'arg_validType!, arg_enumType!, arg_proxyApiType!, ' + r'arg_nullableValidType, arg_nullableEnumType, ' + r'arg_nullableProxyApiType);', + ), + ); + }); + }); + }); +} + +/// Replaces a new line and the indentation with a single white space +/// +/// This +/// +/// ```dart +/// void method( +/// int param1, +/// int param2, +/// ) +/// ``` +/// +/// converts to +/// +/// ```dart +/// void method( int param1, int param2, ) +/// ``` +String _collapseNewlineAndIndentation(String string) { + final StringBuffer result = StringBuffer(); + for (final String line in string.split('\n')) { + result.write('${line.trimLeft()} '); + } + return result.toString().trim(); +} From b08d0179f7a6008597954f54720eaf253f0a7e43 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 2 Feb 2024 14:30:38 -0500 Subject: [PATCH 23/32] generate test api file --- .../example/app/lib/src/messages.g.dart | 2 +- packages/pigeon/lib/dart/templates.dart | 14 +- packages/pigeon/lib/dart_generator.dart | 48 +- packages/pigeon/lib/pigeon.dart | 4 +- packages/pigeon/pigeons/proxy_api_tests.dart | 3 - .../background_platform_channels.gen.dart | 2 +- .../lib/src/generated/core_tests.gen.dart | 2 +- .../lib/src/generated/enum.gen.dart | 2 +- .../src/generated/flutter_unittests.gen.dart | 2 +- .../lib/src/generated/message.gen.dart | 2 +- .../lib/src/generated/multiple_arity.gen.dart | 2 +- .../src/generated/non_null_fields.gen.dart | 2 +- .../lib/src/generated/null_fields.gen.dart | 2 +- .../src/generated/nullable_returns.gen.dart | 2 +- .../lib/src/generated/primitive.gen.dart | 2 +- .../src/generated/proxy_api_tests.gen.dart | 5038 +++++++++++++++++ .../test/instance_manager_test.dart | 168 + packages/pigeon/tool/shared/generation.dart | 1 + 18 files changed, 5254 insertions(+), 44 deletions(-) create mode 100644 packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart create mode 100644 packages/pigeon/platform_tests/shared_test_plugin_code/test/instance_manager_test.dart diff --git a/packages/pigeon/example/app/lib/src/messages.g.dart b/packages/pigeon/example/app/lib/src/messages.g.dart index 59213e4ef2bb..961e9c5856b5 100644 --- a/packages/pigeon/example/app/lib/src/messages.g.dart +++ b/packages/pigeon/example/app/lib/src/messages.g.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/lib/dart/templates.dart b/packages/pigeon/lib/dart/templates.dart index 3459fcd5c242..5da28beafc30 100644 --- a/packages/pigeon/lib/dart/templates.dart +++ b/packages/pigeon/lib/dart/templates.dart @@ -6,7 +6,6 @@ import '../generator_tools.dart'; /// Creates the `InstanceManager` with the passed string values. String instanceManagerTemplate({ - required String proxyApiBaseClassName, required Iterable allProxyApiNames, }) { final Iterable apiHandlerSetUps = allProxyApiNames.map( @@ -333,9 +332,9 @@ const String proxyApiBaseClass = ''' /// All implementers are expected to be [immutable] as defined by the annotation /// and override [${classMemberNamePrefix}copy] returning an instance of itself. @immutable -abstract class $_proxyApiBaseClassName { - /// Construct a [$_proxyApiBaseClassName]. - $_proxyApiBaseClassName({ +abstract class $proxyApiBaseClassName { + /// Construct a [$proxyApiBaseClassName]. + $proxyApiBaseClassName({ this.$_proxyApiBaseClassMessengerVarName, $instanceManagerClassName? $_proxyApiBaseClassInstanceManagerVarName, }) : $_proxyApiBaseClassInstanceManagerVarName = @@ -358,7 +357,7 @@ abstract class $_proxyApiBaseClassName { /// Subclasses should always override their parent's implementation of this /// method. @protected - $_proxyApiBaseClassName ${classMemberNamePrefix}copy(); + $proxyApiBaseClassName ${classMemberNamePrefix}copy(); } '''; @@ -373,7 +372,7 @@ class $_proxyApiCodecName extends StandardMessageCodec { final $instanceManagerClassName instanceManager; @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is $_proxyApiBaseClassName) { + if (value is $proxyApiBaseClassName) { buffer.putUint8(128); writeValue(buffer, instanceManager.getIdentifier(value)); } else { @@ -393,7 +392,8 @@ class $_proxyApiCodecName extends StandardMessageCodec { } '''; -const String _proxyApiBaseClassName = '${classNamePrefix}ProxyApiBaseClass'; +/// Name of the base class of all ProxyApis. +const String proxyApiBaseClassName = '${classNamePrefix}ProxyApiBaseClass'; const String _proxyApiBaseClassMessengerVarName = '${classMemberNamePrefix}binaryMessenger'; const String _proxyApiBaseClassInstanceManagerVarName = diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index d00cfea4c2ee..851649e98525 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -125,7 +125,7 @@ class DartGenerator extends StructuredGenerator { final bool hasProxyApi = root.apis.any((Api api) => api is AstProxyApi); indent.writeln( - "import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer${hasProxyApi ? ' immutable, protected' : ''};"); + "import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer${hasProxyApi ? ', immutable, protected' : ''};"); indent.writeln("import 'package:flutter/services.dart';"); if (hasProxyApi) { indent.writeln( @@ -463,7 +463,6 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; indent.writeln( instanceManagerTemplate( - proxyApiBaseClassName: '${classMemberNamePrefix}ProxyApiBaseClass', allProxyApiNames: root.apis .whereType() .map((AstProxyApi api) => api.name), @@ -551,7 +550,7 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; ..name = api.name ..extend = api.superClass != null ? cb.refer(api.superClass!.baseName) - : cb.refer('${classNamePrefix}ProxyApiBaseClass') + : cb.refer(proxyApiBaseClassName) ..implements.addAll( api.interfaces.map( (TypeDeclaration type) => cb.refer(type.baseName), @@ -583,9 +582,9 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; ), ) ..fields.addAll([ - if (api.methods.isNotEmpty || - api.constructors.isNotEmpty || - api.attachedFields.any((ApiField field) => !field.isStatic)) + if (api.constructors.isNotEmpty || + api.attachedFields.any((ApiField field) => !field.isStatic) || + api.hostMethods.isNotEmpty) _proxyApiCodecInstanceField( codecInstanceName: codecInstanceName, codecName: codecName, @@ -605,7 +604,7 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; dartPackageName: dartPackageName, codecName: codecName, unattachedFields: api.unattachedFields, - hasCallbackConstructor: api.methods + hasCallbackConstructor: api.flutterMethods .followedBy(flutterMethodsFromSuperClasses) .followedBy(flutterMethodsFromInterfaces) .every((Method method) => !method.isRequired), @@ -727,15 +726,22 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; Indent indent, { required String dartPackageName, }) { - final bool hasHostApi = - root.apis.any((Api api) => api.methods.isNotEmpty && api is AstHostApi); - final bool hasFlutterApi = root.apis - .any((Api api) => api.methods.isNotEmpty && api is AstFlutterApi); - - if (hasHostApi) { + final bool hasHostMethod = root.apis + .whereType() + .any((AstHostApi api) => api.methods.isNotEmpty) || + root.apis.whereType().any((AstProxyApi api) => + api.constructors.isNotEmpty || + api.attachedFields.isNotEmpty || + api.hostMethods.isNotEmpty); + final bool hasFlutterMethod = root.apis + .whereType() + .any((AstFlutterApi api) => api.methods.isNotEmpty) || + root.apis.any((Api api) => api is AstProxyApi); + + if (hasHostMethod) { _writeCreateConnectionError(indent); } - if (hasFlutterApi || generatorOptions.testOutPath != null) { + if (hasFlutterMethod || generatorOptions.testOutPath != null) { _writeWrapResponse(generatorOptions, root, indent); } } @@ -1461,12 +1467,14 @@ if (${_varNamePrefix}replyList == null) { ), ]) ..body = cb.Block.of([ - cb.Code( - 'final $codecName $_pigeonChannelCodec = $codecName($_instanceManagerVarName ?? $instanceManagerClassName.instance);', - ), - const cb.Code( - 'final BinaryMessenger? binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', - ), + if (hasCallbackConstructor || flutterMethods.isNotEmpty) ...[ + cb.Code( + 'final $codecName $_pigeonChannelCodec = $codecName($_instanceManagerVarName ?? $instanceManagerClassName.instance);', + ), + const cb.Code( + 'final BinaryMessenger? binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', + ) + ], if (hasCallbackConstructor) ...cb.Block((cb.BlockBuilder builder) { final StringBuffer messageHandlerSink = StringBuffer(); diff --git a/packages/pigeon/lib/pigeon.dart b/packages/pigeon/lib/pigeon.dart index a2c6026e3117..7f2fb7505fa8 100644 --- a/packages/pigeon/lib/pigeon.dart +++ b/packages/pigeon/lib/pigeon.dart @@ -9,7 +9,5 @@ export 'dart_generator.dart' show DartOptions; export 'java_generator.dart' show JavaOptions; export 'kotlin_generator.dart' show KotlinOptions; export 'objc_generator.dart' show ObjcOptions; -// TODO(bparrishMines): Remove hide once implementation of the api is finished -// for Dart and one host language. -export 'pigeon_lib.dart' hide ProxyApi; +export 'pigeon_lib.dart'; export 'swift_generator.dart' show SwiftOptions; diff --git a/packages/pigeon/pigeons/proxy_api_tests.dart b/packages/pigeon/pigeons/proxy_api_tests.dart index c09eebd8239d..51c351ab556a 100644 --- a/packages/pigeon/pigeons/proxy_api_tests.dart +++ b/packages/pigeon/pigeons/proxy_api_tests.dart @@ -3,9 +3,6 @@ // found in the LICENSE file. import 'package:pigeon/pigeon.dart'; -// TODO(bparrishMines): Remove this import when ProxyApi has an implementation -// for at least one host language. -import 'package:pigeon/pigeon_lib.dart'; enum AnEnum { one, diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/background_platform_channels.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/background_platform_channels.gen.dart index 7222e263b32b..91dee132ceba 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/background_platform_channels.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/background_platform_channels.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart index 6815f461c943..7ba41cf8e778 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/enum.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/enum.gen.dart index 8354d159d33e..f465bf2b765c 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/enum.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/enum.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/flutter_unittests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/flutter_unittests.gen.dart index 73f100cf28b6..99cbf7fa3711 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/flutter_unittests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/flutter_unittests.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart index cc7b8b53c360..04dbc6d43a2a 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/multiple_arity.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/multiple_arity.gen.dart index bec054b4be49..19455117087d 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/multiple_arity.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/multiple_arity.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart index 7279e85c40ea..be9c48422aef 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart index ecf7c7f7e970..bc18ccd0ada0 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/nullable_returns.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/nullable_returns.gen.dart index dd1665a463c1..d5c2bb3f63df 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/nullable_returns.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/nullable_returns.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/primitive.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/primitive.gen.dart index 72c115d65278..b1f618a72b6e 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/primitive.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/primitive.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart new file mode 100644 index 000000000000..68b02de3c24e --- /dev/null +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart @@ -0,0 +1,5038 @@ +// 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. +// +// Autogenerated from Pigeon, do not edit directly. +// See also: https://pub.dev/packages/pigeon +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types + +import 'dart:async'; +import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; + +import 'package:flutter/foundation.dart' + show ReadBuffer, WriteBuffer, immutable, protected; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart' show WidgetsFlutterBinding; + +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + +List wrapResponse( + {Object? result, PlatformException? error, bool empty = false}) { + if (empty) { + return []; + } + if (error == null) { + return [result]; + } + return [error.code, error.message, error.details]; +} + +/// An immutable object that serves as the base class for all ProxyApis and +/// can provide functional copies of itself. +/// +/// All implementers are expected to be [immutable] as defined by the annotation +/// and override [pigeon_copy] returning an instance of itself. +@immutable +abstract class Pigeon_ProxyApiBaseClass { + /// Construct a [Pigeon_ProxyApiBaseClass]. + Pigeon_ProxyApiBaseClass({ + this.pigeon_binaryMessenger, + Pigeon_InstanceManager? pigeon_instanceManager, + }) : pigeon_instanceManager = + pigeon_instanceManager ?? Pigeon_InstanceManager.instance; + + /// Sends and receives binary data across the Flutter platform barrier. + /// + /// If it is null, the default BinaryMessenger will be used, which routes to + /// the host platform. + final BinaryMessenger? pigeon_binaryMessenger; + + /// Maintains instances stored to communicate with native language objects. + final Pigeon_InstanceManager pigeon_instanceManager; + + /// Instantiates and returns a functionally identical object to oneself. + /// + /// Outside of tests, this method should only ever be called by + /// [Pigeon_InstanceManager]. + /// + /// Subclasses should always override their parent's implementation of this + /// method. + @protected + Pigeon_ProxyApiBaseClass pigeon_copy(); +} + +/// Maintains instances used to communicate with the native objects they +/// represent. +/// +/// Added instances are stored as weak references and their copies are stored +/// as strong references to maintain access to their variables and callback +/// methods. Both are stored with the same identifier. +/// +/// When a weak referenced instance becomes inaccessible, +/// [onWeakReferenceRemoved] is called with its associated identifier. +/// +/// If an instance is retrieved and has the possibility to be used, +/// (e.g. calling [getInstanceWithWeakReference]) a copy of the strong reference +/// is added as a weak reference with the same identifier. This prevents a +/// scenario where the weak referenced instance was released and then later +/// returned by the host platform. +class Pigeon_InstanceManager { + /// Constructs a [Pigeon_InstanceManager]. + Pigeon_InstanceManager({required void Function(int) onWeakReferenceRemoved}) { + this.onWeakReferenceRemoved = (int identifier) { + _weakInstances.remove(identifier); + onWeakReferenceRemoved(identifier); + }; + _finalizer = Finalizer(this.onWeakReferenceRemoved); + } + + // Identifiers are locked to a specific range to avoid collisions with objects + // created simultaneously by the host platform. + // Host uses identifiers >= 2^16 and Dart is expected to use values n where, + // 0 <= n < 2^16. + static const int _maxDartCreatedIdentifier = 65536; + + /// The default [Pigeon_InstanceManager] used by ProxyApis. + /// + /// On creation, this manager makes a call to clear the native + /// InstanceManager. This is to prevent identifier conflicts after a host + /// restart. + static final Pigeon_InstanceManager instance = _initInstance(); + + // Expando is used because it doesn't prevent its keys from becoming + // inaccessible. This allows the manager to efficiently retrieve an identifier + // of an instance without holding a strong reference to that instance. + // + // It also doesn't use `==` to search for identifiers, which would lead to an + // infinite loop when comparing an object to its copy. (i.e. which was caused + // by calling instanceManager.getIdentifier() inside of `==` while this was a + // HashMap). + final Expando _identifiers = Expando(); + final Map> _weakInstances = + >{}; + final Map _strongInstances = + {}; + late final Finalizer _finalizer; + int _nextIdentifier = 0; + + /// Called when a weak referenced instance is removed by [removeWeakReference] + /// or becomes inaccessible. + late final void Function(int) onWeakReferenceRemoved; + + static Pigeon_InstanceManager _initInstance() { + WidgetsFlutterBinding.ensureInitialized(); + final _Pigeon_InstanceManagerApi api = _Pigeon_InstanceManagerApi(); + // Clears the native `Pigeon_InstanceManager` on the initial use of the Dart one. + api.clear(); + final Pigeon_InstanceManager instanceManager = Pigeon_InstanceManager( + onWeakReferenceRemoved: (int identifier) { + api.removeStrongReference(identifier); + }, + ); + _Pigeon_InstanceManagerApi.setUpMessageHandlers( + instanceManager: instanceManager); + ProxyApiTestClass.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + ProxyApiSuperClass.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + ProxyApiInterface.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + return instanceManager; + } + + /// Adds a new instance that was instantiated by Dart. + /// + /// In other words, Dart wants to add a new instance that will represent + /// an object that will be instantiated on the host platform. + /// + /// Throws assertion error if the instance has already been added. + /// + /// Returns the randomly generated id of the [instance] added. + int addDartCreatedInstance(Pigeon_ProxyApiBaseClass instance) { + final int identifier = _nextUniqueIdentifier(); + _addInstanceWithIdentifier(instance, identifier); + return identifier; + } + + /// Removes the instance, if present, and call [onWeakReferenceRemoved] with + /// its identifier. + /// + /// Returns the identifier associated with the removed instance. Otherwise, + /// `null` if the instance was not found in this manager. + /// + /// This does not remove the strong referenced instance associated with + /// [instance]. This can be done with [remove]. + int? removeWeakReference(Pigeon_ProxyApiBaseClass instance) { + final int? identifier = getIdentifier(instance); + if (identifier == null) { + return null; + } + + _identifiers[instance] = null; + _finalizer.detach(instance); + onWeakReferenceRemoved(identifier); + + return identifier; + } + + /// Removes [identifier] and its associated strongly referenced instance, if + /// present, from the manager. + /// + /// Returns the strong referenced instance associated with [identifier] before + /// it was removed. Returns `null` if [identifier] was not associated with + /// any strong reference. + /// + /// This does not remove the weak referenced instance associated with + /// [identifier]. This can be done with [removeWeakReference]. + T? remove(int identifier) { + return _strongInstances.remove(identifier) as T?; + } + + /// Retrieves the instance associated with identifier. + /// + /// The value returned is chosen from the following order: + /// + /// 1. A weakly referenced instance associated with identifier. + /// 2. If the only instance associated with identifier is a strongly + /// referenced instance, a copy of the instance is added as a weak reference + /// with the same identifier. Returning the newly created copy. + /// 3. If no instance is associated with identifier, returns null. + /// + /// This method also expects the host `InstanceManager` to have a strong + /// reference to the instance the identifier is associated with. + T? getInstanceWithWeakReference( + int identifier) { + final Pigeon_ProxyApiBaseClass? weakInstance = + _weakInstances[identifier]?.target; + + if (weakInstance == null) { + final Pigeon_ProxyApiBaseClass? strongInstance = + _strongInstances[identifier]; + if (strongInstance != null) { + final Pigeon_ProxyApiBaseClass copy = strongInstance.pigeon_copy(); + _identifiers[copy] = identifier; + _weakInstances[identifier] = + WeakReference(copy); + _finalizer.attach(copy, identifier, detach: copy); + return copy as T; + } + return strongInstance as T?; + } + + return weakInstance as T; + } + + /// Retrieves the identifier associated with instance. + int? getIdentifier(Pigeon_ProxyApiBaseClass instance) { + return _identifiers[instance]; + } + + /// Adds a new instance that was instantiated by the host platform. + /// + /// In other words, the host platform wants to add a new instance that + /// represents an object on the host platform. Stored with [identifier]. + /// + /// Throws assertion error if the instance or its identifier has already been + /// added. + /// + /// Returns unique identifier of the [instance] added. + void addHostCreatedInstance( + Pigeon_ProxyApiBaseClass instance, int identifier) { + _addInstanceWithIdentifier(instance, identifier); + } + + void _addInstanceWithIdentifier( + Pigeon_ProxyApiBaseClass instance, int identifier) { + assert(!containsIdentifier(identifier)); + assert(getIdentifier(instance) == null); + assert(identifier >= 0); + + _identifiers[instance] = identifier; + _weakInstances[identifier] = + WeakReference(instance); + _finalizer.attach(instance, identifier, detach: instance); + + final Pigeon_ProxyApiBaseClass copy = instance.pigeon_copy(); + _identifiers[copy] = identifier; + _strongInstances[identifier] = copy; + } + + /// Whether this manager contains the given [identifier]. + bool containsIdentifier(int identifier) { + return _weakInstances.containsKey(identifier) || + _strongInstances.containsKey(identifier); + } + + int _nextUniqueIdentifier() { + late int identifier; + do { + identifier = _nextIdentifier; + _nextIdentifier = (_nextIdentifier + 1) % _maxDartCreatedIdentifier; + } while (containsIdentifier(identifier)); + return identifier; + } +} + +/// Generated API for managing the Dart and native `Pigeon_InstanceManager`s. +class _Pigeon_InstanceManagerApi { + /// Constructor for [_Pigeon_InstanceManagerApi ]. + _Pigeon_InstanceManagerApi({BinaryMessenger? binaryMessenger}) + : _binaryMessenger = binaryMessenger; + + final BinaryMessenger? _binaryMessenger; + + static const MessageCodec pigeonChannelCodec = + StandardMessageCodec(); + + static void setUpMessageHandlers({ + BinaryMessenger? binaryMessenger, + Pigeon_InstanceManager? instanceManager, + }) { + const String channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.Pigeon_InstanceManagerApi.removeStrongReference'; + final BasicMessageChannel channel = BasicMessageChannel( + channelName, + pigeonChannelCodec, + binaryMessenger: binaryMessenger, + ); + channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $channelName was null.', + ); + final int? identifier = message as int?; + assert( + identifier != null, + r'Argument for $channelName, expected non-null int.', + ); + (instanceManager ?? Pigeon_InstanceManager.instance).remove(identifier!); + return; + }); + } + + Future removeStrongReference(int identifier) async { + const String channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.Pigeon_InstanceManagerApi.removeStrongReference'; + final BasicMessageChannel channel = BasicMessageChannel( + channelName, + pigeonChannelCodec, + binaryMessenger: _binaryMessenger, + ); + final List? replyList = + await channel.send(identifier) as List?; + if (replyList == null) { + throw _createConnectionError(channelName); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return; + } + } + + /// Clear the native `Pigeon_InstanceManager`. + /// + /// This is typically called after a hot restart. + Future clear() async { + const String channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.Pigeon_InstanceManagerApi.clear'; + final BasicMessageChannel channel = BasicMessageChannel( + channelName, + pigeonChannelCodec, + binaryMessenger: _binaryMessenger, + ); + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { + throw _createConnectionError(channelName); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return; + } + } +} + +class _Pigeon_ProxyApiBaseCodec extends StandardMessageCodec { + const _Pigeon_ProxyApiBaseCodec(this.instanceManager); + final Pigeon_InstanceManager instanceManager; + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is Pigeon_ProxyApiBaseClass) { + buffer.putUint8(128); + writeValue(buffer, instanceManager.getIdentifier(value)); + } else { + super.writeValue(buffer, value); + } + } + + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + case 128: + return instanceManager + .getInstanceWithWeakReference(readValue(buffer)! as int); + default: + return super.readValueOfType(type, buffer); + } + } +} + +enum AnEnum { + one, + two, + three, +} + +/// The core interface that each host language plugin must implement in +/// platform_test integration tests. +class ProxyApiTestClass extends ProxyApiSuperClass + implements ProxyApiInterface { + ProxyApiTestClass({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.aBool, + required this.anInt, + required this.aDouble, + required this.aString, + required this.aUint8List, + required this.aList, + required this.aMap, + required this.anEnum, + required this.aProxyApi, + this.aNullableBool, + this.aNullableInt, + this.aNullableDouble, + this.aNullableString, + this.aNullableUint8List, + this.aNullableList, + this.aNullableMap, + this.aNullableEnum, + this.aNullableProxyApi, + this.anInterfaceMethod, + this.flutterNoop, + this.flutterThrowError, + this.flutterThrowErrorFromVoid, + this.flutterEchoBool, + this.flutterEchoInt, + this.flutterEchoDouble, + this.flutterEchoString, + this.flutterEchoUint8List, + this.flutterEchoList, + this.flutterEchoProxyApiList, + this.flutterEchoMap, + this.flutterEchoProxyApiMap, + this.flutterEchoEnum, + this.flutterEchoProxyApi, + this.flutterEchoNullableBool, + this.flutterEchoNullableInt, + this.flutterEchoNullableDouble, + this.flutterEchoNullableString, + this.flutterEchoNullableUint8List, + this.flutterEchoNullableList, + this.flutterEchoNullableMap, + this.flutterEchoNullableEnum, + this.flutterEchoNullableProxyApi, + this.flutterNoopAsync, + this.flutterEchoAsyncString, + required bool boolParam, + required int intParam, + required double doubleParam, + required String stringParam, + required Uint8List aUint8ListParam, + required List listParam, + required Map mapParam, + required AnEnum enumParam, + required ProxyApiSuperClass proxyApiParam, + bool? nullableBoolParam, + int? nullableIntParam, + double? nullableDoubleParam, + String? nullableStringParam, + Uint8List? nullableUint8ListParam, + List? nullableListParam, + Map? nullableMapParam, + AnEnum? nullableEnumParam, + ProxyApiSuperClass? nullableProxyApiParam, + }) : super.pigeon_detached() { + final int __pigeon_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + () async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_defaultConstructor'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([ + __pigeon_instanceIdentifier, + aBool, + anInt, + aDouble, + aString, + aUint8List, + aList, + aMap, + anEnum.index, + aProxyApi, + aNullableBool, + aNullableInt, + aNullableDouble, + aNullableString, + aNullableUint8List, + aNullableList, + aNullableMap, + aNullableEnum?.index, + aNullableProxyApi, + boolParam, + intParam, + doubleParam, + stringParam, + aUint8ListParam, + listParam, + mapParam, + enumParam.index, + proxyApiParam, + nullableBoolParam, + nullableIntParam, + nullableDoubleParam, + nullableStringParam, + nullableUint8ListParam, + nullableListParam, + nullableMapParam, + nullableEnumParam?.index, + nullableProxyApiParam + ]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + }(); + } + + /// Constructs ProxyApiTestClass without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [Pigeon_InstanceManager]. + ProxyApiTestClass.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.aBool, + required this.anInt, + required this.aDouble, + required this.aString, + required this.aUint8List, + required this.aList, + required this.aMap, + required this.anEnum, + required this.aProxyApi, + this.aNullableBool, + this.aNullableInt, + this.aNullableDouble, + this.aNullableString, + this.aNullableUint8List, + this.aNullableList, + this.aNullableMap, + this.aNullableEnum, + this.aNullableProxyApi, + this.anInterfaceMethod, + this.flutterNoop, + this.flutterThrowError, + this.flutterThrowErrorFromVoid, + this.flutterEchoBool, + this.flutterEchoInt, + this.flutterEchoDouble, + this.flutterEchoString, + this.flutterEchoUint8List, + this.flutterEchoList, + this.flutterEchoProxyApiList, + this.flutterEchoMap, + this.flutterEchoProxyApiMap, + this.flutterEchoEnum, + this.flutterEchoProxyApi, + this.flutterEchoNullableBool, + this.flutterEchoNullableInt, + this.flutterEchoNullableDouble, + this.flutterEchoNullableString, + this.flutterEchoNullableUint8List, + this.flutterEchoNullableList, + this.flutterEchoNullableMap, + this.flutterEchoNullableEnum, + this.flutterEchoNullableProxyApi, + this.flutterNoopAsync, + this.flutterEchoAsyncString, + }) : super.pigeon_detached(); + + late final _Pigeon_ProxyApiBaseCodec __pigeon_codecProxyApiTestClass = + _Pigeon_ProxyApiBaseCodec(pigeon_instanceManager); + + final bool aBool; + + final int anInt; + + final double aDouble; + + final String aString; + + final Uint8List aUint8List; + + final List aList; + + final Map aMap; + + final AnEnum anEnum; + + final ProxyApiSuperClass aProxyApi; + + final bool? aNullableBool; + + final int? aNullableInt; + + final double? aNullableDouble; + + final String? aNullableString; + + final Uint8List? aNullableUint8List; + + final List? aNullableList; + + final Map? aNullableMap; + + final AnEnum? aNullableEnum; + + final ProxyApiSuperClass? aNullableProxyApi; + + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic calling. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterNoop: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final void Function(ProxyApiTestClass pigeon_instance)? flutterNoop; + + /// Responds with an error from an async function returning a value. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterThrowError: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final Object? Function(ProxyApiTestClass pigeon_instance)? flutterThrowError; + + /// Responds with an error from an async void function. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterThrowErrorFromVoid: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final void Function(ProxyApiTestClass pigeon_instance)? + flutterThrowErrorFromVoid; + + /// Returns the passed boolean, to test serialization and deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoBool: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final bool Function( + ProxyApiTestClass pigeon_instance, + bool aBool, + )? flutterEchoBool; + + /// Returns the passed int, to test serialization and deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoInt: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final int Function( + ProxyApiTestClass pigeon_instance, + int anInt, + )? flutterEchoInt; + + /// Returns the passed double, to test serialization and deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoDouble: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final double Function( + ProxyApiTestClass pigeon_instance, + double aDouble, + )? flutterEchoDouble; + + /// Returns the passed string, to test serialization and deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoString: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final String Function( + ProxyApiTestClass pigeon_instance, + String aString, + )? flutterEchoString; + + /// Returns the passed byte list, to test serialization and deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoUint8List: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final Uint8List Function( + ProxyApiTestClass pigeon_instance, + Uint8List aList, + )? flutterEchoUint8List; + + /// Returns the passed list, to test serialization and deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoList: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final List Function( + ProxyApiTestClass pigeon_instance, + List aList, + )? flutterEchoList; + + /// Returns the passed list with ProxyApis, to test serialization and + /// deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoProxyApiList: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final List Function( + ProxyApiTestClass pigeon_instance, + List aList, + )? flutterEchoProxyApiList; + + /// Returns the passed map, to test serialization and deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoMap: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final Map Function( + ProxyApiTestClass pigeon_instance, + Map aMap, + )? flutterEchoMap; + + /// Returns the passed map with ProxyApis, to test serialization and + /// deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoProxyApiMap: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final Map Function( + ProxyApiTestClass pigeon_instance, + Map aMap, + )? flutterEchoProxyApiMap; + + /// Returns the passed enum to test serialization and deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoEnum: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final AnEnum Function( + ProxyApiTestClass pigeon_instance, + AnEnum anEnum, + )? flutterEchoEnum; + + /// Returns the passed ProxyApi to test serialization and deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoProxyApi: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final ProxyApiSuperClass Function( + ProxyApiTestClass pigeon_instance, + ProxyApiSuperClass aProxyApi, + )? flutterEchoProxyApi; + + /// Returns the passed boolean, to test serialization and deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoNullableBool: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final bool? Function( + ProxyApiTestClass pigeon_instance, + bool? aBool, + )? flutterEchoNullableBool; + + /// Returns the passed int, to test serialization and deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoNullableInt: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final int? Function( + ProxyApiTestClass pigeon_instance, + int? anInt, + )? flutterEchoNullableInt; + + /// Returns the passed double, to test serialization and deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoNullableDouble: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final double? Function( + ProxyApiTestClass pigeon_instance, + double? aDouble, + )? flutterEchoNullableDouble; + + /// Returns the passed string, to test serialization and deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoNullableString: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final String? Function( + ProxyApiTestClass pigeon_instance, + String? aString, + )? flutterEchoNullableString; + + /// Returns the passed byte list, to test serialization and deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoNullableUint8List: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final Uint8List? Function( + ProxyApiTestClass pigeon_instance, + Uint8List? aList, + )? flutterEchoNullableUint8List; + + /// Returns the passed list, to test serialization and deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoNullableList: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final List? Function( + ProxyApiTestClass pigeon_instance, + List? aList, + )? flutterEchoNullableList; + + /// Returns the passed map, to test serialization and deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoNullableMap: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final Map? Function( + ProxyApiTestClass pigeon_instance, + Map? aMap, + )? flutterEchoNullableMap; + + /// Returns the passed enum to test serialization and deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoNullableEnum: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final AnEnum? Function( + ProxyApiTestClass pigeon_instance, + AnEnum? anEnum, + )? flutterEchoNullableEnum; + + /// Returns the passed ProxyApi to test serialization and deserialization. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoNullableProxyApi: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final ProxyApiSuperClass? Function( + ProxyApiTestClass pigeon_instance, + ProxyApiSuperClass? aProxyApi, + )? flutterEchoNullableProxyApi; + + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic asynchronous calling. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterNoopAsync: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final Future Function(ProxyApiTestClass pigeon_instance)? + flutterNoopAsync; + + /// Returns the passed in generic Object asynchronously. + /// + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiTestClass instance = ProxyApiTestClass( + /// flutterEchoAsyncString: (ProxyApiTestClass pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final Future Function( + ProxyApiTestClass pigeon_instance, + String aString, + )? flutterEchoAsyncString; + + @override + final void Function(ProxyApiInterface pigeon_instance)? anInterfaceMethod; + + late final ProxyApiSuperClass attachedField = __pigeon_attachedField(); + + static final ProxyApiSuperClass staticAttachedField = + __pigeon_staticAttachedField(); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + Pigeon_InstanceManager? pigeon_instanceManager, + ProxyApiTestClass Function( + bool aBool, + int anInt, + double aDouble, + String aString, + Uint8List aUint8List, + List aList, + Map aMap, + AnEnum anEnum, + ProxyApiSuperClass aProxyApi, + bool? aNullableBool, + int? aNullableInt, + double? aNullableDouble, + String? aNullableString, + Uint8List? aNullableUint8List, + List? aNullableList, + Map? aNullableMap, + AnEnum? aNullableEnum, + ProxyApiSuperClass? aNullableProxyApi, + )? pigeon_newInstance, + void Function(ProxyApiTestClass pigeon_instance)? flutterNoop, + Object? Function(ProxyApiTestClass pigeon_instance)? flutterThrowError, + void Function(ProxyApiTestClass pigeon_instance)? flutterThrowErrorFromVoid, + bool Function( + ProxyApiTestClass pigeon_instance, + bool aBool, + )? flutterEchoBool, + int Function( + ProxyApiTestClass pigeon_instance, + int anInt, + )? flutterEchoInt, + double Function( + ProxyApiTestClass pigeon_instance, + double aDouble, + )? flutterEchoDouble, + String Function( + ProxyApiTestClass pigeon_instance, + String aString, + )? flutterEchoString, + Uint8List Function( + ProxyApiTestClass pigeon_instance, + Uint8List aList, + )? flutterEchoUint8List, + List Function( + ProxyApiTestClass pigeon_instance, + List aList, + )? flutterEchoList, + List Function( + ProxyApiTestClass pigeon_instance, + List aList, + )? flutterEchoProxyApiList, + Map Function( + ProxyApiTestClass pigeon_instance, + Map aMap, + )? flutterEchoMap, + Map Function( + ProxyApiTestClass pigeon_instance, + Map aMap, + )? flutterEchoProxyApiMap, + AnEnum Function( + ProxyApiTestClass pigeon_instance, + AnEnum anEnum, + )? flutterEchoEnum, + ProxyApiSuperClass Function( + ProxyApiTestClass pigeon_instance, + ProxyApiSuperClass aProxyApi, + )? flutterEchoProxyApi, + bool? Function( + ProxyApiTestClass pigeon_instance, + bool? aBool, + )? flutterEchoNullableBool, + int? Function( + ProxyApiTestClass pigeon_instance, + int? anInt, + )? flutterEchoNullableInt, + double? Function( + ProxyApiTestClass pigeon_instance, + double? aDouble, + )? flutterEchoNullableDouble, + String? Function( + ProxyApiTestClass pigeon_instance, + String? aString, + )? flutterEchoNullableString, + Uint8List? Function( + ProxyApiTestClass pigeon_instance, + Uint8List? aList, + )? flutterEchoNullableUint8List, + List? Function( + ProxyApiTestClass pigeon_instance, + List? aList, + )? flutterEchoNullableList, + Map? Function( + ProxyApiTestClass pigeon_instance, + Map? aMap, + )? flutterEchoNullableMap, + AnEnum? Function( + ProxyApiTestClass pigeon_instance, + AnEnum? anEnum, + )? flutterEchoNullableEnum, + ProxyApiSuperClass? Function( + ProxyApiTestClass pigeon_instance, + ProxyApiSuperClass? aProxyApi, + )? flutterEchoNullableProxyApi, + Future Function(ProxyApiTestClass pigeon_instance)? flutterNoopAsync, + Future Function( + ProxyApiTestClass pigeon_instance, + String aString, + )? flutterEchoAsyncString, + }) { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + _Pigeon_ProxyApiBaseCodec( + pigeon_instanceManager ?? Pigeon_InstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_newInstance was null, expected non-null int.'); + final bool? arg_aBool = (args[1] as bool?); + assert(arg_aBool != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_newInstance was null, expected non-null bool.'); + final int? arg_anInt = (args[2] as int?); + assert(arg_anInt != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_newInstance was null, expected non-null int.'); + final double? arg_aDouble = (args[3] as double?); + assert(arg_aDouble != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_newInstance was null, expected non-null double.'); + final String? arg_aString = (args[4] as String?); + assert(arg_aString != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_newInstance was null, expected non-null String.'); + final Uint8List? arg_aUint8List = (args[5] as Uint8List?); + assert(arg_aUint8List != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_newInstance was null, expected non-null Uint8List.'); + final List? arg_aList = + (args[6] as List?)?.cast(); + assert(arg_aList != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_newInstance was null, expected non-null List.'); + final Map? arg_aMap = + (args[7] as Map?)?.cast(); + assert(arg_aMap != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_newInstance was null, expected non-null Map.'); + final AnEnum? arg_anEnum = + args[8] == null ? null : AnEnum.values[args[8]! as int]; + assert(arg_anEnum != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_newInstance was null, expected non-null AnEnum.'); + final ProxyApiSuperClass? arg_aProxyApi = + (args[9] as ProxyApiSuperClass?); + assert(arg_aProxyApi != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_newInstance was null, expected non-null ProxyApiSuperClass.'); + final bool? arg_aNullableBool = (args[10] as bool?); + final int? arg_aNullableInt = (args[11] as int?); + final double? arg_aNullableDouble = (args[12] as double?); + final String? arg_aNullableString = (args[13] as String?); + final Uint8List? arg_aNullableUint8List = (args[14] as Uint8List?); + final List? arg_aNullableList = + (args[15] as List?)?.cast(); + final Map? arg_aNullableMap = + (args[16] as Map?)?.cast(); + final AnEnum? arg_aNullableEnum = + args[17] == null ? null : AnEnum.values[args[17]! as int]; + final ProxyApiSuperClass? arg_aNullableProxyApi = + (args[18] as ProxyApiSuperClass?); + try { + (pigeon_instanceManager ?? Pigeon_InstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call( + arg_aBool!, + arg_anInt!, + arg_aDouble!, + arg_aString!, + arg_aUint8List!, + arg_aList!, + arg_aMap!, + arg_anEnum!, + arg_aProxyApi!, + arg_aNullableBool, + arg_aNullableInt, + arg_aNullableDouble, + arg_aNullableString, + arg_aNullableUint8List, + arg_aNullableList, + arg_aNullableMap, + arg_aNullableEnum, + arg_aNullableProxyApi) ?? + ProxyApiTestClass.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + aBool: arg_aBool!, + anInt: arg_anInt!, + aDouble: arg_aDouble!, + aString: arg_aString!, + aUint8List: arg_aUint8List!, + aList: arg_aList!, + aMap: arg_aMap!, + anEnum: arg_anEnum!, + aProxyApi: arg_aProxyApi!, + aNullableBool: arg_aNullableBool, + aNullableInt: arg_aNullableInt, + aNullableDouble: arg_aNullableDouble, + aNullableString: arg_aNullableString, + aNullableUint8List: arg_aNullableUint8List, + aNullableList: arg_aNullableList, + aNullableMap: arg_aNullableMap, + aNullableEnum: arg_aNullableEnum, + aNullableProxyApi: arg_aNullableProxyApi, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterNoop', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterNoop was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterNoop was null, expected non-null ProxyApiTestClass.'); + try { + (flutterNoop ?? arg_pigeon_instance!.flutterNoop) + ?.call(arg_pigeon_instance!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterThrowError', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterThrowError was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterThrowError was null, expected non-null ProxyApiTestClass.'); + try { + final Object? output = + (flutterThrowError ?? arg_pigeon_instance!.flutterThrowError) + ?.call(arg_pigeon_instance!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterThrowErrorFromVoid', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterThrowErrorFromVoid was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterThrowErrorFromVoid was null, expected non-null ProxyApiTestClass.'); + try { + (flutterThrowErrorFromVoid ?? + arg_pigeon_instance!.flutterThrowErrorFromVoid) + ?.call(arg_pigeon_instance!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoBool', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoBool was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoBool was null, expected non-null ProxyApiTestClass.'); + final bool? arg_aBool = (args[1] as bool?); + assert(arg_aBool != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoBool was null, expected non-null bool.'); + try { + final bool? output = + (flutterEchoBool ?? arg_pigeon_instance!.flutterEchoBool) + ?.call(arg_pigeon_instance!, arg_aBool!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoInt', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoInt was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoInt was null, expected non-null ProxyApiTestClass.'); + final int? arg_anInt = (args[1] as int?); + assert(arg_anInt != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoInt was null, expected non-null int.'); + try { + final int? output = + (flutterEchoInt ?? arg_pigeon_instance!.flutterEchoInt) + ?.call(arg_pigeon_instance!, arg_anInt!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoDouble', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoDouble was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoDouble was null, expected non-null ProxyApiTestClass.'); + final double? arg_aDouble = (args[1] as double?); + assert(arg_aDouble != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoDouble was null, expected non-null double.'); + try { + final double? output = + (flutterEchoDouble ?? arg_pigeon_instance!.flutterEchoDouble) + ?.call(arg_pigeon_instance!, arg_aDouble!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoString', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoString was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoString was null, expected non-null ProxyApiTestClass.'); + final String? arg_aString = (args[1] as String?); + assert(arg_aString != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoString was null, expected non-null String.'); + try { + final String? output = + (flutterEchoString ?? arg_pigeon_instance!.flutterEchoString) + ?.call(arg_pigeon_instance!, arg_aString!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoUint8List', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoUint8List was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoUint8List was null, expected non-null ProxyApiTestClass.'); + final Uint8List? arg_aList = (args[1] as Uint8List?); + assert(arg_aList != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoUint8List was null, expected non-null Uint8List.'); + try { + final Uint8List? output = (flutterEchoUint8List ?? + arg_pigeon_instance!.flutterEchoUint8List) + ?.call(arg_pigeon_instance!, arg_aList!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoList', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoList was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoList was null, expected non-null ProxyApiTestClass.'); + final List? arg_aList = + (args[1] as List?)?.cast(); + assert(arg_aList != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoList was null, expected non-null List.'); + try { + final List? output = + (flutterEchoList ?? arg_pigeon_instance!.flutterEchoList) + ?.call(arg_pigeon_instance!, arg_aList!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoProxyApiList', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoProxyApiList was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoProxyApiList was null, expected non-null ProxyApiTestClass.'); + final List? arg_aList = + (args[1] as List?)?.cast(); + assert(arg_aList != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoProxyApiList was null, expected non-null List.'); + try { + final List? output = (flutterEchoProxyApiList ?? + arg_pigeon_instance!.flutterEchoProxyApiList) + ?.call(arg_pigeon_instance!, arg_aList!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoMap', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoMap was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoMap was null, expected non-null ProxyApiTestClass.'); + final Map? arg_aMap = + (args[1] as Map?)?.cast(); + assert(arg_aMap != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoMap was null, expected non-null Map.'); + try { + final Map? output = + (flutterEchoMap ?? arg_pigeon_instance!.flutterEchoMap) + ?.call(arg_pigeon_instance!, arg_aMap!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoProxyApiMap', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoProxyApiMap was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoProxyApiMap was null, expected non-null ProxyApiTestClass.'); + final Map? arg_aMap = + (args[1] as Map?) + ?.cast(); + assert(arg_aMap != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoProxyApiMap was null, expected non-null Map.'); + try { + final Map? output = + (flutterEchoProxyApiMap ?? + arg_pigeon_instance!.flutterEchoProxyApiMap) + ?.call(arg_pigeon_instance!, arg_aMap!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoEnum', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoEnum was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoEnum was null, expected non-null ProxyApiTestClass.'); + final AnEnum? arg_anEnum = + args[1] == null ? null : AnEnum.values[args[1]! as int]; + assert(arg_anEnum != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoEnum was null, expected non-null AnEnum.'); + try { + final AnEnum? output = + (flutterEchoEnum ?? arg_pigeon_instance!.flutterEchoEnum) + ?.call(arg_pigeon_instance!, arg_anEnum!); + return wrapResponse(result: output?.index); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoProxyApi', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoProxyApi was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoProxyApi was null, expected non-null ProxyApiTestClass.'); + final ProxyApiSuperClass? arg_aProxyApi = + (args[1] as ProxyApiSuperClass?); + assert(arg_aProxyApi != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoProxyApi was null, expected non-null ProxyApiSuperClass.'); + try { + final ProxyApiSuperClass? output = (flutterEchoProxyApi ?? + arg_pigeon_instance!.flutterEchoProxyApi) + ?.call(arg_pigeon_instance!, arg_aProxyApi!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableBool', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableBool was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableBool was null, expected non-null ProxyApiTestClass.'); + final bool? arg_aBool = (args[1] as bool?); + try { + final bool? output = (flutterEchoNullableBool ?? + arg_pigeon_instance!.flutterEchoNullableBool) + ?.call(arg_pigeon_instance!, arg_aBool); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableInt', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableInt was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableInt was null, expected non-null ProxyApiTestClass.'); + final int? arg_anInt = (args[1] as int?); + try { + final int? output = (flutterEchoNullableInt ?? + arg_pigeon_instance!.flutterEchoNullableInt) + ?.call(arg_pigeon_instance!, arg_anInt); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableDouble', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableDouble was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableDouble was null, expected non-null ProxyApiTestClass.'); + final double? arg_aDouble = (args[1] as double?); + try { + final double? output = (flutterEchoNullableDouble ?? + arg_pigeon_instance!.flutterEchoNullableDouble) + ?.call(arg_pigeon_instance!, arg_aDouble); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableString', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableString was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableString was null, expected non-null ProxyApiTestClass.'); + final String? arg_aString = (args[1] as String?); + try { + final String? output = (flutterEchoNullableString ?? + arg_pigeon_instance!.flutterEchoNullableString) + ?.call(arg_pigeon_instance!, arg_aString); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableUint8List', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableUint8List was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableUint8List was null, expected non-null ProxyApiTestClass.'); + final Uint8List? arg_aList = (args[1] as Uint8List?); + try { + final Uint8List? output = (flutterEchoNullableUint8List ?? + arg_pigeon_instance!.flutterEchoNullableUint8List) + ?.call(arg_pigeon_instance!, arg_aList); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableList', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableList was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableList was null, expected non-null ProxyApiTestClass.'); + final List? arg_aList = + (args[1] as List?)?.cast(); + try { + final List? output = (flutterEchoNullableList ?? + arg_pigeon_instance!.flutterEchoNullableList) + ?.call(arg_pigeon_instance!, arg_aList); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableMap', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableMap was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableMap was null, expected non-null ProxyApiTestClass.'); + final Map? arg_aMap = + (args[1] as Map?)?.cast(); + try { + final Map? output = (flutterEchoNullableMap ?? + arg_pigeon_instance!.flutterEchoNullableMap) + ?.call(arg_pigeon_instance!, arg_aMap); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableEnum', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableEnum was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableEnum was null, expected non-null ProxyApiTestClass.'); + final AnEnum? arg_anEnum = + args[1] == null ? null : AnEnum.values[args[1]! as int]; + try { + final AnEnum? output = (flutterEchoNullableEnum ?? + arg_pigeon_instance!.flutterEchoNullableEnum) + ?.call(arg_pigeon_instance!, arg_anEnum); + return wrapResponse(result: output?.index); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableProxyApi', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableProxyApi was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableProxyApi was null, expected non-null ProxyApiTestClass.'); + final ProxyApiSuperClass? arg_aProxyApi = + (args[1] as ProxyApiSuperClass?); + try { + final ProxyApiSuperClass? output = (flutterEchoNullableProxyApi ?? + arg_pigeon_instance!.flutterEchoNullableProxyApi) + ?.call(arg_pigeon_instance!, arg_aProxyApi); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterNoopAsync', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterNoopAsync was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterNoopAsync was null, expected non-null ProxyApiTestClass.'); + try { + await (flutterNoopAsync ?? arg_pigeon_instance!.flutterNoopAsync) + ?.call(arg_pigeon_instance!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoAsyncString', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoAsyncString was null.'); + final List args = (message as List?)!; + final ProxyApiTestClass? arg_pigeon_instance = + (args[0] as ProxyApiTestClass?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoAsyncString was null, expected non-null ProxyApiTestClass.'); + final String? arg_aString = (args[1] as String?); + assert(arg_aString != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoAsyncString was null, expected non-null String.'); + try { + final String? output = await (flutterEchoAsyncString ?? + arg_pigeon_instance!.flutterEchoAsyncString) + ?.call(arg_pigeon_instance!, arg_aString!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + ProxyApiSuperClass __pigeon_attachedField() { + final ProxyApiSuperClass __pigeon_instance = + ProxyApiSuperClass.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ); + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + final int __pigeon_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(__pigeon_instance); + () async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.attachedField'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, __pigeon_instanceIdentifier]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + }(); + return __pigeon_instance; + } + + static ProxyApiSuperClass __pigeon_staticAttachedField() { + final ProxyApiSuperClass __pigeon_instance = + ProxyApiSuperClass.pigeon_detached(); + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + _Pigeon_ProxyApiBaseCodec(Pigeon_InstanceManager.instance); + final BinaryMessenger __pigeon_binaryMessenger = + ServicesBinding.instance.defaultBinaryMessenger; + final int __pigeon_instanceIdentifier = Pigeon_InstanceManager.instance + .addDartCreatedInstance(__pigeon_instance); + () async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.staticAttachedField'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([__pigeon_instanceIdentifier]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + }(); + return __pigeon_instance; + } + + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic calling. + Future noop() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.noop'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + /// Returns an error, to test error handling. + Future throwError() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.throwError'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return __pigeon_replyList[0]; + } + } + + /// Returns an error from a void function, to test error handling. + Future throwErrorFromVoid() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.throwErrorFromVoid'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + /// Returns a Flutter error, to test error handling. + Future throwFlutterError() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.throwFlutterError'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return __pigeon_replyList[0]; + } + } + + /// Returns passed in int. + Future echoInt(int anInt) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoInt'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, anInt]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as int?)!; + } + } + + /// Returns passed in double. + Future echoDouble(double aDouble) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoDouble'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aDouble]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as double?)!; + } + } + + /// Returns the passed in boolean. + Future echoBool(bool aBool) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoBool'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aBool]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as bool?)!; + } + } + + /// Returns the passed in string. + Future echoString(String aString) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aString]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as String?)!; + } + } + + /// Returns the passed in Uint8List. + Future echoUint8List(Uint8List aUint8List) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoUint8List'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, aUint8List]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Uint8List?)!; + } + } + + /// Returns the passed in generic Object. + Future echoObject(Object anObject) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoObject'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, anObject]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return __pigeon_replyList[0]!; + } + } + + /// Returns the passed list, to test serialization and deserialization. + Future> echoList(List aList) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoList'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aList]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as List?)!.cast(); + } + } + + /// Returns the passed list with ProxyApis, to test serialization and + /// deserialization. + Future> echoProxyApiList( + List aList) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoProxyApiList'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aList]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as List?)! + .cast(); + } + } + + /// Returns the passed map, to test serialization and deserialization. + Future> echoMap(Map aMap) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoMap'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aMap]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Map?)! + .cast(); + } + } + + /// Returns the passed map with ProxyApis, to test serialization and + /// deserialization. + Future> echoProxyApiMap( + Map aMap) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoProxyApiMap'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aMap]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Map?)! + .cast(); + } + } + + /// Returns the passed enum to test serialization and deserialization. + Future echoEnum(AnEnum anEnum) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoEnum'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, anEnum.index]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return AnEnum.values[__pigeon_replyList[0]! as int]; + } + } + + /// Returns the passed ProxyApi to test serialization and deserialization. + Future echoProxyApi(ProxyApiSuperClass aProxyApi) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoProxyApi'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, aProxyApi]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as ProxyApiSuperClass?)!; + } + } + + /// Returns passed in int. + Future echoNullableInt(int? aNullableInt) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableInt'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, aNullableInt]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as int?); + } + } + + /// Returns passed in double. + Future echoNullableDouble(double? aNullableDouble) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableDouble'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, aNullableDouble]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as double?); + } + } + + /// Returns the passed in boolean. + Future echoNullableBool(bool? aNullableBool) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableBool'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, aNullableBool]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as bool?); + } + } + + /// Returns the passed in string. + Future echoNullableString(String? aNullableString) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, aNullableString]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as String?); + } + } + + /// Returns the passed in Uint8List. + Future echoNullableUint8List( + Uint8List? aNullableUint8List) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableUint8List'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, aNullableUint8List]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as Uint8List?); + } + } + + /// Returns the passed in generic Object. + Future echoNullableObject(Object? aNullableObject) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableObject'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, aNullableObject]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return __pigeon_replyList[0]; + } + } + + /// Returns the passed list, to test serialization and deserialization. + Future?> echoNullableList(List? aNullableList) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableList'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, aNullableList]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as List?)?.cast(); + } + } + + /// Returns the passed map, to test serialization and deserialization. + Future?> echoNullableMap( + Map? aNullableMap) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableMap'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, aNullableMap]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as Map?) + ?.cast(); + } + } + + Future echoNullableEnum(AnEnum? aNullableEnum) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableEnum'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, aNullableEnum?.index]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as int?) == null + ? null + : AnEnum.values[__pigeon_replyList[0]! as int]; + } + } + + /// Returns the passed ProxyApi to test serialization and deserialization. + Future echoNullableProxyApi( + ProxyApiSuperClass? aNullableProxyApi) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableProxyApi'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, aNullableProxyApi]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as ProxyApiSuperClass?); + } + } + + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic asynchronous calling. + Future noopAsync() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.noopAsync'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + /// Returns passed in int asynchronously. + Future echoAsyncInt(int anInt) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncInt'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, anInt]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as int?)!; + } + } + + /// Returns passed in double asynchronously. + Future echoAsyncDouble(double aDouble) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncDouble'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aDouble]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as double?)!; + } + } + + /// Returns the passed in boolean asynchronously. + Future echoAsyncBool(bool aBool) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncBool'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aBool]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as bool?)!; + } + } + + /// Returns the passed string asynchronously. + Future echoAsyncString(String aString) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aString]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as String?)!; + } + } + + /// Returns the passed in Uint8List asynchronously. + Future echoAsyncUint8List(Uint8List aUint8List) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncUint8List'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, aUint8List]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Uint8List?)!; + } + } + + /// Returns the passed in generic Object asynchronously. + Future echoAsyncObject(Object anObject) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncObject'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, anObject]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return __pigeon_replyList[0]!; + } + } + + /// Returns the passed list, to test asynchronous serialization and deserialization. + Future> echoAsyncList(List aList) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncList'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aList]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as List?)!.cast(); + } + } + + /// Returns the passed map, to test asynchronous serialization and deserialization. + Future> echoAsyncMap(Map aMap) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncMap'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aMap]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Map?)! + .cast(); + } + } + + /// Returns the passed enum, to test asynchronous serialization and deserialization. + Future echoAsyncEnum(AnEnum anEnum) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncEnum'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, anEnum.index]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return AnEnum.values[__pigeon_replyList[0]! as int]; + } + } + + /// Responds with an error from an async function returning a value. + Future throwAsyncError() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.throwAsyncError'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return __pigeon_replyList[0]; + } + } + + /// Responds with an error from an async void function. + Future throwAsyncErrorFromVoid() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.throwAsyncErrorFromVoid'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + /// Responds with a Flutter error from an async function returning a value. + Future throwAsyncFlutterError() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.throwAsyncFlutterError'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return __pigeon_replyList[0]; + } + } + + /// Returns passed in int asynchronously. + Future echoAsyncNullableInt(int? anInt) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableInt'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, anInt]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as int?); + } + } + + /// Returns passed in double asynchronously. + Future echoAsyncNullableDouble(double? aDouble) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableDouble'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aDouble]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as double?); + } + } + + /// Returns the passed in boolean asynchronously. + Future echoAsyncNullableBool(bool? aBool) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableBool'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aBool]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as bool?); + } + } + + /// Returns the passed string asynchronously. + Future echoAsyncNullableString(String? aString) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aString]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as String?); + } + } + + /// Returns the passed in Uint8List asynchronously. + Future echoAsyncNullableUint8List(Uint8List? aUint8List) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableUint8List'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, aUint8List]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as Uint8List?); + } + } + + /// Returns the passed in generic Object asynchronously. + Future echoAsyncNullableObject(Object? anObject) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableObject'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, anObject]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return __pigeon_replyList[0]; + } + } + + /// Returns the passed list, to test asynchronous serialization and deserialization. + Future?> echoAsyncNullableList(List? aList) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableList'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aList]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as List?)?.cast(); + } + } + + /// Returns the passed map, to test asynchronous serialization and deserialization. + Future?> echoAsyncNullableMap( + Map? aMap) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableMap'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aMap]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as Map?) + ?.cast(); + } + } + + /// Returns the passed enum, to test asynchronous serialization and deserialization. + Future echoAsyncNullableEnum(AnEnum? anEnum) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableEnum'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, anEnum?.index]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as int?) == null + ? null + : AnEnum.values[__pigeon_replyList[0]! as int]; + } + } + + static Future staticNoop({ + BinaryMessenger? pigeon_binaryMessenger, + Pigeon_InstanceManager? pigeon_instanceManager, + }) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + _Pigeon_ProxyApiBaseCodec( + pigeon_instanceManager ?? Pigeon_InstanceManager.instance); + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.staticNoop'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + static Future echoStaticString( + String aString, { + BinaryMessenger? pigeon_binaryMessenger, + Pigeon_InstanceManager? pigeon_instanceManager, + }) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + _Pigeon_ProxyApiBaseCodec( + pigeon_instanceManager ?? Pigeon_InstanceManager.instance); + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoStaticString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([aString]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as String?)!; + } + } + + static Future staticAsyncNoop({ + BinaryMessenger? pigeon_binaryMessenger, + Pigeon_InstanceManager? pigeon_instanceManager, + }) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + _Pigeon_ProxyApiBaseCodec( + pigeon_instanceManager ?? Pigeon_InstanceManager.instance); + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.staticAsyncNoop'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future callFlutterNoop() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterNoop'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future callFlutterThrowError() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterThrowError'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return __pigeon_replyList[0]; + } + } + + Future callFlutterThrowErrorFromVoid() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterThrowErrorFromVoid'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future callFlutterEchoBool(bool aBool) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoBool'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aBool]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as bool?)!; + } + } + + Future callFlutterEchoInt(int anInt) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoInt'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, anInt]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as int?)!; + } + } + + Future callFlutterEchoDouble(double aDouble) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoDouble'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aDouble]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as double?)!; + } + } + + Future callFlutterEchoString(String aString) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aString]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as String?)!; + } + } + + Future callFlutterEchoUint8List(Uint8List aUint8List) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoUint8List'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, aUint8List]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Uint8List?)!; + } + } + + Future> callFlutterEchoList(List aList) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoList'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aList]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as List?)!.cast(); + } + } + + Future> callFlutterEchoProxyApiList( + List aList) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoProxyApiList'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aList]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as List?)! + .cast(); + } + } + + Future> callFlutterEchoMap( + Map aMap) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoMap'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aMap]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Map?)! + .cast(); + } + } + + Future> callFlutterEchoProxyApiMap( + Map aMap) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoProxyApiMap'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aMap]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Map?)! + .cast(); + } + } + + Future callFlutterEchoEnum(AnEnum anEnum) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoEnum'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, anEnum.index]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return AnEnum.values[__pigeon_replyList[0]! as int]; + } + } + + Future callFlutterEchoProxyApi( + ProxyApiSuperClass aProxyApi) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoProxyApi'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, aProxyApi]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as ProxyApiSuperClass?)!; + } + } + + Future callFlutterEchoNullableBool(bool? aBool) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableBool'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aBool]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as bool?); + } + } + + Future callFlutterEchoNullableInt(int? anInt) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableInt'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, anInt]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as int?); + } + } + + Future callFlutterEchoNullableDouble(double? aDouble) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableDouble'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aDouble]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as double?); + } + } + + Future callFlutterEchoNullableString(String? aString) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aString]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as String?); + } + } + + Future callFlutterEchoNullableUint8List( + Uint8List? aUint8List) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableUint8List'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, aUint8List]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as Uint8List?); + } + } + + Future?> callFlutterEchoNullableList( + List? aList) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableList'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aList]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as List?)?.cast(); + } + } + + Future?> callFlutterEchoNullableMap( + Map? aMap) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableMap'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aMap]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as Map?) + ?.cast(); + } + } + + Future callFlutterEchoNullableEnum(AnEnum? anEnum) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableEnum'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, anEnum?.index]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as int?) == null + ? null + : AnEnum.values[__pigeon_replyList[0]! as int]; + } + } + + Future callFlutterEchoNullableProxyApi( + ProxyApiSuperClass? aProxyApi) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableProxyApi'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([this, aProxyApi]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as ProxyApiSuperClass?); + } + } + + Future callFlutterNoopAsync() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterNoopAsync'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future callFlutterEchoAsyncString(String aString) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiTestClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoAsyncString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this, aString]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as String?)!; + } + } + + @override + ProxyApiTestClass pigeon_copy() { + return ProxyApiTestClass.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + aBool: aBool, + anInt: anInt, + aDouble: aDouble, + aString: aString, + aUint8List: aUint8List, + aList: aList, + aMap: aMap, + anEnum: anEnum, + aProxyApi: aProxyApi, + aNullableBool: aNullableBool, + aNullableInt: aNullableInt, + aNullableDouble: aNullableDouble, + aNullableString: aNullableString, + aNullableUint8List: aNullableUint8List, + aNullableList: aNullableList, + aNullableMap: aNullableMap, + aNullableEnum: aNullableEnum, + aNullableProxyApi: aNullableProxyApi, + anInterfaceMethod: anInterfaceMethod, + flutterNoop: flutterNoop, + flutterThrowError: flutterThrowError, + flutterThrowErrorFromVoid: flutterThrowErrorFromVoid, + flutterEchoBool: flutterEchoBool, + flutterEchoInt: flutterEchoInt, + flutterEchoDouble: flutterEchoDouble, + flutterEchoString: flutterEchoString, + flutterEchoUint8List: flutterEchoUint8List, + flutterEchoList: flutterEchoList, + flutterEchoProxyApiList: flutterEchoProxyApiList, + flutterEchoMap: flutterEchoMap, + flutterEchoProxyApiMap: flutterEchoProxyApiMap, + flutterEchoEnum: flutterEchoEnum, + flutterEchoProxyApi: flutterEchoProxyApi, + flutterEchoNullableBool: flutterEchoNullableBool, + flutterEchoNullableInt: flutterEchoNullableInt, + flutterEchoNullableDouble: flutterEchoNullableDouble, + flutterEchoNullableString: flutterEchoNullableString, + flutterEchoNullableUint8List: flutterEchoNullableUint8List, + flutterEchoNullableList: flutterEchoNullableList, + flutterEchoNullableMap: flutterEchoNullableMap, + flutterEchoNullableEnum: flutterEchoNullableEnum, + flutterEchoNullableProxyApi: flutterEchoNullableProxyApi, + flutterNoopAsync: flutterNoopAsync, + flutterEchoAsyncString: flutterEchoAsyncString, + ); + } +} + +/// ProxyApi to serve as a super class to the core ProxyApi interface. +class ProxyApiSuperClass extends Pigeon_ProxyApiBaseClass { + ProxyApiSuperClass({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + }) { + final int __pigeon_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiSuperClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + () async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.pigeon_defaultConstructor'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([__pigeon_instanceIdentifier]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + }(); + } + + /// Constructs ProxyApiSuperClass without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [Pigeon_InstanceManager]. + ProxyApiSuperClass.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + }); + + late final _Pigeon_ProxyApiBaseCodec __pigeon_codecProxyApiSuperClass = + _Pigeon_ProxyApiBaseCodec(pigeon_instanceManager); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + Pigeon_InstanceManager? pigeon_instanceManager, + ProxyApiSuperClass Function()? pigeon_newInstance, + }) { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + _Pigeon_ProxyApiBaseCodec( + pigeon_instanceManager ?? Pigeon_InstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? Pigeon_InstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + ProxyApiSuperClass.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + Future aSuperMethod() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiSuperClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.aSuperMethod'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([this]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + @override + ProxyApiSuperClass pigeon_copy() { + return ProxyApiSuperClass.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ); + } +} + +/// ProxyApi to serve as an interface to the core ProxyApi interface. +class ProxyApiInterface extends Pigeon_ProxyApiBaseClass { + /// Constructs ProxyApiInterface without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [Pigeon_InstanceManager]. + ProxyApiInterface.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + this.anInterfaceMethod, + }); + + /// Dart: + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final ProxyApiInterface instance = ProxyApiInterface( + /// anInterfaceMethod: (ProxyApiInterface pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. + final void Function(ProxyApiInterface pigeon_instance)? anInterfaceMethod; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + Pigeon_InstanceManager? pigeon_instanceManager, + ProxyApiInterface Function()? pigeon_newInstance, + void Function(ProxyApiInterface pigeon_instance)? anInterfaceMethod, + }) { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + _Pigeon_ProxyApiBaseCodec( + pigeon_instanceManager ?? Pigeon_InstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? Pigeon_InstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + ProxyApiInterface.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.anInterfaceMethod', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.anInterfaceMethod was null.'); + final List args = (message as List?)!; + final ProxyApiInterface? arg_pigeon_instance = + (args[0] as ProxyApiInterface?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.anInterfaceMethod was null, expected non-null ProxyApiInterface.'); + try { + (anInterfaceMethod ?? arg_pigeon_instance!.anInterfaceMethod) + ?.call(arg_pigeon_instance!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + @override + ProxyApiInterface pigeon_copy() { + return ProxyApiInterface.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + anInterfaceMethod: anInterfaceMethod, + ); + } +} diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/test/instance_manager_test.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/test/instance_manager_test.dart new file mode 100644 index 000000000000..fc5ceba03dfb --- /dev/null +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/test/instance_manager_test.dart @@ -0,0 +1,168 @@ +// 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. + +// This file specifically tests the test Pigeon_InstanceManager generated by core_tests. + +import 'package:flutter_test/flutter_test.dart'; +import 'package:shared_test_plugin_code/src/generated/proxy_api_tests.gen.dart'; + +void main() { + group('InstanceManager', () { + test('addHostCreatedInstance', () { + final Pigeon_InstanceManager instanceManager = + Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + + final CopyableObject object = CopyableObject( + pigeon_instanceManager: instanceManager, + ); + + instanceManager.addHostCreatedInstance(object, 0); + + expect(instanceManager.getIdentifier(object), 0); + expect( + instanceManager.getInstanceWithWeakReference(0), + object, + ); + }); + + test('addHostCreatedInstance prevents already used objects and ids', () { + final Pigeon_InstanceManager instanceManager = + Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + + final CopyableObject object = CopyableObject( + pigeon_instanceManager: instanceManager, + ); + + instanceManager.addHostCreatedInstance(object, 0); + + expect( + () => instanceManager.addHostCreatedInstance(object, 0), + throwsAssertionError, + ); + + expect( + () => instanceManager.addHostCreatedInstance( + CopyableObject(pigeon_instanceManager: instanceManager), + 0, + ), + throwsAssertionError, + ); + }); + + test('addFlutterCreatedInstance', () { + final Pigeon_InstanceManager instanceManager = + Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + + final CopyableObject object = CopyableObject( + pigeon_instanceManager: instanceManager, + ); + + instanceManager.addDartCreatedInstance(object); + + final int? instanceId = instanceManager.getIdentifier(object); + expect(instanceId, isNotNull); + expect( + instanceManager.getInstanceWithWeakReference(instanceId!), + object, + ); + }); + + test('removeWeakReference', () { + int? weakInstanceId; + final Pigeon_InstanceManager instanceManager = + Pigeon_InstanceManager(onWeakReferenceRemoved: (int instanceId) { + weakInstanceId = instanceId; + }); + + final CopyableObject object = CopyableObject( + pigeon_instanceManager: instanceManager, + ); + + instanceManager.addHostCreatedInstance(object, 0); + + expect(instanceManager.removeWeakReference(object), 0); + expect( + instanceManager.getInstanceWithWeakReference(0), + isA(), + ); + expect(weakInstanceId, 0); + }); + + test('removeWeakReference removes only weak reference', () { + final Pigeon_InstanceManager instanceManager = + Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + + final CopyableObject object = CopyableObject( + pigeon_instanceManager: instanceManager, + ); + + instanceManager.addHostCreatedInstance(object, 0); + + expect(instanceManager.removeWeakReference(object), 0); + final CopyableObject copy = instanceManager.getInstanceWithWeakReference( + 0, + )!; + expect(identical(object, copy), isFalse); + }); + + test('removeStrongReference', () { + final Pigeon_InstanceManager instanceManager = + Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + + final CopyableObject object = CopyableObject( + pigeon_instanceManager: instanceManager, + ); + + instanceManager.addHostCreatedInstance(object, 0); + instanceManager.removeWeakReference(object); + expect(instanceManager.remove(0), isA()); + expect(instanceManager.containsIdentifier(0), isFalse); + }); + + test('removeStrongReference removes only strong reference', () { + final Pigeon_InstanceManager instanceManager = + Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + + final CopyableObject object = CopyableObject( + pigeon_instanceManager: instanceManager, + ); + + instanceManager.addHostCreatedInstance(object, 0); + expect(instanceManager.remove(0), isA()); + expect( + instanceManager.getInstanceWithWeakReference(0), + object, + ); + }); + + test('getInstance can add a new weak reference', () { + final Pigeon_InstanceManager instanceManager = + Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + + final CopyableObject object = CopyableObject( + pigeon_instanceManager: instanceManager, + ); + + instanceManager.addHostCreatedInstance(object, 0); + instanceManager.removeWeakReference(object); + + final CopyableObject newWeakCopy = + instanceManager.getInstanceWithWeakReference( + 0, + )!; + expect(identical(object, newWeakCopy), isFalse); + }); + }); +} + +class CopyableObject extends Pigeon_ProxyApiBaseClass { + // ignore: non_constant_identifier_names + CopyableObject({super.pigeon_instanceManager}); + + @override + // ignore: non_constant_identifier_names + CopyableObject pigeon_copy() { + return CopyableObject(pigeon_instanceManager: pigeon_instanceManager); + } +} diff --git a/packages/pigeon/tool/shared/generation.dart b/packages/pigeon/tool/shared/generation.dart index 9915e26aa57d..c14e923b85dc 100644 --- a/packages/pigeon/tool/shared/generation.dart +++ b/packages/pigeon/tool/shared/generation.dart @@ -68,6 +68,7 @@ Future generateTestPigeons({required String baseDir}) async { 'null_fields', 'nullable_returns', 'primitive', + 'proxy_api_tests', ]; final String outputBase = p.join(baseDir, 'platform_tests', 'test_plugin'); From fc3df6f14c748ab3c7c706a3aec10b3ce43b1b97 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 2 Feb 2024 14:58:51 -0500 Subject: [PATCH 24/32] method improvements --- packages/pigeon/lib/dart_generator.dart | 29 ++++++++++--------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 851649e98525..4cb24e0ab61b 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -516,11 +516,12 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; // All ProxyApis this API `implements` and all the interfaces those APIs // `implements`. - final Set interfacesApis = recursiveFindAllInterfaceApis(api); + final Set apisOfInterfaces = + recursiveFindAllInterfaceApis(api); // All methods inherited from interfaces and the interfaces of interfaces. final List flutterMethodsFromInterfaces = []; - for (final AstProxyApi proxyApi in interfacesApis) { + for (final AstProxyApi proxyApi in apisOfInterfaces) { flutterMethodsFromInterfaces.addAll(proxyApi.methods); } @@ -595,7 +596,7 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; api.flutterMethods, apiName: api.name, )) - ..fields.addAll(_proxyApiInterfaceApiFields(interfacesApis)) + ..fields.addAll(_proxyApiInterfaceApiFields(apisOfInterfaces)) ..fields.addAll(_proxyApiAttachedFields(api.attachedFields)) ..methods.add( _proxyApiSetUpMessageHandlerMethod( @@ -627,11 +628,11 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; codecName: codecName, )) ..methods.add(_proxyApiCopyMethod( - flutterMethods: api.flutterMethods, - flutterMethodsFromSuperClasses: flutterMethodsFromSuperClasses, apiName: api.name, unattachedFields: api.unattachedFields, - interfacesApis: interfacesApis, + declaredAndInheritedFlutterMethods: flutterMethodsFromSuperClasses + .followedBy(flutterMethodsFromInterfaces) + .followedBy(api.flutterMethods), )), ); @@ -1315,9 +1316,9 @@ if (${_varNamePrefix}replyList == null) { /// inherited from apis that are being implemented (following the `implements` /// keyword). Iterable _proxyApiInterfaceApiFields( - Iterable apis, + Iterable apisOfInterfaces, ) sync* { - for (final AstProxyApi proxyApi in apis) { + for (final AstProxyApi proxyApi in apisOfInterfaces) { for (final Method method in proxyApi.methods) { yield cb.Field( (cb.FieldBuilder builder) => builder @@ -1770,11 +1771,9 @@ if (${_varNamePrefix}replyList == null) { /// and unattached fields passed to the new instance. This method is inherited /// from the base ProxyApi class. cb.Method _proxyApiCopyMethod({ - required Iterable flutterMethods, - required Iterable flutterMethodsFromSuperClasses, required String apiName, required Iterable unattachedFields, - required Iterable interfacesApis, + required Iterable declaredAndInheritedFlutterMethods, }) { return cb.Method( (cb.MethodBuilder builder) => builder @@ -1792,12 +1791,8 @@ 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 flutterMethodsFromSuperClasses) - method.name: cb.refer(method.name), - for (final AstProxyApi proxyApi in interfacesApis) - for (final Method method in proxyApi.methods) - method.name: cb.refer(method.name), - for (final Method method in flutterMethods) + for (final Method method + in declaredAndInheritedFlutterMethods) method.name: cb.refer(method.name), }, ) From 0caa96372bf2971c98cd43fd80f20183e3dee24e Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 2 Feb 2024 15:11:34 -0500 Subject: [PATCH 25/32] add protected for more methods --- packages/pigeon/lib/dart/templates.dart | 2 + packages/pigeon/lib/dart_generator.dart | 7 ++- .../src/generated/proxy_api_tests.gen.dart | 63 ++++++++++--------- 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/packages/pigeon/lib/dart/templates.dart b/packages/pigeon/lib/dart/templates.dart index 5da28beafc30..6de2a11ee9a4 100644 --- a/packages/pigeon/lib/dart/templates.dart +++ b/packages/pigeon/lib/dart/templates.dart @@ -344,9 +344,11 @@ abstract class $proxyApiBaseClassName { /// /// If it is null, the default BinaryMessenger will be used, which routes to /// the host platform. + @protected final BinaryMessenger? $_proxyApiBaseClassMessengerVarName; /// Maintains instances stored to communicate with native language objects. + @protected final $instanceManagerClassName $_proxyApiBaseClassInstanceManagerVarName; /// Instantiates and returns a functionally identical object to oneself. diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 4cb24e0ab61b..a9b1eac032be 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -1170,11 +1170,12 @@ if (${_varNamePrefix}replyList == null) { (cb.ConstructorBuilder builder) => builder ..name = '${classMemberNamePrefix}detached' ..docs.addAll([ - '/// Constructs $apiName without creating the associated native object.', + '/// Constructs [$apiName] without creating the associated native object.', '///', '/// This should only be used by subclasses created by this library or to', '/// create copies for an [$instanceManagerClassName].', ]) + ..annotations.add(cb.refer('protected')) ..optionalParameters.addAll([ binaryMessengerParameter, instanceManagerParameter, @@ -1226,7 +1227,7 @@ if (${_varNamePrefix}replyList == null) { ); } - /// Converts unattached constructors from the pigeon AST to `code_builder` + /// Converts unattached fields from the pigeon AST to `code_builder` /// Fields. Iterable _proxyApiUnattachedFields( Iterable fields, @@ -1279,7 +1280,7 @@ if (${_varNamePrefix}replyList == null) { ');', '```', '', - 'Alternatively, `$instanceManagerClassName.removeWeakReference` can be used to', + 'Alternatively, [$instanceManagerClassName.removeWeakReference] can be used to', 'release the associated Native object manually.', ], ], diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart index 68b02de3c24e..8675499b8022 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart @@ -50,9 +50,11 @@ abstract class Pigeon_ProxyApiBaseClass { /// /// If it is null, the default BinaryMessenger will be used, which routes to /// the host platform. + @protected final BinaryMessenger? pigeon_binaryMessenger; /// Maintains instances stored to communicate with native language objects. + @protected final Pigeon_InstanceManager pigeon_instanceManager; /// Instantiates and returns a functionally identical object to oneself. @@ -533,10 +535,11 @@ class ProxyApiTestClass extends ProxyApiSuperClass }(); } - /// Constructs ProxyApiTestClass without creating the associated native object. + /// Constructs [ProxyApiTestClass] without creating the associated native object. /// /// This should only be used by subclasses created by this library or to /// create copies for an [Pigeon_InstanceManager]. + @protected ProxyApiTestClass.pigeon_detached({ super.pigeon_binaryMessenger, super.pigeon_instanceManager, @@ -644,7 +647,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final void Function(ProxyApiTestClass pigeon_instance)? flutterNoop; @@ -666,7 +669,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final Object? Function(ProxyApiTestClass pigeon_instance)? flutterThrowError; @@ -688,7 +691,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final void Function(ProxyApiTestClass pigeon_instance)? flutterThrowErrorFromVoid; @@ -711,7 +714,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final bool Function( ProxyApiTestClass pigeon_instance, @@ -736,7 +739,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final int Function( ProxyApiTestClass pigeon_instance, @@ -761,7 +764,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final double Function( ProxyApiTestClass pigeon_instance, @@ -786,7 +789,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final String Function( ProxyApiTestClass pigeon_instance, @@ -811,7 +814,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final Uint8List Function( ProxyApiTestClass pigeon_instance, @@ -836,7 +839,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final List Function( ProxyApiTestClass pigeon_instance, @@ -862,7 +865,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final List Function( ProxyApiTestClass pigeon_instance, @@ -887,7 +890,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final Map Function( ProxyApiTestClass pigeon_instance, @@ -913,7 +916,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final Map Function( ProxyApiTestClass pigeon_instance, @@ -938,7 +941,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final AnEnum Function( ProxyApiTestClass pigeon_instance, @@ -963,7 +966,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final ProxyApiSuperClass Function( ProxyApiTestClass pigeon_instance, @@ -988,7 +991,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final bool? Function( ProxyApiTestClass pigeon_instance, @@ -1013,7 +1016,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final int? Function( ProxyApiTestClass pigeon_instance, @@ -1038,7 +1041,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final double? Function( ProxyApiTestClass pigeon_instance, @@ -1063,7 +1066,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final String? Function( ProxyApiTestClass pigeon_instance, @@ -1088,7 +1091,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final Uint8List? Function( ProxyApiTestClass pigeon_instance, @@ -1113,7 +1116,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final List? Function( ProxyApiTestClass pigeon_instance, @@ -1138,7 +1141,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final Map? Function( ProxyApiTestClass pigeon_instance, @@ -1163,7 +1166,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final AnEnum? Function( ProxyApiTestClass pigeon_instance, @@ -1188,7 +1191,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final ProxyApiSuperClass? Function( ProxyApiTestClass pigeon_instance, @@ -1214,7 +1217,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final Future Function(ProxyApiTestClass pigeon_instance)? flutterNoopAsync; @@ -1237,7 +1240,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final Future Function( ProxyApiTestClass pigeon_instance, @@ -4819,10 +4822,11 @@ class ProxyApiSuperClass extends Pigeon_ProxyApiBaseClass { }(); } - /// Constructs ProxyApiSuperClass without creating the associated native object. + /// Constructs [ProxyApiSuperClass] without creating the associated native object. /// /// This should only be used by subclasses created by this library or to /// create copies for an [Pigeon_InstanceManager]. + @protected ProxyApiSuperClass.pigeon_detached({ super.pigeon_binaryMessenger, super.pigeon_instanceManager, @@ -4917,10 +4921,11 @@ class ProxyApiSuperClass extends Pigeon_ProxyApiBaseClass { /// ProxyApi to serve as an interface to the core ProxyApi interface. class ProxyApiInterface extends Pigeon_ProxyApiBaseClass { - /// Constructs ProxyApiInterface without creating the associated native object. + /// Constructs [ProxyApiInterface] without creating the associated native object. /// /// This should only be used by subclasses created by this library or to /// create copies for an [Pigeon_InstanceManager]. + @protected ProxyApiInterface.pigeon_detached({ super.pigeon_binaryMessenger, super.pigeon_instanceManager, @@ -4943,7 +4948,7 @@ class ProxyApiInterface extends Pigeon_ProxyApiBaseClass { /// ); /// ``` /// - /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final void Function(ProxyApiInterface pigeon_instance)? anInterfaceMethod; From 1c61c5110f1de50cd5effe3883c7e80126d3fc7c Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 2 Feb 2024 15:46:17 -0500 Subject: [PATCH 26/32] improvement of docs --- packages/pigeon/lib/dart_generator.dart | 18 ++++++++---- packages/pigeon/lib/pigeon_lib.dart | 2 +- .../src/generated/proxy_api_tests.gen.dart | 28 ++----------------- 3 files changed, 15 insertions(+), 33 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index a9b1eac032be..966c9dcf0452 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -1263,8 +1263,12 @@ if (${_varNamePrefix}replyList == null) { [ ...method.documentationComments, ...[ - if (method.documentationComments.isNotEmpty) '', - 'Dart:', + if (method.documentationComments.isNotEmpty) + '' + else ...[ + 'Callback method.', + '', + ], 'For the associated Native object to be automatically garbage collected,', "it is required that the implementation of this `Function` doesn't have a", 'strong reference to the encapsulating class instance. When this `Function`', @@ -1399,6 +1403,8 @@ if (${_varNamePrefix}replyList == null) { required Iterable unattachedFields, required bool hasCallbackConstructor, }) { + final bool hasAnyMessageHandlers = + hasCallbackConstructor || flutterMethods.isNotEmpty; return cb.Method.returnsVoid( (cb.MethodBuilder builder) => builder ..name = '${classMemberNamePrefix}setUpMessageHandlers' @@ -1469,7 +1475,7 @@ if (${_varNamePrefix}replyList == null) { ), ]) ..body = cb.Block.of([ - if (hasCallbackConstructor || flutterMethods.isNotEmpty) ...[ + if (hasAnyMessageHandlers) ...[ cb.Code( 'final $codecName $_pigeonChannelCodec = $codecName($_instanceManagerVarName ?? $instanceManagerClassName.instance);', ), @@ -1581,11 +1587,11 @@ if (${_varNamePrefix}replyList == null) { ); } - /// Converts attached fields from the pigeon AST to `code_builder` fields. + /// Converts attached fields from the pigeon AST to `code_builder` Methods. /// /// These private methods are used to lazily instantiate attached fields. The /// instance is created and returned synchronously while the native instance - /// is created synchronously. This is similar to how constructors work. + /// is created asynchronously. This is similar to how constructors work. Iterable _proxyApiAttachedFieldMethods( Iterable fields, { required String apiName, @@ -1675,7 +1681,7 @@ if (${_varNamePrefix}replyList == null) { } } - /// Converts host methods from pigeon AST to `code_builder` AST. + /// Converts host methods from pigeon AST to `code_builder` Methods. /// /// This creates methods like a HostApi except that it includes the calling /// instance if the method is not static. diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 65cabf04ef37..eedd8a9f9a81 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -1029,7 +1029,7 @@ List _validateProxyApi( } // Validate this api isn't used as an interface and contains anything except - // Flutter methods or a static host method. + // Flutter methods, a static host method, attached methods. final bool isValidInterfaceProxyApi = api.constructors.isEmpty && api.fields.where((ApiField field) => !field.isStatic).isEmpty && api.hostMethods.where((Method method) => !method.isStatic).isEmpty; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart index 8675499b8022..c3b3e849aad1 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart @@ -631,7 +631,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -653,7 +652,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Responds with an error from an async function returning a value. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -675,7 +673,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Responds with an error from an async void function. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -698,7 +695,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed boolean, to test serialization and deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -723,7 +719,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed int, to test serialization and deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -748,7 +743,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed double, to test serialization and deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -773,7 +767,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed string, to test serialization and deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -798,7 +791,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed byte list, to test serialization and deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -823,7 +815,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed list, to test serialization and deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -849,7 +840,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed list with ProxyApis, to test serialization and /// deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -874,7 +864,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed map, to test serialization and deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -900,7 +889,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed map with ProxyApis, to test serialization and /// deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -925,7 +913,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed enum to test serialization and deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -950,7 +937,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed ProxyApi to test serialization and deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -975,7 +961,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed boolean, to test serialization and deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -1000,7 +985,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed int, to test serialization and deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -1025,7 +1009,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed double, to test serialization and deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -1050,7 +1033,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed string, to test serialization and deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -1075,7 +1057,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed byte list, to test serialization and deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -1100,7 +1081,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed list, to test serialization and deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -1125,7 +1105,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed map, to test serialization and deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -1150,7 +1129,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed enum to test serialization and deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -1175,7 +1153,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed ProxyApi to test serialization and deserialization. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -1201,7 +1178,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -1224,7 +1200,6 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed in generic Object asynchronously. /// - /// Dart: /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` @@ -4932,7 +4907,8 @@ class ProxyApiInterface extends Pigeon_ProxyApiBaseClass { this.anInterfaceMethod, }); - /// Dart: + /// Callback method. + /// /// For the associated Native object to be automatically garbage collected, /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` From cb2e6546b65d2e24d364429197475c4e8058bd32 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Sun, 4 Feb 2024 11:10:36 -0500 Subject: [PATCH 27/32] change enum name --- packages/pigeon/pigeons/proxy_api_tests.dart | 27 +++--- .../src/generated/proxy_api_tests.gen.dart | 82 ++++++++++--------- 2 files changed, 57 insertions(+), 52 deletions(-) diff --git a/packages/pigeon/pigeons/proxy_api_tests.dart b/packages/pigeon/pigeons/proxy_api_tests.dart index 51c351ab556a..1976af972d32 100644 --- a/packages/pigeon/pigeons/proxy_api_tests.dart +++ b/packages/pigeon/pigeons/proxy_api_tests.dart @@ -4,7 +4,7 @@ import 'package:pigeon/pigeon.dart'; -enum AnEnum { +enum ProxyApiTestEnum { one, two, three, @@ -31,7 +31,7 @@ abstract class ProxyApiTestClass extends ProxyApiSuperClass // ignore: avoid_unused_constructor_parameters Map mapParam, // ignore: avoid_unused_constructor_parameters - AnEnum enumParam, + ProxyApiTestEnum enumParam, // ignore: avoid_unused_constructor_parameters ProxyApiSuperClass proxyApiParam, // ignore: avoid_unused_constructor_parameters @@ -49,7 +49,7 @@ abstract class ProxyApiTestClass extends ProxyApiSuperClass // ignore: avoid_unused_constructor_parameters Map? nullableMapParam, // ignore: avoid_unused_constructor_parameters - AnEnum? nullableEnumParam, + ProxyApiTestEnum? nullableEnumParam, // ignore: avoid_unused_constructor_parameters ProxyApiSuperClass? nullableProxyApiParam, ); @@ -61,7 +61,7 @@ abstract class ProxyApiTestClass extends ProxyApiSuperClass late Uint8List aUint8List; late List aList; late Map aMap; - late AnEnum anEnum; + late ProxyApiTestEnum anEnum; late ProxyApiSuperClass aProxyApi; late bool? aNullableBool; @@ -71,7 +71,7 @@ abstract class ProxyApiTestClass extends ProxyApiSuperClass late Uint8List? aNullableUint8List; late List? aNullableList; late Map? aNullableMap; - late AnEnum? aNullableEnum; + late ProxyApiTestEnum? aNullableEnum; late ProxyApiSuperClass? aNullableProxyApi; @attached @@ -125,7 +125,7 @@ abstract class ProxyApiTestClass extends ProxyApiSuperClass Map aMap)? flutterEchoProxyApiMap; /// Returns the passed enum to test serialization and deserialization. - late AnEnum Function(AnEnum anEnum)? flutterEchoEnum; + late ProxyApiTestEnum Function(ProxyApiTestEnum anEnum)? flutterEchoEnum; /// Returns the passed ProxyApi to test serialization and deserialization. late ProxyApiSuperClass Function(ProxyApiSuperClass aProxyApi)? @@ -156,7 +156,8 @@ abstract class ProxyApiTestClass extends ProxyApiSuperClass flutterEchoNullableMap; /// Returns the passed enum to test serialization and deserialization. - late AnEnum? Function(AnEnum? anEnum)? flutterEchoNullableEnum; + late ProxyApiTestEnum? Function(ProxyApiTestEnum? anEnum)? + flutterEchoNullableEnum; /// Returns the passed ProxyApi to test serialization and deserialization. late ProxyApiSuperClass? Function(ProxyApiSuperClass? aProxyApi)? @@ -228,7 +229,7 @@ abstract class ProxyApiTestClass extends ProxyApiSuperClass ); /// Returns the passed enum to test serialization and deserialization. - AnEnum echoEnum(AnEnum anEnum); + ProxyApiTestEnum echoEnum(ProxyApiTestEnum anEnum); /// Returns the passed ProxyApi to test serialization and deserialization. ProxyApiSuperClass echoProxyApi(ProxyApiSuperClass aProxyApi); @@ -259,7 +260,7 @@ abstract class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed map, to test serialization and deserialization. Map? echoNullableMap(Map? aNullableMap); - AnEnum? echoNullableEnum(AnEnum? aNullableEnum); + ProxyApiTestEnum? echoNullableEnum(ProxyApiTestEnum? aNullableEnum); /// Returns the passed ProxyApi to test serialization and deserialization. ProxyApiSuperClass? echoNullableProxyApi( @@ -307,7 +308,7 @@ abstract class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed enum, to test asynchronous serialization and deserialization. @async - AnEnum echoAsyncEnum(AnEnum anEnum); + ProxyApiTestEnum echoAsyncEnum(ProxyApiTestEnum anEnum); /// Responds with an error from an async function returning a value. @async @@ -355,7 +356,7 @@ abstract class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed enum, to test asynchronous serialization and deserialization. @async - AnEnum? echoAsyncNullableEnum(AnEnum? anEnum); + ProxyApiTestEnum? echoAsyncNullableEnum(ProxyApiTestEnum? anEnum); // ========== Static method test ========== @@ -410,7 +411,7 @@ abstract class ProxyApiTestClass extends ProxyApiSuperClass Map aMap); @async - AnEnum callFlutterEchoEnum(AnEnum anEnum); + ProxyApiTestEnum callFlutterEchoEnum(ProxyApiTestEnum anEnum); @async ProxyApiSuperClass callFlutterEchoProxyApi(ProxyApiSuperClass aProxyApi); @@ -439,7 +440,7 @@ abstract class ProxyApiTestClass extends ProxyApiSuperClass ); @async - AnEnum? callFlutterEchoNullableEnum(AnEnum? anEnum); + ProxyApiTestEnum? callFlutterEchoNullableEnum(ProxyApiTestEnum? anEnum); @async ProxyApiSuperClass? callFlutterEchoNullableProxyApi( diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart index c3b3e849aad1..1057954190e9 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart @@ -391,7 +391,7 @@ class _Pigeon_ProxyApiBaseCodec extends StandardMessageCodec { } } -enum AnEnum { +enum ProxyApiTestEnum { one, two, three, @@ -455,7 +455,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass required Uint8List aUint8ListParam, required List listParam, required Map mapParam, - required AnEnum enumParam, + required ProxyApiTestEnum enumParam, required ProxyApiSuperClass proxyApiParam, bool? nullableBoolParam, int? nullableIntParam, @@ -464,7 +464,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass Uint8List? nullableUint8ListParam, List? nullableListParam, Map? nullableMapParam, - AnEnum? nullableEnumParam, + ProxyApiTestEnum? nullableEnumParam, ProxyApiSuperClass? nullableProxyApiParam, }) : super.pigeon_detached() { final int __pigeon_instanceIdentifier = @@ -606,7 +606,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass final Map aMap; - final AnEnum anEnum; + final ProxyApiTestEnum anEnum; final ProxyApiSuperClass aProxyApi; @@ -624,7 +624,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass final Map? aNullableMap; - final AnEnum? aNullableEnum; + final ProxyApiTestEnum? aNullableEnum; final ProxyApiSuperClass? aNullableProxyApi; @@ -930,9 +930,9 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. - final AnEnum Function( + final ProxyApiTestEnum Function( ProxyApiTestClass pigeon_instance, - AnEnum anEnum, + ProxyApiTestEnum anEnum, )? flutterEchoEnum; /// Returns the passed ProxyApi to test serialization and deserialization. @@ -1146,9 +1146,9 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. - final AnEnum? Function( + final ProxyApiTestEnum? Function( ProxyApiTestClass pigeon_instance, - AnEnum? anEnum, + ProxyApiTestEnum? anEnum, )? flutterEchoNullableEnum; /// Returns the passed ProxyApi to test serialization and deserialization. @@ -1242,7 +1242,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass Uint8List aUint8List, List aList, Map aMap, - AnEnum anEnum, + ProxyApiTestEnum anEnum, ProxyApiSuperClass aProxyApi, bool? aNullableBool, int? aNullableInt, @@ -1251,7 +1251,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass Uint8List? aNullableUint8List, List? aNullableList, Map? aNullableMap, - AnEnum? aNullableEnum, + ProxyApiTestEnum? aNullableEnum, ProxyApiSuperClass? aNullableProxyApi, )? pigeon_newInstance, void Function(ProxyApiTestClass pigeon_instance)? flutterNoop, @@ -1293,9 +1293,9 @@ class ProxyApiTestClass extends ProxyApiSuperClass ProxyApiTestClass pigeon_instance, Map aMap, )? flutterEchoProxyApiMap, - AnEnum Function( + ProxyApiTestEnum Function( ProxyApiTestClass pigeon_instance, - AnEnum anEnum, + ProxyApiTestEnum anEnum, )? flutterEchoEnum, ProxyApiSuperClass Function( ProxyApiTestClass pigeon_instance, @@ -1329,9 +1329,9 @@ class ProxyApiTestClass extends ProxyApiSuperClass ProxyApiTestClass pigeon_instance, Map? aMap, )? flutterEchoNullableMap, - AnEnum? Function( + ProxyApiTestEnum? Function( ProxyApiTestClass pigeon_instance, - AnEnum? anEnum, + ProxyApiTestEnum? anEnum, )? flutterEchoNullableEnum, ProxyApiSuperClass? Function( ProxyApiTestClass pigeon_instance, @@ -1386,10 +1386,10 @@ class ProxyApiTestClass extends ProxyApiSuperClass (args[7] as Map?)?.cast(); assert(arg_aMap != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_newInstance was null, expected non-null Map.'); - final AnEnum? arg_anEnum = - args[8] == null ? null : AnEnum.values[args[8]! as int]; + final ProxyApiTestEnum? arg_anEnum = + args[8] == null ? null : ProxyApiTestEnum.values[args[8]! as int]; assert(arg_anEnum != null, - 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_newInstance was null, expected non-null AnEnum.'); + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_newInstance was null, expected non-null ProxyApiTestEnum.'); final ProxyApiSuperClass? arg_aProxyApi = (args[9] as ProxyApiSuperClass?); assert(arg_aProxyApi != null, @@ -1403,8 +1403,9 @@ class ProxyApiTestClass extends ProxyApiSuperClass (args[15] as List?)?.cast(); final Map? arg_aNullableMap = (args[16] as Map?)?.cast(); - final AnEnum? arg_aNullableEnum = - args[17] == null ? null : AnEnum.values[args[17]! as int]; + final ProxyApiTestEnum? arg_aNullableEnum = args[17] == null + ? null + : ProxyApiTestEnum.values[args[17]! as int]; final ProxyApiSuperClass? arg_aNullableProxyApi = (args[18] as ProxyApiSuperClass?); try { @@ -1897,12 +1898,12 @@ class ProxyApiTestClass extends ProxyApiSuperClass (args[0] as ProxyApiTestClass?); assert(arg_pigeon_instance != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoEnum was null, expected non-null ProxyApiTestClass.'); - final AnEnum? arg_anEnum = - args[1] == null ? null : AnEnum.values[args[1]! as int]; + final ProxyApiTestEnum? arg_anEnum = + args[1] == null ? null : ProxyApiTestEnum.values[args[1]! as int]; assert(arg_anEnum != null, - 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoEnum was null, expected non-null AnEnum.'); + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoEnum was null, expected non-null ProxyApiTestEnum.'); try { - final AnEnum? output = + final ProxyApiTestEnum? output = (flutterEchoEnum ?? arg_pigeon_instance!.flutterEchoEnum) ?.call(arg_pigeon_instance!, arg_anEnum!); return wrapResponse(result: output?.index); @@ -2202,10 +2203,10 @@ class ProxyApiTestClass extends ProxyApiSuperClass (args[0] as ProxyApiTestClass?); assert(arg_pigeon_instance != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableEnum was null, expected non-null ProxyApiTestClass.'); - final AnEnum? arg_anEnum = - args[1] == null ? null : AnEnum.values[args[1]! as int]; + final ProxyApiTestEnum? arg_anEnum = + args[1] == null ? null : ProxyApiTestEnum.values[args[1]! as int]; try { - final AnEnum? output = (flutterEchoNullableEnum ?? + final ProxyApiTestEnum? output = (flutterEchoNullableEnum ?? arg_pigeon_instance!.flutterEchoNullableEnum) ?.call(arg_pigeon_instance!, arg_anEnum); return wrapResponse(result: output?.index); @@ -2843,7 +2844,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } /// Returns the passed enum to test serialization and deserialization. - Future echoEnum(AnEnum anEnum) async { + Future echoEnum(ProxyApiTestEnum anEnum) async { final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; @@ -2871,7 +2872,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass message: 'Host platform returned null value for non-null return value.', ); } else { - return AnEnum.values[__pigeon_replyList[0]! as int]; + return ProxyApiTestEnum.values[__pigeon_replyList[0]! as int]; } } @@ -3135,7 +3136,8 @@ class ProxyApiTestClass extends ProxyApiSuperClass } } - Future echoNullableEnum(AnEnum? aNullableEnum) async { + Future echoNullableEnum( + ProxyApiTestEnum? aNullableEnum) async { final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; @@ -3160,7 +3162,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } else { return (__pigeon_replyList[0] as int?) == null ? null - : AnEnum.values[__pigeon_replyList[0]! as int]; + : ProxyApiTestEnum.values[__pigeon_replyList[0]! as int]; } } @@ -3488,7 +3490,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } /// Returns the passed enum, to test asynchronous serialization and deserialization. - Future echoAsyncEnum(AnEnum anEnum) async { + Future echoAsyncEnum(ProxyApiTestEnum anEnum) async { final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; @@ -3516,7 +3518,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass message: 'Host platform returned null value for non-null return value.', ); } else { - return AnEnum.values[__pigeon_replyList[0]! as int]; + return ProxyApiTestEnum.values[__pigeon_replyList[0]! as int]; } } @@ -3831,7 +3833,8 @@ class ProxyApiTestClass extends ProxyApiSuperClass } /// Returns the passed enum, to test asynchronous serialization and deserialization. - Future echoAsyncNullableEnum(AnEnum? anEnum) async { + Future echoAsyncNullableEnum( + ProxyApiTestEnum? anEnum) async { final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; @@ -3856,7 +3859,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } else { return (__pigeon_replyList[0] as int?) == null ? null - : AnEnum.values[__pigeon_replyList[0]! as int]; + : ProxyApiTestEnum.values[__pigeon_replyList[0]! as int]; } } @@ -4334,7 +4337,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } } - Future callFlutterEchoEnum(AnEnum anEnum) async { + Future callFlutterEchoEnum(ProxyApiTestEnum anEnum) async { final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; @@ -4362,7 +4365,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass message: 'Host platform returned null value for non-null return value.', ); } else { - return AnEnum.values[__pigeon_replyList[0]! as int]; + return ProxyApiTestEnum.values[__pigeon_replyList[0]! as int]; } } @@ -4592,7 +4595,8 @@ class ProxyApiTestClass extends ProxyApiSuperClass } } - Future callFlutterEchoNullableEnum(AnEnum? anEnum) async { + Future callFlutterEchoNullableEnum( + ProxyApiTestEnum? anEnum) async { final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; @@ -4617,7 +4621,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } else { return (__pigeon_replyList[0] as int?) == null ? null - : AnEnum.values[__pigeon_replyList[0]! as int]; + : ProxyApiTestEnum.values[__pigeon_replyList[0]! as int]; } } From 12d9c7d30beb387d5635b2bde5fb26e8f7faec98 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Sun, 4 Feb 2024 13:15:51 -0500 Subject: [PATCH 28/32] dont gen method without apis --- packages/pigeon/lib/objc_generator.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/pigeon/lib/objc_generator.dart b/packages/pigeon/lib/objc_generator.dart index bc26495e650b..6effa34ee6cf 100644 --- a/packages/pigeon/lib/objc_generator.dart +++ b/packages/pigeon/lib/objc_generator.dart @@ -715,7 +715,10 @@ class ObjcSourceGenerator extends StructuredGenerator { _writeCreateConnectionError(indent); indent.newln(); } - _writeGetNullableObjectAtIndex(indent); + + if (hasHostApi || hasFlutterApi) { + _writeGetNullableObjectAtIndex(indent); + } } void _writeWrapError(Indent indent) { From c0aa558af3db39ceaa307ab83d551e312e3fb66c Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 27 Feb 2024 15:38:43 -0500 Subject: [PATCH 29/32] fix class name generation without underscore --- .../example/app/lib/src/messages.g.dart | 2 +- packages/pigeon/lib/dart_generator.dart | 5 +- packages/pigeon/lib/generator_tools.dart | 2 +- .../background_platform_channels.gen.dart | 2 +- .../lib/src/generated/core_tests.gen.dart | 2 +- .../lib/src/generated/enum.gen.dart | 2 +- .../src/generated/flutter_unittests.gen.dart | 2 +- .../lib/src/generated/message.gen.dart | 2 +- .../lib/src/generated/multiple_arity.gen.dart | 2 +- .../src/generated/non_null_fields.gen.dart | 2 +- .../lib/src/generated/null_fields.gen.dart | 2 +- .../src/generated/nullable_returns.gen.dart | 2 +- .../lib/src/generated/primitive.gen.dart | 2 +- .../src/generated/proxy_api_tests.gen.dart | 384 +++++++++--------- .../test/instance_manager_test.dart | 36 +- packages/pigeon/test/dart/proxy_api_test.dart | 18 +- 16 files changed, 232 insertions(+), 235 deletions(-) diff --git a/packages/pigeon/example/app/lib/src/messages.g.dart b/packages/pigeon/example/app/lib/src/messages.g.dart index 961e9c5856b5..59213e4ef2bb 100644 --- a/packages/pigeon/example/app/lib/src/messages.g.dart +++ b/packages/pigeon/example/app/lib/src/messages.g.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 966c9dcf0452..9e59fecf4804 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -102,10 +102,7 @@ class DartGenerator extends StructuredGenerator { indent.writeln('// ${getGeneratedCodeWarning()}'); indent.writeln('// $seeAlsoWarning'); indent.writeln( - '// ignore_for_file: public_member_api_docs, non_constant_identifier_names, ' - 'avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, ' - 'omit_local_variable_types, unused_shown_name, unnecessary_import, ' - 'no_leading_underscores_for_local_identifiers, camel_case_types', + '// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers', ); indent.newln(); } diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 1954dad7f9bd..f60fdcbc4cc4 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -299,7 +299,7 @@ const String seeAlsoWarning = 'See also: https://pub.dev/packages/pigeon'; /// /// This lowers the chances of variable name collisions with user defined /// parameters. -const String classNamePrefix = 'Pigeon_'; +const String classNamePrefix = 'Pigeon'; /// Name for the generated InstanceManager for ProxyApis. /// diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/background_platform_channels.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/background_platform_channels.gen.dart index 91dee132ceba..7222e263b32b 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/background_platform_channels.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/background_platform_channels.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart index e0ff30162031..98c1aea5c084 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/enum.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/enum.gen.dart index b58d7d652834..c585d3a83259 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/enum.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/enum.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/flutter_unittests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/flutter_unittests.gen.dart index 99cbf7fa3711..73f100cf28b6 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/flutter_unittests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/flutter_unittests.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart index 04dbc6d43a2a..cc7b8b53c360 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/multiple_arity.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/multiple_arity.gen.dart index 19455117087d..bec054b4be49 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/multiple_arity.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/multiple_arity.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart index be9c48422aef..7279e85c40ea 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart index bc18ccd0ada0..ecf7c7f7e970 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/nullable_returns.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/nullable_returns.gen.dart index d5c2bb3f63df..dd1665a463c1 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/nullable_returns.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/nullable_returns.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/primitive.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/primitive.gen.dart index b1f618a72b6e..72c115d65278 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/primitive.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/primitive.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart index 1057954190e9..6aa044710aef 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers, camel_case_types +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -38,13 +38,13 @@ List wrapResponse( /// All implementers are expected to be [immutable] as defined by the annotation /// and override [pigeon_copy] returning an instance of itself. @immutable -abstract class Pigeon_ProxyApiBaseClass { - /// Construct a [Pigeon_ProxyApiBaseClass]. - Pigeon_ProxyApiBaseClass({ +abstract class PigeonProxyApiBaseClass { + /// Construct a [PigeonProxyApiBaseClass]. + PigeonProxyApiBaseClass({ this.pigeon_binaryMessenger, - Pigeon_InstanceManager? pigeon_instanceManager, + PigeonInstanceManager? pigeon_instanceManager, }) : pigeon_instanceManager = - pigeon_instanceManager ?? Pigeon_InstanceManager.instance; + pigeon_instanceManager ?? PigeonInstanceManager.instance; /// Sends and receives binary data across the Flutter platform barrier. /// @@ -55,17 +55,17 @@ abstract class Pigeon_ProxyApiBaseClass { /// Maintains instances stored to communicate with native language objects. @protected - final Pigeon_InstanceManager pigeon_instanceManager; + final PigeonInstanceManager pigeon_instanceManager; /// Instantiates and returns a functionally identical object to oneself. /// /// Outside of tests, this method should only ever be called by - /// [Pigeon_InstanceManager]. + /// [PigeonInstanceManager]. /// /// Subclasses should always override their parent's implementation of this /// method. @protected - Pigeon_ProxyApiBaseClass pigeon_copy(); + PigeonProxyApiBaseClass pigeon_copy(); } /// Maintains instances used to communicate with the native objects they @@ -83,9 +83,9 @@ abstract class Pigeon_ProxyApiBaseClass { /// is added as a weak reference with the same identifier. This prevents a /// scenario where the weak referenced instance was released and then later /// returned by the host platform. -class Pigeon_InstanceManager { - /// Constructs a [Pigeon_InstanceManager]. - Pigeon_InstanceManager({required void Function(int) onWeakReferenceRemoved}) { +class PigeonInstanceManager { + /// Constructs a [PigeonInstanceManager]. + PigeonInstanceManager({required void Function(int) onWeakReferenceRemoved}) { this.onWeakReferenceRemoved = (int identifier) { _weakInstances.remove(identifier); onWeakReferenceRemoved(identifier); @@ -99,12 +99,12 @@ class Pigeon_InstanceManager { // 0 <= n < 2^16. static const int _maxDartCreatedIdentifier = 65536; - /// The default [Pigeon_InstanceManager] used by ProxyApis. + /// The default [PigeonInstanceManager] used by ProxyApis. /// /// On creation, this manager makes a call to clear the native /// InstanceManager. This is to prevent identifier conflicts after a host /// restart. - static final Pigeon_InstanceManager instance = _initInstance(); + static final PigeonInstanceManager instance = _initInstance(); // Expando is used because it doesn't prevent its keys from becoming // inaccessible. This allows the manager to efficiently retrieve an identifier @@ -115,10 +115,10 @@ class Pigeon_InstanceManager { // by calling instanceManager.getIdentifier() inside of `==` while this was a // HashMap). final Expando _identifiers = Expando(); - final Map> _weakInstances = - >{}; - final Map _strongInstances = - {}; + final Map> _weakInstances = + >{}; + final Map _strongInstances = + {}; late final Finalizer _finalizer; int _nextIdentifier = 0; @@ -126,17 +126,17 @@ class Pigeon_InstanceManager { /// or becomes inaccessible. late final void Function(int) onWeakReferenceRemoved; - static Pigeon_InstanceManager _initInstance() { + static PigeonInstanceManager _initInstance() { WidgetsFlutterBinding.ensureInitialized(); - final _Pigeon_InstanceManagerApi api = _Pigeon_InstanceManagerApi(); - // Clears the native `Pigeon_InstanceManager` on the initial use of the Dart one. + final _PigeonInstanceManagerApi api = _PigeonInstanceManagerApi(); + // Clears the native `PigeonInstanceManager` on the initial use of the Dart one. api.clear(); - final Pigeon_InstanceManager instanceManager = Pigeon_InstanceManager( + final PigeonInstanceManager instanceManager = PigeonInstanceManager( onWeakReferenceRemoved: (int identifier) { api.removeStrongReference(identifier); }, ); - _Pigeon_InstanceManagerApi.setUpMessageHandlers( + _PigeonInstanceManagerApi.setUpMessageHandlers( instanceManager: instanceManager); ProxyApiTestClass.pigeon_setUpMessageHandlers( pigeon_instanceManager: instanceManager); @@ -155,7 +155,7 @@ class Pigeon_InstanceManager { /// Throws assertion error if the instance has already been added. /// /// Returns the randomly generated id of the [instance] added. - int addDartCreatedInstance(Pigeon_ProxyApiBaseClass instance) { + int addDartCreatedInstance(PigeonProxyApiBaseClass instance) { final int identifier = _nextUniqueIdentifier(); _addInstanceWithIdentifier(instance, identifier); return identifier; @@ -169,7 +169,7 @@ class Pigeon_InstanceManager { /// /// This does not remove the strong referenced instance associated with /// [instance]. This can be done with [remove]. - int? removeWeakReference(Pigeon_ProxyApiBaseClass instance) { + int? removeWeakReference(PigeonProxyApiBaseClass instance) { final int? identifier = getIdentifier(instance); if (identifier == null) { return null; @@ -191,7 +191,7 @@ class Pigeon_InstanceManager { /// /// This does not remove the weak referenced instance associated with /// [identifier]. This can be done with [removeWeakReference]. - T? remove(int identifier) { + T? remove(int identifier) { return _strongInstances.remove(identifier) as T?; } @@ -207,19 +207,19 @@ class Pigeon_InstanceManager { /// /// This method also expects the host `InstanceManager` to have a strong /// reference to the instance the identifier is associated with. - T? getInstanceWithWeakReference( + T? getInstanceWithWeakReference( int identifier) { - final Pigeon_ProxyApiBaseClass? weakInstance = + final PigeonProxyApiBaseClass? weakInstance = _weakInstances[identifier]?.target; if (weakInstance == null) { - final Pigeon_ProxyApiBaseClass? strongInstance = + final PigeonProxyApiBaseClass? strongInstance = _strongInstances[identifier]; if (strongInstance != null) { - final Pigeon_ProxyApiBaseClass copy = strongInstance.pigeon_copy(); + final PigeonProxyApiBaseClass copy = strongInstance.pigeon_copy(); _identifiers[copy] = identifier; _weakInstances[identifier] = - WeakReference(copy); + WeakReference(copy); _finalizer.attach(copy, identifier, detach: copy); return copy as T; } @@ -230,7 +230,7 @@ class Pigeon_InstanceManager { } /// Retrieves the identifier associated with instance. - int? getIdentifier(Pigeon_ProxyApiBaseClass instance) { + int? getIdentifier(PigeonProxyApiBaseClass instance) { return _identifiers[instance]; } @@ -244,22 +244,22 @@ class Pigeon_InstanceManager { /// /// Returns unique identifier of the [instance] added. void addHostCreatedInstance( - Pigeon_ProxyApiBaseClass instance, int identifier) { + PigeonProxyApiBaseClass instance, int identifier) { _addInstanceWithIdentifier(instance, identifier); } void _addInstanceWithIdentifier( - Pigeon_ProxyApiBaseClass instance, int identifier) { + PigeonProxyApiBaseClass instance, int identifier) { assert(!containsIdentifier(identifier)); assert(getIdentifier(instance) == null); assert(identifier >= 0); _identifiers[instance] = identifier; _weakInstances[identifier] = - WeakReference(instance); + WeakReference(instance); _finalizer.attach(instance, identifier, detach: instance); - final Pigeon_ProxyApiBaseClass copy = instance.pigeon_copy(); + final PigeonProxyApiBaseClass copy = instance.pigeon_copy(); _identifiers[copy] = identifier; _strongInstances[identifier] = copy; } @@ -280,10 +280,10 @@ class Pigeon_InstanceManager { } } -/// Generated API for managing the Dart and native `Pigeon_InstanceManager`s. -class _Pigeon_InstanceManagerApi { - /// Constructor for [_Pigeon_InstanceManagerApi ]. - _Pigeon_InstanceManagerApi({BinaryMessenger? binaryMessenger}) +/// Generated API for managing the Dart and native `PigeonInstanceManager`s. +class _PigeonInstanceManagerApi { + /// Constructor for [_PigeonInstanceManagerApi ]. + _PigeonInstanceManagerApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; final BinaryMessenger? _binaryMessenger; @@ -293,10 +293,10 @@ class _Pigeon_InstanceManagerApi { static void setUpMessageHandlers({ BinaryMessenger? binaryMessenger, - Pigeon_InstanceManager? instanceManager, + PigeonInstanceManager? instanceManager, }) { const String channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.Pigeon_InstanceManagerApi.removeStrongReference'; + r'dev.flutter.pigeon.pigeon_integration_tests.PigeonInstanceManagerApi.removeStrongReference'; final BasicMessageChannel channel = BasicMessageChannel( channelName, pigeonChannelCodec, @@ -312,14 +312,14 @@ class _Pigeon_InstanceManagerApi { identifier != null, r'Argument for $channelName, expected non-null int.', ); - (instanceManager ?? Pigeon_InstanceManager.instance).remove(identifier!); + (instanceManager ?? PigeonInstanceManager.instance).remove(identifier!); return; }); } Future removeStrongReference(int identifier) async { const String channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.Pigeon_InstanceManagerApi.removeStrongReference'; + r'dev.flutter.pigeon.pigeon_integration_tests.PigeonInstanceManagerApi.removeStrongReference'; final BasicMessageChannel channel = BasicMessageChannel( channelName, pigeonChannelCodec, @@ -340,12 +340,12 @@ class _Pigeon_InstanceManagerApi { } } - /// Clear the native `Pigeon_InstanceManager`. + /// Clear the native `PigeonInstanceManager`. /// /// This is typically called after a hot restart. Future clear() async { const String channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.Pigeon_InstanceManagerApi.clear'; + r'dev.flutter.pigeon.pigeon_integration_tests.PigeonInstanceManagerApi.clear'; final BasicMessageChannel channel = BasicMessageChannel( channelName, pigeonChannelCodec, @@ -366,12 +366,12 @@ class _Pigeon_InstanceManagerApi { } } -class _Pigeon_ProxyApiBaseCodec extends StandardMessageCodec { - const _Pigeon_ProxyApiBaseCodec(this.instanceManager); - final Pigeon_InstanceManager instanceManager; +class _PigeonProxyApiBaseCodec extends StandardMessageCodec { + const _PigeonProxyApiBaseCodec(this.instanceManager); + final PigeonInstanceManager instanceManager; @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is Pigeon_ProxyApiBaseClass) { + if (value is PigeonProxyApiBaseClass) { buffer.putUint8(128); writeValue(buffer, instanceManager.getIdentifier(value)); } else { @@ -469,7 +469,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass }) : super.pigeon_detached() { final int __pigeon_instanceIdentifier = pigeon_instanceManager.addDartCreatedInstance(this); - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; () async { @@ -538,7 +538,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Constructs [ProxyApiTestClass] without creating the associated native object. /// /// This should only be used by subclasses created by this library or to - /// create copies for an [Pigeon_InstanceManager]. + /// create copies for an [PigeonInstanceManager]. @protected ProxyApiTestClass.pigeon_detached({ super.pigeon_binaryMessenger, @@ -589,8 +589,8 @@ class ProxyApiTestClass extends ProxyApiSuperClass this.flutterEchoAsyncString, }) : super.pigeon_detached(); - late final _Pigeon_ProxyApiBaseCodec __pigeon_codecProxyApiTestClass = - _Pigeon_ProxyApiBaseCodec(pigeon_instanceManager); + late final _PigeonProxyApiBaseCodec __pigeon_codecProxyApiTestClass = + _PigeonProxyApiBaseCodec(pigeon_instanceManager); final bool aBool; @@ -646,7 +646,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final void Function(ProxyApiTestClass pigeon_instance)? flutterNoop; @@ -667,7 +667,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final Object? Function(ProxyApiTestClass pigeon_instance)? flutterThrowError; @@ -688,7 +688,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final void Function(ProxyApiTestClass pigeon_instance)? flutterThrowErrorFromVoid; @@ -710,7 +710,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final bool Function( ProxyApiTestClass pigeon_instance, @@ -734,7 +734,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final int Function( ProxyApiTestClass pigeon_instance, @@ -758,7 +758,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final double Function( ProxyApiTestClass pigeon_instance, @@ -782,7 +782,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final String Function( ProxyApiTestClass pigeon_instance, @@ -806,7 +806,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final Uint8List Function( ProxyApiTestClass pigeon_instance, @@ -830,7 +830,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final List Function( ProxyApiTestClass pigeon_instance, @@ -855,7 +855,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final List Function( ProxyApiTestClass pigeon_instance, @@ -879,7 +879,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final Map Function( ProxyApiTestClass pigeon_instance, @@ -904,7 +904,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final Map Function( ProxyApiTestClass pigeon_instance, @@ -928,7 +928,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final ProxyApiTestEnum Function( ProxyApiTestClass pigeon_instance, @@ -952,7 +952,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final ProxyApiSuperClass Function( ProxyApiTestClass pigeon_instance, @@ -976,7 +976,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final bool? Function( ProxyApiTestClass pigeon_instance, @@ -1000,7 +1000,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final int? Function( ProxyApiTestClass pigeon_instance, @@ -1024,7 +1024,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final double? Function( ProxyApiTestClass pigeon_instance, @@ -1048,7 +1048,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final String? Function( ProxyApiTestClass pigeon_instance, @@ -1072,7 +1072,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final Uint8List? Function( ProxyApiTestClass pigeon_instance, @@ -1096,7 +1096,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final List? Function( ProxyApiTestClass pigeon_instance, @@ -1120,7 +1120,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final Map? Function( ProxyApiTestClass pigeon_instance, @@ -1144,7 +1144,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final ProxyApiTestEnum? Function( ProxyApiTestClass pigeon_instance, @@ -1168,7 +1168,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final ProxyApiSuperClass? Function( ProxyApiTestClass pigeon_instance, @@ -1193,7 +1193,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final Future Function(ProxyApiTestClass pigeon_instance)? flutterNoopAsync; @@ -1215,7 +1215,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final Future Function( ProxyApiTestClass pigeon_instance, @@ -1233,7 +1233,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass static void pigeon_setUpMessageHandlers({ bool pigeon_clearHandlers = false, BinaryMessenger? pigeon_binaryMessenger, - Pigeon_InstanceManager? pigeon_instanceManager, + PigeonInstanceManager? pigeon_instanceManager, ProxyApiTestClass Function( bool aBool, int anInt, @@ -1343,9 +1343,9 @@ class ProxyApiTestClass extends ProxyApiSuperClass String aString, )? flutterEchoAsyncString, }) { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = - _Pigeon_ProxyApiBaseCodec( - pigeon_instanceManager ?? Pigeon_InstanceManager.instance); + final _PigeonProxyApiBaseCodec pigeonChannelCodec = + _PigeonProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; { final BasicMessageChannel __pigeon_channel = BasicMessageChannel< @@ -1409,7 +1409,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass final ProxyApiSuperClass? arg_aNullableProxyApi = (args[18] as ProxyApiSuperClass?); try { - (pigeon_instanceManager ?? Pigeon_InstanceManager.instance) + (pigeon_instanceManager ?? PigeonInstanceManager.instance) .addHostCreatedInstance( pigeon_newInstance?.call( arg_aBool!, @@ -2327,7 +2327,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass pigeon_binaryMessenger: pigeon_binaryMessenger, pigeon_instanceManager: pigeon_instanceManager, ); - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; final int __pigeon_instanceIdentifier = @@ -2361,11 +2361,11 @@ class ProxyApiTestClass extends ProxyApiSuperClass static ProxyApiSuperClass __pigeon_staticAttachedField() { final ProxyApiSuperClass __pigeon_instance = ProxyApiSuperClass.pigeon_detached(); - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = - _Pigeon_ProxyApiBaseCodec(Pigeon_InstanceManager.instance); + final _PigeonProxyApiBaseCodec pigeonChannelCodec = + _PigeonProxyApiBaseCodec(PigeonInstanceManager.instance); final BinaryMessenger __pigeon_binaryMessenger = ServicesBinding.instance.defaultBinaryMessenger; - final int __pigeon_instanceIdentifier = Pigeon_InstanceManager.instance + final int __pigeon_instanceIdentifier = PigeonInstanceManager.instance .addDartCreatedInstance(__pigeon_instance); () async { const String __pigeon_channelName = @@ -2396,7 +2396,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. Future noop() async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -2424,7 +2424,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns an error, to test error handling. Future throwError() async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -2452,7 +2452,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns an error from a void function, to test error handling. Future throwErrorFromVoid() async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -2480,7 +2480,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns a Flutter error, to test error handling. Future throwFlutterError() async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -2508,7 +2508,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns passed in int. Future echoInt(int anInt) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -2541,7 +2541,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns passed in double. Future echoDouble(double aDouble) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -2574,7 +2574,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed in boolean. Future echoBool(bool aBool) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -2607,7 +2607,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed in string. Future echoString(String aString) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -2640,7 +2640,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed in Uint8List. Future echoUint8List(Uint8List aUint8List) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -2673,7 +2673,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed in generic Object. Future echoObject(Object anObject) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -2706,7 +2706,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed list, to test serialization and deserialization. Future> echoList(List aList) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -2741,7 +2741,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// deserialization. Future> echoProxyApiList( List aList) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -2775,7 +2775,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed map, to test serialization and deserialization. Future> echoMap(Map aMap) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -2811,7 +2811,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// deserialization. Future> echoProxyApiMap( Map aMap) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -2845,7 +2845,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed enum to test serialization and deserialization. Future echoEnum(ProxyApiTestEnum anEnum) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -2878,7 +2878,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed ProxyApi to test serialization and deserialization. Future echoProxyApi(ProxyApiSuperClass aProxyApi) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -2911,7 +2911,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns passed in int. Future echoNullableInt(int? aNullableInt) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -2939,7 +2939,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns passed in double. Future echoNullableDouble(double? aNullableDouble) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -2967,7 +2967,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed in boolean. Future echoNullableBool(bool? aNullableBool) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -2995,7 +2995,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed in string. Future echoNullableString(String? aNullableString) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3024,7 +3024,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed in Uint8List. Future echoNullableUint8List( Uint8List? aNullableUint8List) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3052,7 +3052,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed in generic Object. Future echoNullableObject(Object? aNullableObject) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3080,7 +3080,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed list, to test serialization and deserialization. Future?> echoNullableList(List? aNullableList) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3109,7 +3109,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed map, to test serialization and deserialization. Future?> echoNullableMap( Map? aNullableMap) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3138,7 +3138,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass Future echoNullableEnum( ProxyApiTestEnum? aNullableEnum) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3169,7 +3169,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed ProxyApi to test serialization and deserialization. Future echoNullableProxyApi( ProxyApiSuperClass? aNullableProxyApi) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3198,7 +3198,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. Future noopAsync() async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3226,7 +3226,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns passed in int asynchronously. Future echoAsyncInt(int anInt) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3259,7 +3259,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns passed in double asynchronously. Future echoAsyncDouble(double aDouble) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3292,7 +3292,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed in boolean asynchronously. Future echoAsyncBool(bool aBool) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3325,7 +3325,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed string asynchronously. Future echoAsyncString(String aString) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3358,7 +3358,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed in Uint8List asynchronously. Future echoAsyncUint8List(Uint8List aUint8List) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3391,7 +3391,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed in generic Object asynchronously. Future echoAsyncObject(Object anObject) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3424,7 +3424,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed list, to test asynchronous serialization and deserialization. Future> echoAsyncList(List aList) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3457,7 +3457,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed map, to test asynchronous serialization and deserialization. Future> echoAsyncMap(Map aMap) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3491,7 +3491,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed enum, to test asynchronous serialization and deserialization. Future echoAsyncEnum(ProxyApiTestEnum anEnum) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3524,7 +3524,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Responds with an error from an async function returning a value. Future throwAsyncError() async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3552,7 +3552,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Responds with an error from an async void function. Future throwAsyncErrorFromVoid() async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3580,7 +3580,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Responds with a Flutter error from an async function returning a value. Future throwAsyncFlutterError() async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3608,7 +3608,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns passed in int asynchronously. Future echoAsyncNullableInt(int? anInt) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3636,7 +3636,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns passed in double asynchronously. Future echoAsyncNullableDouble(double? aDouble) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3664,7 +3664,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed in boolean asynchronously. Future echoAsyncNullableBool(bool? aBool) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3692,7 +3692,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed string asynchronously. Future echoAsyncNullableString(String? aString) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3720,7 +3720,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed in Uint8List asynchronously. Future echoAsyncNullableUint8List(Uint8List? aUint8List) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3748,7 +3748,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed in generic Object asynchronously. Future echoAsyncNullableObject(Object? anObject) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3776,7 +3776,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed list, to test asynchronous serialization and deserialization. Future?> echoAsyncNullableList(List? aList) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3805,7 +3805,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed map, to test asynchronous serialization and deserialization. Future?> echoAsyncNullableMap( Map? aMap) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3835,7 +3835,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// Returns the passed enum, to test asynchronous serialization and deserialization. Future echoAsyncNullableEnum( ProxyApiTestEnum? anEnum) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3865,11 +3865,11 @@ class ProxyApiTestClass extends ProxyApiSuperClass static Future staticNoop({ BinaryMessenger? pigeon_binaryMessenger, - Pigeon_InstanceManager? pigeon_instanceManager, + PigeonInstanceManager? pigeon_instanceManager, }) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = - _Pigeon_ProxyApiBaseCodec( - pigeon_instanceManager ?? Pigeon_InstanceManager.instance); + final _PigeonProxyApiBaseCodec pigeonChannelCodec = + _PigeonProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.staticNoop'; @@ -3897,11 +3897,11 @@ class ProxyApiTestClass extends ProxyApiSuperClass static Future echoStaticString( String aString, { BinaryMessenger? pigeon_binaryMessenger, - Pigeon_InstanceManager? pigeon_instanceManager, + PigeonInstanceManager? pigeon_instanceManager, }) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = - _Pigeon_ProxyApiBaseCodec( - pigeon_instanceManager ?? Pigeon_InstanceManager.instance); + final _PigeonProxyApiBaseCodec pigeonChannelCodec = + _PigeonProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoStaticString'; @@ -3933,11 +3933,11 @@ class ProxyApiTestClass extends ProxyApiSuperClass static Future staticAsyncNoop({ BinaryMessenger? pigeon_binaryMessenger, - Pigeon_InstanceManager? pigeon_instanceManager, + PigeonInstanceManager? pigeon_instanceManager, }) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = - _Pigeon_ProxyApiBaseCodec( - pigeon_instanceManager ?? Pigeon_InstanceManager.instance); + final _PigeonProxyApiBaseCodec pigeonChannelCodec = + _PigeonProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.staticAsyncNoop'; @@ -3963,7 +3963,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } Future callFlutterNoop() async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -3990,7 +3990,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } Future callFlutterThrowError() async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4017,7 +4017,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } Future callFlutterThrowErrorFromVoid() async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4044,7 +4044,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } Future callFlutterEchoBool(bool aBool) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4076,7 +4076,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } Future callFlutterEchoInt(int anInt) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4108,7 +4108,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } Future callFlutterEchoDouble(double aDouble) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4140,7 +4140,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } Future callFlutterEchoString(String aString) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4172,7 +4172,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } Future callFlutterEchoUint8List(Uint8List aUint8List) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4204,7 +4204,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } Future> callFlutterEchoList(List aList) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4237,7 +4237,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass Future> callFlutterEchoProxyApiList( List aList) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4271,7 +4271,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass Future> callFlutterEchoMap( Map aMap) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4305,7 +4305,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass Future> callFlutterEchoProxyApiMap( Map aMap) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4338,7 +4338,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } Future callFlutterEchoEnum(ProxyApiTestEnum anEnum) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4371,7 +4371,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass Future callFlutterEchoProxyApi( ProxyApiSuperClass aProxyApi) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4403,7 +4403,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } Future callFlutterEchoNullableBool(bool? aBool) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4430,7 +4430,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } Future callFlutterEchoNullableInt(int? anInt) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4457,7 +4457,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } Future callFlutterEchoNullableDouble(double? aDouble) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4484,7 +4484,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } Future callFlutterEchoNullableString(String? aString) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4512,7 +4512,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass Future callFlutterEchoNullableUint8List( Uint8List? aUint8List) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4540,7 +4540,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass Future?> callFlutterEchoNullableList( List? aList) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4568,7 +4568,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass Future?> callFlutterEchoNullableMap( Map? aMap) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4597,7 +4597,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass Future callFlutterEchoNullableEnum( ProxyApiTestEnum? anEnum) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4627,7 +4627,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass Future callFlutterEchoNullableProxyApi( ProxyApiSuperClass? aProxyApi) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4654,7 +4654,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } Future callFlutterNoopAsync() async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4681,7 +4681,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } Future callFlutterEchoAsyncString(String aString) async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiTestClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4766,14 +4766,14 @@ class ProxyApiTestClass extends ProxyApiSuperClass } /// ProxyApi to serve as a super class to the core ProxyApi interface. -class ProxyApiSuperClass extends Pigeon_ProxyApiBaseClass { +class ProxyApiSuperClass extends PigeonProxyApiBaseClass { ProxyApiSuperClass({ super.pigeon_binaryMessenger, super.pigeon_instanceManager, }) { final int __pigeon_instanceIdentifier = pigeon_instanceManager.addDartCreatedInstance(this); - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiSuperClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; () async { @@ -4804,25 +4804,25 @@ class ProxyApiSuperClass extends Pigeon_ProxyApiBaseClass { /// Constructs [ProxyApiSuperClass] without creating the associated native object. /// /// This should only be used by subclasses created by this library or to - /// create copies for an [Pigeon_InstanceManager]. + /// create copies for an [PigeonInstanceManager]. @protected ProxyApiSuperClass.pigeon_detached({ super.pigeon_binaryMessenger, super.pigeon_instanceManager, }); - late final _Pigeon_ProxyApiBaseCodec __pigeon_codecProxyApiSuperClass = - _Pigeon_ProxyApiBaseCodec(pigeon_instanceManager); + late final _PigeonProxyApiBaseCodec __pigeon_codecProxyApiSuperClass = + _PigeonProxyApiBaseCodec(pigeon_instanceManager); static void pigeon_setUpMessageHandlers({ bool pigeon_clearHandlers = false, BinaryMessenger? pigeon_binaryMessenger, - Pigeon_InstanceManager? pigeon_instanceManager, + PigeonInstanceManager? pigeon_instanceManager, ProxyApiSuperClass Function()? pigeon_newInstance, }) { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = - _Pigeon_ProxyApiBaseCodec( - pigeon_instanceManager ?? Pigeon_InstanceManager.instance); + final _PigeonProxyApiBaseCodec pigeonChannelCodec = + _PigeonProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; { final BasicMessageChannel __pigeon_channel = BasicMessageChannel< @@ -4841,7 +4841,7 @@ class ProxyApiSuperClass extends Pigeon_ProxyApiBaseClass { assert(arg_pigeon_instanceIdentifier != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.pigeon_newInstance was null, expected non-null int.'); try { - (pigeon_instanceManager ?? Pigeon_InstanceManager.instance) + (pigeon_instanceManager ?? PigeonInstanceManager.instance) .addHostCreatedInstance( pigeon_newInstance?.call() ?? ProxyApiSuperClass.pigeon_detached( @@ -4863,7 +4863,7 @@ class ProxyApiSuperClass extends Pigeon_ProxyApiBaseClass { } Future aSuperMethod() async { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + final _PigeonProxyApiBaseCodec pigeonChannelCodec = __pigeon_codecProxyApiSuperClass; final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = @@ -4899,11 +4899,11 @@ class ProxyApiSuperClass extends Pigeon_ProxyApiBaseClass { } /// ProxyApi to serve as an interface to the core ProxyApi interface. -class ProxyApiInterface extends Pigeon_ProxyApiBaseClass { +class ProxyApiInterface extends PigeonProxyApiBaseClass { /// Constructs [ProxyApiInterface] without creating the associated native object. /// /// This should only be used by subclasses created by this library or to - /// create copies for an [Pigeon_InstanceManager]. + /// create copies for an [PigeonInstanceManager]. @protected ProxyApiInterface.pigeon_detached({ super.pigeon_binaryMessenger, @@ -4928,20 +4928,20 @@ class ProxyApiInterface extends Pigeon_ProxyApiBaseClass { /// ); /// ``` /// - /// Alternatively, [Pigeon_InstanceManager.removeWeakReference] can be used to + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to /// release the associated Native object manually. final void Function(ProxyApiInterface pigeon_instance)? anInterfaceMethod; static void pigeon_setUpMessageHandlers({ bool pigeon_clearHandlers = false, BinaryMessenger? pigeon_binaryMessenger, - Pigeon_InstanceManager? pigeon_instanceManager, + PigeonInstanceManager? pigeon_instanceManager, ProxyApiInterface Function()? pigeon_newInstance, void Function(ProxyApiInterface pigeon_instance)? anInterfaceMethod, }) { - final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = - _Pigeon_ProxyApiBaseCodec( - pigeon_instanceManager ?? Pigeon_InstanceManager.instance); + final _PigeonProxyApiBaseCodec pigeonChannelCodec = + _PigeonProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; { final BasicMessageChannel __pigeon_channel = BasicMessageChannel< @@ -4960,7 +4960,7 @@ class ProxyApiInterface extends Pigeon_ProxyApiBaseClass { assert(arg_pigeon_instanceIdentifier != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.pigeon_newInstance was null, expected non-null int.'); try { - (pigeon_instanceManager ?? Pigeon_InstanceManager.instance) + (pigeon_instanceManager ?? PigeonInstanceManager.instance) .addHostCreatedInstance( pigeon_newInstance?.call() ?? ProxyApiInterface.pigeon_detached( diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/test/instance_manager_test.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/test/instance_manager_test.dart index fc5ceba03dfb..aadce1b81d7b 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/test/instance_manager_test.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/test/instance_manager_test.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// This file specifically tests the test Pigeon_InstanceManager generated by core_tests. +// This file specifically tests the test PigeonInstanceManager generated by core_tests. import 'package:flutter_test/flutter_test.dart'; import 'package:shared_test_plugin_code/src/generated/proxy_api_tests.gen.dart'; @@ -10,8 +10,8 @@ import 'package:shared_test_plugin_code/src/generated/proxy_api_tests.gen.dart'; void main() { group('InstanceManager', () { test('addHostCreatedInstance', () { - final Pigeon_InstanceManager instanceManager = - Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + final PigeonInstanceManager instanceManager = + PigeonInstanceManager(onWeakReferenceRemoved: (_) {}); final CopyableObject object = CopyableObject( pigeon_instanceManager: instanceManager, @@ -27,8 +27,8 @@ void main() { }); test('addHostCreatedInstance prevents already used objects and ids', () { - final Pigeon_InstanceManager instanceManager = - Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + final PigeonInstanceManager instanceManager = + PigeonInstanceManager(onWeakReferenceRemoved: (_) {}); final CopyableObject object = CopyableObject( pigeon_instanceManager: instanceManager, @@ -51,8 +51,8 @@ void main() { }); test('addFlutterCreatedInstance', () { - final Pigeon_InstanceManager instanceManager = - Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + final PigeonInstanceManager instanceManager = + PigeonInstanceManager(onWeakReferenceRemoved: (_) {}); final CopyableObject object = CopyableObject( pigeon_instanceManager: instanceManager, @@ -70,8 +70,8 @@ void main() { test('removeWeakReference', () { int? weakInstanceId; - final Pigeon_InstanceManager instanceManager = - Pigeon_InstanceManager(onWeakReferenceRemoved: (int instanceId) { + final PigeonInstanceManager instanceManager = + PigeonInstanceManager(onWeakReferenceRemoved: (int instanceId) { weakInstanceId = instanceId; }); @@ -90,8 +90,8 @@ void main() { }); test('removeWeakReference removes only weak reference', () { - final Pigeon_InstanceManager instanceManager = - Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + final PigeonInstanceManager instanceManager = + PigeonInstanceManager(onWeakReferenceRemoved: (_) {}); final CopyableObject object = CopyableObject( pigeon_instanceManager: instanceManager, @@ -107,8 +107,8 @@ void main() { }); test('removeStrongReference', () { - final Pigeon_InstanceManager instanceManager = - Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + final PigeonInstanceManager instanceManager = + PigeonInstanceManager(onWeakReferenceRemoved: (_) {}); final CopyableObject object = CopyableObject( pigeon_instanceManager: instanceManager, @@ -121,8 +121,8 @@ void main() { }); test('removeStrongReference removes only strong reference', () { - final Pigeon_InstanceManager instanceManager = - Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + final PigeonInstanceManager instanceManager = + PigeonInstanceManager(onWeakReferenceRemoved: (_) {}); final CopyableObject object = CopyableObject( pigeon_instanceManager: instanceManager, @@ -137,8 +137,8 @@ void main() { }); test('getInstance can add a new weak reference', () { - final Pigeon_InstanceManager instanceManager = - Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + final PigeonInstanceManager instanceManager = + PigeonInstanceManager(onWeakReferenceRemoved: (_) {}); final CopyableObject object = CopyableObject( pigeon_instanceManager: instanceManager, @@ -156,7 +156,7 @@ void main() { }); } -class CopyableObject extends Pigeon_ProxyApiBaseClass { +class CopyableObject extends PigeonProxyApiBaseClass { // ignore: non_constant_identifier_names CopyableObject({super.pigeon_instanceManager}); diff --git a/packages/pigeon/test/dart/proxy_api_test.dart b/packages/pigeon/test/dart/proxy_api_test.dart index 081b3ab843bd..fb24a2038615 100644 --- a/packages/pigeon/test/dart/proxy_api_test.dart +++ b/packages/pigeon/test/dart/proxy_api_test.dart @@ -80,18 +80,18 @@ void main() { final String collapsedCode = _collapseNewlineAndIndentation(code); // Instance Manager - expect(code, contains(r'class Pigeon_InstanceManager')); - expect(code, contains(r'class _Pigeon_InstanceManagerApi')); + expect(code, contains(r'class PigeonInstanceManager')); + expect(code, contains(r'class _PigeonInstanceManagerApi')); // Base Api class expect( code, - contains(r'abstract class Pigeon_ProxyApiBaseClass'), + contains(r'abstract class PigeonProxyApiBaseClass'), ); // Codec and class - expect(code, contains('class _Pigeon_ProxyApiBaseCodec')); - expect(code, contains(r'class Api extends Pigeon_ProxyApiBaseClass')); + expect(code, contains('class _PigeonProxyApiBaseCodec')); + expect(code, contains(r'class Api extends PigeonProxyApiBaseClass')); // Constructors expect( @@ -202,7 +202,7 @@ void main() { expect( code, contains( - r'class Api extends Pigeon_ProxyApiBaseClass implements Api2', + r'class Api extends PigeonProxyApiBaseClass implements Api2', ), ); }); @@ -254,7 +254,7 @@ void main() { expect( code, contains( - r'class Api extends Pigeon_ProxyApiBaseClass implements Api2, Api3', + r'class Api extends PigeonProxyApiBaseClass implements Api2, Api3', ), ); }); @@ -309,7 +309,7 @@ void main() { expect( code, contains( - r'class Api extends Pigeon_ProxyApiBaseClass implements Api2', + r'class Api extends PigeonProxyApiBaseClass implements Api2', ), ); expect( @@ -839,7 +839,7 @@ void main() { collapsedCode, contains( r'static Future doSomething({ BinaryMessenger? pigeon_binaryMessenger, ' - r'Pigeon_InstanceManager? pigeon_instanceManager, })', + r'PigeonInstanceManager? pigeon_instanceManager, })', ), ); expect( From 1f0c6ce90159d5e851f5bea75eda868adec27dc9 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 27 Feb 2024 16:16:00 -0500 Subject: [PATCH 30/32] change to indexMap and fix extra space --- packages/pigeon/lib/dart/templates.dart | 2 +- packages/pigeon/lib/dart_generator.dart | 19 ++++++++++++------- .../src/generated/proxy_api_tests.gen.dart | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/pigeon/lib/dart/templates.dart b/packages/pigeon/lib/dart/templates.dart index 6de2a11ee9a4..ce986b888dbf 100644 --- a/packages/pigeon/lib/dart/templates.dart +++ b/packages/pigeon/lib/dart/templates.dart @@ -237,7 +237,7 @@ String instanceManagerApiTemplate({ return ''' /// Generated API for managing the Dart and native `$instanceManagerClassName`s. class _$apiName { - /// Constructor for [_$apiName ]. + /// Constructor for [_$apiName]. _$apiName({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 9e59fecf4804..d69a70870ee3 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -3,7 +3,6 @@ // found in the LICENSE file. import 'package:code_builder/code_builder.dart' as cb; -import 'package:collection/collection.dart' as collection; import 'package:dart_style/dart_style.dart'; import 'package:path/path.dart' as path; @@ -1075,7 +1074,8 @@ if (${_varNamePrefix}replyList == null) { ..toThis = true ..required = method.isRequired, ), - ...constructor.parameters.mapIndexed( + ...indexMap( + constructor.parameters, (int index, NamedType parameter) => cb.Parameter( (cb.ParameterBuilder builder) => builder ..name = _getParameterName(index, parameter) @@ -1296,7 +1296,8 @@ if (${_varNamePrefix}replyList == null) { ..isNullable = !method.isRequired ..requiredParameters.addAll([ cb.refer('$apiName ${classMemberNamePrefix}instance'), - ...method.parameters.mapIndexed( + ...indexMap( + method.parameters, (int index, NamedType parameter) { return cb.refer( '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', @@ -1342,7 +1343,8 @@ if (${_varNamePrefix}replyList == null) { cb.refer( '${proxyApi.name} ${classMemberNamePrefix}instance', ), - ...method.parameters.mapIndexed( + ...indexMap( + method.parameters, (int index, NamedType parameter) { return cb.refer( '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', @@ -1437,7 +1439,8 @@ if (${_varNamePrefix}replyList == null) { ..returnType = cb.refer(apiName) ..isNullable = true ..requiredParameters.addAll( - unattachedFields.mapIndexed( + indexMap( + unattachedFields, (int index, ApiField field) { return cb.refer( '${_addGenericTypesNullable(field.type)} ${_getParameterName(index, field)}', @@ -1460,7 +1463,8 @@ if (${_varNamePrefix}replyList == null) { ..isNullable = true ..requiredParameters.addAll([ cb.refer('$apiName ${classMemberNamePrefix}instance'), - ...method.parameters.mapIndexed( + ...indexMap( + method.parameters, (int index, NamedType parameter) { return cb.refer( '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', @@ -1702,7 +1706,8 @@ if (${_varNamePrefix}replyList == null) { )) ..returns = _refer(method.returnType, asFuture: true) ..requiredParameters.addAll( - method.parameters.mapIndexed( + indexMap( + method.parameters, (int index, NamedType parameter) => cb.Parameter( (cb.ParameterBuilder builder) => builder ..name = _getParameterName(index, parameter) diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart index 6aa044710aef..a14413a3d3fd 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart @@ -282,7 +282,7 @@ class PigeonInstanceManager { /// Generated API for managing the Dart and native `PigeonInstanceManager`s. class _PigeonInstanceManagerApi { - /// Constructor for [_PigeonInstanceManagerApi ]. + /// Constructor for [_PigeonInstanceManagerApi]. _PigeonInstanceManagerApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; From 7f1f70eb5db8d2e302e2cd0a97bff91312c71982 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 27 Feb 2024 17:39:27 -0500 Subject: [PATCH 31/32] review comments and regen --- packages/pigeon/lib/ast.dart | 41 ++++++++ packages/pigeon/lib/dart_generator.dart | 97 ++++++------------- packages/pigeon/pigeons/proxy_api_tests.dart | 8 +- .../src/generated/proxy_api_tests.gen.dart | 60 ++++++------ 4 files changed, 105 insertions(+), 101 deletions(-) diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index 0c48faa45456..070ab5a5945f 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -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, List); @@ -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 get allSuperClasses => recursiveGetSuperClassApisChain( + this, + ); + + /// All ProxyApis this API `implements` and all the interfaces those APIs + /// `implements`. + Iterable get apisOfInterfaces => + recursiveFindAllInterfaceApis(this); + + /// All methods inherited from interfaces and the interfaces of interfaces. + Iterable 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 flutterMethodsFromSuperClasses() sync* { + for (final AstProxyApi proxyApi in allSuperClasses.toList().reversed) { + yield* proxyApi.flutterMethods; + } + if (superClass != null) { + final Set interfaceApisFromSuperClasses = + recursiveFindAllInterfaceApis( + superClass!.associatedProxyApi!, + ); + for (final AstProxyApi proxyApi in interfaceApisFromSuperClasses) { + yield* proxyApi.methods; + } + } + } + @override String toString() { return '(ProxyApi name:$name methods:$methods field:$fields ' diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index d69a70870ee3..3d07568a21c6 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -455,9 +455,9 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; Indent indent, { required String dartPackageName, }) { - indent.writeln(proxyApiBaseClass); + indent.format(proxyApiBaseClass); - indent.writeln( + indent.format( instanceManagerTemplate( allProxyApiNames: root.apis .whereType() @@ -473,7 +473,7 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; Indent indent, { required String dartPackageName, }) { - indent.writeln( + indent.format( instanceManagerApiTemplate( dartPackageName: dartPackageName, pigeonChannelCodecVarName: _pigeonChannelCodec, @@ -487,7 +487,7 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; Root root, Indent indent, ) { - indent.writeln(proxyApiBaseCodec); + indent.format(proxyApiBaseCodec); } @override @@ -500,48 +500,11 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; }) { const String codecName = '_${classNamePrefix}ProxyApiBaseCodec'; - // Each api has a private codec instance used by every host method, + // Each API has a private codec instance used by every host method, // constructor, or non-static field. final String codecInstanceName = '${_varNamePrefix}codec${api.name}'; - // A list of ProxyApis where each `extends` the API that follows it. - final List superClassApisChain = - recursiveGetSuperClassApisChain( - api, - ); - - // All ProxyApis this API `implements` and all the interfaces those APIs - // `implements`. - final Set apisOfInterfaces = - recursiveFindAllInterfaceApis(api); - - // All methods inherited from interfaces and the interfaces of interfaces. - final List flutterMethodsFromInterfaces = []; - for (final AstProxyApi proxyApi in apisOfInterfaces) { - flutterMethodsFromInterfaces.addAll(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`. - final List flutterMethodsFromSuperClasses = []; - for (final AstProxyApi proxyApi in superClassApisChain.reversed) { - flutterMethodsFromSuperClasses.addAll(proxyApi.flutterMethods); - } - if (api.superClass != null) { - final Set interfaceApisFromSuperClasses = - recursiveFindAllInterfaceApis( - api.superClass!.associatedProxyApi!, - ); - for (final AstProxyApi proxyApi in interfaceApisFromSuperClasses) { - flutterMethodsFromSuperClasses.addAll(proxyApi.methods); - } - } - - // Ast class used by code_builder to generate the code. + // AST class used by code_builder to generate the code. final cb.Class proxyApi = cb.Class( (cb.ClassBuilder builder) => builder ..name = api.name @@ -564,8 +527,8 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; codecInstanceName: codecInstanceName, superClassApi: api.superClass?.associatedProxyApi, unattachedFields: api.unattachedFields, - flutterMethodsFromSuperClasses: flutterMethodsFromSuperClasses, - flutterMethodsFromInterfaces: flutterMethodsFromInterfaces, + flutterMethodsFromSuperClasses: api.flutterMethodsFromSuperClasses(), + flutterMethodsFromInterfaces: api.flutterMethodsFromInterfaces(), declaredFlutterMethods: api.flutterMethods, )) ..constructors.add( @@ -573,8 +536,9 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; apiName: api.name, superClassApi: api.superClass?.associatedProxyApi, unattachedFields: api.unattachedFields, - flutterMethodsFromSuperClasses: flutterMethodsFromSuperClasses, - flutterMethodsFromInterfaces: flutterMethodsFromInterfaces, + flutterMethodsFromSuperClasses: + api.flutterMethodsFromSuperClasses(), + flutterMethodsFromInterfaces: api.flutterMethodsFromInterfaces(), declaredFlutterMethods: api.flutterMethods, ), ) @@ -592,7 +556,7 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; api.flutterMethods, apiName: api.name, )) - ..fields.addAll(_proxyApiInterfaceApiFields(apisOfInterfaces)) + ..fields.addAll(_proxyApiInterfaceApiFields(api.apisOfInterfaces)) ..fields.addAll(_proxyApiAttachedFields(api.attachedFields)) ..methods.add( _proxyApiSetUpMessageHandlerMethod( @@ -602,8 +566,8 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; codecName: codecName, unattachedFields: api.unattachedFields, hasCallbackConstructor: api.flutterMethods - .followedBy(flutterMethodsFromSuperClasses) - .followedBy(flutterMethodsFromInterfaces) + .followedBy(api.flutterMethodsFromSuperClasses()) + .followedBy(api.flutterMethodsFromInterfaces()) .every((Method method) => !method.isRequired), ), ) @@ -623,17 +587,20 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; codecInstanceName: codecInstanceName, codecName: codecName, )) - ..methods.add(_proxyApiCopyMethod( - apiName: api.name, - unattachedFields: api.unattachedFields, - declaredAndInheritedFlutterMethods: flutterMethodsFromSuperClasses - .followedBy(flutterMethodsFromInterfaces) - .followedBy(api.flutterMethods), - )), + ..methods.add( + _proxyApiCopyMethod( + apiName: api.name, + unattachedFields: api.unattachedFields, + declaredAndInheritedFlutterMethods: api + .flutterMethodsFromSuperClasses() + .followedBy(api.flutterMethodsFromInterfaces()) + .followedBy(api.flutterMethods), + ), + ), ); final cb.DartEmitter emitter = cb.DartEmitter(useNullSafetySyntax: true); - indent.write(DartFormatter().format('${proxyApi.accept(emitter)}')); + indent.format(DartFormatter().format('${proxyApi.accept(emitter)}')); } /// Generates Dart source code for test support libraries based on the given AST @@ -1140,8 +1107,8 @@ if (${_varNamePrefix}replyList == null) { /// The detached constructor present for every ProxyApi. /// /// This constructor doesn't include a host method call to create a new native - /// class instance. It is mainly used when the native side once to create a - /// Dart instance and when the `InstanceManager` wants to create a copy for + /// class instance. It is mainly used when the native side wants to create a + /// Dart instance or when the `InstanceManager` wants to create a copy for /// automatic garbage collection. cb.Constructor _proxyApiDetachedConstructor({ required String apiName, @@ -1260,17 +1227,13 @@ if (${_varNamePrefix}replyList == null) { [ ...method.documentationComments, ...[ - if (method.documentationComments.isNotEmpty) - '' - else ...[ - 'Callback method.', - '', - ], + if (method.documentationComments.isEmpty) 'Callback method.', + '', 'For the associated Native object to be automatically garbage collected,', "it is required that the implementation of this `Function` doesn't have a", 'strong reference to the encapsulating class instance. When this `Function`', 'references a non-local variable, it is strongly recommended to access it', - 'from a `WeakReference`:', + 'with a `WeakReference`:', '', '```dart', 'final WeakReference weakMyVariable = WeakReference(myVariable);', diff --git a/packages/pigeon/pigeons/proxy_api_tests.dart b/packages/pigeon/pigeons/proxy_api_tests.dart index 1976af972d32..699e5dfaed86 100644 --- a/packages/pigeon/pigeons/proxy_api_tests.dart +++ b/packages/pigeon/pigeons/proxy_api_tests.dart @@ -10,8 +10,8 @@ enum ProxyApiTestEnum { three, } -/// The core interface that each host language plugin must implement in -/// platform_test integration tests. +/// The core ProxyApi test class that each supported host language must +/// implement in platform_tests integration tests. @ProxyApi() abstract class ProxyApiTestClass extends ProxyApiSuperClass implements ProxyApiInterface { @@ -454,7 +454,7 @@ abstract class ProxyApiTestClass extends ProxyApiSuperClass String callFlutterEchoAsyncString(String aString); } -/// ProxyApi to serve as a super class to the core ProxyApi interface. +/// ProxyApi to serve as a super class to the core ProxyApi class. @ProxyApi() abstract class ProxyApiSuperClass { ProxyApiSuperClass(); @@ -462,7 +462,7 @@ abstract class ProxyApiSuperClass { void aSuperMethod(); } -/// ProxyApi to serve as an interface to the core ProxyApi interface. +/// ProxyApi to serve as an interface to the core ProxyApi class. @ProxyApi() abstract class ProxyApiInterface { late void Function()? anInterfaceMethod; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart index a14413a3d3fd..762f65d5aad0 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart @@ -397,8 +397,8 @@ enum ProxyApiTestEnum { three, } -/// The core interface that each host language plugin must implement in -/// platform_test integration tests. +/// The core ProxyApi test class that each supported host language must +/// implement in platform_tests integration tests. class ProxyApiTestClass extends ProxyApiSuperClass implements ProxyApiInterface { ProxyApiTestClass({ @@ -635,7 +635,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -656,7 +656,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -677,7 +677,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -699,7 +699,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -723,7 +723,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -747,7 +747,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -771,7 +771,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -795,7 +795,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -819,7 +819,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -844,7 +844,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -868,7 +868,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -893,7 +893,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -917,7 +917,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -941,7 +941,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -965,7 +965,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -989,7 +989,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -1013,7 +1013,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -1037,7 +1037,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -1061,7 +1061,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -1085,7 +1085,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -1109,7 +1109,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -1133,7 +1133,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -1157,7 +1157,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -1182,7 +1182,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -1204,7 +1204,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); @@ -4765,7 +4765,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass } } -/// ProxyApi to serve as a super class to the core ProxyApi interface. +/// ProxyApi to serve as a super class to the core ProxyApi class. class ProxyApiSuperClass extends PigeonProxyApiBaseClass { ProxyApiSuperClass({ super.pigeon_binaryMessenger, @@ -4898,7 +4898,7 @@ class ProxyApiSuperClass extends PigeonProxyApiBaseClass { } } -/// ProxyApi to serve as an interface to the core ProxyApi interface. +/// ProxyApi to serve as an interface to the core ProxyApi class. class ProxyApiInterface extends PigeonProxyApiBaseClass { /// Constructs [ProxyApiInterface] without creating the associated native object. /// @@ -4917,7 +4917,7 @@ class ProxyApiInterface extends PigeonProxyApiBaseClass { /// it is required that the implementation of this `Function` doesn't have a /// strong reference to the encapsulating class instance. When this `Function` /// references a non-local variable, it is strongly recommended to access it - /// from a `WeakReference`: + /// with a `WeakReference`: /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); From 796d336a314659e7833f1bfee83f8076412d338b Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 28 Feb 2024 18:39:57 -0500 Subject: [PATCH 32/32] move methods --- packages/pigeon/lib/ast.dart | 106 ++++++++++++++++-- packages/pigeon/lib/dart_generator.dart | 7 +- packages/pigeon/lib/generator_tools.dart | 86 -------------- .../pigeon/test/generator_tools_test.dart | 13 +-- 4 files changed, 101 insertions(+), 111 deletions(-) diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index 070ab5a5945f..bc4ec8c44777 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -4,7 +4,6 @@ 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, List); @@ -179,18 +178,55 @@ class AstProxyApi extends Api { ); /// A list of AstProxyApis where each `extends` the API that follows it. - Iterable get allSuperClasses => recursiveGetSuperClassApisChain( - this, + /// + /// 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 allSuperClasses() { + final List superClassChain = []; + + 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 get apisOfInterfaces => - recursiveFindAllInterfaceApis(this); + Iterable apisOfInterfaces() => _recursiveFindAllInterfaceApis(); /// All methods inherited from interfaces and the interfaces of interfaces. Iterable flutterMethodsFromInterfaces() sync* { - for (final AstProxyApi proxyApi in apisOfInterfaces) { + for (final AstProxyApi proxyApi in apisOfInterfaces()) { yield* proxyApi.methods; } } @@ -204,20 +240,70 @@ class AstProxyApi extends Api { /// This also includes methods that super classes inherited from interfaces /// with `implements`. Iterable flutterMethodsFromSuperClasses() sync* { - for (final AstProxyApi proxyApi in allSuperClasses.toList().reversed) { + for (final AstProxyApi proxyApi in allSuperClasses().toList().reversed) { yield* proxyApi.flutterMethods; } if (superClass != null) { final Set interfaceApisFromSuperClasses = - recursiveFindAllInterfaceApis( - superClass!.associatedProxyApi!, - ); + 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 _recursiveFindAllInterfaceApis([ + Set seenApis = const {}, + ]) { + final Set allInterfaces = {}; + + 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 newSeenApis = {...seenApis, this}; + + for (final AstProxyApi interfaceApi in {...allInterfaces}) { + allInterfaces.addAll( + interfaceApi._recursiveFindAllInterfaceApis(newSeenApis), + ); + } + + return allInterfaces; + } + @override String toString() { return '(ProxyApi name:$name methods:$methods field:$fields ' diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 3d07568a21c6..40ce7a6e5df4 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -556,7 +556,7 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; api.flutterMethods, apiName: api.name, )) - ..fields.addAll(_proxyApiInterfaceApiFields(api.apisOfInterfaces)) + ..fields.addAll(_proxyApiInterfaceApiFields(api.apisOfInterfaces())) ..fields.addAll(_proxyApiAttachedFields(api.attachedFields)) ..methods.add( _proxyApiSetUpMessageHandlerMethod( @@ -565,10 +565,7 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; dartPackageName: dartPackageName, codecName: codecName, unattachedFields: api.unattachedFields, - hasCallbackConstructor: api.flutterMethods - .followedBy(api.flutterMethodsFromSuperClasses()) - .followedBy(api.flutterMethodsFromInterfaces()) - .every((Method method) => !method.isRequired), + hasCallbackConstructor: api.hasCallbackConstructor(), ), ) ..methods.addAll( diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index d2d17ebc40e7..66dd99750f34 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -645,92 +645,6 @@ String? deducePackageName(String mainDartFile) { } } -/// 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 recursiveFindAllInterfaceApis( - AstProxyApi api, { - Set seenApis = const {}, -}) { - final Set allInterfaces = {}; - - allInterfaces.addAll( - api.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 newSeenApis = {...seenApis, api}; - - for (final AstProxyApi interfaceApi in {...allInterfaces}) { - allInterfaces.addAll(recursiveFindAllInterfaceApis( - interfaceApi, - seenApis: newSeenApis, - )); - } - - return allInterfaces; -} - -/// Creates a list of ProxyApis where each `extends` the ProxyApi that follows -/// it. -/// -/// Returns an empty list if [proxyApi] 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]. -List recursiveGetSuperClassApisChain(AstProxyApi api) { - final List superClassChain = []; - - if (api.superClass != null && !api.superClass!.isProxyApi) { - throw ArgumentError( - 'Could not find a ProxyApi for super class: ${api.superClass!.baseName}', - ); - } - - AstProxyApi? currentProxyApi = api.superClass?.associatedProxyApi; - while (currentProxyApi != null) { - if (superClassChain.contains(currentProxyApi)) { - throw ArgumentError( - 'Loop found when processing super classes for a ProxyApi: ' - '${api.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; -} - /// Enum to specify api type when generating code. enum ApiType { /// Flutter api. diff --git a/packages/pigeon/test/generator_tools_test.dart b/packages/pigeon/test/generator_tools_test.dart index 6b43b93eecc5..e68bb96239c1 100644 --- a/packages/pigeon/test/generator_tools_test.dart +++ b/packages/pigeon/test/generator_tools_test.dart @@ -404,10 +404,8 @@ void main() { ), ); - final List apiChain = recursiveGetSuperClassApisChain(api); - expect( - apiChain, + api.allSuperClasses().toList(), containsAllInOrder([ superClassApi, superClassOfSuperClassApi, @@ -478,10 +476,8 @@ void main() { }, ); - final Set allInterfaces = recursiveFindAllInterfaceApis(api); - expect( - allInterfaces, + api.apisOfInterfaces(), containsAll([ interfaceApi, interfaceApi2, @@ -523,9 +519,6 @@ void main() { TypeDeclaration(baseName: 'A', isNullable: false, associatedProxyApi: a), }; - expect( - () => recursiveFindAllInterfaceApis(a), - throwsArgumentError, - ); + expect(() => a.apisOfInterfaces(), throwsArgumentError); }); }