From 169cd76cc7e326e305f8ee07cf8762060cf0d7df Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 30 Nov 2023 13:52:23 -0500 Subject: [PATCH 01/73] update ast --- packages/pigeon/lib/ast.dart | 155 ++++++++++++++++++++-- packages/pigeon/lib/cpp_generator.dart | 21 ++- packages/pigeon/lib/dart_generator.dart | 21 ++- packages/pigeon/lib/generator.dart | 87 +++++++++--- packages/pigeon/lib/java_generator.dart | 20 ++- packages/pigeon/lib/kotlin_generator.dart | 17 +-- packages/pigeon/lib/objc_generator.dart | 15 +-- packages/pigeon/lib/pigeon_lib.dart | 18 ++- packages/pigeon/lib/swift_generator.dart | 20 ++- 9 files changed, 273 insertions(+), 101 deletions(-) diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index 261ba62040d3..2e6170c427ba 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, + required this.required, 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,147 @@ 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. + final 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; + + @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, + }); + + /// Whether this is an attached field for a [ProxyApiNode]. + /// + /// Attached fields provide a synchronous [ProxyApiNode] instance as a field for + /// another [ProxyApiNode] + final bool isAttached; + + /// Whether this is a static field of a ProxyApi. + final bool 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 +243,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)'; } } diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index 41c8226bb806..56010ab22b02 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -191,10 +191,11 @@ 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) { @@ -317,10 +318,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 +370,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); } @@ -823,10 +822,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 +935,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 1f0b4dac38c8..d8bfafc8bbc8 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); @@ -641,12 +639,10 @@ if (${_varNamePrefix}replyList == null) { 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( + if (api is AstHostApi && 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,11 @@ 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.whereType().any((Api api) => api.methods.isNotEmpty); + final bool hasFlutterApi = root.apis + .whereType() + .any((Api api) => api.methods.isNotEmpty); if (hasHostApi) { _writeCreateConnectionError(indent); diff --git a/packages/pigeon/lib/generator.dart b/packages/pigeon/lib/generator.dart index 1bd083078745..1f48724012eb 100644 --- a/packages/pigeon/lib/generator.dart +++ b/packages/pigeon/lib/generator.dart @@ -63,6 +63,22 @@ 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, + ); + } + writeEnums( generatorOptions, root, @@ -224,22 +240,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 +274,7 @@ abstract class StructuredGenerator extends Generator { T generatorOptions, Root root, Indent indent, - Api api, { + AstFlutterApi api, { required String dartPackageName, }); @@ -258,7 +283,33 @@ 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 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/java_generator.dart b/packages/pigeon/lib/java_generator.dart index 16e806a170b4..4e94a92f8a97 100644 --- a/packages/pigeon/lib/java_generator.dart +++ b/packages/pigeon/lib/java_generator.dart @@ -389,7 +389,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 @@ -403,7 +403,6 @@ class JavaGenerator extends StructuredGenerator { return '${_getArgumentName(count, argument)}Arg'; } - assert(api.location == ApiLocation.flutter); if (getCodecClasses(api, root).isNotEmpty) { _writeCodec(indent, api, root); } @@ -546,9 +545,8 @@ class JavaGenerator extends StructuredGenerator { required String dartPackageName, }) { if (root.apis.any((Api api) => - api.location == ApiLocation.host && - api.methods.any((Method it) => it.isAsynchronous) || - api.location == ApiLocation.flutter)) { + api is AstHostApi && api.methods.any((Method it) => it.isAsynchronous) || + api is AstFlutterApi)) { indent.newln(); _writeResultInterfaces(indent); } @@ -567,10 +565,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); } @@ -946,10 +943,11 @@ 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 e8d69ebef5f0..decaf310d6d2 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); @@ -447,11 +446,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; @@ -739,10 +736,10 @@ 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..674ba1c2cf41 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,11 @@ 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 032cb691788f..032969c1723b 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -831,8 +831,7 @@ List _validateAst(Root root, String source) { )); } } - if (method.taskQueueType != TaskQueueType.serial && - api.location != ApiLocation.host) { + if (method.taskQueueType != TaskQueueType.serial && api is HostApi) { result.add(Error( message: 'Unsupported TaskQueue specification on ${method.name}', lineNumber: _calculateLineNumberNullable(source, method.offset), @@ -1066,18 +1065,17 @@ 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), - ); + ) as Api; } else if (_hasMetadata(node.metadata, 'FlutterApi')) { - _currentApi = Api( + _currentApi = AstFlutterApi( name: node.name.lexeme, - location: ApiLocation.flutter, methods: [], documentationComments: _documentationCommentsParser(node.documentationComment?.tokens), @@ -1228,6 +1226,12 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { typeAnnotationsToTypeArguments(returnType.typeArguments), isNullable: returnType.question != null), parameters: arguments, + required: true, + location: switch (_currentApi!) { + AstHostApi() => ApiLocation.host, + AstProxyApi() => ApiLocation.host, + AstFlutterApi() => ApiLocation.flutter, + }, isAsynchronous: isAsynchronous, objcSelector: objcSelector, swiftFunction: swiftFunction, diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index ae869426e620..724c234c9b73 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -236,8 +236,7 @@ import FlutterMacOS required String dartPackageName, }) { if (root.apis.any((Api api) => - api.location == ApiLocation.host && - api.methods.any((Method it) => it.isAsynchronous))) { + api is AstHostApi && api.methods.any((Method it) => it.isAsynchronous))) { indent.newln(); } super.writeApis(generatorOptions, root, indent, @@ -256,11 +255,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 +377,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 +797,11 @@ 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); From 9d4f82c6b7b6b8158ebca9ecd642c3f075e09e9b Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 30 Nov 2023 15:36:00 -0500 Subject: [PATCH 02/73] update pigeon_lib --- packages/pigeon/lib/ast.dart | 13 +- packages/pigeon/lib/pigeon_lib.dart | 206 +++++++++++++++++++++++++++- 2 files changed, 216 insertions(+), 3 deletions(-) diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index 2e6170c427ba..1a83fdae86bc 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. - final List fields; + List fields; /// Name of the class this class considers the super class. final String? superClassName; @@ -217,6 +217,17 @@ class Field extends NamedType { /// Whether this is a static field of a ProxyApi. 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, + ); + } } /// Represents a collection of [Method]s. diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 032969c1723b..6c8a1e5e9dab 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -39,9 +39,23 @@ 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. +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 +102,27 @@ 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, this.interfaces = const {}}); + + /// The ProxyApi that this class extends. + final Type? superClass; + + /// The set of interfaces this class implements. + final Set interfaces; +} + /// 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. @@ -788,6 +823,9 @@ List _validateAst(Root root, String source) { } } for (final Api api in root.apis) { + if (api is AstProxyApi) { + continue; + } for (final Method method in api.methods) { for (final Parameter param in method.parameters) { if (param.type.baseName.isEmpty) { @@ -941,6 +979,23 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { func.parameters = paramList; func.returnType = _attachClassesAndEnums(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(_attachClassesAndEnums(param.type)), + ); + } + constructor.parameters = paramList; + } + + final List fieldList = []; + for (final Field field in api.fields) { + fieldList.add(field.copyWithType(_attachClassesAndEnums(field.type))); + api.fields = fieldList; + } + } } return ParseResults( @@ -987,6 +1042,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) { @@ -1000,6 +1057,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: @@ -1080,6 +1150,32 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { 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); + } + } + + _currentApi = AstProxyApi( + name: node.name.lexeme, + methods: [], + constructors: [], + fields: [], + superClassName: annotationMap['superClass'] as String?, + interfacesNames: annotationMap['interfaces'] != null + ? (annotationMap['interfaces']! as Set).cast() + : {}, + documentationComments: + _documentationCommentsParser(node.documentationComment?.tokens), + ); } } else { _currentClass = Class( @@ -1187,6 +1283,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 @@ -1227,6 +1324,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { isNullable: returnType.question != null), parameters: arguments, required: true, + isStatic: isStatic, location: switch (_currentApi!) { AstHostApi() => ApiLocation.host, AstProxyApi() => ApiLocation.host, @@ -1287,8 +1385,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: @@ -1324,6 +1422,87 @@ 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, + 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").', @@ -1335,7 +1514,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))); From b5d7fcd11afd7b3295393156bfefb731477ddbfa Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Sat, 2 Dec 2023 20:10:21 -0500 Subject: [PATCH 03/73] fix unit tests --- packages/pigeon/lib/ast.dart | 2 +- packages/pigeon/lib/pigeon_lib.dart | 3 +- packages/pigeon/test/cpp_generator_test.dart | 88 +++++--- packages/pigeon/test/dart_generator_test.dart | 167 ++++++++------- .../pigeon/test/generator_tools_test.dart | 27 +-- packages/pigeon/test/java_generator_test.dart | 87 +++++--- .../pigeon/test/kotlin_generator_test.dart | 80 +++++--- packages/pigeon/test/objc_generator_test.dart | 193 ++++++++++++------ packages/pigeon/test/pigeon_lib_test.dart | 4 +- .../pigeon/test/swift_generator_test.dart | 84 +++++--- .../webview_flutter_android/pubspec.yaml | 3 +- 11 files changed, 467 insertions(+), 271 deletions(-) diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index 1a83fdae86bc..b5014d5f8f1e 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, - required this.required, + this.required = false, this.isAsynchronous = false, this.isStatic = false, this.offset, diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 6c8a1e5e9dab..62b6cfd6d0d9 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -869,7 +869,8 @@ List _validateAst(Root root, String source) { )); } } - if (method.taskQueueType != TaskQueueType.serial && api is HostApi) { + if (method.taskQueueType != TaskQueueType.serial && + api is AstFlutterApi) { result.add(Error( message: 'Unsupported TaskQueue specification on ${method.name}', lineNumber: _calculateLineNumberNullable(source, method.offset), 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 2ab5f3f8df08..ed6579ae38a0 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( @@ -1467,13 +1492,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: [ @@ -1542,12 +1567,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( @@ -1580,9 +1605,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( @@ -1633,13 +1659,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( @@ -1686,9 +1712,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..060b03994691 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 Api 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 Api 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 Api 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( + AstFlutterApi( 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 99936ca2b925..8222cb232948 100644 --- a/packages/pigeon/test/java_generator_test.dart +++ b/packages/pigeon/test/java_generator_test.dart @@ -122,9 +122,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( @@ -264,9 +265,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( @@ -317,9 +319,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( @@ -358,9 +361,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( @@ -402,9 +406,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', @@ -439,9 +444,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', @@ -577,9 +583,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( @@ -638,9 +645,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( @@ -744,9 +752,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( @@ -874,9 +883,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( @@ -909,9 +919,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( @@ -944,9 +955,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, @@ -976,9 +988,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, @@ -1009,9 +1022,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: [], @@ -1040,9 +1054,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', @@ -1081,9 +1096,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', @@ -1109,9 +1125,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', @@ -1151,9 +1168,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', @@ -1183,9 +1201,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, @@ -1212,9 +1231,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, @@ -1243,9 +1263,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( @@ -1276,9 +1297,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( @@ -1312,9 +1334,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( @@ -1414,13 +1437,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: [ @@ -1495,12 +1518,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( @@ -1534,9 +1557,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( @@ -1586,8 +1610,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: [], @@ -1609,12 +1632,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 606f47e3690f..56d4bca85716 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( 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 dc0f6061e37f..4dc956bd200c 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,7 +370,7 @@ 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, + expect((results.root.apis[0] as AstHostApi).dartHostTestHandler, equals('ApiWithMockDartClassMock')); }); 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( diff --git a/packages/webview_flutter/webview_flutter_android/pubspec.yaml b/packages/webview_flutter/webview_flutter_android/pubspec.yaml index 4a36901a13a1..3bf27efd1ab9 100644 --- a/packages/webview_flutter/webview_flutter_android/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_android/pubspec.yaml @@ -27,7 +27,8 @@ dev_dependencies: flutter_test: sdk: flutter mockito: 5.4.1 - pigeon: ^11.0.0 + pigeon: + path: ../../pigeon topics: - html From 740a39511c4a31602a3ce5266fb505b3aa2ccfb6 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Sun, 3 Dec 2023 00:08:06 -0500 Subject: [PATCH 04/73] add impls for instancemanager and instancemanager api --- packages/pigeon/lib/dart_generator.dart | 352 +++++++++++++++++- packages/pigeon/lib/generator_tools.dart | 19 +- packages/pigeon/pubspec.yaml | 2 + .../webview_flutter_android/pubspec.yaml | 2 +- 4 files changed, 366 insertions(+), 9 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index d8bfafc8bbc8..37680d954545 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -112,8 +112,13 @@ class DartGenerator extends StructuredGenerator { ); indent.newln(); indent.writeln( - "import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer;"); + "import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer, immutable, protected;"); indent.writeln("import 'package:flutter/services.dart';"); + if (root.apis.any((Api api) => api is AstProxyApi)) { + indent.writeln( + "import 'package:flutter/widgets.dart' show WidgetsFlutterBinding;", + ); + } } @override @@ -605,6 +610,341 @@ if (${_varNamePrefix}replyList == null) { }); } + @override + void writeInstanceManager( + DartOptions generatorOptions, + Root root, + Indent indent, { + required String dartPackageName, + }) { + final Iterable apiHandlerSetups = + root.apis.whereType().map( + (AstProxyApi api) { + return '${api.name}.\$setUpMessageHandlers(\$instanceManager: instanceManager);'; + }, + ); + indent.format(''' +/// An immutable object that can provide functional copies of itself. +/// +/// All implementers are expected to be immutable as defined by the annotation. +@immutable +mixin \$Copyable { + /// Instantiates and returns a functionally identical object to oneself. + /// + /// Outside of tests, this method should only ever be called by + /// [\$InstanceManager]. + /// + /// Subclasses should always override their parent's implementation of this + /// method. + @protected + \$Copyable \$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 \$InstanceManager { + /// Constructs an [\$InstanceManager]. + \$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; + + static final \$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 \$InstanceManager _initInstance() { + WidgetsFlutterBinding.ensureInitialized(); + final _InstanceManagerApi api = _InstanceManagerApi(); + // Clears the native `InstanceManager` on the initial use of the Dart one. + api.clear(); + final \$InstanceManager instanceManager = \$InstanceManager( + onWeakReferenceRemoved: (int identifier) { + api.removeStrongReference(identifier); + }, + ); + _InstanceManagerApi.\$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(\$Copyable 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(\$Copyable 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 \$Copyable? weakInstance = _weakInstances[identifier]?.target; + + if (weakInstance == null) { + final \$Copyable? strongInstance = _strongInstances[identifier]; + if (strongInstance != null) { + final \$Copyable copy = strongInstance.\$copy(); + _identifiers[copy] = identifier; + _weakInstances[identifier] = WeakReference<\$Copyable>(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(\$Copyable 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(\$Copyable instance, int identifier) { + _addInstanceWithIdentifier(instance, identifier); + } + + void _addInstanceWithIdentifier(\$Copyable instance, int identifier) { + assert(!containsIdentifier(identifier)); + assert(getIdentifier(instance) == null); + assert(identifier >= 0); + + _identifiers[instance] = identifier; + _weakInstances[identifier] = WeakReference<\$Copyable>(instance); + _finalizer.attach(instance, identifier, detach: instance); + + final \$Copyable copy = instance.\$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; + } +} +'''); + } + + @override + void writeInstanceManagerApi( + DartOptions generatorOptions, + Root root, + Indent indent, { + required String dartPackageName, + }) { + final String removeStrongReferenceName = makeChannelNameWithStrings( + apiName: r'$InstanceManagerApi', + methodName: 'removeStrongReference', + dartPackageName: dartPackageName, + ); + final String clearName = makeChannelNameWithStrings( + apiName: r'$InstanceManagerApi', + methodName: 'clear', + dartPackageName: dartPackageName, + ); + + indent.writeln(''' +/// Generated API for managing the Dart and native `InstanceManager`s. +class _InstanceManagerApi { + /// Constructor for [_InstanceManagerApi]. + /// + /// The [binaryMessenger] named argument is available for dependency + /// injection. If it is left null, the default [BinaryMessenger] will be used + /// which routes to the host platform. + _InstanceManagerApi({BinaryMessenger? binaryMessenger}) + : _binaryMessenger = binaryMessenger; + + final BinaryMessenger? _binaryMessenger; + + static const MessageCodec pigeonChannelCodec = + StandardMessageCodec(); + + static void \$setUpMessageHandlers({ + BinaryMessenger? binaryMessenger, + \$InstanceManager? instanceManager, + }) { + const String channelName = + r'$removeStrongReferenceName'; + 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 ?? \$InstanceManager.instance).remove(identifier!); + return; + }); + } + + Future removeStrongReference(int identifier) async { + const String channelName = + r'$removeStrongReferenceName'; + 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 `InstanceManager`. + /// + /// This is typically called after a hot restart. + Future clear() async { + const String channelName = + r'$clearName'; + 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; + } + } +}'''); + } + /// 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 @@ -692,16 +1032,18 @@ if (${_varNamePrefix}replyList == null) { Indent indent, { required String dartPackageName, }) { - final bool hasHostApi = - root.apis.whereType().any((Api api) => api.methods.isNotEmpty); + final bool hasHostApi = root.apis + .whereType() + .any((Api api) => api.methods.isNotEmpty); final bool hasFlutterApi = root.apis .whereType() .any((Api api) => api.methods.isNotEmpty); + final bool hasProxyApi = root.apis.any((Api api) => api is AstProxyApi); - if (hasHostApi) { + if (hasHostApi || hasProxyApi) { _writeCreateConnectionError(indent); } - if (hasFlutterApi) { + if (hasFlutterApi || hasProxyApi) { _writeWrapResponse(generatorOptions, root, indent); } } diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 050bbacb974e..d007d8f0358f 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. diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index dcb9487727dd..fa7125de5464 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.8.0 collection: ^1.15.0 + dart_style: ^2.3.4 meta: ^1.7.0 path: ^1.8.0 yaml: ^3.1.1 diff --git a/packages/webview_flutter/webview_flutter_android/pubspec.yaml b/packages/webview_flutter/webview_flutter_android/pubspec.yaml index 3bf27efd1ab9..0d27fb8909d2 100644 --- a/packages/webview_flutter/webview_flutter_android/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_android/pubspec.yaml @@ -26,7 +26,7 @@ dev_dependencies: build_runner: ^2.1.4 flutter_test: sdk: flutter - mockito: 5.4.1 + mockito: 5.4.3 pigeon: path: ../../pigeon From 304e1a03aa1c28e9895e4480d4870265483d5472 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Sun, 3 Dec 2023 19:57:58 -0500 Subject: [PATCH 05/73] add write proxy api impl --- packages/pigeon/lib/dart_generator.dart | 1260 ++++++++++++++++++++++ packages/pigeon/lib/functional.dart | 16 + packages/pigeon/lib/generator_tools.dart | 46 + 3 files changed, 1322 insertions(+) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 37680d954545..491843f7ec61 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:dart_style/dart_style.dart'; import 'package:path/path.dart' as path; import 'ast.dart'; @@ -945,6 +947,1101 @@ class _InstanceManagerApi { }'''); } + @override + void writeProxyApi( + DartOptions generatorOptions, + Root root, + Indent indent, + AstProxyApi api, { + required String dartPackageName, + }) { + final String codecName = _getCodecName(api); + + // Write Codec + indent.writeln(''' +class $codecName extends StandardMessageCodec { + const $codecName(this.instanceManager); + + final \$InstanceManager instanceManager; + + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is \$Copyable) { + 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); + } + } +} +'''); + + final Iterable hostMethods = api.methods.where( + (Method method) => method.location == ApiLocation.host, + ); + + final Iterable flutterMethods = api.methods.where( + (Method method) => method.location == ApiLocation.flutter, + ); + + final Iterable attachedFields = api.fields.where( + (Field field) => field.isAttached, + ); + final Iterable nonAttachedFields = api.fields.where( + (Field field) => !field.isAttached, + ); + + final Iterable allProxyApis = + root.apis.whereType(); + + final List superClassApisChain = + recursiveGetSuperClassApisChain( + api, + allProxyApis, + ); + + final AstProxyApi? superClassApi = + superClassApisChain.isNotEmpty ? superClassApisChain.first : null; + + final Set interfacesApis = recursiveFindAllInterfacesApis( + api.interfacesNames, + allProxyApis, + ); + + final List interfacesMethods = []; + for (final AstProxyApi proxyApi in interfacesApis) { + interfacesMethods.addAll(proxyApi.methods); + } + + // A list of inherited methods from super classes that constructors set with + // `super.`. + final List superClassFlutterMethods = []; + if (superClassApi != null) { + for (final AstProxyApi proxyApi in superClassApisChain) { + for (final Method method in proxyApi.methods) { + if (method.location == ApiLocation.flutter) { + superClassFlutterMethods.add(method); + } + } + } + + final Set superClassInterfacesApis = + recursiveFindAllInterfacesApis( + superClassApi.interfacesNames, + allProxyApis, + ); + for (final AstProxyApi proxyApi in superClassInterfacesApis) { + superClassFlutterMethods.addAll(proxyApi.methods); + } + } + + final bool hasARequiredFlutterMethod = api.methods + .followedBy(superClassFlutterMethods) + .followedBy(interfacesMethods) + .any((Method method) { + return method.location == ApiLocation.flutter && method.required; + }); + + final List customEnumNames = + root.enums.map((Enum x) => x.name).toList(); + + final cb.Class proxyApi = cb.Class( + (cb.ClassBuilder builder) => builder + ..name = api.name + ..extend = _referOrNull(superClassApi?.name) + ..implements.addAll([ + if (api.interfacesNames.isNotEmpty) + ...api.interfacesNames.map((String name) => cb.refer(name)) + else + cb.refer(r'$Copyable') + ]) + ..docs.addAll(_asDartComments(api.documentationComments)) + ..constructors.addAll( + api.constructors.map( + (Constructor constructor) => cb.Constructor( + (cb.ConstructorBuilder builder) => builder + ..name = constructor.name.isNotEmpty ? constructor.name : null + ..docs.addAll(_asDartComments( + constructor.documentationComments, + )) + ..optionalParameters.addAll( + [ + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = r'$binaryMessenger' + ..named = true + ..toSuper = superClassApi != null + ..toThis = superClassApi == null, + ), + cb.Parameter((cb.ParameterBuilder builder) => builder + ..name = r'$instanceManager' + ..type = _referOrNull( + superClassApi == null ? r'$InstanceManager' : null, + isNullable: true, + ) + ..named = true + ..toSuper = superClassApi != null), + for (final Field field in nonAttachedFields) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = field.name + ..named = true + ..toThis = true + ..required = !field.type.isNullable, + ), + for (final Method method in superClassFlutterMethods) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = method.name + ..named = true + ..toSuper = true + ..required = method.required, + ), + for (final Method method in interfacesMethods) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = method.name + ..named = true + ..toThis = true + ..required = method.required, + ), + for (final Method method in flutterMethods) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = method.name + ..named = true + ..toThis = true + ..required = method.required, + ), + ...indexMap( + constructor.parameters, + (int index, NamedType parameter) => cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = _getSafeArgumentName(index, parameter) + ..type = cb.refer( + _addGenericTypesNullable(parameter.type), + ) + ..named = true + ..required = !parameter.type.isNullable, + ), + ), + ], + ) + ..initializers.add( + cb.Code( + superClassApi != null + ? r'super.$detached()' + : r'$instanceManager = $instanceManager ?? $InstanceManager.instance', + ), + ) + ..body = cb.Block.of([ + _basicMessageChannel( + channelName: makeChannelNameWithStrings( + apiName: api.name, + methodName: constructor.name.isNotEmpty + ? constructor.name + : r'$defaultConstructor', + dartPackageName: dartPackageName, + ), + codec: cb.refer('_codec${api.name}'), + binaryMessenger: cb.refer(r'$binaryMessenger'), + ), + cb.Code( + 'final int instanceIdentifier = ${superClassApi != null ? '' : 'this.'}\$instanceManager.addDartCreatedInstance(this);', + ), + cb + .refer('channel') + .property('send') + .call([ + cb.literalList( + [ + cb.refer('instanceIdentifier'), + ...indexMap( + nonAttachedFields, + (int index, Field field) => _parameterArgument( + index, field, + getArgumentName: _getParameterName), + ), + ...indexMap( + constructor.parameters, + (int index, NamedType type) => _parameterArgument( + index, + type, + ), + ), + ], + cb.refer('Object?'), + ) + ]) + .property('then') + .call( + [ + cb.Method( + (cb.MethodBuilder builder) => builder + ..requiredParameters.add( + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = 'value' + ..type = cb.refer('Object?'), + ), + ) + ..body = cb.Block.of([ + const cb.Code( + 'final List? replyList = value as List?;', + ), + const cb.Code('if (replyList == null) {'), + cb.InvokeExpression.newOf( + cb.refer('PlatformException'), + [], + { + 'code': cb.literalString('channel-error'), + 'message': cb.literalString( + 'Unable to establish connection on channel.', + ) + }).thrown.statement, + const cb.Code( + '} else if (replyList.length > 1) {', + ), + cb.InvokeExpression.newOf( + cb.refer('PlatformException'), + [], + { + 'code': cb + .refer('replyList') + .index(cb.literal(0)) + .nullChecked + .asA(cb.refer('String')), + 'message': cb + .refer('replyList') + .index(cb.literal(1)) + .asA(cb.refer('String?')), + 'details': cb + .refer('replyList') + .index(cb.literal(2)), + }).thrown.statement, + const cb.Code('}'), + ]), + ).genericClosure + ], + {}, + [cb.refer('void')], + ) + .statement + ]), + ), + ), + ) + ..constructors.add( + cb.Constructor( + (cb.ConstructorBuilder builder) => builder + ..name = r'$detached' + ..docs.addAll([ + '/// Constructs ${api.name} without creating the associated native object.', + '///', + '/// This should only be used by subclasses created by this library or to', + '/// create copies.', + ]) + ..optionalParameters.addAll([ + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = r'$binaryMessenger' + ..named = true + ..toSuper = superClassApi != null + ..toThis = superClassApi == null, + ), + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = r'$instanceManager' + ..type = _referOrNull( + superClassApi == null ? r'$InstanceManager' : null, + isNullable: true, + ) + ..named = true + ..toSuper = superClassApi != null, + ), + for (final Field field in nonAttachedFields) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = field.name + ..named = true + ..toThis = true + ..required = !field.type.isNullable, + ), + for (final Method method in superClassFlutterMethods) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = method.name + ..named = true + ..toSuper = true + ..required = method.required, + ), + for (final Method method in interfacesMethods) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = method.name + ..named = true + ..toThis = true + ..required = method.required, + ), + for (final Method method in flutterMethods) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = method.name + ..named = true + ..toThis = true + ..required = method.required, + ), + ]) + ..initializers.add( + cb.Code( + superClassApi != null + ? r'super.$detached()' + : r'$instanceManager = $instanceManager ?? $InstanceManager.instance', + ), + ), + ), + ) + ..methods.add( + cb.Method.returnsVoid( + (cb.MethodBuilder builder) => builder + ..name = r'$setUpMessageHandlers' + ..returns = cb.refer('void') + ..static = true + ..optionalParameters.addAll([ + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = r'$binaryMessenger' + ..named = true + ..type = cb.refer('BinaryMessenger?'), + ), + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = r'$instanceManager' + ..named = true + ..type = cb.refer(r'$InstanceManager?'), + ), + if (!hasARequiredFlutterMethod) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = r'$detached' + ..named = true + ..type = cb.FunctionType( + (cb.FunctionTypeBuilder builder) => builder + ..returnType = cb.refer(api.name) + ..isNullable = true + ..requiredParameters.addAll(indexMap( + nonAttachedFields, + (int index, Field 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 = _referOrNull( + _addGenericTypesNullable(method.returnType), + isFuture: method.isAsynchronous, + ) + ..isNullable = true + ..requiredParameters.addAll([ + cb.refer('${api.name} instance'), + ...indexMap( + method.parameters, + (int index, NamedType parameter) { + return cb.refer( + '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', + ); + }, + ) + ]), + ), + ), + ]) + ..body = cb.Block.of([ + cb.Code( + 'final $codecName codec = $codecName(\$instanceManager ?? \$InstanceManager.instance);', + ), + if (!hasARequiredFlutterMethod) ...[ + const cb.Code('{'), + _basicMessageChannel( + channelName: makeChannelNameWithStrings( + apiName: api.name, + methodName: r'$detached', + dartPackageName: dartPackageName, + ), + binaryMessenger: cb.refer(r'$binaryMessenger'), + ), + cb.refer('channel').property('setMessageHandler').call( + [ + cb.Method( + (cb.MethodBuilder builder) => builder + ..modifier = cb.MethodModifier.async + ..requiredParameters.add( + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = 'message' + ..type = cb.refer('Object?'), + ), + ) + ..body = cb.Block((cb.BlockBuilder builder) { + final String channelName = + makeChannelNameWithStrings( + apiName: api.name, + methodName: r'$detached', + dartPackageName: dartPackageName, + ); + builder.statements.addAll([ + _assert( + condition: cb + .refer('message') + .notEqualTo(cb.literalNull), + message: cb.literalString( + 'Argument for $channelName was null.', + raw: true, + ), + ), + const cb.Code( + 'final List args = (message as List?)!;', + ), + const cb.Code( + 'final int? instanceIdentifier = (args[0] as int?);', + ), + _assert( + condition: cb + .refer('instanceIdentifier') + .notEqualTo(cb.literalNull), + message: cb.literalString( + 'Argument for $channelName was null, expected non-null int.', + raw: true, + ), + ), + ...indexFold, Field>( + nonAttachedFields, + [], + (List list, int index, Field field) { + return list + ..addAll(_messageArg( + index + 1, + field, + customEnumNames: customEnumNames, + channelName: channelName, + )); + }, + ), + cb + .refer( + r'($instanceManager ?? $InstanceManager.instance)', + ) + .property('addHostCreatedInstance') + .call([ + cb + .refer(r'$detached?.call') + .call( + indexMap( + nonAttachedFields, + (int index, Field field) { + // The calling instance is the first arg. + final String name = + _getSafeArgumentName( + index + 1, + field, + ); + return field.type.isNullable + ? cb.refer(name) + : cb.refer(name).nullChecked; + }, + ), + ) + .ifNullThen( + cb.refer('${api.name}.\$detached').call( + [], + { + r'$binaryMessenger': + cb.refer(r'$binaryMessenger'), + r'$instanceManager': + cb.refer(r'$instanceManager'), + ...nonAttachedFields + .toList() + .asMap() + .map( + (int index, Field field) { + final String argName = + _getSafeArgumentName( + index + 1, + field, + ); + return MapEntry( + field.name, + field.type.isNullable + ? cb.refer(argName) + : cb + .refer(argName) + .nullChecked, + ); + }, + ) + }, + ), + ), + cb.refer('instanceIdentifier').nullChecked + ]).statement, + const cb.Code('return;'), + ]); + }), + ).genericClosure + ], + ).statement, + const cb.Code('}'), + ], + ...flutterMethods.fold>( + [], + (List list, Method method) { + final String channelName = makeChannelName( + api, + method, + dartPackageName, + ); + final cb.Expression call = cb + .refer( + '(${method.name} ?? instance!.${method.name})${method.required ? '' : '?'}.call', + ) + .call( + [ + cb.refer('instance').nullChecked, + ...indexMap( + method.parameters, + (int index, NamedType parameter) { + final String name = _getSafeArgumentName( + index + 1, + parameter, + ); + return cb + .refer(name) + .nullCheckedIf(!parameter.type.isNullable); + }, + ), + ], + ); + return list + ..addAll([ + const cb.Code('{'), + _basicMessageChannel( + channelName: channelName, + binaryMessenger: cb.refer(r'$binaryMessenger'), + ), + cb.refer('channel').property('setMessageHandler').call( + [ + cb.Method( + (cb.MethodBuilder builder) => builder + ..modifier = cb.MethodModifier.async + ..requiredParameters.add( + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = 'message' + ..type = cb.refer('Object?'), + ), + ) + ..body = cb.Block((cb.BlockBuilder builder) { + builder.statements.addAll([ + _assert( + condition: cb + .refer('message') + .notEqualTo(cb.literalNull), + message: cb.literalString( + 'Argument for $channelName was null.', + raw: true, + ), + ), + const cb.Code( + 'final List args = (message as List?)!;', + ), + cb.Code( + 'final ${api.name}? instance = (args[0] as ${api.name}?);', + ), + _assert( + condition: cb + .refer('instance') + .notEqualTo(cb.literalNull), + message: cb.literalString( + 'Argument for $channelName was null, expected non-null ${api.name}.', + raw: true, + ), + ), + ...indexFold, NamedType>( + method.parameters, + [], + ( + List list, + int index, + NamedType type, + ) { + return list + ..addAll(_messageArg( + index + 1, + type, + customEnumNames: customEnumNames, + channelName: channelName, + )); + }, + ), + const cb.Code('try {'), + if (method.returnType.isVoid) ...[ + if (method.isAsynchronous) + call.awaited.statement + else + call.statement, + const cb.Code( + 'return wrapResponse(empty: true);', + ), + ] else ...[ + cb + .declareFinal( + 'output', + type: cb.refer( + _addGenericTypesNullable( + method.returnType, + ), + ), + ) + .assign( + call.awaitedIf( + method.isAsynchronous, + ), + ) + .statement, + _wrapResultResponse( + root, method.returnType) + .returned + .statement, + ], + const cb.Code( + '} on PlatformException catch (e) {', + ), + const cb.Code( + 'return wrapResponse(error: e);', + ), + const cb.Code('} catch (e) {'), + const cb.Code( + "return wrapResponse(error: PlatformException(code: 'error', message: e.toString()),);", + ), + const cb.Code('}') + ]); + }), + ).genericClosure + ], + ).statement, + const cb.Code('}'), + ]); + }, + ), + ]), + ), + ) + ..fields.addAll([ + if (hostMethods.isNotEmpty || + api.constructors.isNotEmpty || + attachedFields.where((Field field) => !field.isStatic).isNotEmpty) + cb.Field( + (cb.FieldBuilder builder) => builder + ..name = '_codec${api.name}' + ..type = cb.refer(codecName) + ..late = true + ..modifier = cb.FieldModifier.final$ + ..assignment = cb.Code('$codecName(\$instanceManager)'), + ), + if (superClassApi == null) ...[ + cb.Field( + (cb.FieldBuilder builder) => builder + ..name = r'$binaryMessenger' + ..type = cb.refer('BinaryMessenger?') + ..modifier = cb.FieldModifier.final$ + ..docs.addAll([ + '/// 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.', + ]) + ..annotations.addAll([ + if (superClassApi == null && interfacesApis.isNotEmpty) + cb.refer('override'), + ]), + ), + cb.Field( + (cb.FieldBuilder builder) => builder + ..name = r'$instanceManager' + ..type = cb.refer(r'$InstanceManager') + ..modifier = cb.FieldModifier.final$ + ..docs.add( + '/// Maintains instances stored to communicate with native language objects.', + ) + ..annotations.addAll([ + if (superClassApi == null && interfacesApis.isNotEmpty) + cb.refer('override'), + ]), + ), + ], + for (final Field field in nonAttachedFields) + cb.Field( + (cb.FieldBuilder builder) => builder + ..name = field.name + ..type = cb.refer(_addGenericTypesNullable(field.type)) + ..modifier = cb.FieldModifier.final$ + ..docs.addAll(_asDartComments(field.documentationComments)), + ), + for (final Method method in flutterMethods) + cb.Field( + (cb.FieldBuilder builder) => builder + ..name = method.name + ..modifier = cb.FieldModifier.final$ + ..docs.addAll(_asDartComments(method.documentationComments)) + ..type = cb.FunctionType( + (cb.FunctionTypeBuilder builder) => builder + ..returnType = _referOrNull( + _addGenericTypesNullable(method.returnType), + isFuture: method.isAsynchronous, + ) + ..isNullable = !method.required + ..requiredParameters.addAll([ + cb.refer('${api.name} instance'), + ...indexMap( + method.parameters, + (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(_asDartComments(method.documentationComments)) + ..type = cb.FunctionType( + (cb.FunctionTypeBuilder builder) => builder + ..returnType = _referOrNull( + _addGenericTypesNullable(method.returnType), + isFuture: method.isAsynchronous, + ) + ..isNullable = !method.required + ..requiredParameters.addAll([ + cb.refer('${proxyApi.name} instance'), + ...indexMap( + method.parameters, + (int index, NamedType parameter) { + return cb.refer( + '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', + ); + }, + ), + ]), + ), + ), + for (final Field 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(_asDartComments(field.documentationComments)) + ..assignment = cb.Code('_${field.name}()'), + ), + ]) + ..methods.addAll([ + for (final Field field in attachedFields) + cb.Method( + (cb.MethodBuilder builder) { + final String type = _addGenericTypesNullable(field.type); + final String channelName = makeChannelNameWithStrings( + apiName: api.name, + methodName: field.name, + dartPackageName: dartPackageName, + ); + builder + ..name = '_${field.name}' + ..static = field.isStatic + ..returns = cb.refer(type) + ..body = cb.Block.of( + [ + cb.Code('final $type instance = $type.\$detached('), + if (!field.isStatic) ...[ + const cb.Code(r'$binaryMessenger: $binaryMessenger,'), + const cb.Code(r'$instanceManager: $instanceManager,'), + ], + const cb.Code(');'), + _basicMessageChannel( + channelName: channelName, + codec: !field.isStatic + ? cb.refer('_codec${api.name}') + : cb.refer( + '$codecName(\$InstanceManager.instance)', + ), + binaryMessenger: !field.isStatic + ? cb.refer(r'$binaryMessenger') + : null, + ), + cb.Code( + 'final int instanceIdentifier = ${field.isStatic ? r'$InstanceManager.instance' : r'$instanceManager'}.addDartCreatedInstance(instance);', + ), + cb + .refer('channel.send') + .call([ + cb.literalList( + [ + if (!field.isStatic) cb.refer('this'), + cb.refer('instanceIdentifier') + ], + cb.refer('Object?'), + ) + ]) + .property('then') + .call( + [ + cb.Method( + (cb.MethodBuilder builder) => builder + ..requiredParameters.add( + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = 'value' + ..type = cb.refer('Object?'), + ), + ) + ..body = cb.Block.of([ + const cb.Code( + 'final List? replyList = value as List?;', + ), + const cb.Code('if (replyList == null) {'), + cb.InvokeExpression.newOf( + cb.refer('PlatformException'), + [], + { + 'code': + cb.literalString('channel-error'), + 'message': cb.literalString( + 'Unable to establish connection on channel.', + ) + }).thrown.statement, + const cb.Code( + '} else if (replyList.length > 1) {', + ), + cb.InvokeExpression.newOf( + cb.refer('PlatformException'), + [], + { + 'code': cb + .refer('replyList') + .index(cb.literal(0)) + .nullChecked + .asA(cb.refer('String')), + 'message': cb + .refer('replyList') + .index(cb.literal(1)) + .asA(cb.refer('String?')), + 'details': cb + .refer('replyList') + .index(cb.literal(2)), + }).thrown.statement, + const cb.Code('}'), + ]), + ).genericClosure, + ], + {}, + [cb.refer('void')], + ) + .statement, + const cb.Code('return instance;'), + ], + ); + }, + ), + for (final Method method in hostMethods) + cb.Method( + (cb.MethodBuilder builder) => builder + ..name = method.name + ..static = method.isStatic + ..modifier = cb.MethodModifier.async + ..docs.addAll(_asDartComments(method.documentationComments)) + ..returns = _referOrNull( + _addGenericTypesNullable(method.returnType), + isFuture: true, + ) + ..requiredParameters.addAll(indexMap( + method.parameters, + (int index, NamedType parameter) => cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = _getSafeArgumentName(index, parameter) + ..type = cb.refer( + _addGenericTypesNullable(parameter.type), + ), + ), + )) + ..optionalParameters.addAll([ + if (method.isStatic) ...[ + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = r'$binaryMessenger' + ..type = cb.refer('BinaryMessenger?') + ..named = true, + ), + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = r'$instanceManager' + ..type = cb.refer(r'$InstanceManager?'), + ), + ], + ]) + ..body = cb.Block.of([ + _basicMessageChannel( + channelName: makeChannelName(api, method, dartPackageName), + codec: !method.isStatic + ? cb.refer('_codec${api.name}') + : cb.refer( + '$codecName(\$instanceManager ?? \$InstanceManager.instance)', + ), + binaryMessenger: cb.refer(r'$binaryMessenger'), + ), + const cb.Code('final List? replyList ='), + cb + .refer('channel.send') + .call([ + cb.literalList( + [ + if (!method.isStatic) cb.refer('this'), + ...indexMap( + method.parameters, + (int index, NamedType parameter) => _referOrNull( + _getSafeArgumentName(index, parameter), + isNullable: parameter.type.isNullable, + )! + .propertyIf( + root.enums.map((Enum e) => e.name).contains( + parameter.type.baseName, + ), + 'index', + ), + ), + ], + cb.refer('Object?'), + ) + ]) + .awaited + .asA(cb.refer('List?')) + .statement, + const cb.Code('if (replyList == null) {'), + cb.InvokeExpression.newOf( + cb.refer('PlatformException'), + [], + { + 'code': cb.literalString('channel-error'), + 'message': cb.literalString( + 'Unable to establish connection on channel.', + ) + }).thrown.statement, + const cb.Code( + '} else if (replyList.length > 1) {', + ), + cb.InvokeExpression.newOf( + cb.refer('PlatformException'), + [], + { + 'code': cb + .refer('replyList') + .index(cb.literal(0)) + .nullChecked + .asA(cb.refer('String')), + 'message': cb + .refer('replyList') + .index(cb.literal(1)) + .asA(cb.refer('String?')), + 'details': cb.refer('replyList').index(cb.literal(2)), + }).thrown.statement, + // On iOS we can return nil from functions to accommodate error + // handling. Returning a nil value and not returning an error is an + // exception. + if (!method.returnType.isNullable && + !method.returnType.isVoid) ...[ + const cb.Code( + '} else if (replyList[0] == null) {', + ), + cb.InvokeExpression.newOf( + cb.refer('PlatformException'), + [], + { + 'code': cb.literalString('null-error'), + 'message': cb.literalString( + 'Host platform returned null value for non-null return value.', + ) + }).thrown.statement, + ], + const cb.Code('} else {'), + _unwrapReturnValue( + method.returnType, + customEnumNames: customEnumNames, + ).returned.statement, + const cb.Code('}'), + ]), + ), + cb.Method( + (cb.MethodBuilder builder) => builder + ..name = r'$copy' + ..returns = cb.refer(api.name) + ..annotations.add(cb.refer('override')) + ..body = cb.Block.of([ + cb + .refer('${api.name}.\$detached') + .call( + [], + { + r'$binaryMessenger': cb.refer(r'$binaryMessenger'), + r'$instanceManager': cb.refer(r'$instanceManager'), + for (final Field field in nonAttachedFields) + 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, + ]), + ), + ]), + ); + + final cb.DartEmitter emitter = cb.DartEmitter(useNullSafetySyntax: true); + indent.writeln(DartFormatter().format('${proxyApi.accept(emitter)}')); + } + /// 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 @@ -1077,6 +2174,169 @@ PlatformException _createConnectionError(String channelName) { } } +// TODO: this needs to be replaced with an addDocumentation like thing +Iterable _asDartComments(Iterable comments) sync* { + for (final String comment in comments) { + yield '///$comment'; + } +} + +// Adds support for conditional expressions. +extension on cb.Expression { + cb.Expression awaitedIf(bool condition) => condition ? awaited : this; + cb.Expression nullCheckedIf(bool condition) => condition ? nullChecked : this; + cb.Expression propertyIf(bool condition, String name) => + condition ? property(name) : this; +} + +cb.Expression _unwrapReturnValue( + TypeDeclaration returnType, { + required List customEnumNames, +}) { + final String type = _makeGenericTypeArguments(returnType); + final String genericCastCall = _makeGenericCastCall(returnType); + const String accessor = 'replyList[0]'; + final String nullablyTypedAccessor = + type == 'Object' ? accessor : '($accessor as $type?)'; + final String nullHandler = + returnType.isNullable ? (genericCastCall.isEmpty ? '' : '?') : '!'; + if (customEnumNames.contains(type)) { + if (returnType.isNullable) { + return cb.refer( + '($accessor as int?) == null ? null : $type.values[$accessor! as int]', + ); + } else { + return cb.refer( + '$type.values[$accessor! as int]', + ); + } + } else if (!returnType.isVoid) { + return cb.refer('$nullablyTypedAccessor$nullHandler$genericCastCall'); + } + return cb.refer(''); +} + +cb.Expression _wrapResultResponse(Root root, TypeDeclaration type) { + return cb + .refer('wrapResponse') + .call([], { + 'result': _referOrNull('output', isNullable: type.isNullable)!.propertyIf( + type.isEnum, + 'index', + ), + }); +} + +/// final = ([] as ); +Iterable _messageArg( + int index, + NamedType parameter, { + required List customEnumNames, + required String channelName, + String argsVariableName = 'args', +}) { + final String argType = _addGenericTypes(parameter.type); + final String argName = _getSafeArgumentName(index, parameter); + final String genericArgType = _makeGenericTypeArguments(parameter.type); + final String castCall = _makeGenericCastCall(parameter.type); + + late final cb.Expression assign; + if (customEnumNames.contains(parameter.type.baseName)) { + assign = cb + .refer( + '$argsVariableName[$index] == null ? null : $argType.values[$argsVariableName[$index]! as int]', + ) + .expression; + } else { + assign = cb + .refer( + '($argsVariableName[$index] as $genericArgType?)${castCall.isEmpty ? '' : '?$castCall'}', + ) + .expression; + } + + return [ + cb + .declareFinal(argName, type: cb.refer('$argType?')) + .assign(assign) + .statement, + if (!parameter.type.isNullable) + _assert( + condition: cb.refer(argName).notEqualTo(cb.literalNull), + message: cb.literalString( + 'Argument for $channelName was null, expected non-null $argType.', + raw: true, + ), + ), + ]; +} + +cb.Code _assert({ + required cb.Expression condition, + required cb.Expression message, +}) { + return cb.refer('assert').call([condition, message]).statement; +} + +cb.Code _basicMessageChannel({ + required String channelName, + cb.Expression codec = const cb.Reference('codec'), + cb.Expression? binaryMessenger = const cb.Reference('binaryMessenger'), +}) { + final cb.Reference basicMessageChannel = cb.refer( + 'BasicMessageChannel', + ); + return cb + .declareFinal('channel', type: basicMessageChannel) + .assign( + basicMessageChannel.newInstance( + [ + cb.literalString(channelName, raw: true), + codec, + ], + { + if (binaryMessenger != null) 'binaryMessenger': binaryMessenger, + }, + ), + ) + .statement; +} + +/// Converts enums to use their index. +/// +/// ```dart +/// apple, banana, myEnum${type.isNullable : '?' : ''}.index +/// ``` +cb.Expression _parameterArgument( + int index, + NamedType type, { + String Function(int index, NamedType type) getArgumentName = + _getSafeArgumentName, +}) { + final cb.Reference nameRef = cb.refer(getArgumentName(index, type)); + if (type.type.isEnum) { + if (type.type.isNullable) { + return nameRef.nullSafeProperty('index'); + } else { + return nameRef.property('index'); + } + } else { + return nameRef; + } +} + +cb.Reference? _referOrNull( + String? symbol, { + bool isFuture = false, + bool isNullable = false, +}) { + final String nullability = isNullable ? '?' : ''; + return symbol != null + ? cb.refer( + isFuture ? 'Future<$symbol$nullability>' : '$symbol$nullability') + : null; +} + String _escapeForDartSingleQuotedString(String raw) { return raw .replaceAll(r'\', r'\\') diff --git a/packages/pigeon/lib/functional.dart b/packages/pigeon/lib/functional.dart index 8e23950e9e70..017071187787 100644 --- a/packages/pigeon/lib/functional.dart +++ b/packages/pigeon/lib/functional.dart @@ -13,6 +13,22 @@ Iterable indexMap( } } +/// A [map] function that calls the function with an enumeration as well as the +/// value. +T indexFold( + Iterable iterable, + T initialValue, + T Function(T previousValue, int index, E element) combine, +) { + int index = 0; + T value = initialValue; + for (final E element in iterable) { + value = combine(value, index, element); + ++index; + } + return value; +} + /// Performs like [forEach] but invokes [func] with an enumeration. void enumerate(Iterable iterable, void Function(int, T) func) { int count = 0; diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index d007d8f0358f..52be855d9dbd 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -622,6 +622,52 @@ enum FileType { na, } +/// Recursively search for all the interfaces apis from a list of names of +/// interfaces. +Set recursiveFindAllInterfacesApis( + Set interfaces, + Iterable allProxyApis, +) { + final Set interfacesApis = {}; + + for (final AstProxyApi proxyApi in allProxyApis) { + if (interfaces.contains(proxyApi.name)) { + interfacesApis.add(proxyApi); + } + } + + for (final AstProxyApi proxyApi in Set.from(interfacesApis)) { + interfacesApis.addAll( + recursiveFindAllInterfacesApis(proxyApi.interfacesNames, allProxyApis), + ); + } + + return interfacesApis; +} + +/// Recursively find super classes for a ProxyApi and return them in order. +List recursiveGetSuperClassApisChain( + AstProxyApi proxyApi, + Iterable allProxyApis, +) { + final List proxyApis = []; + + String? currentProxyApiName = proxyApi.superClassName; + while (currentProxyApiName != null) { + AstProxyApi? nextProxyApi; + for (final AstProxyApi node in allProxyApis) { + if (currentProxyApiName == node.name) { + nextProxyApi = node; + proxyApis.add(node); + } + } + + currentProxyApiName = nextProxyApi?.superClassName; + } + + return proxyApis; +} + /// Options for [Generator]s that have multiple output file types. /// /// Specifies which file to write as well as wraps all language options. From 968715d66ab4462ebb763d8f8554a2428adf49f9 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Sun, 3 Dec 2023 20:10:06 -0500 Subject: [PATCH 06/73] fix comments --- packages/pigeon/lib/dart_generator.dart | 34 ++++++++++++++---------- packages/pigeon/lib/generator_tools.dart | 29 ++++++++++++++------ 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 491843f7ec61..2218b1f4986a 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -1066,14 +1066,18 @@ class $codecName extends StandardMessageCodec { else cb.refer(r'$Copyable') ]) - ..docs.addAll(_asDartComments(api.documentationComments)) + ..docs.addAll(asDocumentationComments( + api.documentationComments, + _docCommentSpec, + )) ..constructors.addAll( api.constructors.map( (Constructor constructor) => cb.Constructor( (cb.ConstructorBuilder builder) => builder ..name = constructor.name.isNotEmpty ? constructor.name : null - ..docs.addAll(_asDartComments( + ..docs.addAll(asDocumentationComments( constructor.documentationComments, + _docCommentSpec, )) ..optionalParameters.addAll( [ @@ -1705,14 +1709,18 @@ class $codecName extends StandardMessageCodec { ..name = field.name ..type = cb.refer(_addGenericTypesNullable(field.type)) ..modifier = cb.FieldModifier.final$ - ..docs.addAll(_asDartComments(field.documentationComments)), + ..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(_asDartComments(method.documentationComments)) + ..docs.addAll(asDocumentationComments( + method.documentationComments, _docCommentSpec)) ..type = cb.FunctionType( (cb.FunctionTypeBuilder builder) => builder ..returnType = _referOrNull( @@ -1740,7 +1748,8 @@ class $codecName extends StandardMessageCodec { ..name = method.name ..modifier = cb.FieldModifier.final$ ..annotations.add(cb.refer('override')) - ..docs.addAll(_asDartComments(method.documentationComments)) + ..docs.addAll(asDocumentationComments( + method.documentationComments, _docCommentSpec)) ..type = cb.FunctionType( (cb.FunctionTypeBuilder builder) => builder ..returnType = _referOrNull( @@ -1769,7 +1778,8 @@ class $codecName extends StandardMessageCodec { ..modifier = cb.FieldModifier.final$ ..static = field.isStatic ..late = !field.isStatic - ..docs.addAll(_asDartComments(field.documentationComments)) + ..docs.addAll(asDocumentationComments( + field.documentationComments, _docCommentSpec)) ..assignment = cb.Code('_${field.name}()'), ), ]) @@ -1886,7 +1896,10 @@ class $codecName extends StandardMessageCodec { ..name = method.name ..static = method.isStatic ..modifier = cb.MethodModifier.async - ..docs.addAll(_asDartComments(method.documentationComments)) + ..docs.addAll(asDocumentationComments( + method.documentationComments, + _docCommentSpec, + )) ..returns = _referOrNull( _addGenericTypesNullable(method.returnType), isFuture: true, @@ -2174,13 +2187,6 @@ PlatformException _createConnectionError(String channelName) { } } -// TODO: this needs to be replaced with an addDocumentation like thing -Iterable _asDartComments(Iterable comments) sync* { - for (final String comment in comments) { - yield '///$comment'; - } -} - // Adds support for conditional expressions. extension on cb.Expression { cb.Expression awaitedIf(bool condition) => condition ? awaited : this; diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 52be855d9dbd..c802450e6147 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -523,6 +523,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) '', @@ -531,24 +548,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 4628c706460d26a426eae4725c57f6de5e5fec69 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Sun, 3 Dec 2023 21:00:37 -0500 Subject: [PATCH 07/73] update constructors --- packages/pigeon/lib/dart_generator.dart | 1953 ++++++++++++----------- 1 file changed, 988 insertions(+), 965 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 2218b1f4986a..20beb1eae668 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -956,6 +956,7 @@ class _InstanceManagerApi { required String dartPackageName, }) { final String codecName = _getCodecName(api); + final String codecInstanceName = '_codec${api.name}'; // Write Codec indent.writeln(''' @@ -1056,1003 +1057,1026 @@ class $codecName extends StandardMessageCodec { final List customEnumNames = root.enums.map((Enum x) => x.name).toList(); - final cb.Class proxyApi = cb.Class( - (cb.ClassBuilder builder) => builder - ..name = api.name - ..extend = _referOrNull(superClassApi?.name) - ..implements.addAll([ - if (api.interfacesNames.isNotEmpty) - ...api.interfacesNames.map((String name) => cb.refer(name)) - else - cb.refer(r'$Copyable') - ]) - ..docs.addAll(asDocumentationComments( - api.documentationComments, - _docCommentSpec, - )) - ..constructors.addAll( - api.constructors.map( - (Constructor constructor) => cb.Constructor( - (cb.ConstructorBuilder builder) => builder - ..name = constructor.name.isNotEmpty ? constructor.name : null - ..docs.addAll(asDocumentationComments( - constructor.documentationComments, - _docCommentSpec, - )) - ..optionalParameters.addAll( - [ - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = r'$binaryMessenger' - ..named = true - ..toSuper = superClassApi != null - ..toThis = superClassApi == null, - ), - cb.Parameter((cb.ParameterBuilder builder) => builder - ..name = r'$instanceManager' - ..type = _referOrNull( - superClassApi == null ? r'$InstanceManager' : null, - isNullable: true, - ) + final cb.Class proxyApi = cb.Class((cb.ClassBuilder builder) => builder + ..name = api.name + ..extend = _referOrNull(superClassApi?.name) + ..implements.addAll([ + if (api.interfacesNames.isNotEmpty) + ...api.interfacesNames.map((String name) => cb.refer(name)) + else + cb.refer(r'$Copyable') + ]) + ..docs.addAll(asDocumentationComments( + api.documentationComments, + _docCommentSpec, + )) + ..constructors.addAll(_proxyApiConstructors( + api.constructors, + apiName: api.name, + dartPackageName: dartPackageName, + codecInstanceName: codecInstanceName, + superClassApi: superClassApi, + nonAttachedFields: nonAttachedFields, + superClassFlutterMethods: superClassFlutterMethods, + interfacesMethods: interfacesMethods, + flutterMethods: flutterMethods, + )) + // ..methods.add( + // cb.Method.returnsVoid( + // (cb.MethodBuilder builder) => builder + // ..name = r'$setUpMessageHandlers' + // ..returns = cb.refer('void') + // ..static = true + // ..optionalParameters.addAll([ + // cb.Parameter( + // (cb.ParameterBuilder builder) => builder + // ..name = r'$binaryMessenger' + // ..named = true + // ..type = cb.refer('BinaryMessenger?'), + // ), + // cb.Parameter( + // (cb.ParameterBuilder builder) => builder + // ..name = r'$instanceManager' + // ..named = true + // ..type = cb.refer(r'$InstanceManager?'), + // ), + // if (!hasARequiredFlutterMethod) + // cb.Parameter( + // (cb.ParameterBuilder builder) => builder + // ..name = r'$detached' + // ..named = true + // ..type = cb.FunctionType( + // (cb.FunctionTypeBuilder builder) => builder + // ..returnType = cb.refer(api.name) + // ..isNullable = true + // ..requiredParameters.addAll(indexMap( + // nonAttachedFields, + // (int index, Field 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 = _referOrNull( + // _addGenericTypesNullable(method.returnType), + // isFuture: method.isAsynchronous, + // ) + // ..isNullable = true + // ..requiredParameters.addAll([ + // cb.refer('${api.name} instance'), + // ...indexMap( + // method.parameters, + // (int index, NamedType parameter) { + // return cb.refer( + // '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', + // ); + // }, + // ) + // ]), + // ), + // ), + // ]) + // ..body = cb.Block.of([ + // cb.Code( + // 'final $codecName codec = $codecName(\$instanceManager ?? \$InstanceManager.instance);', + // ), + // if (!hasARequiredFlutterMethod) ...[ + // const cb.Code('{'), + // _basicMessageChannel( + // channelName: makeChannelNameWithStrings( + // apiName: api.name, + // methodName: r'$detached', + // dartPackageName: dartPackageName, + // ), + // binaryMessenger: cb.refer(r'$binaryMessenger'), + // ), + // cb.refer('channel').property('setMessageHandler').call( + // [ + // cb.Method( + // (cb.MethodBuilder builder) => builder + // ..modifier = cb.MethodModifier.async + // ..requiredParameters.add( + // cb.Parameter( + // (cb.ParameterBuilder builder) => builder + // ..name = 'message' + // ..type = cb.refer('Object?'), + // ), + // ) + // ..body = cb.Block((cb.BlockBuilder builder) { + // final String channelName = + // makeChannelNameWithStrings( + // apiName: api.name, + // methodName: r'$detached', + // dartPackageName: dartPackageName, + // ); + // builder.statements.addAll([ + // _assert( + // condition: cb + // .refer('message') + // .notEqualTo(cb.literalNull), + // message: cb.literalString( + // 'Argument for $channelName was null.', + // raw: true, + // ), + // ), + // const cb.Code( + // 'final List args = (message as List?)!;', + // ), + // const cb.Code( + // 'final int? instanceIdentifier = (args[0] as int?);', + // ), + // _assert( + // condition: cb + // .refer('instanceIdentifier') + // .notEqualTo(cb.literalNull), + // message: cb.literalString( + // 'Argument for $channelName was null, expected non-null int.', + // raw: true, + // ), + // ), + // ...indexFold, Field>( + // nonAttachedFields, + // [], + // (List list, int index, Field field) { + // return list + // ..addAll(_messageArg( + // index + 1, + // field, + // customEnumNames: customEnumNames, + // channelName: channelName, + // )); + // }, + // ), + // cb + // .refer( + // r'($instanceManager ?? $InstanceManager.instance)', + // ) + // .property('addHostCreatedInstance') + // .call([ + // cb + // .refer(r'$detached?.call') + // .call( + // indexMap( + // nonAttachedFields, + // (int index, Field field) { + // // The calling instance is the first arg. + // final String name = + // _getSafeArgumentName( + // index + 1, + // field, + // ); + // return field.type.isNullable + // ? cb.refer(name) + // : cb.refer(name).nullChecked; + // }, + // ), + // ) + // .ifNullThen( + // cb.refer('${api.name}.\$detached').call( + // [], + // { + // r'$binaryMessenger': + // cb.refer(r'$binaryMessenger'), + // r'$instanceManager': + // cb.refer(r'$instanceManager'), + // ...nonAttachedFields + // .toList() + // .asMap() + // .map( + // (int index, Field field) { + // final String argName = + // _getSafeArgumentName( + // index + 1, + // field, + // ); + // return MapEntry( + // field.name, + // field.type.isNullable + // ? cb.refer(argName) + // : cb + // .refer(argName) + // .nullChecked, + // ); + // }, + // ) + // }, + // ), + // ), + // cb.refer('instanceIdentifier').nullChecked + // ]).statement, + // const cb.Code('return;'), + // ]); + // }), + // ).genericClosure + // ], + // ).statement, + // const cb.Code('}'), + // ], + // ...flutterMethods.fold>( + // [], + // (List list, Method method) { + // final String channelName = makeChannelName( + // api, + // method, + // dartPackageName, + // ); + // final cb.Expression call = cb + // .refer( + // '(${method.name} ?? instance!.${method.name})${method.required ? '' : '?'}.call', + // ) + // .call( + // [ + // cb.refer('instance').nullChecked, + // ...indexMap( + // method.parameters, + // (int index, NamedType parameter) { + // final String name = _getSafeArgumentName( + // index + 1, + // parameter, + // ); + // return cb + // .refer(name) + // .nullCheckedIf(!parameter.type.isNullable); + // }, + // ), + // ], + // ); + // return list + // ..addAll([ + // const cb.Code('{'), + // _basicMessageChannel( + // channelName: channelName, + // binaryMessenger: cb.refer(r'$binaryMessenger'), + // ), + // cb.refer('channel').property('setMessageHandler').call( + // [ + // cb.Method( + // (cb.MethodBuilder builder) => builder + // ..modifier = cb.MethodModifier.async + // ..requiredParameters.add( + // cb.Parameter( + // (cb.ParameterBuilder builder) => builder + // ..name = 'message' + // ..type = cb.refer('Object?'), + // ), + // ) + // ..body = cb.Block((cb.BlockBuilder builder) { + // builder.statements.addAll([ + // _assert( + // condition: cb + // .refer('message') + // .notEqualTo(cb.literalNull), + // message: cb.literalString( + // 'Argument for $channelName was null.', + // raw: true, + // ), + // ), + // const cb.Code( + // 'final List args = (message as List?)!;', + // ), + // cb.Code( + // 'final ${api.name}? instance = (args[0] as ${api.name}?);', + // ), + // _assert( + // condition: cb + // .refer('instance') + // .notEqualTo(cb.literalNull), + // message: cb.literalString( + // 'Argument for $channelName was null, expected non-null ${api.name}.', + // raw: true, + // ), + // ), + // ...indexFold, NamedType>( + // method.parameters, + // [], + // ( + // List list, + // int index, + // NamedType type, + // ) { + // return list + // ..addAll(_messageArg( + // index + 1, + // type, + // customEnumNames: customEnumNames, + // channelName: channelName, + // )); + // }, + // ), + // const cb.Code('try {'), + // if (method.returnType.isVoid) ...[ + // if (method.isAsynchronous) + // call.awaited.statement + // else + // call.statement, + // const cb.Code( + // 'return wrapResponse(empty: true);', + // ), + // ] else ...[ + // cb + // .declareFinal( + // 'output', + // type: cb.refer( + // _addGenericTypesNullable( + // method.returnType, + // ), + // ), + // ) + // .assign( + // call.awaitedIf( + // method.isAsynchronous, + // ), + // ) + // .statement, + // _wrapResultResponse( + // root, method.returnType) + // .returned + // .statement, + // ], + // const cb.Code( + // '} on PlatformException catch (e) {', + // ), + // const cb.Code( + // 'return wrapResponse(error: e);', + // ), + // const cb.Code('} catch (e) {'), + // const cb.Code( + // "return wrapResponse(error: PlatformException(code: 'error', message: e.toString()),);", + // ), + // const cb.Code('}') + // ]); + // }), + // ).genericClosure + // ], + // ).statement, + // const cb.Code('}'), + // ]); + // }, + // ), + // ]), + // ), + // ) + // ..fields.addAll([ + // if (hostMethods.isNotEmpty || + // api.constructors.isNotEmpty || + // attachedFields.where((Field field) => !field.isStatic).isNotEmpty) + // cb.Field( + // (cb.FieldBuilder builder) => builder + // ..name = '_codec${api.name}' + // ..type = cb.refer(codecName) + // ..late = true + // ..modifier = cb.FieldModifier.final$ + // ..assignment = cb.Code('$codecName(\$instanceManager)'), + // ), + // if (superClassApi == null) ...[ + // cb.Field( + // (cb.FieldBuilder builder) => builder + // ..name = r'$binaryMessenger' + // ..type = cb.refer('BinaryMessenger?') + // ..modifier = cb.FieldModifier.final$ + // ..docs.addAll([ + // '/// 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.', + // ]) + // ..annotations.addAll([ + // if (superClassApi == null && interfacesApis.isNotEmpty) + // cb.refer('override'), + // ]), + // ), + // cb.Field( + // (cb.FieldBuilder builder) => builder + // ..name = r'$instanceManager' + // ..type = cb.refer(r'$InstanceManager') + // ..modifier = cb.FieldModifier.final$ + // ..docs.add( + // '/// Maintains instances stored to communicate with native language objects.', + // ) + // ..annotations.addAll([ + // if (superClassApi == null && interfacesApis.isNotEmpty) + // cb.refer('override'), + // ]), + // ), + // ], + // for (final Field field in nonAttachedFields) + // 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, _docCommentSpec)) + // ..type = cb.FunctionType( + // (cb.FunctionTypeBuilder builder) => builder + // ..returnType = _referOrNull( + // _addGenericTypesNullable(method.returnType), + // isFuture: method.isAsynchronous, + // ) + // ..isNullable = !method.required + // ..requiredParameters.addAll([ + // cb.refer('${api.name} instance'), + // ...indexMap( + // method.parameters, + // (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 = _referOrNull( + // _addGenericTypesNullable(method.returnType), + // isFuture: method.isAsynchronous, + // ) + // ..isNullable = !method.required + // ..requiredParameters.addAll([ + // cb.refer('${proxyApi.name} instance'), + // ...indexMap( + // method.parameters, + // (int index, NamedType parameter) { + // return cb.refer( + // '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', + // ); + // }, + // ), + // ]), + // ), + // ), + // for (final Field 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('_${field.name}()'), + // ), + // ]) + // ..methods.addAll([ + // for (final Field field in attachedFields) + // cb.Method( + // (cb.MethodBuilder builder) { + // final String type = _addGenericTypesNullable(field.type); + // final String channelName = makeChannelNameWithStrings( + // apiName: api.name, + // methodName: field.name, + // dartPackageName: dartPackageName, + // ); + // builder + // ..name = '_${field.name}' + // ..static = field.isStatic + // ..returns = cb.refer(type) + // ..body = cb.Block.of( + // [ + // cb.Code('final $type instance = $type.\$detached('), + // if (!field.isStatic) ...[ + // const cb.Code(r'$binaryMessenger: $binaryMessenger,'), + // const cb.Code(r'$instanceManager: $instanceManager,'), + // ], + // const cb.Code(');'), + // _basicMessageChannel( + // channelName: channelName, + // codec: !field.isStatic + // ? cb.refer('_codec${api.name}') + // : cb.refer( + // '$codecName(\$InstanceManager.instance)', + // ), + // binaryMessenger: !field.isStatic + // ? cb.refer(r'$binaryMessenger') + // : null, + // ), + // cb.Code( + // 'final int instanceIdentifier = ${field.isStatic ? r'$InstanceManager.instance' : r'$instanceManager'}.addDartCreatedInstance(instance);', + // ), + // cb + // .refer('channel.send') + // .call([ + // cb.literalList( + // [ + // if (!field.isStatic) cb.refer('this'), + // cb.refer('instanceIdentifier') + // ], + // cb.refer('Object?'), + // ) + // ]) + // .property('then') + // .call( + // [ + // cb.Method( + // (cb.MethodBuilder builder) => builder + // ..requiredParameters.add( + // cb.Parameter( + // (cb.ParameterBuilder builder) => builder + // ..name = 'value' + // ..type = cb.refer('Object?'), + // ), + // ) + // ..body = cb.Block.of([ + // const cb.Code( + // 'final List? replyList = value as List?;', + // ), + // const cb.Code('if (replyList == null) {'), + // cb.InvokeExpression.newOf( + // cb.refer('PlatformException'), + // [], + // { + // 'code': + // cb.literalString('channel-error'), + // 'message': cb.literalString( + // 'Unable to establish connection on channel.', + // ) + // }).thrown.statement, + // const cb.Code( + // '} else if (replyList.length > 1) {', + // ), + // cb.InvokeExpression.newOf( + // cb.refer('PlatformException'), + // [], + // { + // 'code': cb + // .refer('replyList') + // .index(cb.literal(0)) + // .nullChecked + // .asA(cb.refer('String')), + // 'message': cb + // .refer('replyList') + // .index(cb.literal(1)) + // .asA(cb.refer('String?')), + // 'details': cb + // .refer('replyList') + // .index(cb.literal(2)), + // }).thrown.statement, + // const cb.Code('}'), + // ]), + // ).genericClosure, + // ], + // {}, + // [cb.refer('void')], + // ) + // .statement, + // const cb.Code('return instance;'), + // ], + // ); + // }, + // ), + // 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 = _referOrNull( + // _addGenericTypesNullable(method.returnType), + // isFuture: true, + // ) + // ..requiredParameters.addAll(indexMap( + // method.parameters, + // (int index, NamedType parameter) => cb.Parameter( + // (cb.ParameterBuilder builder) => builder + // ..name = _getSafeArgumentName(index, parameter) + // ..type = cb.refer( + // _addGenericTypesNullable(parameter.type), + // ), + // ), + // )) + // ..optionalParameters.addAll([ + // if (method.isStatic) ...[ + // cb.Parameter( + // (cb.ParameterBuilder builder) => builder + // ..name = r'$binaryMessenger' + // ..type = cb.refer('BinaryMessenger?') + // ..named = true, + // ), + // cb.Parameter( + // (cb.ParameterBuilder builder) => builder + // ..name = r'$instanceManager' + // ..type = cb.refer(r'$InstanceManager?'), + // ), + // ], + // ]) + // ..body = cb.Block.of([ + // _basicMessageChannel( + // channelName: makeChannelName(api, method, dartPackageName), + // codec: !method.isStatic + // ? cb.refer('_codec${api.name}') + // : cb.refer( + // '$codecName(\$instanceManager ?? \$InstanceManager.instance)', + // ), + // binaryMessenger: cb.refer(r'$binaryMessenger'), + // ), + // const cb.Code('final List? replyList ='), + // cb + // .refer('channel.send') + // .call([ + // cb.literalList( + // [ + // if (!method.isStatic) cb.refer('this'), + // ...indexMap( + // method.parameters, + // (int index, NamedType parameter) => _referOrNull( + // _getSafeArgumentName(index, parameter), + // isNullable: parameter.type.isNullable, + // )! + // .propertyIf( + // root.enums.map((Enum e) => e.name).contains( + // parameter.type.baseName, + // ), + // 'index', + // ), + // ), + // ], + // cb.refer('Object?'), + // ) + // ]) + // .awaited + // .asA(cb.refer('List?')) + // .statement, + // const cb.Code('if (replyList == null) {'), + // cb.InvokeExpression.newOf( + // cb.refer('PlatformException'), + // [], + // { + // 'code': cb.literalString('channel-error'), + // 'message': cb.literalString( + // 'Unable to establish connection on channel.', + // ) + // }).thrown.statement, + // const cb.Code( + // '} else if (replyList.length > 1) {', + // ), + // cb.InvokeExpression.newOf( + // cb.refer('PlatformException'), + // [], + // { + // 'code': cb + // .refer('replyList') + // .index(cb.literal(0)) + // .nullChecked + // .asA(cb.refer('String')), + // 'message': cb + // .refer('replyList') + // .index(cb.literal(1)) + // .asA(cb.refer('String?')), + // 'details': cb.refer('replyList').index(cb.literal(2)), + // }).thrown.statement, + // // On iOS we can return nil from functions to accommodate error + // // handling. Returning a nil value and not returning an error is an + // // exception. + // if (!method.returnType.isNullable && + // !method.returnType.isVoid) ...[ + // const cb.Code( + // '} else if (replyList[0] == null) {', + // ), + // cb.InvokeExpression.newOf( + // cb.refer('PlatformException'), + // [], + // { + // 'code': cb.literalString('null-error'), + // 'message': cb.literalString( + // 'Host platform returned null value for non-null return value.', + // ) + // }).thrown.statement, + // ], + // const cb.Code('} else {'), + // _unwrapReturnValue( + // method.returnType, + // customEnumNames: customEnumNames, + // ).returned.statement, + // const cb.Code('}'), + // ]), + // ), + // cb.Method( + // (cb.MethodBuilder builder) => builder + // ..name = r'$copy' + // ..returns = cb.refer(api.name) + // ..annotations.add(cb.refer('override')) + // ..body = cb.Block.of([ + // cb + // .refer('${api.name}.\$detached') + // .call( + // [], + // { + // r'$binaryMessenger': cb.refer(r'$binaryMessenger'), + // r'$instanceManager': cb.refer(r'$instanceManager'), + // for (final Field field in nonAttachedFields) + // 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, + // ]), + // ), + // ]), + ); + + final cb.DartEmitter emitter = cb.DartEmitter(useNullSafetySyntax: true); + indent.writeln(DartFormatter().format('${proxyApi.accept(emitter)}')); + } + + Iterable _proxyApiConstructors( + Iterable constructors, { + required String apiName, + required String dartPackageName, + required String codecInstanceName, + required AstProxyApi? superClassApi, + required Iterable nonAttachedFields, + required Iterable superClassFlutterMethods, + required Iterable interfacesMethods, + required Iterable flutterMethods, + }) { + return [ + ...constructors.map( + (Constructor constructor) => cb.Constructor( + (cb.ConstructorBuilder builder) { + final String channelName = makeChannelNameWithStrings( + apiName: apiName, + methodName: constructor.name.isNotEmpty + ? constructor.name + : r'$defaultConstructor', + dartPackageName: dartPackageName, + ); + builder + ..name = constructor.name.isNotEmpty ? constructor.name : null + ..docs.addAll(asDocumentationComments( + constructor.documentationComments, + _docCommentSpec, + )) + ..optionalParameters.addAll( + [ + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = r'$binaryMessenger' ..named = true - ..toSuper = superClassApi != null), - for (final Field field in nonAttachedFields) - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = field.name - ..named = true - ..toThis = true - ..required = !field.type.isNullable, - ), - for (final Method method in superClassFlutterMethods) - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = method.name - ..named = true - ..toSuper = true - ..required = method.required, - ), - for (final Method method in interfacesMethods) - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = method.name - ..named = true - ..toThis = true - ..required = method.required, - ), - for (final Method method in flutterMethods) - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = method.name - ..named = true - ..toThis = true - ..required = method.required, - ), - ...indexMap( - constructor.parameters, - (int index, NamedType parameter) => cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = _getSafeArgumentName(index, parameter) - ..type = cb.refer( - _addGenericTypesNullable(parameter.type), - ) - ..named = true - ..required = !parameter.type.isNullable, - ), - ), - ], - ) - ..initializers.add( - cb.Code( - superClassApi != null - ? r'super.$detached()' - : r'$instanceManager = $instanceManager ?? $InstanceManager.instance', - ), - ) - ..body = cb.Block.of([ - _basicMessageChannel( - channelName: makeChannelNameWithStrings( - apiName: api.name, - methodName: constructor.name.isNotEmpty - ? constructor.name - : r'$defaultConstructor', - dartPackageName: dartPackageName, - ), - codec: cb.refer('_codec${api.name}'), - binaryMessenger: cb.refer(r'$binaryMessenger'), - ), - cb.Code( - 'final int instanceIdentifier = ${superClassApi != null ? '' : 'this.'}\$instanceManager.addDartCreatedInstance(this);', + ..toSuper = superClassApi != null + ..toThis = superClassApi == null, ), - cb - .refer('channel') - .property('send') - .call([ - cb.literalList( - [ - cb.refer('instanceIdentifier'), - ...indexMap( - nonAttachedFields, - (int index, Field field) => _parameterArgument( - index, field, - getArgumentName: _getParameterName), - ), - ...indexMap( - constructor.parameters, - (int index, NamedType type) => _parameterArgument( - index, - type, - ), - ), - ], - cb.refer('Object?'), - ) - ]) - .property('then') - .call( - [ - cb.Method( - (cb.MethodBuilder builder) => builder - ..requiredParameters.add( - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = 'value' - ..type = cb.refer('Object?'), - ), - ) - ..body = cb.Block.of([ - const cb.Code( - 'final List? replyList = value as List?;', - ), - const cb.Code('if (replyList == null) {'), - cb.InvokeExpression.newOf( - cb.refer('PlatformException'), - [], - { - 'code': cb.literalString('channel-error'), - 'message': cb.literalString( - 'Unable to establish connection on channel.', - ) - }).thrown.statement, - const cb.Code( - '} else if (replyList.length > 1) {', - ), - cb.InvokeExpression.newOf( - cb.refer('PlatformException'), - [], - { - 'code': cb - .refer('replyList') - .index(cb.literal(0)) - .nullChecked - .asA(cb.refer('String')), - 'message': cb - .refer('replyList') - .index(cb.literal(1)) - .asA(cb.refer('String?')), - 'details': cb - .refer('replyList') - .index(cb.literal(2)), - }).thrown.statement, - const cb.Code('}'), - ]), - ).genericClosure - ], - {}, - [cb.refer('void')], - ) - .statement - ]), - ), - ), - ) - ..constructors.add( - cb.Constructor( - (cb.ConstructorBuilder builder) => builder - ..name = r'$detached' - ..docs.addAll([ - '/// Constructs ${api.name} without creating the associated native object.', - '///', - '/// This should only be used by subclasses created by this library or to', - '/// create copies.', - ]) - ..optionalParameters.addAll([ - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = r'$binaryMessenger' - ..named = true - ..toSuper = superClassApi != null - ..toThis = superClassApi == null, - ), - cb.Parameter( - (cb.ParameterBuilder builder) => builder + cb.Parameter((cb.ParameterBuilder builder) => builder ..name = r'$instanceManager' ..type = _referOrNull( superClassApi == null ? r'$InstanceManager' : null, isNullable: true, ) ..named = true - ..toSuper = superClassApi != null, - ), - for (final Field field in nonAttachedFields) - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = field.name - ..named = true - ..toThis = true - ..required = !field.type.isNullable, - ), - for (final Method method in superClassFlutterMethods) - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = method.name - ..named = true - ..toSuper = true - ..required = method.required, - ), - for (final Method method in interfacesMethods) - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = method.name - ..named = true - ..toThis = true - ..required = method.required, - ), - for (final Method method in flutterMethods) - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = method.name - ..named = true - ..toThis = true - ..required = method.required, + ..toSuper = superClassApi != null), + for (final Field field in nonAttachedFields) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = field.name + ..named = true + ..toThis = true + ..required = !field.type.isNullable, + ), + for (final Method method in superClassFlutterMethods) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = method.name + ..named = true + ..toSuper = true + ..required = method.required, + ), + for (final Method method in interfacesMethods) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = method.name + ..named = true + ..toThis = true + ..required = method.required, + ), + for (final Method method in flutterMethods) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = method.name + ..named = true + ..toThis = true + ..required = method.required, + ), + ...indexMap( + constructor.parameters, + (int index, NamedType parameter) => cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = _getParameterName(index, parameter) + ..type = cb.refer( + _addGenericTypesNullable(parameter.type), + ) + ..named = true + ..required = !parameter.type.isNullable, + ), ), - ]) + ], + ) ..initializers.add( cb.Code( superClassApi != null ? r'super.$detached()' : r'$instanceManager = $instanceManager ?? $InstanceManager.instance', ), - ), - ), - ) - ..methods.add( - cb.Method.returnsVoid( - (cb.MethodBuilder builder) => builder - ..name = r'$setUpMessageHandlers' - ..returns = cb.refer('void') - ..static = true - ..optionalParameters.addAll([ - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = r'$binaryMessenger' - ..named = true - ..type = cb.refer('BinaryMessenger?'), - ), - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = r'$instanceManager' - ..named = true - ..type = cb.refer(r'$InstanceManager?'), - ), - if (!hasARequiredFlutterMethod) - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = r'$detached' - ..named = true - ..type = cb.FunctionType( - (cb.FunctionTypeBuilder builder) => builder - ..returnType = cb.refer(api.name) - ..isNullable = true - ..requiredParameters.addAll(indexMap( - nonAttachedFields, - (int index, Field 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 = _referOrNull( - _addGenericTypesNullable(method.returnType), - isFuture: method.isAsynchronous, - ) - ..isNullable = true - ..requiredParameters.addAll([ - cb.refer('${api.name} instance'), - ...indexMap( - method.parameters, - (int index, NamedType parameter) { - return cb.refer( - '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', - ); - }, - ) - ]), - ), - ), - ]) + ) ..body = cb.Block.of([ cb.Code( - 'final $codecName codec = $codecName(\$instanceManager ?? \$InstanceManager.instance);', + "final String ${_varNamePrefix}channelName = r'$channelName';", ), - if (!hasARequiredFlutterMethod) ...[ - const cb.Code('{'), - _basicMessageChannel( - channelName: makeChannelNameWithStrings( - apiName: api.name, - methodName: r'$detached', - dartPackageName: dartPackageName, - ), - binaryMessenger: cb.refer(r'$binaryMessenger'), - ), - cb.refer('channel').property('setMessageHandler').call( - [ - cb.Method( - (cb.MethodBuilder builder) => builder - ..modifier = cb.MethodModifier.async - ..requiredParameters.add( - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = 'message' - ..type = cb.refer('Object?'), + _basicMessageChannel( + codec: cb.refer(codecInstanceName), + binaryMessenger: cb.refer(r'$binaryMessenger'), + ), + cb + .refer('${_varNamePrefix}channel.send') + .call([ + cb.literalList( + [ + cb.refer( + '${superClassApi != null ? '' : 'this.'}\$instanceManager.addDartCreatedInstance(this)', + ), + ...indexMap( + nonAttachedFields, + (int index, Field field) => _hostMessageArgument( + index, + field, + getArgumentName: _getParameterName, + ), + ), + ...indexMap( + constructor.parameters, + (int index, NamedType type) => _hostMessageArgument( + index, + type, + getArgumentName: _getParameterName, ), - ) - ..body = cb.Block((cb.BlockBuilder builder) { - final String channelName = - makeChannelNameWithStrings( - apiName: api.name, - methodName: r'$detached', - dartPackageName: dartPackageName, - ); - builder.statements.addAll([ - _assert( - condition: cb - .refer('message') - .notEqualTo(cb.literalNull), - message: cb.literalString( - 'Argument for $channelName was null.', - raw: true, - ), + ), + ], + cb.refer('Object?'), + ) + ]) + .property('then') + .call( + [ + cb.Method( + (cb.MethodBuilder builder) => builder + ..requiredParameters.add( + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = 'value' + ..type = cb.refer('Object?'), ), + ) + ..body = cb.Block.of([ const cb.Code( - 'final List args = (message as List?)!;', + 'final List? ${_varNamePrefix}replyList = value as List?;', ), const cb.Code( - 'final int? instanceIdentifier = (args[0] as int?);', + 'if (${_varNamePrefix}replyList == null) {', ), - _assert( - condition: cb - .refer('instanceIdentifier') - .notEqualTo(cb.literalNull), - message: cb.literalString( - 'Argument for $channelName was null, expected non-null int.', - raw: true, - ), + const cb.Code( + 'throw _createConnectionError(${_varNamePrefix}channelName);', ), - ...indexFold, Field>( - nonAttachedFields, - [], - (List list, int index, Field field) { - return list - ..addAll(_messageArg( - index + 1, - field, - customEnumNames: customEnumNames, - channelName: channelName, - )); - }, + const cb.Code( + '} else if (${_varNamePrefix}replyList.length > 1) {', ), - cb - .refer( - r'($instanceManager ?? $InstanceManager.instance)', - ) - .property('addHostCreatedInstance') - .call([ - cb - .refer(r'$detached?.call') - .call( - indexMap( - nonAttachedFields, - (int index, Field field) { - // The calling instance is the first arg. - final String name = - _getSafeArgumentName( - index + 1, - field, - ); - return field.type.isNullable - ? cb.refer(name) - : cb.refer(name).nullChecked; - }, - ), - ) - .ifNullThen( - cb.refer('${api.name}.\$detached').call( - [], - { - r'$binaryMessenger': - cb.refer(r'$binaryMessenger'), - r'$instanceManager': - cb.refer(r'$instanceManager'), - ...nonAttachedFields - .toList() - .asMap() - .map( - (int index, Field field) { - final String argName = - _getSafeArgumentName( - index + 1, - field, - ); - return MapEntry( - field.name, - field.type.isNullable - ? cb.refer(argName) - : cb - .refer(argName) - .nullChecked, - ); - }, - ) - }, - ), - ), - cb.refer('instanceIdentifier').nullChecked - ]).statement, - const cb.Code('return;'), - ]); - }), - ).genericClosure - ], - ).statement, - const cb.Code('}'), - ], - ...flutterMethods.fold>( - [], - (List list, Method method) { - final String channelName = makeChannelName( - api, - method, - dartPackageName, - ); - final cb.Expression call = cb - .refer( - '(${method.name} ?? instance!.${method.name})${method.required ? '' : '?'}.call', - ) - .call( - [ - cb.refer('instance').nullChecked, - ...indexMap( - method.parameters, - (int index, NamedType parameter) { - final String name = _getSafeArgumentName( - index + 1, - parameter, - ); - return cb - .refer(name) - .nullCheckedIf(!parameter.type.isNullable); - }, - ), + cb.InvokeExpression.newOf( + cb.refer('PlatformException'), + [], + { + 'code': cb + .refer('${_varNamePrefix}replyList') + .index(cb.literal(0)) + .nullChecked + .asA(cb.refer('String')), + 'message': cb + .refer('${_varNamePrefix}replyList') + .index(cb.literal(1)) + .asA(cb.refer('String?')), + 'details': cb + .refer('${_varNamePrefix}replyList') + .index(cb.literal(2)), + }).thrown.statement, + const cb.Code('}'), + ]), + ).genericClosure ], - ); - return list - ..addAll([ - const cb.Code('{'), - _basicMessageChannel( - channelName: channelName, - binaryMessenger: cb.refer(r'$binaryMessenger'), - ), - cb.refer('channel').property('setMessageHandler').call( - [ - cb.Method( - (cb.MethodBuilder builder) => builder - ..modifier = cb.MethodModifier.async - ..requiredParameters.add( - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = 'message' - ..type = cb.refer('Object?'), - ), - ) - ..body = cb.Block((cb.BlockBuilder builder) { - builder.statements.addAll([ - _assert( - condition: cb - .refer('message') - .notEqualTo(cb.literalNull), - message: cb.literalString( - 'Argument for $channelName was null.', - raw: true, - ), - ), - const cb.Code( - 'final List args = (message as List?)!;', - ), - cb.Code( - 'final ${api.name}? instance = (args[0] as ${api.name}?);', - ), - _assert( - condition: cb - .refer('instance') - .notEqualTo(cb.literalNull), - message: cb.literalString( - 'Argument for $channelName was null, expected non-null ${api.name}.', - raw: true, - ), - ), - ...indexFold, NamedType>( - method.parameters, - [], - ( - List list, - int index, - NamedType type, - ) { - return list - ..addAll(_messageArg( - index + 1, - type, - customEnumNames: customEnumNames, - channelName: channelName, - )); - }, - ), - const cb.Code('try {'), - if (method.returnType.isVoid) ...[ - if (method.isAsynchronous) - call.awaited.statement - else - call.statement, - const cb.Code( - 'return wrapResponse(empty: true);', - ), - ] else ...[ - cb - .declareFinal( - 'output', - type: cb.refer( - _addGenericTypesNullable( - method.returnType, - ), - ), - ) - .assign( - call.awaitedIf( - method.isAsynchronous, - ), - ) - .statement, - _wrapResultResponse( - root, method.returnType) - .returned - .statement, - ], - const cb.Code( - '} on PlatformException catch (e) {', - ), - const cb.Code( - 'return wrapResponse(error: e);', - ), - const cb.Code('} catch (e) {'), - const cb.Code( - "return wrapResponse(error: PlatformException(code: 'error', message: e.toString()),);", - ), - const cb.Code('}') - ]); - }), - ).genericClosure - ], - ).statement, - const cb.Code('}'), - ]); - }, - ), - ]), - ), - ) - ..fields.addAll([ - if (hostMethods.isNotEmpty || - api.constructors.isNotEmpty || - attachedFields.where((Field field) => !field.isStatic).isNotEmpty) - cb.Field( - (cb.FieldBuilder builder) => builder - ..name = '_codec${api.name}' - ..type = cb.refer(codecName) - ..late = true - ..modifier = cb.FieldModifier.final$ - ..assignment = cb.Code('$codecName(\$instanceManager)'), - ), - if (superClassApi == null) ...[ - cb.Field( - (cb.FieldBuilder builder) => builder + {}, + [cb.refer('void')], + ) + .statement + ]); + }, + ), + ), + cb.Constructor( + (cb.ConstructorBuilder builder) => builder + ..name = r'$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.', + ]) + ..optionalParameters.addAll([ + cb.Parameter( + (cb.ParameterBuilder builder) => builder ..name = r'$binaryMessenger' - ..type = cb.refer('BinaryMessenger?') - ..modifier = cb.FieldModifier.final$ - ..docs.addAll([ - '/// 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.', - ]) - ..annotations.addAll([ - if (superClassApi == null && interfacesApis.isNotEmpty) - cb.refer('override'), - ]), + ..named = true + ..toSuper = superClassApi != null + ..toThis = superClassApi == null, ), - cb.Field( - (cb.FieldBuilder builder) => builder + cb.Parameter( + (cb.ParameterBuilder builder) => builder ..name = r'$instanceManager' - ..type = cb.refer(r'$InstanceManager') - ..modifier = cb.FieldModifier.final$ - ..docs.add( - '/// Maintains instances stored to communicate with native language objects.', + ..type = _referOrNull( + superClassApi == null ? r'$InstanceManager' : null, + isNullable: true, ) - ..annotations.addAll([ - if (superClassApi == null && interfacesApis.isNotEmpty) - cb.refer('override'), - ]), - ), - ], - for (final Field field in nonAttachedFields) - 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, _docCommentSpec)) - ..type = cb.FunctionType( - (cb.FunctionTypeBuilder builder) => builder - ..returnType = _referOrNull( - _addGenericTypesNullable(method.returnType), - isFuture: method.isAsynchronous, - ) - ..isNullable = !method.required - ..requiredParameters.addAll([ - cb.refer('${api.name} instance'), - ...indexMap( - method.parameters, - (int index, NamedType parameter) { - return cb.refer( - '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', - ); - }, - ), - ]), - ), + ..named = true + ..toSuper = superClassApi != null, ), - for (final AstProxyApi proxyApi in interfacesApis) - for (final Method method in proxyApi.methods) - cb.Field( - (cb.FieldBuilder builder) => builder + for (final Field field in nonAttachedFields) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = field.name + ..named = true + ..toThis = true + ..required = !field.type.isNullable, + ), + for (final Method method in superClassFlutterMethods) + cb.Parameter( + (cb.ParameterBuilder 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 = _referOrNull( - _addGenericTypesNullable(method.returnType), - isFuture: method.isAsynchronous, - ) - ..isNullable = !method.required - ..requiredParameters.addAll([ - cb.refer('${proxyApi.name} instance'), - ...indexMap( - method.parameters, - (int index, NamedType parameter) { - return cb.refer( - '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', - ); - }, - ), - ]), - ), + ..named = true + ..toSuper = true + ..required = method.required, ), - for (final Field 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('_${field.name}()'), - ), - ]) - ..methods.addAll([ - for (final Field field in attachedFields) - cb.Method( - (cb.MethodBuilder builder) { - final String type = _addGenericTypesNullable(field.type); - final String channelName = makeChannelNameWithStrings( - apiName: api.name, - methodName: field.name, - dartPackageName: dartPackageName, - ); - builder - ..name = '_${field.name}' - ..static = field.isStatic - ..returns = cb.refer(type) - ..body = cb.Block.of( - [ - cb.Code('final $type instance = $type.\$detached('), - if (!field.isStatic) ...[ - const cb.Code(r'$binaryMessenger: $binaryMessenger,'), - const cb.Code(r'$instanceManager: $instanceManager,'), - ], - const cb.Code(');'), - _basicMessageChannel( - channelName: channelName, - codec: !field.isStatic - ? cb.refer('_codec${api.name}') - : cb.refer( - '$codecName(\$InstanceManager.instance)', - ), - binaryMessenger: !field.isStatic - ? cb.refer(r'$binaryMessenger') - : null, - ), - cb.Code( - 'final int instanceIdentifier = ${field.isStatic ? r'$InstanceManager.instance' : r'$instanceManager'}.addDartCreatedInstance(instance);', - ), - cb - .refer('channel.send') - .call([ - cb.literalList( - [ - if (!field.isStatic) cb.refer('this'), - cb.refer('instanceIdentifier') - ], - cb.refer('Object?'), - ) - ]) - .property('then') - .call( - [ - cb.Method( - (cb.MethodBuilder builder) => builder - ..requiredParameters.add( - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = 'value' - ..type = cb.refer('Object?'), - ), - ) - ..body = cb.Block.of([ - const cb.Code( - 'final List? replyList = value as List?;', - ), - const cb.Code('if (replyList == null) {'), - cb.InvokeExpression.newOf( - cb.refer('PlatformException'), - [], - { - 'code': - cb.literalString('channel-error'), - 'message': cb.literalString( - 'Unable to establish connection on channel.', - ) - }).thrown.statement, - const cb.Code( - '} else if (replyList.length > 1) {', - ), - cb.InvokeExpression.newOf( - cb.refer('PlatformException'), - [], - { - 'code': cb - .refer('replyList') - .index(cb.literal(0)) - .nullChecked - .asA(cb.refer('String')), - 'message': cb - .refer('replyList') - .index(cb.literal(1)) - .asA(cb.refer('String?')), - 'details': cb - .refer('replyList') - .index(cb.literal(2)), - }).thrown.statement, - const cb.Code('}'), - ]), - ).genericClosure, - ], - {}, - [cb.refer('void')], - ) - .statement, - const cb.Code('return instance;'), - ], - ); - }, - ), - 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 = _referOrNull( - _addGenericTypesNullable(method.returnType), - isFuture: true, - ) - ..requiredParameters.addAll(indexMap( - method.parameters, - (int index, NamedType parameter) => cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = _getSafeArgumentName(index, parameter) - ..type = cb.refer( - _addGenericTypesNullable(parameter.type), - ), - ), - )) - ..optionalParameters.addAll([ - if (method.isStatic) ...[ - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = r'$binaryMessenger' - ..type = cb.refer('BinaryMessenger?') - ..named = true, - ), - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = r'$instanceManager' - ..type = cb.refer(r'$InstanceManager?'), - ), - ], - ]) - ..body = cb.Block.of([ - _basicMessageChannel( - channelName: makeChannelName(api, method, dartPackageName), - codec: !method.isStatic - ? cb.refer('_codec${api.name}') - : cb.refer( - '$codecName(\$instanceManager ?? \$InstanceManager.instance)', - ), - binaryMessenger: cb.refer(r'$binaryMessenger'), - ), - const cb.Code('final List? replyList ='), - cb - .refer('channel.send') - .call([ - cb.literalList( - [ - if (!method.isStatic) cb.refer('this'), - ...indexMap( - method.parameters, - (int index, NamedType parameter) => _referOrNull( - _getSafeArgumentName(index, parameter), - isNullable: parameter.type.isNullable, - )! - .propertyIf( - root.enums.map((Enum e) => e.name).contains( - parameter.type.baseName, - ), - 'index', - ), - ), - ], - cb.refer('Object?'), - ) - ]) - .awaited - .asA(cb.refer('List?')) - .statement, - const cb.Code('if (replyList == null) {'), - cb.InvokeExpression.newOf( - cb.refer('PlatformException'), - [], - { - 'code': cb.literalString('channel-error'), - 'message': cb.literalString( - 'Unable to establish connection on channel.', - ) - }).thrown.statement, - const cb.Code( - '} else if (replyList.length > 1) {', - ), - cb.InvokeExpression.newOf( - cb.refer('PlatformException'), - [], - { - 'code': cb - .refer('replyList') - .index(cb.literal(0)) - .nullChecked - .asA(cb.refer('String')), - 'message': cb - .refer('replyList') - .index(cb.literal(1)) - .asA(cb.refer('String?')), - 'details': cb.refer('replyList').index(cb.literal(2)), - }).thrown.statement, - // On iOS we can return nil from functions to accommodate error - // handling. Returning a nil value and not returning an error is an - // exception. - if (!method.returnType.isNullable && - !method.returnType.isVoid) ...[ - const cb.Code( - '} else if (replyList[0] == null) {', - ), - cb.InvokeExpression.newOf( - cb.refer('PlatformException'), - [], - { - 'code': cb.literalString('null-error'), - 'message': cb.literalString( - 'Host platform returned null value for non-null return value.', - ) - }).thrown.statement, - ], - const cb.Code('} else {'), - _unwrapReturnValue( - method.returnType, - customEnumNames: customEnumNames, - ).returned.statement, - const cb.Code('}'), - ]), + for (final Method method in interfacesMethods) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = method.name + ..named = true + ..toThis = true + ..required = method.required, + ), + for (final Method method in flutterMethods) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = method.name + ..named = true + ..toThis = true + ..required = method.required, + ), + ]) + ..initializers.add( + cb.Code( + superClassApi != null + ? r'super.$detached()' + : r'$instanceManager = $instanceManager ?? $InstanceManager.instance', ), - cb.Method( - (cb.MethodBuilder builder) => builder - ..name = r'$copy' - ..returns = cb.refer(api.name) - ..annotations.add(cb.refer('override')) - ..body = cb.Block.of([ - cb - .refer('${api.name}.\$detached') - .call( - [], - { - r'$binaryMessenger': cb.refer(r'$binaryMessenger'), - r'$instanceManager': cb.refer(r'$instanceManager'), - for (final Field field in nonAttachedFields) - 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, - ]), ), - ]), - ); - - final cb.DartEmitter emitter = cb.DartEmitter(useNullSafetySyntax: true); - indent.writeln(DartFormatter().format('${proxyApi.accept(emitter)}')); + ), + ]; } /// Generates Dart source code for test support libraries based on the given AST @@ -2285,7 +2309,6 @@ cb.Code _assert({ } cb.Code _basicMessageChannel({ - required String channelName, cb.Expression codec = const cb.Reference('codec'), cb.Expression? binaryMessenger = const cb.Reference('binaryMessenger'), }) { @@ -2293,11 +2316,11 @@ cb.Code _basicMessageChannel({ 'BasicMessageChannel', ); return cb - .declareFinal('channel', type: basicMessageChannel) + .declareFinal('${_varNamePrefix}channel', type: basicMessageChannel) .assign( basicMessageChannel.newInstance( [ - cb.literalString(channelName, raw: true), + cb.refer('${_varNamePrefix}channelName'), codec, ], { @@ -2313,7 +2336,7 @@ cb.Code _basicMessageChannel({ /// ```dart /// apple, banana, myEnum${type.isNullable : '?' : ''}.index /// ``` -cb.Expression _parameterArgument( +cb.Expression _hostMessageArgument( int index, NamedType type, { String Function(int index, NamedType type) getArgumentName = From 4f643ebf200e20b53cba45175b490c9cc6326ea3 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Sun, 3 Dec 2023 22:04:41 -0500 Subject: [PATCH 08/73] add field impls --- packages/pigeon/lib/dart_generator.dart | 294 ++++++++++++++---------- 1 file changed, 170 insertions(+), 124 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 20beb1eae668..ab86817a72e0 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -1081,6 +1081,20 @@ class $codecName extends StandardMessageCodec { interfacesMethods: interfacesMethods, flutterMethods: flutterMethods, )) + ..fields.addAll(_proxyApiFields( + nonAttachedFields: nonAttachedFields, + attachedFields: attachedFields, + apiName: api.name, + dartPackageName: dartPackageName, + codecInstanceName: codecInstanceName, + codecName: codecName, + interfacesApis: interfacesApis, + flutterMethods: flutterMethods, + hasSuperClass: superClassApi != null, + hasHostMessageSends: hostMethods.isNotEmpty || + api.constructors.isNotEmpty || + attachedFields.any((Field field) => !field.isStatic), + )) // ..methods.add( // cb.Method.returnsVoid( // (cb.MethodBuilder builder) => builder @@ -1425,129 +1439,6 @@ class $codecName extends StandardMessageCodec { // ]), // ), // ) - // ..fields.addAll([ - // if (hostMethods.isNotEmpty || - // api.constructors.isNotEmpty || - // attachedFields.where((Field field) => !field.isStatic).isNotEmpty) - // cb.Field( - // (cb.FieldBuilder builder) => builder - // ..name = '_codec${api.name}' - // ..type = cb.refer(codecName) - // ..late = true - // ..modifier = cb.FieldModifier.final$ - // ..assignment = cb.Code('$codecName(\$instanceManager)'), - // ), - // if (superClassApi == null) ...[ - // cb.Field( - // (cb.FieldBuilder builder) => builder - // ..name = r'$binaryMessenger' - // ..type = cb.refer('BinaryMessenger?') - // ..modifier = cb.FieldModifier.final$ - // ..docs.addAll([ - // '/// 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.', - // ]) - // ..annotations.addAll([ - // if (superClassApi == null && interfacesApis.isNotEmpty) - // cb.refer('override'), - // ]), - // ), - // cb.Field( - // (cb.FieldBuilder builder) => builder - // ..name = r'$instanceManager' - // ..type = cb.refer(r'$InstanceManager') - // ..modifier = cb.FieldModifier.final$ - // ..docs.add( - // '/// Maintains instances stored to communicate with native language objects.', - // ) - // ..annotations.addAll([ - // if (superClassApi == null && interfacesApis.isNotEmpty) - // cb.refer('override'), - // ]), - // ), - // ], - // for (final Field field in nonAttachedFields) - // 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, _docCommentSpec)) - // ..type = cb.FunctionType( - // (cb.FunctionTypeBuilder builder) => builder - // ..returnType = _referOrNull( - // _addGenericTypesNullable(method.returnType), - // isFuture: method.isAsynchronous, - // ) - // ..isNullable = !method.required - // ..requiredParameters.addAll([ - // cb.refer('${api.name} instance'), - // ...indexMap( - // method.parameters, - // (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 = _referOrNull( - // _addGenericTypesNullable(method.returnType), - // isFuture: method.isAsynchronous, - // ) - // ..isNullable = !method.required - // ..requiredParameters.addAll([ - // cb.refer('${proxyApi.name} instance'), - // ...indexMap( - // method.parameters, - // (int index, NamedType parameter) { - // return cb.refer( - // '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', - // ); - // }, - // ), - // ]), - // ), - // ), - // for (final Field 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('_${field.name}()'), - // ), - // ]) // ..methods.addAll([ // for (final Field field in attachedFields) // cb.Method( @@ -1920,7 +1811,7 @@ class $codecName extends StandardMessageCodec { ) ..body = cb.Block.of([ cb.Code( - "final String ${_varNamePrefix}channelName = r'$channelName';", + "const String ${_varNamePrefix}channelName = r'$channelName';", ), _basicMessageChannel( codec: cb.refer(codecInstanceName), @@ -2079,6 +1970,161 @@ class $codecName extends StandardMessageCodec { ]; } + Iterable _proxyApiFields({ + required Iterable nonAttachedFields, + required Iterable attachedFields, + required String apiName, + required String dartPackageName, + required String codecInstanceName, + required String codecName, + required Iterable interfacesApis, + required Iterable flutterMethods, + required bool hasSuperClass, + required bool hasHostMessageSends, + }) { + return [ + if (hasHostMessageSends) + cb.Field( + (cb.FieldBuilder builder) => builder + ..name = codecInstanceName + ..type = cb.refer(codecName) + ..late = true + ..modifier = cb.FieldModifier.final$ + ..assignment = cb.Code('$codecName(\$instanceManager)'), + ), + if (!hasSuperClass) ...[ + cb.Field( + (cb.FieldBuilder builder) => builder + ..name = r'$binaryMessenger' + ..type = cb.refer('BinaryMessenger?') + ..modifier = cb.FieldModifier.final$ + ..docs.addAll([ + '/// 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.', + ]) + ..annotations.addAll([ + if (!hasSuperClass && interfacesApis.isNotEmpty) + cb.refer('override'), + ]), + ), + cb.Field( + (cb.FieldBuilder builder) => builder + ..name = r'$instanceManager' + ..type = cb.refer(r'$InstanceManager') + ..modifier = cb.FieldModifier.final$ + ..docs.add( + '/// Maintains instances stored to communicate with native language objects.', + ) + ..annotations.addAll([ + if (!hasSuperClass && interfacesApis.isNotEmpty) + cb.refer('override'), + ]), + ), + ], + for (final Field field in nonAttachedFields) + 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, + _docCommentSpec, + )) + ..type = cb.FunctionType( + (cb.FunctionTypeBuilder builder) => builder + ..returnType = _referOrNull( + _addGenericTypesNullable(method.returnType), + isFuture: method.isAsynchronous, + ) + ..isNullable = !method.required + ..requiredParameters.addAll([ + cb.refer('$apiName instance'), + ...indexMap( + method.parameters, + (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 = _referOrNull( + _addGenericTypesNullable(method.returnType), + isFuture: method.isAsynchronous, + ) + ..isNullable = !method.required + ..requiredParameters.addAll([ + cb.refer('${proxyApi.name} instance'), + ...indexMap( + method.parameters, + (int index, NamedType parameter) { + return cb.refer( + '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', + ); + }, + ), + ]), + ), + ), + for (final Field 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('_${field.name}()'), + ), + ]; + } + + Iterable _proxyApiMethods({ + required Iterable hostMethods, + required Iterable flutterMethods, + required String apiName, + required String dartPackageName, + required String codecInstanceName, + required String codecName, + // required Iterable nonAttachedFields, + // required Iterable attachedFields, + // required Iterable interfacesApis, + // required bool hasSuperClass, + // required bool hasHostMessageSends, + }) { + + } + /// 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 From 8a87f7f9e7a858f4296ec787893f8e6b2239d775 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 4 Dec 2023 20:54:45 -0500 Subject: [PATCH 09/73] fix methods --- packages/pigeon/lib/ast.dart | 2 + packages/pigeon/lib/dart_generator.dart | 1328 +++++++++++------------ 2 files changed, 648 insertions(+), 682 deletions(-) diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index b5014d5f8f1e..6b971866af58 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -226,6 +226,8 @@ class Field extends NamedType { type: type, offset: offset, documentationComments: documentationComments, + isAttached: isAttached, + isStatic: isStatic, ); } } diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index ab86817a72e0..53e75df8d20f 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -868,7 +868,7 @@ class _InstanceManagerApi { final BinaryMessenger? _binaryMessenger; - static const MessageCodec pigeonChannelCodec = + static const MessageCodec $_pigeonChannelCodec = StandardMessageCodec(); static void \$setUpMessageHandlers({ @@ -879,7 +879,7 @@ class _InstanceManagerApi { r'$removeStrongReferenceName'; final BasicMessageChannel channel = BasicMessageChannel( channelName, - pigeonChannelCodec, + $_pigeonChannelCodec, binaryMessenger: binaryMessenger, ); channel.setMessageHandler((Object? message) async { @@ -902,7 +902,7 @@ class _InstanceManagerApi { r'$removeStrongReferenceName'; final BasicMessageChannel channel = BasicMessageChannel( channelName, - pigeonChannelCodec, + $_pigeonChannelCodec, binaryMessenger: _binaryMessenger, ); final List? replyList = @@ -928,7 +928,7 @@ class _InstanceManagerApi { r'$clearName'; final BasicMessageChannel channel = BasicMessageChannel( channelName, - pigeonChannelCodec, + $_pigeonChannelCodec, binaryMessenger: _binaryMessenger, ); final List? replyList = await channel.send(null) as List?; @@ -958,7 +958,7 @@ class _InstanceManagerApi { final String codecName = _getCodecName(api); final String codecInstanceName = '_codec${api.name}'; - // Write Codec + // codec indent.writeln(''' class $codecName extends StandardMessageCodec { const $codecName(this.instanceManager); @@ -1054,658 +1054,59 @@ class $codecName extends StandardMessageCodec { return method.location == ApiLocation.flutter && method.required; }); - final List customEnumNames = - root.enums.map((Enum x) => x.name).toList(); - - final cb.Class proxyApi = cb.Class((cb.ClassBuilder builder) => builder - ..name = api.name - ..extend = _referOrNull(superClassApi?.name) - ..implements.addAll([ - if (api.interfacesNames.isNotEmpty) - ...api.interfacesNames.map((String name) => cb.refer(name)) - else - cb.refer(r'$Copyable') - ]) - ..docs.addAll(asDocumentationComments( - api.documentationComments, - _docCommentSpec, - )) - ..constructors.addAll(_proxyApiConstructors( - api.constructors, - apiName: api.name, - dartPackageName: dartPackageName, - codecInstanceName: codecInstanceName, - superClassApi: superClassApi, - nonAttachedFields: nonAttachedFields, - superClassFlutterMethods: superClassFlutterMethods, - interfacesMethods: interfacesMethods, - flutterMethods: flutterMethods, - )) - ..fields.addAll(_proxyApiFields( - nonAttachedFields: nonAttachedFields, - attachedFields: attachedFields, - apiName: api.name, - dartPackageName: dartPackageName, - codecInstanceName: codecInstanceName, - codecName: codecName, - interfacesApis: interfacesApis, - flutterMethods: flutterMethods, - hasSuperClass: superClassApi != null, - hasHostMessageSends: hostMethods.isNotEmpty || - api.constructors.isNotEmpty || - attachedFields.any((Field field) => !field.isStatic), - )) - // ..methods.add( - // cb.Method.returnsVoid( - // (cb.MethodBuilder builder) => builder - // ..name = r'$setUpMessageHandlers' - // ..returns = cb.refer('void') - // ..static = true - // ..optionalParameters.addAll([ - // cb.Parameter( - // (cb.ParameterBuilder builder) => builder - // ..name = r'$binaryMessenger' - // ..named = true - // ..type = cb.refer('BinaryMessenger?'), - // ), - // cb.Parameter( - // (cb.ParameterBuilder builder) => builder - // ..name = r'$instanceManager' - // ..named = true - // ..type = cb.refer(r'$InstanceManager?'), - // ), - // if (!hasARequiredFlutterMethod) - // cb.Parameter( - // (cb.ParameterBuilder builder) => builder - // ..name = r'$detached' - // ..named = true - // ..type = cb.FunctionType( - // (cb.FunctionTypeBuilder builder) => builder - // ..returnType = cb.refer(api.name) - // ..isNullable = true - // ..requiredParameters.addAll(indexMap( - // nonAttachedFields, - // (int index, Field 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 = _referOrNull( - // _addGenericTypesNullable(method.returnType), - // isFuture: method.isAsynchronous, - // ) - // ..isNullable = true - // ..requiredParameters.addAll([ - // cb.refer('${api.name} instance'), - // ...indexMap( - // method.parameters, - // (int index, NamedType parameter) { - // return cb.refer( - // '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', - // ); - // }, - // ) - // ]), - // ), - // ), - // ]) - // ..body = cb.Block.of([ - // cb.Code( - // 'final $codecName codec = $codecName(\$instanceManager ?? \$InstanceManager.instance);', - // ), - // if (!hasARequiredFlutterMethod) ...[ - // const cb.Code('{'), - // _basicMessageChannel( - // channelName: makeChannelNameWithStrings( - // apiName: api.name, - // methodName: r'$detached', - // dartPackageName: dartPackageName, - // ), - // binaryMessenger: cb.refer(r'$binaryMessenger'), - // ), - // cb.refer('channel').property('setMessageHandler').call( - // [ - // cb.Method( - // (cb.MethodBuilder builder) => builder - // ..modifier = cb.MethodModifier.async - // ..requiredParameters.add( - // cb.Parameter( - // (cb.ParameterBuilder builder) => builder - // ..name = 'message' - // ..type = cb.refer('Object?'), - // ), - // ) - // ..body = cb.Block((cb.BlockBuilder builder) { - // final String channelName = - // makeChannelNameWithStrings( - // apiName: api.name, - // methodName: r'$detached', - // dartPackageName: dartPackageName, - // ); - // builder.statements.addAll([ - // _assert( - // condition: cb - // .refer('message') - // .notEqualTo(cb.literalNull), - // message: cb.literalString( - // 'Argument for $channelName was null.', - // raw: true, - // ), - // ), - // const cb.Code( - // 'final List args = (message as List?)!;', - // ), - // const cb.Code( - // 'final int? instanceIdentifier = (args[0] as int?);', - // ), - // _assert( - // condition: cb - // .refer('instanceIdentifier') - // .notEqualTo(cb.literalNull), - // message: cb.literalString( - // 'Argument for $channelName was null, expected non-null int.', - // raw: true, - // ), - // ), - // ...indexFold, Field>( - // nonAttachedFields, - // [], - // (List list, int index, Field field) { - // return list - // ..addAll(_messageArg( - // index + 1, - // field, - // customEnumNames: customEnumNames, - // channelName: channelName, - // )); - // }, - // ), - // cb - // .refer( - // r'($instanceManager ?? $InstanceManager.instance)', - // ) - // .property('addHostCreatedInstance') - // .call([ - // cb - // .refer(r'$detached?.call') - // .call( - // indexMap( - // nonAttachedFields, - // (int index, Field field) { - // // The calling instance is the first arg. - // final String name = - // _getSafeArgumentName( - // index + 1, - // field, - // ); - // return field.type.isNullable - // ? cb.refer(name) - // : cb.refer(name).nullChecked; - // }, - // ), - // ) - // .ifNullThen( - // cb.refer('${api.name}.\$detached').call( - // [], - // { - // r'$binaryMessenger': - // cb.refer(r'$binaryMessenger'), - // r'$instanceManager': - // cb.refer(r'$instanceManager'), - // ...nonAttachedFields - // .toList() - // .asMap() - // .map( - // (int index, Field field) { - // final String argName = - // _getSafeArgumentName( - // index + 1, - // field, - // ); - // return MapEntry( - // field.name, - // field.type.isNullable - // ? cb.refer(argName) - // : cb - // .refer(argName) - // .nullChecked, - // ); - // }, - // ) - // }, - // ), - // ), - // cb.refer('instanceIdentifier').nullChecked - // ]).statement, - // const cb.Code('return;'), - // ]); - // }), - // ).genericClosure - // ], - // ).statement, - // const cb.Code('}'), - // ], - // ...flutterMethods.fold>( - // [], - // (List list, Method method) { - // final String channelName = makeChannelName( - // api, - // method, - // dartPackageName, - // ); - // final cb.Expression call = cb - // .refer( - // '(${method.name} ?? instance!.${method.name})${method.required ? '' : '?'}.call', - // ) - // .call( - // [ - // cb.refer('instance').nullChecked, - // ...indexMap( - // method.parameters, - // (int index, NamedType parameter) { - // final String name = _getSafeArgumentName( - // index + 1, - // parameter, - // ); - // return cb - // .refer(name) - // .nullCheckedIf(!parameter.type.isNullable); - // }, - // ), - // ], - // ); - // return list - // ..addAll([ - // const cb.Code('{'), - // _basicMessageChannel( - // channelName: channelName, - // binaryMessenger: cb.refer(r'$binaryMessenger'), - // ), - // cb.refer('channel').property('setMessageHandler').call( - // [ - // cb.Method( - // (cb.MethodBuilder builder) => builder - // ..modifier = cb.MethodModifier.async - // ..requiredParameters.add( - // cb.Parameter( - // (cb.ParameterBuilder builder) => builder - // ..name = 'message' - // ..type = cb.refer('Object?'), - // ), - // ) - // ..body = cb.Block((cb.BlockBuilder builder) { - // builder.statements.addAll([ - // _assert( - // condition: cb - // .refer('message') - // .notEqualTo(cb.literalNull), - // message: cb.literalString( - // 'Argument for $channelName was null.', - // raw: true, - // ), - // ), - // const cb.Code( - // 'final List args = (message as List?)!;', - // ), - // cb.Code( - // 'final ${api.name}? instance = (args[0] as ${api.name}?);', - // ), - // _assert( - // condition: cb - // .refer('instance') - // .notEqualTo(cb.literalNull), - // message: cb.literalString( - // 'Argument for $channelName was null, expected non-null ${api.name}.', - // raw: true, - // ), - // ), - // ...indexFold, NamedType>( - // method.parameters, - // [], - // ( - // List list, - // int index, - // NamedType type, - // ) { - // return list - // ..addAll(_messageArg( - // index + 1, - // type, - // customEnumNames: customEnumNames, - // channelName: channelName, - // )); - // }, - // ), - // const cb.Code('try {'), - // if (method.returnType.isVoid) ...[ - // if (method.isAsynchronous) - // call.awaited.statement - // else - // call.statement, - // const cb.Code( - // 'return wrapResponse(empty: true);', - // ), - // ] else ...[ - // cb - // .declareFinal( - // 'output', - // type: cb.refer( - // _addGenericTypesNullable( - // method.returnType, - // ), - // ), - // ) - // .assign( - // call.awaitedIf( - // method.isAsynchronous, - // ), - // ) - // .statement, - // _wrapResultResponse( - // root, method.returnType) - // .returned - // .statement, - // ], - // const cb.Code( - // '} on PlatformException catch (e) {', - // ), - // const cb.Code( - // 'return wrapResponse(error: e);', - // ), - // const cb.Code('} catch (e) {'), - // const cb.Code( - // "return wrapResponse(error: PlatformException(code: 'error', message: e.toString()),);", - // ), - // const cb.Code('}') - // ]); - // }), - // ).genericClosure - // ], - // ).statement, - // const cb.Code('}'), - // ]); - // }, - // ), - // ]), - // ), - // ) - // ..methods.addAll([ - // for (final Field field in attachedFields) - // cb.Method( - // (cb.MethodBuilder builder) { - // final String type = _addGenericTypesNullable(field.type); - // final String channelName = makeChannelNameWithStrings( - // apiName: api.name, - // methodName: field.name, - // dartPackageName: dartPackageName, - // ); - // builder - // ..name = '_${field.name}' - // ..static = field.isStatic - // ..returns = cb.refer(type) - // ..body = cb.Block.of( - // [ - // cb.Code('final $type instance = $type.\$detached('), - // if (!field.isStatic) ...[ - // const cb.Code(r'$binaryMessenger: $binaryMessenger,'), - // const cb.Code(r'$instanceManager: $instanceManager,'), - // ], - // const cb.Code(');'), - // _basicMessageChannel( - // channelName: channelName, - // codec: !field.isStatic - // ? cb.refer('_codec${api.name}') - // : cb.refer( - // '$codecName(\$InstanceManager.instance)', - // ), - // binaryMessenger: !field.isStatic - // ? cb.refer(r'$binaryMessenger') - // : null, - // ), - // cb.Code( - // 'final int instanceIdentifier = ${field.isStatic ? r'$InstanceManager.instance' : r'$instanceManager'}.addDartCreatedInstance(instance);', - // ), - // cb - // .refer('channel.send') - // .call([ - // cb.literalList( - // [ - // if (!field.isStatic) cb.refer('this'), - // cb.refer('instanceIdentifier') - // ], - // cb.refer('Object?'), - // ) - // ]) - // .property('then') - // .call( - // [ - // cb.Method( - // (cb.MethodBuilder builder) => builder - // ..requiredParameters.add( - // cb.Parameter( - // (cb.ParameterBuilder builder) => builder - // ..name = 'value' - // ..type = cb.refer('Object?'), - // ), - // ) - // ..body = cb.Block.of([ - // const cb.Code( - // 'final List? replyList = value as List?;', - // ), - // const cb.Code('if (replyList == null) {'), - // cb.InvokeExpression.newOf( - // cb.refer('PlatformException'), - // [], - // { - // 'code': - // cb.literalString('channel-error'), - // 'message': cb.literalString( - // 'Unable to establish connection on channel.', - // ) - // }).thrown.statement, - // const cb.Code( - // '} else if (replyList.length > 1) {', - // ), - // cb.InvokeExpression.newOf( - // cb.refer('PlatformException'), - // [], - // { - // 'code': cb - // .refer('replyList') - // .index(cb.literal(0)) - // .nullChecked - // .asA(cb.refer('String')), - // 'message': cb - // .refer('replyList') - // .index(cb.literal(1)) - // .asA(cb.refer('String?')), - // 'details': cb - // .refer('replyList') - // .index(cb.literal(2)), - // }).thrown.statement, - // const cb.Code('}'), - // ]), - // ).genericClosure, - // ], - // {}, - // [cb.refer('void')], - // ) - // .statement, - // const cb.Code('return instance;'), - // ], - // ); - // }, - // ), - // 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 = _referOrNull( - // _addGenericTypesNullable(method.returnType), - // isFuture: true, - // ) - // ..requiredParameters.addAll(indexMap( - // method.parameters, - // (int index, NamedType parameter) => cb.Parameter( - // (cb.ParameterBuilder builder) => builder - // ..name = _getSafeArgumentName(index, parameter) - // ..type = cb.refer( - // _addGenericTypesNullable(parameter.type), - // ), - // ), - // )) - // ..optionalParameters.addAll([ - // if (method.isStatic) ...[ - // cb.Parameter( - // (cb.ParameterBuilder builder) => builder - // ..name = r'$binaryMessenger' - // ..type = cb.refer('BinaryMessenger?') - // ..named = true, - // ), - // cb.Parameter( - // (cb.ParameterBuilder builder) => builder - // ..name = r'$instanceManager' - // ..type = cb.refer(r'$InstanceManager?'), - // ), - // ], - // ]) - // ..body = cb.Block.of([ - // _basicMessageChannel( - // channelName: makeChannelName(api, method, dartPackageName), - // codec: !method.isStatic - // ? cb.refer('_codec${api.name}') - // : cb.refer( - // '$codecName(\$instanceManager ?? \$InstanceManager.instance)', - // ), - // binaryMessenger: cb.refer(r'$binaryMessenger'), - // ), - // const cb.Code('final List? replyList ='), - // cb - // .refer('channel.send') - // .call([ - // cb.literalList( - // [ - // if (!method.isStatic) cb.refer('this'), - // ...indexMap( - // method.parameters, - // (int index, NamedType parameter) => _referOrNull( - // _getSafeArgumentName(index, parameter), - // isNullable: parameter.type.isNullable, - // )! - // .propertyIf( - // root.enums.map((Enum e) => e.name).contains( - // parameter.type.baseName, - // ), - // 'index', - // ), - // ), - // ], - // cb.refer('Object?'), - // ) - // ]) - // .awaited - // .asA(cb.refer('List?')) - // .statement, - // const cb.Code('if (replyList == null) {'), - // cb.InvokeExpression.newOf( - // cb.refer('PlatformException'), - // [], - // { - // 'code': cb.literalString('channel-error'), - // 'message': cb.literalString( - // 'Unable to establish connection on channel.', - // ) - // }).thrown.statement, - // const cb.Code( - // '} else if (replyList.length > 1) {', - // ), - // cb.InvokeExpression.newOf( - // cb.refer('PlatformException'), - // [], - // { - // 'code': cb - // .refer('replyList') - // .index(cb.literal(0)) - // .nullChecked - // .asA(cb.refer('String')), - // 'message': cb - // .refer('replyList') - // .index(cb.literal(1)) - // .asA(cb.refer('String?')), - // 'details': cb.refer('replyList').index(cb.literal(2)), - // }).thrown.statement, - // // On iOS we can return nil from functions to accommodate error - // // handling. Returning a nil value and not returning an error is an - // // exception. - // if (!method.returnType.isNullable && - // !method.returnType.isVoid) ...[ - // const cb.Code( - // '} else if (replyList[0] == null) {', - // ), - // cb.InvokeExpression.newOf( - // cb.refer('PlatformException'), - // [], - // { - // 'code': cb.literalString('null-error'), - // 'message': cb.literalString( - // 'Host platform returned null value for non-null return value.', - // ) - // }).thrown.statement, - // ], - // const cb.Code('} else {'), - // _unwrapReturnValue( - // method.returnType, - // customEnumNames: customEnumNames, - // ).returned.statement, - // const cb.Code('}'), - // ]), - // ), - // cb.Method( - // (cb.MethodBuilder builder) => builder - // ..name = r'$copy' - // ..returns = cb.refer(api.name) - // ..annotations.add(cb.refer('override')) - // ..body = cb.Block.of([ - // cb - // .refer('${api.name}.\$detached') - // .call( - // [], - // { - // r'$binaryMessenger': cb.refer(r'$binaryMessenger'), - // r'$instanceManager': cb.refer(r'$instanceManager'), - // for (final Field field in nonAttachedFields) - // 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, - // ]), - // ), - // ]), - ); + final cb.Class proxyApi = cb.Class( + (cb.ClassBuilder builder) => builder + ..name = api.name + ..extend = _referOrNull(superClassApi?.name) + ..implements.addAll([ + if (api.interfacesNames.isNotEmpty) + ...api.interfacesNames.map((String name) => cb.refer(name)) + else + cb.refer(r'$Copyable') + ]) + ..docs.addAll(asDocumentationComments( + api.documentationComments, + _docCommentSpec, + )) + ..constructors.addAll(_proxyApiConstructors( + api.constructors, + apiName: api.name, + dartPackageName: dartPackageName, + codecInstanceName: codecInstanceName, + superClassApi: superClassApi, + nonAttachedFields: nonAttachedFields, + superClassFlutterMethods: superClassFlutterMethods, + interfacesMethods: interfacesMethods, + flutterMethods: flutterMethods, + )) + ..fields.addAll(_proxyApiFields( + nonAttachedFields: nonAttachedFields, + attachedFields: attachedFields, + apiName: api.name, + dartPackageName: dartPackageName, + codecInstanceName: codecInstanceName, + codecName: codecName, + interfacesApis: interfacesApis, + flutterMethods: flutterMethods, + hasSuperClass: superClassApi != null, + referencesCodecInstance: hostMethods.isNotEmpty || + api.constructors.isNotEmpty || + attachedFields.any((Field field) => !field.isStatic), + )) + ..methods.addAll(_proxyApiMethods( + hostMethods: hostMethods, + flutterMethods: flutterMethods, + superClassFlutterMethods: superClassFlutterMethods, + apiName: api.name, + dartPackageName: dartPackageName, + codecInstanceName: codecInstanceName, + codecName: codecName, + nonAttachedFields: nonAttachedFields, + attachedFields: attachedFields, + interfacesApis: interfacesApis, + hasARequiredFlutterMethod: hasARequiredFlutterMethod, + )), + ); final cb.DartEmitter emitter = cb.DartEmitter(useNullSafetySyntax: true); indent.writeln(DartFormatter().format('${proxyApi.accept(emitter)}')); @@ -1980,10 +1381,10 @@ class $codecName extends StandardMessageCodec { required Iterable interfacesApis, required Iterable flutterMethods, required bool hasSuperClass, - required bool hasHostMessageSends, + required bool referencesCodecInstance, }) { return [ - if (hasHostMessageSends) + if (referencesCodecInstance) cb.Field( (cb.FieldBuilder builder) => builder ..name = codecInstanceName @@ -2109,20 +1510,591 @@ class $codecName extends StandardMessageCodec { ]; } - Iterable _proxyApiMethods({ + 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 nonAttachedFields, - // required Iterable attachedFields, - // required Iterable interfacesApis, - // required bool hasSuperClass, - // required bool hasHostMessageSends, + required Iterable nonAttachedFields, + required Iterable attachedFields, + required Iterable interfacesApis, + required bool hasARequiredFlutterMethod, }) { - + return [ + cb.Method.returnsVoid( + (cb.MethodBuilder builder) => builder + ..name = r'$setUpMessageHandlers' + ..returns = cb.refer('void') + ..static = true + ..optionalParameters.addAll([ + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = r'$binaryMessenger' + ..named = true + ..type = cb.refer('BinaryMessenger?'), + ), + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = r'$instanceManager' + ..named = true + ..type = cb.refer(r'$InstanceManager?'), + ), + if (!hasARequiredFlutterMethod) + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = r'$detached' + ..named = true + ..type = cb.FunctionType( + (cb.FunctionTypeBuilder builder) => builder + ..returnType = cb.refer(apiName) + ..isNullable = true + ..requiredParameters.addAll(indexMap( + nonAttachedFields, + (int index, Field 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 = _referOrNull( + _addGenericTypesNullable(method.returnType), + isFuture: method.isAsynchronous, + ) + ..isNullable = true + ..requiredParameters.addAll([ + cb.refer('$apiName instance'), + ...indexMap( + method.parameters, + (int index, NamedType parameter) { + return cb.refer( + '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', + ); + }, + ) + ]), + ), + ), + ]) + ..body = cb.Block.of([ + cb.Code( + 'final $codecName $_pigeonChannelCodec = $codecName(\$instanceManager ?? \$InstanceManager.instance);', + ), + if (!hasARequiredFlutterMethod) ...[ + const cb.Code('{'), + cb.Code( + "const String ${_varNamePrefix}channelName = r'${makeChannelNameWithStrings( + apiName: apiName, + methodName: r'$detached', + dartPackageName: dartPackageName, + )}';", + ), + _basicMessageChannel( + binaryMessenger: cb.refer(r'$binaryMessenger'), + ), + cb.refer('${_varNamePrefix}channel.setMessageHandler').call( + [ + cb.Method( + (cb.MethodBuilder builder) => builder + ..modifier = cb.MethodModifier.async + ..requiredParameters.add( + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = 'message' + ..type = cb.refer('Object?'), + ), + ) + ..body = cb.Block((cb.BlockBuilder builder) { + builder.statements.addAll([ + _assert( + condition: + cb.refer('message').notEqualTo(cb.literalNull), + message: cb.literalString( + 'Argument for \$${_varNamePrefix}channelName was null.', + ), + ), + const cb.Code( + 'final List args = (message as List?)!;', + ), + const cb.Code( + 'final int? instanceIdentifier = (args[0] as int?);', + ), + _assert( + condition: cb + .refer('instanceIdentifier') + .notEqualTo(cb.literalNull), + message: cb.literalString( + 'Argument for \$${_varNamePrefix}channelName was null, expected non-null int.', + ), + ), + ...indexFold, Field>( + nonAttachedFields, + [], + (List list, int index, Field field) { + return list + ..addAll( + _messageArg(index + 1, field), + ); + }, + ), + cb + .refer( + r'($instanceManager ?? $InstanceManager.instance)', + ) + .property('addHostCreatedInstance') + .call([ + cb + .refer(r'$detached?.call') + .call( + indexMap( + nonAttachedFields, + (int index, Field field) { + // The calling instance is the first arg. + final String name = _getSafeArgumentName( + index + 1, + field, + ); + return cb.refer(name).nullCheckedIf( + !field.type.isNullable, + ); + }, + ), + ) + .ifNullThen( + cb.refer('$apiName.\$detached').call( + [], + { + r'$binaryMessenger': + cb.refer(r'$binaryMessenger'), + r'$instanceManager': + cb.refer(r'$instanceManager'), + ...nonAttachedFields.toList().asMap().map( + (int index, Field field) { + final String argName = + _getSafeArgumentName( + index + 1, + field, + ); + return MapEntry( + field.name, + cb.refer(argName).nullCheckedIf( + !field.type.isNullable, + ), + ); + }, + ) + }, + ), + ), + cb.refer('instanceIdentifier').nullChecked + ]).statement, + const cb.Code('return;'), + ]); + }), + ).genericClosure + ], + ).statement, + const cb.Code('}'), + ], + ...flutterMethods.fold>( + [], + (List list, Method method) { + final String channelName = makeChannelNameWithStrings( + apiName: apiName, + methodName: method.name, + dartPackageName: dartPackageName, + ); + final cb.Expression call = cb + .refer( + '(${method.name} ?? instance!.${method.name})${method.required ? '' : '?'}.call', + ) + .call( + [ + cb.refer('instance').nullChecked, + ...indexMap( + method.parameters, + (int index, NamedType parameter) { + final String name = _getSafeArgumentName( + index + 1, + parameter, + ); + return cb + .refer(name) + .nullCheckedIf(!parameter.type.isNullable); + }, + ), + ], + ); + return list + ..addAll([ + const cb.Code('{'), + cb.Code( + "const String ${_varNamePrefix}channelName = r'$channelName';", + ), + _basicMessageChannel( + binaryMessenger: cb.refer(r'$binaryMessenger'), + ), + cb.refer('${_varNamePrefix}channel.setMessageHandler').call( + [ + cb.Method( + (cb.MethodBuilder builder) => builder + ..modifier = cb.MethodModifier.async + ..requiredParameters.add( + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = 'message' + ..type = cb.refer('Object?'), + ), + ) + ..body = cb.Block((cb.BlockBuilder builder) { + builder.statements.addAll([ + _assert( + condition: cb + .refer('message') + .notEqualTo(cb.literalNull), + message: cb.literalString( + 'Argument for \$${_varNamePrefix}channelName was null.', + ), + ), + const cb.Code( + 'final List args = (message as List?)!;', + ), + cb.Code( + 'final $apiName? instance = (args[0] as $apiName?);', + ), + _assert( + condition: cb + .refer('instance') + .notEqualTo(cb.literalNull), + message: cb.literalString( + 'Argument for \$${_varNamePrefix}channelName was null, expected non-null $apiName.', + ), + ), + ...indexFold, NamedType>( + method.parameters, + [], + ( + List list, + int index, + NamedType type, + ) { + return list + ..addAll(_messageArg(index + 1, type)); + }, + ), + const cb.Code('try {'), + if (method.returnType.isVoid) ...[ + if (method.isAsynchronous) + call.awaited.statement + else + call.statement, + const cb.Code( + 'return wrapResponse(empty: true);', + ), + ] else ...[ + cb + .declareFinal( + 'output', + type: cb.refer( + _addGenericTypesNullable( + method.returnType, + ), + ), + ) + .assign( + call.awaitedIf(method.isAsynchronous), + ) + .statement, + _wrapResultResponse(method.returnType) + .returned + .statement, + ], + const cb.Code( + '} on PlatformException catch (e) {', + ), + const cb.Code( + 'return wrapResponse(error: e);', + ), + const cb.Code('} catch (e) {'), + const cb.Code( + "return wrapResponse(error: PlatformException(code: 'error', message: e.toString()),);", + ), + const cb.Code('}') + ]); + }), + ).genericClosure + ], + ).statement, + const cb.Code('}'), + ]); + }, + ), + ]), + ), + for (final Field field in attachedFields) + cb.Method( + (cb.MethodBuilder builder) { + final String type = _addGenericTypesNullable(field.type); + final String channelName = makeChannelNameWithStrings( + apiName: apiName, + methodName: field.name, + dartPackageName: dartPackageName, + ); + builder + ..name = '_${field.name}' + ..static = field.isStatic + ..returns = cb.refer(type) + ..body = cb.Block.of( + [ + cb.Code('final $type instance = $type.\$detached('), + if (!field.isStatic) ...[ + const cb.Code(r'$binaryMessenger: $binaryMessenger,'), + const cb.Code(r'$instanceManager: $instanceManager,'), + ], + const cb.Code(');'), + cb.Code( + "const String ${_varNamePrefix}channelName = r'$channelName';", + ), + _basicMessageChannel( + codec: !field.isStatic + ? cb.refer('_codec$apiName') + : cb.refer('$codecName(\$InstanceManager.instance)'), + binaryMessenger: + !field.isStatic ? cb.refer(r'$binaryMessenger') : null, + ), + cb + .refer('${_varNamePrefix}channel.send') + .call([ + cb.literalList( + [ + if (!field.isStatic) cb.refer('this'), + cb.refer( + '${field.isStatic ? r'$InstanceManager.instance' : r'$instanceManager'}.addDartCreatedInstance(instance)', + ), + ], + cb.refer('Object?'), + ) + ]) + .property('then') + .call( + [ + cb.Method( + (cb.MethodBuilder builder) => builder + ..requiredParameters.add( + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = 'value' + ..type = cb.refer('Object?'), + ), + ) + ..body = cb.Block.of([ + const cb.Code( + 'final List? ${_varNamePrefix}replyList = value as List?;', + ), + const cb.Code( + 'if (${_varNamePrefix}replyList == null) {', + ), + const cb.Code( + 'throw _createConnectionError(${_varNamePrefix}channelName);', + ), + const cb.Code( + '} else if (${_varNamePrefix}replyList.length > 1) {', + ), + cb.InvokeExpression.newOf( + cb.refer('PlatformException'), + [], + { + 'code': cb + .refer('${_varNamePrefix}replyList') + .index(cb.literal(0)) + .nullChecked + .asA(cb.refer('String')), + 'message': cb + .refer('${_varNamePrefix}replyList') + .index(cb.literal(1)) + .asA(cb.refer('String?')), + 'details': cb + .refer('${_varNamePrefix}replyList') + .index(cb.literal(2)), + }).thrown.statement, + const cb.Code('}'), + ]), + ).genericClosure, + ], + {}, + [cb.refer('void')], + ) + .statement, + const cb.Code('return instance;'), + ], + ); + }, + ), + 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 = _referOrNull( + _addGenericTypesNullable(method.returnType), + isFuture: true, + ) + ..requiredParameters.addAll(indexMap( + method.parameters, + (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 = r'$binaryMessenger' + ..type = cb.refer('BinaryMessenger?') + ..named = true, + ), + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = r'$instanceManager' + ..type = cb.refer(r'$InstanceManager?'), + ), + ], + ]) + ..body = cb.Block.of([ + cb.Code( + "const String ${_varNamePrefix}channelName = r'${makeChannelNameWithStrings( + apiName: apiName, + methodName: method.name, + dartPackageName: dartPackageName, + )}';", + ), + _basicMessageChannel( + codec: !method.isStatic + ? cb.refer('_codec$apiName') + : cb.refer( + '$codecName(\$instanceManager ?? \$InstanceManager.instance)', + ), + binaryMessenger: cb.refer(r'$binaryMessenger'), + ), + const cb.Code( + 'final List? ${_varNamePrefix}replyList ='), + cb + .refer('${_varNamePrefix}channel.send') + .call([ + cb.literalList( + [ + if (!method.isStatic) cb.refer('this'), + ...indexMap( + method.parameters, + (int index, NamedType parameter) => _referOrNull( + _getParameterName(index, parameter), + isNullable: parameter.type.isNullable, + )! + .propertyIf(parameter.type.isEnum, 'index'), + ), + ], + cb.refer('Object?'), + ) + ]) + .awaited + .asA(cb.refer('List?')) + .statement, + const cb.Code('if (${_varNamePrefix}replyList == null) {'), + const cb.Code( + 'throw _createConnectionError(${_varNamePrefix}channelName);', + ), + const cb.Code( + '} else if (${_varNamePrefix}replyList.length > 1) {', + ), + cb.InvokeExpression.newOf( + cb.refer('PlatformException'), + [], + { + 'code': cb + .refer('${_varNamePrefix}replyList') + .index(cb.literal(0)) + .nullChecked + .asA(cb.refer('String')), + 'message': cb + .refer('${_varNamePrefix}replyList') + .index(cb.literal(1)) + .asA(cb.refer('String?')), + 'details': cb + .refer('${_varNamePrefix}replyList') + .index(cb.literal(2)), + }).thrown.statement, + // On iOS we can return nil from functions to accommodate error + // handling. Returning a nil value and not returning an error is an + // exception. + if (!method.returnType.isNullable && + !method.returnType.isVoid) ...[ + const cb.Code( + '} else if (${_varNamePrefix}replyList[0] == null) {', + ), + cb.InvokeExpression.newOf( + cb.refer('PlatformException'), + [], + { + 'code': cb.literalString('null-error'), + 'message': cb.literalString( + 'Host platform returned null value for non-null return value.', + ) + }).thrown.statement, + ], + const cb.Code('} else {'), + _unwrapReturnValue(method.returnType).returned.statement, + const cb.Code('}'), + ]), + ), + cb.Method( + (cb.MethodBuilder builder) => builder + ..name = r'$copy' + ..returns = cb.refer(apiName) + ..annotations.add(cb.refer('override')) + ..body = cb.Block.of([ + cb + .refer('$apiName.\$detached') + .call( + [], + { + r'$binaryMessenger': cb.refer(r'$binaryMessenger'), + r'$instanceManager': cb.refer(r'$instanceManager'), + for (final Field field in nonAttachedFields) + 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 @@ -2265,26 +2237,21 @@ extension on cb.Expression { condition ? property(name) : this; } -cb.Expression _unwrapReturnValue( - TypeDeclaration returnType, { - required List customEnumNames, -}) { +cb.Expression _unwrapReturnValue(TypeDeclaration returnType) { final String type = _makeGenericTypeArguments(returnType); final String genericCastCall = _makeGenericCastCall(returnType); - const String accessor = 'replyList[0]'; + const String accessor = '${_varNamePrefix}replyList[0]'; final String nullablyTypedAccessor = type == 'Object' ? accessor : '($accessor as $type?)'; final String nullHandler = returnType.isNullable ? (genericCastCall.isEmpty ? '' : '?') : '!'; - if (customEnumNames.contains(type)) { + if (returnType.isEnum) { if (returnType.isNullable) { return cb.refer( '($accessor as int?) == null ? null : $type.values[$accessor! as int]', ); } else { - return cb.refer( - '$type.values[$accessor! as int]', - ); + return cb.refer('$type.values[$accessor! as int]'); } } else if (!returnType.isVoid) { return cb.refer('$nullablyTypedAccessor$nullHandler$genericCastCall'); @@ -2292,7 +2259,7 @@ cb.Expression _unwrapReturnValue( return cb.refer(''); } -cb.Expression _wrapResultResponse(Root root, TypeDeclaration type) { +cb.Expression _wrapResultResponse(TypeDeclaration type) { return cb .refer('wrapResponse') .call([], { @@ -2307,8 +2274,6 @@ cb.Expression _wrapResultResponse(Root root, TypeDeclaration type) { Iterable _messageArg( int index, NamedType parameter, { - required List customEnumNames, - required String channelName, String argsVariableName = 'args', }) { final String argType = _addGenericTypes(parameter.type); @@ -2317,7 +2282,7 @@ Iterable _messageArg( final String castCall = _makeGenericCastCall(parameter.type); late final cb.Expression assign; - if (customEnumNames.contains(parameter.type.baseName)) { + if (parameter.type.isEnum) { assign = cb .refer( '$argsVariableName[$index] == null ? null : $argType.values[$argsVariableName[$index]! as int]', @@ -2340,8 +2305,7 @@ Iterable _messageArg( _assert( condition: cb.refer(argName).notEqualTo(cb.literalNull), message: cb.literalString( - 'Argument for $channelName was null, expected non-null $argType.', - raw: true, + 'Argument for \$${_varNamePrefix}channelName was null, expected non-null $argType.', ), ), ]; @@ -2355,7 +2319,7 @@ cb.Code _assert({ } cb.Code _basicMessageChannel({ - cb.Expression codec = const cb.Reference('codec'), + cb.Expression codec = const cb.Reference(_pigeonChannelCodec), cb.Expression? binaryMessenger = const cb.Reference('binaryMessenger'), }) { final cb.Reference basicMessageChannel = cb.refer( From bb052eb28e0098b5e55ed64c63024f1c2462395b Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 5 Dec 2023 14:07:35 -0500 Subject: [PATCH 10/73] add helper methods to astproxyapi --- packages/pigeon/lib/ast.dart | 20 +++++++++++++ packages/pigeon/lib/dart_generator.dart | 37 ++++++++----------------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index 6b971866af58..1eb063ecefb7 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -153,6 +153,26 @@ class AstProxyApi extends Api { /// 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 . + Iterable get attachedFields => fields.where( + (Field field) => field.isAttached, + ); + + /// All fields that are not attached. + Iterable get nonAttachedFields => fields.where( + (Field field) => !field.isAttached, + ); + @override String toString() { return '(ProxyApi name:$name methods:$methods documentationComments:$documentationComments superClassName:$superClassName interfacesNames:$interfacesNames)'; diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 53e75df8d20f..bee170107966 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -988,21 +988,6 @@ class $codecName extends StandardMessageCodec { } '''); - final Iterable hostMethods = api.methods.where( - (Method method) => method.location == ApiLocation.host, - ); - - final Iterable flutterMethods = api.methods.where( - (Method method) => method.location == ApiLocation.flutter, - ); - - final Iterable attachedFields = api.fields.where( - (Field field) => field.isAttached, - ); - final Iterable nonAttachedFields = api.fields.where( - (Field field) => !field.isAttached, - ); - final Iterable allProxyApis = root.apis.whereType(); @@ -1074,35 +1059,35 @@ class $codecName extends StandardMessageCodec { dartPackageName: dartPackageName, codecInstanceName: codecInstanceName, superClassApi: superClassApi, - nonAttachedFields: nonAttachedFields, + nonAttachedFields: api.nonAttachedFields, superClassFlutterMethods: superClassFlutterMethods, interfacesMethods: interfacesMethods, - flutterMethods: flutterMethods, + flutterMethods: api.flutterMethods, )) ..fields.addAll(_proxyApiFields( - nonAttachedFields: nonAttachedFields, - attachedFields: attachedFields, + nonAttachedFields: api.nonAttachedFields, + attachedFields: api.attachedFields, apiName: api.name, dartPackageName: dartPackageName, codecInstanceName: codecInstanceName, codecName: codecName, interfacesApis: interfacesApis, - flutterMethods: flutterMethods, + flutterMethods: api.flutterMethods, hasSuperClass: superClassApi != null, - referencesCodecInstance: hostMethods.isNotEmpty || + referencesCodecInstance: api.hostMethods.isNotEmpty || api.constructors.isNotEmpty || - attachedFields.any((Field field) => !field.isStatic), + api.attachedFields.any((Field field) => !field.isStatic), )) ..methods.addAll(_proxyApiMethods( - hostMethods: hostMethods, - flutterMethods: flutterMethods, + hostMethods: api.hostMethods, + flutterMethods: api.flutterMethods, superClassFlutterMethods: superClassFlutterMethods, apiName: api.name, dartPackageName: dartPackageName, codecInstanceName: codecInstanceName, codecName: codecName, - nonAttachedFields: nonAttachedFields, - attachedFields: attachedFields, + nonAttachedFields: api.nonAttachedFields, + attachedFields: api.attachedFields, interfacesApis: interfacesApis, hasARequiredFlutterMethod: hasARequiredFlutterMethod, )), From e73f881a86525cc9d53ecf20fc953e230753fcf6 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 6 Dec 2023 00:50:22 -0500 Subject: [PATCH 11/73] start of something --- packages/pigeon/lib/ast.dart | 30 ++++- packages/pigeon/lib/functional.dart | 3 + packages/pigeon/lib/pigeon_lib.dart | 108 ++++++++++++++++-- .../webview_flutter_android/pubspec.yaml | 3 +- 4 files changed, 127 insertions(+), 17 deletions(-) diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index 1eb063ecefb7..2a002c14b0b6 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -227,15 +227,17 @@ class Field extends NamedType { super.documentationComments, this.isAttached = false, this.isStatic = false, - }); + }) : assert(!isStatic || isAttached); - /// Whether this is an attached field for a [ProxyApiNode]. + /// Whether this is an attached field for a [AstProxyApi]. /// - /// Attached fields provide a synchronous [ProxyApiNode] instance as a field for - /// another [ProxyApiNode] + /// Attached fields provide a synchronous [AstProxyApi] instance as a field + /// for another [AstProxyApi]. final bool isAttached; - /// Whether this is a static field of a ProxyApi. + /// Whether this is a static field of a [AstProxyApi]. + /// + /// A static field must also be attached. final bool isStatic; /// Returns a copy of [Parameter] instance with new attached [TypeDeclaration]. @@ -289,6 +291,7 @@ class TypeDeclaration { required this.isNullable, this.associatedEnum, this.associatedClass, + this.associatedProxyApi, this.typeArguments = const [], }); @@ -298,6 +301,7 @@ class TypeDeclaration { isNullable = false, associatedEnum = null, associatedClass = null, + associatedProxyApi = null, typeArguments = const []; /// The base name of the [TypeDeclaration] (ex 'Foo' to 'Foo?'). @@ -324,6 +328,10 @@ class TypeDeclaration { /// Associated [Class], if any. final Class? associatedClass; + final AstProxyApi? associatedProxyApi; + + bool get isProxyApi => associatedProxyApi != null; + @override int get hashCode { // This has to be implemented because TypeDeclaration is used as a Key to a @@ -373,11 +381,21 @@ class TypeDeclaration { ); } + /// Returns duplicated `TypeDeclaration` with attached `associatedClass` 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/functional.dart b/packages/pigeon/lib/functional.dart index 017071187787..6c7be00d7027 100644 --- a/packages/pigeon/lib/functional.dart +++ b/packages/pigeon/lib/functional.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO: replace usage with mapIndexed /// A [map] function that calls the function with an enumeration as well as the /// value. Iterable indexMap( @@ -13,6 +14,7 @@ Iterable indexMap( } } +// TODO: replace usage with foldIndexed /// A [map] function that calls the function with an enumeration as well as the /// value. T indexFold( @@ -29,6 +31,7 @@ T indexFold( return value; } +// TODO: replace usage with forEachIndexed /// Performs like [forEach] but invokes [func] with an enumeration. void enumerate(Iterable iterable, void Function(int, T) func) { int count = 0; diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 62b6cfd6d0d9..773539c51e5b 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -824,7 +824,7 @@ List _validateAst(Root root, String source) { } for (final Api api in root.apis) { if (api is AstProxyApi) { - continue; + result.addAll(_validateProxyApi(api, source, customClasses)); } for (final Method method in api.methods) { for (final Parameter param in method.parameters) { @@ -870,7 +870,7 @@ List _validateAst(Root root, String source) { } } if (method.taskQueueType != TaskQueueType.serial && - api is AstFlutterApi) { + method.location == ApiLocation.flutter) { result.add(Error( message: 'Unsupported TaskQueue specification on ${method.name}', lineNumber: _calculateLineNumberNullable(source, method.offset), @@ -882,6 +882,81 @@ List _validateAst(Root root, String source) { return result; } +List _validateProxyApi( + AstProxyApi api, + String source, + List customClasses, +) { + return []; + // final List result = []; + // + // Error unsupportedDataClassError(NamedType type) { + // return Error( + // message: 'ProxyApis do not support data classes: ${type.type.baseName}.', + // lineNumber: _calculateLineNumberNullable(source, type.offset), + // ); + // } + // + // if (api.constructors.length > 1 && api.nonAttachedFields.isNotEmpty) { + // result.add(Error( + // message: + // 'ProxyApis with more than one constructor can not have any non attached fields: ${api.nonAttachedFields.first.name}', + // lineNumber: _calculateLineNumberNullable( + // source, + // api.nonAttachedFields.first.offset, + // ), + // )); + // } + // + // for (final Constructor constructor in api.constructors) { + // for (final Parameter parameter in constructor.parameters) { + // if (customClasses.contains(parameter.type.baseName)) { + // result.add(unsupportedDataClassError(parameter)); + // } + // } + // } + // + // for (final Method method in api.methods) { + // for (final Parameter parameter in method.parameters) { + // if (customClasses.contains(parameter.type.baseName)) { + // result.add(unsupportedDataClassError(parameter)); + // } + // } + // + // if (method.location == ApiLocation.flutter && method.isStatic) { + // result.add(Error( + // message: 'Static callback methods are not supported: ${method.name}.', + // lineNumber: _calculateLineNumberNullable(source, method.offset), + // )); + // } + // } + // + // for (final Field field in api.fields) { + // if (customClasses.contains(field.type.baseN)) { + // result.add(unsupportedDataClassError(field)); + // } + // + // if (!field.type.isProxyApi) { + // if (field.isStatic) { + // print(field); + // result.add(Error( + // message: + // 'Static fields are considered attached fields and must be another ProxyApi: ${field.type.baseName}.', + // lineNumber: _calculateLineNumberNullable(source, field.offset), + // )); + // } else if (field.isAttached) { + // result.add(Error( + // message: + // 'Attached fields must be another ProxyApi: ${field.type.baseName}.', + // lineNumber: _calculateLineNumberNullable(source, field.offset), + // )); + // } + // } + // } + // + // return result; +} + class _FindInitializer extends dart_ast_visitor.RecursiveAstVisitor { dart_ast.Expression? initializer; @override @@ -966,7 +1041,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; } @@ -975,17 +1052,19 @@ 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(_attachClassesAndEnums(param.type)), + param.copyWithType(_attachClassesEnumsAndProxyApis(param.type)), ); } constructor.parameters = paramList; @@ -993,9 +1072,11 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { final List fieldList = []; for (final Field field in api.fields) { - fieldList.add(field.copyWithType(_attachClassesAndEnums(field.type))); - api.fields = fieldList; + fieldList.add(field.copyWithType( + _attachClassesEnumsAndProxyApis(field.type), + )); } + api.fields = fieldList; } } @@ -1008,15 +1089,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; } @@ -1494,7 +1581,8 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { ), ), name: node.fields.variables[0].name.lexeme, - isAttached: _hasMetadata(node.metadata, 'attached'), + isAttached: + _hasMetadata(node.metadata, 'attached') || isStatic, isStatic: isStatic, offset: node.offset, documentationComments: _documentationCommentsParser( diff --git a/packages/webview_flutter/webview_flutter_android/pubspec.yaml b/packages/webview_flutter/webview_flutter_android/pubspec.yaml index 92aa739c30f2..0d27fb8909d2 100644 --- a/packages/webview_flutter/webview_flutter_android/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_android/pubspec.yaml @@ -27,7 +27,8 @@ dev_dependencies: flutter_test: sdk: flutter mockito: 5.4.3 - pigeon: ^11.0.0 + pigeon: + path: ../../pigeon topics: - html From 38989708ee0576c15fed8a170a28ed9f7310de65 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 6 Dec 2023 01:11:28 -0500 Subject: [PATCH 12/73] use dart extends/implements --- packages/pigeon/lib/pigeon_lib.dart | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 773539c51e5b..d1ca7ae90dec 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -114,13 +114,7 @@ class FlutterApi { /// or static methods. class ProxyApi { /// Parametric constructor for [ProxyApi]. - const ProxyApi({this.superClass, this.interfaces = const {}}); - - /// The ProxyApi that this class extends. - final Type? superClass; - - /// The set of interfaces this class implements. - final Set interfaces; + const ProxyApi(); } /// Metadata to annotation methods to control the selector used for objc output. @@ -1257,10 +1251,11 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { methods: [], constructors: [], fields: [], - superClassName: annotationMap['superClass'] as String?, - interfacesNames: annotationMap['interfaces'] != null - ? (annotationMap['interfaces']! as Set).cast() - : {}, + superClassName: node.extendsClause?.superclass.name2.lexeme, + interfacesNames: node.implementsClause?.interfaces + .map((dart_ast.NamedType type) => type.name2.lexeme) + .toSet() ?? + {}, documentationComments: _documentationCommentsParser(node.documentationComment?.tokens), ); From e216947e38ed39cf00bbbb17e605b98a304dc618 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 6 Dec 2023 16:23:06 -0500 Subject: [PATCH 13/73] validate ast work --- packages/pigeon/lib/pigeon_lib.dart | 201 ++++++++++++++++++---------- 1 file changed, 129 insertions(+), 72 deletions(-) diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index d1ca7ae90dec..019121688f38 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -818,7 +818,13 @@ List _validateAst(Root root, String source) { } for (final Api api in root.apis) { if (api is AstProxyApi) { - result.addAll(_validateProxyApi(api, source, customClasses)); + result.addAll(_validateProxyApi( + api, + source, + customClasses: customClasses.toSet(), + customEnums: customEnums.toSet(), + proxyApis: root.apis.whereType().toSet(), + )); } for (final Method method in api.methods) { for (final Parameter param in method.parameters) { @@ -878,77 +884,128 @@ List _validateAst(Root root, String source) { List _validateProxyApi( AstProxyApi api, - String source, - List customClasses, -) { - return []; - // final List result = []; - // - // Error unsupportedDataClassError(NamedType type) { - // return Error( - // message: 'ProxyApis do not support data classes: ${type.type.baseName}.', - // lineNumber: _calculateLineNumberNullable(source, type.offset), - // ); - // } - // - // if (api.constructors.length > 1 && api.nonAttachedFields.isNotEmpty) { - // result.add(Error( - // message: - // 'ProxyApis with more than one constructor can not have any non attached fields: ${api.nonAttachedFields.first.name}', - // lineNumber: _calculateLineNumberNullable( - // source, - // api.nonAttachedFields.first.offset, - // ), - // )); - // } - // - // for (final Constructor constructor in api.constructors) { - // for (final Parameter parameter in constructor.parameters) { - // if (customClasses.contains(parameter.type.baseName)) { - // result.add(unsupportedDataClassError(parameter)); - // } - // } - // } - // - // for (final Method method in api.methods) { - // for (final Parameter parameter in method.parameters) { - // if (customClasses.contains(parameter.type.baseName)) { - // result.add(unsupportedDataClassError(parameter)); - // } - // } - // - // if (method.location == ApiLocation.flutter && method.isStatic) { - // result.add(Error( - // message: 'Static callback methods are not supported: ${method.name}.', - // lineNumber: _calculateLineNumberNullable(source, method.offset), - // )); - // } - // } - // - // for (final Field field in api.fields) { - // if (customClasses.contains(field.type.baseN)) { - // result.add(unsupportedDataClassError(field)); - // } - // - // if (!field.type.isProxyApi) { - // if (field.isStatic) { - // print(field); - // result.add(Error( - // message: - // 'Static fields are considered attached fields and must be another ProxyApi: ${field.type.baseName}.', - // lineNumber: _calculateLineNumberNullable(source, field.offset), - // )); - // } else if (field.isAttached) { - // result.add(Error( - // message: - // 'Attached fields must be another ProxyApi: ${field.type.baseName}.', - // lineNumber: _calculateLineNumberNullable(source, field.offset), - // )); - // } - // } - // } - // - // return result; + String source, { + required Set customClasses, + required Set customEnums, + required Set proxyApis, +}) { + final List result = []; + + bool isDataClass(NamedType type) => + customClasses.contains(type.type.baseName); + bool isEnum(NamedType type) => customEnums.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), + ); + } + + final List superClassChain = + recursiveGetSuperClassApisChain(api, proxyApis); + + // Verify that the api does not inherit a non attached field from its super class. + if (superClassChain.isNotEmpty && + superClassChain.first.nonAttachedFields.isNotEmpty) { + result.add(Error( + message: + 'Non attached fields can not be inherited. Non attached field found for parent class ${api.nonAttachedFields.first.name}', + lineNumber: _calculateLineNumberNullable( + source, + api.nonAttachedFields.first.offset, + ), + )); + } + + // Verify this api is not used as an attached field while either: + // 1. Having a non-attached field. + // 2. Having a required Flutter method. + final bool hasNonAttachedField = api.nonAttachedFields.isNotEmpty; + final bool hasRequiredFlutterMethod = + api.flutterMethods.any((Method method) => method.required); + if (hasNonAttachedField || hasRequiredFlutterMethod) { + for (final AstProxyApi proxyApi in proxyApis) { + for (final Field field in proxyApi.attachedFields) { + if (field.type.baseName == api.name) { + if (hasNonAttachedField) { + 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, + ), + )); + } + } + } + } + } + + // TODO: verify all super clases are proxy apis + // TODO: same for interfaces + + for (final String interfaceName in api.interfacesNames) { + //final + } + + for (final Constructor constructor in api.constructors) { + for (final Parameter parameter in constructor.parameters) { + if (isDataClass(parameter)) { + result.add(unsupportedDataClassError(parameter)); + } + } + } + + for (final Method method in api.methods) { + for (final Parameter parameter in method.parameters) { + if (isDataClass(parameter)) { + result.add(unsupportedDataClassError(parameter)); + } + } + + if (method.location == ApiLocation.flutter && method.isStatic) { + result.add(Error( + message: 'Static callback methods are not supported: ${method.name}.', + lineNumber: _calculateLineNumberNullable(source, method.offset), + )); + } + } + + for (final Field field in api.fields) { + if (isDataClass(field)) { + result.add(unsupportedDataClassError(field)); + } else if (!isProxyApi(field)) { + if (field.isStatic) { + result.add(Error( + message: + 'Static fields are considered attached fields and must be another ProxyApi: ${field.type.baseName}.', + lineNumber: _calculateLineNumberNullable(source, field.offset), + )); + } else if (field.isAttached) { + result.add(Error( + message: + 'Attached fields must be another ProxyApi: ${field.type.baseName}.', + lineNumber: _calculateLineNumberNullable(source, field.offset), + )); + } + } + } + + return result; } class _FindInitializer extends dart_ast_visitor.RecursiveAstVisitor { From 26044666d5e45a5ed829002f997c7092db15e5f7 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 7 Dec 2023 15:17:09 -0500 Subject: [PATCH 14/73] verify constructor parameters and that all classes are proxyapis --- packages/pigeon/lib/pigeon_lib.dart | 64 ++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 019121688f38..b7e8504df701 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -816,13 +816,35 @@ List _validateAst(Root root, String source) { } } } + + // Verify all super classes and interfaces for ProxyApis are other ProxyAps + final Iterable allProxyApis = root.apis.whereType(); + for (final AstProxyApi api in allProxyApis) { + final String? superClassName = api.superClassName; + if (api.superClassName != null && + !allProxyApis.any((AstProxyApi api) => api.name == superClassName)) { + result.add(Error( + message: + 'Super class of ${api.name} is not marked as a @ProxyApi: $superClassName', + )); + } + + for (final String interfaceName in api.interfacesNames) { + if (!allProxyApis.any((AstProxyApi api) => api.name == interfaceName)) { + result.add(Error( + message: + 'Interface of ${api.name} is not marked as a @ProxyApi: $interfaceName', + )); + } + } + } + for (final Api api in root.apis) { if (api is AstProxyApi) { result.addAll(_validateProxyApi( api, source, customClasses: customClasses.toSet(), - customEnums: customEnums.toSet(), proxyApis: root.apis.whereType().toSet(), )); } @@ -886,14 +908,12 @@ List _validateProxyApi( AstProxyApi api, String source, { required Set customClasses, - required Set customEnums, required Set proxyApis, }) { final List result = []; bool isDataClass(NamedType type) => customClasses.contains(type.type.baseName); - bool isEnum(NamedType type) => customEnums.contains(type.type.baseName); bool isProxyApi(NamedType type) => proxyApis.any( (AstProxyApi api) => api.name == type.type.baseName, ); @@ -955,18 +975,42 @@ List _validateProxyApi( } } - // TODO: verify all super clases are proxy apis - // TODO: same for interfaces - - for (final String interfaceName in api.interfacesNames) { - //final - } - for (final Constructor constructor in api.constructors) { for (final Parameter parameter in constructor.parameters) { if (isDataClass(parameter)) { result.add(unsupportedDataClassError(parameter)); } + + 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), + )); + } + } + 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), + )); + } } } From 8fdcca4ed603bfe12a9b93114581b4eb57659a47 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 8 Dec 2023 12:05:34 -0500 Subject: [PATCH 15/73] inheritance chaecker validator --- packages/pigeon/lib/pigeon_lib.dart | 83 ++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 12 deletions(-) diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index b7e8504df701..e2d44a5b94c1 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -12,7 +12,8 @@ import 'package:analyzer/dart/analysis/analysis_context.dart' show AnalysisContext; import 'package:analyzer/dart/analysis/analysis_context_collection.dart' show AnalysisContextCollection; -import 'package:analyzer/dart/analysis/results.dart' show ParsedUnitResult; +import 'package:analyzer/dart/analysis/results.dart' + show ParsedUnitResult, ErrorsResult; import 'package:analyzer/dart/analysis/session.dart' show AnalysisSession; import 'package:analyzer/dart/ast/ast.dart' as dart_ast; import 'package:analyzer/dart/ast/syntactic_entity.dart' @@ -114,7 +115,13 @@ class FlutterApi { /// or static methods. class ProxyApi { /// Parametric constructor for [ProxyApi]. - const 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. + final Type? superClass; } /// Metadata to annotation methods to control the selector used for objc output. @@ -781,7 +788,7 @@ extension _ObjectAs on Object { T? asNullable() => this as T?; } -List _validateAst(Root root, String source) { +Future> _validateAst(Root root, String source) async { final List result = []; final List customClasses = root.classes.map((Class x) => x.name).toList(); @@ -817,8 +824,9 @@ List _validateAst(Root root, String source) { } } - // Verify all super classes and interfaces for ProxyApis are other ProxyAps final Iterable allProxyApis = root.apis.whereType(); + + // Verify all super classes and interfaces for ProxyApis are other ProxyAps for (final AstProxyApi api in allProxyApis) { final String? superClassName = api.superClassName; if (api.superClassName != null && @@ -839,6 +847,8 @@ List _validateAst(Root root, String source) { } } + result.addAll(await _verifyProxyApisInheritance(allProxyApis)); + for (final Api api in root.apis) { if (api is AstProxyApi) { result.addAll(_validateProxyApi( @@ -904,6 +914,54 @@ List _validateAst(Root root, String source) { return result; } +// Verifies that the super classes and interfaces of ProxyApis don't cause an +// error. It creates a new file with just the class declarations and runs +// analysis on it. +Future> _verifyProxyApisInheritance( + Iterable proxyApis, +) async { + final List errors = []; + + final File tempFile = + File('${Directory.systemTemp.path}/pigeon_inheritance_check.dart'); + tempFile.createSync(); + + final StringBuffer testSource = StringBuffer(); + for (final AstProxyApi api in proxyApis) { + final String extendsClause = + api.superClassName != null ? 'extends ${api.superClassName}' : ''; + final String implementsClause = api.interfacesNames.isNotEmpty + ? 'implements ${api.interfacesNames.join(',')}' + : ''; + + testSource.writeln('class ${api.name} $extendsClause $implementsClause {}'); + } + + tempFile.writeAsStringSync(testSource.toString()); + + final AnalysisContextCollection collection = AnalysisContextCollection( + includedPaths: [tempFile.path], + ); + + for (final AnalysisContext context in collection.contexts) { + for (final String path in context.contextRoot.analyzedFiles()) { + final AnalysisSession session = context.currentSession; + + final ErrorsResult result = await session.getErrors(path) as ErrorsResult; + for (final AnalysisError error in result.errors) { + errors.add( + Error( + message: 'Error parsing ProxyApis: ${error.message}', + filename: error.source.fullName, + ), + ); + } + } + } + + return errors; +} + List _validateProxyApi( AstProxyApi api, String source, { @@ -1092,7 +1150,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { } } - ParseResults results() { + Future results() async { _storeCurrentApi(); _storeCurrentClass(); @@ -1108,7 +1166,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { final Root completeRoot = Root(apis: _apis, classes: referencedClasses, enums: referencedEnums); - final List validateErrors = _validateAst(completeRoot, source); + final List validateErrors = await _validateAst(completeRoot, source); final List totalErrors = List.from(_errors); totalErrors.addAll(validateErrors); @@ -1352,7 +1410,8 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { methods: [], constructors: [], fields: [], - superClassName: node.extendsClause?.superclass.name2.lexeme, + superClassName: annotationMap['superClass'] as String? ?? + node.extendsClause?.superclass.name2.lexeme, interfacesNames: node.implementsClause?.interfaces .map((dart_ast.NamedType type) => type.name2.lexeme) .toSet() ?? @@ -1787,7 +1846,7 @@ class Pigeon { /// it. [types] optionally filters out what datatypes are actually parsed. /// [sdkPath] for specifying the Dart SDK path for /// [AnalysisContextCollection]. - ParseResults parseFile(String inputPath, {String? sdkPath}) { + Future parseFile(String inputPath, {String? sdkPath}) async { final List includedPaths = [ path.absolute(path.normalize(inputPath)) ]; @@ -1906,7 +1965,7 @@ ${_argParser.usage}'''; help: 'The package that generated code will be in.'); /// Convert command-line arguments to [PigeonOptions]. - static PigeonOptions parseArgs(List args) { + static Future parseArgs(List args) async { // Note: This function shouldn't perform any logic, just translate the args // to PigeonOptions. Synthesized values inside of the PigeonOption should // get set in the `run` function to accommodate users that are using the @@ -1972,8 +2031,8 @@ ${_argParser.usage}'''; /// customize the generators that pigeon will use. The optional parameter /// [sdkPath] allows you to specify the Dart SDK path. static Future run(List args, - {List? adapters, String? sdkPath}) { - final PigeonOptions options = Pigeon.parseArgs(args); + {List? adapters, String? sdkPath}) async { + final PigeonOptions options = await Pigeon.parseArgs(args); return runWithOptions(options, adapters: adapters, sdkPath: sdkPath); } @@ -2006,7 +2065,7 @@ ${_argParser.usage}'''; } final ParseResults parseResults = - pigeon.parseFile(options.input!, sdkPath: sdkPath); + await pigeon.parseFile(options.input!, sdkPath: sdkPath); final List errors = []; errors.addAll(parseResults.errors); From 5863c6853f5fa3a228d681389b31c91a23a91c91 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 8 Dec 2023 12:20:26 -0500 Subject: [PATCH 16/73] fix tests --- packages/pigeon/lib/pigeon_lib.dart | 9 +- packages/pigeon/test/pigeon_lib_test.dart | 316 +++++++++++----------- 2 files changed, 167 insertions(+), 158 deletions(-) diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index e2d44a5b94c1..5e32ce8ddc56 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -847,7 +847,7 @@ Future> _validateAst(Root root, String source) async { } } - result.addAll(await _verifyProxyApisInheritance(allProxyApis)); + result.addAll(await _validateProxyApisInheritance(allProxyApis)); for (final Api api in root.apis) { if (api is AstProxyApi) { @@ -917,10 +917,15 @@ Future> _validateAst(Root root, String source) async { // Verifies that the super classes and interfaces of ProxyApis don't cause an // error. It creates a new file with just the class declarations and runs // analysis on it. -Future> _verifyProxyApisInheritance( +// +// This method is really slow, so it doesn't run if proxyApis is empty. +Future> _validateProxyApisInheritance( Iterable proxyApis, ) async { final List errors = []; + if (proxyApis.isEmpty) { + return errors; + } final File tempFile = File('${Directory.systemTemp.path}/pigeon_inheritance_check.dart'); diff --git a/packages/pigeon/test/pigeon_lib_test.dart b/packages/pigeon/test/pigeon_lib_test.dart index 4dc956bd200c..01222b72fb61 100644 --- a/packages/pigeon/test/pigeon_lib_test.dart +++ b/packages/pigeon/test/pigeon_lib_test.dart @@ -40,118 +40,122 @@ void main() { /// Creates a temporary file named [filename] then calls [callback] with a /// [File] representing that temporary directory. The file will be deleted /// after the [callback] is executed. - void withTempFile(String filename, void Function(File) callback) { + Future withTempFile( + String filename, + Future Function(File) callback, + ) async { final Directory dir = Directory.systemTemp.createTempSync(); final String path = '${dir.path}/$filename'; final File file = File(path); file.createSync(); try { - callback(file); + await callback(file); } finally { dir.deleteSync(recursive: true); } } - ParseResults parseSource(String source) { + Future parseSource(String source) async { final Pigeon dartle = Pigeon.setup(); ParseResults? results; - withTempFile('source.dart', (File file) { + await withTempFile('source.dart', (File file) async { file.writeAsStringSync(source); - results = dartle.parseFile(file.path); + results = await dartle.parseFile(file.path); }); return results!; } - test('parse args - input', () { + test('parse args - input', () async { final PigeonOptions opts = - Pigeon.parseArgs(['--input', 'foo.dart']); + await Pigeon.parseArgs(['--input', 'foo.dart']); expect(opts.input, equals('foo.dart')); }); - test('parse args - dart_out', () { + test('parse args - dart_out', () async { final PigeonOptions opts = - Pigeon.parseArgs(['--dart_out', 'foo.dart']); + await Pigeon.parseArgs(['--dart_out', 'foo.dart']); expect(opts.dartOut, equals('foo.dart')); }); - test('parse args - java_package', () { + test('parse args - java_package', () async { final PigeonOptions opts = - Pigeon.parseArgs(['--java_package', 'com.google.foo']); + await Pigeon.parseArgs(['--java_package', 'com.google.foo']); expect(opts.javaOptions?.package, equals('com.google.foo')); }); - test('parse args - input', () { + test('parse args - input', () async { final PigeonOptions opts = - Pigeon.parseArgs(['--java_out', 'foo.java']); + await Pigeon.parseArgs(['--java_out', 'foo.java']); expect(opts.javaOut, equals('foo.java')); }); - test('parse args - objc_header_out', () { + test('parse args - objc_header_out', () async { final PigeonOptions opts = - Pigeon.parseArgs(['--objc_header_out', 'foo.h']); + await Pigeon.parseArgs(['--objc_header_out', 'foo.h']); expect(opts.objcHeaderOut, equals('foo.h')); }); - test('parse args - objc_source_out', () { + test('parse args - objc_source_out', () async { final PigeonOptions opts = - Pigeon.parseArgs(['--objc_source_out', 'foo.m']); + await Pigeon.parseArgs(['--objc_source_out', 'foo.m']); expect(opts.objcSourceOut, equals('foo.m')); }); - test('parse args - swift_out', () { + test('parse args - swift_out', () async { final PigeonOptions opts = - Pigeon.parseArgs(['--swift_out', 'Foo.swift']); + await Pigeon.parseArgs(['--swift_out', 'Foo.swift']); expect(opts.swiftOut, equals('Foo.swift')); }); - test('parse args - kotlin_out', () { + test('parse args - kotlin_out', () async { final PigeonOptions opts = - Pigeon.parseArgs(['--kotlin_out', 'Foo.kt']); + await Pigeon.parseArgs(['--kotlin_out', 'Foo.kt']); expect(opts.kotlinOut, equals('Foo.kt')); }); - test('parse args - kotlin_package', () { + test('parse args - kotlin_package', () async { final PigeonOptions opts = - Pigeon.parseArgs(['--kotlin_package', 'com.google.foo']); + await Pigeon.parseArgs(['--kotlin_package', 'com.google.foo']); expect(opts.kotlinOptions?.package, equals('com.google.foo')); }); - test('parse args - cpp_header_out', () { + test('parse args - cpp_header_out', () async { final PigeonOptions opts = - Pigeon.parseArgs(['--cpp_header_out', 'foo.h']); + await Pigeon.parseArgs(['--cpp_header_out', 'foo.h']); expect(opts.cppHeaderOut, equals('foo.h')); }); - test('parse args - java_use_generated_annotation', () { + test('parse args - java_use_generated_annotation', () async { final PigeonOptions opts = - Pigeon.parseArgs(['--java_use_generated_annotation']); + await Pigeon.parseArgs(['--java_use_generated_annotation']); expect(opts.javaOptions!.useGeneratedAnnotation, isTrue); }); - test('parse args - cpp_source_out', () { + test('parse args - cpp_source_out', () async { final PigeonOptions opts = - Pigeon.parseArgs(['--cpp_source_out', 'foo.cpp']); + await Pigeon.parseArgs(['--cpp_source_out', 'foo.cpp']); expect(opts.cppSourceOut, equals('foo.cpp')); }); - test('parse args - one_language', () { - final PigeonOptions opts = Pigeon.parseArgs(['--one_language']); + test('parse args - one_language', () async { + final PigeonOptions opts = + await Pigeon.parseArgs(['--one_language']); expect(opts.oneLanguage, isTrue); }); - test('parse args - ast_out', () { + test('parse args - ast_out', () async { final PigeonOptions opts = - Pigeon.parseArgs(['--ast_out', 'stdout']); + await Pigeon.parseArgs(['--ast_out', 'stdout']); expect(opts.astOut, equals('stdout')); }); - test('parse args - base_path', () { + test('parse args - base_path', () async { final PigeonOptions opts = - Pigeon.parseArgs(['--base_path', './foo/']); + await Pigeon.parseArgs(['--base_path', './foo/']); expect(opts.basePath, equals('./foo/')); }); - test('simple parse api', () { + test('simple parse api', () async { const String code = ''' class Input1 { String? input; @@ -166,7 +170,7 @@ abstract class Api1 { Output1 doit(Input1 input); } '''; - final ParseResults parseResult = parseSource(code); + final ParseResults parseResult = await parseSource(code); expect(parseResult.errors.length, equals(0)); final Root root = parseResult.root; expect(root.classes.length, equals(2)); @@ -202,7 +206,7 @@ abstract class Api1 { expect(output?.fields[0].type.isNullable, isTrue); }); - test('invalid datatype', () { + test('invalid datatype', () async { const String source = ''' class InvalidDatatype { dynamic something; @@ -213,13 +217,13 @@ abstract class Api { InvalidDatatype foo(); } '''; - final ParseResults results = parseSource(source); + final ParseResults results = await parseSource(source); expect(results.errors.length, 1); expect(results.errors[0].message, contains('InvalidDatatype')); expect(results.errors[0].message, contains('dynamic')); }); - test('enum in classes', () { + test('enum in classes', () async { const String code = ''' enum Enum1 { one, @@ -235,7 +239,7 @@ abstract class Api { ClassWithEnum foo(); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, equals(0)); expect(results.root.classes.length, equals(1)); expect(results.root.classes[0].name, equals('ClassWithEnum')); @@ -245,7 +249,7 @@ abstract class Api { expect(results.root.classes[0].fields[0].name, equals('enum1')); }); - test('two methods', () { + test('two methods', () async { const String code = ''' class Input1 { String? input; @@ -261,7 +265,7 @@ abstract class ApiTwoMethods { Output1 method2(Input1 input); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 0); expect(results.root.apis.length, 1); expect(results.root.apis[0].methods.length, equals(2)); @@ -269,7 +273,7 @@ abstract class ApiTwoMethods { expect(results.root.apis[0].methods[1].name, equals('method2')); }); - test('nested', () { + test('nested', () async { const String code = ''' class Input1 { String? input; @@ -284,7 +288,7 @@ abstract class Api { Nested foo(); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, equals(0)); expect(results.root.classes.length, equals(2)); final Class nested = @@ -294,7 +298,7 @@ abstract class Api { expect(nested.fields[0].type.isNullable, isTrue); }); - test('flutter api', () { + test('flutter api', () async { const String code = ''' class Input1 { String? input; @@ -309,14 +313,14 @@ abstract class AFlutterApi { Output1 doit(Input1 input); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); 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], isA()); }); - test('void host api', () { + test('void host api', () async { const String code = ''' class Input1 { String? input; @@ -327,7 +331,7 @@ abstract class VoidApi { void doit(Input1 input); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, equals(0)); expect(results.root.apis.length, equals(1)); expect(results.root.apis[0].methods.length, equals(1)); @@ -335,7 +339,7 @@ abstract class VoidApi { expect(results.root.apis[0].methods[0].returnType.isVoid, isTrue); }); - test('void arg host api', () { + test('void arg host api', () async { const String code = ''' class Output1 { String? output; @@ -346,7 +350,7 @@ abstract class VoidArgApi { Output1 doit(); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, equals(0)); expect(results.root.apis.length, equals(1)); expect(results.root.apis[0].methods.length, equals(1)); @@ -356,7 +360,7 @@ abstract class VoidArgApi { expect(results.root.apis[0].methods[0].parameters.isEmpty, isTrue); }); - test('mockDartClass', () { + test('mockDartClass', () async { const String code = ''' class Output1 { String? output; @@ -367,14 +371,14 @@ abstract class ApiWithMockDartClass { Output1 doit(); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, equals(0)); expect(results.root.apis.length, equals(1)); expect((results.root.apis[0] as AstHostApi).dartHostTestHandler, equals('ApiWithMockDartClassMock')); }); - test('only visible from nesting', () { + test('only visible from nesting', () async { const String code = ''' class OnlyVisibleFromNesting { String? foo; @@ -389,7 +393,7 @@ abstract class NestorApi { Nestor getit(); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 0); expect(results.root.apis.length, 1); final List classNames = @@ -399,9 +403,9 @@ abstract class NestorApi { expect(classNames.contains('OnlyVisibleFromNesting'), true); }); - test('copyright flag', () { + test('copyright flag', () async { final PigeonOptions results = - Pigeon.parseArgs(['--copyright_header', 'foobar.txt']); + await Pigeon.parseArgs(['--copyright_header', 'foobar.txt']); expect(results.copyrightHeader, 'foobar.txt'); }); @@ -478,7 +482,7 @@ abstract class NestorApi { expect(buffer.toString(), startsWith('// Copyright 2013')); }); - test('nested enum', () { + test('nested enum', () async { const String code = ''' enum NestedEnum { one, two } @@ -500,14 +504,14 @@ abstract class NestedEnumApi { void method(NestedEnum3 foo); } '''; - final ParseResults parseResult = parseSource(code); + final ParseResults parseResult = await parseSource(code); expect(parseResult.errors.length, equals(0)); expect(parseResult.root.apis.length, 1); expect(parseResult.root.classes.length, 3); expect(parseResult.root.enums.length, 1); }); - test('test circular references', () { + test('test circular references', () async { const String code = ''' class Foo { Bar? bar; @@ -522,7 +526,7 @@ abstract class NotificationsHostApi { void doit(Foo foo); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 0); expect(results.root.classes.length, 2); final Class foo = @@ -531,14 +535,14 @@ abstract class NotificationsHostApi { expect(foo.fields[0].type.baseName, 'Bar'); }); - test('test compilation error', () { + test('test compilation error', () async { const String code = 'Hello\n'; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, greaterThanOrEqualTo(1)); expect(results.errors[0].lineNumber, 1); }); - test('test method in data class error', () { + test('test method in data class error', () async { const String code = ''' class Foo { int? x; @@ -550,13 +554,13 @@ abstract class Api { Foo doit(Foo foo); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 3); expect(results.errors[0].message, contains('Method')); }); - test('test field initialization', () { + test('test field initialization', () async { const String code = ''' class Foo { int? x = 123; @@ -567,13 +571,13 @@ abstract class Api { Foo doit(Foo foo); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 2); expect(results.errors[0].message, contains('Initialization')); }); - test('test field in api error', () { + test('test field in api error', () async { const String code = ''' class Foo { int? x; @@ -585,13 +589,13 @@ abstract class Api { Foo doit(Foo foo); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 7); expect(results.errors[0].message, contains('Field')); }); - test('constructor in data class', () { + test('constructor in data class', () async { const String code = ''' class Foo { int? x; @@ -603,11 +607,11 @@ abstract class Api { Foo doit(Foo foo); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 0); }); - test('constructor body in data class', () { + test('constructor body in data class', () async { const String code = ''' class Foo { int? x; @@ -619,13 +623,13 @@ abstract class Api { Foo doit(Foo foo); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 3); expect(results.errors[0].message, contains('Constructor')); }); - test('constructor body in data class', () { + test('constructor body in data class', () async { const String code = ''' class Foo { int? x; @@ -637,13 +641,13 @@ abstract class Api { Foo doit(Foo foo); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 3); expect(results.errors[0].message, contains('Constructor')); }); - test('constructor in api class', () { + test('constructor in api class', () async { const String code = ''' class Foo { int? x; @@ -655,26 +659,26 @@ abstract class Api { Foo doit(Foo foo); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 7); expect(results.errors[0].message, contains('Constructor')); }); - test('test invalid import', () { + test('test invalid import', () async { const String code = "import 'foo.dart';\n"; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, greaterThanOrEqualTo(1)); expect(results.errors[0].lineNumber, 1); }); - test('test valid import', () { + test('test valid import', () async { const String code = "import 'package:pigeon/pigeon.dart';\n"; - final ParseResults parseResults = parseSource(code); + final ParseResults parseResults = await parseSource(code); expect(parseResults.errors.length, 0); }); - test('error with static field', () { + test('error with static field', () async { const String code = ''' class WithStaticField { static int? x; @@ -686,13 +690,13 @@ abstract class WithStaticFieldApi { void doit(WithStaticField withTemplate); } '''; - final ParseResults parseResult = parseSource(code); + final ParseResults parseResult = await parseSource(code); expect(parseResult.errors.length, equals(1)); expect(parseResult.errors[0].message, contains('static field')); expect(parseResult.errors[0].lineNumber, isNotNull); }); - test('parse generics', () { + test('parse generics', () async { const String code = ''' class Foo { List? list; @@ -703,14 +707,14 @@ abstract class Api { void doit(Foo foo); } '''; - final ParseResults parseResult = parseSource(code); + final ParseResults parseResult = await parseSource(code); expect(parseResult.errors.length, equals(0)); final NamedType field = parseResult.root.classes[0].fields[0]; expect(field.type.typeArguments.length, 1); expect(field.type.typeArguments[0].baseName, 'int'); }); - test('parse recursive generics', () { + test('parse recursive generics', () async { const String code = ''' class Foo { List?>? list; @@ -721,7 +725,7 @@ abstract class Api { void doit(Foo foo); } '''; - final ParseResults parseResult = parseSource(code); + final ParseResults parseResult = await parseSource(code); expect(parseResult.errors.length, equals(0)); final NamedType field = parseResult.root.classes[0].fields[0]; expect(field.type.typeArguments.length, 1); @@ -729,7 +733,7 @@ abstract class Api { expect(field.type.typeArguments[0].typeArguments[0].baseName, 'int'); }); - test('error nonnull type argument', () { + test('error nonnull type argument', () async { const String code = ''' class Foo { List list; @@ -740,7 +744,7 @@ abstract class Api { void doit(Foo foo); } '''; - final ParseResults parseResult = parseSource(code); + final ParseResults parseResult = await parseSource(code); expect(parseResult.errors.length, equals(1)); expect(parseResult.errors[0].message, contains('Generic type parameters must be nullable')); @@ -748,7 +752,7 @@ abstract class Api { expect(parseResult.errors[0].lineNumber, 2); }); - test('enums argument host', () { + test('enums argument host', () async { const String code = ''' enum Foo { one, @@ -760,11 +764,11 @@ abstract class Api { void doit(Foo foo); } '''; - final ParseResults parseResult = parseSource(code); + final ParseResults parseResult = await parseSource(code); expect(parseResult.errors.length, equals(0)); }); - test('enums argument flutter', () { + test('enums argument flutter', () async { const String code = ''' enum Foo { @@ -777,11 +781,11 @@ abstract class Api { void doit(Foo foo); } '''; - final ParseResults parseResult = parseSource(code); + final ParseResults parseResult = await parseSource(code); expect(parseResult.errors.length, equals(0)); }); - test('enums list argument', () { + test('enums list argument', () async { const String code = ''' enum Foo { one, two } @@ -790,11 +794,11 @@ abstract class Api { void doit(List foo); } '''; - final ParseResults parseResult = parseSource(code); + final ParseResults parseResult = await parseSource(code); expect(parseResult.errors.length, equals(0)); }); - test('enums map argument key', () { + test('enums map argument key', () async { const String code = ''' enum Foo { one, two } @@ -803,11 +807,11 @@ abstract class Api { void doit(Map foo); } '''; - final ParseResults parseResult = parseSource(code); + final ParseResults parseResult = await parseSource(code); expect(parseResult.errors.length, equals(0)); }); - test('enums map argument value', () { + test('enums map argument value', () async { const String code = ''' enum Foo { one, two } @@ -816,11 +820,11 @@ abstract class Api { void doit(Map foo); } '''; - final ParseResults parseResult = parseSource(code); + final ParseResults parseResult = await parseSource(code); expect(parseResult.errors.length, equals(0)); }); - test('enums return value', () { + test('enums return value', () async { const String code = ''' enum Foo { @@ -833,18 +837,18 @@ abstract class Api { Foo doit(); } '''; - final ParseResults parseResult = parseSource(code); + final ParseResults parseResult = await parseSource(code); expect(parseResult.errors.length, equals(0)); }); - test('return type generics', () { + test('return type generics', () async { const String code = ''' @HostApi() abstract class Api { List doit(); } '''; - final ParseResults parseResult = parseSource(code); + final ParseResults parseResult = await parseSource(code); expect(parseResult.root.apis[0].methods[0].returnType.baseName, 'List'); expect( parseResult @@ -856,14 +860,14 @@ abstract class Api { isTrue); }); - test('argument generics', () { + test('argument generics', () async { const String code = ''' @HostApi() abstract class Api { void doit(int x, List value); } '''; - final ParseResults parseResult = parseSource(code); + final ParseResults parseResult = await parseSource(code); expect(parseResult.root.apis[0].methods[0].parameters[1].type.baseName, 'List'); expect( @@ -876,7 +880,7 @@ abstract class Api { isTrue); }); - test('map generics', () { + test('map generics', () async { const String code = ''' class Foo { Map map; @@ -887,14 +891,14 @@ abstract class Api { void doit(Foo foo); } '''; - final ParseResults parseResult = parseSource(code); + final ParseResults parseResult = await parseSource(code); final NamedType field = parseResult.root.classes[0].fields[0]; expect(field.type.typeArguments.length, 2); expect(field.type.typeArguments[0].baseName, 'String'); expect(field.type.typeArguments[1].baseName, 'int'); }); - test('two parameters', () { + test('two parameters', () async { const String code = ''' class Input { String? input; @@ -905,28 +909,28 @@ abstract class Api { void method(Input input1, Input input2); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.root.apis.length, 1); expect(results.root.apis[0].methods.length, equals(1)); expect(results.root.apis[0].methods[0].name, equals('method')); expect(results.root.apis[0].methods[0].parameters.length, 2); }); - test('no type name argument', () { + test('no type name argument', () async { const String code = ''' @HostApi() abstract class Api { void method(x); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 3); expect(results.errors[0].message, contains('Parameters must specify their type')); }); - test('custom objc selector', () { + test('custom objc selector', () async { const String code = ''' @HostApi() abstract class Api { @@ -934,7 +938,7 @@ abstract class Api { void subtract(int x, int y); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 0); expect(results.root.apis.length, 1); expect(results.root.apis[0].methods.length, equals(1)); @@ -942,7 +946,7 @@ abstract class Api { equals('subtractValue:by:')); }); - test('custom objc invalid selector', () { + test('custom objc invalid selector', () async { const String code = ''' @HostApi() abstract class Api { @@ -950,14 +954,14 @@ abstract class Api { void subtract(int x, int y); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 3); expect(results.errors[0].message, contains('Invalid selector, expected 2 parameters')); }); - test('custom objc no parameters', () { + test('custom objc no parameters', () async { const String code = ''' @HostApi() abstract class Api { @@ -965,14 +969,14 @@ abstract class Api { void initialize(); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 0); expect(results.root.apis.length, 1); expect(results.root.apis[0].methods.length, equals(1)); expect(results.root.apis[0].methods[0].objcSelector, equals('foobar')); }); - test('custom swift valid function signature', () { + test('custom swift valid function signature', () async { const String code = ''' @HostApi() abstract class Api { @@ -980,7 +984,7 @@ abstract class Api { void subtract(int x, int y); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 0); expect(results.root.apis.length, 1); expect(results.root.apis[0].methods.length, equals(1)); @@ -988,7 +992,7 @@ abstract class Api { equals('subtractValue(_:by:)')); }); - test('custom swift invalid function signature', () { + test('custom swift invalid function signature', () async { const String code = ''' @HostApi() abstract class Api { @@ -996,14 +1000,14 @@ abstract class Api { void subtract(int x, int y); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 3); expect(results.errors[0].message, contains('Invalid function signature, expected 2 parameters')); }); - test('custom swift function signature no parameters', () { + test('custom swift function signature no parameters', () async { const String code = ''' @HostApi() abstract class Api { @@ -1011,7 +1015,7 @@ abstract class Api { void initialize(); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 0); expect(results.root.apis.length, 1); expect(results.root.apis[0].methods.length, equals(1)); @@ -1032,7 +1036,7 @@ abstract class Api { expect(buffer.toString(), startsWith('// Copyright 2013')); }); - test('only class reference is type argument for return value', () { + test('only class reference is type argument for return value', () async { const String code = ''' class Foo { int? foo; @@ -1043,13 +1047,13 @@ abstract class Api { List grabAll(); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 0); expect(results.root.classes.length, 1); expect(results.root.classes[0].name, 'Foo'); }); - test('only class reference is type argument for argument', () { + test('only class reference is type argument for argument', () async { const String code = ''' class Foo { int? foo; @@ -1060,13 +1064,13 @@ abstract class Api { void storeAll(List foos); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 0); expect(results.root.classes.length, 1); expect(results.root.classes[0].name, 'Foo'); }); - test('recurse into type parameters', () { + test('recurse into type parameters', () async { const String code = ''' class Foo { int? foo; @@ -1082,7 +1086,7 @@ abstract class Api { void storeAll(List foos); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 0); expect(results.root.classes.length, 2); expect( @@ -1097,31 +1101,31 @@ abstract class Api { 1); }); - test('undeclared class in argument type argument', () { + test('undeclared class in argument type argument', () async { const String code = ''' @HostApi() abstract class Api { void storeAll(List foos); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 3); expect(results.errors[0].message, contains('Unknown type: Foo')); }); - test('Object type argument', () { + test('Object type argument', () async { const String code = ''' @HostApi() abstract class Api { void storeAll(List foos); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 0); }); - test('Enum key not supported', () { + test('Enum key not supported', () async { const String code = ''' enum MessageKey { title, @@ -1139,11 +1143,11 @@ abstract class HostApiBridge { void sendMessage(Message message); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 1); }); - test('Export unreferenced enums', () { + test('Export unreferenced enums', () async { const String code = ''' enum MessageKey { title, @@ -1161,12 +1165,12 @@ abstract class HostApiBridge { void sendMessage(Message message); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.root.enums.length, 1); expect(results.root.enums[0].name, 'MessageKey'); }); - test('@ConfigurePigeon JavaOptions.copyrightHeader', () { + test('@ConfigurePigeon JavaOptions.copyrightHeader', () async { const String code = ''' @ConfigurePigeon(PigeonOptions( javaOptions: JavaOptions(copyrightHeader: ['A', 'Header']), @@ -1176,12 +1180,12 @@ class Message { } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); final PigeonOptions options = PigeonOptions.fromMap(results.pigeonOptions!); expect(options.javaOptions!.copyrightHeader, ['A', 'Header']); }); - test('@ConfigurePigeon DartOptions.copyrightHeader', () { + test('@ConfigurePigeon DartOptions.copyrightHeader', () async { const String code = ''' @ConfigurePigeon(PigeonOptions( dartOptions: DartOptions(copyrightHeader: ['A', 'Header']), @@ -1191,12 +1195,12 @@ class Message { } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); final PigeonOptions options = PigeonOptions.fromMap(results.pigeonOptions!); expect(options.dartOptions!.copyrightHeader, ['A', 'Header']); }); - test('@ConfigurePigeon ObjcOptions.copyrightHeader', () { + test('@ConfigurePigeon ObjcOptions.copyrightHeader', () async { const String code = ''' @ConfigurePigeon(PigeonOptions( objcOptions: ObjcOptions(copyrightHeader: ['A', 'Header']), @@ -1206,12 +1210,12 @@ class Message { } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); final PigeonOptions options = PigeonOptions.fromMap(results.pigeonOptions!); expect(options.objcOptions!.copyrightHeader, ['A', 'Header']); }); - test('return nullable', () { + test('return nullable', () async { const String code = ''' @HostApi() abstract class Api { @@ -1219,25 +1223,25 @@ abstract class Api { } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 0); expect(results.root.apis[0].methods[0].returnType.isNullable, isTrue); }); - test('nullable parameters', () { + test('nullable parameters', () async { const String code = ''' @HostApi() abstract class Api { void calc(int? value); } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 0); expect( results.root.apis[0].methods[0].parameters[0].type.isNullable, isTrue); }); - test('task queue specified', () { + test('task queue specified', () async { const String code = ''' @HostApi() abstract class Api { @@ -1246,13 +1250,13 @@ abstract class Api { } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 0); expect(results.root.apis[0].methods[0].taskQueueType, equals(TaskQueueType.serialBackgroundThread)); }); - test('task queue unspecified', () { + test('task queue unspecified', () async { const String code = ''' @HostApi() abstract class Api { @@ -1260,13 +1264,13 @@ abstract class Api { } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 0); expect(results.root.apis[0].methods[0].taskQueueType, equals(TaskQueueType.serial)); }); - test('unsupported task queue on FlutterApi', () { + test('unsupported task queue on FlutterApi', () async { const String code = ''' @FlutterApi() abstract class Api { @@ -1275,7 +1279,7 @@ abstract class Api { } '''; - final ParseResults results = parseSource(code); + final ParseResults results = await parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].message, contains('Unsupported TaskQueue specification')); @@ -1283,7 +1287,7 @@ abstract class Api { test('generator validation', () async { final Completer completer = Completer(); - withTempFile('foo.dart', (File input) async { + await withTempFile('foo.dart', (File input) async { final _ValidatorGeneratorAdapter generator = _ValidatorGeneratorAdapter(stdout); final int result = await Pigeon.run(['--input', input.path], @@ -1297,7 +1301,7 @@ abstract class Api { test('generator validation skipped', () async { final Completer completer = Completer(); - withTempFile('foo.dart', (File input) async { + await withTempFile('foo.dart', (File input) async { final _ValidatorGeneratorAdapter generator = _ValidatorGeneratorAdapter(null); final int result = await Pigeon.run( @@ -1312,7 +1316,7 @@ abstract class Api { test('run with PigeonOptions', () async { final Completer completer = Completer(); - withTempFile('foo.dart', (File input) async { + await withTempFile('foo.dart', (File input) async { final _ValidatorGeneratorAdapter generator = _ValidatorGeneratorAdapter(null); final int result = await Pigeon.runWithOptions( From b7ec6ca66aaa78929c21be6919139f5648a2654f Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 8 Dec 2023 13:45:11 -0500 Subject: [PATCH 17/73] undo making validate async --- packages/pigeon/lib/generator_tools.dart | 12 + packages/pigeon/lib/pigeon_lib.dart | 77 +----- packages/pigeon/test/pigeon_lib_test.dart | 322 +++++++++++----------- 3 files changed, 182 insertions(+), 229 deletions(-) diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index c802450e6147..eebf9a64dc91 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -659,6 +659,9 @@ Set recursiveFindAllInterfacesApis( } /// Recursively find super classes for a ProxyApi and return them in order. +/// +/// This method assumes the super classes of each ProxyApi doesn't create a +/// loop. Throws a [StateError] if a loop is found. List recursiveGetSuperClassApisChain( AstProxyApi proxyApi, Iterable allProxyApis, @@ -667,6 +670,15 @@ List recursiveGetSuperClassApisChain( String? currentProxyApiName = proxyApi.superClassName; while (currentProxyApiName != null) { + if (proxyApis.length > allProxyApis.length) { + final Iterable apiNames = proxyApis.map( + (AstProxyApi api) => api.name, + ); + throw StateError( + '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) { diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 5e32ce8ddc56..374fb3d20372 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -12,8 +12,7 @@ import 'package:analyzer/dart/analysis/analysis_context.dart' show AnalysisContext; import 'package:analyzer/dart/analysis/analysis_context_collection.dart' show AnalysisContextCollection; -import 'package:analyzer/dart/analysis/results.dart' - show ParsedUnitResult, ErrorsResult; +import 'package:analyzer/dart/analysis/results.dart' show ParsedUnitResult; import 'package:analyzer/dart/analysis/session.dart' show AnalysisSession; import 'package:analyzer/dart/ast/ast.dart' as dart_ast; import 'package:analyzer/dart/ast/syntactic_entity.dart' @@ -788,7 +787,7 @@ extension _ObjectAs on Object { T? asNullable() => this as T?; } -Future> _validateAst(Root root, String source) async { +List _validateAst(Root root, String source) { final List result = []; final List customClasses = root.classes.map((Class x) => x.name).toList(); @@ -824,9 +823,8 @@ Future> _validateAst(Root root, String source) async { } } - final Iterable allProxyApis = root.apis.whereType(); - // Verify all super classes and interfaces for ProxyApis are other ProxyAps + final Iterable allProxyApis = root.apis.whereType(); for (final AstProxyApi api in allProxyApis) { final String? superClassName = api.superClassName; if (api.superClassName != null && @@ -847,8 +845,6 @@ Future> _validateAst(Root root, String source) async { } } - result.addAll(await _validateProxyApisInheritance(allProxyApis)); - for (final Api api in root.apis) { if (api is AstProxyApi) { result.addAll(_validateProxyApi( @@ -914,59 +910,6 @@ Future> _validateAst(Root root, String source) async { return result; } -// Verifies that the super classes and interfaces of ProxyApis don't cause an -// error. It creates a new file with just the class declarations and runs -// analysis on it. -// -// This method is really slow, so it doesn't run if proxyApis is empty. -Future> _validateProxyApisInheritance( - Iterable proxyApis, -) async { - final List errors = []; - if (proxyApis.isEmpty) { - return errors; - } - - final File tempFile = - File('${Directory.systemTemp.path}/pigeon_inheritance_check.dart'); - tempFile.createSync(); - - final StringBuffer testSource = StringBuffer(); - for (final AstProxyApi api in proxyApis) { - final String extendsClause = - api.superClassName != null ? 'extends ${api.superClassName}' : ''; - final String implementsClause = api.interfacesNames.isNotEmpty - ? 'implements ${api.interfacesNames.join(',')}' - : ''; - - testSource.writeln('class ${api.name} $extendsClause $implementsClause {}'); - } - - tempFile.writeAsStringSync(testSource.toString()); - - final AnalysisContextCollection collection = AnalysisContextCollection( - includedPaths: [tempFile.path], - ); - - for (final AnalysisContext context in collection.contexts) { - for (final String path in context.contextRoot.analyzedFiles()) { - final AnalysisSession session = context.currentSession; - - final ErrorsResult result = await session.getErrors(path) as ErrorsResult; - for (final AnalysisError error in result.errors) { - errors.add( - Error( - message: 'Error parsing ProxyApis: ${error.message}', - filename: error.source.fullName, - ), - ); - } - } - } - - return errors; -} - List _validateProxyApi( AstProxyApi api, String source, { @@ -1155,7 +1098,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { } } - Future results() async { + ParseResults results() { _storeCurrentApi(); _storeCurrentClass(); @@ -1171,7 +1114,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { final Root completeRoot = Root(apis: _apis, classes: referencedClasses, enums: referencedEnums); - final List validateErrors = await _validateAst(completeRoot, source); + final List validateErrors = _validateAst(completeRoot, source); final List totalErrors = List.from(_errors); totalErrors.addAll(validateErrors); @@ -1851,7 +1794,7 @@ class Pigeon { /// it. [types] optionally filters out what datatypes are actually parsed. /// [sdkPath] for specifying the Dart SDK path for /// [AnalysisContextCollection]. - Future parseFile(String inputPath, {String? sdkPath}) async { + ParseResults parseFile(String inputPath, {String? sdkPath}) { final List includedPaths = [ path.absolute(path.normalize(inputPath)) ]; @@ -1970,7 +1913,7 @@ ${_argParser.usage}'''; help: 'The package that generated code will be in.'); /// Convert command-line arguments to [PigeonOptions]. - static Future parseArgs(List args) async { + static PigeonOptions parseArgs(List args) { // Note: This function shouldn't perform any logic, just translate the args // to PigeonOptions. Synthesized values inside of the PigeonOption should // get set in the `run` function to accommodate users that are using the @@ -2036,8 +1979,8 @@ ${_argParser.usage}'''; /// customize the generators that pigeon will use. The optional parameter /// [sdkPath] allows you to specify the Dart SDK path. static Future run(List args, - {List? adapters, String? sdkPath}) async { - final PigeonOptions options = await Pigeon.parseArgs(args); + {List? adapters, String? sdkPath}) { + final PigeonOptions options = Pigeon.parseArgs(args); return runWithOptions(options, adapters: adapters, sdkPath: sdkPath); } @@ -2070,7 +2013,7 @@ ${_argParser.usage}'''; } final ParseResults parseResults = - await pigeon.parseFile(options.input!, sdkPath: sdkPath); + pigeon.parseFile(options.input!, sdkPath: sdkPath); final List errors = []; errors.addAll(parseResults.errors); diff --git a/packages/pigeon/test/pigeon_lib_test.dart b/packages/pigeon/test/pigeon_lib_test.dart index 01222b72fb61..5cb81959992b 100644 --- a/packages/pigeon/test/pigeon_lib_test.dart +++ b/packages/pigeon/test/pigeon_lib_test.dart @@ -40,122 +40,118 @@ void main() { /// Creates a temporary file named [filename] then calls [callback] with a /// [File] representing that temporary directory. The file will be deleted /// after the [callback] is executed. - Future withTempFile( - String filename, - Future Function(File) callback, - ) async { + void withTempFile(String filename, void Function(File) callback) { final Directory dir = Directory.systemTemp.createTempSync(); final String path = '${dir.path}/$filename'; final File file = File(path); file.createSync(); try { - await callback(file); + callback(file); } finally { dir.deleteSync(recursive: true); } } - Future parseSource(String source) async { + ParseResults parseSource(String source) { final Pigeon dartle = Pigeon.setup(); ParseResults? results; - await withTempFile('source.dart', (File file) async { + withTempFile('source.dart', (File file) { file.writeAsStringSync(source); - results = await dartle.parseFile(file.path); + results = dartle.parseFile(file.path); }); return results!; } - test('parse args - input', () async { + test('parse args - input', () { final PigeonOptions opts = - await Pigeon.parseArgs(['--input', 'foo.dart']); + Pigeon.parseArgs(['--input', 'foo.dart']); expect(opts.input, equals('foo.dart')); }); - test('parse args - dart_out', () async { + test('parse args - dart_out', () { final PigeonOptions opts = - await Pigeon.parseArgs(['--dart_out', 'foo.dart']); + Pigeon.parseArgs(['--dart_out', 'foo.dart']); expect(opts.dartOut, equals('foo.dart')); }); - test('parse args - java_package', () async { + test('parse args - java_package', () { final PigeonOptions opts = - await Pigeon.parseArgs(['--java_package', 'com.google.foo']); + Pigeon.parseArgs(['--java_package', 'com.google.foo']); expect(opts.javaOptions?.package, equals('com.google.foo')); }); - test('parse args - input', () async { + test('parse args - input', () { final PigeonOptions opts = - await Pigeon.parseArgs(['--java_out', 'foo.java']); + Pigeon.parseArgs(['--java_out', 'foo.java']); expect(opts.javaOut, equals('foo.java')); }); - test('parse args - objc_header_out', () async { + test('parse args - objc_header_out', () { final PigeonOptions opts = - await Pigeon.parseArgs(['--objc_header_out', 'foo.h']); + Pigeon.parseArgs(['--objc_header_out', 'foo.h']); expect(opts.objcHeaderOut, equals('foo.h')); }); - test('parse args - objc_source_out', () async { + test('parse args - objc_source_out', () { final PigeonOptions opts = - await Pigeon.parseArgs(['--objc_source_out', 'foo.m']); + Pigeon.parseArgs(['--objc_source_out', 'foo.m']); expect(opts.objcSourceOut, equals('foo.m')); }); - test('parse args - swift_out', () async { + test('parse args - swift_out', () { final PigeonOptions opts = - await Pigeon.parseArgs(['--swift_out', 'Foo.swift']); + Pigeon.parseArgs(['--swift_out', 'Foo.swift']); expect(opts.swiftOut, equals('Foo.swift')); }); - test('parse args - kotlin_out', () async { + test('parse args - kotlin_out', () { final PigeonOptions opts = - await Pigeon.parseArgs(['--kotlin_out', 'Foo.kt']); + Pigeon.parseArgs(['--kotlin_out', 'Foo.kt']); expect(opts.kotlinOut, equals('Foo.kt')); }); - test('parse args - kotlin_package', () async { + test('parse args - kotlin_package', () { final PigeonOptions opts = - await Pigeon.parseArgs(['--kotlin_package', 'com.google.foo']); + Pigeon.parseArgs(['--kotlin_package', 'com.google.foo']); expect(opts.kotlinOptions?.package, equals('com.google.foo')); }); - test('parse args - cpp_header_out', () async { + test('parse args - cpp_header_out', () { final PigeonOptions opts = - await Pigeon.parseArgs(['--cpp_header_out', 'foo.h']); + Pigeon.parseArgs(['--cpp_header_out', 'foo.h']); expect(opts.cppHeaderOut, equals('foo.h')); }); - test('parse args - java_use_generated_annotation', () async { + test('parse args - java_use_generated_annotation', () { final PigeonOptions opts = - await Pigeon.parseArgs(['--java_use_generated_annotation']); + Pigeon.parseArgs(['--java_use_generated_annotation']); expect(opts.javaOptions!.useGeneratedAnnotation, isTrue); }); - test('parse args - cpp_source_out', () async { + test('parse args - cpp_source_out', () { final PigeonOptions opts = - await Pigeon.parseArgs(['--cpp_source_out', 'foo.cpp']); + Pigeon.parseArgs(['--cpp_source_out', 'foo.cpp']); expect(opts.cppSourceOut, equals('foo.cpp')); }); - test('parse args - one_language', () async { - final PigeonOptions opts = - await Pigeon.parseArgs(['--one_language']); + test('parse args - one_language', () { + final PigeonOptions opts = Pigeon.parseArgs(['--one_language']); expect(opts.oneLanguage, isTrue); }); - test('parse args - ast_out', () async { + test('parse args - ast_out', () { final PigeonOptions opts = - await Pigeon.parseArgs(['--ast_out', 'stdout']); + Pigeon.parseArgs(['--ast_out', 'stdout']); expect(opts.astOut, equals('stdout')); }); - test('parse args - base_path', () async { + test('parse args - base_path', () { final PigeonOptions opts = - await Pigeon.parseArgs(['--base_path', './foo/']); + Pigeon.parseArgs(['--base_path', './foo/']); expect(opts.basePath, equals('./foo/')); }); - test('simple parse api', () async { + test('simple parse api', () { const String code = ''' class Input1 { String? input; @@ -170,7 +166,7 @@ abstract class Api1 { Output1 doit(Input1 input); } '''; - final ParseResults parseResult = await parseSource(code); + final ParseResults parseResult = parseSource(code); expect(parseResult.errors.length, equals(0)); final Root root = parseResult.root; expect(root.classes.length, equals(2)); @@ -206,7 +202,7 @@ abstract class Api1 { expect(output?.fields[0].type.isNullable, isTrue); }); - test('invalid datatype', () async { + test('invalid datatype', () { const String source = ''' class InvalidDatatype { dynamic something; @@ -217,13 +213,13 @@ abstract class Api { InvalidDatatype foo(); } '''; - final ParseResults results = await parseSource(source); + final ParseResults results = parseSource(source); expect(results.errors.length, 1); expect(results.errors[0].message, contains('InvalidDatatype')); expect(results.errors[0].message, contains('dynamic')); }); - test('enum in classes', () async { + test('enum in classes', () { const String code = ''' enum Enum1 { one, @@ -239,7 +235,7 @@ abstract class Api { ClassWithEnum foo(); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, equals(0)); expect(results.root.classes.length, equals(1)); expect(results.root.classes[0].name, equals('ClassWithEnum')); @@ -249,7 +245,7 @@ abstract class Api { expect(results.root.classes[0].fields[0].name, equals('enum1')); }); - test('two methods', () async { + test('two methods', () { const String code = ''' class Input1 { String? input; @@ -265,7 +261,7 @@ abstract class ApiTwoMethods { Output1 method2(Input1 input); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 0); expect(results.root.apis.length, 1); expect(results.root.apis[0].methods.length, equals(2)); @@ -273,7 +269,7 @@ abstract class ApiTwoMethods { expect(results.root.apis[0].methods[1].name, equals('method2')); }); - test('nested', () async { + test('nested', () { const String code = ''' class Input1 { String? input; @@ -288,7 +284,7 @@ abstract class Api { Nested foo(); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, equals(0)); expect(results.root.classes.length, equals(2)); final Class nested = @@ -298,7 +294,7 @@ abstract class Api { expect(nested.fields[0].type.isNullable, isTrue); }); - test('flutter api', () async { + test('flutter api', () { const String code = ''' class Input1 { String? input; @@ -313,14 +309,14 @@ abstract class AFlutterApi { Output1 doit(Input1 input); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); 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], isA()); }); - test('void host api', () async { + test('void host api', () { const String code = ''' class Input1 { String? input; @@ -331,7 +327,7 @@ abstract class VoidApi { void doit(Input1 input); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, equals(0)); expect(results.root.apis.length, equals(1)); expect(results.root.apis[0].methods.length, equals(1)); @@ -339,7 +335,7 @@ abstract class VoidApi { expect(results.root.apis[0].methods[0].returnType.isVoid, isTrue); }); - test('void arg host api', () async { + test('void arg host api', () { const String code = ''' class Output1 { String? output; @@ -350,7 +346,7 @@ abstract class VoidArgApi { Output1 doit(); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, equals(0)); expect(results.root.apis.length, equals(1)); expect(results.root.apis[0].methods.length, equals(1)); @@ -360,7 +356,7 @@ abstract class VoidArgApi { expect(results.root.apis[0].methods[0].parameters.isEmpty, isTrue); }); - test('mockDartClass', () async { + test('mockDartClass', () { const String code = ''' class Output1 { String? output; @@ -371,14 +367,16 @@ abstract class ApiWithMockDartClass { Output1 doit(); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, equals(0)); expect(results.root.apis.length, equals(1)); - expect((results.root.apis[0] as AstHostApi).dartHostTestHandler, - equals('ApiWithMockDartClassMock')); + expect( + (results.root.apis[0] as AstHostApi).dartHostTestHandler, + equals('ApiWithMockDartClassMock'), + ); }); - test('only visible from nesting', () async { + test('only visible from nesting', () { const String code = ''' class OnlyVisibleFromNesting { String? foo; @@ -393,7 +391,7 @@ abstract class NestorApi { Nestor getit(); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 0); expect(results.root.apis.length, 1); final List classNames = @@ -403,9 +401,9 @@ abstract class NestorApi { expect(classNames.contains('OnlyVisibleFromNesting'), true); }); - test('copyright flag', () async { + test('copyright flag', () { final PigeonOptions results = - await Pigeon.parseArgs(['--copyright_header', 'foobar.txt']); + Pigeon.parseArgs(['--copyright_header', 'foobar.txt']); expect(results.copyrightHeader, 'foobar.txt'); }); @@ -482,7 +480,7 @@ abstract class NestorApi { expect(buffer.toString(), startsWith('// Copyright 2013')); }); - test('nested enum', () async { + test('nested enum', () { const String code = ''' enum NestedEnum { one, two } @@ -504,14 +502,14 @@ abstract class NestedEnumApi { void method(NestedEnum3 foo); } '''; - final ParseResults parseResult = await parseSource(code); + final ParseResults parseResult = parseSource(code); expect(parseResult.errors.length, equals(0)); expect(parseResult.root.apis.length, 1); expect(parseResult.root.classes.length, 3); expect(parseResult.root.enums.length, 1); }); - test('test circular references', () async { + test('test circular references', () { const String code = ''' class Foo { Bar? bar; @@ -526,7 +524,7 @@ abstract class NotificationsHostApi { void doit(Foo foo); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 0); expect(results.root.classes.length, 2); final Class foo = @@ -535,14 +533,14 @@ abstract class NotificationsHostApi { expect(foo.fields[0].type.baseName, 'Bar'); }); - test('test compilation error', () async { + test('test compilation error', () { const String code = 'Hello\n'; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, greaterThanOrEqualTo(1)); expect(results.errors[0].lineNumber, 1); }); - test('test method in data class error', () async { + test('test method in data class error', () { const String code = ''' class Foo { int? x; @@ -554,13 +552,13 @@ abstract class Api { Foo doit(Foo foo); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 3); expect(results.errors[0].message, contains('Method')); }); - test('test field initialization', () async { + test('test field initialization', () { const String code = ''' class Foo { int? x = 123; @@ -571,13 +569,13 @@ abstract class Api { Foo doit(Foo foo); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 2); expect(results.errors[0].message, contains('Initialization')); }); - test('test field in api error', () async { + test('test field in api error', () { const String code = ''' class Foo { int? x; @@ -589,13 +587,13 @@ abstract class Api { Foo doit(Foo foo); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 7); expect(results.errors[0].message, contains('Field')); }); - test('constructor in data class', () async { + test('constructor in data class', () { const String code = ''' class Foo { int? x; @@ -607,11 +605,11 @@ abstract class Api { Foo doit(Foo foo); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 0); }); - test('constructor body in data class', () async { + test('constructor body in data class', () { const String code = ''' class Foo { int? x; @@ -623,13 +621,13 @@ abstract class Api { Foo doit(Foo foo); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 3); expect(results.errors[0].message, contains('Constructor')); }); - test('constructor body in data class', () async { + test('constructor body in data class', () { const String code = ''' class Foo { int? x; @@ -641,13 +639,13 @@ abstract class Api { Foo doit(Foo foo); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 3); expect(results.errors[0].message, contains('Constructor')); }); - test('constructor in api class', () async { + test('constructor in api class', () { const String code = ''' class Foo { int? x; @@ -659,26 +657,26 @@ abstract class Api { Foo doit(Foo foo); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 7); expect(results.errors[0].message, contains('Constructor')); }); - test('test invalid import', () async { + test('test invalid import', () { const String code = "import 'foo.dart';\n"; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, greaterThanOrEqualTo(1)); expect(results.errors[0].lineNumber, 1); }); - test('test valid import', () async { + test('test valid import', () { const String code = "import 'package:pigeon/pigeon.dart';\n"; - final ParseResults parseResults = await parseSource(code); + final ParseResults parseResults = parseSource(code); expect(parseResults.errors.length, 0); }); - test('error with static field', () async { + test('error with static field', () { const String code = ''' class WithStaticField { static int? x; @@ -690,13 +688,13 @@ abstract class WithStaticFieldApi { void doit(WithStaticField withTemplate); } '''; - final ParseResults parseResult = await parseSource(code); + final ParseResults parseResult = parseSource(code); expect(parseResult.errors.length, equals(1)); expect(parseResult.errors[0].message, contains('static field')); expect(parseResult.errors[0].lineNumber, isNotNull); }); - test('parse generics', () async { + test('parse generics', () { const String code = ''' class Foo { List? list; @@ -707,14 +705,14 @@ abstract class Api { void doit(Foo foo); } '''; - final ParseResults parseResult = await parseSource(code); + final ParseResults parseResult = parseSource(code); expect(parseResult.errors.length, equals(0)); final NamedType field = parseResult.root.classes[0].fields[0]; expect(field.type.typeArguments.length, 1); expect(field.type.typeArguments[0].baseName, 'int'); }); - test('parse recursive generics', () async { + test('parse recursive generics', () { const String code = ''' class Foo { List?>? list; @@ -725,7 +723,7 @@ abstract class Api { void doit(Foo foo); } '''; - final ParseResults parseResult = await parseSource(code); + final ParseResults parseResult = parseSource(code); expect(parseResult.errors.length, equals(0)); final NamedType field = parseResult.root.classes[0].fields[0]; expect(field.type.typeArguments.length, 1); @@ -733,7 +731,7 @@ abstract class Api { expect(field.type.typeArguments[0].typeArguments[0].baseName, 'int'); }); - test('error nonnull type argument', () async { + test('error nonnull type argument', () { const String code = ''' class Foo { List list; @@ -744,7 +742,7 @@ abstract class Api { void doit(Foo foo); } '''; - final ParseResults parseResult = await parseSource(code); + final ParseResults parseResult = parseSource(code); expect(parseResult.errors.length, equals(1)); expect(parseResult.errors[0].message, contains('Generic type parameters must be nullable')); @@ -752,7 +750,7 @@ abstract class Api { expect(parseResult.errors[0].lineNumber, 2); }); - test('enums argument host', () async { + test('enums argument host', () { const String code = ''' enum Foo { one, @@ -764,11 +762,11 @@ abstract class Api { void doit(Foo foo); } '''; - final ParseResults parseResult = await parseSource(code); + final ParseResults parseResult = parseSource(code); expect(parseResult.errors.length, equals(0)); }); - test('enums argument flutter', () async { + test('enums argument flutter', () { const String code = ''' enum Foo { @@ -781,11 +779,11 @@ abstract class Api { void doit(Foo foo); } '''; - final ParseResults parseResult = await parseSource(code); + final ParseResults parseResult = parseSource(code); expect(parseResult.errors.length, equals(0)); }); - test('enums list argument', () async { + test('enums list argument', () { const String code = ''' enum Foo { one, two } @@ -794,11 +792,11 @@ abstract class Api { void doit(List foo); } '''; - final ParseResults parseResult = await parseSource(code); + final ParseResults parseResult = parseSource(code); expect(parseResult.errors.length, equals(0)); }); - test('enums map argument key', () async { + test('enums map argument key', () { const String code = ''' enum Foo { one, two } @@ -807,11 +805,11 @@ abstract class Api { void doit(Map foo); } '''; - final ParseResults parseResult = await parseSource(code); + final ParseResults parseResult = parseSource(code); expect(parseResult.errors.length, equals(0)); }); - test('enums map argument value', () async { + test('enums map argument value', () { const String code = ''' enum Foo { one, two } @@ -820,11 +818,11 @@ abstract class Api { void doit(Map foo); } '''; - final ParseResults parseResult = await parseSource(code); + final ParseResults parseResult = parseSource(code); expect(parseResult.errors.length, equals(0)); }); - test('enums return value', () async { + test('enums return value', () { const String code = ''' enum Foo { @@ -837,18 +835,18 @@ abstract class Api { Foo doit(); } '''; - final ParseResults parseResult = await parseSource(code); + final ParseResults parseResult = parseSource(code); expect(parseResult.errors.length, equals(0)); }); - test('return type generics', () async { + test('return type generics', () { const String code = ''' @HostApi() abstract class Api { List doit(); } '''; - final ParseResults parseResult = await parseSource(code); + final ParseResults parseResult = parseSource(code); expect(parseResult.root.apis[0].methods[0].returnType.baseName, 'List'); expect( parseResult @@ -860,14 +858,14 @@ abstract class Api { isTrue); }); - test('argument generics', () async { + test('argument generics', () { const String code = ''' @HostApi() abstract class Api { void doit(int x, List value); } '''; - final ParseResults parseResult = await parseSource(code); + final ParseResults parseResult = parseSource(code); expect(parseResult.root.apis[0].methods[0].parameters[1].type.baseName, 'List'); expect( @@ -880,7 +878,7 @@ abstract class Api { isTrue); }); - test('map generics', () async { + test('map generics', () { const String code = ''' class Foo { Map map; @@ -891,14 +889,14 @@ abstract class Api { void doit(Foo foo); } '''; - final ParseResults parseResult = await parseSource(code); + final ParseResults parseResult = parseSource(code); final NamedType field = parseResult.root.classes[0].fields[0]; expect(field.type.typeArguments.length, 2); expect(field.type.typeArguments[0].baseName, 'String'); expect(field.type.typeArguments[1].baseName, 'int'); }); - test('two parameters', () async { + test('two parameters', () { const String code = ''' class Input { String? input; @@ -909,28 +907,28 @@ abstract class Api { void method(Input input1, Input input2); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.root.apis.length, 1); expect(results.root.apis[0].methods.length, equals(1)); expect(results.root.apis[0].methods[0].name, equals('method')); expect(results.root.apis[0].methods[0].parameters.length, 2); }); - test('no type name argument', () async { + test('no type name argument', () { const String code = ''' @HostApi() abstract class Api { void method(x); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 3); expect(results.errors[0].message, contains('Parameters must specify their type')); }); - test('custom objc selector', () async { + test('custom objc selector', () { const String code = ''' @HostApi() abstract class Api { @@ -938,7 +936,7 @@ abstract class Api { void subtract(int x, int y); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 0); expect(results.root.apis.length, 1); expect(results.root.apis[0].methods.length, equals(1)); @@ -946,7 +944,7 @@ abstract class Api { equals('subtractValue:by:')); }); - test('custom objc invalid selector', () async { + test('custom objc invalid selector', () { const String code = ''' @HostApi() abstract class Api { @@ -954,14 +952,14 @@ abstract class Api { void subtract(int x, int y); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 3); expect(results.errors[0].message, contains('Invalid selector, expected 2 parameters')); }); - test('custom objc no parameters', () async { + test('custom objc no parameters', () { const String code = ''' @HostApi() abstract class Api { @@ -969,14 +967,14 @@ abstract class Api { void initialize(); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 0); expect(results.root.apis.length, 1); expect(results.root.apis[0].methods.length, equals(1)); expect(results.root.apis[0].methods[0].objcSelector, equals('foobar')); }); - test('custom swift valid function signature', () async { + test('custom swift valid function signature', () { const String code = ''' @HostApi() abstract class Api { @@ -984,7 +982,7 @@ abstract class Api { void subtract(int x, int y); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 0); expect(results.root.apis.length, 1); expect(results.root.apis[0].methods.length, equals(1)); @@ -992,7 +990,7 @@ abstract class Api { equals('subtractValue(_:by:)')); }); - test('custom swift invalid function signature', () async { + test('custom swift invalid function signature', () { const String code = ''' @HostApi() abstract class Api { @@ -1000,14 +998,14 @@ abstract class Api { void subtract(int x, int y); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 3); expect(results.errors[0].message, contains('Invalid function signature, expected 2 parameters')); }); - test('custom swift function signature no parameters', () async { + test('custom swift function signature no parameters', () { const String code = ''' @HostApi() abstract class Api { @@ -1015,7 +1013,7 @@ abstract class Api { void initialize(); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 0); expect(results.root.apis.length, 1); expect(results.root.apis[0].methods.length, equals(1)); @@ -1036,7 +1034,7 @@ abstract class Api { expect(buffer.toString(), startsWith('// Copyright 2013')); }); - test('only class reference is type argument for return value', () async { + test('only class reference is type argument for return value', () { const String code = ''' class Foo { int? foo; @@ -1047,13 +1045,13 @@ abstract class Api { List grabAll(); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 0); expect(results.root.classes.length, 1); expect(results.root.classes[0].name, 'Foo'); }); - test('only class reference is type argument for argument', () async { + test('only class reference is type argument for argument', () { const String code = ''' class Foo { int? foo; @@ -1064,13 +1062,13 @@ abstract class Api { void storeAll(List foos); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 0); expect(results.root.classes.length, 1); expect(results.root.classes[0].name, 'Foo'); }); - test('recurse into type parameters', () async { + test('recurse into type parameters', () { const String code = ''' class Foo { int? foo; @@ -1086,7 +1084,7 @@ abstract class Api { void storeAll(List foos); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 0); expect(results.root.classes.length, 2); expect( @@ -1101,31 +1099,31 @@ abstract class Api { 1); }); - test('undeclared class in argument type argument', () async { + test('undeclared class in argument type argument', () { const String code = ''' @HostApi() abstract class Api { void storeAll(List foos); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 3); expect(results.errors[0].message, contains('Unknown type: Foo')); }); - test('Object type argument', () async { + test('Object type argument', () { const String code = ''' @HostApi() abstract class Api { void storeAll(List foos); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 0); }); - test('Enum key not supported', () async { + test('Enum key not supported', () { const String code = ''' enum MessageKey { title, @@ -1143,11 +1141,11 @@ abstract class HostApiBridge { void sendMessage(Message message); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 1); }); - test('Export unreferenced enums', () async { + test('Export unreferenced enums', () { const String code = ''' enum MessageKey { title, @@ -1165,12 +1163,12 @@ abstract class HostApiBridge { void sendMessage(Message message); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.root.enums.length, 1); expect(results.root.enums[0].name, 'MessageKey'); }); - test('@ConfigurePigeon JavaOptions.copyrightHeader', () async { + test('@ConfigurePigeon JavaOptions.copyrightHeader', () { const String code = ''' @ConfigurePigeon(PigeonOptions( javaOptions: JavaOptions(copyrightHeader: ['A', 'Header']), @@ -1180,12 +1178,12 @@ class Message { } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); final PigeonOptions options = PigeonOptions.fromMap(results.pigeonOptions!); expect(options.javaOptions!.copyrightHeader, ['A', 'Header']); }); - test('@ConfigurePigeon DartOptions.copyrightHeader', () async { + test('@ConfigurePigeon DartOptions.copyrightHeader', () { const String code = ''' @ConfigurePigeon(PigeonOptions( dartOptions: DartOptions(copyrightHeader: ['A', 'Header']), @@ -1195,12 +1193,12 @@ class Message { } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); final PigeonOptions options = PigeonOptions.fromMap(results.pigeonOptions!); expect(options.dartOptions!.copyrightHeader, ['A', 'Header']); }); - test('@ConfigurePigeon ObjcOptions.copyrightHeader', () async { + test('@ConfigurePigeon ObjcOptions.copyrightHeader', () { const String code = ''' @ConfigurePigeon(PigeonOptions( objcOptions: ObjcOptions(copyrightHeader: ['A', 'Header']), @@ -1210,12 +1208,12 @@ class Message { } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); final PigeonOptions options = PigeonOptions.fromMap(results.pigeonOptions!); expect(options.objcOptions!.copyrightHeader, ['A', 'Header']); }); - test('return nullable', () async { + test('return nullable', () { const String code = ''' @HostApi() abstract class Api { @@ -1223,25 +1221,25 @@ abstract class Api { } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 0); expect(results.root.apis[0].methods[0].returnType.isNullable, isTrue); }); - test('nullable parameters', () async { + test('nullable parameters', () { const String code = ''' @HostApi() abstract class Api { void calc(int? value); } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 0); expect( results.root.apis[0].methods[0].parameters[0].type.isNullable, isTrue); }); - test('task queue specified', () async { + test('task queue specified', () { const String code = ''' @HostApi() abstract class Api { @@ -1250,13 +1248,13 @@ abstract class Api { } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 0); expect(results.root.apis[0].methods[0].taskQueueType, equals(TaskQueueType.serialBackgroundThread)); }); - test('task queue unspecified', () async { + test('task queue unspecified', () { const String code = ''' @HostApi() abstract class Api { @@ -1264,13 +1262,13 @@ abstract class Api { } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 0); expect(results.root.apis[0].methods[0].taskQueueType, equals(TaskQueueType.serial)); }); - test('unsupported task queue on FlutterApi', () async { + test('unsupported task queue on FlutterApi', () { const String code = ''' @FlutterApi() abstract class Api { @@ -1279,7 +1277,7 @@ abstract class Api { } '''; - final ParseResults results = await parseSource(code); + final ParseResults results = parseSource(code); expect(results.errors.length, 1); expect(results.errors[0].message, contains('Unsupported TaskQueue specification')); @@ -1287,7 +1285,7 @@ abstract class Api { test('generator validation', () async { final Completer completer = Completer(); - await withTempFile('foo.dart', (File input) async { + withTempFile('foo.dart', (File input) async { final _ValidatorGeneratorAdapter generator = _ValidatorGeneratorAdapter(stdout); final int result = await Pigeon.run(['--input', input.path], @@ -1301,7 +1299,7 @@ abstract class Api { test('generator validation skipped', () async { final Completer completer = Completer(); - await withTempFile('foo.dart', (File input) async { + withTempFile('foo.dart', (File input) async { final _ValidatorGeneratorAdapter generator = _ValidatorGeneratorAdapter(null); final int result = await Pigeon.run( @@ -1316,7 +1314,7 @@ abstract class Api { test('run with PigeonOptions', () async { final Completer completer = Completer(); - await withTempFile('foo.dart', (File input) async { + withTempFile('foo.dart', (File input) async { final _ValidatorGeneratorAdapter generator = _ValidatorGeneratorAdapter(null); final int result = await Pigeon.runWithOptions( From be1f9fb832f4ff97440f10092bcf30700f2460b9 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 8 Dec 2023 14:12:03 -0500 Subject: [PATCH 18/73] finish proxyapi validation (maybe) --- packages/pigeon/lib/pigeon_lib.dart | 89 ++++++++++++++++++----------- 1 file changed, 55 insertions(+), 34 deletions(-) diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 374fb3d20372..0d9047d02ee4 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -823,28 +823,6 @@ List _validateAst(Root root, String source) { } } - // Verify all super classes and interfaces for ProxyApis are other ProxyAps - final Iterable allProxyApis = root.apis.whereType(); - for (final AstProxyApi api in allProxyApis) { - final String? superClassName = api.superClassName; - if (api.superClassName != null && - !allProxyApis.any((AstProxyApi api) => api.name == superClassName)) { - result.add(Error( - message: - 'Super class of ${api.name} is not marked as a @ProxyApi: $superClassName', - )); - } - - for (final String interfaceName in api.interfacesNames) { - if (!allProxyApis.any((AstProxyApi api) => api.name == interfaceName)) { - result.add(Error( - message: - 'Interface of ${api.name} is not marked as a @ProxyApi: $interfaceName', - )); - } - } - } - for (final Api api in root.apis) { if (api is AstProxyApi) { result.addAll(_validateProxyApi( @@ -930,11 +908,36 @@ List _validateProxyApi( ); } - final List superClassChain = - recursiveGetSuperClassApisChain(api, proxyApis); + // 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', + )); + } - // Verify that the api does not inherit a non attached field from its super class. - if (superClassChain.isNotEmpty && + // 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.nonAttachedFields.isNotEmpty) { result.add(Error( message: @@ -946,14 +949,14 @@ List _validateProxyApi( )); } - // Verify this api is not used as an attached field while either: - // 1. Having a non-attached field. - // 2. Having a required Flutter method. - final bool hasNonAttachedField = api.nonAttachedFields.isNotEmpty; - final bool hasRequiredFlutterMethod = - api.flutterMethods.any((Method method) => method.required); - if (hasNonAttachedField || hasRequiredFlutterMethod) { - for (final AstProxyApi proxyApi in proxyApis) { + for (final AstProxyApi proxyApi in proxyApis) { + // Validate this api is not used as an attached field while either: + // 1. Having a non-attached field. + // 2. Having a required Flutter method. + final bool hasNonAttachedField = api.nonAttachedFields.isNotEmpty; + final bool hasRequiredFlutterMethod = + api.flutterMethods.any((Method method) => method.required); + if (hasNonAttachedField || hasRequiredFlutterMethod) { for (final Field field in proxyApi.attachedFields) { if (field.type.baseName == api.name) { if (hasNonAttachedField) { @@ -979,8 +982,24 @@ List _validateProxyApi( } } } + + // Validate only Flutter methods are used for implemented ProxyApis. + 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 that are implemented 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)) { @@ -1020,6 +1039,7 @@ List _validateProxyApi( } } + // Validate method parameters for (final Method method in api.methods) { for (final Parameter parameter in method.parameters) { if (isDataClass(parameter)) { @@ -1035,6 +1055,7 @@ List _validateProxyApi( } } + // Validate fields for (final Field field in api.fields) { if (isDataClass(field)) { result.add(unsupportedDataClassError(field)); From abf11b683f11bc41f328db199e9d32682cccd995 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 8 Dec 2023 14:56:37 -0500 Subject: [PATCH 19/73] undo pubspec change --- packages/pigeon/lib/pigeon_lib.dart | 6 +++--- .../webview_flutter/webview_flutter_android/pubspec.yaml | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 0d9047d02ee4..f9b86c377779 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -992,7 +992,7 @@ List _validateProxyApi( if (interfaceName == api.name) { result.add(Error( message: - 'ProxyApis that are implemented can only have callback methods: ${proxyApi.name}', + 'ProxyApis used as interfaces can only have callback methods: ${proxyApi.name}', )); } } @@ -1063,13 +1063,13 @@ List _validateProxyApi( if (field.isStatic) { result.add(Error( message: - 'Static fields are considered attached fields and must be another 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.isAttached) { result.add(Error( message: - 'Attached fields must be another ProxyApi: ${field.type.baseName}.', + 'Attached fields must be a ProxyApi: ${field.type.baseName}.', lineNumber: _calculateLineNumberNullable(source, field.offset), )); } diff --git a/packages/webview_flutter/webview_flutter_android/pubspec.yaml b/packages/webview_flutter/webview_flutter_android/pubspec.yaml index 0d27fb8909d2..92aa739c30f2 100644 --- a/packages/webview_flutter/webview_flutter_android/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_android/pubspec.yaml @@ -27,8 +27,7 @@ dev_dependencies: flutter_test: sdk: flutter mockito: 5.4.3 - pigeon: - path: ../../pigeon + pigeon: ^11.0.0 topics: - html From 8a35b5ebe98383185ea03abb97c23a41205dbb23 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 8 Dec 2023 14:58:05 -0500 Subject: [PATCH 20/73] version bump --- packages/pigeon/CHANGELOG.md | 4 ++++ packages/pigeon/lib/generator_tools.dart | 2 +- packages/pigeon/pubspec.yaml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 501f6c83dd04..c94cbac9922e 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,7 @@ +## 14.1.0 + +* ProxyApi support. + ## 14.0.1 * Updates minimum supported SDK version to Flutter 3.10/Dart 3.0. diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index d7ceb4d7e73f..41b88f308c11 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 = '14.0.1'; +const String pigeonVersion = '14.1.0'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index fae31f868331..cb8bae177a5c 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: 14.0.1 # This must match the version in lib/generator_tools.dart +version: 14.1.0 # This must match the version in lib/generator_tools.dart environment: sdk: ">=3.0.0 <4.0.0" From 9a79ea9a544e70692459a2bfd704ea6a7eabee87 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 8 Dec 2023 15:08:12 -0500 Subject: [PATCH 21/73] fix lints --- packages/pigeon/lib/ast.dart | 2 ++ packages/pigeon/lib/functional.dart | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index 2a002c14b0b6..1e3f8ef3712a 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -328,8 +328,10 @@ 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 diff --git a/packages/pigeon/lib/functional.dart b/packages/pigeon/lib/functional.dart index 6c7be00d7027..b9e01410014d 100644 --- a/packages/pigeon/lib/functional.dart +++ b/packages/pigeon/lib/functional.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. -// TODO: replace usage with mapIndexed +// TODO(bparrishMines): replace usage with mapIndexed /// A [map] function that calls the function with an enumeration as well as the /// value. Iterable indexMap( @@ -14,7 +14,7 @@ Iterable indexMap( } } -// TODO: replace usage with foldIndexed +// TODO(bparrishMines): replace usage with foldIndexed /// A [map] function that calls the function with an enumeration as well as the /// value. T indexFold( @@ -31,7 +31,7 @@ T indexFold( return value; } -// TODO: replace usage with forEachIndexed +// TODO(bparrishMines): replace usage with forEachIndexed /// Performs like [forEach] but invokes [func] with an enumeration. void enumerate(Iterable iterable, void Function(int, T) func) { int count = 0; From 245a32291ea2bafabd24c9cbb7bc1a1c431fec6a Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 8 Dec 2023 15:19:19 -0500 Subject: [PATCH 22/73] remove unneccessary cast --- packages/pigeon/lib/pigeon_lib.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index f9b86c377779..f3117eb4b180 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -1352,7 +1352,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { dartHostTestHandler: dartHostTestHandler, documentationComments: _documentationCommentsParser(node.documentationComment?.tokens), - ) as Api; + ); } else if (_hasMetadata(node.metadata, 'FlutterApi')) { _currentApi = AstFlutterApi( name: node.name.lexeme, From 4a5c1c76d4e71a0bb98f44b91830d331f728b4fa Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 8 Dec 2023 15:36:03 -0500 Subject: [PATCH 23/73] formatting --- packages/pigeon/lib/cpp_generator.dart | 5 +++-- packages/pigeon/lib/java_generator.dart | 8 +++++--- packages/pigeon/lib/kotlin_generator.dart | 10 ++++++---- packages/pigeon/lib/objc_generator.dart | 5 +++-- packages/pigeon/lib/pigeon_lib.dart | 4 ++-- packages/pigeon/lib/swift_generator.dart | 8 +++++--- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index 56010ab22b02..c89820fe3173 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -191,8 +191,9 @@ class CppHeaderGenerator extends StructuredGenerator { Indent indent, { required String dartPackageName, }) { - final bool hasHostApi = - root.apis.whereType().any((Api api) => api.methods.isNotEmpty); + final bool hasHostApi = root.apis + .whereType() + .any((Api api) => api.methods.isNotEmpty); final bool hasFlutterApi = root.apis .whereType() .any((Api api) => api.methods.isNotEmpty); diff --git a/packages/pigeon/lib/java_generator.dart b/packages/pigeon/lib/java_generator.dart index 4e94a92f8a97..693e4951170d 100644 --- a/packages/pigeon/lib/java_generator.dart +++ b/packages/pigeon/lib/java_generator.dart @@ -545,7 +545,8 @@ class JavaGenerator extends StructuredGenerator { required String dartPackageName, }) { if (root.apis.any((Api api) => - api is AstHostApi && api.methods.any((Method it) => it.isAsynchronous) || + api is AstHostApi && + api.methods.any((Method it) => it.isAsynchronous) || api is AstFlutterApi)) { indent.newln(); _writeResultInterfaces(indent); @@ -943,8 +944,9 @@ protected static ArrayList wrapError(@NonNull Throwable exception) { Indent indent, { required String dartPackageName, }) { - final bool hasHostApi = - root.apis.whereType().any((Api api) => api.methods.isNotEmpty); + final bool hasHostApi = root.apis + .whereType() + .any((Api api) => api.methods.isNotEmpty); final bool hasFlutterApi = root.apis .whereType() .any((Api api) => api.methods.isNotEmpty); diff --git a/packages/pigeon/lib/kotlin_generator.dart b/packages/pigeon/lib/kotlin_generator.dart index decaf310d6d2..15e501ee36a0 100644 --- a/packages/pigeon/lib/kotlin_generator.dart +++ b/packages/pigeon/lib/kotlin_generator.dart @@ -736,10 +736,12 @@ class KotlinGenerator extends StructuredGenerator { Indent indent, { required String dartPackageName, }) { - final bool hasHostApi = root.apis.whereType().any((Api api) => - api.methods.isNotEmpty); - final bool hasFlutterApi = root.apis.whereType().any((Api api) => - api.methods.isNotEmpty); + 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 674ba1c2cf41..bc26495e650b 100644 --- a/packages/pigeon/lib/objc_generator.dart +++ b/packages/pigeon/lib/objc_generator.dart @@ -700,8 +700,9 @@ class ObjcSourceGenerator extends StructuredGenerator { Indent indent, { required String dartPackageName, }) { - final bool hasHostApi = - root.apis.whereType().any((Api api) => api.methods.isNotEmpty); + final bool hasHostApi = root.apis + .whereType() + .any((Api api) => api.methods.isNotEmpty); final bool hasFlutterApi = root.apis .whereType() .any((Api api) => api.methods.isNotEmpty); diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index f3117eb4b180..c7420a5b618d 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -984,8 +984,8 @@ List _validateProxyApi( } // Validate only Flutter methods are used for implemented ProxyApis. - final bool isValidInterfaceProxyApi = api.hostMethods.isEmpty || - api.constructors.isEmpty || + final bool isValidInterfaceProxyApi = api.hostMethods.isEmpty && + api.constructors.isEmpty && api.fields.isEmpty; if (!isValidInterfaceProxyApi) { for (final String interfaceName in proxyApi.interfacesNames) { diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index 724c234c9b73..cd2b36880530 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -236,7 +236,8 @@ import FlutterMacOS required String dartPackageName, }) { if (root.apis.any((Api api) => - api is AstHostApi && api.methods.any((Method it) => it.isAsynchronous))) { + api is AstHostApi && + api.methods.any((Method it) => it.isAsynchronous))) { indent.newln(); } super.writeApis(generatorOptions, root, indent, @@ -797,8 +798,9 @@ private func nilOrValue(_ value: Any?) -> T? { Indent indent, { required String dartPackageName, }) { - final bool hasHostApi = - root.apis.whereType().any((Api api) => api.methods.isNotEmpty); + final bool hasHostApi = root.apis + .whereType() + .any((Api api) => api.methods.isNotEmpty); final bool hasFlutterApi = root.apis .whereType() .any((Api api) => api.methods.isNotEmpty); From abefd56a79366acc328c93ea4a439fb8bcd38a6a Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 12 Dec 2023 14:32:32 -0500 Subject: [PATCH 24/73] fix kotlin tests --- packages/pigeon/test/kotlin_generator_test.dart | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/pigeon/test/kotlin_generator_test.dart b/packages/pigeon/test/kotlin_generator_test.dart index d5181799eabf..e680e3ac66d2 100644 --- a/packages/pigeon/test/kotlin_generator_test.dart +++ b/packages/pigeon/test/kotlin_generator_test.dart @@ -1661,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( @@ -1700,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( @@ -1739,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( @@ -1781,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( From 54e4102392e179863e2dd6faa2bfc1dda8c74e9e Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 12 Dec 2023 22:22:43 -0500 Subject: [PATCH 25/73] fix and add core tests --- .../example/app/lib/src/messages.g.dart | 3 +- packages/pigeon/lib/dart_generator.dart | 60 +- packages/pigeon/lib/pigeon_lib.dart | 2 + packages/pigeon/pigeons/core_tests.dart | 370 ++ .../background_platform_channels.gen.dart | 3 +- .../lib/src/generated/core_tests.gen.dart | 3703 ++++++++++++++++- .../lib/src/generated/enum.gen.dart | 3 +- .../src/generated/flutter_unittests.gen.dart | 3 +- .../lib/src/generated/message.gen.dart | 3 +- .../lib/src/generated/multiple_arity.gen.dart | 3 +- .../src/generated/non_null_fields.gen.dart | 3 +- .../lib/src/generated/null_fields.gen.dart | 3 +- .../src/generated/nullable_returns.gen.dart | 3 +- .../lib/src/generated/primitive.gen.dart | 3 +- .../windows/pigeon/core_tests.gen.h | 9 + 15 files changed, 4127 insertions(+), 47 deletions(-) diff --git a/packages/pigeon/example/app/lib/src/messages.g.dart b/packages/pigeon/example/app/lib/src/messages.g.dart index 59213e4ef2bb..0c50d2189d8d 100644 --- a/packages/pigeon/example/app/lib/src/messages.g.dart +++ b/packages/pigeon/example/app/lib/src/messages.g.dart @@ -8,7 +8,8 @@ import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; +import 'package:flutter/foundation.dart' + show ReadBuffer, WriteBuffer, immutable, protected; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index bee170107966..4bc92dd46307 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -1211,21 +1211,10 @@ class $codecName extends StandardMessageCodec { cb.refer( '${superClassApi != null ? '' : 'this.'}\$instanceManager.addDartCreatedInstance(this)', ), - ...indexMap( - nonAttachedFields, - (int index, Field field) => _hostMessageArgument( - index, - field, - getArgumentName: _getParameterName, - ), - ), + ...indexMap(nonAttachedFields, _hostMessageArgument), ...indexMap( constructor.parameters, - (int index, NamedType type) => _hostMessageArgument( - index, - type, - getArgumentName: _getParameterName, - ), + _hostMessageArgument, ), ], cb.refer('Object?'), @@ -1791,17 +1780,18 @@ class $codecName extends StandardMessageCodec { cb .declareFinal( 'output', - type: cb.refer( - _addGenericTypesNullable( - method.returnType, - ), + type: _referOrNull( + _addGenericTypes(method.returnType), + isNullable: + method.returnType.isNullable || + !method.required, ), ) .assign( call.awaitedIf(method.isAsynchronous), ) .statement, - _wrapResultResponse(method.returnType) + _wrapResultResponse(method) .returned .statement, ], @@ -1989,14 +1979,7 @@ class $codecName extends StandardMessageCodec { cb.literalList( [ if (!method.isStatic) cb.refer('this'), - ...indexMap( - method.parameters, - (int index, NamedType parameter) => _referOrNull( - _getParameterName(index, parameter), - isNullable: parameter.type.isNullable, - )! - .propertyIf(parameter.type.isEnum, 'index'), - ), + ...indexMap(method.parameters, _hostMessageArgument), ], cb.refer('Object?'), ) @@ -2244,15 +2227,20 @@ cb.Expression _unwrapReturnValue(TypeDeclaration returnType) { return cb.refer(''); } -cb.Expression _wrapResultResponse(TypeDeclaration type) { - return cb - .refer('wrapResponse') - .call([], { - 'result': _referOrNull('output', isNullable: type.isNullable)!.propertyIf( - type.isEnum, - 'index', - ), - }); +cb.Expression _wrapResultResponse(Method method) { + final TypeDeclaration returnType = method.returnType; + return cb.refer('wrapResponse').call( + [], + { + if (returnType.isEnum) + if (returnType.isNullable || !method.required) + 'result': cb.refer('output?.index') + else + 'result': cb.refer('output.index') + else + 'result': cb.refer('output'), + }, + ); } /// final = ([] as ); @@ -2335,7 +2323,7 @@ cb.Expression _hostMessageArgument( int index, NamedType type, { String Function(int index, NamedType type) getArgumentName = - _getSafeArgumentName, + _getParameterName, }) { final cb.Reference nameRef = cb.refer(getArgumentName(index, type)); if (type.type.isEnum) { diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index c7420a5b618d..19c88b6a4849 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -894,6 +894,8 @@ List _validateProxyApi( required Set customClasses, required Set proxyApis, }) { + // TODO: Verify constructor params dont overlap field params + final List result = []; bool isDataClass(NamedType type) => diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index a0c6a3ccf29f..6000f014b161 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -699,3 +699,373 @@ class TestMessage { // ignore: always_specify_types, strict_raw_type List? testList; } + +/// The core interface that each host language plugin must implement in +/// platform_test integration tests. +@ProxyApi() +abstract class ProxyIntegrationCoreApi { + ProxyIntegrationCoreApi( + // 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 + 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, + ); + + 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 bool? aNullableBool; + late int? aNullableInt; + late double? aNullableDouble; + late String? aNullableString; + late Uint8List? aNullableUint8List; + late List? aNullableList; + late Map? aNullableMap; + late AnEnum? aNullableEnum; + + /// 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 map, to test serialization and deserialization. + late Map Function(Map aMap)? + flutterEchoMap; + + /// Returns the passed enum to test serialization and deserialization. + late AnEnum Function(AnEnum anEnum)? flutterEchoEnum; + + // ========== 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; + + // ========== 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()? callFlutterNoopAsync; + + /// Returns the passed in generic Object asynchronously. + @async + late String Function(String aString)? callFlutterEchoAsyncString; + + // ========== 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 map, to test serialization and deserialization. + Map echoMap(Map aMap); + + /// Returns the passed enum to test serialization and deserialization. + AnEnum echoEnum(AnEnum anEnum); + + // ========== 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? anEnum); + + // ========== 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 aList); + + @async + List callFlutterEchoList(List aList); + + @async + Map callFlutterEchoMap(Map aMap); + + @async + AnEnum callFlutterEchoEnum(AnEnum anEnum); + + @async + bool? callFlutterEchoNullableBool(bool? aBool); + + @async + int? callFlutterEchoNullableInt(int? anInt); + + @async + double? callFlutterEchoNullableDouble(double? aDouble); + + @async + String? callFlutterEchoNullableString(String? aString); + + @async + Uint8List? callFlutterEchoNullableUint8List(Uint8List? aList); + + @async + List? callFlutterEchoNullableList(List? aList); + + @async + Map? callFlutterEchoNullableMap( + Map? aMap, + ); + + @async + AnEnum? callFlutterEchoNullableEnum(AnEnum? anEnum); +} 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..a26cefa855e9 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 @@ -9,7 +9,8 @@ import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; +import 'package:flutter/foundation.dart' + show ReadBuffer, WriteBuffer, immutable, protected; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { 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..f3a88bcd3782 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 @@ -9,8 +9,10 @@ import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; +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( @@ -30,6 +32,306 @@ List wrapResponse( return [error.code, error.message, error.details]; } +/// An immutable object that can provide functional copies of itself. +/// +/// All implementers are expected to be immutable as defined by the annotation. +@immutable +mixin $Copyable { + /// Instantiates and returns a functionally identical object to oneself. + /// + /// Outside of tests, this method should only ever be called by + /// [$InstanceManager]. + /// + /// Subclasses should always override their parent's implementation of this + /// method. + @protected + $Copyable $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 $InstanceManager { + /// Constructs an [$InstanceManager]. + $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; + + static final $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 $InstanceManager _initInstance() { + WidgetsFlutterBinding.ensureInitialized(); + final _InstanceManagerApi api = _InstanceManagerApi(); + // Clears the native `InstanceManager` on the initial use of the Dart one. + api.clear(); + final $InstanceManager instanceManager = $InstanceManager( + onWeakReferenceRemoved: (int identifier) { + api.removeStrongReference(identifier); + }, + ); + _InstanceManagerApi.$setUpMessageHandlers(instanceManager: instanceManager); + ProxyIntegrationCoreApi.$setUpMessageHandlers( + $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($Copyable 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($Copyable 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 $Copyable? weakInstance = _weakInstances[identifier]?.target; + + if (weakInstance == null) { + final $Copyable? strongInstance = _strongInstances[identifier]; + if (strongInstance != null) { + final $Copyable copy = strongInstance.$copy(); + _identifiers[copy] = identifier; + _weakInstances[identifier] = WeakReference<$Copyable>(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($Copyable 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($Copyable instance, int identifier) { + _addInstanceWithIdentifier(instance, identifier); + } + + void _addInstanceWithIdentifier($Copyable instance, int identifier) { + assert(!containsIdentifier(identifier)); + assert(getIdentifier(instance) == null); + assert(identifier >= 0); + + _identifiers[instance] = identifier; + _weakInstances[identifier] = WeakReference<$Copyable>(instance); + _finalizer.attach(instance, identifier, detach: instance); + + final $Copyable copy = instance.$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 `InstanceManager`s. +class _InstanceManagerApi { + /// Constructor for [_InstanceManagerApi]. + /// + /// The [binaryMessenger] named argument is available for dependency + /// injection. If it is left null, the default [BinaryMessenger] will be used + /// which routes to the host platform. + _InstanceManagerApi({BinaryMessenger? binaryMessenger}) + : _binaryMessenger = binaryMessenger; + + final BinaryMessenger? _binaryMessenger; + + static const MessageCodec pigeonChannelCodec = + StandardMessageCodec(); + + static void $setUpMessageHandlers({ + BinaryMessenger? binaryMessenger, + $InstanceManager? instanceManager, + }) { + const String channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.$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 ?? $InstanceManager.instance).remove(identifier!); + return; + }); + } + + Future removeStrongReference(int identifier) async { + const String channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.$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 `InstanceManager`. + /// + /// This is typically called after a hot restart. + Future clear() async { + const String channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.$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; + } + } +} + enum AnEnum { one, two, @@ -3446,3 +3748,3402 @@ abstract class FlutterSmallApi { } } } + +class _ProxyIntegrationCoreApiCodec extends StandardMessageCodec { + const _ProxyIntegrationCoreApiCodec(this.instanceManager); + + final $InstanceManager instanceManager; + + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is $Copyable) { + 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); + } + } +} + +/// The core interface that each host language plugin must implement in +/// platform_test integration tests. +class ProxyIntegrationCoreApi implements $Copyable { + ProxyIntegrationCoreApi({ + this.$binaryMessenger, + $InstanceManager? $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, + this.aNullableBool, + this.aNullableInt, + this.aNullableDouble, + this.aNullableString, + this.aNullableUint8List, + this.aNullableList, + this.aNullableMap, + this.aNullableEnum, + this.flutterNoop, + this.flutterThrowError, + this.flutterThrowErrorFromVoid, + this.flutterEchoBool, + this.flutterEchoInt, + this.flutterEchoDouble, + this.flutterEchoString, + this.flutterEchoUint8List, + this.flutterEchoList, + this.flutterEchoMap, + this.flutterEchoEnum, + this.flutterEchoNullableBool, + this.flutterEchoNullableInt, + this.flutterEchoNullableDouble, + this.flutterEchoNullableString, + this.flutterEchoNullableUint8List, + this.flutterEchoNullableList, + this.flutterEchoNullableMap, + this.flutterEchoNullableEnum, + this.callFlutterNoopAsync, + this.callFlutterEchoAsyncString, + required bool boolParam, + required int intParam, + required double doubleParam, + required String stringParam, + required Uint8List aUint8ListParam, + required List listParam, + required Map mapParam, + required AnEnum enumParam, + bool? nullableBoolParam, + int? nullableIntParam, + double? nullableDoubleParam, + String? nullableStringParam, + Uint8List? nullableUint8ListParam, + List? nullableListParam, + Map? nullableMapParam, + AnEnum? nullableEnumParam, + }) : $instanceManager = $instanceManager ?? $InstanceManager.instance { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.$defaultConstructor'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.send([ + this.$instanceManager.addDartCreatedInstance(this), + aBool, + anInt, + aDouble, + aString, + aUint8List, + aList, + aMap, + anEnum.index, + aNullableBool, + aNullableInt, + aNullableDouble, + aNullableString, + aNullableUint8List, + aNullableList, + aNullableMap, + aNullableEnum?.index, + boolParam, + intParam, + doubleParam, + stringParam, + aUint8ListParam, + listParam, + mapParam, + enumParam.index, + nullableBoolParam, + nullableIntParam, + nullableDoubleParam, + nullableStringParam, + nullableUint8ListParam, + nullableListParam, + nullableMapParam, + nullableEnumParam?.index, + ]).then((Object? value) { + final List? __pigeon_replyList = value 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], + ); + } + }); + } + + /// Constructs ProxyIntegrationCoreApi without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies. + ProxyIntegrationCoreApi.$detached({ + this.$binaryMessenger, + $InstanceManager? $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, + this.aNullableBool, + this.aNullableInt, + this.aNullableDouble, + this.aNullableString, + this.aNullableUint8List, + this.aNullableList, + this.aNullableMap, + this.aNullableEnum, + this.flutterNoop, + this.flutterThrowError, + this.flutterThrowErrorFromVoid, + this.flutterEchoBool, + this.flutterEchoInt, + this.flutterEchoDouble, + this.flutterEchoString, + this.flutterEchoUint8List, + this.flutterEchoList, + this.flutterEchoMap, + this.flutterEchoEnum, + this.flutterEchoNullableBool, + this.flutterEchoNullableInt, + this.flutterEchoNullableDouble, + this.flutterEchoNullableString, + this.flutterEchoNullableUint8List, + this.flutterEchoNullableList, + this.flutterEchoNullableMap, + this.flutterEchoNullableEnum, + this.callFlutterNoopAsync, + this.callFlutterEchoAsyncString, + }) : $instanceManager = $instanceManager ?? $InstanceManager.instance; + + late final _ProxyIntegrationCoreApiCodec _codecProxyIntegrationCoreApi = + _ProxyIntegrationCoreApiCodec($instanceManager); + + /// 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? $binaryMessenger; + + /// Maintains instances stored to communicate with native language objects. + final $InstanceManager $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 bool? aNullableBool; + + final int? aNullableInt; + + final double? aNullableDouble; + + final String? aNullableString; + + final Uint8List? aNullableUint8List; + + final List? aNullableList; + + final Map? aNullableMap; + + final AnEnum? aNullableEnum; + + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic calling. + final void Function(ProxyIntegrationCoreApi instance)? flutterNoop; + + /// Responds with an error from an async function returning a value. + final Object? Function(ProxyIntegrationCoreApi instance)? flutterThrowError; + + /// Responds with an error from an async void function. + final void Function(ProxyIntegrationCoreApi instance)? + flutterThrowErrorFromVoid; + + /// Returns the passed boolean, to test serialization and deserialization. + final bool Function( + ProxyIntegrationCoreApi instance, + bool aBool, + )? flutterEchoBool; + + /// Returns the passed int, to test serialization and deserialization. + final int Function( + ProxyIntegrationCoreApi instance, + int anInt, + )? flutterEchoInt; + + /// Returns the passed double, to test serialization and deserialization. + final double Function( + ProxyIntegrationCoreApi instance, + double aDouble, + )? flutterEchoDouble; + + /// Returns the passed string, to test serialization and deserialization. + final String Function( + ProxyIntegrationCoreApi instance, + String aString, + )? flutterEchoString; + + /// Returns the passed byte list, to test serialization and deserialization. + final Uint8List Function( + ProxyIntegrationCoreApi instance, + Uint8List aList, + )? flutterEchoUint8List; + + /// Returns the passed list, to test serialization and deserialization. + final List Function( + ProxyIntegrationCoreApi instance, + List aList, + )? flutterEchoList; + + /// Returns the passed map, to test serialization and deserialization. + final Map Function( + ProxyIntegrationCoreApi instance, + Map aMap, + )? flutterEchoMap; + + /// Returns the passed enum to test serialization and deserialization. + final AnEnum Function( + ProxyIntegrationCoreApi instance, + AnEnum anEnum, + )? flutterEchoEnum; + + /// Returns the passed boolean, to test serialization and deserialization. + final bool? Function( + ProxyIntegrationCoreApi instance, + bool? aBool, + )? flutterEchoNullableBool; + + /// Returns the passed int, to test serialization and deserialization. + final int? Function( + ProxyIntegrationCoreApi instance, + int? anInt, + )? flutterEchoNullableInt; + + /// Returns the passed double, to test serialization and deserialization. + final double? Function( + ProxyIntegrationCoreApi instance, + double? aDouble, + )? flutterEchoNullableDouble; + + /// Returns the passed string, to test serialization and deserialization. + final String? Function( + ProxyIntegrationCoreApi instance, + String? aString, + )? flutterEchoNullableString; + + /// Returns the passed byte list, to test serialization and deserialization. + final Uint8List? Function( + ProxyIntegrationCoreApi instance, + Uint8List? aList, + )? flutterEchoNullableUint8List; + + /// Returns the passed list, to test serialization and deserialization. + final List? Function( + ProxyIntegrationCoreApi instance, + List? aList, + )? flutterEchoNullableList; + + /// Returns the passed map, to test serialization and deserialization. + final Map? Function( + ProxyIntegrationCoreApi instance, + Map? aMap, + )? flutterEchoNullableMap; + + /// Returns the passed enum to test serialization and deserialization. + final AnEnum? Function( + ProxyIntegrationCoreApi instance, + AnEnum? anEnum, + )? flutterEchoNullableEnum; + + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic asynchronous calling. + final Future Function(ProxyIntegrationCoreApi instance)? + callFlutterNoopAsync; + + /// Returns the passed in generic Object asynchronously. + final Future Function( + ProxyIntegrationCoreApi instance, + String aString, + )? callFlutterEchoAsyncString; + + static void $setUpMessageHandlers({ + BinaryMessenger? $binaryMessenger, + $InstanceManager? $instanceManager, + ProxyIntegrationCoreApi Function( + bool aBool, + int anInt, + double aDouble, + String aString, + Uint8List aUint8List, + List aList, + Map aMap, + AnEnum anEnum, + bool? aNullableBool, + int? aNullableInt, + double? aNullableDouble, + String? aNullableString, + Uint8List? aNullableUint8List, + List? aNullableList, + Map? aNullableMap, + AnEnum? aNullableEnum, + )? $detached, + void Function(ProxyIntegrationCoreApi instance)? flutterNoop, + Object? Function(ProxyIntegrationCoreApi instance)? flutterThrowError, + void Function(ProxyIntegrationCoreApi instance)? flutterThrowErrorFromVoid, + bool Function( + ProxyIntegrationCoreApi instance, + bool aBool, + )? flutterEchoBool, + int Function( + ProxyIntegrationCoreApi instance, + int anInt, + )? flutterEchoInt, + double Function( + ProxyIntegrationCoreApi instance, + double aDouble, + )? flutterEchoDouble, + String Function( + ProxyIntegrationCoreApi instance, + String aString, + )? flutterEchoString, + Uint8List Function( + ProxyIntegrationCoreApi instance, + Uint8List aList, + )? flutterEchoUint8List, + List Function( + ProxyIntegrationCoreApi instance, + List aList, + )? flutterEchoList, + Map Function( + ProxyIntegrationCoreApi instance, + Map aMap, + )? flutterEchoMap, + AnEnum Function( + ProxyIntegrationCoreApi instance, + AnEnum anEnum, + )? flutterEchoEnum, + bool? Function( + ProxyIntegrationCoreApi instance, + bool? aBool, + )? flutterEchoNullableBool, + int? Function( + ProxyIntegrationCoreApi instance, + int? anInt, + )? flutterEchoNullableInt, + double? Function( + ProxyIntegrationCoreApi instance, + double? aDouble, + )? flutterEchoNullableDouble, + String? Function( + ProxyIntegrationCoreApi instance, + String? aString, + )? flutterEchoNullableString, + Uint8List? Function( + ProxyIntegrationCoreApi instance, + Uint8List? aList, + )? flutterEchoNullableUint8List, + List? Function( + ProxyIntegrationCoreApi instance, + List? aList, + )? flutterEchoNullableList, + Map? Function( + ProxyIntegrationCoreApi instance, + Map? aMap, + )? flutterEchoNullableMap, + AnEnum? Function( + ProxyIntegrationCoreApi instance, + AnEnum? anEnum, + )? flutterEchoNullableEnum, + Future Function(ProxyIntegrationCoreApi instance)? + callFlutterNoopAsync, + Future Function( + ProxyIntegrationCoreApi instance, + String aString, + )? callFlutterEchoAsyncString, + }) { + final _ProxyIntegrationCoreApiCodec pigeonChannelCodec = + _ProxyIntegrationCoreApiCodec( + $instanceManager ?? $InstanceManager.instance); + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.$detached'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final int? instanceIdentifier = (args[0] as int?); + assert( + instanceIdentifier != null, + 'Argument for $__pigeon_channelName was null, expected non-null int.', + ); + final bool? arg_aBool = (args[1] as bool?); + assert( + arg_aBool != null, + 'Argument for $__pigeon_channelName was null, expected non-null bool.', + ); + final int? arg_anInt = (args[2] as int?); + assert( + arg_anInt != null, + 'Argument for $__pigeon_channelName was null, expected non-null int.', + ); + final double? arg_aDouble = (args[3] as double?); + assert( + arg_aDouble != null, + 'Argument for $__pigeon_channelName was null, expected non-null double.', + ); + final String? arg_aString = (args[4] as String?); + assert( + arg_aString != null, + 'Argument for $__pigeon_channelName was null, expected non-null String.', + ); + final Uint8List? arg_aUint8List = (args[5] as Uint8List?); + assert( + arg_aUint8List != null, + 'Argument for $__pigeon_channelName was null, expected non-null Uint8List.', + ); + final List? arg_aList = + (args[6] as List?)?.cast(); + assert( + arg_aList != null, + 'Argument for $__pigeon_channelName was null, expected non-null List.', + ); + final Map? arg_aMap = + (args[7] as Map?)?.cast(); + assert( + arg_aMap != null, + 'Argument for $__pigeon_channelName 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 $__pigeon_channelName was null, expected non-null AnEnum.', + ); + final bool? arg_aNullableBool = (args[9] as bool?); + final int? arg_aNullableInt = (args[10] as int?); + final double? arg_aNullableDouble = (args[11] as double?); + final String? arg_aNullableString = (args[12] as String?); + final Uint8List? arg_aNullableUint8List = (args[13] as Uint8List?); + final List? arg_aNullableList = + (args[14] as List?)?.cast(); + final Map? arg_aNullableMap = + (args[15] as Map?)?.cast(); + final AnEnum? arg_aNullableEnum = + args[16] == null ? null : AnEnum.values[args[16]! as int]; + ($instanceManager ?? $InstanceManager.instance).addHostCreatedInstance( + $detached?.call( + arg_aBool!, + arg_anInt!, + arg_aDouble!, + arg_aString!, + arg_aUint8List!, + arg_aList!, + arg_aMap!, + arg_anEnum!, + arg_aNullableBool, + arg_aNullableInt, + arg_aNullableDouble, + arg_aNullableString, + arg_aNullableUint8List, + arg_aNullableList, + arg_aNullableMap, + arg_aNullableEnum, + ) ?? + ProxyIntegrationCoreApi.$detached( + $binaryMessenger: $binaryMessenger, + $instanceManager: $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!, + aNullableBool: arg_aNullableBool, + aNullableInt: arg_aNullableInt, + aNullableDouble: arg_aNullableDouble, + aNullableString: arg_aNullableString, + aNullableUint8List: arg_aNullableUint8List, + aNullableList: arg_aNullableList, + aNullableMap: arg_aNullableMap, + aNullableEnum: arg_aNullableEnum, + ), + instanceIdentifier!, + ); + return; + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterNoop'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + try { + (flutterNoop ?? instance!.flutterNoop)?.call(instance!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterThrowError'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + try { + final Object? output = + (flutterThrowError ?? instance!.flutterThrowError) + ?.call(instance!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterThrowErrorFromVoid'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + try { + (flutterThrowErrorFromVoid ?? instance!.flutterThrowErrorFromVoid) + ?.call(instance!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoBool'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final bool? arg_aBool = (args[1] as bool?); + assert( + arg_aBool != null, + 'Argument for $__pigeon_channelName was null, expected non-null bool.', + ); + try { + final bool? output = + (flutterEchoBool ?? instance!.flutterEchoBool)?.call( + 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()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoInt'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final int? arg_anInt = (args[1] as int?); + assert( + arg_anInt != null, + 'Argument for $__pigeon_channelName was null, expected non-null int.', + ); + try { + final int? output = + (flutterEchoInt ?? instance!.flutterEchoInt)?.call( + 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()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoDouble'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final double? arg_aDouble = (args[1] as double?); + assert( + arg_aDouble != null, + 'Argument for $__pigeon_channelName was null, expected non-null double.', + ); + try { + final double? output = + (flutterEchoDouble ?? instance!.flutterEchoDouble)?.call( + 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()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final String? arg_aString = (args[1] as String?); + assert( + arg_aString != null, + 'Argument for $__pigeon_channelName was null, expected non-null String.', + ); + try { + final String? output = + (flutterEchoString ?? instance!.flutterEchoString)?.call( + 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()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoUint8List'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final Uint8List? arg_aList = (args[1] as Uint8List?); + assert( + arg_aList != null, + 'Argument for $__pigeon_channelName was null, expected non-null Uint8List.', + ); + try { + final Uint8List? output = + (flutterEchoUint8List ?? instance!.flutterEchoUint8List)?.call( + 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()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoList'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final List? arg_aList = + (args[1] as List?)?.cast(); + assert( + arg_aList != null, + 'Argument for $__pigeon_channelName was null, expected non-null List.', + ); + try { + final List? output = + (flutterEchoList ?? instance!.flutterEchoList)?.call( + 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()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoMap'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final Map? arg_aMap = + (args[1] as Map?)?.cast(); + assert( + arg_aMap != null, + 'Argument for $__pigeon_channelName was null, expected non-null Map.', + ); + try { + final Map? output = + (flutterEchoMap ?? instance!.flutterEchoMap)?.call( + 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()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoEnum'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final AnEnum? arg_anEnum = + args[1] == null ? null : AnEnum.values[args[1]! as int]; + assert( + arg_anEnum != null, + 'Argument for $__pigeon_channelName was null, expected non-null AnEnum.', + ); + try { + final AnEnum? output = + (flutterEchoEnum ?? instance!.flutterEchoEnum)?.call( + 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()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableBool'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final bool? arg_aBool = (args[1] as bool?); + try { + final bool? output = + (flutterEchoNullableBool ?? instance!.flutterEchoNullableBool) + ?.call( + 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()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableInt'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final int? arg_anInt = (args[1] as int?); + try { + final int? output = + (flutterEchoNullableInt ?? instance!.flutterEchoNullableInt) + ?.call( + 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()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableDouble'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final double? arg_aDouble = (args[1] as double?); + try { + final double? output = + (flutterEchoNullableDouble ?? instance!.flutterEchoNullableDouble) + ?.call( + 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()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final String? arg_aString = (args[1] as String?); + try { + final String? output = + (flutterEchoNullableString ?? instance!.flutterEchoNullableString) + ?.call( + 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()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableUint8List'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final Uint8List? arg_aList = (args[1] as Uint8List?); + try { + final Uint8List? output = (flutterEchoNullableUint8List ?? + instance!.flutterEchoNullableUint8List) + ?.call( + 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()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableList'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final List? arg_aList = + (args[1] as List?)?.cast(); + try { + final List? output = + (flutterEchoNullableList ?? instance!.flutterEchoNullableList) + ?.call( + 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()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableMap'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final Map? arg_aMap = + (args[1] as Map?)?.cast(); + try { + final Map? output = + (flutterEchoNullableMap ?? instance!.flutterEchoNullableMap) + ?.call( + 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()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableEnum'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final AnEnum? arg_anEnum = + args[1] == null ? null : AnEnum.values[args[1]! as int]; + try { + final AnEnum? output = + (flutterEchoNullableEnum ?? instance!.flutterEchoNullableEnum) + ?.call( + 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()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterNoopAsync'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + try { + await (callFlutterNoopAsync ?? instance!.callFlutterNoopAsync) + ?.call(instance!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString()), + ); + } + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoAsyncString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final String? arg_aString = (args[1] as String?); + assert( + arg_aString != null, + 'Argument for $__pigeon_channelName was null, expected non-null String.', + ); + try { + final String? output = await (callFlutterEchoAsyncString ?? + instance!.callFlutterEchoAsyncString) + ?.call( + 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()), + ); + } + }); + } + } + + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic calling. + Future noop() async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.noop'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.throwError'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.throwErrorFromVoid'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.throwFlutterError'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoInt'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoDouble'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoBool'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoUint8List'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoObject'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoList'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoMap'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoEnum'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 passed in int. + Future echoNullableInt(int? aNullableInt) async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableInt'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableDouble'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableBool'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableUint8List'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableObject'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableList'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableMap'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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? anEnum) async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableEnum'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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]; + } + } + + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic asynchronous calling. + Future noopAsync() async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.noopAsync'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncInt'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncDouble'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncBool'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncUint8List'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncObject'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncList'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncMap'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncEnum'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.throwAsyncError'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.throwAsyncErrorFromVoid'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.throwAsyncFlutterError'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableInt'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableDouble'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableBool'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableUint8List'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableObject'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableList'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableMap'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableEnum'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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? $binaryMessenger, + $InstanceManager? $instanceManager, + }) async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.staticNoop'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _ProxyIntegrationCoreApiCodec( + $instanceManager ?? $InstanceManager.instance), + binaryMessenger: $binaryMessenger, + ); + final List? __pigeon_replyList = + (await __pigeon_channel.send([]) 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? $binaryMessenger, + $InstanceManager? $instanceManager, + }) async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoStaticString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _ProxyIntegrationCoreApiCodec( + $instanceManager ?? $InstanceManager.instance), + binaryMessenger: $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? $binaryMessenger, + $InstanceManager? $instanceManager, + }) async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.staticAsyncNoop'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _ProxyIntegrationCoreApiCodec( + $instanceManager ?? $InstanceManager.instance), + binaryMessenger: $binaryMessenger, + ); + final List? __pigeon_replyList = + (await __pigeon_channel.send([]) 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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterNoop'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterThrowError'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterThrowErrorFromVoid'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoBool'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoInt'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoDouble'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 aList) async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoUint8List'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 Uint8List?)!; + } + } + + Future> callFlutterEchoList(List aList) async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoList'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoMap'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoEnum'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 callFlutterEchoNullableBool(bool? aBool) async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableBool'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableInt'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableDouble'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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? aList) async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableUint8List'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 Uint8List?); + } + } + + Future?> callFlutterEchoNullableList( + List? aList) async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableList'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableMap'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableEnum'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + binaryMessenger: $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]; + } + } + + @override + ProxyIntegrationCoreApi $copy() { + return ProxyIntegrationCoreApi.$detached( + $binaryMessenger: $binaryMessenger, + $instanceManager: $instanceManager, + aBool: aBool, + anInt: anInt, + aDouble: aDouble, + aString: aString, + aUint8List: aUint8List, + aList: aList, + aMap: aMap, + anEnum: anEnum, + aNullableBool: aNullableBool, + aNullableInt: aNullableInt, + aNullableDouble: aNullableDouble, + aNullableString: aNullableString, + aNullableUint8List: aNullableUint8List, + aNullableList: aNullableList, + aNullableMap: aNullableMap, + aNullableEnum: aNullableEnum, + flutterNoop: flutterNoop, + flutterThrowError: flutterThrowError, + flutterThrowErrorFromVoid: flutterThrowErrorFromVoid, + flutterEchoBool: flutterEchoBool, + flutterEchoInt: flutterEchoInt, + flutterEchoDouble: flutterEchoDouble, + flutterEchoString: flutterEchoString, + flutterEchoUint8List: flutterEchoUint8List, + flutterEchoList: flutterEchoList, + flutterEchoMap: flutterEchoMap, + flutterEchoEnum: flutterEchoEnum, + flutterEchoNullableBool: flutterEchoNullableBool, + flutterEchoNullableInt: flutterEchoNullableInt, + flutterEchoNullableDouble: flutterEchoNullableDouble, + flutterEchoNullableString: flutterEchoNullableString, + flutterEchoNullableUint8List: flutterEchoNullableUint8List, + flutterEchoNullableList: flutterEchoNullableList, + flutterEchoNullableMap: flutterEchoNullableMap, + flutterEchoNullableEnum: flutterEchoNullableEnum, + callFlutterNoopAsync: callFlutterNoopAsync, + callFlutterEchoAsyncString: callFlutterEchoAsyncString, + ); + } +} 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..9e6b2fc35361 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 @@ -9,7 +9,8 @@ import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; +import 'package:flutter/foundation.dart' + show ReadBuffer, WriteBuffer, immutable, protected; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { 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..782288d0e31f 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 @@ -9,7 +9,8 @@ import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; +import 'package:flutter/foundation.dart' + show ReadBuffer, WriteBuffer, immutable, protected; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { 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..0840d5478a22 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 @@ -9,7 +9,8 @@ import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; +import 'package:flutter/foundation.dart' + show ReadBuffer, WriteBuffer, immutable, protected; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { 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..c7094a718bc5 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 @@ -9,7 +9,8 @@ import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; +import 'package:flutter/foundation.dart' + show ReadBuffer, WriteBuffer, immutable, protected; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { 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..a852f522aaa5 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 @@ -9,7 +9,8 @@ import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; +import 'package:flutter/foundation.dart' + show ReadBuffer, WriteBuffer, immutable, protected; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { 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..389905f8e829 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 @@ -9,7 +9,8 @@ import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; +import 'package:flutter/foundation.dart' + show ReadBuffer, WriteBuffer, immutable, protected; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { 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..bd8833dee205 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 @@ -9,7 +9,8 @@ import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; +import 'package:flutter/foundation.dart' + show ReadBuffer, WriteBuffer, immutable, protected; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { 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..91db25103325 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 @@ -9,7 +9,8 @@ import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; +import 'package:flutter/foundation.dart' + show ReadBuffer, WriteBuffer, immutable, protected; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h index 53c3320b3cf1..ff8ab3fa850b 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h @@ -59,6 +59,7 @@ class ErrorOr { friend class HostTrivialApi; friend class HostSmallApi; friend class FlutterSmallApi; + friend class ProxyIntegrationCoreApi; ErrorOr() = default; T TakeValue() && { return std::get(std::move(v_)); } @@ -136,6 +137,8 @@ class AllTypes { friend class HostSmallApiCodecSerializer; friend class FlutterSmallApi; friend class FlutterSmallApiCodecSerializer; + friend class ProxyIntegrationCoreApi; + friend class ProxyIntegrationCoreApiCodecSerializer; friend class CoreTestsTest; bool a_bool_; int64_t an_int_; @@ -256,6 +259,8 @@ class AllNullableTypes { friend class HostSmallApiCodecSerializer; friend class FlutterSmallApi; friend class FlutterSmallApiCodecSerializer; + friend class ProxyIntegrationCoreApi; + friend class ProxyIntegrationCoreApiCodecSerializer; friend class CoreTestsTest; std::optional a_nullable_bool_; std::optional a_nullable_int_; @@ -312,6 +317,8 @@ class AllClassesWrapper { friend class HostSmallApiCodecSerializer; friend class FlutterSmallApi; friend class FlutterSmallApiCodecSerializer; + friend class ProxyIntegrationCoreApi; + friend class ProxyIntegrationCoreApiCodecSerializer; friend class CoreTestsTest; AllNullableTypes all_nullable_types_; std::optional all_types_; @@ -345,6 +352,8 @@ class TestMessage { friend class HostSmallApiCodecSerializer; friend class FlutterSmallApi; friend class FlutterSmallApiCodecSerializer; + friend class ProxyIntegrationCoreApi; + friend class ProxyIntegrationCoreApiCodecSerializer; friend class CoreTestsTest; std::optional test_list_; }; From 00aafe6fe30a0469bec09b378f73475a0b1e8e02 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 12 Dec 2023 22:29:30 -0500 Subject: [PATCH 26/73] ensure constructor parameter names dont overlap field or flutter method names --- packages/pigeon/lib/pigeon_lib.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 19c88b6a4849..7a4dab1039ed 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -1008,6 +1008,16 @@ List _validateProxyApi( 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: From c5b3790fea8ffda9b00b9deac90ca3482dcfb3ee Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 13 Dec 2023 20:57:10 -0500 Subject: [PATCH 27/73] some unit tests --- packages/pigeon/lib/pigeon_lib.dart | 2 - packages/pigeon/test/dart_generator_test.dart | 505 +++++++++++++++++- 2 files changed, 484 insertions(+), 23 deletions(-) diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 7a4dab1039ed..e43a843fa8fd 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -894,8 +894,6 @@ List _validateProxyApi( required Set customClasses, required Set proxyApis, }) { - // TODO: Verify constructor params dont overlap field params - final List result = []; bool isDataClass(NamedType type) => diff --git a/packages/pigeon/test/dart_generator_test.dart b/packages/pigeon/test/dart_generator_test.dart index 061e31c0ba26..b4744e6b0837 100644 --- a/packages/pigeon/test/dart_generator_test.dart +++ b/packages/pigeon/test/dart_generator_test.dart @@ -1740,30 +1740,62 @@ name: foobar }); group('ProxyApi', () { - test('gen one api', () { + test('one api', () { final Root root = Root(apis: [ - AstProxyApi( - name: 'Api', - constructors: [], - fields: [], - methods: [ - Method( - name: 'doSomething', - location: ApiLocation.host, - parameters: [ - Parameter( - type: const TypeDeclaration( - baseName: 'Input', - isNullable: false, - ), - name: 'input') - ], - returnType: const TypeDeclaration( - baseName: 'String', + AstProxyApi(name: 'Api', constructors: [ + Constructor(name: 'name', parameters: [ + Parameter( + type: const TypeDeclaration( + baseName: 'Input', + isNullable: false, + ), + name: 'input', + ), + ]), + ], fields: [ + Field( + 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, + ), + ), + ]) ], classes: [], enums: []); final StringBuffer sink = StringBuffer(); const DartGenerator generator = DartGenerator(); @@ -1774,8 +1806,439 @@ name: foobar dartPackageName: DEFAULT_PACKAGE_NAME, ); final String code = sink.toString(); - expect(code, contains('class Api')); + final String collapsedCode = _collapseNewlineAndIndentation(code); + + // Instance Manager + expect(code, contains(r'class $InstanceManager')); + expect(code, contains(r'class _InstanceManagerApi')); + + // Codec and class + expect(code, contains('class _ApiCodec')); + expect(code, contains(r'class Api implements $Copyable')); + + // Constructors + expect( + collapsedCode, + contains( + r'Api.name({ this.$binaryMessenger, $InstanceManager? $instanceManager, required this.someField, this.doSomethingElse, required Input input, })', + ), + ); + expect( + code, + contains( + r'Api.$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 $setUpMessageHandlers({')); + expect( + collapsedCode, + contains( + 'final String Function( Api instance, Input input, )? doSomethingElse;', + ), + ); + + // Copy method + expect(code, contains(r'Api $copy')); + }); + + group('inheritance', () { + test('extends', () { + final Root root = Root(apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [], + methods: [], + superClassName: 'Api2', + ), + AstProxyApi( + name: 'Api2', + constructors: [], + 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(r'class Api extends Api2')); + expect( + collapsedCode, + contains( + r'Api.$detached({ super.$binaryMessenger, super.$instanceManager, }) : super.$detached();', + ), + ); + }); + + test('implements', () { + final Root root = Root(apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [], + methods: [], + interfacesNames: {'Api2'}, + ), + AstProxyApi( + name: 'Api2', + constructors: [], + 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(); + expect(code, contains(r'class Api implements Api2')); + }); + + test('implements 2 ProxyApis', () { + final Root root = Root(apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [], + methods: [], + interfacesNames: {'Api2', 'Api3'}, + ), + AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ), + AstProxyApi( + name: 'Api3', + constructors: [], + 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(); + expect(code, contains(r'class Api implements Api2, Api3')); + }); + }); + + 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({ this.$binaryMessenger, ' + r'$InstanceManager? $instanceManager, })', + ), + ); + expect( + collapsedCode, + contains( + r"const String __pigeon_channelName = r'dev.flutter.pigeon.test_package.Api.$defaultConstructor';", + ), + ); + expect( + collapsedCode, + contains( + r'__pigeon_channel.send([ ' + r'this.$instanceManager.addDartCreatedInstance(this) ])', + ), + ); + }); + + test('multiple params constructor', () { + 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: const TypeDeclaration( + isNullable: false, + baseName: '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: const TypeDeclaration( + isNullable: true, + baseName: 'AnEnum', + ), + name: 'nullableEnumType', + ), + Parameter( + type: const TypeDeclaration( + isNullable: true, + baseName: 'Api2', + ), + name: 'nullableProxyApiType', + ), + ], + ) + ], fields: [], methods: []), + AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ) + ], + classes: [], + enums: [ + Enum( + name: 'AnEnum', + members: [EnumMember(name: 'one')], + ), + ], + ); + 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({ this.$binaryMessenger, ' + r'$InstanceManager? $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'this.$instanceManager.addDartCreatedInstance(this), ' + r'validType, enumType, proxyApiType, ' + r'nullableValidType, nullableEnumType, nullableProxyApiType, ])', + ), + ); + }); + }); + + group('Host methods', () { + test('multiple params host method', () { + 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: 'x', + ), + Parameter( + type: const TypeDeclaration( + isNullable: false, baseName: 'int'), + name: 'y', + ), + ], + 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'Future doSomething( int x, int y, )'), + ); + expect( + collapsedCode, + contains(r'await __pigeon_channel.send([ this, x, y, ])'), + ); + }); + }); + + group('Flutter methods', () { + test('multiple params flutter method', () { + final Root root = Root(apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [], + methods: [ + Method( + name: 'doSomething', + location: ApiLocation.flutter, + parameters: [ + Parameter( + type: const TypeDeclaration( + isNullable: false, baseName: 'int'), + name: 'x', + ), + Parameter( + type: const TypeDeclaration( + isNullable: false, baseName: 'int'), + name: 'y', + ), + ], + 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'final void Function( Api instance, int x, int y, )? doSomething;', + ), + ); + expect( + collapsedCode, + contains( + r'void Function( Api instance, int x, int y, )? doSomething'), + ); + expect( + code, + contains(r'final Api? instance = (args[0] as Api?);'), + ); + expect( + code, + contains(r'final int? arg_x = (args[1] as int?);'), + ); + expect( + code, + contains(r'final int? arg_y = (args[2] as int?);'), + ); + expect( + collapsedCode, + contains( + r'(doSomething ?? instance!.doSomething)?.call( instance!, arg_x!, arg_y!, );', + ), + ); + }); }); }); } + +/// 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 fb20cd9227072b45c83a01cee1ab3e9d6b5dd44f Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 13 Dec 2023 22:38:57 -0500 Subject: [PATCH 28/73] more tests --- packages/pigeon/test/dart_generator_test.dart | 288 ++++++++++++++++-- 1 file changed, 255 insertions(+), 33 deletions(-) diff --git a/packages/pigeon/test/dart_generator_test.dart b/packages/pigeon/test/dart_generator_test.dart index b4744e6b0837..9749c15712a4 100644 --- a/packages/pigeon/test/dart_generator_test.dart +++ b/packages/pigeon/test/dart_generator_test.dart @@ -1946,6 +1946,58 @@ name: foobar final String code = sink.toString(); expect(code, contains(r'class Api implements Api2, Api3')); }); + + test('implements inherits flutter method', () { + final Root root = Root(apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [], + methods: [], + interfacesNames: {'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, + required: true, + ), + ], + ), + ], 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 implements Api2')); + expect( + collapsedCode, + contains( + r'Api.$detached({ this.$binaryMessenger, ' + r'$InstanceManager? $instanceManager, ' + r'this.aFlutterMethod, ' + r'required this.aNullableFlutterMethod, })', + ), + ); + }); }); group('Constructors', () { @@ -1996,6 +2048,10 @@ name: foobar }); test('multiple params constructor', () { + final Enum anEnum = Enum( + name: 'AnEnum', + members: [EnumMember(name: 'one')], + ); final Root root = Root( apis: [ AstProxyApi(name: 'Api', constructors: [ @@ -2010,9 +2066,10 @@ name: foobar name: 'validType', ), Parameter( - type: const TypeDeclaration( + type: TypeDeclaration( isNullable: false, baseName: 'AnEnum', + associatedEnum: anEnum, ), name: 'enumType', ), @@ -2031,9 +2088,10 @@ name: foobar name: 'nullableValidType', ), Parameter( - type: const TypeDeclaration( + type: TypeDeclaration( isNullable: true, baseName: 'AnEnum', + associatedEnum: anEnum, ), name: 'nullableEnumType', ), @@ -2052,15 +2110,10 @@ name: foobar constructors: [], fields: [], methods: [], - ) - ], - classes: [], - enums: [ - Enum( - name: 'AnEnum', - members: [EnumMember(name: 'one')], ), ], + classes: [], + enums: [anEnum], ); final StringBuffer sink = StringBuffer(); const DartGenerator generator = DartGenerator(); @@ -2091,17 +2144,22 @@ name: foobar contains( r'__pigeon_channel.send([ ' r'this.$instanceManager.addDartCreatedInstance(this), ' - r'validType, enumType, proxyApiType, ' - r'nullableValidType, nullableEnumType, nullableProxyApiType, ])', + r'validType, enumType.index, proxyApiType, ' + r'nullableValidType, nullableEnumType?.index, nullableProxyApiType, ])', ), ); }); }); group('Host methods', () { - test('multiple params host method', () { - final Root root = Root(apis: [ - AstProxyApi( + test('multiple params method', () { + final Enum anEnum = Enum( + name: 'AnEnum', + members: [EnumMember(name: 'one')], + ); + final Root root = Root( + apis: [ + AstProxyApi( name: 'Api', constructors: [], fields: [], @@ -2112,19 +2170,63 @@ name: foobar parameters: [ Parameter( type: const TypeDeclaration( - isNullable: false, baseName: 'int'), - name: 'x', + 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: false, baseName: 'int'), - name: 'y', + isNullable: true, + baseName: 'Api2', + ), + name: 'nullableProxyApiType', ), ], returnType: const TypeDeclaration.voidDeclaration(), - ) - ]) - ], classes: [], enums: []); + ), + ], + ), + AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ), + ], + classes: [], + enums: [anEnum], + ); final StringBuffer sink = StringBuffer(); const DartGenerator generator = DartGenerator(); generator.generate( @@ -2138,17 +2240,74 @@ name: foobar expect(code, contains('class Api')); expect( collapsedCode, - contains(r'Future doSomething( int x, int y, )'), + 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, x, y, ])'), + 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? $binaryMessenger, ' + r'$InstanceManager? $instanceManager, })', + ), + ); + expect( + collapsedCode, + contains(r'await __pigeon_channel.send([])'), ); }); }); 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', @@ -2161,19 +2320,55 @@ name: foobar parameters: [ Parameter( type: const TypeDeclaration( - isNullable: false, baseName: 'int'), - name: 'x', + 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: false, baseName: 'int'), - name: 'y', + isNullable: true, + baseName: 'Api2', + ), + name: 'nullableProxyApiType', ), ], returnType: const TypeDeclaration.voidDeclaration(), ) ]) - ], classes: [], enums: []); + ], classes: [], enums: [ + anEnum + ]); final StringBuffer sink = StringBuffer(); const DartGenerator generator = DartGenerator(); generator.generate( @@ -2188,13 +2383,19 @@ name: foobar expect( collapsedCode, contains( - r'final void Function( Api instance, int x, int y, )? doSomething;', + r'final void Function( Api instance, int validType, ' + r'AnEnum enumType, Api2 proxyApiType, int? nullableValidType, ' + r'AnEnum? nullableEnumType, Api2? nullableProxyApiType, )? ' + r'doSomething;', ), ); expect( collapsedCode, contains( - r'void Function( Api instance, int x, int y, )? doSomething'), + r'void Function( Api instance, int validType, AnEnum enumType, ' + r'Api2 proxyApiType, int? nullableValidType, ' + r'AnEnum? nullableEnumType, Api2? nullableProxyApiType, )? ' + r'doSomething'), ); expect( code, @@ -2202,16 +2403,37 @@ name: foobar ); expect( code, - contains(r'final int? arg_x = (args[1] as int?);'), + 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 int? arg_y = (args[2] as int?);'), + 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 ?? instance!.doSomething)?.call( instance!, arg_x!, arg_y!, );', + r'(doSomething ?? instance!.doSomething)?.call( instance!, ' + r'arg_validType!, arg_enumType!, arg_proxyApiType!, ' + r'arg_nullableValidType, arg_nullableEnumType, ' + r'arg_nullableProxyApiType, );', ), ); }); From 3aa0fe94b3361b0c7f39fda155809cb4dfea573d Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 13 Dec 2023 23:22:12 -0500 Subject: [PATCH 29/73] test fields --- packages/pigeon/test/dart_generator_test.dart | 223 ++++++++++++++++++ 1 file changed, 223 insertions(+) diff --git a/packages/pigeon/test/dart_generator_test.dart b/packages/pigeon/test/dart_generator_test.dart index 9749c15712a4..ca2cd83c8aa7 100644 --- a/packages/pigeon/test/dart_generator_test.dart +++ b/packages/pigeon/test/dart_generator_test.dart @@ -2151,6 +2151,229 @@ name: foobar }); }); + 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: [ + Field( + type: const TypeDeclaration( + isNullable: false, + baseName: 'int', + ), + name: 'validType', + ), + Field( + type: TypeDeclaration( + isNullable: false, + baseName: 'AnEnum', + associatedEnum: anEnum, + ), + name: 'enumType', + ), + Field( + type: const TypeDeclaration( + isNullable: false, + baseName: 'Api2', + ), + name: 'proxyApiType', + ), + Field( + type: const TypeDeclaration( + isNullable: true, + baseName: 'int', + ), + name: 'nullableValidType', + ), + Field( + type: TypeDeclaration( + isNullable: true, + baseName: 'AnEnum', + associatedEnum: anEnum, + ), + name: 'nullableEnumType', + ), + Field( + 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({ this.$binaryMessenger, ' + r'$InstanceManager? $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'this.$instanceManager.addDartCreatedInstance(this), ' + 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: [ + Field( + 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 = _aField();')); + expect(code, contains(r'Api2 _aField()')); + }); + + test('static attached field', () { + final AstProxyApi api2 = AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ); + final Root root = Root( + apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [ + Field( + 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 = _aField();')); + expect(code, contains(r'static Api2 _aField()')); + }); + }); + group('Host methods', () { test('multiple params method', () { final Enum anEnum = Enum( From 147604a1f375b17d48f7507e7a30474f419fc372 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 13 Dec 2023 23:45:46 -0500 Subject: [PATCH 30/73] core tests inheritance and error for double super class naming --- packages/pigeon/lib/pigeon_lib.dart | 18 +- packages/pigeon/pigeons/core_tests.dart | 15 +- .../lib/src/generated/core_tests.gen.dart | 290 +++++++++++++++++- .../windows/pigeon/core_tests.gen.h | 18 ++ 4 files changed, 321 insertions(+), 20 deletions(-) diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index e43a843fa8fd..c34fd50237a2 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -120,6 +120,9 @@ class ProxyApi { /// /// 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; } @@ -1384,13 +1387,24 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { } } + 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, methods: [], constructors: [], fields: [], - superClassName: annotationMap['superClass'] as String? ?? - node.extendsClause?.superclass.name2.lexeme, + superClassName: + superClassName ?? node.extendsClause?.superclass.name2.lexeme, interfacesNames: node.implementsClause?.interfaces .map((dart_ast.NamedType type) => type.name2.lexeme) .toSet() ?? diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index 6000f014b161..1a1656df33db 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -703,7 +703,8 @@ class TestMessage { /// The core interface that each host language plugin must implement in /// platform_test integration tests. @ProxyApi() -abstract class ProxyIntegrationCoreApi { +abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass + implements ProxyApiInterface { ProxyIntegrationCoreApi( // ignore: avoid_unused_constructor_parameters bool boolParam, @@ -1069,3 +1070,15 @@ abstract class ProxyIntegrationCoreApi { @async AnEnum? callFlutterEchoNullableEnum(AnEnum? anEnum); } + +/// ProxyApi to serve as a super class to the core ProxyApi interface. +@ProxyApi() +abstract class 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/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 f3a88bcd3782..69117ef83202 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 @@ -113,6 +113,8 @@ class $InstanceManager { _InstanceManagerApi.$setUpMessageHandlers(instanceManager: instanceManager); ProxyIntegrationCoreApi.$setUpMessageHandlers( $instanceManager: instanceManager); + ProxyApiSuperClass.$setUpMessageHandlers($instanceManager: instanceManager); + ProxyApiInterface.$setUpMessageHandlers($instanceManager: instanceManager); return instanceManager; } @@ -3778,10 +3780,11 @@ class _ProxyIntegrationCoreApiCodec extends StandardMessageCodec { /// The core interface that each host language plugin must implement in /// platform_test integration tests. -class ProxyIntegrationCoreApi implements $Copyable { +class ProxyIntegrationCoreApi extends ProxyApiSuperClass + implements ProxyApiInterface { ProxyIntegrationCoreApi({ - this.$binaryMessenger, - $InstanceManager? $instanceManager, + super.$binaryMessenger, + super.$instanceManager, required this.aBool, required this.anInt, required this.aDouble, @@ -3798,6 +3801,7 @@ class ProxyIntegrationCoreApi implements $Copyable { this.aNullableList, this.aNullableMap, this.aNullableEnum, + this.anInterfaceMethod, this.flutterNoop, this.flutterThrowError, this.flutterThrowErrorFromVoid, @@ -3835,7 +3839,7 @@ class ProxyIntegrationCoreApi implements $Copyable { List? nullableListParam, Map? nullableMapParam, AnEnum? nullableEnumParam, - }) : $instanceManager = $instanceManager ?? $InstanceManager.instance { + }) : super.$detached() { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.$defaultConstructor'; final BasicMessageChannel __pigeon_channel = @@ -3845,7 +3849,7 @@ class ProxyIntegrationCoreApi implements $Copyable { binaryMessenger: $binaryMessenger, ); __pigeon_channel.send([ - this.$instanceManager.addDartCreatedInstance(this), + $instanceManager.addDartCreatedInstance(this), aBool, anInt, aDouble, @@ -3897,8 +3901,8 @@ class ProxyIntegrationCoreApi implements $Copyable { /// This should only be used by subclasses created by this library or to /// create copies. ProxyIntegrationCoreApi.$detached({ - this.$binaryMessenger, - $InstanceManager? $instanceManager, + super.$binaryMessenger, + super.$instanceManager, required this.aBool, required this.anInt, required this.aDouble, @@ -3915,6 +3919,7 @@ class ProxyIntegrationCoreApi implements $Copyable { this.aNullableList, this.aNullableMap, this.aNullableEnum, + this.anInterfaceMethod, this.flutterNoop, this.flutterThrowError, this.flutterThrowErrorFromVoid, @@ -3936,20 +3941,11 @@ class ProxyIntegrationCoreApi implements $Copyable { this.flutterEchoNullableEnum, this.callFlutterNoopAsync, this.callFlutterEchoAsyncString, - }) : $instanceManager = $instanceManager ?? $InstanceManager.instance; + }) : super.$detached(); late final _ProxyIntegrationCoreApiCodec _codecProxyIntegrationCoreApi = _ProxyIntegrationCoreApiCodec($instanceManager); - /// 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? $binaryMessenger; - - /// Maintains instances stored to communicate with native language objects. - final $InstanceManager $instanceManager; - final bool aBool; final int anInt; @@ -4100,6 +4096,9 @@ class ProxyIntegrationCoreApi implements $Copyable { String aString, )? callFlutterEchoAsyncString; + @override + final void Function(ProxyApiInterface instance)? anInterfaceMethod; + static void $setUpMessageHandlers({ BinaryMessenger? $binaryMessenger, $InstanceManager? $instanceManager, @@ -7123,6 +7122,7 @@ class ProxyIntegrationCoreApi implements $Copyable { aNullableList: aNullableList, aNullableMap: aNullableMap, aNullableEnum: aNullableEnum, + anInterfaceMethod: anInterfaceMethod, flutterNoop: flutterNoop, flutterThrowError: flutterThrowError, flutterThrowErrorFromVoid: flutterThrowErrorFromVoid, @@ -7147,3 +7147,259 @@ class ProxyIntegrationCoreApi implements $Copyable { ); } } + +class _ProxyApiSuperClassCodec extends StandardMessageCodec { + const _ProxyApiSuperClassCodec(this.instanceManager); + + final $InstanceManager instanceManager; + + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is $Copyable) { + 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); + } + } +} + +/// ProxyApi to serve as a super class to the core ProxyApi interface. +class ProxyApiSuperClass implements $Copyable { + /// Constructs ProxyApiSuperClass without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies. + ProxyApiSuperClass.$detached({ + this.$binaryMessenger, + $InstanceManager? $instanceManager, + }) : $instanceManager = $instanceManager ?? $InstanceManager.instance; + + late final _ProxyApiSuperClassCodec _codecProxyApiSuperClass = + _ProxyApiSuperClassCodec($instanceManager); + + /// 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? $binaryMessenger; + + /// Maintains instances stored to communicate with native language objects. + final $InstanceManager $instanceManager; + + static void $setUpMessageHandlers({ + BinaryMessenger? $binaryMessenger, + $InstanceManager? $instanceManager, + ProxyApiSuperClass Function()? $detached, + }) { + final _ProxyApiSuperClassCodec pigeonChannelCodec = + _ProxyApiSuperClassCodec($instanceManager ?? $InstanceManager.instance); + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.$detached'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final int? instanceIdentifier = (args[0] as int?); + assert( + instanceIdentifier != null, + 'Argument for $__pigeon_channelName was null, expected non-null int.', + ); + ($instanceManager ?? $InstanceManager.instance).addHostCreatedInstance( + $detached?.call() ?? + ProxyApiSuperClass.$detached( + $binaryMessenger: $binaryMessenger, + $instanceManager: $instanceManager, + ), + instanceIdentifier!, + ); + return; + }); + } + } + + Future aSuperMethod() async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.aSuperMethod'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyApiSuperClass, + binaryMessenger: $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 $copy() { + return ProxyApiSuperClass.$detached( + $binaryMessenger: $binaryMessenger, + $instanceManager: $instanceManager, + ); + } +} + +class _ProxyApiInterfaceCodec extends StandardMessageCodec { + const _ProxyApiInterfaceCodec(this.instanceManager); + + final $InstanceManager instanceManager; + + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is $Copyable) { + 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); + } + } +} + +/// ProxyApi to serve as an interface to the core ProxyApi interface. +class ProxyApiInterface implements $Copyable { + /// Constructs ProxyApiInterface without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies. + ProxyApiInterface.$detached({ + this.$binaryMessenger, + $InstanceManager? $instanceManager, + this.anInterfaceMethod, + }) : $instanceManager = $instanceManager ?? $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? $binaryMessenger; + + /// Maintains instances stored to communicate with native language objects. + final $InstanceManager $instanceManager; + + final void Function(ProxyApiInterface instance)? anInterfaceMethod; + + static void $setUpMessageHandlers({ + BinaryMessenger? $binaryMessenger, + $InstanceManager? $instanceManager, + ProxyApiInterface Function()? $detached, + void Function(ProxyApiInterface instance)? anInterfaceMethod, + }) { + final _ProxyApiInterfaceCodec pigeonChannelCodec = + _ProxyApiInterfaceCodec($instanceManager ?? $InstanceManager.instance); + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.$detached'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final int? instanceIdentifier = (args[0] as int?); + assert( + instanceIdentifier != null, + 'Argument for $__pigeon_channelName was null, expected non-null int.', + ); + ($instanceManager ?? $InstanceManager.instance).addHostCreatedInstance( + $detached?.call() ?? + ProxyApiInterface.$detached( + $binaryMessenger: $binaryMessenger, + $instanceManager: $instanceManager, + ), + instanceIdentifier!, + ); + return; + }); + } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.anInterfaceMethod'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: $binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyApiInterface? instance = (args[0] as ProxyApiInterface?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyApiInterface.', + ); + try { + (anInterfaceMethod ?? instance!.anInterfaceMethod)?.call(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 $copy() { + return ProxyApiInterface.$detached( + $binaryMessenger: $binaryMessenger, + $instanceManager: $instanceManager, + anInterfaceMethod: anInterfaceMethod, + ); + } +} diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h index ff8ab3fa850b..866e1b504c48 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h @@ -60,6 +60,8 @@ class ErrorOr { friend class HostSmallApi; friend class FlutterSmallApi; friend class ProxyIntegrationCoreApi; + friend class ProxyApiSuperClass; + friend class ProxyApiInterface; ErrorOr() = default; T TakeValue() && { return std::get(std::move(v_)); } @@ -139,6 +141,10 @@ class AllTypes { friend class FlutterSmallApiCodecSerializer; friend class ProxyIntegrationCoreApi; friend class ProxyIntegrationCoreApiCodecSerializer; + friend class ProxyApiSuperClass; + friend class ProxyApiSuperClassCodecSerializer; + friend class ProxyApiInterface; + friend class ProxyApiInterfaceCodecSerializer; friend class CoreTestsTest; bool a_bool_; int64_t an_int_; @@ -261,6 +267,10 @@ class AllNullableTypes { friend class FlutterSmallApiCodecSerializer; friend class ProxyIntegrationCoreApi; friend class ProxyIntegrationCoreApiCodecSerializer; + friend class ProxyApiSuperClass; + friend class ProxyApiSuperClassCodecSerializer; + friend class ProxyApiInterface; + friend class ProxyApiInterfaceCodecSerializer; friend class CoreTestsTest; std::optional a_nullable_bool_; std::optional a_nullable_int_; @@ -319,6 +329,10 @@ class AllClassesWrapper { friend class FlutterSmallApiCodecSerializer; friend class ProxyIntegrationCoreApi; friend class ProxyIntegrationCoreApiCodecSerializer; + friend class ProxyApiSuperClass; + friend class ProxyApiSuperClassCodecSerializer; + friend class ProxyApiInterface; + friend class ProxyApiInterfaceCodecSerializer; friend class CoreTestsTest; AllNullableTypes all_nullable_types_; std::optional all_types_; @@ -354,6 +368,10 @@ class TestMessage { friend class FlutterSmallApiCodecSerializer; friend class ProxyIntegrationCoreApi; friend class ProxyIntegrationCoreApiCodecSerializer; + friend class ProxyApiSuperClass; + friend class ProxyApiSuperClassCodecSerializer; + friend class ProxyApiInterface; + friend class ProxyApiInterfaceCodecSerializer; friend class CoreTestsTest; std::optional test_list_; }; From d40f97636e865969e126ec91286a676d78ba61bd Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 13 Dec 2023 23:48:59 -0500 Subject: [PATCH 31/73] add code_builder and dart_style to allowed deps --- script/configs/allowed_unpinned_deps.yaml | 2 ++ 1 file changed, 2 insertions(+) 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 6f887e2e8e22a3031803ac4c556f263d4c96c7b3 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 14 Dec 2023 17:22:04 -0500 Subject: [PATCH 32/73] add todo --- packages/pigeon/lib/dart_generator.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 4bc92dd46307..18f9a1b009ac 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -2201,8 +2201,6 @@ PlatformException _createConnectionError(String channelName) { extension on cb.Expression { cb.Expression awaitedIf(bool condition) => condition ? awaited : this; cb.Expression nullCheckedIf(bool condition) => condition ? nullChecked : this; - cb.Expression propertyIf(bool condition, String name) => - condition ? property(name) : this; } cb.Expression _unwrapReturnValue(TypeDeclaration returnType) { @@ -2337,6 +2335,7 @@ cb.Expression _hostMessageArgument( } } +// TODO: can probably get rid of the OrNull cb.Reference? _referOrNull( String? symbol, { bool isFuture = false, From b129a510d69827f6b00f611c671742888d6a1a41 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 14 Dec 2023 22:47:25 -0500 Subject: [PATCH 33/73] use collection for functional methods --- packages/pigeon/lib/cpp_generator.dart | 21 +- packages/pigeon/lib/dart_generator.dart | 193 +++++++++--------- packages/pigeon/lib/functional.dart | 49 +---- packages/pigeon/lib/generator_tools.dart | 60 +++--- packages/pigeon/lib/java_generator.dart | 14 +- packages/pigeon/lib/kotlin_generator.dart | 16 +- packages/pigeon/lib/objc_generator.dart | 49 ++--- packages/pigeon/lib/pigeon_lib.dart | 1 + packages/pigeon/lib/swift_generator.dart | 18 +- packages/pigeon/test/functional_test.dart | 28 --- .../pigeon/test/generator_tools_test.dart | 46 ----- 11 files changed, 201 insertions(+), 294 deletions(-) diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index c89820fe3173..695031557de2 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_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:collection/collection.dart'; + import 'ast.dart'; import 'functional.dart'; import 'generator.dart'; @@ -175,7 +177,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) { + anEnum.members.forEachIndexed((int index, EnumMember member) { addDocumentationComments( indent, member.documentationComments, _docCommentSpec); indent.writeln( @@ -350,7 +352,7 @@ class CppHeaderGenerator extends StructuredGenerator { return _flutterApiArgumentType(hostType); }); final Iterable argNames = - indexMap(func.parameters, _getArgumentName); + func.parameters.mapIndexed(_getArgumentName); final List parameters = [ ...map2(argTypes, argNames, (String x, String y) => '$x $y'), ..._flutterApiCallbackParameters(returnType), @@ -775,9 +777,10 @@ class CppSourceGenerator extends StructuredGenerator { returnType: classDefinition.name, parameters: ['const EncodableList& list'], body: () { const String instanceVariable = 'decoded'; - final Iterable<_IndexedField> indexedFields = indexMap( - getFieldsInSerializationOrder(classDefinition), - (int index, NamedType field) => _IndexedField(index, field)); + final Iterable<_IndexedField> indexedFields = + getFieldsInSerializationOrder(classDefinition).mapIndexed( + (int index, NamedType field) => _IndexedField(index, field)); + final Iterable<_IndexedField> nullableFields = indexedFields .where((_IndexedField field) => field.field.type.isNullable); final Iterable<_IndexedField> nonNullableFields = indexedFields @@ -851,11 +854,11 @@ class CppSourceGenerator extends StructuredGenerator { // Determine the input parameter list, saved in a structured form for later // use as platform channel call arguments. final Iterable<_HostNamedType> hostParameters = - indexMap(func.parameters, (int i, NamedType arg) { + func.parameters.mapIndexed((int i, NamedType arg) { final HostDatatype hostType = getFieldHostDatatype(arg, _shortBaseCppTypeForBuiltinDartType); return _HostNamedType(_getSafeArgumentName(i, arg), hostType, arg.type); - }); + },); final List parameters = [ ...hostParameters.map((_HostNamedType arg) => '${_flutterApiArgumentType(arg.hostType)} ${arg.name}'), @@ -979,7 +982,7 @@ class CppSourceGenerator extends StructuredGenerator { indent.writeln( 'const auto& args = std::get(message);'); - enumerate(method.parameters, (int index, NamedType arg) { + method.parameters.forEachIndexed((int index, NamedType arg) { final HostDatatype hostType = getHostDatatype( arg.type, (TypeDeclaration x) => @@ -1676,7 +1679,7 @@ void _writeFunction( indent.add('(${parameters.first})'); } else { indent.addScoped('(', null, () { - enumerate(parameters, (int index, final String param) { + parameters.forEachIndexed((int index, final String param) { if (index == parameters.length - 1) { indent.write('$param)'); } else { diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 18f9a1b009ac..918774f600ae 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -3,11 +3,11 @@ // found in the LICENSE file. import 'package:code_builder/code_builder.dart' as cb; +import 'package:collection/collection.dart'; import 'package:dart_style/dart_style.dart'; import 'package:path/path.dart' as path; import 'ast.dart'; -import 'functional.dart'; import 'generator.dart'; import 'generator_tools.dart'; @@ -113,8 +113,13 @@ class DartGenerator extends StructuredGenerator { "import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List;", ); indent.newln(); - indent.writeln( - "import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer, immutable, protected;"); + if (root.apis.any((Api api) => api is AstProxyApi)) { + indent.writeln( + "import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer, immutable, protected;"); + } else { + indent.writeln( + "import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer;"); + } indent.writeln("import 'package:flutter/services.dart';"); if (root.apis.any((Api api) => api is AstProxyApi)) { indent.writeln( @@ -295,8 +300,8 @@ $resultAt != null indent.writeln('result as List;'); indent.write('return ${classDefinition.name}'); indent.addScoped('(', ');', () { - enumerate(getFieldsInSerializationOrder(classDefinition), - (int index, final NamedType field) { + getFieldsInSerializationOrder(classDefinition) + .forEachIndexed((int index, final NamedType field) { indent.write('${field.name}: '); writeValueDecode(field, index); indent.addln(','); @@ -402,7 +407,7 @@ $resultAt != null 'final List $argsArray = (message as List?)!;'); String argNameFunc(int index, NamedType type) => _getSafeArgumentName(index, type); - enumerate(func.parameters, (int count, NamedType arg) { + func.parameters.forEachIndexed((int count, NamedType arg) { final String argType = _addGenericTypes(arg.type); final String argName = argNameFunc(count, arg); final String genericArgType = @@ -424,7 +429,7 @@ $resultAt != null } }); final Iterable argNames = - indexMap(func.parameters, (int index, NamedType field) { + func.parameters.mapIndexed((int index, NamedType field) { final String name = _getSafeArgumentName(index, field); return '$name${field.type.isNullable ? '' : '!'}'; }); @@ -532,7 +537,7 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; String sendArgument = 'null'; if (func.parameters.isNotEmpty) { final Iterable argExpressions = - indexMap(func.parameters, (int index, NamedType type) { + func.parameters.mapIndexed((int index, NamedType type) { final String name = _getParameterName(index, type); if (type.type.isEnum) { return '$name${type.type.isNullable ? '?' : ''}.index'; @@ -1174,8 +1179,7 @@ class $codecName extends StandardMessageCodec { ..toThis = true ..required = method.required, ), - ...indexMap( - constructor.parameters, + ...constructor.parameters.mapIndexed( (int index, NamedType parameter) => cb.Parameter( (cb.ParameterBuilder builder) => builder ..name = _getParameterName(index, parameter) @@ -1185,7 +1189,7 @@ class $codecName extends StandardMessageCodec { ..named = true ..required = !parameter.type.isNullable, ), - ), + ) ], ) ..initializers.add( @@ -1211,11 +1215,10 @@ class $codecName extends StandardMessageCodec { cb.refer( '${superClassApi != null ? '' : 'this.'}\$instanceManager.addDartCreatedInstance(this)', ), - ...indexMap(nonAttachedFields, _hostMessageArgument), - ...indexMap( - constructor.parameters, + ...nonAttachedFields.mapIndexed(_hostMessageArgument), + ...constructor.parameters.mapIndexed( _hostMessageArgument, - ), + ) ], cb.refer('Object?'), ) @@ -1427,8 +1430,7 @@ class $codecName extends StandardMessageCodec { ..isNullable = !method.required ..requiredParameters.addAll([ cb.refer('$apiName instance'), - ...indexMap( - method.parameters, + ...method.parameters.mapIndexed( (int index, NamedType parameter) { return cb.refer( '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', @@ -1456,14 +1458,12 @@ class $codecName extends StandardMessageCodec { ..isNullable = !method.required ..requiredParameters.addAll([ cb.refer('${proxyApi.name} instance'), - ...indexMap( - method.parameters, - (int index, NamedType parameter) { - return cb.refer( - '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', - ); - }, - ), + ...method.parameters + .mapIndexed((int index, NamedType parameter) { + return cb.refer( + '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', + ); + }), ]), ), ), @@ -1525,14 +1525,15 @@ class $codecName extends StandardMessageCodec { (cb.FunctionTypeBuilder builder) => builder ..returnType = cb.refer(apiName) ..isNullable = true - ..requiredParameters.addAll(indexMap( - nonAttachedFields, - (int index, Field field) { - return cb.refer( - '${_addGenericTypesNullable(field.type)} ${_getParameterName(index, field)}', - ); - }, - )), + ..requiredParameters.addAll( + nonAttachedFields.mapIndexed( + (int index, Field field) { + return cb.refer( + '${_addGenericTypesNullable(field.type)} ${_getParameterName(index, field)}', + ); + }, + ), + ), ), ), for (final Method method in flutterMethods) @@ -1548,14 +1549,13 @@ class $codecName extends StandardMessageCodec { ..isNullable = true ..requiredParameters.addAll([ cb.refer('$apiName instance'), - ...indexMap( - method.parameters, + ...method.parameters.mapIndexed( (int index, NamedType parameter) { return cb.refer( '${_addGenericTypesNullable(parameter.type)} ${_getParameterName(index, parameter)}', ); }, - ) + ), ]), ), ), @@ -1611,14 +1611,11 @@ class $codecName extends StandardMessageCodec { 'Argument for \$${_varNamePrefix}channelName was null, expected non-null int.', ), ), - ...indexFold, Field>( - nonAttachedFields, + ...nonAttachedFields.foldIndexed>( [], - (List list, int index, Field field) { - return list - ..addAll( - _messageArg(index + 1, field), - ); + (int index, List previous, Field field) { + return previous + ..addAll(_messageArg(index + 1, field)); }, ), cb @@ -1629,48 +1626,43 @@ class $codecName extends StandardMessageCodec { .call([ cb .refer(r'$detached?.call') - .call( - indexMap( - nonAttachedFields, + .call(nonAttachedFields.mapIndexed( + (int index, Field field) { + // The calling instance is the first arg. + final String name = _getSafeArgumentName( + index + 1, + field, + ); + return cb.refer(name).nullCheckedIf( + !field.type.isNullable, + ); + }, + )).ifNullThen( + cb.refer('$apiName.\$detached').call( + [], + { + r'$binaryMessenger': + cb.refer(r'$binaryMessenger'), + r'$instanceManager': + cb.refer(r'$instanceManager'), + ...nonAttachedFields.toList().asMap().map( (int index, Field field) { - // The calling instance is the first arg. - final String name = _getSafeArgumentName( + final String argName = + _getSafeArgumentName( index + 1, field, ); - return cb.refer(name).nullCheckedIf( - !field.type.isNullable, - ); - }, - ), - ) - .ifNullThen( - cb.refer('$apiName.\$detached').call( - [], - { - r'$binaryMessenger': - cb.refer(r'$binaryMessenger'), - r'$instanceManager': - cb.refer(r'$instanceManager'), - ...nonAttachedFields.toList().asMap().map( - (int index, Field field) { - final String argName = - _getSafeArgumentName( - index + 1, - field, - ); - return MapEntry( - field.name, - cb.refer(argName).nullCheckedIf( - !field.type.isNullable, - ), - ); - }, - ) + return MapEntry( + field.name, + cb.refer(argName).nullCheckedIf( + !field.type.isNullable, + ), + ); }, - ), - ), + ) + }, + ), + ), cb.refer('instanceIdentifier').nullChecked ]).statement, const cb.Code('return;'), @@ -1696,8 +1688,7 @@ class $codecName extends StandardMessageCodec { .call( [ cb.refer('instance').nullChecked, - ...indexMap( - method.parameters, + ...method.parameters.mapIndexed( (int index, NamedType parameter) { final String name = _getSafeArgumentName( index + 1, @@ -1755,16 +1746,18 @@ class $codecName extends StandardMessageCodec { 'Argument for \$${_varNamePrefix}channelName was null, expected non-null $apiName.', ), ), - ...indexFold, NamedType>( - method.parameters, + ...method.parameters.foldIndexed>( [], ( - List list, int index, - NamedType type, + List previous, + Parameter parameter, ) { - return list - ..addAll(_messageArg(index + 1, type)); + return previous + ..addAll(_messageArg( + index + 1, + parameter, + )); }, ), const cb.Code('try {'), @@ -1930,16 +1923,17 @@ class $codecName extends StandardMessageCodec { _addGenericTypesNullable(method.returnType), isFuture: true, ) - ..requiredParameters.addAll(indexMap( - method.parameters, - (int index, NamedType parameter) => cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = _getParameterName(index, parameter) - ..type = cb.refer( - _addGenericTypesNullable(parameter.type), - ), + ..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( @@ -1979,7 +1973,7 @@ class $codecName extends StandardMessageCodec { cb.literalList( [ if (!method.isStatic) cb.refer('this'), - ...indexMap(method.parameters, _hostMessageArgument), + ...method.parameters.mapIndexed(_hostMessageArgument), ], cb.refer('Object?'), ) @@ -2372,7 +2366,8 @@ void _writeCodec(Indent indent, String codecName, Api api, Root root) { indent.writeln('@override'); indent.write('void writeValue(WriteBuffer buffer, Object? value) '); indent.addScoped('{', '}', () { - enumerate(codecClasses, (int index, final EnumeratedClass customClass) { + codecClasses + .forEachIndexed((int index, final EnumeratedClass customClass) { final String ifValue = 'if (value is ${customClass.name}) '; if (index == 0) { indent.write(''); diff --git a/packages/pigeon/lib/functional.dart b/packages/pigeon/lib/functional.dart index b9e01410014d..4ad0da085342 100644 --- a/packages/pigeon/lib/functional.dart +++ b/packages/pigeon/lib/functional.dart @@ -2,44 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// TODO(bparrishMines): replace usage with mapIndexed -/// A [map] function that calls the function with an enumeration as well as the -/// value. -Iterable indexMap( - Iterable iterable, U Function(int index, T value) func) sync* { - int index = 0; - for (final T value in iterable) { - yield func(index, value); - ++index; - } -} - -// TODO(bparrishMines): replace usage with foldIndexed -/// A [map] function that calls the function with an enumeration as well as the -/// value. -T indexFold( - Iterable iterable, - T initialValue, - T Function(T previousValue, int index, E element) combine, -) { - int index = 0; - T value = initialValue; - for (final E element in iterable) { - value = combine(value, index, element); - ++index; - } - return value; -} - -// TODO(bparrishMines): replace usage with forEachIndexed -/// Performs like [forEach] but invokes [func] with an enumeration. -void enumerate(Iterable iterable, void Function(int, T) func) { - int count = 0; - for (final T value in iterable) { - func(count, value); - ++count; - } -} +// // TODO(bparrishMines): replace usage with mapIndexed +// /// A [map] function that calls the function with an enumeration as well as the +// /// value. +// Iterable indexMap( +// Iterable iterable, U Function(int index, T value) func) sync* { +// int index = 0; +// for (final T value in iterable) { +// yield func(index, value); +// ++index; +// } +// } /// A [map] function that takes in 2 iterables. The [Iterable]s must be of /// equal length. diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 93e9d23b7087..9c846083372e 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -326,36 +326,36 @@ void addLines(Indent indent, Iterable lines, {String? linePrefix}) { } } -/// Recursively merges [modification] into [base]. -/// -/// In other words, whenever there is a conflict over the value of a key path, -/// [modification]'s value for that key path is selected. -Map mergeMaps( - Map base, - Map modification, -) { - final Map result = {}; - for (final MapEntry entry in modification.entries) { - if (base.containsKey(entry.key)) { - final Object entryValue = entry.value; - if (entryValue is Map) { - assert(base[entry.key] is Map); - result[entry.key] = - mergeMaps((base[entry.key] as Map?)!, entryValue); - } else { - result[entry.key] = entry.value; - } - } else { - result[entry.key] = entry.value; - } - } - for (final MapEntry entry in base.entries) { - if (!result.containsKey(entry.key)) { - result[entry.key] = entry.value; - } - } - return result; -} +// /// Recursively merges [modification] into [base]. +// /// +// /// In other words, whenever there is a conflict over the value of a key path, +// /// [modification]'s value for that key path is selected. +// Map mergeMaps( +// Map base, +// Map modification, +// ) { +// final Map result = {}; +// for (final MapEntry entry in modification.entries) { +// if (base.containsKey(entry.key)) { +// final Object entryValue = entry.value; +// if (entryValue is Map) { +// assert(base[entry.key] is Map); +// result[entry.key] = +// mergeMaps((base[entry.key] as Map?)!, entryValue); +// } else { +// result[entry.key] = entry.value; +// } +// } else { +// result[entry.key] = entry.value; +// } +// } +// for (final MapEntry entry in base.entries) { +// if (!result.containsKey(entry.key)) { +// result[entry.key] = entry.value; +// } +// } +// return result; +// } /// A class name that is enumerated. class EnumeratedClass { diff --git a/packages/pigeon/lib/java_generator.dart b/packages/pigeon/lib/java_generator.dart index c0961adf5efa..c7501df79d77 100644 --- a/packages/pigeon/lib/java_generator.dart +++ b/packages/pigeon/lib/java_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:collection/collection.dart'; + import 'ast.dart'; import 'functional.dart'; import 'generator.dart'; @@ -183,7 +185,7 @@ class JavaGenerator extends StructuredGenerator { indent.write('public enum ${anEnum.name} '); indent.addScoped('{', '}', () { - enumerate(anEnum.members, (int index, final EnumMember member) { + anEnum.members.forEachIndexed((int index, final EnumMember member) { addDocumentationComments( indent, member.documentationComments, _docCommentSpec); indent.writeln( @@ -369,8 +371,8 @@ class JavaGenerator extends StructuredGenerator { const String result = 'pigeonResult'; indent.writeln( '${classDefinition.name} $result = new ${classDefinition.name}();'); - enumerate(getFieldsInSerializationOrder(classDefinition), - (int index, final NamedType field) { + getFieldsInSerializationOrder(classDefinition) + .forEachIndexed((int index, final NamedType field) { final String fieldVariable = field.name; final String setter = _makeSetter(field); indent.writeln('Object $fieldVariable = list.get($index);'); @@ -463,9 +465,9 @@ class JavaGenerator extends StructuredGenerator { final Iterable argTypes = func.parameters .map((NamedType e) => _nullsafeJavaTypeForDartType(e.type)); final Iterable argNames = - indexMap(func.parameters, _getSafeArgumentName); + func.parameters.mapIndexed(_getSafeArgumentName); final Iterable enumSafeArgNames = - indexMap(func.parameters, getEnumSafeArgumentExpression); + func.parameters.mapIndexed(getEnumSafeArgumentExpression); if (func.parameters.length == 1) { sendArgument = 'new ArrayList(Collections.singletonList(${enumSafeArgNames.first}))'; @@ -716,7 +718,7 @@ class JavaGenerator extends StructuredGenerator { if (method.parameters.isNotEmpty) { indent.writeln( 'ArrayList args = (ArrayList) message;'); - enumerate(method.parameters, (int index, NamedType arg) { + method.parameters.forEachIndexed((int index, NamedType arg) { // The StandardMessageCodec can give us [Integer, Long] for // a Dart 'int'. To keep things simple we just use 64bit // longs in Pigeon with Java. diff --git a/packages/pigeon/lib/kotlin_generator.dart b/packages/pigeon/lib/kotlin_generator.dart index 78337cc2cb14..d0a0ccb06cec 100644 --- a/packages/pigeon/lib/kotlin_generator.dart +++ b/packages/pigeon/lib/kotlin_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:collection/collection.dart'; + import 'ast.dart'; import 'functional.dart'; import 'generator.dart'; @@ -124,7 +126,7 @@ class KotlinGenerator extends StructuredGenerator { indent, anEnum.documentationComments, _docCommentSpec); indent.write('enum class ${anEnum.name}(val raw: Int) '); indent.addScoped('{', '}', () { - enumerate(anEnum.members, (int index, final EnumMember member) { + anEnum.members.forEachIndexed((int index, final EnumMember member) { addDocumentationComments( indent, member.documentationComments, _docCommentSpec); indent.write('${member.name.toUpperCase()}($index)'); @@ -240,8 +242,8 @@ class KotlinGenerator extends StructuredGenerator { indent.write('fun fromList(list: List): $className '); indent.addScoped('{', '}', () { - enumerate(getFieldsInSerializationOrder(classDefinition), - (int index, final NamedType field) { + getFieldsInSerializationOrder(classDefinition) + .forEachIndexed((int index, final NamedType field) { final String listValue = 'list[$index]'; final String fieldType = _kotlinTypeForDartType(field.type); @@ -375,9 +377,8 @@ class KotlinGenerator extends StructuredGenerator { final Iterable argTypes = func.parameters .map((NamedType e) => _nullsafeKotlinTypeForDartType(e.type)); final Iterable argNames = - indexMap(func.parameters, _getSafeArgumentName); - final Iterable enumSafeArgNames = indexMap( - func.parameters, + func.parameters.mapIndexed(_getSafeArgumentName); + final Iterable enumSafeArgNames = func.parameters.mapIndexed( (int count, NamedType type) => _getEnumSafeArgumentExpression(count, type)); sendArgument = 'listOf(${enumSafeArgNames.join(', ')})'; @@ -548,7 +549,8 @@ class KotlinGenerator extends StructuredGenerator { final List methodArguments = []; if (method.parameters.isNotEmpty) { indent.writeln('val args = message as List'); - enumerate(method.parameters, (int index, NamedType arg) { + method.parameters + .forEachIndexed((int index, NamedType arg) { final String argName = _getSafeArgumentName(index, arg); final String argIndex = 'args[$index]'; indent.writeln( diff --git a/packages/pigeon/lib/objc_generator.dart b/packages/pigeon/lib/objc_generator.dart index bc26495e650b..d4bec6e066ef 100644 --- a/packages/pigeon/lib/objc_generator.dart +++ b/packages/pigeon/lib/objc_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:collection/collection.dart'; + import 'ast.dart'; import 'functional.dart'; import 'generator.dart'; @@ -149,7 +151,7 @@ class ObjcHeaderGenerator extends StructuredGenerator { indent.write('typedef NS_ENUM(NSUInteger, $enumName) '); indent.addScoped('{', '};', () { - enumerate(anEnum.members, (int index, final EnumMember member) { + anEnum.members.forEachIndexed((int index, final EnumMember member) { addDocumentationComments( indent, member.documentationComments, _docCommentSpec); // Capitalized first letter to ensure Swift compatibility @@ -572,26 +574,27 @@ class ObjcSourceGenerator extends StructuredGenerator { indent.addScoped('{', '}', () { const String resultName = 'pigeonResult'; indent.writeln('$className *$resultName = [[$className alloc] init];'); - enumerate(getFieldsInSerializationOrder(classDefinition), - (int index, final NamedType field) { - final bool isEnumType = field.type.isEnum; - final String valueGetter = - _listGetter('list', field, index, generatorOptions.prefix); - final String? primitiveExtractionMethod = - _nsnumberExtractionMethod(field.type); - final String ivarValueExpression; - if (primitiveExtractionMethod != null) { - ivarValueExpression = '[$valueGetter $primitiveExtractionMethod]'; - } else if (isEnumType) { - indent.writeln('NSNumber *${field.name}AsNumber = $valueGetter;'); - indent.writeln( - '${_enumName(field.type.baseName, suffix: ' *', prefix: generatorOptions.prefix, box: true)}${field.name} = ${field.name}AsNumber == nil ? nil : [[${_enumName(field.type.baseName, prefix: generatorOptions.prefix, box: true)} alloc] initWithValue:[${field.name}AsNumber integerValue]];'); - ivarValueExpression = field.name; - } else { - ivarValueExpression = valueGetter; - } - indent.writeln('$resultName.${field.name} = $ivarValueExpression;'); - }); + getFieldsInSerializationOrder(classDefinition).forEachIndexed( + (int index, final NamedType field) { + final bool isEnumType = field.type.isEnum; + final String valueGetter = + _listGetter('list', field, index, generatorOptions.prefix); + final String? primitiveExtractionMethod = + _nsnumberExtractionMethod(field.type); + final String ivarValueExpression; + if (primitiveExtractionMethod != null) { + ivarValueExpression = '[$valueGetter $primitiveExtractionMethod]'; + } else if (isEnumType) { + indent.writeln('NSNumber *${field.name}AsNumber = $valueGetter;'); + indent.writeln( + '${_enumName(field.type.baseName, suffix: ' *', prefix: generatorOptions.prefix, box: true)}${field.name} = ${field.name}AsNumber == nil ? nil : [[${_enumName(field.type.baseName, prefix: generatorOptions.prefix, box: true)} alloc] initWithValue:[${field.name}AsNumber integerValue]];'); + ivarValueExpression = field.name; + } else { + ivarValueExpression = valueGetter; + } + indent.writeln('$resultName.${field.name} = $ivarValueExpression;'); + }, + ); indent.writeln('return $resultName;'); }); @@ -858,7 +861,7 @@ static FlutterError *createConnectionError(NSString *channelName) { final Iterable selectorComponents = _getSelectorComponents(func, lastSelectorComponent); final Iterable argNames = - indexMap(func.parameters, _getSafeArgName); + func.parameters.mapIndexed(_getSafeArgName); final String callSignature = map2(selectorComponents.take(argNames.length), argNames, (String selectorComponent, String argName) { @@ -1453,7 +1456,7 @@ String _makeObjcSignature({ (int _, NamedType e) => e.type.isNullable && e.type.isEnum ? '${e.name}Boxed' : e.name; final Iterable argNames = - followedByOne(indexMap(func.parameters, argNameFunc), lastArgName); + followedByOne(func.parameters.mapIndexed(argNameFunc), lastArgName); final Iterable selectorComponents = _getSelectorComponents(func, lastArgName); final Iterable argTypes = followedByOne( diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index c34fd50237a2..861360d0bb9a 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -22,6 +22,7 @@ import 'package:analyzer/dart/ast/visitor.dart' as dart_ast_visitor; import 'package:analyzer/error/error.dart' show AnalysisError; import 'package:args/args.dart'; import 'package:collection/collection.dart' as collection; +import 'package:collection/collection.dart'; import 'package:path/path.dart' as path; import 'ast.dart'; diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index cd2b36880530..36d0c0d8dbea 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_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:collection/collection.dart'; + import 'ast.dart'; import 'functional.dart'; import 'generator.dart'; @@ -100,7 +102,7 @@ import FlutterMacOS indent.write('enum ${anEnum.name}: Int '); indent.addScoped('{', '}', () { - enumerate(anEnum.members, (int index, final EnumMember member) { + anEnum.members.forEachIndexed((int index, final EnumMember member) { addDocumentationComments( indent, member.documentationComments, _docCommentSpec); indent.writeln('case ${_camelCase(member.name)} = $index'); @@ -191,8 +193,8 @@ import FlutterMacOS indent.write('static func fromList(_ list: [Any?]) -> $className? '); indent.addScoped('{', '}', () { - enumerate(getFieldsInSerializationOrder(classDefinition), - (int index, final NamedType field) { + getFieldsInSerializationOrder(classDefinition) + .forEachIndexed((int index, final NamedType field) { final String listValue = 'list[$index]'; _writeDecodeCasting( @@ -469,8 +471,8 @@ import FlutterMacOS final List methodArgument = []; if (components.arguments.isNotEmpty) { indent.writeln('let args = message as! [Any?]'); - enumerate(components.arguments, - (int index, _SwiftFunctionArgument arg) { + components.arguments + .forEachIndexed((int index, _SwiftFunctionArgument arg) { final String argName = _getSafeArgumentName(index, arg.namedType); final String argIndex = 'args[$index]'; @@ -904,12 +906,12 @@ String _getMethodSignature(Method func) { } else { final Iterable argTypes = func.parameters .map((NamedType e) => _nullsafeSwiftTypeForDartType(e.type)); - final Iterable argLabels = indexMap(components.arguments, - (int index, _SwiftFunctionArgument argument) { + final Iterable argLabels = components.arguments + .mapIndexed((int index, _SwiftFunctionArgument argument) { return argument.label ?? _getArgumentName(index, argument.namedType); }); final Iterable argNames = - indexMap(func.parameters, _getSafeArgumentName); + func.parameters.mapIndexed(_getSafeArgumentName); final String argsSignature = map3(argTypes, argLabels, argNames, (String type, String label, String name) => '$label $name: $type') .join(', '); diff --git a/packages/pigeon/test/functional_test.dart b/packages/pigeon/test/functional_test.dart index 1c2079ccae4d..ade909799aca 100644 --- a/packages/pigeon/test/functional_test.dart +++ b/packages/pigeon/test/functional_test.dart @@ -6,34 +6,6 @@ import 'package:pigeon/functional.dart'; import 'package:test/test.dart'; void main() { - test('indexMap', () { - final List items = ['a', 'b', 'c']; - final List result = - indexMap(items, (int index, String value) => value + index.toString()) - .toList(); - expect(result[0], 'a0'); - expect(result[1], 'b1'); - expect(result[2], 'c2'); - }); - - test('enumerate', () { - final List items = ['a', 'b', 'c']; - int saw = 0; - enumerate(items, (int index, String value) { - if (index == 0) { - expect(value, 'a'); - saw |= 0x1; - } else if (index == 1) { - expect(value, 'b'); - saw |= 0x2; - } else if (index == 2) { - expect(value, 'c'); - saw |= 0x4; - } - }); - expect(saw, 0x7); - }); - test('map2', () { final List result = map2([3, 5, 7], [1, 2, 3], (int x, int y) => x * y).toList(); diff --git a/packages/pigeon/test/generator_tools_test.dart b/packages/pigeon/test/generator_tools_test.dart index 060b03994691..b2dd939f4aaf 100644 --- a/packages/pigeon/test/generator_tools_test.dart +++ b/packages/pigeon/test/generator_tools_test.dart @@ -18,25 +18,6 @@ bool _equalSet(Set x, Set y) { return true; } -bool _equalMaps(Map x, Map y) { - if (!_equalSet(x.keys.toSet(), y.keys.toSet())) { - return false; - } - for (final String key in x.keys) { - final Object xValue = x[key]!; - if (xValue is Map) { - if (!_equalMaps(xValue, (y[key] as Map?)!)) { - return false; - } - } else { - if (xValue != y[key]) { - return false; - } - } - } - return true; -} - final Class emptyClass = Class(name: 'className', fields: [ NamedType( name: 'namedTypeName', @@ -50,33 +31,6 @@ final Enum emptyEnum = Enum( ); void main() { - test('test merge maps', () { - final Map source = { - '1': '1', - '2': { - '1': '1', - '3': '3', - }, - '3': '3', // not modified - }; - final Map modification = { - '1': '2', // modify - '2': { - '2': '2', // added - }, - }; - final Map expected = { - '1': '2', - '2': { - '1': '1', - '2': '2', - '3': '3', - }, - '3': '3', - }; - expect(_equalMaps(expected, mergeMaps(source, modification)), isTrue); - }); - test('get codec classes from argument type arguments', () { final Api api = AstFlutterApi(name: 'Api', methods: [ Method( From 9f52a74d7f373bdbc3a5ea6e34c01c012e536c89 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 14 Dec 2023 22:58:08 -0500 Subject: [PATCH 34/73] formatting and some updates --- .../example/app/lib/src/messages.g.dart | 3 +- packages/pigeon/lib/cpp_generator.dart | 13 ++++--- packages/pigeon/lib/dart_generator.dart | 38 +++++++++---------- .../background_platform_channels.gen.dart | 3 +- .../lib/src/generated/enum.gen.dart | 3 +- .../src/generated/flutter_unittests.gen.dart | 3 +- .../lib/src/generated/message.gen.dart | 3 +- .../lib/src/generated/multiple_arity.gen.dart | 3 +- .../src/generated/non_null_fields.gen.dart | 3 +- .../lib/src/generated/null_fields.gen.dart | 3 +- .../src/generated/nullable_returns.gen.dart | 3 +- .../lib/src/generated/primitive.gen.dart | 3 +- 12 files changed, 35 insertions(+), 46 deletions(-) diff --git a/packages/pigeon/example/app/lib/src/messages.g.dart b/packages/pigeon/example/app/lib/src/messages.g.dart index 0c50d2189d8d..59213e4ef2bb 100644 --- a/packages/pigeon/example/app/lib/src/messages.g.dart +++ b/packages/pigeon/example/app/lib/src/messages.g.dart @@ -8,8 +8,7 @@ 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/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index 695031557de2..aa6bdb512f6a 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -854,11 +854,14 @@ class CppSourceGenerator extends StructuredGenerator { // Determine the input parameter list, saved in a structured form for later // use as platform channel call arguments. final Iterable<_HostNamedType> hostParameters = - func.parameters.mapIndexed((int i, NamedType arg) { - final HostDatatype hostType = - getFieldHostDatatype(arg, _shortBaseCppTypeForBuiltinDartType); - return _HostNamedType(_getSafeArgumentName(i, arg), hostType, arg.type); - },); + func.parameters.mapIndexed( + (int i, NamedType arg) { + final HostDatatype hostType = + getFieldHostDatatype(arg, _shortBaseCppTypeForBuiltinDartType); + return _HostNamedType( + _getSafeArgumentName(i, arg), hostType, arg.type); + }, + ); final List parameters = [ ...hostParameters.map((_HostNamedType arg) => '${_flutterApiArgumentType(arg.hostType)} ${arg.name}'), diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 918774f600ae..7934b82e3cb9 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -1047,7 +1047,7 @@ class $codecName extends StandardMessageCodec { final cb.Class proxyApi = cb.Class( (cb.ClassBuilder builder) => builder ..name = api.name - ..extend = _referOrNull(superClassApi?.name) + ..extend = superClassApi != null ? cb.refer(superClassApi.name) : null ..implements.addAll([ if (api.interfacesNames.isNotEmpty) ...api.interfacesNames.map((String name) => cb.refer(name)) @@ -1141,10 +1141,9 @@ class $codecName extends StandardMessageCodec { ), cb.Parameter((cb.ParameterBuilder builder) => builder ..name = r'$instanceManager' - ..type = _referOrNull( - superClassApi == null ? r'$InstanceManager' : null, - isNullable: true, - ) + ..type = superClassApi == null + ? cb.refer(r'$InstanceManager?') + : null ..named = true ..toSuper = superClassApi != null), for (final Field field in nonAttachedFields) @@ -1297,10 +1296,9 @@ class $codecName extends StandardMessageCodec { cb.Parameter( (cb.ParameterBuilder builder) => builder ..name = r'$instanceManager' - ..type = _referOrNull( - superClassApi == null ? r'$InstanceManager' : null, - isNullable: true, - ) + ..type = superClassApi == null + ? cb.refer(r'$InstanceManager?') + : null ..named = true ..toSuper = superClassApi != null, ), @@ -1423,7 +1421,7 @@ class $codecName extends StandardMessageCodec { )) ..type = cb.FunctionType( (cb.FunctionTypeBuilder builder) => builder - ..returnType = _referOrNull( + ..returnType = _refer( _addGenericTypesNullable(method.returnType), isFuture: method.isAsynchronous, ) @@ -1451,7 +1449,7 @@ class $codecName extends StandardMessageCodec { method.documentationComments, _docCommentSpec)) ..type = cb.FunctionType( (cb.FunctionTypeBuilder builder) => builder - ..returnType = _referOrNull( + ..returnType = _refer( _addGenericTypesNullable(method.returnType), isFuture: method.isAsynchronous, ) @@ -1542,7 +1540,7 @@ class $codecName extends StandardMessageCodec { ..name = method.name ..type = cb.FunctionType( (cb.FunctionTypeBuilder builder) => builder - ..returnType = _referOrNull( + ..returnType = _refer( _addGenericTypesNullable(method.returnType), isFuture: method.isAsynchronous, ) @@ -1773,7 +1771,7 @@ class $codecName extends StandardMessageCodec { cb .declareFinal( 'output', - type: _referOrNull( + type: _refer( _addGenericTypes(method.returnType), isNullable: method.returnType.isNullable || @@ -1919,7 +1917,7 @@ class $codecName extends StandardMessageCodec { method.documentationComments, _docCommentSpec, )) - ..returns = _referOrNull( + ..returns = _refer( _addGenericTypesNullable(method.returnType), isFuture: true, ) @@ -2329,17 +2327,15 @@ cb.Expression _hostMessageArgument( } } -// TODO: can probably get rid of the OrNull -cb.Reference? _referOrNull( - String? symbol, { +cb.Reference _refer( + String symbol, { bool isFuture = false, bool isNullable = false, }) { final String nullability = isNullable ? '?' : ''; - return symbol != null - ? cb.refer( - isFuture ? 'Future<$symbol$nullability>' : '$symbol$nullability') - : null; + return cb.refer( + isFuture ? 'Future<$symbol$nullability>' : '$symbol$nullability', + ); } String _escapeForDartSingleQuotedString(String raw) { 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 a26cefa855e9..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 @@ -9,8 +9,7 @@ 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/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { 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 9e6b2fc35361..8354d159d33e 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 @@ -9,8 +9,7 @@ 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/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { 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 782288d0e31f..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 @@ -9,8 +9,7 @@ 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/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { 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 0840d5478a22..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 @@ -9,8 +9,7 @@ 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/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { 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 c7094a718bc5..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 @@ -9,8 +9,7 @@ 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/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { 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 a852f522aaa5..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 @@ -9,8 +9,7 @@ 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/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { 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 389905f8e829..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 @@ -9,8 +9,7 @@ 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/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { 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 bd8833dee205..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 @@ -9,8 +9,7 @@ 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/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { 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 91db25103325..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 @@ -9,8 +9,7 @@ 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/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; PlatformException _createConnectionError(String channelName) { From e947f31dffae38429753f71f8805e68dce25fd1f Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 14 Dec 2023 23:06:44 -0500 Subject: [PATCH 35/73] improve PR looks and commented out code --- packages/pigeon/lib/cpp_generator.dart | 13 +++----- packages/pigeon/lib/functional.dart | 12 ------- packages/pigeon/lib/generator_tools.dart | 31 ------------------ packages/pigeon/lib/objc_generator.dart | 41 ++++++++++++------------ 4 files changed, 25 insertions(+), 72 deletions(-) diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index aa6bdb512f6a..b03c2bd5c360 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -854,14 +854,11 @@ class CppSourceGenerator extends StructuredGenerator { // Determine the input parameter list, saved in a structured form for later // use as platform channel call arguments. final Iterable<_HostNamedType> hostParameters = - func.parameters.mapIndexed( - (int i, NamedType arg) { - final HostDatatype hostType = - getFieldHostDatatype(arg, _shortBaseCppTypeForBuiltinDartType); - return _HostNamedType( - _getSafeArgumentName(i, arg), hostType, arg.type); - }, - ); + func.parameters.mapIndexed((int i, NamedType arg) { + final HostDatatype hostType = + getFieldHostDatatype(arg, _shortBaseCppTypeForBuiltinDartType); + return _HostNamedType(_getSafeArgumentName(i, arg), hostType, arg.type); + }); final List parameters = [ ...hostParameters.map((_HostNamedType arg) => '${_flutterApiArgumentType(arg.hostType)} ${arg.name}'), diff --git a/packages/pigeon/lib/functional.dart b/packages/pigeon/lib/functional.dart index 4ad0da085342..59e477783c3a 100644 --- a/packages/pigeon/lib/functional.dart +++ b/packages/pigeon/lib/functional.dart @@ -2,18 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// // TODO(bparrishMines): replace usage with mapIndexed -// /// A [map] function that calls the function with an enumeration as well as the -// /// value. -// Iterable indexMap( -// Iterable iterable, U Function(int index, T value) func) sync* { -// int index = 0; -// for (final T value in iterable) { -// yield func(index, value); -// ++index; -// } -// } - /// A [map] function that takes in 2 iterables. The [Iterable]s must be of /// equal length. Iterable map2( diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 9c846083372e..290aaac0a9a9 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -326,37 +326,6 @@ void addLines(Indent indent, Iterable lines, {String? linePrefix}) { } } -// /// Recursively merges [modification] into [base]. -// /// -// /// In other words, whenever there is a conflict over the value of a key path, -// /// [modification]'s value for that key path is selected. -// Map mergeMaps( -// Map base, -// Map modification, -// ) { -// final Map result = {}; -// for (final MapEntry entry in modification.entries) { -// if (base.containsKey(entry.key)) { -// final Object entryValue = entry.value; -// if (entryValue is Map) { -// assert(base[entry.key] is Map); -// result[entry.key] = -// mergeMaps((base[entry.key] as Map?)!, entryValue); -// } else { -// result[entry.key] = entry.value; -// } -// } else { -// result[entry.key] = entry.value; -// } -// } -// for (final MapEntry entry in base.entries) { -// if (!result.containsKey(entry.key)) { -// result[entry.key] = entry.value; -// } -// } -// return result; -// } - /// A class name that is enumerated. class EnumeratedClass { /// Constructor. diff --git a/packages/pigeon/lib/objc_generator.dart b/packages/pigeon/lib/objc_generator.dart index d4bec6e066ef..378393b46dc0 100644 --- a/packages/pigeon/lib/objc_generator.dart +++ b/packages/pigeon/lib/objc_generator.dart @@ -574,27 +574,26 @@ class ObjcSourceGenerator extends StructuredGenerator { indent.addScoped('{', '}', () { const String resultName = 'pigeonResult'; indent.writeln('$className *$resultName = [[$className alloc] init];'); - getFieldsInSerializationOrder(classDefinition).forEachIndexed( - (int index, final NamedType field) { - final bool isEnumType = field.type.isEnum; - final String valueGetter = - _listGetter('list', field, index, generatorOptions.prefix); - final String? primitiveExtractionMethod = - _nsnumberExtractionMethod(field.type); - final String ivarValueExpression; - if (primitiveExtractionMethod != null) { - ivarValueExpression = '[$valueGetter $primitiveExtractionMethod]'; - } else if (isEnumType) { - indent.writeln('NSNumber *${field.name}AsNumber = $valueGetter;'); - indent.writeln( - '${_enumName(field.type.baseName, suffix: ' *', prefix: generatorOptions.prefix, box: true)}${field.name} = ${field.name}AsNumber == nil ? nil : [[${_enumName(field.type.baseName, prefix: generatorOptions.prefix, box: true)} alloc] initWithValue:[${field.name}AsNumber integerValue]];'); - ivarValueExpression = field.name; - } else { - ivarValueExpression = valueGetter; - } - indent.writeln('$resultName.${field.name} = $ivarValueExpression;'); - }, - ); + getFieldsInSerializationOrder(classDefinition) + .forEachIndexed((int index, final NamedType field) { + final bool isEnumType = field.type.isEnum; + final String valueGetter = + _listGetter('list', field, index, generatorOptions.prefix); + final String? primitiveExtractionMethod = + _nsnumberExtractionMethod(field.type); + final String ivarValueExpression; + if (primitiveExtractionMethod != null) { + ivarValueExpression = '[$valueGetter $primitiveExtractionMethod]'; + } else if (isEnumType) { + indent.writeln('NSNumber *${field.name}AsNumber = $valueGetter;'); + indent.writeln( + '${_enumName(field.type.baseName, suffix: ' *', prefix: generatorOptions.prefix, box: true)}${field.name} = ${field.name}AsNumber == nil ? nil : [[${_enumName(field.type.baseName, prefix: generatorOptions.prefix, box: true)} alloc] initWithValue:[${field.name}AsNumber integerValue]];'); + ivarValueExpression = field.name; + } else { + ivarValueExpression = valueGetter; + } + indent.writeln('$resultName.${field.name} = $ivarValueExpression;'); + }); indent.writeln('return $resultName;'); }); From 4463b0962af22228555ebba7f6eb0e5bfbe9edc1 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 14 Dec 2023 23:12:29 -0500 Subject: [PATCH 36/73] exclude astproxyapi --- packages/pigeon/lib/cpp_generator.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index b03c2bd5c360..9daa26d92b8b 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -295,7 +295,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};'); From f0ca94948bc4baff493bc1337e910dbdfc652f30 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 14 Dec 2023 23:14:38 -0500 Subject: [PATCH 37/73] regenerate code --- .../windows/pigeon/core_tests.gen.h | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h index 866e1b504c48..924ce54672a7 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h @@ -139,12 +139,6 @@ class AllTypes { friend class HostSmallApiCodecSerializer; friend class FlutterSmallApi; friend class FlutterSmallApiCodecSerializer; - friend class ProxyIntegrationCoreApi; - friend class ProxyIntegrationCoreApiCodecSerializer; - friend class ProxyApiSuperClass; - friend class ProxyApiSuperClassCodecSerializer; - friend class ProxyApiInterface; - friend class ProxyApiInterfaceCodecSerializer; friend class CoreTestsTest; bool a_bool_; int64_t an_int_; @@ -265,12 +259,6 @@ class AllNullableTypes { friend class HostSmallApiCodecSerializer; friend class FlutterSmallApi; friend class FlutterSmallApiCodecSerializer; - friend class ProxyIntegrationCoreApi; - friend class ProxyIntegrationCoreApiCodecSerializer; - friend class ProxyApiSuperClass; - friend class ProxyApiSuperClassCodecSerializer; - friend class ProxyApiInterface; - friend class ProxyApiInterfaceCodecSerializer; friend class CoreTestsTest; std::optional a_nullable_bool_; std::optional a_nullable_int_; @@ -327,12 +315,6 @@ class AllClassesWrapper { friend class HostSmallApiCodecSerializer; friend class FlutterSmallApi; friend class FlutterSmallApiCodecSerializer; - friend class ProxyIntegrationCoreApi; - friend class ProxyIntegrationCoreApiCodecSerializer; - friend class ProxyApiSuperClass; - friend class ProxyApiSuperClassCodecSerializer; - friend class ProxyApiInterface; - friend class ProxyApiInterfaceCodecSerializer; friend class CoreTestsTest; AllNullableTypes all_nullable_types_; std::optional all_types_; @@ -366,12 +348,6 @@ class TestMessage { friend class HostSmallApiCodecSerializer; friend class FlutterSmallApi; friend class FlutterSmallApiCodecSerializer; - friend class ProxyIntegrationCoreApi; - friend class ProxyIntegrationCoreApiCodecSerializer; - friend class ProxyApiSuperClass; - friend class ProxyApiSuperClassCodecSerializer; - friend class ProxyApiInterface; - friend class ProxyApiInterfaceCodecSerializer; friend class CoreTestsTest; std::optional test_list_; }; From 6a5226b4f19f621d2b3bd372819fa64d79f8ee20 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 14 Dec 2023 23:19:11 -0500 Subject: [PATCH 38/73] fix last cpp prob --- packages/pigeon/lib/cpp_generator.dart | 7 ++++++- .../test_plugin/windows/pigeon/core_tests.gen.h | 3 --- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index 9daa26d92b8b..007cc6286434 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -202,7 +202,12 @@ class CppHeaderGenerator extends StructuredGenerator { _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. diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h index 924ce54672a7..53c3320b3cf1 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h @@ -59,9 +59,6 @@ class ErrorOr { friend class HostTrivialApi; friend class HostSmallApi; friend class FlutterSmallApi; - friend class ProxyIntegrationCoreApi; - friend class ProxyApiSuperClass; - friend class ProxyApiInterface; ErrorOr() = default; T TakeValue() && { return std::get(std::move(v_)); } From 8e26c0822e216f7c4f9c9781d5e35cc56dbad4eb Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 15 Dec 2023 13:24:07 -0500 Subject: [PATCH 39/73] test generator_tools additions --- packages/pigeon/lib/dart_generator.dart | 4 +- packages/pigeon/lib/generator_tools.dart | 33 +++++- .../pigeon/test/generator_tools_test.dart | 105 ++++++++++++++++-- 3 files changed, 122 insertions(+), 20 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 7934b82e3cb9..ba71bab04efe 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -1006,7 +1006,7 @@ class $codecName extends StandardMessageCodec { superClassApisChain.isNotEmpty ? superClassApisChain.first : null; final Set interfacesApis = recursiveFindAllInterfacesApis( - api.interfacesNames, + api, allProxyApis, ); @@ -1029,7 +1029,7 @@ class $codecName extends StandardMessageCodec { final Set superClassInterfacesApis = recursiveFindAllInterfacesApis( - superClassApi.interfacesNames, + superClassApi, allProxyApis, ); for (final AstProxyApi proxyApi in superClassInterfacesApis) { diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 290aaac0a9a9..a4cc8c757da5 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -606,21 +606,31 @@ enum FileType { /// 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 [ArgumentError]. Set recursiveFindAllInterfacesApis( - Set interfaces, + AstProxyApi api, Iterable allProxyApis, ) { final Set interfacesApis = {}; for (final AstProxyApi proxyApi in allProxyApis) { - if (interfaces.contains(proxyApi.name)) { + 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.interfacesNames, allProxyApis), + recursiveFindAllInterfacesApis(proxyApi, allProxyApis), ); } @@ -631,6 +641,9 @@ Set recursiveFindAllInterfacesApis( /// /// This method assumes the super classes of each ProxyApi doesn't create a /// loop. Throws a [StateError] if a loop is found. +/// +/// This method also assumes that all super class names can be found in +/// [allProxyApis]. List recursiveGetSuperClassApisChain( AstProxyApi proxyApi, Iterable allProxyApis, @@ -643,8 +656,9 @@ List recursiveGetSuperClassApisChain( final Iterable apiNames = proxyApis.map( (AstProxyApi api) => api.name, ); - throw StateError( - 'Loop found when processing super classes for a ProxyApi: ${proxyApi.name},${apiNames.join(',')}', + throw ArgumentError( + 'Loop found when processing super classes for a ProxyApi: ' + '${proxyApi.name},${apiNames.join(',')}', ); } @@ -656,7 +670,14 @@ List recursiveGetSuperClassApisChain( } } - currentProxyApiName = nextProxyApi?.superClassName; + 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; diff --git a/packages/pigeon/test/generator_tools_test.dart b/packages/pigeon/test/generator_tools_test.dart index b2dd939f4aaf..68a2cb0861fa 100644 --- a/packages/pigeon/test/generator_tools_test.dart +++ b/packages/pigeon/test/generator_tools_test.dart @@ -6,18 +6,6 @@ import 'package:pigeon/ast.dart'; import 'package:pigeon/generator_tools.dart'; import 'package:test/test.dart'; -bool _equalSet(Set x, Set y) { - if (x.length != y.length) { - return false; - } - for (final T object in x) { - if (!y.contains(object)) { - return false; - } - } - return true; -} - final Class emptyClass = Class(name: 'className', fields: [ NamedType( name: 'namedTypeName', @@ -327,4 +315,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 fcdc09f58a59d4484fbbfa0261f5e7cd78ce15e9 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 18 Dec 2023 20:10:07 -0500 Subject: [PATCH 40/73] change to avoid using $ in code gen --- packages/pigeon/CHANGELOG.md | 2 +- .../example/app/lib/src/messages.g.dart | 2 +- packages/pigeon/lib/dart_generator.dart | 203 ++++---- packages/pigeon/lib/generator_tools.dart | 18 + .../background_platform_channels.gen.dart | 2 +- .../lib/src/generated/core_tests.gen.dart | 459 +++++++++--------- .../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 +- 14 files changed, 369 insertions(+), 333 deletions(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 1f816dc3f008..44de8eb74e7c 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,6 +1,6 @@ ## 15.0.2 -* Adds support for `ProxyApi` generation for Dart. +* Adds support for `ProxyApi` generation only for Dart. ## 15.0.1 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_generator.dart b/packages/pigeon/lib/dart_generator.dart index ba71bab04efe..a269f32472b1 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -96,7 +96,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', + '// 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(); } @@ -624,10 +624,11 @@ if (${_varNamePrefix}replyList == null) { Indent indent, { required String dartPackageName, }) { + const String copyableClassName = '${classNamePrefix}Copyable'; final Iterable apiHandlerSetups = root.apis.whereType().map( (AstProxyApi api) { - return '${api.name}.\$setUpMessageHandlers(\$instanceManager: instanceManager);'; + return '${api.name}.${classMemberNamePrefix}setUpMessageHandlers(${classMemberNamePrefix}instanceManager: instanceManager);'; }, ); indent.format(''' @@ -635,16 +636,16 @@ if (${_varNamePrefix}replyList == null) { /// /// All implementers are expected to be immutable as defined by the annotation. @immutable -mixin \$Copyable { +mixin $copyableClassName { /// Instantiates and returns a functionally identical object to oneself. /// /// Outside of tests, this method should only ever be called by - /// [\$InstanceManager]. + /// [$instanceManagerClassName]. /// /// Subclasses should always override their parent's implementation of this /// method. @protected - \$Copyable \$copy(); + $copyableClassName ${classMemberNamePrefix}copy(); } /// Maintains instances used to communicate with the native objects they @@ -662,9 +663,9 @@ mixin \$Copyable { /// 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 \$InstanceManager { - /// Constructs an [\$InstanceManager]. - \$InstanceManager({required void Function(int) onWeakReferenceRemoved}) { +class $instanceManagerClassName { + /// Constructs an [$instanceManagerClassName]. + $instanceManagerClassName({required void Function(int) onWeakReferenceRemoved}) { this.onWeakReferenceRemoved = (int identifier) { _weakInstances.remove(identifier); onWeakReferenceRemoved(identifier); @@ -678,7 +679,7 @@ class \$InstanceManager { // 0 <= n < 2^16. static const int _maxDartCreatedIdentifier = 65536; - static final \$InstanceManager instance = _initInstance(); + 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 @@ -689,9 +690,9 @@ class \$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; @@ -699,17 +700,17 @@ class \$InstanceManager { /// or becomes inaccessible. late final void Function(int) onWeakReferenceRemoved; - static \$InstanceManager _initInstance() { + static $instanceManagerClassName _initInstance() { WidgetsFlutterBinding.ensureInitialized(); - final _InstanceManagerApi api = _InstanceManagerApi(); - // Clears the native `InstanceManager` on the initial use of the Dart one. + final _${instanceManagerClassName}Api api = _${instanceManagerClassName}Api(); + // Clears the native `$instanceManagerClassName` on the initial use of the Dart one. api.clear(); - final \$InstanceManager instanceManager = \$InstanceManager( + final $instanceManagerClassName instanceManager = $instanceManagerClassName( onWeakReferenceRemoved: (int identifier) { api.removeStrongReference(identifier); }, ); - _InstanceManagerApi.\$setUpMessageHandlers(instanceManager: instanceManager); + _${instanceManagerClassName}Api.setUpMessageHandlers(instanceManager: instanceManager); ${apiHandlerSetups.join('\n\t\t')} return instanceManager; } @@ -722,7 +723,7 @@ class \$InstanceManager { /// Throws assertion error if the instance has already been added. /// /// Returns the randomly generated id of the [instance] added. - int addDartCreatedInstance(\$Copyable instance) { + int addDartCreatedInstance($copyableClassName instance) { final int identifier = _nextUniqueIdentifier(); _addInstanceWithIdentifier(instance, identifier); return identifier; @@ -736,7 +737,7 @@ class \$InstanceManager { /// /// This does not remove the strong referenced instance associated with /// [instance]. This can be done with [remove]. - int? removeWeakReference(\$Copyable instance) { + int? removeWeakReference($copyableClassName instance) { final int? identifier = getIdentifier(instance); if (identifier == null) { return null; @@ -758,7 +759,7 @@ class \$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?; } @@ -774,15 +775,15 @@ class \$InstanceManager { /// /// 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 \$Copyable? weakInstance = _weakInstances[identifier]?.target; + T? getInstanceWithWeakReference(int identifier) { + final $copyableClassName? weakInstance = _weakInstances[identifier]?.target; if (weakInstance == null) { - final \$Copyable? strongInstance = _strongInstances[identifier]; + final $copyableClassName? strongInstance = _strongInstances[identifier]; if (strongInstance != null) { - final \$Copyable copy = strongInstance.\$copy(); + final $copyableClassName copy = strongInstance.${classMemberNamePrefix}copy(); _identifiers[copy] = identifier; - _weakInstances[identifier] = WeakReference<\$Copyable>(copy); + _weakInstances[identifier] = WeakReference<$copyableClassName>(copy); _finalizer.attach(copy, identifier, detach: copy); return copy as T; } @@ -793,7 +794,7 @@ class \$InstanceManager { } /// Retrieves the identifier associated with instance. - int? getIdentifier(\$Copyable instance) { + int? getIdentifier($copyableClassName instance) { return _identifiers[instance]; } @@ -806,20 +807,20 @@ class \$InstanceManager { /// added. /// /// Returns unique identifier of the [instance] added. - void addHostCreatedInstance(\$Copyable instance, int identifier) { + void addHostCreatedInstance($copyableClassName instance, int identifier) { _addInstanceWithIdentifier(instance, identifier); } - void _addInstanceWithIdentifier(\$Copyable instance, int identifier) { + void _addInstanceWithIdentifier($copyableClassName instance, int identifier) { assert(!containsIdentifier(identifier)); assert(getIdentifier(instance) == null); assert(identifier >= 0); _identifiers[instance] = identifier; - _weakInstances[identifier] = WeakReference<\$Copyable>(instance); + _weakInstances[identifier] = WeakReference<$copyableClassName>(instance); _finalizer.attach(instance, identifier, detach: instance); - final \$Copyable copy = instance.\$copy(); + final $copyableClassName copy = instance.${classMemberNamePrefix}copy(); _identifiers[copy] = identifier; _strongInstances[identifier] = copy; } @@ -849,26 +850,23 @@ class \$InstanceManager { Indent indent, { required String dartPackageName, }) { + const String apiName = '${instanceManagerClassName}Api'; final String removeStrongReferenceName = makeChannelNameWithStrings( - apiName: r'$InstanceManagerApi', + apiName: apiName, methodName: 'removeStrongReference', dartPackageName: dartPackageName, ); final String clearName = makeChannelNameWithStrings( - apiName: r'$InstanceManagerApi', + apiName: apiName, methodName: 'clear', dartPackageName: dartPackageName, ); indent.writeln(''' -/// Generated API for managing the Dart and native `InstanceManager`s. -class _InstanceManagerApi { - /// Constructor for [_InstanceManagerApi]. - /// - /// The [binaryMessenger] named argument is available for dependency - /// injection. If it is left null, the default [BinaryMessenger] will be used - /// which routes to the host platform. - _InstanceManagerApi({BinaryMessenger? binaryMessenger}) +/// Generated API for managing the Dart and native `$instanceManagerClassName`s. +class _$apiName { + /// Constructor for [_$apiName ]. + _$apiName({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; final BinaryMessenger? _binaryMessenger; @@ -876,9 +874,9 @@ class _InstanceManagerApi { static const MessageCodec $_pigeonChannelCodec = StandardMessageCodec(); - static void \$setUpMessageHandlers({ + static void setUpMessageHandlers({ BinaryMessenger? binaryMessenger, - \$InstanceManager? instanceManager, + $instanceManagerClassName? instanceManager, }) { const String channelName = r'$removeStrongReferenceName'; @@ -897,7 +895,7 @@ class _InstanceManagerApi { identifier != null, r'Argument for \$channelName, expected non-null int.', ); - (instanceManager ?? \$InstanceManager.instance).remove(identifier!); + (instanceManager ?? $instanceManagerClassName.instance).remove(identifier!); return; }); } @@ -925,7 +923,7 @@ class _InstanceManagerApi { } } - /// Clear the native `InstanceManager`. + /// Clear the native `$instanceManagerClassName`. /// /// This is typically called after a hot restart. Future clear() async { @@ -968,11 +966,11 @@ class _InstanceManagerApi { class $codecName extends StandardMessageCodec { const $codecName(this.instanceManager); - final \$InstanceManager instanceManager; + final $instanceManagerClassName instanceManager; @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is \$Copyable) { + if (value is ${classNamePrefix}Copyable) { buffer.putUint8(128); writeValue(buffer, instanceManager.getIdentifier(value)); } else { @@ -1052,7 +1050,7 @@ class $codecName extends StandardMessageCodec { if (api.interfacesNames.isNotEmpty) ...api.interfacesNames.map((String name) => cb.refer(name)) else - cb.refer(r'$Copyable') + cb.refer('${classNamePrefix}Copyable') ]) ..docs.addAll(asDocumentationComments( api.documentationComments, @@ -1121,7 +1119,7 @@ class $codecName extends StandardMessageCodec { apiName: apiName, methodName: constructor.name.isNotEmpty ? constructor.name - : r'$defaultConstructor', + : '${classMemberNamePrefix}defaultConstructor', dartPackageName: dartPackageName, ); builder @@ -1134,15 +1132,15 @@ class $codecName extends StandardMessageCodec { [ cb.Parameter( (cb.ParameterBuilder builder) => builder - ..name = r'$binaryMessenger' + ..name = '${classMemberNamePrefix}binaryMessenger' ..named = true ..toSuper = superClassApi != null ..toThis = superClassApi == null, ), cb.Parameter((cb.ParameterBuilder builder) => builder - ..name = r'$instanceManager' + ..name = '${classMemberNamePrefix}instanceManager' ..type = superClassApi == null - ? cb.refer(r'$InstanceManager?') + ? cb.refer('$instanceManagerClassName?') : null ..named = true ..toSuper = superClassApi != null), @@ -1194,8 +1192,8 @@ class $codecName extends StandardMessageCodec { ..initializers.add( cb.Code( superClassApi != null - ? r'super.$detached()' - : r'$instanceManager = $instanceManager ?? $InstanceManager.instance', + ? 'super.${classMemberNamePrefix}detached()' + : '${classMemberNamePrefix}instanceManager = ${classMemberNamePrefix}instanceManager ?? $instanceManagerClassName.instance', ), ) ..body = cb.Block.of([ @@ -1204,7 +1202,8 @@ class $codecName extends StandardMessageCodec { ), _basicMessageChannel( codec: cb.refer(codecInstanceName), - binaryMessenger: cb.refer(r'$binaryMessenger'), + binaryMessenger: + cb.refer('${classMemberNamePrefix}binaryMessenger'), ), cb .refer('${_varNamePrefix}channel.send') @@ -1212,7 +1211,7 @@ class $codecName extends StandardMessageCodec { cb.literalList( [ cb.refer( - '${superClassApi != null ? '' : 'this.'}\$instanceManager.addDartCreatedInstance(this)', + '${superClassApi != null ? '' : 'this.'}${classMemberNamePrefix}instanceManager.addDartCreatedInstance(this)', ), ...nonAttachedFields.mapIndexed(_hostMessageArgument), ...constructor.parameters.mapIndexed( @@ -1278,7 +1277,7 @@ class $codecName extends StandardMessageCodec { ), cb.Constructor( (cb.ConstructorBuilder builder) => builder - ..name = r'$detached' + ..name = '${classMemberNamePrefix}detached' ..docs.addAll([ '/// Constructs $apiName without creating the associated native object.', '///', @@ -1288,16 +1287,16 @@ class $codecName extends StandardMessageCodec { ..optionalParameters.addAll([ cb.Parameter( (cb.ParameterBuilder builder) => builder - ..name = r'$binaryMessenger' + ..name = '${classMemberNamePrefix}binaryMessenger' ..named = true ..toSuper = superClassApi != null ..toThis = superClassApi == null, ), cb.Parameter( (cb.ParameterBuilder builder) => builder - ..name = r'$instanceManager' + ..name = '${classMemberNamePrefix}instanceManager' ..type = superClassApi == null - ? cb.refer(r'$InstanceManager?') + ? cb.refer('$instanceManagerClassName?') : null ..named = true ..toSuper = superClassApi != null, @@ -1338,8 +1337,8 @@ class $codecName extends StandardMessageCodec { ..initializers.add( cb.Code( superClassApi != null - ? r'super.$detached()' - : r'$instanceManager = $instanceManager ?? $InstanceManager.instance', + ? 'super.${classMemberNamePrefix}detached()' + : '${classMemberNamePrefix}instanceManager = ${classMemberNamePrefix}instanceManager ?? $instanceManagerClassName.instance', ), ), ), @@ -1366,12 +1365,13 @@ class $codecName extends StandardMessageCodec { ..type = cb.refer(codecName) ..late = true ..modifier = cb.FieldModifier.final$ - ..assignment = cb.Code('$codecName(\$instanceManager)'), + ..assignment = + cb.Code('$codecName(${classMemberNamePrefix}instanceManager)'), ), if (!hasSuperClass) ...[ cb.Field( (cb.FieldBuilder builder) => builder - ..name = r'$binaryMessenger' + ..name = '${classMemberNamePrefix}binaryMessenger' ..type = cb.refer('BinaryMessenger?') ..modifier = cb.FieldModifier.final$ ..docs.addAll([ @@ -1387,8 +1387,8 @@ class $codecName extends StandardMessageCodec { ), cb.Field( (cb.FieldBuilder builder) => builder - ..name = r'$instanceManager' - ..type = cb.refer(r'$InstanceManager') + ..name = '${classMemberNamePrefix}instanceManager' + ..type = cb.refer(instanceManagerClassName) ..modifier = cb.FieldModifier.final$ ..docs.add( '/// Maintains instances stored to communicate with native language objects.', @@ -1498,26 +1498,26 @@ class $codecName extends StandardMessageCodec { return [ cb.Method.returnsVoid( (cb.MethodBuilder builder) => builder - ..name = r'$setUpMessageHandlers' + ..name = '${classMemberNamePrefix}setUpMessageHandlers' ..returns = cb.refer('void') ..static = true ..optionalParameters.addAll([ cb.Parameter( (cb.ParameterBuilder builder) => builder - ..name = r'$binaryMessenger' + ..name = '${classMemberNamePrefix}binaryMessenger' ..named = true ..type = cb.refer('BinaryMessenger?'), ), cb.Parameter( (cb.ParameterBuilder builder) => builder - ..name = r'$instanceManager' + ..name = '${classMemberNamePrefix}instanceManager' ..named = true - ..type = cb.refer(r'$InstanceManager?'), + ..type = cb.refer('$instanceManagerClassName?'), ), if (!hasARequiredFlutterMethod) cb.Parameter( (cb.ParameterBuilder builder) => builder - ..name = r'$detached' + ..name = '${classMemberNamePrefix}detached' ..named = true ..type = cb.FunctionType( (cb.FunctionTypeBuilder builder) => builder @@ -1560,19 +1560,20 @@ class $codecName extends StandardMessageCodec { ]) ..body = cb.Block.of([ cb.Code( - 'final $codecName $_pigeonChannelCodec = $codecName(\$instanceManager ?? \$InstanceManager.instance);', + 'final $codecName $_pigeonChannelCodec = $codecName(${classMemberNamePrefix}instanceManager ?? $instanceManagerClassName.instance);', ), if (!hasARequiredFlutterMethod) ...[ const cb.Code('{'), cb.Code( "const String ${_varNamePrefix}channelName = r'${makeChannelNameWithStrings( apiName: apiName, - methodName: r'$detached', + methodName: '${classMemberNamePrefix}detached', dartPackageName: dartPackageName, )}';", ), _basicMessageChannel( - binaryMessenger: cb.refer(r'$binaryMessenger'), + binaryMessenger: + cb.refer('${classMemberNamePrefix}binaryMessenger'), ), cb.refer('${_varNamePrefix}channel.setMessageHandler').call( [ @@ -1618,12 +1619,12 @@ class $codecName extends StandardMessageCodec { ), cb .refer( - r'($instanceManager ?? $InstanceManager.instance)', + '(${classMemberNamePrefix}instanceManager ?? $instanceManagerClassName.instance)', ) .property('addHostCreatedInstance') .call([ cb - .refer(r'$detached?.call') + .refer('${classMemberNamePrefix}detached?.call') .call(nonAttachedFields.mapIndexed( (int index, Field field) { // The calling instance is the first arg. @@ -1636,13 +1637,18 @@ class $codecName extends StandardMessageCodec { ); }, )).ifNullThen( - cb.refer('$apiName.\$detached').call( + cb + .refer( + '$apiName.${classMemberNamePrefix}detached') + .call( [], { - r'$binaryMessenger': - cb.refer(r'$binaryMessenger'), - r'$instanceManager': - cb.refer(r'$instanceManager'), + '${classMemberNamePrefix}binaryMessenger': + cb.refer( + '${classMemberNamePrefix}binaryMessenger'), + '${classMemberNamePrefix}instanceManager': + cb.refer( + '${classMemberNamePrefix}instanceManager'), ...nonAttachedFields.toList().asMap().map( (int index, Field field) { final String argName = @@ -1706,7 +1712,8 @@ class $codecName extends StandardMessageCodec { "const String ${_varNamePrefix}channelName = r'$channelName';", ), _basicMessageChannel( - binaryMessenger: cb.refer(r'$binaryMessenger'), + binaryMessenger: + cb.refer('${classMemberNamePrefix}binaryMessenger'), ), cb.refer('${_varNamePrefix}channel.setMessageHandler').call( [ @@ -1823,7 +1830,8 @@ class $codecName extends StandardMessageCodec { ..returns = cb.refer(type) ..body = cb.Block.of( [ - cb.Code('final $type instance = $type.\$detached('), + cb.Code( + 'final $type instance = $type.${classMemberNamePrefix}detached('), if (!field.isStatic) ...[ const cb.Code(r'$binaryMessenger: $binaryMessenger,'), const cb.Code(r'$instanceManager: $instanceManager,'), @@ -1835,9 +1843,11 @@ class $codecName extends StandardMessageCodec { _basicMessageChannel( codec: !field.isStatic ? cb.refer('_codec$apiName') - : cb.refer('$codecName(\$InstanceManager.instance)'), - binaryMessenger: - !field.isStatic ? cb.refer(r'$binaryMessenger') : null, + : cb.refer( + '$codecName($instanceManagerClassName.instance)'), + binaryMessenger: !field.isStatic + ? cb.refer('${classMemberNamePrefix}binaryMessenger') + : null, ), cb .refer('${_varNamePrefix}channel.send') @@ -1846,7 +1856,7 @@ class $codecName extends StandardMessageCodec { [ if (!field.isStatic) cb.refer('this'), cb.refer( - '${field.isStatic ? r'$InstanceManager.instance' : r'$instanceManager'}.addDartCreatedInstance(instance)', + '${field.isStatic ? r'$InstanceManager.instance' : '${classMemberNamePrefix}instanceManager'}.addDartCreatedInstance(instance)', ), ], cb.refer('Object?'), @@ -1936,14 +1946,14 @@ class $codecName extends StandardMessageCodec { if (method.isStatic) ...[ cb.Parameter( (cb.ParameterBuilder builder) => builder - ..name = r'$binaryMessenger' + ..name = '${classMemberNamePrefix}binaryMessenger' ..type = cb.refer('BinaryMessenger?') ..named = true, ), cb.Parameter( (cb.ParameterBuilder builder) => builder - ..name = r'$instanceManager' - ..type = cb.refer(r'$InstanceManager?'), + ..name = '${classMemberNamePrefix}instanceManager' + ..type = cb.refer('$instanceManagerClassName?'), ), ], ]) @@ -1959,9 +1969,10 @@ class $codecName extends StandardMessageCodec { codec: !method.isStatic ? cb.refer('_codec$apiName') : cb.refer( - '$codecName(\$instanceManager ?? \$InstanceManager.instance)', + '$codecName(${classMemberNamePrefix}instanceManager ?? $instanceManagerClassName.instance)', ), - binaryMessenger: cb.refer(r'$binaryMessenger'), + binaryMessenger: + cb.refer('${classMemberNamePrefix}binaryMessenger'), ), const cb.Code( 'final List? ${_varNamePrefix}replyList ='), @@ -2028,17 +2039,19 @@ class $codecName extends StandardMessageCodec { ), cb.Method( (cb.MethodBuilder builder) => builder - ..name = r'$copy' + ..name = '${classMemberNamePrefix}copy' ..returns = cb.refer(apiName) ..annotations.add(cb.refer('override')) ..body = cb.Block.of([ cb - .refer('$apiName.\$detached') + .refer('$apiName.${classMemberNamePrefix}detached') .call( [], { - r'$binaryMessenger': cb.refer(r'$binaryMessenger'), - r'$instanceManager': cb.refer(r'$instanceManager'), + '${classMemberNamePrefix}binaryMessenger': + cb.refer('${classMemberNamePrefix}binaryMessenger'), + '${classMemberNamePrefix}instanceManager': + cb.refer('${classMemberNamePrefix}instanceManager'), for (final Field field in nonAttachedFields) field.name: cb.refer(field.name), for (final Method method in superClassFlutterMethods) diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index a4cc8c757da5..3102064a524e 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -295,6 +295,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. 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 69117ef83202..4878e2265bce 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; @@ -36,16 +36,16 @@ List wrapResponse( /// /// All implementers are expected to be immutable as defined by the annotation. @immutable -mixin $Copyable { +mixin Pigeon_Copyable { /// Instantiates and returns a functionally identical object to oneself. /// /// Outside of tests, this method should only ever be called by - /// [$InstanceManager]. + /// [Pigeon_InstanceManager]. /// /// Subclasses should always override their parent's implementation of this /// method. @protected - $Copyable $copy(); + Pigeon_Copyable pigeon_copy(); } /// Maintains instances used to communicate with the native objects they @@ -63,9 +63,9 @@ mixin $Copyable { /// 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 $InstanceManager { - /// Constructs an [$InstanceManager]. - $InstanceManager({required void Function(int) onWeakReferenceRemoved}) { +class Pigeon_InstanceManager { + /// Constructs an [Pigeon_InstanceManager]. + Pigeon_InstanceManager({required void Function(int) onWeakReferenceRemoved}) { this.onWeakReferenceRemoved = (int identifier) { _weakInstances.remove(identifier); onWeakReferenceRemoved(identifier); @@ -79,7 +79,7 @@ class $InstanceManager { // 0 <= n < 2^16. static const int _maxDartCreatedIdentifier = 65536; - static final $InstanceManager instance = _initInstance(); + 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 @@ -90,9 +90,9 @@ class $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; @@ -100,21 +100,24 @@ class $InstanceManager { /// or becomes inaccessible. late final void Function(int) onWeakReferenceRemoved; - static $InstanceManager _initInstance() { + static Pigeon_InstanceManager _initInstance() { WidgetsFlutterBinding.ensureInitialized(); - final _InstanceManagerApi api = _InstanceManagerApi(); - // Clears the native `InstanceManager` on the initial use of the Dart one. + final _Pigeon_InstanceManagerApi api = _Pigeon_InstanceManagerApi(); + // Clears the native `Pigeon_InstanceManager` on the initial use of the Dart one. api.clear(); - final $InstanceManager instanceManager = $InstanceManager( + final Pigeon_InstanceManager instanceManager = Pigeon_InstanceManager( onWeakReferenceRemoved: (int identifier) { api.removeStrongReference(identifier); }, ); - _InstanceManagerApi.$setUpMessageHandlers(instanceManager: instanceManager); - ProxyIntegrationCoreApi.$setUpMessageHandlers( - $instanceManager: instanceManager); - ProxyApiSuperClass.$setUpMessageHandlers($instanceManager: instanceManager); - ProxyApiInterface.$setUpMessageHandlers($instanceManager: instanceManager); + _Pigeon_InstanceManagerApi.setUpMessageHandlers( + instanceManager: instanceManager); + ProxyIntegrationCoreApi.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + ProxyApiSuperClass.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + ProxyApiInterface.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); return instanceManager; } @@ -126,7 +129,7 @@ class $InstanceManager { /// Throws assertion error if the instance has already been added. /// /// Returns the randomly generated id of the [instance] added. - int addDartCreatedInstance($Copyable instance) { + int addDartCreatedInstance(Pigeon_Copyable instance) { final int identifier = _nextUniqueIdentifier(); _addInstanceWithIdentifier(instance, identifier); return identifier; @@ -140,7 +143,7 @@ class $InstanceManager { /// /// This does not remove the strong referenced instance associated with /// [instance]. This can be done with [remove]. - int? removeWeakReference($Copyable instance) { + int? removeWeakReference(Pigeon_Copyable instance) { final int? identifier = getIdentifier(instance); if (identifier == null) { return null; @@ -162,7 +165,7 @@ class $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?; } @@ -178,15 +181,15 @@ class $InstanceManager { /// /// 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 $Copyable? weakInstance = _weakInstances[identifier]?.target; + T? getInstanceWithWeakReference(int identifier) { + final Pigeon_Copyable? weakInstance = _weakInstances[identifier]?.target; if (weakInstance == null) { - final $Copyable? strongInstance = _strongInstances[identifier]; + final Pigeon_Copyable? strongInstance = _strongInstances[identifier]; if (strongInstance != null) { - final $Copyable copy = strongInstance.$copy(); + final Pigeon_Copyable copy = strongInstance.pigeon_copy(); _identifiers[copy] = identifier; - _weakInstances[identifier] = WeakReference<$Copyable>(copy); + _weakInstances[identifier] = WeakReference(copy); _finalizer.attach(copy, identifier, detach: copy); return copy as T; } @@ -197,7 +200,7 @@ class $InstanceManager { } /// Retrieves the identifier associated with instance. - int? getIdentifier($Copyable instance) { + int? getIdentifier(Pigeon_Copyable instance) { return _identifiers[instance]; } @@ -210,20 +213,20 @@ class $InstanceManager { /// added. /// /// Returns unique identifier of the [instance] added. - void addHostCreatedInstance($Copyable instance, int identifier) { + void addHostCreatedInstance(Pigeon_Copyable instance, int identifier) { _addInstanceWithIdentifier(instance, identifier); } - void _addInstanceWithIdentifier($Copyable instance, int identifier) { + void _addInstanceWithIdentifier(Pigeon_Copyable instance, int identifier) { assert(!containsIdentifier(identifier)); assert(getIdentifier(instance) == null); assert(identifier >= 0); _identifiers[instance] = identifier; - _weakInstances[identifier] = WeakReference<$Copyable>(instance); + _weakInstances[identifier] = WeakReference(instance); _finalizer.attach(instance, identifier, detach: instance); - final $Copyable copy = instance.$copy(); + final Pigeon_Copyable copy = instance.pigeon_copy(); _identifiers[copy] = identifier; _strongInstances[identifier] = copy; } @@ -244,14 +247,10 @@ class $InstanceManager { } } -/// Generated API for managing the Dart and native `InstanceManager`s. -class _InstanceManagerApi { - /// Constructor for [_InstanceManagerApi]. - /// - /// The [binaryMessenger] named argument is available for dependency - /// injection. If it is left null, the default [BinaryMessenger] will be used - /// which routes to the host platform. - _InstanceManagerApi({BinaryMessenger? binaryMessenger}) +/// 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; @@ -259,12 +258,12 @@ class _InstanceManagerApi { static const MessageCodec pigeonChannelCodec = StandardMessageCodec(); - static void $setUpMessageHandlers({ + static void setUpMessageHandlers({ BinaryMessenger? binaryMessenger, - $InstanceManager? instanceManager, + Pigeon_InstanceManager? instanceManager, }) { const String channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.$InstanceManagerApi.removeStrongReference'; + r'dev.flutter.pigeon.pigeon_integration_tests.Pigeon_InstanceManagerApi.removeStrongReference'; final BasicMessageChannel channel = BasicMessageChannel( channelName, pigeonChannelCodec, @@ -280,14 +279,14 @@ class _InstanceManagerApi { identifier != null, r'Argument for $channelName, expected non-null int.', ); - (instanceManager ?? $InstanceManager.instance).remove(identifier!); + (instanceManager ?? Pigeon_InstanceManager.instance).remove(identifier!); return; }); } Future removeStrongReference(int identifier) async { const String channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.$InstanceManagerApi.removeStrongReference'; + r'dev.flutter.pigeon.pigeon_integration_tests.Pigeon_InstanceManagerApi.removeStrongReference'; final BasicMessageChannel channel = BasicMessageChannel( channelName, pigeonChannelCodec, @@ -308,12 +307,12 @@ class _InstanceManagerApi { } } - /// Clear the native `InstanceManager`. + /// 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.$InstanceManagerApi.clear'; + r'dev.flutter.pigeon.pigeon_integration_tests.Pigeon_InstanceManagerApi.clear'; final BasicMessageChannel channel = BasicMessageChannel( channelName, pigeonChannelCodec, @@ -3754,11 +3753,11 @@ abstract class FlutterSmallApi { class _ProxyIntegrationCoreApiCodec extends StandardMessageCodec { const _ProxyIntegrationCoreApiCodec(this.instanceManager); - final $InstanceManager instanceManager; + final Pigeon_InstanceManager instanceManager; @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is $Copyable) { + if (value is Pigeon_Copyable) { buffer.putUint8(128); writeValue(buffer, instanceManager.getIdentifier(value)); } else { @@ -3783,8 +3782,8 @@ class _ProxyIntegrationCoreApiCodec extends StandardMessageCodec { class ProxyIntegrationCoreApi extends ProxyApiSuperClass implements ProxyApiInterface { ProxyIntegrationCoreApi({ - super.$binaryMessenger, - super.$instanceManager, + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, required this.aBool, required this.anInt, required this.aDouble, @@ -3839,17 +3838,17 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass List? nullableListParam, Map? nullableMapParam, AnEnum? nullableEnumParam, - }) : super.$detached() { + }) : super.pigeon_detached() { const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.$defaultConstructor'; + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.pigeon_defaultConstructor'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.send([ - $instanceManager.addDartCreatedInstance(this), + pigeon_instanceManager.addDartCreatedInstance(this), aBool, anInt, aDouble, @@ -3900,9 +3899,9 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// This should only be used by subclasses created by this library or to /// create copies. - ProxyIntegrationCoreApi.$detached({ - super.$binaryMessenger, - super.$instanceManager, + ProxyIntegrationCoreApi.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, required this.aBool, required this.anInt, required this.aDouble, @@ -3941,10 +3940,10 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass this.flutterEchoNullableEnum, this.callFlutterNoopAsync, this.callFlutterEchoAsyncString, - }) : super.$detached(); + }) : super.pigeon_detached(); late final _ProxyIntegrationCoreApiCodec _codecProxyIntegrationCoreApi = - _ProxyIntegrationCoreApiCodec($instanceManager); + _ProxyIntegrationCoreApiCodec(pigeon_instanceManager); final bool aBool; @@ -4099,9 +4098,9 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass @override final void Function(ProxyApiInterface instance)? anInterfaceMethod; - static void $setUpMessageHandlers({ - BinaryMessenger? $binaryMessenger, - $InstanceManager? $instanceManager, + static void pigeon_setUpMessageHandlers({ + BinaryMessenger? pigeon_binaryMessenger, + Pigeon_InstanceManager? pigeon_instanceManager, ProxyIntegrationCoreApi Function( bool aBool, int anInt, @@ -4119,7 +4118,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass List? aNullableList, Map? aNullableMap, AnEnum? aNullableEnum, - )? $detached, + )? pigeon_detached, void Function(ProxyIntegrationCoreApi instance)? flutterNoop, Object? Function(ProxyIntegrationCoreApi instance)? flutterThrowError, void Function(ProxyIntegrationCoreApi instance)? flutterThrowErrorFromVoid, @@ -4196,15 +4195,15 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass }) { final _ProxyIntegrationCoreApiCodec pigeonChannelCodec = _ProxyIntegrationCoreApiCodec( - $instanceManager ?? $InstanceManager.instance); + pigeon_instanceManager ?? Pigeon_InstanceManager.instance); { const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.$detached'; + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.pigeon_detached'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -4271,8 +4270,9 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass (args[15] as Map?)?.cast(); final AnEnum? arg_aNullableEnum = args[16] == null ? null : AnEnum.values[args[16]! as int]; - ($instanceManager ?? $InstanceManager.instance).addHostCreatedInstance( - $detached?.call( + (pigeon_instanceManager ?? Pigeon_InstanceManager.instance) + .addHostCreatedInstance( + pigeon_detached?.call( arg_aBool!, arg_anInt!, arg_aDouble!, @@ -4290,9 +4290,9 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass arg_aNullableMap, arg_aNullableEnum, ) ?? - ProxyIntegrationCoreApi.$detached( - $binaryMessenger: $binaryMessenger, - $instanceManager: $instanceManager, + ProxyIntegrationCoreApi.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, aBool: arg_aBool!, anInt: arg_anInt!, aDouble: arg_aDouble!, @@ -4322,7 +4322,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -4355,7 +4355,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -4390,7 +4390,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -4424,7 +4424,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -4466,7 +4466,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -4508,7 +4508,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -4550,7 +4550,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -4592,7 +4592,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -4634,7 +4634,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -4677,7 +4677,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -4720,7 +4720,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -4763,7 +4763,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -4802,7 +4802,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -4841,7 +4841,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -4880,7 +4880,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -4919,7 +4919,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -4958,7 +4958,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -4998,7 +4998,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -5038,7 +5038,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -5078,7 +5078,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -5112,7 +5112,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -5159,7 +5159,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([this]) as List?); @@ -5184,7 +5184,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([this]) as List?); @@ -5209,7 +5209,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([this]) as List?); @@ -5234,7 +5234,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([this]) as List?); @@ -5259,7 +5259,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5292,7 +5292,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5325,7 +5325,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5358,7 +5358,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5391,7 +5391,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5424,7 +5424,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5457,7 +5457,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5490,7 +5490,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5524,7 +5524,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5557,7 +5557,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5585,7 +5585,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5613,7 +5613,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5641,7 +5641,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5670,7 +5670,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5698,7 +5698,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5726,7 +5726,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5755,7 +5755,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5783,7 +5783,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5814,7 +5814,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([this]) as List?); @@ -5839,7 +5839,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5872,7 +5872,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5905,7 +5905,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5938,7 +5938,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -5971,7 +5971,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6004,7 +6004,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6037,7 +6037,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6070,7 +6070,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6104,7 +6104,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6137,7 +6137,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([this]) as List?); @@ -6162,7 +6162,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([this]) as List?); @@ -6187,7 +6187,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([this]) as List?); @@ -6212,7 +6212,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6240,7 +6240,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6268,7 +6268,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6296,7 +6296,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6324,7 +6324,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6352,7 +6352,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6380,7 +6380,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6409,7 +6409,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6438,7 +6438,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6461,8 +6461,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } static Future staticNoop({ - BinaryMessenger? $binaryMessenger, - $InstanceManager? $instanceManager, + BinaryMessenger? pigeon_binaryMessenger, + Pigeon_InstanceManager? pigeon_instanceManager, }) async { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.staticNoop'; @@ -6470,8 +6470,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _ProxyIntegrationCoreApiCodec( - $instanceManager ?? $InstanceManager.instance), - binaryMessenger: $binaryMessenger, + pigeon_instanceManager ?? Pigeon_InstanceManager.instance), + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([]) as List?); @@ -6490,8 +6490,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass static Future echoStaticString( String aString, { - BinaryMessenger? $binaryMessenger, - $InstanceManager? $instanceManager, + BinaryMessenger? pigeon_binaryMessenger, + Pigeon_InstanceManager? pigeon_instanceManager, }) async { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoStaticString'; @@ -6499,8 +6499,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _ProxyIntegrationCoreApiCodec( - $instanceManager ?? $InstanceManager.instance), - binaryMessenger: $binaryMessenger, + pigeon_instanceManager ?? Pigeon_InstanceManager.instance), + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([aString]) as List?); @@ -6523,8 +6523,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } static Future staticAsyncNoop({ - BinaryMessenger? $binaryMessenger, - $InstanceManager? $instanceManager, + BinaryMessenger? pigeon_binaryMessenger, + Pigeon_InstanceManager? pigeon_instanceManager, }) async { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.staticAsyncNoop'; @@ -6532,8 +6532,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _ProxyIntegrationCoreApiCodec( - $instanceManager ?? $InstanceManager.instance), - binaryMessenger: $binaryMessenger, + pigeon_instanceManager ?? Pigeon_InstanceManager.instance), + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([]) as List?); @@ -6557,7 +6557,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([this]) as List?); @@ -6581,7 +6581,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([this]) as List?); @@ -6605,7 +6605,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([this]) as List?); @@ -6629,7 +6629,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6661,7 +6661,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6693,7 +6693,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6725,7 +6725,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6757,7 +6757,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6789,7 +6789,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6822,7 +6822,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6855,7 +6855,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6887,7 +6887,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6914,7 +6914,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6941,7 +6941,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6968,7 +6968,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -6995,7 +6995,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -7023,7 +7023,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -7051,7 +7051,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -7079,7 +7079,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass BasicMessageChannel( __pigeon_channelName, _codecProxyIntegrationCoreApi, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([ @@ -7102,10 +7102,10 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } @override - ProxyIntegrationCoreApi $copy() { - return ProxyIntegrationCoreApi.$detached( - $binaryMessenger: $binaryMessenger, - $instanceManager: $instanceManager, + ProxyIntegrationCoreApi pigeon_copy() { + return ProxyIntegrationCoreApi.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, aBool: aBool, anInt: anInt, aDouble: aDouble, @@ -7151,11 +7151,11 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass class _ProxyApiSuperClassCodec extends StandardMessageCodec { const _ProxyApiSuperClassCodec(this.instanceManager); - final $InstanceManager instanceManager; + final Pigeon_InstanceManager instanceManager; @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is $Copyable) { + if (value is Pigeon_Copyable) { buffer.putUint8(128); writeValue(buffer, instanceManager.getIdentifier(value)); } else { @@ -7176,43 +7176,45 @@ class _ProxyApiSuperClassCodec extends StandardMessageCodec { } /// ProxyApi to serve as a super class to the core ProxyApi interface. -class ProxyApiSuperClass implements $Copyable { +class ProxyApiSuperClass implements Pigeon_Copyable { /// Constructs ProxyApiSuperClass without creating the associated native object. /// /// This should only be used by subclasses created by this library or to /// create copies. - ProxyApiSuperClass.$detached({ - this.$binaryMessenger, - $InstanceManager? $instanceManager, - }) : $instanceManager = $instanceManager ?? $InstanceManager.instance; + ProxyApiSuperClass.pigeon_detached({ + this.pigeon_binaryMessenger, + Pigeon_InstanceManager? pigeon_instanceManager, + }) : pigeon_instanceManager = + pigeon_instanceManager ?? Pigeon_InstanceManager.instance; late final _ProxyApiSuperClassCodec _codecProxyApiSuperClass = - _ProxyApiSuperClassCodec($instanceManager); + _ProxyApiSuperClassCodec(pigeon_instanceManager); /// 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? $binaryMessenger; + final BinaryMessenger? pigeon_binaryMessenger; /// Maintains instances stored to communicate with native language objects. - final $InstanceManager $instanceManager; + final Pigeon_InstanceManager pigeon_instanceManager; - static void $setUpMessageHandlers({ - BinaryMessenger? $binaryMessenger, - $InstanceManager? $instanceManager, - ProxyApiSuperClass Function()? $detached, + static void pigeon_setUpMessageHandlers({ + BinaryMessenger? pigeon_binaryMessenger, + Pigeon_InstanceManager? pigeon_instanceManager, + ProxyApiSuperClass Function()? pigeon_detached, }) { final _ProxyApiSuperClassCodec pigeonChannelCodec = - _ProxyApiSuperClassCodec($instanceManager ?? $InstanceManager.instance); + _ProxyApiSuperClassCodec( + pigeon_instanceManager ?? Pigeon_InstanceManager.instance); { const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.$detached'; + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.pigeon_detached'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -7225,11 +7227,12 @@ class ProxyApiSuperClass implements $Copyable { instanceIdentifier != null, 'Argument for $__pigeon_channelName was null, expected non-null int.', ); - ($instanceManager ?? $InstanceManager.instance).addHostCreatedInstance( - $detached?.call() ?? - ProxyApiSuperClass.$detached( - $binaryMessenger: $binaryMessenger, - $instanceManager: $instanceManager, + (pigeon_instanceManager ?? Pigeon_InstanceManager.instance) + .addHostCreatedInstance( + pigeon_detached?.call() ?? + ProxyApiSuperClass.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, ), instanceIdentifier!, ); @@ -7245,7 +7248,7 @@ class ProxyApiSuperClass implements $Copyable { BasicMessageChannel( __pigeon_channelName, _codecProxyApiSuperClass, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = (await __pigeon_channel.send([this]) as List?); @@ -7263,10 +7266,10 @@ class ProxyApiSuperClass implements $Copyable { } @override - ProxyApiSuperClass $copy() { - return ProxyApiSuperClass.$detached( - $binaryMessenger: $binaryMessenger, - $instanceManager: $instanceManager, + ProxyApiSuperClass pigeon_copy() { + return ProxyApiSuperClass.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, ); } } @@ -7274,11 +7277,11 @@ class ProxyApiSuperClass implements $Copyable { class _ProxyApiInterfaceCodec extends StandardMessageCodec { const _ProxyApiInterfaceCodec(this.instanceManager); - final $InstanceManager instanceManager; + final Pigeon_InstanceManager instanceManager; @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is $Copyable) { + if (value is Pigeon_Copyable) { buffer.putUint8(128); writeValue(buffer, instanceManager.getIdentifier(value)); } else { @@ -7299,44 +7302,45 @@ class _ProxyApiInterfaceCodec extends StandardMessageCodec { } /// ProxyApi to serve as an interface to the core ProxyApi interface. -class ProxyApiInterface implements $Copyable { +class ProxyApiInterface implements Pigeon_Copyable { /// Constructs ProxyApiInterface without creating the associated native object. /// /// This should only be used by subclasses created by this library or to /// create copies. - ProxyApiInterface.$detached({ - this.$binaryMessenger, - $InstanceManager? $instanceManager, + ProxyApiInterface.pigeon_detached({ + this.pigeon_binaryMessenger, + Pigeon_InstanceManager? pigeon_instanceManager, this.anInterfaceMethod, - }) : $instanceManager = $instanceManager ?? $InstanceManager.instance; + }) : 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? $binaryMessenger; + final BinaryMessenger? pigeon_binaryMessenger; /// Maintains instances stored to communicate with native language objects. - final $InstanceManager $instanceManager; + final Pigeon_InstanceManager pigeon_instanceManager; final void Function(ProxyApiInterface instance)? anInterfaceMethod; - static void $setUpMessageHandlers({ - BinaryMessenger? $binaryMessenger, - $InstanceManager? $instanceManager, - ProxyApiInterface Function()? $detached, + static void pigeon_setUpMessageHandlers({ + BinaryMessenger? pigeon_binaryMessenger, + Pigeon_InstanceManager? pigeon_instanceManager, + ProxyApiInterface Function()? pigeon_detached, void Function(ProxyApiInterface instance)? anInterfaceMethod, }) { - final _ProxyApiInterfaceCodec pigeonChannelCodec = - _ProxyApiInterfaceCodec($instanceManager ?? $InstanceManager.instance); + final _ProxyApiInterfaceCodec pigeonChannelCodec = _ProxyApiInterfaceCodec( + pigeon_instanceManager ?? Pigeon_InstanceManager.instance); { const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.$detached'; + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.pigeon_detached'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -7349,11 +7353,12 @@ class ProxyApiInterface implements $Copyable { instanceIdentifier != null, 'Argument for $__pigeon_channelName was null, expected non-null int.', ); - ($instanceManager ?? $InstanceManager.instance).addHostCreatedInstance( - $detached?.call() ?? - ProxyApiInterface.$detached( - $binaryMessenger: $binaryMessenger, - $instanceManager: $instanceManager, + (pigeon_instanceManager ?? Pigeon_InstanceManager.instance) + .addHostCreatedInstance( + pigeon_detached?.call() ?? + ProxyApiInterface.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, ), instanceIdentifier!, ); @@ -7367,7 +7372,7 @@ class ProxyApiInterface implements $Copyable { BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, - binaryMessenger: $binaryMessenger, + binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.setMessageHandler((Object? message) async { assert( @@ -7395,10 +7400,10 @@ class ProxyApiInterface implements $Copyable { } @override - ProxyApiInterface $copy() { - return ProxyApiInterface.$detached( - $binaryMessenger: $binaryMessenger, - $instanceManager: $instanceManager, + 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/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; From 8572dbaa42ecb65c359206541623578d77a8c312 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 18 Dec 2023 20:22:36 -0500 Subject: [PATCH 41/73] add attached fields to core tests and make instance avoid collisions --- packages/pigeon/lib/dart_generator.dart | 12 ++-- packages/pigeon/pigeons/core_tests.dart | 6 ++ .../lib/src/generated/core_tests.gen.dart | 63 +++++++++++++++++++ 3 files changed, 76 insertions(+), 5 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index a269f32472b1..429256324d4e 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -1831,10 +1831,12 @@ class $codecName extends StandardMessageCodec { ..body = cb.Block.of( [ cb.Code( - 'final $type instance = $type.${classMemberNamePrefix}detached('), + 'final $type ${_varNamePrefix}instance = $type.${classMemberNamePrefix}detached('), if (!field.isStatic) ...[ - const cb.Code(r'$binaryMessenger: $binaryMessenger,'), - const cb.Code(r'$instanceManager: $instanceManager,'), + const cb.Code( + '${classMemberNamePrefix}binaryMessenger: ${classMemberNamePrefix}binaryMessenger,'), + const cb.Code( + '${classMemberNamePrefix}instanceManager: ${classMemberNamePrefix}instanceManager,'), ], const cb.Code(');'), cb.Code( @@ -1856,7 +1858,7 @@ class $codecName extends StandardMessageCodec { [ if (!field.isStatic) cb.refer('this'), cb.refer( - '${field.isStatic ? r'$InstanceManager.instance' : '${classMemberNamePrefix}instanceManager'}.addDartCreatedInstance(instance)', + '${field.isStatic ? '$instanceManagerClassName.instance' : '${classMemberNamePrefix}instanceManager'}.addDartCreatedInstance(${_varNamePrefix}instance)', ), ], cb.refer('Object?'), @@ -1912,7 +1914,7 @@ class $codecName extends StandardMessageCodec { [cb.refer('void')], ) .statement, - const cb.Code('return instance;'), + const cb.Code('return ${_varNamePrefix}instance;'), ], ); }, diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index 1a1656df33db..e2d4eb71e665 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -1074,6 +1074,12 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// ProxyApi to serve as a super class to the core ProxyApi interface. @ProxyApi() abstract class ProxyApiSuperClass { + @attached + late ProxyApiSuperClass attachedField; + + @static + late ProxyApiSuperClass staticAttachedField; + void aSuperMethod(); } 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 4878e2265bce..4c2dd97bc3d6 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 @@ -7199,6 +7199,10 @@ class ProxyApiSuperClass implements Pigeon_Copyable { /// Maintains instances stored to communicate with native language objects. final Pigeon_InstanceManager pigeon_instanceManager; + late final ProxyApiSuperClass attachedField = _attachedField(); + + static final ProxyApiSuperClass staticAttachedField = _staticAttachedField(); + static void pigeon_setUpMessageHandlers({ BinaryMessenger? pigeon_binaryMessenger, Pigeon_InstanceManager? pigeon_instanceManager, @@ -7241,6 +7245,65 @@ class ProxyApiSuperClass implements Pigeon_Copyable { } } + ProxyApiSuperClass _attachedField() { + final ProxyApiSuperClass __pigeon_instance = + ProxyApiSuperClass.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ); + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.attachedField'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyApiSuperClass, + binaryMessenger: pigeon_binaryMessenger, + ); + __pigeon_channel.send([ + this, + pigeon_instanceManager.addDartCreatedInstance(__pigeon_instance), + ]).then((Object? value) { + final List? __pigeon_replyList = value 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], + ); + } + }); + return __pigeon_instance; + } + + static ProxyApiSuperClass _staticAttachedField() { + final ProxyApiSuperClass __pigeon_instance = + ProxyApiSuperClass.pigeon_detached(); + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.staticAttachedField'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _ProxyApiSuperClassCodec(Pigeon_InstanceManager.instance), + ); + __pigeon_channel.send([ + Pigeon_InstanceManager.instance.addDartCreatedInstance(__pigeon_instance) + ]).then((Object? value) { + final List? __pigeon_replyList = value 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], + ); + } + }); + return __pigeon_instance; + } + Future aSuperMethod() async { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.aSuperMethod'; From fd144c5de1b1c1701c9c3c30df970bffa310e9cf Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 18 Dec 2023 20:39:44 -0500 Subject: [PATCH 42/73] fix lists and maps with proxy apis --- packages/pigeon/lib/pigeon_lib.dart | 4 + packages/pigeon/pigeons/core_tests.dart | 30 ++ .../lib/src/generated/core_tests.gen.dart | 257 ++++++++++++++++++ 3 files changed, 291 insertions(+) diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 861360d0bb9a..885e01cce6d3 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -1161,6 +1161,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' && diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index e2d4eb71e665..06f96360744c 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -788,10 +788,20 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// 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; @@ -872,9 +882,21 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// 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); @@ -1038,9 +1060,17 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass @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); 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 4c2dd97bc3d6..147f7d67db3c 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 @@ -3810,7 +3810,9 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass this.flutterEchoString, this.flutterEchoUint8List, this.flutterEchoList, + this.flutterEchoProxyApiList, this.flutterEchoMap, + this.flutterEchoProxyApiMap, this.flutterEchoEnum, this.flutterEchoNullableBool, this.flutterEchoNullableInt, @@ -3928,7 +3930,9 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass this.flutterEchoString, this.flutterEchoUint8List, this.flutterEchoList, + this.flutterEchoProxyApiList, this.flutterEchoMap, + this.flutterEchoProxyApiMap, this.flutterEchoEnum, this.flutterEchoNullableBool, this.flutterEchoNullableInt, @@ -4024,12 +4028,26 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass List aList, )? flutterEchoList; + /// Returns the passed list with ProxyApis, to test serialization and + /// deserialization. + final List Function( + ProxyIntegrationCoreApi instance, + List aList, + )? flutterEchoProxyApiList; + /// Returns the passed map, to test serialization and deserialization. final Map Function( ProxyIntegrationCoreApi instance, Map aMap, )? flutterEchoMap; + /// Returns the passed map with ProxyApis, to test serialization and + /// deserialization. + final Map Function( + ProxyIntegrationCoreApi instance, + Map aMap, + )? flutterEchoProxyApiMap; + /// Returns the passed enum to test serialization and deserialization. final AnEnum Function( ProxyIntegrationCoreApi instance, @@ -4146,10 +4164,18 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass ProxyIntegrationCoreApi instance, List aList, )? flutterEchoList, + List Function( + ProxyIntegrationCoreApi instance, + List aList, + )? flutterEchoProxyApiList, Map Function( ProxyIntegrationCoreApi instance, Map aMap, )? flutterEchoMap, + Map Function( + ProxyIntegrationCoreApi instance, + Map aMap, + )? flutterEchoProxyApiMap, AnEnum Function( ProxyIntegrationCoreApi instance, AnEnum anEnum, @@ -4670,6 +4696,50 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } }); } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoProxyApiList'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: pigeon_binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final List? arg_aList = + (args[1] as List?)?.cast(); + assert( + arg_aList != null, + 'Argument for $__pigeon_channelName was null, expected non-null List.', + ); + try { + final List? output = + (flutterEchoProxyApiList ?? instance!.flutterEchoProxyApiList) + ?.call( + 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()), + ); + } + }); + } { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoMap'; @@ -4713,6 +4783,51 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } }); } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoProxyApiMap'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: pigeon_binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final Map? arg_aMap = + (args[1] as Map?) + ?.cast(); + assert( + arg_aMap != null, + 'Argument for $__pigeon_channelName was null, expected non-null Map.', + ); + try { + final Map? output = + (flutterEchoProxyApiMap ?? instance!.flutterEchoProxyApiMap) + ?.call( + 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()), + ); + } + }); + } { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoEnum'; @@ -5482,6 +5597,42 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } } + /// Returns the passed list with ProxyApis, to test serialization and + /// deserialization. + Future> echoProxyApiList( + List aList) async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoProxyApiList'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + 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 { const String __pigeon_channelName = @@ -5516,6 +5667,42 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } } + /// Returns the passed map with ProxyApis, to test serialization and + /// deserialization. + Future> echoProxyApiMap( + Map aMap) async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoProxyApiMap'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + 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 { const String __pigeon_channelName = @@ -6814,6 +7001,40 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } } + Future> callFlutterEchoProxyApiList( + List aList) async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoProxyApiList'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + 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 { const String __pigeon_channelName = @@ -6848,6 +7069,40 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } } + Future> callFlutterEchoProxyApiMap( + Map aMap) async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoProxyApiMap'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _codecProxyIntegrationCoreApi, + 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 { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoEnum'; @@ -7132,7 +7387,9 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass flutterEchoString: flutterEchoString, flutterEchoUint8List: flutterEchoUint8List, flutterEchoList: flutterEchoList, + flutterEchoProxyApiList: flutterEchoProxyApiList, flutterEchoMap: flutterEchoMap, + flutterEchoProxyApiMap: flutterEchoProxyApiMap, flutterEchoEnum: flutterEchoEnum, flutterEchoNullableBool: flutterEchoNullableBool, flutterEchoNullableInt: flutterEchoNullableInt, From 7c490578ecde85d790381203f1a410a11d1f6978 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 18 Dec 2023 20:59:53 -0500 Subject: [PATCH 43/73] test dart instance manager --- .../test/instance_manager_test.dart | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 packages/pigeon/platform_tests/shared_test_plugin_code/test/instance_manager_test.dart 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..22a4a7785062 --- /dev/null +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/test/instance_manager_test.dart @@ -0,0 +1,146 @@ +// 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/core_tests.gen.dart'; + +void main() { + group('InstanceManager', () { + test('addHostCreatedInstance', () { + final CopyableObject object = CopyableObject(); + + final Pigeon_InstanceManager instanceManager = + Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + + instanceManager.addHostCreatedInstance(object, 0); + + expect(instanceManager.getIdentifier(object), 0); + expect( + instanceManager.getInstanceWithWeakReference(0), + object, + ); + }); + + test('addHostCreatedInstance prevents already used objects and ids', () { + final CopyableObject object = CopyableObject(); + + final Pigeon_InstanceManager instanceManager = + Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + + instanceManager.addHostCreatedInstance(object, 0); + + expect( + () => instanceManager.addHostCreatedInstance(object, 0), + throwsAssertionError, + ); + + expect( + () => instanceManager.addHostCreatedInstance(CopyableObject(), 0), + throwsAssertionError, + ); + }); + + test('addFlutterCreatedInstance', () { + final CopyableObject object = CopyableObject(); + + final Pigeon_InstanceManager instanceManager = + Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + + instanceManager.addDartCreatedInstance(object); + + final int? instanceId = instanceManager.getIdentifier(object); + expect(instanceId, isNotNull); + expect( + instanceManager.getInstanceWithWeakReference(instanceId!), + object, + ); + }); + + test('removeWeakReference', () { + final CopyableObject object = CopyableObject(); + + int? weakInstanceId; + final Pigeon_InstanceManager instanceManager = + Pigeon_InstanceManager(onWeakReferenceRemoved: (int instanceId) { + weakInstanceId = instanceId; + }); + + instanceManager.addHostCreatedInstance(object, 0); + + expect(instanceManager.removeWeakReference(object), 0); + expect( + instanceManager.getInstanceWithWeakReference(0), + isA(), + ); + expect(weakInstanceId, 0); + }); + + test('removeWeakReference removes only weak reference', () { + final CopyableObject object = CopyableObject(); + + final Pigeon_InstanceManager instanceManager = + Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + + instanceManager.addHostCreatedInstance(object, 0); + + expect(instanceManager.removeWeakReference(object), 0); + final CopyableObject copy = instanceManager.getInstanceWithWeakReference( + 0, + )!; + expect(identical(object, copy), isFalse); + }); + + test('removeStrongReference', () { + final CopyableObject object = CopyableObject(); + + final Pigeon_InstanceManager instanceManager = + Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + + instanceManager.addHostCreatedInstance(object, 0); + instanceManager.removeWeakReference(object); + expect(instanceManager.remove(0), isA()); + expect(instanceManager.containsIdentifier(0), isFalse); + }); + + test('removeStrongReference removes only strong reference', () { + final CopyableObject object = CopyableObject(); + + final Pigeon_InstanceManager instanceManager = + Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + + instanceManager.addHostCreatedInstance(object, 0); + expect(instanceManager.remove(0), isA()); + expect( + instanceManager.getInstanceWithWeakReference(0), + object, + ); + }); + + test('getInstance can add a new weak reference', () { + final CopyableObject object = CopyableObject(); + + final Pigeon_InstanceManager instanceManager = + Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + + instanceManager.addHostCreatedInstance(object, 0); + instanceManager.removeWeakReference(object); + + final CopyableObject newWeakCopy = + instanceManager.getInstanceWithWeakReference( + 0, + )!; + expect(identical(object, newWeakCopy), isFalse); + }); + }); +} + +class CopyableObject with Pigeon_Copyable { + @override + // ignore: non_constant_identifier_names + CopyableObject pigeon_copy() { + return CopyableObject(); + } +} From f8f460aadef2814a3258350698a1bc08827ecb02 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 18 Dec 2023 21:05:56 -0500 Subject: [PATCH 44/73] use prefix for attached fields --- packages/pigeon/lib/dart_generator.dart | 4 ++-- .../lib/src/generated/core_tests.gen.dart | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 429256324d4e..3503a68fa2dc 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -1477,7 +1477,7 @@ class $codecName extends StandardMessageCodec { field.documentationComments, _docCommentSpec, )) - ..assignment = cb.Code('_${field.name}()'), + ..assignment = cb.Code('$_varNamePrefix${field.name}()'), ), ]; } @@ -1825,7 +1825,7 @@ class $codecName extends StandardMessageCodec { dartPackageName: dartPackageName, ); builder - ..name = '_${field.name}' + ..name = '$_varNamePrefix${field.name}' ..static = field.isStatic ..returns = cb.refer(type) ..body = cb.Block.of( 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 147f7d67db3c..f733c2bf0d4e 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 @@ -7456,9 +7456,10 @@ class ProxyApiSuperClass implements Pigeon_Copyable { /// Maintains instances stored to communicate with native language objects. final Pigeon_InstanceManager pigeon_instanceManager; - late final ProxyApiSuperClass attachedField = _attachedField(); + late final ProxyApiSuperClass attachedField = __pigeon_attachedField(); - static final ProxyApiSuperClass staticAttachedField = _staticAttachedField(); + static final ProxyApiSuperClass staticAttachedField = + __pigeon_staticAttachedField(); static void pigeon_setUpMessageHandlers({ BinaryMessenger? pigeon_binaryMessenger, @@ -7502,7 +7503,7 @@ class ProxyApiSuperClass implements Pigeon_Copyable { } } - ProxyApiSuperClass _attachedField() { + ProxyApiSuperClass __pigeon_attachedField() { final ProxyApiSuperClass __pigeon_instance = ProxyApiSuperClass.pigeon_detached( pigeon_binaryMessenger: pigeon_binaryMessenger, @@ -7534,7 +7535,7 @@ class ProxyApiSuperClass implements Pigeon_Copyable { return __pigeon_instance; } - static ProxyApiSuperClass _staticAttachedField() { + static ProxyApiSuperClass __pigeon_staticAttachedField() { final ProxyApiSuperClass __pigeon_instance = ProxyApiSuperClass.pigeon_detached(); const String __pigeon_channelName = From 66af2985f0b2986425ef80a688ab45b5b08ab0b4 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 20 Dec 2023 00:15:10 -0500 Subject: [PATCH 45/73] validate naming and change private codec instance name --- packages/pigeon/lib/dart_generator.dart | 6 +- packages/pigeon/lib/pigeon_lib.dart | 52 +++++++ .../lib/src/generated/core_tests.gen.dart | 145 +++++++++--------- 3 files changed, 128 insertions(+), 75 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index f1349103750e..57fdcf7e09e4 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -959,7 +959,7 @@ class _$apiName { required String dartPackageName, }) { final String codecName = _getCodecName(api); - final String codecInstanceName = '_codec${api.name}'; + final String codecInstanceName = '${_varNamePrefix}codec${api.name}'; // codec indent.writeln(''' @@ -1844,7 +1844,7 @@ class $codecName extends StandardMessageCodec { ), _basicMessageChannel( codec: !field.isStatic - ? cb.refer('_codec$apiName') + ? cb.refer(codecInstanceName) : cb.refer( '$codecName($instanceManagerClassName.instance)'), binaryMessenger: !field.isStatic @@ -1969,7 +1969,7 @@ class $codecName extends StandardMessageCodec { ), _basicMessageChannel( codec: !method.isStatic - ? cb.refer('_codec$apiName') + ? cb.refer(codecInstanceName) : cb.refer( '$codecName(${classMemberNamePrefix}instanceManager ?? $instanceManagerClassName.instance)', ), diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index fa9065eba508..18cd3f347fae 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -1053,6 +1053,18 @@ List _validateProxyApi( '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) { @@ -1074,6 +1086,20 @@ List _validateProxyApi( 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) { @@ -1103,6 +1129,32 @@ 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)) { + result.add(Error( + message: + 'Field name must not begin with "$classMemberNamePrefix" in API: "${api.name}"', + lineNumber: _calculateLineNumberNullable(source, field.offset), + )); + } } return result; 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 f733c2bf0d4e..3729ae6caaf3 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 @@ -3846,7 +3846,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.send([ @@ -3946,7 +3946,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass this.callFlutterEchoAsyncString, }) : super.pigeon_detached(); - late final _ProxyIntegrationCoreApiCodec _codecProxyIntegrationCoreApi = + late final _ProxyIntegrationCoreApiCodec + __pigeon_codecProxyIntegrationCoreApi = _ProxyIntegrationCoreApiCodec(pigeon_instanceManager); final bool aBool; @@ -5273,7 +5274,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5298,7 +5299,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5323,7 +5324,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5348,7 +5349,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5373,7 +5374,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5406,7 +5407,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5439,7 +5440,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5472,7 +5473,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5505,7 +5506,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5538,7 +5539,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5571,7 +5572,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5606,7 +5607,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5640,7 +5641,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5676,7 +5677,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5710,7 +5711,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5743,7 +5744,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5771,7 +5772,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5799,7 +5800,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5827,7 +5828,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5856,7 +5857,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5884,7 +5885,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5912,7 +5913,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5941,7 +5942,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -5969,7 +5970,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6000,7 +6001,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6025,7 +6026,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6058,7 +6059,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6091,7 +6092,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6124,7 +6125,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6157,7 +6158,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6190,7 +6191,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6223,7 +6224,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6256,7 +6257,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6290,7 +6291,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6323,7 +6324,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6348,7 +6349,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6373,7 +6374,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6398,7 +6399,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6426,7 +6427,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6454,7 +6455,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6482,7 +6483,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6510,7 +6511,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6538,7 +6539,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6566,7 +6567,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6595,7 +6596,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6624,7 +6625,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6743,7 +6744,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6767,7 +6768,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6791,7 +6792,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6815,7 +6816,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6847,7 +6848,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6879,7 +6880,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6911,7 +6912,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6943,7 +6944,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -6975,7 +6976,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -7008,7 +7009,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -7042,7 +7043,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -7076,7 +7077,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -7109,7 +7110,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -7141,7 +7142,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -7168,7 +7169,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -7195,7 +7196,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -7222,7 +7223,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -7249,7 +7250,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -7277,7 +7278,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -7305,7 +7306,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -7333,7 +7334,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyIntegrationCoreApi, + __pigeon_codecProxyIntegrationCoreApi, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = @@ -7444,7 +7445,7 @@ class ProxyApiSuperClass implements Pigeon_Copyable { }) : pigeon_instanceManager = pigeon_instanceManager ?? Pigeon_InstanceManager.instance; - late final _ProxyApiSuperClassCodec _codecProxyApiSuperClass = + late final _ProxyApiSuperClassCodec __pigeon_codecProxyApiSuperClass = _ProxyApiSuperClassCodec(pigeon_instanceManager); /// Sends and receives binary data across the Flutter platform barrier. @@ -7514,7 +7515,7 @@ class ProxyApiSuperClass implements Pigeon_Copyable { final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyApiSuperClass, + __pigeon_codecProxyApiSuperClass, binaryMessenger: pigeon_binaryMessenger, ); __pigeon_channel.send([ @@ -7568,7 +7569,7 @@ class ProxyApiSuperClass implements Pigeon_Copyable { final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _codecProxyApiSuperClass, + __pigeon_codecProxyApiSuperClass, binaryMessenger: pigeon_binaryMessenger, ); final List? __pigeon_replyList = From 5d4cc54367b663ff6c4ef97943534a5fd8be7b2b Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 20 Dec 2023 12:46:27 -0500 Subject: [PATCH 46/73] make a base codec and move attached fields to main class --- packages/pigeon/lib/dart_generator.dart | 22 +- packages/pigeon/lib/generator.dart | 9 + packages/pigeon/pigeons/core_tests.dart | 12 +- .../lib/src/generated/core_tests.gen.dart | 264 +++++++----------- 4 files changed, 135 insertions(+), 172 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 57fdcf7e09e4..ce948b955076 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -951,17 +951,13 @@ class _$apiName { } @override - void writeProxyApi( + void writeProxyApiBaseCodec( DartOptions generatorOptions, Root root, Indent indent, - AstProxyApi api, { - required String dartPackageName, - }) { - final String codecName = _getCodecName(api); - final String codecInstanceName = '${_varNamePrefix}codec${api.name}'; + ) { + const String codecName = '_${classNamePrefix}ProxyApiBaseCodec'; - // codec indent.writeln(''' class $codecName extends StandardMessageCodec { const $codecName(this.instanceManager); @@ -990,6 +986,18 @@ class $codecName extends StandardMessageCodec { } } '''); + } + + @override + void writeProxyApi( + DartOptions generatorOptions, + Root root, + Indent indent, + AstProxyApi api, { + required String dartPackageName, + }) { + const String codecName = '_${classNamePrefix}ProxyApiBaseCodec'; + final String codecInstanceName = '${_varNamePrefix}codec${api.name}'; final Iterable allProxyApis = root.apis.whereType(); diff --git a/packages/pigeon/lib/generator.dart b/packages/pigeon/lib/generator.dart index 1f48724012eb..687421c0b54d 100644 --- a/packages/pigeon/lib/generator.dart +++ b/packages/pigeon/lib/generator.dart @@ -77,6 +77,8 @@ abstract class StructuredGenerator extends Generator { indent, dartPackageName: dartPackageName, ); + + writeProxyApiBaseCodec(generatorOptions, root, indent); } writeEnums( @@ -304,6 +306,13 @@ abstract class StructuredGenerator extends Generator { required String dartPackageName, }) {} + /// Writes the base codec to be used by ProxyApis. + void writeProxyApiBaseCodec( + T generatorOptions, + Root root, + Indent indent, + ) {} + /// Writes a single Proxy Api to [indent]. void writeProxyApi( T generatorOptions, diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index 06f96360744c..87a65268e632 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -758,6 +758,12 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass late Map? aNullableMap; late AnEnum? aNullableEnum; + @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; @@ -1104,12 +1110,6 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// ProxyApi to serve as a super class to the core ProxyApi interface. @ProxyApi() abstract class ProxyApiSuperClass { - @attached - late ProxyApiSuperClass attachedField; - - @static - late ProxyApiSuperClass staticAttachedField; - void aSuperMethod(); } 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 3729ae6caaf3..fdf9369baef6 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 @@ -333,6 +333,33 @@ class _Pigeon_InstanceManagerApi { } } +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_Copyable) { + 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, @@ -3750,33 +3777,6 @@ abstract class FlutterSmallApi { } } -class _ProxyIntegrationCoreApiCodec extends StandardMessageCodec { - const _ProxyIntegrationCoreApiCodec(this.instanceManager); - - final Pigeon_InstanceManager instanceManager; - - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is Pigeon_Copyable) { - 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); - } - } -} - /// The core interface that each host language plugin must implement in /// platform_test integration tests. class ProxyIntegrationCoreApi extends ProxyApiSuperClass @@ -3946,9 +3946,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass this.callFlutterEchoAsyncString, }) : super.pigeon_detached(); - late final _ProxyIntegrationCoreApiCodec - __pigeon_codecProxyIntegrationCoreApi = - _ProxyIntegrationCoreApiCodec(pigeon_instanceManager); + late final _Pigeon_ProxyApiBaseCodec __pigeon_codecProxyIntegrationCoreApi = + _Pigeon_ProxyApiBaseCodec(pigeon_instanceManager); final bool aBool; @@ -4117,6 +4116,11 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass @override final void Function(ProxyApiInterface instance)? anInterfaceMethod; + late final ProxyApiSuperClass attachedField = __pigeon_attachedField(); + + static final ProxyApiSuperClass staticAttachedField = + __pigeon_staticAttachedField(); + static void pigeon_setUpMessageHandlers({ BinaryMessenger? pigeon_binaryMessenger, Pigeon_InstanceManager? pigeon_instanceManager, @@ -4220,8 +4224,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass String aString, )? callFlutterEchoAsyncString, }) { - final _ProxyIntegrationCoreApiCodec pigeonChannelCodec = - _ProxyIntegrationCoreApiCodec( + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + _Pigeon_ProxyApiBaseCodec( pigeon_instanceManager ?? Pigeon_InstanceManager.instance); { const String __pigeon_channelName = @@ -5266,6 +5270,65 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } } + ProxyApiSuperClass __pigeon_attachedField() { + final ProxyApiSuperClass __pigeon_instance = + ProxyApiSuperClass.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ); + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.attachedField'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + __pigeon_codecProxyIntegrationCoreApi, + binaryMessenger: pigeon_binaryMessenger, + ); + __pigeon_channel.send([ + this, + pigeon_instanceManager.addDartCreatedInstance(__pigeon_instance), + ]).then((Object? value) { + final List? __pigeon_replyList = value 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], + ); + } + }); + return __pigeon_instance; + } + + static ProxyApiSuperClass __pigeon_staticAttachedField() { + final ProxyApiSuperClass __pigeon_instance = + ProxyApiSuperClass.pigeon_detached(); + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.staticAttachedField'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + _Pigeon_ProxyApiBaseCodec(Pigeon_InstanceManager.instance), + ); + __pigeon_channel.send([ + Pigeon_InstanceManager.instance.addDartCreatedInstance(__pigeon_instance) + ]).then((Object? value) { + final List? __pigeon_replyList = value 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], + ); + } + }); + return __pigeon_instance; + } + /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. Future noop() async { @@ -6657,7 +6720,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _ProxyIntegrationCoreApiCodec( + _Pigeon_ProxyApiBaseCodec( pigeon_instanceManager ?? Pigeon_InstanceManager.instance), binaryMessenger: pigeon_binaryMessenger, ); @@ -6686,7 +6749,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _ProxyIntegrationCoreApiCodec( + _Pigeon_ProxyApiBaseCodec( pigeon_instanceManager ?? Pigeon_InstanceManager.instance), binaryMessenger: pigeon_binaryMessenger, ); @@ -6719,7 +6782,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _ProxyIntegrationCoreApiCodec( + _Pigeon_ProxyApiBaseCodec( pigeon_instanceManager ?? Pigeon_InstanceManager.instance), binaryMessenger: pigeon_binaryMessenger, ); @@ -7406,33 +7469,6 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } } -class _ProxyApiSuperClassCodec extends StandardMessageCodec { - const _ProxyApiSuperClassCodec(this.instanceManager); - - final Pigeon_InstanceManager instanceManager; - - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is Pigeon_Copyable) { - 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); - } - } -} - /// ProxyApi to serve as a super class to the core ProxyApi interface. class ProxyApiSuperClass implements Pigeon_Copyable { /// Constructs ProxyApiSuperClass without creating the associated native object. @@ -7445,8 +7481,8 @@ class ProxyApiSuperClass implements Pigeon_Copyable { }) : pigeon_instanceManager = pigeon_instanceManager ?? Pigeon_InstanceManager.instance; - late final _ProxyApiSuperClassCodec __pigeon_codecProxyApiSuperClass = - _ProxyApiSuperClassCodec(pigeon_instanceManager); + late final _Pigeon_ProxyApiBaseCodec __pigeon_codecProxyApiSuperClass = + _Pigeon_ProxyApiBaseCodec(pigeon_instanceManager); /// Sends and receives binary data across the Flutter platform barrier. /// @@ -7457,18 +7493,13 @@ class ProxyApiSuperClass implements Pigeon_Copyable { /// Maintains instances stored to communicate with native language objects. final Pigeon_InstanceManager pigeon_instanceManager; - late final ProxyApiSuperClass attachedField = __pigeon_attachedField(); - - static final ProxyApiSuperClass staticAttachedField = - __pigeon_staticAttachedField(); - static void pigeon_setUpMessageHandlers({ BinaryMessenger? pigeon_binaryMessenger, Pigeon_InstanceManager? pigeon_instanceManager, ProxyApiSuperClass Function()? pigeon_detached, }) { - final _ProxyApiSuperClassCodec pigeonChannelCodec = - _ProxyApiSuperClassCodec( + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + _Pigeon_ProxyApiBaseCodec( pigeon_instanceManager ?? Pigeon_InstanceManager.instance); { const String __pigeon_channelName = @@ -7504,65 +7535,6 @@ class ProxyApiSuperClass implements Pigeon_Copyable { } } - ProxyApiSuperClass __pigeon_attachedField() { - final ProxyApiSuperClass __pigeon_instance = - ProxyApiSuperClass.pigeon_detached( - pigeon_binaryMessenger: pigeon_binaryMessenger, - pigeon_instanceManager: pigeon_instanceManager, - ); - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.attachedField'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - __pigeon_codecProxyApiSuperClass, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.send([ - this, - pigeon_instanceManager.addDartCreatedInstance(__pigeon_instance), - ]).then((Object? value) { - final List? __pigeon_replyList = value 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], - ); - } - }); - return __pigeon_instance; - } - - static ProxyApiSuperClass __pigeon_staticAttachedField() { - final ProxyApiSuperClass __pigeon_instance = - ProxyApiSuperClass.pigeon_detached(); - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.staticAttachedField'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - _ProxyApiSuperClassCodec(Pigeon_InstanceManager.instance), - ); - __pigeon_channel.send([ - Pigeon_InstanceManager.instance.addDartCreatedInstance(__pigeon_instance) - ]).then((Object? value) { - final List? __pigeon_replyList = value 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], - ); - } - }); - return __pigeon_instance; - } - Future aSuperMethod() async { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.aSuperMethod'; @@ -7596,33 +7568,6 @@ class ProxyApiSuperClass implements Pigeon_Copyable { } } -class _ProxyApiInterfaceCodec extends StandardMessageCodec { - const _ProxyApiInterfaceCodec(this.instanceManager); - - final Pigeon_InstanceManager instanceManager; - - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is Pigeon_Copyable) { - 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); - } - } -} - /// ProxyApi to serve as an interface to the core ProxyApi interface. class ProxyApiInterface implements Pigeon_Copyable { /// Constructs ProxyApiInterface without creating the associated native object. @@ -7653,8 +7598,9 @@ class ProxyApiInterface implements Pigeon_Copyable { ProxyApiInterface Function()? pigeon_detached, void Function(ProxyApiInterface instance)? anInterfaceMethod, }) { - final _ProxyApiInterfaceCodec pigeonChannelCodec = _ProxyApiInterfaceCodec( - pigeon_instanceManager ?? Pigeon_InstanceManager.instance); + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + _Pigeon_ProxyApiBaseCodec( + pigeon_instanceManager ?? Pigeon_InstanceManager.instance); { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.pigeon_detached'; From eb72b385d5d69c110b0143e80497275828c5c8fa Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 20 Dec 2023 12:50:22 -0500 Subject: [PATCH 47/73] fix unit test --- packages/pigeon/test/dart_generator_test.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/pigeon/test/dart_generator_test.dart b/packages/pigeon/test/dart_generator_test.dart index 227668bb64e1..1678b8e9afeb 100644 --- a/packages/pigeon/test/dart_generator_test.dart +++ b/packages/pigeon/test/dart_generator_test.dart @@ -1445,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( From 50fc804794cf7f83275850d81d8ad355dde991a4 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 20 Dec 2023 19:20:28 -0500 Subject: [PATCH 48/73] fix version error --- packages/pigeon/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index e0625284c84a..519870f31ad9 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: 15.0.2 # This must match the version in lib/generator_tools.dart +version: 15.0.3 # This must match the version in lib/generator_tools.dart environment: sdk: ">=3.0.0 <4.0.0" From fbe7c5b623269600477e63bb9274b5456cdd3ed6 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 20 Dec 2023 22:28:10 -0500 Subject: [PATCH 49/73] fix test and make instance avoid collisions --- packages/pigeon/lib/dart_generator.dart | 4 +- .../lib/src/generated/core_tests.gen.dart | 99 ++++++++++--------- packages/pigeon/test/dart_generator_test.dart | 61 ++++++------ 3 files changed, 84 insertions(+), 80 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index ce948b955076..4ea34a3c2639 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -1435,7 +1435,7 @@ class $codecName extends StandardMessageCodec { ) ..isNullable = !method.required ..requiredParameters.addAll([ - cb.refer('$apiName instance'), + cb.refer('$apiName ${classMemberNamePrefix}instance'), ...method.parameters.mapIndexed( (int index, NamedType parameter) { return cb.refer( @@ -1554,7 +1554,7 @@ class $codecName extends StandardMessageCodec { ) ..isNullable = true ..requiredParameters.addAll([ - cb.refer('$apiName instance'), + cb.refer('$apiName ${classMemberNamePrefix}instance'), ...method.parameters.mapIndexed( (int index, NamedType parameter) { return cb.refer( 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 fdf9369baef6..6ce87f5f8adb 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 @@ -3983,133 +3983,134 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. - final void Function(ProxyIntegrationCoreApi instance)? flutterNoop; + final void Function(ProxyIntegrationCoreApi pigeon_instance)? flutterNoop; /// Responds with an error from an async function returning a value. - final Object? Function(ProxyIntegrationCoreApi instance)? flutterThrowError; + final Object? Function(ProxyIntegrationCoreApi pigeon_instance)? + flutterThrowError; /// Responds with an error from an async void function. - final void Function(ProxyIntegrationCoreApi instance)? + final void Function(ProxyIntegrationCoreApi pigeon_instance)? flutterThrowErrorFromVoid; /// Returns the passed boolean, to test serialization and deserialization. final bool Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, bool aBool, )? flutterEchoBool; /// Returns the passed int, to test serialization and deserialization. final int Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, int anInt, )? flutterEchoInt; /// Returns the passed double, to test serialization and deserialization. final double Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, double aDouble, )? flutterEchoDouble; /// Returns the passed string, to test serialization and deserialization. final String Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, String aString, )? flutterEchoString; /// Returns the passed byte list, to test serialization and deserialization. final Uint8List Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, Uint8List aList, )? flutterEchoUint8List; /// Returns the passed list, to test serialization and deserialization. final List Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, List aList, )? flutterEchoList; /// Returns the passed list with ProxyApis, to test serialization and /// deserialization. final List Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, List aList, )? flutterEchoProxyApiList; /// Returns the passed map, to test serialization and deserialization. final Map Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, Map aMap, )? flutterEchoMap; /// Returns the passed map with ProxyApis, to test serialization and /// deserialization. final Map Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, Map aMap, )? flutterEchoProxyApiMap; /// Returns the passed enum to test serialization and deserialization. final AnEnum Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, AnEnum anEnum, )? flutterEchoEnum; /// Returns the passed boolean, to test serialization and deserialization. final bool? Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, bool? aBool, )? flutterEchoNullableBool; /// Returns the passed int, to test serialization and deserialization. final int? Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, int? anInt, )? flutterEchoNullableInt; /// Returns the passed double, to test serialization and deserialization. final double? Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, double? aDouble, )? flutterEchoNullableDouble; /// Returns the passed string, to test serialization and deserialization. final String? Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, String? aString, )? flutterEchoNullableString; /// Returns the passed byte list, to test serialization and deserialization. final Uint8List? Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, Uint8List? aList, )? flutterEchoNullableUint8List; /// Returns the passed list, to test serialization and deserialization. final List? Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, List? aList, )? flutterEchoNullableList; /// Returns the passed map, to test serialization and deserialization. final Map? Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, Map? aMap, )? flutterEchoNullableMap; /// Returns the passed enum to test serialization and deserialization. final AnEnum? Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, AnEnum? anEnum, )? flutterEchoNullableEnum; /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. - final Future Function(ProxyIntegrationCoreApi instance)? + final Future Function(ProxyIntegrationCoreApi pigeon_instance)? callFlutterNoopAsync; /// Returns the passed in generic Object asynchronously. final Future Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, String aString, )? callFlutterEchoAsyncString; @@ -4142,85 +4143,87 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass Map? aNullableMap, AnEnum? aNullableEnum, )? pigeon_detached, - void Function(ProxyIntegrationCoreApi instance)? flutterNoop, - Object? Function(ProxyIntegrationCoreApi instance)? flutterThrowError, - void Function(ProxyIntegrationCoreApi instance)? flutterThrowErrorFromVoid, + void Function(ProxyIntegrationCoreApi pigeon_instance)? flutterNoop, + Object? Function(ProxyIntegrationCoreApi pigeon_instance)? + flutterThrowError, + void Function(ProxyIntegrationCoreApi pigeon_instance)? + flutterThrowErrorFromVoid, bool Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, bool aBool, )? flutterEchoBool, int Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, int anInt, )? flutterEchoInt, double Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, double aDouble, )? flutterEchoDouble, String Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, String aString, )? flutterEchoString, Uint8List Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, Uint8List aList, )? flutterEchoUint8List, List Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, List aList, )? flutterEchoList, List Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, List aList, )? flutterEchoProxyApiList, Map Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, Map aMap, )? flutterEchoMap, Map Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, Map aMap, )? flutterEchoProxyApiMap, AnEnum Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, AnEnum anEnum, )? flutterEchoEnum, bool? Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, bool? aBool, )? flutterEchoNullableBool, int? Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, int? anInt, )? flutterEchoNullableInt, double? Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, double? aDouble, )? flutterEchoNullableDouble, String? Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, String? aString, )? flutterEchoNullableString, Uint8List? Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, Uint8List? aList, )? flutterEchoNullableUint8List, List? Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, List? aList, )? flutterEchoNullableList, Map? Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, Map? aMap, )? flutterEchoNullableMap, AnEnum? Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, AnEnum? anEnum, )? flutterEchoNullableEnum, - Future Function(ProxyIntegrationCoreApi instance)? + Future Function(ProxyIntegrationCoreApi pigeon_instance)? callFlutterNoopAsync, Future Function( - ProxyIntegrationCoreApi instance, + ProxyIntegrationCoreApi pigeon_instance, String aString, )? callFlutterEchoAsyncString, }) { @@ -7590,13 +7593,13 @@ class ProxyApiInterface implements Pigeon_Copyable { /// Maintains instances stored to communicate with native language objects. final Pigeon_InstanceManager pigeon_instanceManager; - final void Function(ProxyApiInterface instance)? anInterfaceMethod; + final void Function(ProxyApiInterface pigeon_instance)? anInterfaceMethod; static void pigeon_setUpMessageHandlers({ BinaryMessenger? pigeon_binaryMessenger, Pigeon_InstanceManager? pigeon_instanceManager, ProxyApiInterface Function()? pigeon_detached, - void Function(ProxyApiInterface instance)? anInterfaceMethod, + void Function(ProxyApiInterface pigeon_instance)? anInterfaceMethod, }) { final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = _Pigeon_ProxyApiBaseCodec( diff --git a/packages/pigeon/test/dart_generator_test.dart b/packages/pigeon/test/dart_generator_test.dart index 1678b8e9afeb..4b9aeb9eb226 100644 --- a/packages/pigeon/test/dart_generator_test.dart +++ b/packages/pigeon/test/dart_generator_test.dart @@ -1845,24 +1845,24 @@ name: foobar final String collapsedCode = _collapseNewlineAndIndentation(code); // Instance Manager - expect(code, contains(r'class $InstanceManager')); - expect(code, contains(r'class _InstanceManagerApi')); + expect(code, contains(r'class Pigeon_InstanceManager')); + expect(code, contains(r'class _Pigeon_InstanceManagerApi')); // Codec and class - expect(code, contains('class _ApiCodec')); - expect(code, contains(r'class Api implements $Copyable')); + expect(code, contains('class _Pigeon_ProxyApiBaseCodec')); + expect(code, contains(r'class Api implements Pigeon_Copyable')); // Constructors expect( collapsedCode, contains( - r'Api.name({ this.$binaryMessenger, $InstanceManager? $instanceManager, required this.someField, this.doSomethingElse, required Input input, })', + r'Api.name({ this.pigeon_binaryMessenger, Pigeon_InstanceManager? pigeon_instanceManager, required this.someField, this.doSomethingElse, required Input input, })', ), ); expect( code, contains( - r'Api.$detached', + r'Api.pigeon_detached', ), ); @@ -1873,16 +1873,16 @@ name: foobar expect(code, contains('Future doSomething(Input input)')); // Host -> Dart method - expect(code, contains(r'static void $setUpMessageHandlers({')); + expect(code, contains(r'static void pigeon_setUpMessageHandlers({')); expect( collapsedCode, contains( - 'final String Function( Api instance, Input input, )? doSomethingElse;', + 'final String Function( Api pigeon_instance, Input input, )? doSomethingElse;', ), ); // Copy method - expect(code, contains(r'Api $copy')); + expect(code, contains(r'Api pigeon_copy(')); }); group('inheritance', () { @@ -1916,7 +1916,7 @@ name: foobar expect( collapsedCode, contains( - r'Api.$detached({ super.$binaryMessenger, super.$instanceManager, }) : super.$detached();', + r'Api.pigeon_detached({ super.pigeon_binaryMessenger, super.pigeon_instanceManager, }) : super.pigeon_detached();', ), ); }); @@ -2027,8 +2027,8 @@ name: foobar expect( collapsedCode, contains( - r'Api.$detached({ this.$binaryMessenger, ' - r'$InstanceManager? $instanceManager, ' + r'Api.pigeon_detached({ this.pigeon_binaryMessenger, ' + r'Pigeon_InstanceManager? pigeon_instanceManager, ' r'this.aFlutterMethod, ' r'required this.aNullableFlutterMethod, })', ), @@ -2064,21 +2064,21 @@ name: foobar expect( collapsedCode, contains( - r'Api({ this.$binaryMessenger, ' - r'$InstanceManager? $instanceManager, })', + r'Api({ this.pigeon_binaryMessenger, ' + r'Pigeon_InstanceManager? pigeon_instanceManager, })', ), ); expect( collapsedCode, contains( - r"const String __pigeon_channelName = r'dev.flutter.pigeon.test_package.Api.$defaultConstructor';", + r"const String __pigeon_channelName = r'dev.flutter.pigeon.test_package.Api.pigeon_defaultConstructor';", ), ); expect( collapsedCode, contains( r'__pigeon_channel.send([ ' - r'this.$instanceManager.addDartCreatedInstance(this) ])', + r'this.pigeon_instanceManager.addDartCreatedInstance(this) ])', ), ); }); @@ -2165,8 +2165,8 @@ name: foobar expect( collapsedCode, contains( - r'Api.name({ this.$binaryMessenger, ' - r'$InstanceManager? $instanceManager, ' + r'Api.name({ this.pigeon_binaryMessenger, ' + r'Pigeon_InstanceManager? pigeon_instanceManager, ' r'required int validType, ' r'required AnEnum enumType, ' r'required Api2 proxyApiType, ' @@ -2179,7 +2179,7 @@ name: foobar collapsedCode, contains( r'__pigeon_channel.send([ ' - r'this.$instanceManager.addDartCreatedInstance(this), ' + r'this.pigeon_instanceManager.addDartCreatedInstance(this), ' r'validType, enumType.index, proxyApiType, ' r'nullableValidType, nullableEnumType?.index, nullableProxyApiType, ])', ), @@ -2275,8 +2275,8 @@ name: foobar expect( collapsedCode, contains( - r'Api.name({ this.$binaryMessenger, ' - r'$InstanceManager? $instanceManager, ' + r'Api.name({ this.pigeon_binaryMessenger, ' + r'Pigeon_InstanceManager? pigeon_instanceManager, ' r'required this.validType, ' r'required this.enumType, ' r'required this.proxyApiType, ' @@ -2289,7 +2289,7 @@ name: foobar collapsedCode, contains( r'__pigeon_channel.send([ ' - r'this.$instanceManager.addDartCreatedInstance(this), ' + r'this.pigeon_instanceManager.addDartCreatedInstance(this), ' r'validType, enumType.index, proxyApiType, ' r'nullableValidType, nullableEnumType?.index, nullableProxyApiType, ])', ), @@ -2360,8 +2360,8 @@ name: foobar ); final String code = sink.toString(); expect(code, contains('class Api')); - expect(code, contains(r'late final Api2 aField = _aField();')); - expect(code, contains(r'Api2 _aField()')); + expect(code, contains(r'late final Api2 aField = __pigeon_aField();')); + expect(code, contains(r'Api2 __pigeon_aField()')); }); test('static attached field', () { @@ -2405,8 +2405,9 @@ name: foobar ); final String code = sink.toString(); expect(code, contains('class Api')); - expect(code, contains(r'static final Api2 aField = _aField();')); - expect(code, contains(r'static Api2 _aField()')); + expect( + code, contains(r'static final Api2 aField = __pigeon_aField();')); + expect(code, contains(r'static Api2 __pigeon_aField()')); }); }); @@ -2550,8 +2551,8 @@ name: foobar expect( collapsedCode, contains( - r'static Future doSomething({ BinaryMessenger? $binaryMessenger, ' - r'$InstanceManager? $instanceManager, })', + r'static Future doSomething({ BinaryMessenger? pigeon_binaryMessenger, ' + r'Pigeon_InstanceManager? pigeon_instanceManager, })', ), ); expect( @@ -2642,7 +2643,7 @@ name: foobar expect( collapsedCode, contains( - r'final void Function( Api instance, int validType, ' + r'final void Function( Api pigeon_instance, int validType, ' r'AnEnum enumType, Api2 proxyApiType, int? nullableValidType, ' r'AnEnum? nullableEnumType, Api2? nullableProxyApiType, )? ' r'doSomething;', @@ -2651,7 +2652,7 @@ name: foobar expect( collapsedCode, contains( - r'void Function( Api instance, int validType, AnEnum enumType, ' + r'void Function( Api pigeon_instance, int validType, AnEnum enumType, ' r'Api2 proxyApiType, int? nullableValidType, ' r'AnEnum? nullableEnumType, Api2? nullableProxyApiType, )? ' r'doSomething'), From df2ecacd9ed7bef2a16c091a7aa8a52cf4edd418 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 20 Dec 2023 23:22:22 -0500 Subject: [PATCH 50/73] add documentation --- packages/pigeon/lib/ast.dart | 11 +++++--- packages/pigeon/lib/dart_generator.dart | 36 +++++++++++++++++++----- packages/pigeon/lib/generator.dart | 11 +++++++- packages/pigeon/lib/generator_tools.dart | 11 +++++--- packages/pigeon/lib/pigeon_lib.dart | 24 +++++++++++++++- 5 files changed, 76 insertions(+), 17 deletions(-) diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index 5b943dd2d72d..c950a5cde965 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -163,12 +163,16 @@ class AstProxyApi extends Api { (Method method) => method.location == ApiLocation.flutter, ); - /// All fields that are attached . + /// 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 nonAttachedFields => fields.where( (Field field) => !field.isAttached, ); @@ -231,13 +235,12 @@ class Field extends NamedType { /// Whether this is an attached field for a [AstProxyApi]. /// - /// Attached fields provide a synchronous [AstProxyApi] instance as a field - /// for another [AstProxyApi]. + /// See [attached]. final bool isAttached; /// Whether this is a static field of a [AstProxyApi]. /// - /// A static field must also be attached. + /// A static field must also be attached. See [attached]. final bool isStatic; /// Returns a copy of [Parameter] instance with new attached [TypeDeclaration]. diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 4ea34a3c2639..33da57ffe05b 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -997,40 +997,48 @@ class $codecName extends StandardMessageCodec { required String dartPackageName, }) { const String codecName = '_${classNamePrefix}ProxyApiBaseCodec'; + + // Each api has an private codec instance used by every host method. + // constructor, or non-static field. final String codecInstanceName = '${_varNamePrefix}codec${api.name}'; final Iterable allProxyApis = root.apis.whereType(); + // A list of ProxyApis where each `extends` the API that follows it. final List superClassApisChain = recursiveGetSuperClassApisChain( api, allProxyApis, ); + // The proxy api this api `extends` if it exists. final AstProxyApi? superClassApi = superClassApisChain.isNotEmpty ? superClassApisChain.first : null; + // All ProxyApis this API `implements` and all the interfaces those APIs + // `implements`. final Set interfacesApis = recursiveFindAllInterfacesApis( api, allProxyApis, ); + // 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 inherited methods from super classes that constructors set with - // `super.`. + // 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 = []; if (superClassApi != null) { for (final AstProxyApi proxyApi in superClassApisChain) { - for (final Method method in proxyApi.methods) { - if (method.location == ApiLocation.flutter) { - superClassFlutterMethods.add(method); - } - } + superClassFlutterMethods.addAll(proxyApi.flutterMethods); } final Set superClassInterfacesApis = @@ -1050,6 +1058,7 @@ class $codecName extends StandardMessageCodec { return method.location == ApiLocation.flutter && method.required; }); + // Ast class used by code_builder. final cb.Class proxyApi = cb.Class( (cb.ClassBuilder builder) => builder ..name = api.name @@ -1120,6 +1129,7 @@ class $codecName extends StandardMessageCodec { required Iterable flutterMethods, }) { return [ + // All constructors for this api defined in the pigeon file. ...constructors.map( (Constructor constructor) => cb.Constructor( (cb.ConstructorBuilder builder) { @@ -1213,9 +1223,12 @@ class $codecName extends StandardMessageCodec { binaryMessenger: cb.refer('${classMemberNamePrefix}binaryMessenger'), ), + // __pigeon_channel.send([]).then((Object? value) { ... }); cb .refer('${_varNamePrefix}channel.send') .call([ + // List of arguments for the method call + // [, ..., ...] cb.literalList( [ cb.refer( @@ -1232,6 +1245,7 @@ class $codecName extends StandardMessageCodec { .property('then') .call( [ + // This creates a lambda Function `(Object? value) {...}` cb.Method( (cb.MethodBuilder builder) => builder ..requiredParameters.add( @@ -1241,6 +1255,7 @@ class $codecName extends StandardMessageCodec { ..type = cb.refer('Object?'), ), ) + // Body of lambda function ..body = cb.Block.of([ const cb.Code( 'final List? ${_varNamePrefix}replyList = value as List?;', @@ -1283,6 +1298,11 @@ class $codecName extends StandardMessageCodec { }, ), ), + // 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' @@ -1376,6 +1396,8 @@ class $codecName extends StandardMessageCodec { ..assignment = cb.Code('$codecName(${classMemberNamePrefix}instanceManager)'), ), + // If this api doesn't have a super class it has to include an + // `InstanceManager` and a `BinaryMessenger`. if (!hasSuperClass) ...[ cb.Field( (cb.FieldBuilder builder) => builder diff --git a/packages/pigeon/lib/generator.dart b/packages/pigeon/lib/generator.dart index 687421c0b54d..3711fd28dbe3 100644 --- a/packages/pigeon/lib/generator.dart +++ b/packages/pigeon/lib/generator.dart @@ -306,7 +306,16 @@ abstract class StructuredGenerator extends Generator { required String dartPackageName, }) {} - /// Writes the base codec to be used by ProxyApis. + /// 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, diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index b057f180c0fd..92d2bef9a8a7 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -626,7 +626,7 @@ enum FileType { /// interfaces. /// /// This method assumes that all interfaces names can be found in -/// [allProxyApis]. Otherwise, throws [ArgumentError]. +/// [allProxyApis]. Otherwise, throws an [ArgumentError]. Set recursiveFindAllInterfacesApis( AstProxyApi api, Iterable allProxyApis, @@ -655,13 +655,16 @@ Set recursiveFindAllInterfacesApis( return interfacesApis; } -/// Recursively find super classes for a ProxyApi and return them in order. +/// 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 [StateError] if a loop is found. +/// loop. Throws a [ArgumentError] if a loop is found. /// /// This method also assumes that all super class names can be found in -/// [allProxyApis]. +/// [allProxyApis]. Otherwise, throws an [ArgumentError]. List recursiveGetSuperClassApisChain( AstProxyApi proxyApi, Iterable allProxyApis, diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 18cd3f347fae..894dc51b5d83 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -52,6 +52,27 @@ class _Static { 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. @@ -1002,7 +1023,8 @@ List _validateProxyApi( } } - // Validate only Flutter methods are used for implemented ProxyApis. + // 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; From e1575687f23234933b0ed8d88b27de5732c58b61 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 21 Dec 2023 15:50:41 -0500 Subject: [PATCH 51/73] create a base class for dart --- packages/pigeon/lib/dart_generator.dart | 113 ++++++++---------- .../lib/src/generated/core_tests.gen.dart | 53 ++++---- 2 files changed, 74 insertions(+), 92 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 33da57ffe05b..a12fc1d4d6d0 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -841,6 +841,8 @@ class $instanceManagerClassName { } } '''); + + _writeProxyApiBaseClass(indent); } @override @@ -1062,12 +1064,12 @@ class $codecName extends StandardMessageCodec { final cb.Class proxyApi = cb.Class( (cb.ClassBuilder builder) => builder ..name = api.name - ..extend = superClassApi != null ? cb.refer(superClassApi.name) : null + ..extend = superClassApi != null + ? cb.refer(superClassApi.name) + : cb.refer('_${classNamePrefix}ProxyApiBaseClass') ..implements.addAll([ if (api.interfacesNames.isNotEmpty) ...api.interfacesNames.map((String name) => cb.refer(name)) - else - cb.refer('${classNamePrefix}Copyable') ]) ..docs.addAll(asDocumentationComments( api.documentationComments, @@ -1152,16 +1154,14 @@ class $codecName extends StandardMessageCodec { (cb.ParameterBuilder builder) => builder ..name = '${classMemberNamePrefix}binaryMessenger' ..named = true - ..toSuper = superClassApi != null - ..toThis = superClassApi == null, + ..toSuper = true, + ), + cb.Parameter( + (cb.ParameterBuilder builder) => builder + ..name = '${classMemberNamePrefix}instanceManager' + ..named = true + ..toSuper = true, ), - cb.Parameter((cb.ParameterBuilder builder) => builder - ..name = '${classMemberNamePrefix}instanceManager' - ..type = superClassApi == null - ? cb.refer('$instanceManagerClassName?') - : null - ..named = true - ..toSuper = superClassApi != null), for (final Field field in nonAttachedFields) cb.Parameter( (cb.ParameterBuilder builder) => builder @@ -1207,12 +1207,11 @@ class $codecName extends StandardMessageCodec { ) ], ) - ..initializers.add( - cb.Code( - superClassApi != null - ? 'super.${classMemberNamePrefix}detached()' - : '${classMemberNamePrefix}instanceManager = ${classMemberNamePrefix}instanceManager ?? $instanceManagerClassName.instance', - ), + ..initializers.addAll( + [ + if (superClassApi != null) + const cb.Code('super.${classMemberNamePrefix}detached()') + ], ) ..body = cb.Block.of([ cb.Code( @@ -1317,17 +1316,13 @@ class $codecName extends StandardMessageCodec { (cb.ParameterBuilder builder) => builder ..name = '${classMemberNamePrefix}binaryMessenger' ..named = true - ..toSuper = superClassApi != null - ..toThis = superClassApi == null, + ..toSuper = true, ), cb.Parameter( (cb.ParameterBuilder builder) => builder ..name = '${classMemberNamePrefix}instanceManager' - ..type = superClassApi == null - ? cb.refer('$instanceManagerClassName?') - : null ..named = true - ..toSuper = superClassApi != null, + ..toSuper = true, ), for (final Field field in nonAttachedFields) cb.Parameter( @@ -1362,13 +1357,10 @@ class $codecName extends StandardMessageCodec { ..required = method.required, ), ]) - ..initializers.add( - cb.Code( - superClassApi != null - ? 'super.${classMemberNamePrefix}detached()' - : '${classMemberNamePrefix}instanceManager = ${classMemberNamePrefix}instanceManager ?? $instanceManagerClassName.instance', - ), - ), + ..initializers.addAll([ + if (superClassApi != null) + const cb.Code('super.${classMemberNamePrefix}detached()'), + ]), ), ]; } @@ -1396,39 +1388,6 @@ class $codecName extends StandardMessageCodec { ..assignment = cb.Code('$codecName(${classMemberNamePrefix}instanceManager)'), ), - // If this api doesn't have a super class it has to include an - // `InstanceManager` and a `BinaryMessenger`. - if (!hasSuperClass) ...[ - cb.Field( - (cb.FieldBuilder builder) => builder - ..name = '${classMemberNamePrefix}binaryMessenger' - ..type = cb.refer('BinaryMessenger?') - ..modifier = cb.FieldModifier.final$ - ..docs.addAll([ - '/// 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.', - ]) - ..annotations.addAll([ - if (!hasSuperClass && interfacesApis.isNotEmpty) - cb.refer('override'), - ]), - ), - cb.Field( - (cb.FieldBuilder builder) => builder - ..name = '${classMemberNamePrefix}instanceManager' - ..type = cb.refer(instanceManagerClassName) - ..modifier = cb.FieldModifier.final$ - ..docs.add( - '/// Maintains instances stored to communicate with native language objects.', - ) - ..annotations.addAll([ - if (!hasSuperClass && interfacesApis.isNotEmpty) - cb.refer('override'), - ]), - ), - ], for (final Field field in nonAttachedFields) cb.Field( (cb.FieldBuilder builder) => builder @@ -2102,6 +2061,32 @@ class $codecName extends StandardMessageCodec { ]; } + // The base class of all generated ProxyApis. + void _writeProxyApiBaseClass(Indent indent) { + const String className = '_${classNamePrefix}ProxyApiBaseClass'; + const String messengerVarName = '${classMemberNamePrefix}binaryMessenger'; + const String instanceManagerVarName = + '${classMemberNamePrefix}instanceManager'; + indent.writeln(''' +abstract class $className implements ${classNamePrefix}Copyable { + $className({ + this.$messengerVarName, + $instanceManagerClassName? $instanceManagerVarName, + }) : $instanceManagerVarName = + $instanceManagerVarName ?? $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? $messengerVarName; + + /// Maintains instances stored to communicate with native language objects. + final $instanceManagerClassName $instanceManagerVarName; +} +'''); + } + /// 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 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 6ce87f5f8adb..bf444b46f9f2 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 @@ -247,6 +247,23 @@ class Pigeon_InstanceManager { } } +abstract class _Pigeon_ProxyApiBaseClass implements Pigeon_Copyable { + _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; +} + /// Generated API for managing the Dart and native `Pigeon_InstanceManager`s. class _Pigeon_InstanceManagerApi { /// Constructor for [_Pigeon_InstanceManagerApi ]. @@ -7473,29 +7490,19 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } /// ProxyApi to serve as a super class to the core ProxyApi interface. -class ProxyApiSuperClass implements Pigeon_Copyable { +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. ProxyApiSuperClass.pigeon_detached({ - this.pigeon_binaryMessenger, - Pigeon_InstanceManager? pigeon_instanceManager, - }) : pigeon_instanceManager = - pigeon_instanceManager ?? Pigeon_InstanceManager.instance; + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + }); late final _Pigeon_ProxyApiBaseCodec __pigeon_codecProxyApiSuperClass = _Pigeon_ProxyApiBaseCodec(pigeon_instanceManager); - /// 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; - static void pigeon_setUpMessageHandlers({ BinaryMessenger? pigeon_binaryMessenger, Pigeon_InstanceManager? pigeon_instanceManager, @@ -7572,26 +7579,16 @@ class ProxyApiSuperClass implements Pigeon_Copyable { } /// ProxyApi to serve as an interface to the core ProxyApi interface. -class ProxyApiInterface implements Pigeon_Copyable { +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. ProxyApiInterface.pigeon_detached({ - this.pigeon_binaryMessenger, - Pigeon_InstanceManager? pigeon_instanceManager, + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, this.anInterfaceMethod, - }) : 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; + }); final void Function(ProxyApiInterface pigeon_instance)? anInterfaceMethod; From de987e088e5e2f795dd8295d99b52ecf36a0e1c1 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 21 Dec 2023 16:08:38 -0500 Subject: [PATCH 52/73] fix tests and lint --- packages/pigeon/lib/dart_generator.dart | 4 +- packages/pigeon/test/dart_generator_test.dart | 54 +++++++++++++------ 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index a12fc1d4d6d0..78ccd76e86fc 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -1095,7 +1095,6 @@ class $codecName extends StandardMessageCodec { codecName: codecName, interfacesApis: interfacesApis, flutterMethods: api.flutterMethods, - hasSuperClass: superClassApi != null, referencesCodecInstance: api.hostMethods.isNotEmpty || api.constructors.isNotEmpty || api.attachedFields.any((Field field) => !field.isStatic), @@ -1231,7 +1230,7 @@ class $codecName extends StandardMessageCodec { cb.literalList( [ cb.refer( - '${superClassApi != null ? '' : 'this.'}${classMemberNamePrefix}instanceManager.addDartCreatedInstance(this)', + '${classMemberNamePrefix}instanceManager.addDartCreatedInstance(this)', ), ...nonAttachedFields.mapIndexed(_hostMessageArgument), ...constructor.parameters.mapIndexed( @@ -1374,7 +1373,6 @@ class $codecName extends StandardMessageCodec { required String codecName, required Iterable interfacesApis, required Iterable flutterMethods, - required bool hasSuperClass, required bool referencesCodecInstance, }) { return [ diff --git a/packages/pigeon/test/dart_generator_test.dart b/packages/pigeon/test/dart_generator_test.dart index 4b9aeb9eb226..c885cbc8ceb7 100644 --- a/packages/pigeon/test/dart_generator_test.dart +++ b/packages/pigeon/test/dart_generator_test.dart @@ -1848,15 +1848,22 @@ name: foobar 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 implements Pigeon_Copyable'), + ); + // Codec and class expect(code, contains('class _Pigeon_ProxyApiBaseCodec')); - expect(code, contains(r'class Api implements Pigeon_Copyable')); + expect(code, contains(r'class Api extends _Pigeon_ProxyApiBaseClass')); // Constructors expect( collapsedCode, contains( - r'Api.name({ this.pigeon_binaryMessenger, Pigeon_InstanceManager? pigeon_instanceManager, required this.someField, this.doSomethingElse, required Input input, })', + r'Api.name({ super.pigeon_binaryMessenger, super.pigeon_instanceManager, required this.someField, this.doSomethingElse, required Input input, })', ), ); expect( @@ -1946,7 +1953,12 @@ name: foobar dartPackageName: DEFAULT_PACKAGE_NAME, ); final String code = sink.toString(); - expect(code, contains(r'class Api implements Api2')); + expect( + code, + contains( + r'class Api extends _Pigeon_ProxyApiBaseClass implements Api2', + ), + ); }); test('implements 2 ProxyApis', () { @@ -1980,7 +1992,12 @@ name: foobar dartPackageName: DEFAULT_PACKAGE_NAME, ); final String code = sink.toString(); - expect(code, contains(r'class Api implements Api2, Api3')); + expect( + code, + contains( + r'class Api extends _Pigeon_ProxyApiBaseClass implements Api2, Api3', + ), + ); }); test('implements inherits flutter method', () { @@ -2023,12 +2040,17 @@ name: foobar ); final String code = sink.toString(); final String collapsedCode = _collapseNewlineAndIndentation(code); - expect(code, contains(r'class Api implements Api2')); + expect( + code, + contains( + r'class Api extends _Pigeon_ProxyApiBaseClass implements Api2', + ), + ); expect( collapsedCode, contains( - r'Api.pigeon_detached({ this.pigeon_binaryMessenger, ' - r'Pigeon_InstanceManager? pigeon_instanceManager, ' + r'Api.pigeon_detached({ super.pigeon_binaryMessenger, ' + r'super.pigeon_instanceManager, ' r'this.aFlutterMethod, ' r'required this.aNullableFlutterMethod, })', ), @@ -2064,8 +2086,8 @@ name: foobar expect( collapsedCode, contains( - r'Api({ this.pigeon_binaryMessenger, ' - r'Pigeon_InstanceManager? pigeon_instanceManager, })', + r'Api({ super.pigeon_binaryMessenger, ' + r'super.pigeon_instanceManager, })', ), ); expect( @@ -2078,7 +2100,7 @@ name: foobar collapsedCode, contains( r'__pigeon_channel.send([ ' - r'this.pigeon_instanceManager.addDartCreatedInstance(this) ])', + r'pigeon_instanceManager.addDartCreatedInstance(this) ])', ), ); }); @@ -2165,8 +2187,8 @@ name: foobar expect( collapsedCode, contains( - r'Api.name({ this.pigeon_binaryMessenger, ' - r'Pigeon_InstanceManager? pigeon_instanceManager, ' + r'Api.name({ super.pigeon_binaryMessenger, ' + r'super.pigeon_instanceManager, ' r'required int validType, ' r'required AnEnum enumType, ' r'required Api2 proxyApiType, ' @@ -2179,7 +2201,7 @@ name: foobar collapsedCode, contains( r'__pigeon_channel.send([ ' - r'this.pigeon_instanceManager.addDartCreatedInstance(this), ' + r'pigeon_instanceManager.addDartCreatedInstance(this), ' r'validType, enumType.index, proxyApiType, ' r'nullableValidType, nullableEnumType?.index, nullableProxyApiType, ])', ), @@ -2275,8 +2297,8 @@ name: foobar expect( collapsedCode, contains( - r'Api.name({ this.pigeon_binaryMessenger, ' - r'Pigeon_InstanceManager? pigeon_instanceManager, ' + r'Api.name({ super.pigeon_binaryMessenger, ' + r'super.pigeon_instanceManager, ' r'required this.validType, ' r'required this.enumType, ' r'required this.proxyApiType, ' @@ -2289,7 +2311,7 @@ name: foobar collapsedCode, contains( r'__pigeon_channel.send([ ' - r'this.pigeon_instanceManager.addDartCreatedInstance(this), ' + r'pigeon_instanceManager.addDartCreatedInstance(this), ' r'validType, enumType.index, proxyApiType, ' r'nullableValidType, nullableEnumType?.index, nullableProxyApiType, ])', ), From 30abd65c1a743569b7980378eb868dd0aead07f2 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 21 Dec 2023 21:01:06 -0500 Subject: [PATCH 53/73] replace copyable with a base class --- packages/pigeon/lib/dart_generator.dart | 86 +++++++++-------- .../lib/src/generated/core_tests.gen.dart | 94 +++++++++++-------- 2 files changed, 100 insertions(+), 80 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 78ccd76e86fc..69ef44fcea34 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -624,7 +624,9 @@ if (${_varNamePrefix}replyList == null) { Indent indent, { required String dartPackageName, }) { - const String copyableClassName = '${classNamePrefix}Copyable'; + _writeProxyApiBaseClass(indent); + + const String proxyApiBaseClassName = '${classNamePrefix}ProxyApiBaseClass'; final Iterable apiHandlerSetups = root.apis.whereType().map( (AstProxyApi api) { @@ -632,22 +634,6 @@ if (${_varNamePrefix}replyList == null) { }, ); indent.format(''' -/// An immutable object that can provide functional copies of itself. -/// -/// All implementers are expected to be immutable as defined by the annotation. -@immutable -mixin $copyableClassName { - /// 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 - $copyableClassName ${classMemberNamePrefix}copy(); -} - /// Maintains instances used to communicate with the native objects they /// represent. /// @@ -664,7 +650,7 @@ mixin $copyableClassName { /// scenario where the weak referenced instance was released and then later /// returned by the host platform. class $instanceManagerClassName { - /// Constructs an [$instanceManagerClassName]. + /// Constructs a [$instanceManagerClassName]. $instanceManagerClassName({required void Function(int) onWeakReferenceRemoved}) { this.onWeakReferenceRemoved = (int identifier) { _weakInstances.remove(identifier); @@ -679,6 +665,11 @@ class $instanceManagerClassName { // 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 @@ -690,9 +681,9 @@ class $instanceManagerClassName { // 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; @@ -723,7 +714,7 @@ class $instanceManagerClassName { /// Throws assertion error if the instance has already been added. /// /// Returns the randomly generated id of the [instance] added. - int addDartCreatedInstance($copyableClassName instance) { + int addDartCreatedInstance($proxyApiBaseClassName instance) { final int identifier = _nextUniqueIdentifier(); _addInstanceWithIdentifier(instance, identifier); return identifier; @@ -737,7 +728,7 @@ class $instanceManagerClassName { /// /// This does not remove the strong referenced instance associated with /// [instance]. This can be done with [remove]. - int? removeWeakReference($copyableClassName instance) { + int? removeWeakReference($proxyApiBaseClassName instance) { final int? identifier = getIdentifier(instance); if (identifier == null) { return null; @@ -759,7 +750,7 @@ class $instanceManagerClassName { /// /// 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?; } @@ -775,15 +766,15 @@ class $instanceManagerClassName { /// /// 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 $copyableClassName? weakInstance = _weakInstances[identifier]?.target; + T? getInstanceWithWeakReference(int identifier) { + final $proxyApiBaseClassName? weakInstance = _weakInstances[identifier]?.target; if (weakInstance == null) { - final $copyableClassName? strongInstance = _strongInstances[identifier]; + final $proxyApiBaseClassName? strongInstance = _strongInstances[identifier]; if (strongInstance != null) { - final $copyableClassName copy = strongInstance.${classMemberNamePrefix}copy(); + final $proxyApiBaseClassName copy = strongInstance.${classMemberNamePrefix}copy(); _identifiers[copy] = identifier; - _weakInstances[identifier] = WeakReference<$copyableClassName>(copy); + _weakInstances[identifier] = WeakReference<$proxyApiBaseClassName>(copy); _finalizer.attach(copy, identifier, detach: copy); return copy as T; } @@ -794,7 +785,7 @@ class $instanceManagerClassName { } /// Retrieves the identifier associated with instance. - int? getIdentifier($copyableClassName instance) { + int? getIdentifier($proxyApiBaseClassName instance) { return _identifiers[instance]; } @@ -807,20 +798,20 @@ class $instanceManagerClassName { /// added. /// /// Returns unique identifier of the [instance] added. - void addHostCreatedInstance($copyableClassName instance, int identifier) { + void addHostCreatedInstance($proxyApiBaseClassName instance, int identifier) { _addInstanceWithIdentifier(instance, identifier); } - void _addInstanceWithIdentifier($copyableClassName instance, int identifier) { + void _addInstanceWithIdentifier($proxyApiBaseClassName instance, int identifier) { assert(!containsIdentifier(identifier)); assert(getIdentifier(instance) == null); assert(identifier >= 0); _identifiers[instance] = identifier; - _weakInstances[identifier] = WeakReference<$copyableClassName>(instance); + _weakInstances[identifier] = WeakReference<$proxyApiBaseClassName>(instance); _finalizer.attach(instance, identifier, detach: instance); - final $copyableClassName copy = instance.${classMemberNamePrefix}copy(); + final $proxyApiBaseClassName copy = instance.${classMemberNamePrefix}copy(); _identifiers[copy] = identifier; _strongInstances[identifier] = copy; } @@ -841,8 +832,6 @@ class $instanceManagerClassName { } } '''); - - _writeProxyApiBaseClass(indent); } @override @@ -968,7 +957,7 @@ class $codecName extends StandardMessageCodec { @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is ${classNamePrefix}Copyable) { + if (value is ${classNamePrefix}ProxyApiBaseClass) { buffer.putUint8(128); writeValue(buffer, instanceManager.getIdentifier(value)); } else { @@ -1066,7 +1055,7 @@ class $codecName extends StandardMessageCodec { ..name = api.name ..extend = superClassApi != null ? cb.refer(superClassApi.name) - : cb.refer('_${classNamePrefix}ProxyApiBaseClass') + : cb.refer('${classNamePrefix}ProxyApiBaseClass') ..implements.addAll([ if (api.interfacesNames.isNotEmpty) ...api.interfacesNames.map((String name) => cb.refer(name)) @@ -2061,12 +2050,19 @@ class $codecName extends StandardMessageCodec { // The base class of all generated ProxyApis. void _writeProxyApiBaseClass(Indent indent) { - const String className = '_${classNamePrefix}ProxyApiBaseClass'; + const String className = '${classNamePrefix}ProxyApiBaseClass'; const String messengerVarName = '${classMemberNamePrefix}binaryMessenger'; const String instanceManagerVarName = '${classMemberNamePrefix}instanceManager'; indent.writeln(''' -abstract class $className implements ${classNamePrefix}Copyable { +/// 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 $className { + /// Construct a [$className]. $className({ this.$messengerVarName, $instanceManagerClassName? $instanceManagerVarName, @@ -2081,6 +2077,16 @@ abstract class $className implements ${classNamePrefix}Copyable { /// Maintains instances stored to communicate with native language objects. final $instanceManagerClassName $instanceManagerVarName; + + /// 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 + $className ${classMemberNamePrefix}copy(); } '''); } 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 bf444b46f9f2..650b1c08328e 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 @@ -32,11 +32,29 @@ List wrapResponse( return [error.code, error.message, error.details]; } -/// An immutable object that can provide functional copies of itself. +/// 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. +/// All implementers are expected to be immutable as defined by the annotation +/// and override [pigeon_copy] returning an instance of itself. @immutable -mixin Pigeon_Copyable { +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 @@ -45,7 +63,7 @@ mixin Pigeon_Copyable { /// Subclasses should always override their parent's implementation of this /// method. @protected - Pigeon_Copyable pigeon_copy(); + Pigeon_ProxyApiBaseClass pigeon_copy(); } /// Maintains instances used to communicate with the native objects they @@ -79,6 +97,11 @@ class Pigeon_InstanceManager { // 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 @@ -90,9 +113,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; @@ -129,7 +153,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_Copyable instance) { + int addDartCreatedInstance(Pigeon_ProxyApiBaseClass instance) { final int identifier = _nextUniqueIdentifier(); _addInstanceWithIdentifier(instance, identifier); return identifier; @@ -143,7 +167,7 @@ class Pigeon_InstanceManager { /// /// This does not remove the strong referenced instance associated with /// [instance]. This can be done with [remove]. - int? removeWeakReference(Pigeon_Copyable instance) { + int? removeWeakReference(Pigeon_ProxyApiBaseClass instance) { final int? identifier = getIdentifier(instance); if (identifier == null) { return null; @@ -165,7 +189,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?; } @@ -181,15 +205,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(int identifier) { - final Pigeon_Copyable? weakInstance = _weakInstances[identifier]?.target; + T? getInstanceWithWeakReference( + int identifier) { + final Pigeon_ProxyApiBaseClass? weakInstance = + _weakInstances[identifier]?.target; if (weakInstance == null) { - final Pigeon_Copyable? strongInstance = _strongInstances[identifier]; + final Pigeon_ProxyApiBaseClass? strongInstance = + _strongInstances[identifier]; if (strongInstance != null) { - final Pigeon_Copyable copy = strongInstance.pigeon_copy(); + final Pigeon_ProxyApiBaseClass copy = strongInstance.pigeon_copy(); _identifiers[copy] = identifier; - _weakInstances[identifier] = WeakReference(copy); + _weakInstances[identifier] = + WeakReference(copy); _finalizer.attach(copy, identifier, detach: copy); return copy as T; } @@ -200,7 +228,7 @@ class Pigeon_InstanceManager { } /// Retrieves the identifier associated with instance. - int? getIdentifier(Pigeon_Copyable instance) { + int? getIdentifier(Pigeon_ProxyApiBaseClass instance) { return _identifiers[instance]; } @@ -213,20 +241,23 @@ class Pigeon_InstanceManager { /// added. /// /// Returns unique identifier of the [instance] added. - void addHostCreatedInstance(Pigeon_Copyable instance, int identifier) { + void addHostCreatedInstance( + Pigeon_ProxyApiBaseClass instance, int identifier) { _addInstanceWithIdentifier(instance, identifier); } - void _addInstanceWithIdentifier(Pigeon_Copyable instance, int 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); + _weakInstances[identifier] = + WeakReference(instance); _finalizer.attach(instance, identifier, detach: instance); - final Pigeon_Copyable copy = instance.pigeon_copy(); + final Pigeon_ProxyApiBaseClass copy = instance.pigeon_copy(); _identifiers[copy] = identifier; _strongInstances[identifier] = copy; } @@ -247,23 +278,6 @@ class Pigeon_InstanceManager { } } -abstract class _Pigeon_ProxyApiBaseClass implements Pigeon_Copyable { - _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; -} - /// Generated API for managing the Dart and native `Pigeon_InstanceManager`s. class _Pigeon_InstanceManagerApi { /// Constructor for [_Pigeon_InstanceManagerApi ]. @@ -357,7 +371,7 @@ class _Pigeon_ProxyApiBaseCodec extends StandardMessageCodec { @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is Pigeon_Copyable) { + if (value is Pigeon_ProxyApiBaseClass) { buffer.putUint8(128); writeValue(buffer, instanceManager.getIdentifier(value)); } else { @@ -7490,7 +7504,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } /// ProxyApi to serve as a super class to the core ProxyApi interface. -class ProxyApiSuperClass extends _Pigeon_ProxyApiBaseClass { +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 @@ -7579,7 +7593,7 @@ class ProxyApiSuperClass extends _Pigeon_ProxyApiBaseClass { } /// ProxyApi to serve as an interface to the core ProxyApi interface. -class ProxyApiInterface extends _Pigeon_ProxyApiBaseClass { +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 From c4e0af320b9e095ebd8e195deff4db1227029085 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 21 Dec 2023 21:02:48 -0500 Subject: [PATCH 54/73] fix unit tests --- .../lib/src/generated/core_tests.gen.dart | 2 +- packages/pigeon/test/dart_generator_test.dart | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) 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 650b1c08328e..e5e8397078fc 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 @@ -82,7 +82,7 @@ abstract class Pigeon_ProxyApiBaseClass { /// scenario where the weak referenced instance was released and then later /// returned by the host platform. class Pigeon_InstanceManager { - /// Constructs an [Pigeon_InstanceManager]. + /// Constructs a [Pigeon_InstanceManager]. Pigeon_InstanceManager({required void Function(int) onWeakReferenceRemoved}) { this.onWeakReferenceRemoved = (int identifier) { _weakInstances.remove(identifier); diff --git a/packages/pigeon/test/dart_generator_test.dart b/packages/pigeon/test/dart_generator_test.dart index c885cbc8ceb7..5439d6dbdecf 100644 --- a/packages/pigeon/test/dart_generator_test.dart +++ b/packages/pigeon/test/dart_generator_test.dart @@ -1851,13 +1851,12 @@ name: foobar // Base Api class expect( code, - contains( - r'abstract class _Pigeon_ProxyApiBaseClass implements Pigeon_Copyable'), + contains(r'abstract class Pigeon_ProxyApiBaseClass'), ); // Codec and class expect(code, contains('class _Pigeon_ProxyApiBaseCodec')); - expect(code, contains(r'class Api extends _Pigeon_ProxyApiBaseClass')); + expect(code, contains(r'class Api extends Pigeon_ProxyApiBaseClass')); // Constructors expect( @@ -1956,7 +1955,7 @@ name: foobar expect( code, contains( - r'class Api extends _Pigeon_ProxyApiBaseClass implements Api2', + r'class Api extends Pigeon_ProxyApiBaseClass implements Api2', ), ); }); @@ -1995,7 +1994,7 @@ name: foobar expect( code, contains( - r'class Api extends _Pigeon_ProxyApiBaseClass implements Api2, Api3', + r'class Api extends Pigeon_ProxyApiBaseClass implements Api2, Api3', ), ); }); @@ -2043,7 +2042,7 @@ name: foobar expect( code, contains( - r'class Api extends _Pigeon_ProxyApiBaseClass implements Api2', + r'class Api extends Pigeon_ProxyApiBaseClass implements Api2', ), ); expect( From cd71bf0388160f1f93ebdecaa79248b49d7565dd Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 21 Dec 2023 21:06:25 -0500 Subject: [PATCH 55/73] link to immutable --- packages/pigeon/lib/dart_generator.dart | 2 +- .../lib/src/generated/core_tests.gen.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 69ef44fcea34..f6ad337a651b 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -2058,7 +2058,7 @@ class $codecName extends StandardMessageCodec { /// 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 +/// All implementers are expected to be [immutable] as defined by the annotation /// and override [${classMemberNamePrefix}copy] returning an instance of itself. @immutable abstract class $className { 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 e5e8397078fc..4af6c8936d11 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 @@ -35,7 +35,7 @@ List wrapResponse( /// 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 +/// 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 { From b28e27bcc456ae779a4bde12e00435af27ee4fe5 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 21 Dec 2023 21:31:32 -0500 Subject: [PATCH 56/73] fix instance manager tests --- .../test/instance_manager_test.dart | 60 +++++++++++++------ 1 file changed, 41 insertions(+), 19 deletions(-) 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 22a4a7785062..3d3de761a977 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 @@ -10,11 +10,13 @@ import 'package:shared_test_plugin_code/src/generated/core_tests.gen.dart'; void main() { group('InstanceManager', () { test('addHostCreatedInstance', () { - final CopyableObject object = CopyableObject(); - final Pigeon_InstanceManager instanceManager = Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + final CopyableObject object = CopyableObject( + pigeon_instanceManager: instanceManager, + ); + instanceManager.addHostCreatedInstance(object, 0); expect(instanceManager.getIdentifier(object), 0); @@ -25,11 +27,13 @@ void main() { }); test('addHostCreatedInstance prevents already used objects and ids', () { - final CopyableObject object = CopyableObject(); - final Pigeon_InstanceManager instanceManager = Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + final CopyableObject object = CopyableObject( + pigeon_instanceManager: instanceManager, + ); + instanceManager.addHostCreatedInstance(object, 0); expect( @@ -38,17 +42,22 @@ void main() { ); expect( - () => instanceManager.addHostCreatedInstance(CopyableObject(), 0), + () => instanceManager.addHostCreatedInstance( + CopyableObject(pigeon_instanceManager: instanceManager), + 0, + ), throwsAssertionError, ); }); test('addFlutterCreatedInstance', () { - final CopyableObject object = CopyableObject(); - final Pigeon_InstanceManager instanceManager = Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + final CopyableObject object = CopyableObject( + pigeon_instanceManager: instanceManager, + ); + instanceManager.addDartCreatedInstance(object); final int? instanceId = instanceManager.getIdentifier(object); @@ -60,14 +69,16 @@ void main() { }); test('removeWeakReference', () { - final CopyableObject object = CopyableObject(); - 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); @@ -79,11 +90,13 @@ void main() { }); test('removeWeakReference removes only weak reference', () { - final CopyableObject object = CopyableObject(); - final Pigeon_InstanceManager instanceManager = Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + final CopyableObject object = CopyableObject( + pigeon_instanceManager: instanceManager, + ); + instanceManager.addHostCreatedInstance(object, 0); expect(instanceManager.removeWeakReference(object), 0); @@ -94,11 +107,13 @@ void main() { }); test('removeStrongReference', () { - final CopyableObject object = CopyableObject(); - 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()); @@ -106,11 +121,13 @@ void main() { }); test('removeStrongReference removes only strong reference', () { - final CopyableObject object = CopyableObject(); - final Pigeon_InstanceManager instanceManager = Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + final CopyableObject object = CopyableObject( + pigeon_instanceManager: instanceManager, + ); + instanceManager.addHostCreatedInstance(object, 0); expect(instanceManager.remove(0), isA()); expect( @@ -120,11 +137,13 @@ void main() { }); test('getInstance can add a new weak reference', () { - final CopyableObject object = CopyableObject(); - final Pigeon_InstanceManager instanceManager = Pigeon_InstanceManager(onWeakReferenceRemoved: (_) {}); + final CopyableObject object = CopyableObject( + pigeon_instanceManager: instanceManager, + ); + instanceManager.addHostCreatedInstance(object, 0); instanceManager.removeWeakReference(object); @@ -137,10 +156,13 @@ void main() { }); } -class CopyableObject with Pigeon_Copyable { +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(); + return CopyableObject(pigeon_instanceManager: pigeon_instanceManager); } } From 096d65c67661e39ebe3772b5e299de3d90553d4a Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 25 Dec 2023 23:14:00 -0500 Subject: [PATCH 57/73] change nonattached to unattached --- packages/pigeon/lib/ast.dart | 2 +- packages/pigeon/lib/dart_generator.dart | 30 ++++++++++++------------- packages/pigeon/lib/pigeon_lib.dart | 14 ++++++------ 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index c950a5cde965..ff686b1dfb82 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -173,7 +173,7 @@ class AstProxyApi extends Api { /// All fields that are not attached. /// /// See [attached]. - Iterable get nonAttachedFields => fields.where( + Iterable get unattachedFields => fields.where( (Field field) => !field.isAttached, ); diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index f6ad337a651b..cdb2e3e1277b 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -1070,13 +1070,13 @@ class $codecName extends StandardMessageCodec { dartPackageName: dartPackageName, codecInstanceName: codecInstanceName, superClassApi: superClassApi, - nonAttachedFields: api.nonAttachedFields, + unattachedFields: api.unattachedFields, superClassFlutterMethods: superClassFlutterMethods, interfacesMethods: interfacesMethods, flutterMethods: api.flutterMethods, )) ..fields.addAll(_proxyApiFields( - nonAttachedFields: api.nonAttachedFields, + unattachedFields: api.unattachedFields, attachedFields: api.attachedFields, apiName: api.name, dartPackageName: dartPackageName, @@ -1096,7 +1096,7 @@ class $codecName extends StandardMessageCodec { dartPackageName: dartPackageName, codecInstanceName: codecInstanceName, codecName: codecName, - nonAttachedFields: api.nonAttachedFields, + unattachedFields: api.unattachedFields, attachedFields: api.attachedFields, interfacesApis: interfacesApis, hasARequiredFlutterMethod: hasARequiredFlutterMethod, @@ -1113,7 +1113,7 @@ class $codecName extends StandardMessageCodec { required String dartPackageName, required String codecInstanceName, required AstProxyApi? superClassApi, - required Iterable nonAttachedFields, + required Iterable unattachedFields, required Iterable superClassFlutterMethods, required Iterable interfacesMethods, required Iterable flutterMethods, @@ -1150,7 +1150,7 @@ class $codecName extends StandardMessageCodec { ..named = true ..toSuper = true, ), - for (final Field field in nonAttachedFields) + for (final Field field in unattachedFields) cb.Parameter( (cb.ParameterBuilder builder) => builder ..name = field.name @@ -1221,7 +1221,7 @@ class $codecName extends StandardMessageCodec { cb.refer( '${classMemberNamePrefix}instanceManager.addDartCreatedInstance(this)', ), - ...nonAttachedFields.mapIndexed(_hostMessageArgument), + ...unattachedFields.mapIndexed(_hostMessageArgument), ...constructor.parameters.mapIndexed( _hostMessageArgument, ) @@ -1312,7 +1312,7 @@ class $codecName extends StandardMessageCodec { ..named = true ..toSuper = true, ), - for (final Field field in nonAttachedFields) + for (final Field field in unattachedFields) cb.Parameter( (cb.ParameterBuilder builder) => builder ..name = field.name @@ -1354,7 +1354,7 @@ class $codecName extends StandardMessageCodec { } Iterable _proxyApiFields({ - required Iterable nonAttachedFields, + required Iterable unattachedFields, required Iterable attachedFields, required String apiName, required String dartPackageName, @@ -1375,7 +1375,7 @@ class $codecName extends StandardMessageCodec { ..assignment = cb.Code('$codecName(${classMemberNamePrefix}instanceManager)'), ), - for (final Field field in nonAttachedFields) + for (final Field field in unattachedFields) cb.Field( (cb.FieldBuilder builder) => builder ..name = field.name @@ -1466,7 +1466,7 @@ class $codecName extends StandardMessageCodec { required String dartPackageName, required String codecInstanceName, required String codecName, - required Iterable nonAttachedFields, + required Iterable unattachedFields, required Iterable attachedFields, required Iterable interfacesApis, required bool hasARequiredFlutterMethod, @@ -1500,7 +1500,7 @@ class $codecName extends StandardMessageCodec { ..returnType = cb.refer(apiName) ..isNullable = true ..requiredParameters.addAll( - nonAttachedFields.mapIndexed( + unattachedFields.mapIndexed( (int index, Field field) { return cb.refer( '${_addGenericTypesNullable(field.type)} ${_getParameterName(index, field)}', @@ -1586,7 +1586,7 @@ class $codecName extends StandardMessageCodec { 'Argument for \$${_varNamePrefix}channelName was null, expected non-null int.', ), ), - ...nonAttachedFields.foldIndexed>( + ...unattachedFields.foldIndexed>( [], (int index, List previous, Field field) { return previous @@ -1601,7 +1601,7 @@ class $codecName extends StandardMessageCodec { .call([ cb .refer('${classMemberNamePrefix}detached?.call') - .call(nonAttachedFields.mapIndexed( + .call(unattachedFields.mapIndexed( (int index, Field field) { // The calling instance is the first arg. final String name = _getSafeArgumentName( @@ -1625,7 +1625,7 @@ class $codecName extends StandardMessageCodec { '${classMemberNamePrefix}instanceManager': cb.refer( '${classMemberNamePrefix}instanceManager'), - ...nonAttachedFields.toList().asMap().map( + ...unattachedFields.toList().asMap().map( (int index, Field field) { final String argName = _getSafeArgumentName( @@ -2030,7 +2030,7 @@ class $codecName extends StandardMessageCodec { cb.refer('${classMemberNamePrefix}binaryMessenger'), '${classMemberNamePrefix}instanceManager': cb.refer('${classMemberNamePrefix}instanceManager'), - for (final Field field in nonAttachedFields) + for (final Field field in unattachedFields) field.name: cb.refer(field.name), for (final Method method in superClassFlutterMethods) method.name: cb.refer(method.name), diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 894dc51b5d83..1d0d756a2890 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -978,28 +978,28 @@ List _validateProxyApi( // Validate that the api does not inherit a non attached field from its super class. if (superClassChain != null && superClassChain.isNotEmpty && - superClassChain.first.nonAttachedFields.isNotEmpty) { + superClassChain.first.unattachedFields.isNotEmpty) { result.add(Error( message: - 'Non attached fields can not be inherited. Non attached field found for parent class ${api.nonAttachedFields.first.name}', + 'Non attached fields can not be inherited. Non attached field found for parent class ${api.unattachedFields.first.name}', lineNumber: _calculateLineNumberNullable( source, - api.nonAttachedFields.first.offset, + api.unattachedFields.first.offset, ), )); } for (final AstProxyApi proxyApi in proxyApis) { // Validate this api is not used as an attached field while either: - // 1. Having a non-attached field. + // 1. Having an unattached field. // 2. Having a required Flutter method. - final bool hasNonAttachedField = api.nonAttachedFields.isNotEmpty; + final bool hasUnattachedField = api.unattachedFields.isNotEmpty; final bool hasRequiredFlutterMethod = api.flutterMethods.any((Method method) => method.required); - if (hasNonAttachedField || hasRequiredFlutterMethod) { + if (hasUnattachedField || hasRequiredFlutterMethod) { for (final Field field in proxyApi.attachedFields) { if (field.type.baseName == api.name) { - if (hasNonAttachedField) { + if (hasUnattachedField) { result.add(Error( message: 'ProxyApis with fields can not be used as attached fields: ${field.name}', From 4601ce208d3921bb5b0d826d94fc98b875d366d3 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 25 Dec 2023 23:26:20 -0500 Subject: [PATCH 58/73] change flutter method constructor to newInstance --- packages/pigeon/lib/dart_generator.dart | 7 ++++--- .../lib/src/generated/core_tests.gen.dart | 18 +++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index cdb2e3e1277b..f7af14b8f409 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -1493,7 +1493,7 @@ class $codecName extends StandardMessageCodec { if (!hasARequiredFlutterMethod) cb.Parameter( (cb.ParameterBuilder builder) => builder - ..name = '${classMemberNamePrefix}detached' + ..name = '${classMemberNamePrefix}newInstance' ..named = true ..type = cb.FunctionType( (cb.FunctionTypeBuilder builder) => builder @@ -1543,7 +1543,7 @@ class $codecName extends StandardMessageCodec { cb.Code( "const String ${_varNamePrefix}channelName = r'${makeChannelNameWithStrings( apiName: apiName, - methodName: '${classMemberNamePrefix}detached', + methodName: '${classMemberNamePrefix}newInstance', dartPackageName: dartPackageName, )}';", ), @@ -1600,7 +1600,8 @@ class $codecName extends StandardMessageCodec { .property('addHostCreatedInstance') .call([ cb - .refer('${classMemberNamePrefix}detached?.call') + .refer( + '${classMemberNamePrefix}newInstance?.call') .call(unattachedFields.mapIndexed( (int index, Field field) { // The calling instance is the first arg. 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 4af6c8936d11..3be3b013403b 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 @@ -4173,7 +4173,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass List? aNullableList, Map? aNullableMap, AnEnum? aNullableEnum, - )? pigeon_detached, + )? pigeon_newInstance, void Function(ProxyIntegrationCoreApi pigeon_instance)? flutterNoop, Object? Function(ProxyIntegrationCoreApi pigeon_instance)? flutterThrowError, @@ -4263,7 +4263,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass pigeon_instanceManager ?? Pigeon_InstanceManager.instance); { const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.pigeon_detached'; + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.pigeon_newInstance'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, @@ -4337,7 +4337,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass args[16] == null ? null : AnEnum.values[args[16]! as int]; (pigeon_instanceManager ?? Pigeon_InstanceManager.instance) .addHostCreatedInstance( - pigeon_detached?.call( + pigeon_newInstance?.call( arg_aBool!, arg_anInt!, arg_aDouble!, @@ -7520,14 +7520,14 @@ class ProxyApiSuperClass extends Pigeon_ProxyApiBaseClass { static void pigeon_setUpMessageHandlers({ BinaryMessenger? pigeon_binaryMessenger, Pigeon_InstanceManager? pigeon_instanceManager, - ProxyApiSuperClass Function()? pigeon_detached, + ProxyApiSuperClass Function()? pigeon_newInstance, }) { final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = _Pigeon_ProxyApiBaseCodec( pigeon_instanceManager ?? Pigeon_InstanceManager.instance); { const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.pigeon_detached'; + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.pigeon_newInstance'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, @@ -7547,7 +7547,7 @@ class ProxyApiSuperClass extends Pigeon_ProxyApiBaseClass { ); (pigeon_instanceManager ?? Pigeon_InstanceManager.instance) .addHostCreatedInstance( - pigeon_detached?.call() ?? + pigeon_newInstance?.call() ?? ProxyApiSuperClass.pigeon_detached( pigeon_binaryMessenger: pigeon_binaryMessenger, pigeon_instanceManager: pigeon_instanceManager, @@ -7609,7 +7609,7 @@ class ProxyApiInterface extends Pigeon_ProxyApiBaseClass { static void pigeon_setUpMessageHandlers({ BinaryMessenger? pigeon_binaryMessenger, Pigeon_InstanceManager? pigeon_instanceManager, - ProxyApiInterface Function()? pigeon_detached, + ProxyApiInterface Function()? pigeon_newInstance, void Function(ProxyApiInterface pigeon_instance)? anInterfaceMethod, }) { final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = @@ -7617,7 +7617,7 @@ class ProxyApiInterface extends Pigeon_ProxyApiBaseClass { pigeon_instanceManager ?? Pigeon_InstanceManager.instance); { const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.pigeon_detached'; + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.pigeon_newInstance'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, @@ -7637,7 +7637,7 @@ class ProxyApiInterface extends Pigeon_ProxyApiBaseClass { ); (pigeon_instanceManager ?? Pigeon_InstanceManager.instance) .addHostCreatedInstance( - pigeon_detached?.call() ?? + pigeon_newInstance?.call() ?? ProxyApiInterface.pigeon_detached( pigeon_binaryMessenger: pigeon_binaryMessenger, pigeon_instanceManager: pigeon_instanceManager, From 235464f1487aeecf87b65870de4fd5e29ff8d657 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 26 Dec 2023 13:00:50 -0500 Subject: [PATCH 59/73] add passing proxy api to core test class --- packages/pigeon/pigeons/core_tests.dart | 28 ++ .../lib/src/generated/core_tests.gen.dart | 385 +++++++++++------- 2 files changed, 276 insertions(+), 137 deletions(-) diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index 87a65268e632..ef15aa279447 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -723,6 +723,8 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass // 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, @@ -738,6 +740,8 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass Map? nullableMapParam, // ignore: avoid_unused_constructor_parameters AnEnum? nullableEnumParam, + // ignore: avoid_unused_constructor_parameters + ProxyApiSuperClass? nullableProxyApiParam, ); late bool aBool; @@ -748,6 +752,7 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass late List aList; late Map aMap; late AnEnum anEnum; + late ProxyApiSuperClass aProxyApi; late bool? aNullableBool; late int? aNullableInt; @@ -757,6 +762,7 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass late List? aNullableList; late Map? aNullableMap; late AnEnum? aNullableEnum; + late ProxyApiSuperClass? aNullableProxyApi; @attached late ProxyApiSuperClass attachedField; @@ -811,6 +817,10 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// 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. @@ -838,6 +848,10 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// 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 @@ -906,6 +920,9 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// 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. @@ -934,6 +951,9 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass AnEnum? echoNullableEnum(AnEnum? anEnum); + /// Returns the passed ProxyApi to test serialization and deserialization. + ProxyApiSuperClass? echoNullableProxyApi(ProxyApiSuperClass? aProxyApi); + // ========== Asynchronous method tests ========== /// A no-op function taking no arguments and returning no value, to sanity @@ -1080,6 +1100,9 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass @async AnEnum callFlutterEchoEnum(AnEnum anEnum); + @async + ProxyApiSuperClass callFlutterEchoProxyApi(ProxyApiSuperClass aProxyApi); + @async bool? callFlutterEchoNullableBool(bool? aBool); @@ -1105,6 +1128,11 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass @async AnEnum? callFlutterEchoNullableEnum(AnEnum? anEnum); + + @async + ProxyApiSuperClass? callFlutterEchoNullableProxyApi( + ProxyApiSuperClass? aProxyApi, + ); } /// ProxyApi to serve as a super class to the core ProxyApi interface. 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 3be3b013403b..c1ab8ddd2e8f 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 @@ -3823,6 +3823,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass required this.aList, required this.aMap, required this.anEnum, + required this.aProxyApi, this.aNullableBool, this.aNullableInt, this.aNullableDouble, @@ -3831,6 +3832,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass this.aNullableList, this.aNullableMap, this.aNullableEnum, + this.aNullableProxyApi, this.anInterfaceMethod, this.flutterNoop, this.flutterThrowError, @@ -3845,6 +3847,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass this.flutterEchoMap, this.flutterEchoProxyApiMap, this.flutterEchoEnum, + required this.flutterEchoProxyApi, this.flutterEchoNullableBool, this.flutterEchoNullableInt, this.flutterEchoNullableDouble, @@ -3853,6 +3856,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass this.flutterEchoNullableList, this.flutterEchoNullableMap, this.flutterEchoNullableEnum, + required this.flutterEchoNullableProxyApi, this.callFlutterNoopAsync, this.callFlutterEchoAsyncString, required bool boolParam, @@ -3863,6 +3867,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass required List listParam, required Map mapParam, required AnEnum enumParam, + required ProxyApiSuperClass proxyApiParam, bool? nullableBoolParam, int? nullableIntParam, double? nullableDoubleParam, @@ -3871,6 +3876,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass List? nullableListParam, Map? nullableMapParam, AnEnum? nullableEnumParam, + ProxyApiSuperClass? nullableProxyApiParam, }) : super.pigeon_detached() { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.pigeon_defaultConstructor'; @@ -3890,6 +3896,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass aList, aMap, anEnum.index, + aProxyApi, aNullableBool, aNullableInt, aNullableDouble, @@ -3898,6 +3905,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass aNullableList, aNullableMap, aNullableEnum?.index, + aNullableProxyApi, boolParam, intParam, doubleParam, @@ -3906,6 +3914,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass listParam, mapParam, enumParam.index, + proxyApiParam, nullableBoolParam, nullableIntParam, nullableDoubleParam, @@ -3914,6 +3923,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass nullableListParam, nullableMapParam, nullableEnumParam?.index, + nullableProxyApiParam, ]).then((Object? value) { final List? __pigeon_replyList = value as List?; if (__pigeon_replyList == null) { @@ -3943,6 +3953,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass required this.aList, required this.aMap, required this.anEnum, + required this.aProxyApi, this.aNullableBool, this.aNullableInt, this.aNullableDouble, @@ -3951,6 +3962,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass this.aNullableList, this.aNullableMap, this.aNullableEnum, + this.aNullableProxyApi, this.anInterfaceMethod, this.flutterNoop, this.flutterThrowError, @@ -3965,6 +3977,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass this.flutterEchoMap, this.flutterEchoProxyApiMap, this.flutterEchoEnum, + required this.flutterEchoProxyApi, this.flutterEchoNullableBool, this.flutterEchoNullableInt, this.flutterEchoNullableDouble, @@ -3973,6 +3986,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass this.flutterEchoNullableList, this.flutterEchoNullableMap, this.flutterEchoNullableEnum, + required this.flutterEchoNullableProxyApi, this.callFlutterNoopAsync, this.callFlutterEchoAsyncString, }) : super.pigeon_detached(); @@ -3996,6 +4010,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final AnEnum anEnum; + final ProxyApiSuperClass aProxyApi; + final bool? aNullableBool; final int? aNullableInt; @@ -4012,6 +4028,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final AnEnum? aNullableEnum; + final ProxyApiSuperClass? aNullableProxyApi; + /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. final void Function(ProxyIntegrationCoreApi pigeon_instance)? flutterNoop; @@ -4086,6 +4104,12 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass AnEnum anEnum, )? flutterEchoEnum; + /// Returns the passed ProxyApi to test serialization and deserialization. + final ProxyApiSuperClass Function( + ProxyIntegrationCoreApi pigeon_instance, + ProxyApiSuperClass aProxyApi, + ) flutterEchoProxyApi; + /// Returns the passed boolean, to test serialization and deserialization. final bool? Function( ProxyIntegrationCoreApi pigeon_instance, @@ -4134,6 +4158,12 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass AnEnum? anEnum, )? flutterEchoNullableEnum; + /// Returns the passed ProxyApi to test serialization and deserialization. + final ProxyApiSuperClass? Function( + ProxyIntegrationCoreApi pigeon_instance, + ProxyApiSuperClass? aProxyApi, + ) flutterEchoNullableProxyApi; + /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. final Future Function(ProxyIntegrationCoreApi pigeon_instance)? @@ -4156,24 +4186,6 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass static void pigeon_setUpMessageHandlers({ BinaryMessenger? pigeon_binaryMessenger, Pigeon_InstanceManager? pigeon_instanceManager, - ProxyIntegrationCoreApi Function( - bool aBool, - int anInt, - double aDouble, - String aString, - Uint8List aUint8List, - List aList, - Map aMap, - AnEnum anEnum, - bool? aNullableBool, - int? aNullableInt, - double? aNullableDouble, - String? aNullableString, - Uint8List? aNullableUint8List, - List? aNullableList, - Map? aNullableMap, - AnEnum? aNullableEnum, - )? pigeon_newInstance, void Function(ProxyIntegrationCoreApi pigeon_instance)? flutterNoop, Object? Function(ProxyIntegrationCoreApi pigeon_instance)? flutterThrowError, @@ -4219,6 +4231,10 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass ProxyIntegrationCoreApi pigeon_instance, AnEnum anEnum, )? flutterEchoEnum, + ProxyApiSuperClass Function( + ProxyIntegrationCoreApi pigeon_instance, + ProxyApiSuperClass aProxyApi, + )? flutterEchoProxyApi, bool? Function( ProxyIntegrationCoreApi pigeon_instance, bool? aBool, @@ -4251,6 +4267,10 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass ProxyIntegrationCoreApi pigeon_instance, AnEnum? anEnum, )? flutterEchoNullableEnum, + ProxyApiSuperClass? Function( + ProxyIntegrationCoreApi pigeon_instance, + ProxyApiSuperClass? aProxyApi, + )? flutterEchoNullableProxyApi, Future Function(ProxyIntegrationCoreApi pigeon_instance)? callFlutterNoopAsync, Future Function( @@ -4261,125 +4281,6 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = _Pigeon_ProxyApiBaseCodec( pigeon_instanceManager ?? Pigeon_InstanceManager.instance); - { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.pigeon_newInstance'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final int? instanceIdentifier = (args[0] as int?); - assert( - instanceIdentifier != null, - 'Argument for $__pigeon_channelName was null, expected non-null int.', - ); - final bool? arg_aBool = (args[1] as bool?); - assert( - arg_aBool != null, - 'Argument for $__pigeon_channelName was null, expected non-null bool.', - ); - final int? arg_anInt = (args[2] as int?); - assert( - arg_anInt != null, - 'Argument for $__pigeon_channelName was null, expected non-null int.', - ); - final double? arg_aDouble = (args[3] as double?); - assert( - arg_aDouble != null, - 'Argument for $__pigeon_channelName was null, expected non-null double.', - ); - final String? arg_aString = (args[4] as String?); - assert( - arg_aString != null, - 'Argument for $__pigeon_channelName was null, expected non-null String.', - ); - final Uint8List? arg_aUint8List = (args[5] as Uint8List?); - assert( - arg_aUint8List != null, - 'Argument for $__pigeon_channelName was null, expected non-null Uint8List.', - ); - final List? arg_aList = - (args[6] as List?)?.cast(); - assert( - arg_aList != null, - 'Argument for $__pigeon_channelName was null, expected non-null List.', - ); - final Map? arg_aMap = - (args[7] as Map?)?.cast(); - assert( - arg_aMap != null, - 'Argument for $__pigeon_channelName 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 $__pigeon_channelName was null, expected non-null AnEnum.', - ); - final bool? arg_aNullableBool = (args[9] as bool?); - final int? arg_aNullableInt = (args[10] as int?); - final double? arg_aNullableDouble = (args[11] as double?); - final String? arg_aNullableString = (args[12] as String?); - final Uint8List? arg_aNullableUint8List = (args[13] as Uint8List?); - final List? arg_aNullableList = - (args[14] as List?)?.cast(); - final Map? arg_aNullableMap = - (args[15] as Map?)?.cast(); - final AnEnum? arg_aNullableEnum = - args[16] == null ? null : AnEnum.values[args[16]! as int]; - (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_aNullableBool, - arg_aNullableInt, - arg_aNullableDouble, - arg_aNullableString, - arg_aNullableUint8List, - arg_aNullableList, - arg_aNullableMap, - arg_aNullableEnum, - ) ?? - ProxyIntegrationCoreApi.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!, - aNullableBool: arg_aNullableBool, - aNullableInt: arg_aNullableInt, - aNullableDouble: arg_aNullableDouble, - aNullableString: arg_aNullableString, - aNullableUint8List: arg_aNullableUint8List, - aNullableList: arg_aNullableList, - aNullableMap: arg_aNullableMap, - aNullableEnum: arg_aNullableEnum, - ), - instanceIdentifier!, - ); - return; - }); - } { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterNoop'; @@ -4910,6 +4811,49 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } }); } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoProxyApi'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: pigeon_binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final ProxyApiSuperClass? arg_aProxyApi = + (args[1] as ProxyApiSuperClass?); + assert( + arg_aProxyApi != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyApiSuperClass.', + ); + try { + final ProxyApiSuperClass output = + (flutterEchoProxyApi ?? instance!.flutterEchoProxyApi).call( + 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()), + ); + } + }); + } { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableBool'; @@ -5225,6 +5169,46 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } }); } + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableProxyApi'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: pigeon_binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? instance = + (args[0] as ProxyIntegrationCoreApi?); + assert( + instance != null, + 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', + ); + final ProxyApiSuperClass? arg_aProxyApi = + (args[1] as ProxyApiSuperClass?); + try { + final ProxyApiSuperClass? output = (flutterEchoNullableProxyApi ?? + instance!.flutterEchoNullableProxyApi) + .call( + 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()), + ); + } + }); + } { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterNoopAsync'; @@ -5834,6 +5818,39 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } } + /// Returns the passed ProxyApi to test serialization and deserialization. + Future echoProxyApi(ProxyApiSuperClass aProxyApi) async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoProxyApi'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + __pigeon_codecProxyIntegrationCoreApi, + 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 { const String __pigeon_channelName = @@ -6090,6 +6107,35 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } } + /// Returns the passed ProxyApi to test serialization and deserialization. + Future echoNullableProxyApi( + ProxyApiSuperClass? aProxyApi) async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableProxyApi'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + __pigeon_codecProxyIntegrationCoreApi, + 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?); + } + } + /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. Future noopAsync() async { @@ -7233,6 +7279,39 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } } + Future callFlutterEchoProxyApi( + ProxyApiSuperClass aProxyApi) async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoProxyApi'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + __pigeon_codecProxyIntegrationCoreApi, + 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 { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableBool'; @@ -7454,6 +7533,34 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } } + Future callFlutterEchoNullableProxyApi( + ProxyApiSuperClass? aProxyApi) async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableProxyApi'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + __pigeon_codecProxyIntegrationCoreApi, + 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?); + } + } + @override ProxyIntegrationCoreApi pigeon_copy() { return ProxyIntegrationCoreApi.pigeon_detached( @@ -7467,6 +7574,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass aList: aList, aMap: aMap, anEnum: anEnum, + aProxyApi: aProxyApi, aNullableBool: aNullableBool, aNullableInt: aNullableInt, aNullableDouble: aNullableDouble, @@ -7475,6 +7583,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass aNullableList: aNullableList, aNullableMap: aNullableMap, aNullableEnum: aNullableEnum, + aNullableProxyApi: aNullableProxyApi, anInterfaceMethod: anInterfaceMethod, flutterNoop: flutterNoop, flutterThrowError: flutterThrowError, @@ -7489,6 +7598,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass flutterEchoMap: flutterEchoMap, flutterEchoProxyApiMap: flutterEchoProxyApiMap, flutterEchoEnum: flutterEchoEnum, + flutterEchoProxyApi: flutterEchoProxyApi, flutterEchoNullableBool: flutterEchoNullableBool, flutterEchoNullableInt: flutterEchoNullableInt, flutterEchoNullableDouble: flutterEchoNullableDouble, @@ -7497,6 +7607,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass flutterEchoNullableList: flutterEchoNullableList, flutterEchoNullableMap: flutterEchoNullableMap, flutterEchoNullableEnum: flutterEchoNullableEnum, + flutterEchoNullableProxyApi: flutterEchoNullableProxyApi, callFlutterNoopAsync: callFlutterNoopAsync, callFlutterEchoAsyncString: callFlutterEchoAsyncString, ); From 66161fc8f1db50553175dc83a678fac2ca40369b Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 26 Dec 2023 15:30:03 -0500 Subject: [PATCH 60/73] verify nonnull attached fields and add docs to callback methods --- packages/pigeon/lib/dart_generator.dart | 25 +- packages/pigeon/lib/pigeon_lib.dart | 21 +- .../lib/src/generated/core_tests.gen.dart | 493 ++++++++++++++++++ 3 files changed, 535 insertions(+), 4 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index f7af14b8f409..24896b12f597 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -1392,7 +1392,30 @@ class $codecName extends StandardMessageCodec { ..name = method.name ..modifier = cb.FieldModifier.final$ ..docs.addAll(asDocumentationComments( - method.documentationComments, + [ + ...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 MyClass instance = MyClass(', + ' myCallbackMethod: (_) {', + ' print(weakMyVariable?.target);', + ' },', + ');', + '```', + '', + 'Alternatively, `$instanceManagerClassName.removeWeakReference` can be used to', + 'release the associated Native object manually.', + ], + ], _docCommentSpec, )) ..type = cb.FunctionType( diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 1d0d756a2890..56dc43ed5b21 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -1136,20 +1136,35 @@ List _validateProxyApi( for (final Field field in api.fields) { if (isDataClass(field)) { result.add(unsupportedDataClassError(field)); - } else if (!isProxyApi(field)) { - if (field.isStatic) { + } 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.isAttached) { + } 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_')) { 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 c1ab8ddd2e8f..d35df20f0cb0 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 @@ -4032,47 +4032,218 @@ class ProxyIntegrationCoreApi 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` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final void Function(ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final Object? Function(ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final void Function(ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final bool Function( ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final int Function( ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final double Function( ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final String Function( ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final Uint8List Function( ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final List Function( ProxyIntegrationCoreApi pigeon_instance, List aList, @@ -4080,12 +4251,50 @@ class ProxyIntegrationCoreApi 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` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final List Function( ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final Map Function( ProxyIntegrationCoreApi pigeon_instance, Map aMap, @@ -4093,72 +4302,300 @@ class ProxyIntegrationCoreApi 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` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final Map Function( ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final AnEnum Function( ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final ProxyApiSuperClass Function( ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final bool? Function( ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final int? Function( ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final double? Function( ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final String? Function( ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final Uint8List? Function( ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final List? Function( ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final Map? Function( ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final AnEnum? Function( ProxyIntegrationCoreApi 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final ProxyApiSuperClass? Function( ProxyIntegrationCoreApi pigeon_instance, ProxyApiSuperClass? aProxyApi, @@ -4166,10 +4603,48 @@ class ProxyIntegrationCoreApi 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` + /// references a non-local variable, it is strongly recommended to access it + /// from a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final Future Function(ProxyIntegrationCoreApi pigeon_instance)? callFlutterNoopAsync; /// 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to + /// release the associated Native object manually. final Future Function( ProxyIntegrationCoreApi pigeon_instance, String aString, @@ -7715,6 +8190,24 @@ class ProxyApiInterface extends Pigeon_ProxyApiBaseClass { 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 MyClass instance = MyClass( + /// myCallbackMethod: (_) { + /// 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({ From 1a8b46477aed6d02334cbc285689fd4a8ff76cc6 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 26 Dec 2023 16:52:05 -0500 Subject: [PATCH 61/73] make all test callback methods nullable --- packages/pigeon/pigeons/core_tests.dart | 4 +- .../lib/src/generated/core_tests.gen.dart | 169 +++++++++++++++++- 2 files changed, 162 insertions(+), 11 deletions(-) diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index ef15aa279447..f1a391d055c8 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -818,7 +818,7 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass late AnEnum Function(AnEnum anEnum)? flutterEchoEnum; /// Returns the passed ProxyApi to test serialization and deserialization. - late ProxyApiSuperClass Function(ProxyApiSuperClass aProxyApi) + late ProxyApiSuperClass Function(ProxyApiSuperClass aProxyApi)? flutterEchoProxyApi; // ========== Nullable argument/return type tests ========== @@ -849,7 +849,7 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass late AnEnum? Function(AnEnum? anEnum)? flutterEchoNullableEnum; /// Returns the passed ProxyApi to test serialization and deserialization. - late ProxyApiSuperClass? Function(ProxyApiSuperClass? aProxyApi) + late ProxyApiSuperClass? Function(ProxyApiSuperClass? aProxyApi)? flutterEchoNullableProxyApi; // ========== Async tests ========== 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 d35df20f0cb0..2f6dac68f068 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 @@ -3847,7 +3847,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass this.flutterEchoMap, this.flutterEchoProxyApiMap, this.flutterEchoEnum, - required this.flutterEchoProxyApi, + this.flutterEchoProxyApi, this.flutterEchoNullableBool, this.flutterEchoNullableInt, this.flutterEchoNullableDouble, @@ -3856,7 +3856,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass this.flutterEchoNullableList, this.flutterEchoNullableMap, this.flutterEchoNullableEnum, - required this.flutterEchoNullableProxyApi, + this.flutterEchoNullableProxyApi, this.callFlutterNoopAsync, this.callFlutterEchoAsyncString, required bool boolParam, @@ -3977,7 +3977,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass this.flutterEchoMap, this.flutterEchoProxyApiMap, this.flutterEchoEnum, - required this.flutterEchoProxyApi, + this.flutterEchoProxyApi, this.flutterEchoNullableBool, this.flutterEchoNullableInt, this.flutterEchoNullableDouble, @@ -3986,7 +3986,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass this.flutterEchoNullableList, this.flutterEchoNullableMap, this.flutterEchoNullableEnum, - required this.flutterEchoNullableProxyApi, + this.flutterEchoNullableProxyApi, this.callFlutterNoopAsync, this.callFlutterEchoAsyncString, }) : super.pigeon_detached(); @@ -4374,7 +4374,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final ProxyApiSuperClass Function( ProxyIntegrationCoreApi pigeon_instance, ProxyApiSuperClass aProxyApi, - ) flutterEchoProxyApi; + )? flutterEchoProxyApi; /// Returns the passed boolean, to test serialization and deserialization. /// @@ -4599,7 +4599,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final ProxyApiSuperClass? Function( ProxyIntegrationCoreApi pigeon_instance, ProxyApiSuperClass? aProxyApi, - ) flutterEchoNullableProxyApi; + )? flutterEchoNullableProxyApi; /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. @@ -4661,6 +4661,26 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass static void pigeon_setUpMessageHandlers({ BinaryMessenger? pigeon_binaryMessenger, Pigeon_InstanceManager? pigeon_instanceManager, + ProxyIntegrationCoreApi 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(ProxyIntegrationCoreApi pigeon_instance)? flutterNoop, Object? Function(ProxyIntegrationCoreApi pigeon_instance)? flutterThrowError, @@ -4756,6 +4776,137 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = _Pigeon_ProxyApiBaseCodec( pigeon_instanceManager ?? Pigeon_InstanceManager.instance); + { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.pigeon_newInstance'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: pigeon_binaryMessenger, + ); + __pigeon_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for $__pigeon_channelName was null.', + ); + final List args = (message as List?)!; + final int? instanceIdentifier = (args[0] as int?); + assert( + instanceIdentifier != null, + 'Argument for $__pigeon_channelName was null, expected non-null int.', + ); + final bool? arg_aBool = (args[1] as bool?); + assert( + arg_aBool != null, + 'Argument for $__pigeon_channelName was null, expected non-null bool.', + ); + final int? arg_anInt = (args[2] as int?); + assert( + arg_anInt != null, + 'Argument for $__pigeon_channelName was null, expected non-null int.', + ); + final double? arg_aDouble = (args[3] as double?); + assert( + arg_aDouble != null, + 'Argument for $__pigeon_channelName was null, expected non-null double.', + ); + final String? arg_aString = (args[4] as String?); + assert( + arg_aString != null, + 'Argument for $__pigeon_channelName was null, expected non-null String.', + ); + final Uint8List? arg_aUint8List = (args[5] as Uint8List?); + assert( + arg_aUint8List != null, + 'Argument for $__pigeon_channelName was null, expected non-null Uint8List.', + ); + final List? arg_aList = + (args[6] as List?)?.cast(); + assert( + arg_aList != null, + 'Argument for $__pigeon_channelName was null, expected non-null List.', + ); + final Map? arg_aMap = + (args[7] as Map?)?.cast(); + assert( + arg_aMap != null, + 'Argument for $__pigeon_channelName 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 $__pigeon_channelName was null, expected non-null AnEnum.', + ); + final ProxyApiSuperClass? arg_aProxyApi = + (args[9] as ProxyApiSuperClass?); + assert( + arg_aProxyApi != null, + 'Argument for $__pigeon_channelName 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?); + (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, + ) ?? + ProxyIntegrationCoreApi.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, + ), + instanceIdentifier!, + ); + return; + }); + } { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterNoop'; @@ -5314,8 +5465,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'Argument for $__pigeon_channelName was null, expected non-null ProxyApiSuperClass.', ); try { - final ProxyApiSuperClass output = - (flutterEchoProxyApi ?? instance!.flutterEchoProxyApi).call( + final ProxyApiSuperClass? output = + (flutterEchoProxyApi ?? instance!.flutterEchoProxyApi)?.call( instance!, arg_aProxyApi!, ); @@ -5670,7 +5821,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass try { final ProxyApiSuperClass? output = (flutterEchoNullableProxyApi ?? instance!.flutterEchoNullableProxyApi) - .call( + ?.call( instance!, arg_aProxyApi, ); From 5fe2e2647341146824467490a311cbed3706783a Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 27 Dec 2023 21:59:26 -0500 Subject: [PATCH 62/73] update test pigeon and docs --- packages/pigeon/lib/ast.dart | 2 +- packages/pigeon/pigeons/core_tests.dart | 16 +++++++++------- .../lib/src/generated/core_tests.gen.dart | 17 +++++++++-------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index ff686b1dfb82..7b0e32511fae 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -386,7 +386,7 @@ class TypeDeclaration { ); } - /// Returns duplicated `TypeDeclaration` with attached `associatedClass` value. + /// Returns duplicated `TypeDeclaration` with attached `associatedProxyApi` value. TypeDeclaration copyWithProxyApi(AstProxyApi proxyApiDefinition) { return TypeDeclaration( baseName: baseName, diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index f1a391d055c8..bf75f3dec126 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -905,7 +905,7 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed list with ProxyApis, to test serialization and /// deserialization. List echoProxyApiList( - List aList, + List aList, ); /// Returns the passed map, to test serialization and deserialization. @@ -913,8 +913,8 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed map with ProxyApis, to test serialization and /// deserialization. - Map echoProxyApiMap( - Map aMap, + Map echoProxyApiMap( + Map aMap, ); /// Returns the passed enum to test serialization and deserialization. @@ -949,10 +949,12 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed map, to test serialization and deserialization. Map? echoNullableMap(Map? aNullableMap); - AnEnum? echoNullableEnum(AnEnum? anEnum); + AnEnum? echoNullableEnum(AnEnum? aNullableEnum); /// Returns the passed ProxyApi to test serialization and deserialization. - ProxyApiSuperClass? echoNullableProxyApi(ProxyApiSuperClass? aProxyApi); + ProxyApiSuperClass? echoNullableProxyApi( + ProxyApiSuperClass? aNullableProxyApi, + ); // ========== Asynchronous method tests ========== @@ -1081,7 +1083,7 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass String callFlutterEchoString(String aString); @async - Uint8List callFlutterEchoUint8List(Uint8List aList); + Uint8List callFlutterEchoUint8List(Uint8List aUint8List); @async List callFlutterEchoList(List aList); @@ -1116,7 +1118,7 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass String? callFlutterEchoNullableString(String? aString); @async - Uint8List? callFlutterEchoNullableUint8List(Uint8List? aList); + Uint8List? callFlutterEchoNullableUint8List(Uint8List? aUint8List); @async List? callFlutterEchoNullableList(List? aList); 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 2f6dac68f068..8f8213bff8d5 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 @@ -6704,7 +6704,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } } - Future echoNullableEnum(AnEnum? anEnum) async { + Future echoNullableEnum(AnEnum? aNullableEnum) async { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableEnum'; final BasicMessageChannel __pigeon_channel = @@ -6716,7 +6716,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final List? __pigeon_replyList = (await __pigeon_channel.send([ this, - anEnum?.index, + aNullableEnum?.index, ]) as List?); if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); @@ -6735,7 +6735,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed ProxyApi to test serialization and deserialization. Future echoNullableProxyApi( - ProxyApiSuperClass? aProxyApi) async { + ProxyApiSuperClass? aNullableProxyApi) async { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableProxyApi'; final BasicMessageChannel __pigeon_channel = @@ -6747,7 +6747,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final List? __pigeon_replyList = (await __pigeon_channel.send([ this, - aProxyApi, + aNullableProxyApi, ]) as List?); if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); @@ -7707,7 +7707,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } } - Future callFlutterEchoUint8List(Uint8List aList) async { + Future callFlutterEchoUint8List(Uint8List aUint8List) async { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoUint8List'; final BasicMessageChannel __pigeon_channel = @@ -7719,7 +7719,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final List? __pigeon_replyList = (await __pigeon_channel.send([ this, - aList, + aUint8List, ]) as List?); if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); @@ -8046,7 +8046,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } } - Future callFlutterEchoNullableUint8List(Uint8List? aList) async { + Future callFlutterEchoNullableUint8List( + Uint8List? aUint8List) async { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableUint8List'; final BasicMessageChannel __pigeon_channel = @@ -8058,7 +8059,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final List? __pigeon_replyList = (await __pigeon_channel.send([ this, - aList, + aUint8List, ]) as List?); if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); From c0d96c0b52e83033036b0c82782d750c584f25a3 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 28 Dec 2023 12:11:27 -0500 Subject: [PATCH 63/73] add constructor to proxyapisuperclass --- packages/pigeon/pigeons/core_tests.dart | 2 ++ .../lib/src/generated/core_tests.gen.dart | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index bf75f3dec126..2fae345e4b9c 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -1140,6 +1140,8 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// ProxyApi to serve as a super class to the core ProxyApi interface. @ProxyApi() abstract class ProxyApiSuperClass { + ProxyApiSuperClass(); + void aSuperMethod(); } 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 8f8213bff8d5..6217c3635ca1 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 @@ -8243,6 +8243,34 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// ProxyApi to serve as a super class to the core ProxyApi interface. class ProxyApiSuperClass extends Pigeon_ProxyApiBaseClass { + ProxyApiSuperClass({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + }) { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.pigeon_defaultConstructor'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + __pigeon_codecProxyApiSuperClass, + binaryMessenger: pigeon_binaryMessenger, + ); + __pigeon_channel.send([ + pigeon_instanceManager.addDartCreatedInstance(this) + ]).then((Object? value) { + final List? __pigeon_replyList = value 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], + ); + } + }); + } + /// Constructs ProxyApiSuperClass without creating the associated native object. /// /// This should only be used by subclasses created by this library or to From ffbe73b262e5b46dd4c4bcd50fb48df1fb7c338e Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 28 Dec 2023 12:38:36 -0500 Subject: [PATCH 64/73] update test pigeon --- packages/pigeon/pigeons/core_tests.dart | 10 ++- .../lib/src/generated/core_tests.gen.dart | 88 +++++++++++++++---- 2 files changed, 80 insertions(+), 18 deletions(-) diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index 2fae345e4b9c..0a98f5b95128 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -860,11 +860,11 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. @async - late void Function()? callFlutterNoopAsync; + late void Function()? flutterNoopAsync; /// Returns the passed in generic Object asynchronously. @async - late String Function(String aString)? callFlutterEchoAsyncString; + late String Function(String aString)? flutterEchoAsyncString; // ========== Synchronous host method tests ========== @@ -1135,6 +1135,12 @@ abstract class ProxyIntegrationCoreApi extends ProxyApiSuperClass ProxyApiSuperClass? callFlutterEchoNullableProxyApi( ProxyApiSuperClass? aProxyApi, ); + + @async + void callFlutterNoopAsync(); + + @async + String callFlutterEchoAsyncString(String aString); } /// ProxyApi to serve as a super class to the core ProxyApi interface. 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 6217c3635ca1..001117986192 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 @@ -3857,8 +3857,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass this.flutterEchoNullableMap, this.flutterEchoNullableEnum, this.flutterEchoNullableProxyApi, - this.callFlutterNoopAsync, - this.callFlutterEchoAsyncString, + this.flutterNoopAsync, + this.flutterEchoAsyncString, required bool boolParam, required int intParam, required double doubleParam, @@ -3987,8 +3987,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass this.flutterEchoNullableMap, this.flutterEchoNullableEnum, this.flutterEchoNullableProxyApi, - this.callFlutterNoopAsync, - this.callFlutterEchoAsyncString, + this.flutterNoopAsync, + this.flutterEchoAsyncString, }) : super.pigeon_detached(); late final _Pigeon_ProxyApiBaseCodec __pigeon_codecProxyIntegrationCoreApi = @@ -4623,7 +4623,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Alternatively, `Pigeon_InstanceManager.removeWeakReference` can be used to /// release the associated Native object manually. final Future Function(ProxyIntegrationCoreApi pigeon_instance)? - callFlutterNoopAsync; + flutterNoopAsync; /// Returns the passed in generic Object asynchronously. /// @@ -4648,7 +4648,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final Future Function( ProxyIntegrationCoreApi pigeon_instance, String aString, - )? callFlutterEchoAsyncString; + )? flutterEchoAsyncString; @override final void Function(ProxyApiInterface instance)? anInterfaceMethod; @@ -4767,11 +4767,11 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass ProxyApiSuperClass? aProxyApi, )? flutterEchoNullableProxyApi, Future Function(ProxyIntegrationCoreApi pigeon_instance)? - callFlutterNoopAsync, + flutterNoopAsync, Future Function( ProxyIntegrationCoreApi pigeon_instance, String aString, - )? callFlutterEchoAsyncString, + )? flutterEchoAsyncString, }) { final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = _Pigeon_ProxyApiBaseCodec( @@ -5837,7 +5837,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } { const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterNoopAsync'; + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterNoopAsync'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, @@ -5857,7 +5857,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', ); try { - await (callFlutterNoopAsync ?? instance!.callFlutterNoopAsync) + await (flutterNoopAsync ?? instance!.flutterNoopAsync) ?.call(instance!); return wrapResponse(empty: true); } on PlatformException catch (e) { @@ -5871,7 +5871,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } { const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoAsyncString'; + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoAsyncString'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, @@ -5896,9 +5896,9 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'Argument for $__pigeon_channelName was null, expected non-null String.', ); try { - final String? output = await (callFlutterEchoAsyncString ?? - instance!.callFlutterEchoAsyncString) - ?.call( + final String? output = + await (flutterEchoAsyncString ?? instance!.flutterEchoAsyncString) + ?.call( instance!, arg_aString!, ); @@ -8188,6 +8188,62 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } } + Future callFlutterNoopAsync() async { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterNoopAsync'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + __pigeon_codecProxyIntegrationCoreApi, + 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 { + const String __pigeon_channelName = + r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoAsyncString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + __pigeon_codecProxyIntegrationCoreApi, + 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 ProxyIntegrationCoreApi pigeon_copy() { return ProxyIntegrationCoreApi.pigeon_detached( @@ -8235,8 +8291,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass flutterEchoNullableMap: flutterEchoNullableMap, flutterEchoNullableEnum: flutterEchoNullableEnum, flutterEchoNullableProxyApi: flutterEchoNullableProxyApi, - callFlutterNoopAsync: callFlutterNoopAsync, - callFlutterEchoAsyncString: callFlutterEchoAsyncString, + flutterNoopAsync: flutterNoopAsync, + flutterEchoAsyncString: flutterEchoAsyncString, ); } } From c4f589e2d50a0974b4706c142fc106dbd667f9f5 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 28 Dec 2023 13:50:36 -0500 Subject: [PATCH 65/73] fix formatting some --- packages/pigeon/lib/dart_generator.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 24896b12f597..a5160550b577 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -1104,7 +1104,7 @@ class $codecName extends StandardMessageCodec { ); final cb.DartEmitter emitter = cb.DartEmitter(useNullSafetySyntax: true); - indent.writeln(DartFormatter().format('${proxyApi.accept(emitter)}')); + indent.write(DartFormatter().format('${proxyApi.accept(emitter)}')); } Iterable _proxyApiConstructors( From 716cd7922d774cd3d24d6286beee7c50e69277ac Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 5 Jan 2024 20:32:19 -0500 Subject: [PATCH 66/73] dont have repeating code start --- packages/pigeon/lib/dart_generator.dart | 369 +++++++++--------- .../lib/src/generated/core_tests.gen.dart | 146 +++---- 2 files changed, 257 insertions(+), 258 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index a5160550b577..ae962246c701 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -355,7 +355,9 @@ $resultAt != null final String returnType = isAsync ? 'Future<${_addGenericTypesNullable(func.returnType)}>' : _addGenericTypesNullable(func.returnType); - final String argSignature = _getMethodParameterSignature(func); + final String argSignature = _getMethodParameterSignature( + func.parameters, + ); indent.writeln('$returnType ${func.name}($argSignature);'); indent.newln(); } @@ -531,88 +533,14 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; } else { first = false; } - addDocumentationComments( - indent, func.documentationComments, _docCommentSpec); - String argSignature = ''; - String sendArgument = 'null'; - if (func.parameters.isNotEmpty) { - final Iterable argExpressions = - func.parameters.mapIndexed((int index, NamedType type) { - final String name = _getParameterName(index, type); - if (type.type.isEnum) { - return '$name${type.type.isNullable ? '?' : ''}.index'; - } else { - return name; - } - }); - sendArgument = '[${argExpressions.join(', ')}]'; - argSignature = _getMethodParameterSignature(func); - } - indent.write( - 'Future<${_addGenericTypesNullable(func.returnType)}> ${func.name}($argSignature) async ', + _writeHostMethod( + indent, + name: func.name, + parameters: func.parameters, + returnType: func.returnType, + documentationComments: func.documentationComments, + channelName: makeChannelName(api, func, dartPackageName), ); - indent.addScoped('{', '}', () { - indent.writeln( - "const String ${_varNamePrefix}channelName = '${makeChannelName(api, func, dartPackageName)}';"); - indent.writeScoped( - 'final BasicMessageChannel ${_varNamePrefix}channel = BasicMessageChannel(', - ');', () { - indent.writeln('${_varNamePrefix}channelName,'); - indent.writeln('$_pigeonChannelCodec,'); - indent - .writeln('binaryMessenger: ${_varNamePrefix}binaryMessenger,'); - }); - final String returnType = _makeGenericTypeArguments(func.returnType); - final String genericCastCall = _makeGenericCastCall(func.returnType); - const String accessor = '${_varNamePrefix}replyList[0]'; - // Avoid warnings from pointlessly casting to `Object?`. - final String nullablyTypedAccessor = - returnType == 'Object' ? accessor : '($accessor as $returnType?)'; - final String nullHandler = func.returnType.isNullable - ? (genericCastCall.isEmpty ? '' : '?') - : '!'; - String returnStatement = 'return'; - if (func.returnType.isEnum) { - if (func.returnType.isNullable) { - returnStatement = - '$returnStatement ($accessor as int?) == null ? null : $returnType.values[$accessor! as int]'; - } else { - returnStatement = - '$returnStatement $returnType.values[$accessor! as int]'; - } - } else if (!func.returnType.isVoid) { - returnStatement = - '$returnStatement $nullablyTypedAccessor$nullHandler$genericCastCall'; - } - returnStatement = '$returnStatement;'; - - indent.format(''' -final List? ${_varNamePrefix}replyList = -\t\tawait ${_varNamePrefix}channel.send($sendArgument) as List?; -if (${_varNamePrefix}replyList == null) { -\tthrow _createConnectionError(${_varNamePrefix}channelName); -} else if (${_varNamePrefix}replyList.length > 1) { -\tthrow PlatformException( -\t\tcode: ${_varNamePrefix}replyList[0]! as String, -\t\tmessage: ${_varNamePrefix}replyList[1] as String?, -\t\tdetails: ${_varNamePrefix}replyList[2], -\t);'''); - // On iOS we can return nil from functions to accommodate error - // handling. Returning a nil value and not returning an error is an - // exception. - if (!func.returnType.isNullable && !func.returnType.isVoid) { - indent.format(''' -} else if (${_varNamePrefix}replyList[0] == null) { -\tthrow PlatformException( -\t\tcode: 'null-error', -\t\tmessage: 'Host platform returned null value for non-null return value.', -\t);'''); - } - indent.format(''' -} else { -\t$returnStatement -}'''); - }); } }); } @@ -1068,6 +996,7 @@ class $codecName extends StandardMessageCodec { api.constructors, apiName: api.name, dartPackageName: dartPackageName, + codecName: codecName, codecInstanceName: codecInstanceName, superClassApi: superClassApi, unattachedFields: api.unattachedFields, @@ -1111,6 +1040,7 @@ class $codecName extends StandardMessageCodec { Iterable constructors, { required String apiName, required String dartPackageName, + required String codecName, required String codecInstanceName, required AstProxyApi? superClassApi, required Iterable unattachedFields, @@ -1118,6 +1048,18 @@ class $codecName extends StandardMessageCodec { 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 = '${classMemberNamePrefix}instanceManager' + ..named = true + ..toSuper = true, + ); return [ // All constructors for this api defined in the pigeon file. ...constructors.map( @@ -1138,18 +1080,8 @@ class $codecName extends StandardMessageCodec { )) ..optionalParameters.addAll( [ - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = '${classMemberNamePrefix}binaryMessenger' - ..named = true - ..toSuper = true, - ), - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = '${classMemberNamePrefix}instanceManager' - ..named = true - ..toSuper = true, - ), + binaryMessengerParameter, + instanceManagerParameter, for (final Field field in unattachedFields) cb.Parameter( (cb.ParameterBuilder builder) => builder @@ -1201,87 +1133,43 @@ class $codecName extends StandardMessageCodec { const cb.Code('super.${classMemberNamePrefix}detached()') ], ) - ..body = cb.Block.of([ - cb.Code( - "const String ${_varNamePrefix}channelName = r'$channelName';", - ), - _basicMessageChannel( - codec: cb.refer(codecInstanceName), - binaryMessenger: - cb.refer('${classMemberNamePrefix}binaryMessenger'), - ), - // __pigeon_channel.send([]).then((Object? value) { ... }); - cb - .refer('${_varNamePrefix}channel.send') - .call([ - // List of arguments for the method call - // [, ..., ...] - cb.literalList( - [ - cb.refer( - '${classMemberNamePrefix}instanceManager.addDartCreatedInstance(this)', - ), - ...unattachedFields.mapIndexed(_hostMessageArgument), - ...constructor.parameters.mapIndexed( - _hostMessageArgument, - ) - ], - cb.refer('Object?'), - ) - ]) - .property('then') - .call( - [ - // This creates a lambda Function `(Object? value) {...}` - cb.Method( - (cb.MethodBuilder builder) => builder - ..requiredParameters.add( - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = 'value' - ..type = cb.refer('Object?'), - ), - ) - // Body of lambda function - ..body = cb.Block.of([ - const cb.Code( - 'final List? ${_varNamePrefix}replyList = value as List?;', - ), - const cb.Code( - 'if (${_varNamePrefix}replyList == null) {', - ), - const cb.Code( - 'throw _createConnectionError(${_varNamePrefix}channelName);', - ), - const cb.Code( - '} else if (${_varNamePrefix}replyList.length > 1) {', - ), - cb.InvokeExpression.newOf( - cb.refer('PlatformException'), - [], - { - 'code': cb - .refer('${_varNamePrefix}replyList') - .index(cb.literal(0)) - .nullChecked - .asA(cb.refer('String')), - 'message': cb - .refer('${_varNamePrefix}replyList') - .index(cb.literal(1)) - .asA(cb.refer('String?')), - 'details': cb - .refer('${_varNamePrefix}replyList') - .index(cb.literal(2)), - }).thrown.statement, - const cb.Code('}'), - ]), - ).genericClosure - ], - {}, - [cb.refer('void')], - ) - .statement - ]); + ..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( + (Field field) => Parameter( + name: field.name, + type: field.type, + ), + ), + ...constructor.parameters, + ], + returnType: const TypeDeclaration.voidDeclaration(), + ); + builder.statements.addAll([ + const cb.Code( + 'final int ${_varNamePrefix}instanceIdentifier = ${classMemberNamePrefix}instanceManager.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('}();'), + ]); + }, + ); }, ), ), @@ -1300,18 +1188,8 @@ class $codecName extends StandardMessageCodec { '/// create copies.', ]) ..optionalParameters.addAll([ - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = '${classMemberNamePrefix}binaryMessenger' - ..named = true - ..toSuper = true, - ), - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = '${classMemberNamePrefix}instanceManager' - ..named = true - ..toSuper = true, - ), + binaryMessengerParameter, + instanceManagerParameter, for (final Field field in unattachedFields) cb.Parameter( (cb.ParameterBuilder builder) => builder @@ -2243,6 +2121,113 @@ PlatformException _createConnectionError(String channelName) { \t\tcode: 'channel-error', \t\tmessage: 'Unable to establish connection on channel: "\$channelName".', \t); +}'''); + } + + void _writeHostMethod( + Indent indent, { + required String name, + required Iterable parameters, + required TypeDeclaration returnType, + required List documentationComments, + required String channelName, + }) { + addDocumentationComments(indent, documentationComments, _docCommentSpec); + String argSignature = ''; + if (parameters.isNotEmpty) { + argSignature = _getMethodParameterSignature(parameters); + } + indent.write( + 'Future<${_addGenericTypesNullable(returnType)}> $name($argSignature) async ', + ); + indent.addScoped('{', '}', () { + _writeHostMethodMessageCall( + indent, + channelName: channelName, + parameters: parameters, + returnType: returnType, + ); + }); + } + + void _writeHostMethodMessageCall( + Indent indent, { + required String channelName, + required Iterable parameters, + required TypeDeclaration returnType, + }) { + String sendArgument = 'null'; + if (parameters.isNotEmpty) { + final Iterable argExpressions = + parameters.mapIndexed((int index, NamedType type) { + final String name = _getParameterName(index, type); + if (type.type.isEnum) { + return '$name${type.type.isNullable ? '?' : ''}.index'; + } else { + return name; + } + }); + sendArgument = '[${argExpressions.join(', ')}]'; + } + + indent + .writeln("const String ${_varNamePrefix}channelName = '$channelName';"); + indent.writeScoped( + 'final BasicMessageChannel ${_varNamePrefix}channel = BasicMessageChannel(', + ');', () { + indent.writeln('${_varNamePrefix}channelName,'); + indent.writeln('$_pigeonChannelCodec,'); + indent.writeln('binaryMessenger: ${_varNamePrefix}binaryMessenger,'); + }); + final String returnTypeName = _makeGenericTypeArguments(returnType); + final String genericCastCall = _makeGenericCastCall(returnType); + const String accessor = '${_varNamePrefix}replyList[0]'; + // Avoid warnings from pointlessly casting to `Object?`. + final String nullablyTypedAccessor = returnTypeName == 'Object' + ? accessor + : '($accessor as $returnTypeName?)'; + final String nullHandler = + returnType.isNullable ? (genericCastCall.isEmpty ? '' : '?') : '!'; + String returnStatement = 'return'; + if (returnType.isEnum) { + if (returnType.isNullable) { + returnStatement = + '$returnStatement ($accessor as int?) == null ? null : $returnTypeName.values[$accessor! as int]'; + } else { + returnStatement = + '$returnStatement $returnTypeName.values[$accessor! as int]'; + } + } else if (!returnType.isVoid) { + returnStatement = + '$returnStatement $nullablyTypedAccessor$nullHandler$genericCastCall'; + } + returnStatement = '$returnStatement;'; + + indent.format(''' +final List? ${_varNamePrefix}replyList = +\t\tawait ${_varNamePrefix}channel.send($sendArgument) as List?; +if (${_varNamePrefix}replyList == null) { +\tthrow _createConnectionError(${_varNamePrefix}channelName); +} else if (${_varNamePrefix}replyList.length > 1) { +\tthrow PlatformException( +\t\tcode: ${_varNamePrefix}replyList[0]! as String, +\t\tmessage: ${_varNamePrefix}replyList[1] as String?, +\t\tdetails: ${_varNamePrefix}replyList[2], +\t);'''); + // On iOS we can return nil from functions to accommodate error + // handling. Returning a nil value and not returning an error is an + // exception. + if (!returnType.isNullable && !returnType.isVoid) { + indent.format(''' +} else if (${_varNamePrefix}replyList[0] == null) { +\tthrow PlatformException( +\t\tcode: 'null-error', +\t\tmessage: 'Host platform returned null value for non-null return value.', +\t);'''); + } + indent.format(''' +} else { +\t$returnStatement }'''); } } @@ -2483,20 +2468,20 @@ String _getParameterName(int count, NamedType field) => /// Generates the parameters code for [func] /// Example: (func, _getParameterName) -> 'String? foo, int bar' -String _getMethodParameterSignature(Method func) { +String _getMethodParameterSignature(Iterable parameters) { String signature = ''; - if (func.parameters.isEmpty) { + if (parameters.isEmpty) { return signature; } - final List requiredPositionalParams = func.parameters + final List requiredPositionalParams = parameters .where((Parameter p) => p.isPositional && !p.isOptional) .toList(); - final List optionalPositionalParams = func.parameters + final List optionalPositionalParams = parameters .where((Parameter p) => p.isPositional && p.isOptional) .toList(); final List namedParams = - func.parameters.where((Parameter p) => !p.isPositional).toList(); + parameters.where((Parameter p) => !p.isPositional).toList(); String getParameterString(Parameter p) { final String required = p.isRequired && !p.isPositional ? 'required ' : ''; 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 001117986192..30b7e97e5a3f 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 @@ -3878,64 +3878,72 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass AnEnum? nullableEnumParam, ProxyApiSuperClass? nullableProxyApiParam, }) : super.pigeon_detached() { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.pigeon_defaultConstructor'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.send([ - pigeon_instanceManager.addDartCreatedInstance(this), - 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, - ]).then((Object? value) { - final List? __pigeon_replyList = value as List?; + final int __pigeon_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; + () async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); + } else { + return; } - }); + }(); } /// Constructs ProxyIntegrationCoreApi without creating the associated native object. @@ -8303,28 +8311,34 @@ class ProxyApiSuperClass extends Pigeon_ProxyApiBaseClass { super.pigeon_binaryMessenger, super.pigeon_instanceManager, }) { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.pigeon_defaultConstructor'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - __pigeon_codecProxyApiSuperClass, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.send([ - pigeon_instanceManager.addDartCreatedInstance(this) - ]).then((Object? value) { - final List? __pigeon_replyList = value as List?; + 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?), + 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. From 1630fa6773df9ed01ef45c0f8c14d9a36bceb8e3 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 5 Jan 2024 21:00:29 -0500 Subject: [PATCH 67/73] fix up host methods --- packages/pigeon/lib/dart_generator.dart | 160 +- .../lib/src/generated/core_tests.gen.dart | 1396 +++++++++-------- 2 files changed, 759 insertions(+), 797 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index ae962246c701..c1a5ce097a45 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -1837,85 +1837,44 @@ class $codecName extends StandardMessageCodec { ), ], ]) - ..body = cb.Block.of([ - cb.Code( - "const String ${_varNamePrefix}channelName = r'${makeChannelNameWithStrings( - apiName: apiName, - methodName: method.name, - dartPackageName: dartPackageName, - )}';", - ), - _basicMessageChannel( - codec: !method.isStatic - ? cb.refer(codecInstanceName) - : cb.refer( - '$codecName(${classMemberNamePrefix}instanceManager ?? $instanceManagerClassName.instance)', + ..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, + ), ), - binaryMessenger: - cb.refer('${classMemberNamePrefix}binaryMessenger'), - ), - const cb.Code( - 'final List? ${_varNamePrefix}replyList ='), - cb - .refer('${_varNamePrefix}channel.send') - .call([ - cb.literalList( - [ - if (!method.isStatic) cb.refer('this'), - ...method.parameters.mapIndexed(_hostMessageArgument), - ], - cb.refer('Object?'), - ) - ]) - .awaited - .asA(cb.refer('List?')) - .statement, - const cb.Code('if (${_varNamePrefix}replyList == null) {'), - const cb.Code( - 'throw _createConnectionError(${_varNamePrefix}channelName);', - ), - const cb.Code( - '} else if (${_varNamePrefix}replyList.length > 1) {', - ), - cb.InvokeExpression.newOf( - cb.refer('PlatformException'), - [], - { - 'code': cb - .refer('${_varNamePrefix}replyList') - .index(cb.literal(0)) - .nullChecked - .asA(cb.refer('String')), - 'message': cb - .refer('${_varNamePrefix}replyList') - .index(cb.literal(1)) - .asA(cb.refer('String?')), - 'details': cb - .refer('${_varNamePrefix}replyList') - .index(cb.literal(2)), - }).thrown.statement, - // On iOS we can return nil from functions to accommodate error - // handling. Returning a nil value and not returning an error is an - // exception. - if (!method.returnType.isNullable && - !method.returnType.isVoid) ...[ - const cb.Code( - '} else if (${_varNamePrefix}replyList[0] == null) {', - ), - cb.InvokeExpression.newOf( - cb.refer('PlatformException'), - [], - { - 'code': cb.literalString('null-error'), - 'message': cb.literalString( - 'Host platform returned null value for non-null return value.', - ) - }).thrown.statement, - ], - const cb.Code('} else {'), - _unwrapReturnValue(method.returnType).returned.statement, - const cb.Code('}'), - ]), + ...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(${classMemberNamePrefix}instanceManager ?? $instanceManagerClassName.instance);', + ), + const cb.Code( + 'final BinaryMessenger? ${_varNamePrefix}binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', + ), + cb.Code(messageCallSink.toString()), + ]); + }, + ), ), cb.Method( (cb.MethodBuilder builder) => builder @@ -2238,28 +2197,6 @@ extension on cb.Expression { cb.Expression nullCheckedIf(bool condition) => condition ? nullChecked : this; } -cb.Expression _unwrapReturnValue(TypeDeclaration returnType) { - final String type = _makeGenericTypeArguments(returnType); - final String genericCastCall = _makeGenericCastCall(returnType); - const String accessor = '${_varNamePrefix}replyList[0]'; - final String nullablyTypedAccessor = - type == 'Object' ? accessor : '($accessor as $type?)'; - final String nullHandler = - returnType.isNullable ? (genericCastCall.isEmpty ? '' : '?') : '!'; - if (returnType.isEnum) { - if (returnType.isNullable) { - return cb.refer( - '($accessor as int?) == null ? null : $type.values[$accessor! as int]', - ); - } else { - return cb.refer('$type.values[$accessor! as int]'); - } - } else if (!returnType.isVoid) { - return cb.refer('$nullablyTypedAccessor$nullHandler$genericCastCall'); - } - return cb.refer(''); -} - cb.Expression _wrapResultResponse(Method method) { final TypeDeclaration returnType = method.returnType; return cb.refer('wrapResponse').call( @@ -2347,29 +2284,6 @@ cb.Code _basicMessageChannel({ .statement; } -/// Converts enums to use their index. -/// -/// ```dart -/// apple, banana, myEnum${type.isNullable : '?' : ''}.index -/// ``` -cb.Expression _hostMessageArgument( - int index, - NamedType type, { - String Function(int index, NamedType type) getArgumentName = - _getParameterName, -}) { - final cb.Reference nameRef = cb.refer(getArgumentName(index, type)); - if (type.type.isEnum) { - if (type.type.isNullable) { - return nameRef.nullSafeProperty('index'); - } else { - return nameRef.property('index'); - } - } else { - return nameRef; - } -} - cb.Reference _refer( String symbol, { bool isFuture = false, 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 30b7e97e5a3f..db4373680232 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 @@ -5984,22 +5984,25 @@ class ProxyIntegrationCoreApi 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 = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.noop'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.noop'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([this]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -6009,22 +6012,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns an error, to test error handling. Future throwError() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.throwError'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.throwError'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([this]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -6034,22 +6040,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns an error from a void function, to test error handling. Future throwErrorFromVoid() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.throwErrorFromVoid'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.throwErrorFromVoid'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([this]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -6059,22 +6068,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns a Flutter error, to test error handling. Future throwFlutterError() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.throwFlutterError'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.throwFlutterError'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([this]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -6084,25 +6096,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns passed in int. Future echoInt(int anInt) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoInt'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoInt'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - anInt, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -6117,25 +6129,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns passed in double. Future echoDouble(double aDouble) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoDouble'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoDouble'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aDouble, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -6150,25 +6162,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed in boolean. Future echoBool(bool aBool) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoBool'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoBool'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aBool, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -6183,25 +6195,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed in string. Future echoString(String aString) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoString'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoString'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aString, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -6216,25 +6228,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed in Uint8List. Future echoUint8List(Uint8List aUint8List) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoUint8List'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoUint8List'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aUint8List, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -6249,25 +6261,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed in generic Object. Future echoObject(Object anObject) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoObject'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoObject'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - anObject, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -6282,25 +6294,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed list, to test serialization and deserialization. Future> echoList(List aList) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoList'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoList'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aList, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -6317,25 +6329,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// deserialization. Future> echoProxyApiList( List aList) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoProxyApiList'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoProxyApiList'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aList, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -6351,25 +6363,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed map, to test serialization and deserialization. Future> echoMap(Map aMap) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoMap'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoMap'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aMap, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -6387,25 +6399,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// deserialization. Future> echoProxyApiMap( Map aMap) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoProxyApiMap'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoProxyApiMap'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aMap, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -6421,25 +6433,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed enum to test serialization and deserialization. Future echoEnum(AnEnum anEnum) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoEnum'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoEnum'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - anEnum.index, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -6454,25 +6466,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed ProxyApi to test serialization and deserialization. Future echoProxyApi(ProxyApiSuperClass aProxyApi) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoProxyApi'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoProxyApi'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aProxyApi, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -6487,25 +6499,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns passed in int. Future echoNullableInt(int? aNullableInt) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableInt'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableInt'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aNullableInt, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -6515,25 +6527,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns passed in double. Future echoNullableDouble(double? aNullableDouble) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableDouble'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableDouble'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aNullableDouble, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -6543,25 +6555,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed in boolean. Future echoNullableBool(bool? aNullableBool) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableBool'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableBool'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aNullableBool, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -6571,25 +6583,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed in string. Future echoNullableString(String? aNullableString) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableString'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableString'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aNullableString, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -6600,25 +6612,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed in Uint8List. Future echoNullableUint8List( Uint8List? aNullableUint8List) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableUint8List'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableUint8List'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aNullableUint8List, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -6628,25 +6640,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed in generic Object. Future echoNullableObject(Object? aNullableObject) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableObject'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableObject'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aNullableObject, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -6656,25 +6668,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed list, to test serialization and deserialization. Future?> echoNullableList(List? aNullableList) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableList'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableList'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aNullableList, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -6685,25 +6697,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed map, to test serialization and deserialization. Future?> echoNullableMap( Map? aNullableMap) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableMap'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableMap'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aNullableMap, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -6713,25 +6725,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } Future echoNullableEnum(AnEnum? aNullableEnum) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableEnum'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableEnum'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aNullableEnum?.index, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -6744,25 +6756,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed ProxyApi to test serialization and deserialization. Future echoNullableProxyApi( ProxyApiSuperClass? aNullableProxyApi) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableProxyApi'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoNullableProxyApi'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aNullableProxyApi, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -6773,22 +6785,25 @@ class ProxyIntegrationCoreApi 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 = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.noopAsync'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.noopAsync'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([this]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -6798,25 +6813,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns passed in int asynchronously. Future echoAsyncInt(int anInt) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncInt'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncInt'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - anInt, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -6831,25 +6846,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns passed in double asynchronously. Future echoAsyncDouble(double aDouble) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncDouble'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncDouble'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aDouble, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -6864,25 +6879,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed in boolean asynchronously. Future echoAsyncBool(bool aBool) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncBool'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncBool'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aBool, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -6897,25 +6912,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed string asynchronously. Future echoAsyncString(String aString) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncString'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncString'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aString, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -6930,25 +6945,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed in Uint8List asynchronously. Future echoAsyncUint8List(Uint8List aUint8List) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncUint8List'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncUint8List'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aUint8List, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -6963,25 +6978,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed in generic Object asynchronously. Future echoAsyncObject(Object anObject) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncObject'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncObject'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - anObject, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -6996,25 +7011,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed list, to test asynchronous serialization and deserialization. Future> echoAsyncList(List aList) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncList'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncList'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aList, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -7029,25 +7044,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed map, to test asynchronous serialization and deserialization. Future> echoAsyncMap(Map aMap) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncMap'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncMap'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aMap, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -7063,25 +7078,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed enum, to test asynchronous serialization and deserialization. Future echoAsyncEnum(AnEnum anEnum) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncEnum'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncEnum'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - anEnum.index, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -7096,22 +7111,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Responds with an error from an async function returning a value. Future throwAsyncError() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.throwAsyncError'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.throwAsyncError'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([this]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -7121,22 +7139,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Responds with an error from an async void function. Future throwAsyncErrorFromVoid() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.throwAsyncErrorFromVoid'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.throwAsyncErrorFromVoid'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([this]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -7146,22 +7167,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Responds with a Flutter error from an async function returning a value. Future throwAsyncFlutterError() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.throwAsyncFlutterError'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.throwAsyncFlutterError'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([this]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -7171,25 +7195,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns passed in int asynchronously. Future echoAsyncNullableInt(int? anInt) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableInt'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableInt'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - anInt, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -7199,25 +7223,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns passed in double asynchronously. Future echoAsyncNullableDouble(double? aDouble) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableDouble'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableDouble'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aDouble, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -7227,25 +7251,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed in boolean asynchronously. Future echoAsyncNullableBool(bool? aBool) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableBool'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableBool'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aBool, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -7255,25 +7279,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed string asynchronously. Future echoAsyncNullableString(String? aString) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableString'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableString'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aString, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -7283,25 +7307,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed in Uint8List asynchronously. Future echoAsyncNullableUint8List(Uint8List? aUint8List) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableUint8List'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableUint8List'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aUint8List, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -7311,25 +7335,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed in generic Object asynchronously. Future echoAsyncNullableObject(Object? anObject) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableObject'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableObject'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - anObject, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -7339,25 +7363,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed list, to test asynchronous serialization and deserialization. Future?> echoAsyncNullableList(List? aList) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableList'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableList'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aList, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -7368,25 +7392,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed map, to test asynchronous serialization and deserialization. Future?> echoAsyncNullableMap( Map? aMap) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableMap'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableMap'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aMap, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -7397,25 +7421,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// Returns the passed enum, to test asynchronous serialization and deserialization. Future echoAsyncNullableEnum(AnEnum? anEnum) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableEnum'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoAsyncNullableEnum'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - anEnum?.index, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -7429,23 +7453,26 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 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 = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.staticNoop'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.staticNoop'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _Pigeon_ProxyApiBaseCodec( - pigeon_instanceManager ?? Pigeon_InstanceManager.instance), - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -7458,23 +7485,26 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 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 = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoStaticString'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.echoStaticString'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _Pigeon_ProxyApiBaseCodec( - pigeon_instanceManager ?? Pigeon_InstanceManager.instance), - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([aString]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -7491,23 +7521,26 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 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 = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.staticAsyncNoop'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.staticAsyncNoop'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - _Pigeon_ProxyApiBaseCodec( - pigeon_instanceManager ?? Pigeon_InstanceManager.instance), - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -7516,22 +7549,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } Future callFlutterNoop() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterNoop'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterNoop'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([this]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -7540,22 +7576,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } Future callFlutterThrowError() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterThrowError'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterThrowError'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([this]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -7564,22 +7603,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } Future callFlutterThrowErrorFromVoid() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterThrowErrorFromVoid'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterThrowErrorFromVoid'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([this]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -7588,25 +7630,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } Future callFlutterEchoBool(bool aBool) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoBool'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoBool'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aBool, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -7620,25 +7662,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } Future callFlutterEchoInt(int anInt) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoInt'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoInt'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - anInt, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -7652,25 +7694,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } Future callFlutterEchoDouble(double aDouble) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoDouble'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoDouble'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aDouble, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -7684,25 +7726,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } Future callFlutterEchoString(String aString) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoString'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoString'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aString, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -7716,25 +7758,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } Future callFlutterEchoUint8List(Uint8List aUint8List) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoUint8List'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoUint8List'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aUint8List, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -7748,25 +7790,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } Future> callFlutterEchoList(List aList) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoList'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoList'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aList, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -7781,25 +7823,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass Future> callFlutterEchoProxyApiList( List aList) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoProxyApiList'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoProxyApiList'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aList, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -7815,25 +7857,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass Future> callFlutterEchoMap( Map aMap) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoMap'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoMap'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aMap, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -7849,25 +7891,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass Future> callFlutterEchoProxyApiMap( Map aMap) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoProxyApiMap'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoProxyApiMap'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aMap, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -7882,25 +7924,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } Future callFlutterEchoEnum(AnEnum anEnum) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoEnum'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoEnum'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - anEnum.index, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -7915,25 +7957,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass Future callFlutterEchoProxyApi( ProxyApiSuperClass aProxyApi) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoProxyApi'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoProxyApi'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aProxyApi, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -7947,25 +7989,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } Future callFlutterEchoNullableBool(bool? aBool) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableBool'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableBool'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aBool, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -7974,25 +8016,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } Future callFlutterEchoNullableInt(int? anInt) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableInt'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableInt'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - anInt, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -8001,25 +8043,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } Future callFlutterEchoNullableDouble(double? aDouble) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableDouble'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableDouble'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aDouble, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -8028,25 +8070,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } Future callFlutterEchoNullableString(String? aString) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableString'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableString'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aString, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -8056,25 +8098,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass Future callFlutterEchoNullableUint8List( Uint8List? aUint8List) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableUint8List'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableUint8List'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aUint8List, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -8084,25 +8126,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass Future?> callFlutterEchoNullableList( List? aList) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableList'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableList'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aList, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -8112,25 +8154,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass Future?> callFlutterEchoNullableMap( Map? aMap) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableMap'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableMap'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aMap, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -8140,25 +8182,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } Future callFlutterEchoNullableEnum(AnEnum? anEnum) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableEnum'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableEnum'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - anEnum?.index, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -8170,25 +8212,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass Future callFlutterEchoNullableProxyApi( ProxyApiSuperClass? aProxyApi) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableProxyApi'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoNullableProxyApi'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aProxyApi, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -8197,22 +8239,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } Future callFlutterNoopAsync() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterNoopAsync'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterNoopAsync'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([this]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { @@ -8221,25 +8266,25 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass } Future callFlutterEchoAsyncString(String aString) async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoAsyncString'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.callFlutterEchoAsyncString'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([ - this, - aString, - ]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else if (__pigeon_replyList[0] == null) { @@ -8396,22 +8441,25 @@ class ProxyApiSuperClass extends Pigeon_ProxyApiBaseClass { } Future aSuperMethod() async { + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyApiSuperClass; + final BinaryMessenger? __pigeon_binaryMessenger = pigeon_binaryMessenger; const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.aSuperMethod'; + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.aSuperMethod'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, - __pigeon_codecProxyApiSuperClass, - binaryMessenger: pigeon_binaryMessenger, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - (await __pigeon_channel.send([this]) as List?); + 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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); } else { From 6fb56be762b84a817bb5d6f28ec3f7429ba6c748 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 5 Jan 2024 21:59:30 -0500 Subject: [PATCH 68/73] update fields --- packages/pigeon/lib/dart_generator.dart | 166 +++++++--------- .../lib/src/generated/core_tests.gen.dart | 177 ++++++++++-------- 2 files changed, 166 insertions(+), 177 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index c1a5ce097a45..32c296f3c1f1 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -1283,8 +1283,8 @@ class $codecName extends StandardMessageCodec { '', '```dart', 'final WeakReference weakMyVariable = WeakReference(myVariable);', - 'final MyClass instance = MyClass(', - ' myCallbackMethod: (_) {', + 'final $apiName instance = $apiName(', + ' ${method.name}: ($apiName ${classMemberNamePrefix}instance, ...) {', ' print(weakMyVariable?.target);', ' },', ');', @@ -1373,6 +1373,7 @@ class $codecName extends StandardMessageCodec { required bool hasARequiredFlutterMethod, }) { return [ + // Flutter methods message handler cb.Method.returnsVoid( (cb.MethodBuilder builder) => builder ..name = '${classMemberNamePrefix}setUpMessageHandlers' @@ -1697,103 +1698,78 @@ class $codecName extends StandardMessageCodec { cb.Method( (cb.MethodBuilder builder) { final String type = _addGenericTypesNullable(field.type); - final String channelName = makeChannelNameWithStrings( - apiName: apiName, - methodName: field.name, - dartPackageName: dartPackageName, - ); + 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.of( - [ - cb.Code( - 'final $type ${_varNamePrefix}instance = $type.${classMemberNamePrefix}detached('), - if (!field.isStatic) ...[ - const cb.Code( - '${classMemberNamePrefix}binaryMessenger: ${classMemberNamePrefix}binaryMessenger,'), - const cb.Code( - '${classMemberNamePrefix}instanceManager: ${classMemberNamePrefix}instanceManager,'), - ], - const cb.Code(');'), - cb.Code( - "const String ${_varNamePrefix}channelName = r'$channelName';", - ), - _basicMessageChannel( - codec: !field.isStatic - ? cb.refer(codecInstanceName) - : cb.refer( - '$codecName($instanceManagerClassName.instance)'), - binaryMessenger: !field.isStatic - ? cb.refer('${classMemberNamePrefix}binaryMessenger') - : null, - ), - cb - .refer('${_varNamePrefix}channel.send') - .call([ - cb.literalList( - [ - if (!field.isStatic) cb.refer('this'), - cb.refer( - '${field.isStatic ? '$instanceManagerClassName.instance' : '${classMemberNamePrefix}instanceManager'}.addDartCreatedInstance(${_varNamePrefix}instance)', - ), - ], - cb.refer('Object?'), - ) - ]) - .property('then') - .call( - [ - cb.Method( - (cb.MethodBuilder builder) => builder - ..requiredParameters.add( - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = 'value' - ..type = cb.refer('Object?'), - ), - ) - ..body = cb.Block.of([ - const cb.Code( - 'final List? ${_varNamePrefix}replyList = value as List?;', - ), - const cb.Code( - 'if (${_varNamePrefix}replyList == null) {', - ), - const cb.Code( - 'throw _createConnectionError(${_varNamePrefix}channelName);', - ), - const cb.Code( - '} else if (${_varNamePrefix}replyList.length > 1) {', - ), - cb.InvokeExpression.newOf( - cb.refer('PlatformException'), - [], - { - 'code': cb - .refer('${_varNamePrefix}replyList') - .index(cb.literal(0)) - .nullChecked - .asA(cb.refer('String')), - 'message': cb - .refer('${_varNamePrefix}replyList') - .index(cb.literal(1)) - .asA(cb.refer('String?')), - 'details': cb - .refer('${_varNamePrefix}replyList') - .index(cb.literal(2)), - }).thrown.statement, - const cb.Code('}'), - ]), - ).genericClosure, - ], - {}, - [cb.refer('void')], - ) - .statement, - const cb.Code('return ${_varNamePrefix}instance;'), - ], + ..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 = ${classMemberNamePrefix}instanceManager.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;'), + ]); + }, ); }, ), 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 db4373680232..504bee1cfa75 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 @@ -4050,8 +4050,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterNoop: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4072,8 +4072,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterThrowError: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4095,8 +4095,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterThrowErrorFromVoid: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4118,8 +4118,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoBool: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4143,8 +4143,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoInt: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4168,8 +4168,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoDouble: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4193,8 +4193,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoString: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4218,8 +4218,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoUint8List: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4243,8 +4243,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoList: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4269,8 +4269,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoProxyApiList: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4294,8 +4294,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoMap: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4320,8 +4320,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoProxyApiMap: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4345,8 +4345,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoEnum: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4370,8 +4370,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoProxyApi: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4395,8 +4395,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoNullableBool: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4420,8 +4420,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoNullableInt: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4445,8 +4445,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoNullableDouble: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4470,8 +4470,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoNullableString: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4495,8 +4495,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoNullableUint8List: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4520,8 +4520,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoNullableList: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4545,8 +4545,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoNullableMap: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4570,8 +4570,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoNullableEnum: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4595,8 +4595,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoNullableProxyApi: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4621,8 +4621,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterNoopAsync: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -4644,8 +4644,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyIntegrationCoreApi instance = ProxyIntegrationCoreApi( + /// flutterEchoAsyncString: (ProxyIntegrationCoreApi pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); @@ -5928,56 +5928,69 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass pigeon_binaryMessenger: pigeon_binaryMessenger, pigeon_instanceManager: pigeon_instanceManager, ); - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.attachedField'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - __pigeon_codecProxyIntegrationCoreApi, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.send([ - this, - pigeon_instanceManager.addDartCreatedInstance(__pigeon_instance), - ]).then((Object? value) { - final List? __pigeon_replyList = value as List?; + final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = + __pigeon_codecProxyIntegrationCoreApi; + 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.ProxyIntegrationCoreApi.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?), + 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(); - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.staticAttachedField'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - _Pigeon_ProxyApiBaseCodec(Pigeon_InstanceManager.instance), - ); - __pigeon_channel.send([ - Pigeon_InstanceManager.instance.addDartCreatedInstance(__pigeon_instance) - ]).then((Object? value) { - final List? __pigeon_replyList = value as List?; + 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.ProxyIntegrationCoreApi.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?), + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); + } else { + return; } - }); + }(); return __pigeon_instance; } @@ -8497,8 +8510,8 @@ class ProxyApiInterface extends Pigeon_ProxyApiBaseClass { /// /// ```dart /// final WeakReference weakMyVariable = WeakReference(myVariable); - /// final MyClass instance = MyClass( - /// myCallbackMethod: (_) { + /// final ProxyApiInterface instance = ProxyApiInterface( + /// anInterfaceMethod: (ProxyApiInterface pigeon_instance, ...) { /// print(weakMyVariable?.target); /// }, /// ); From 139e3df3ba9ec73af1a3b191f5e25908c9fe37cd Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Sat, 6 Jan 2024 13:44:01 -0500 Subject: [PATCH 69/73] reuse flutter method call code --- packages/pigeon/lib/dart_generator.dart | 432 ++-- .../lib/src/generated/core_tests.gen.dart | 1832 ++++++++--------- 2 files changed, 1022 insertions(+), 1242 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 32c296f3c1f1..30138aebe655 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -365,115 +365,17 @@ $resultAt != null 'static void setup(${api.name}? api, {BinaryMessenger? binaryMessenger}) '); indent.addScoped('{', '}', () { for (final Method func in api.methods) { - indent.write(''); - indent.addScoped('{', '}', () { - indent.writeln( - 'final BasicMessageChannel ${_varNamePrefix}channel = BasicMessageChannel(', - ); - final String channelName = channelNameFunc == null + _writeFlutterMethodMessageHandler( + indent, + name: func.name, + parameters: func.parameters, + returnType: func.returnType, + channelName: channelNameFunc == null ? makeChannelName(api, func, dartPackageName) - : channelNameFunc(func); - indent.nest(2, () { - indent.writeln("'$channelName', $_pigeonChannelCodec,"); - indent.writeln( - 'binaryMessenger: binaryMessenger);', - ); - }); - final String messageHandlerSetterWithOpeningParentheses = isMockHandler - ? '_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(${_varNamePrefix}channel, ' - : '${_varNamePrefix}channel.setMessageHandler('; - indent.write('if (api == null) '); - indent.addScoped('{', '}', () { - indent.writeln( - '${messageHandlerSetterWithOpeningParentheses}null);'); - }, addTrailingNewline: false); - indent.add(' else '); - indent.addScoped('{', '}', () { - indent.write( - '$messageHandlerSetterWithOpeningParentheses(Object? message) async ', - ); - indent.addScoped('{', '});', () { - final String returnType = - _addGenericTypesNullable(func.returnType); - final bool isAsync = func.isAsynchronous; - const String emptyReturnStatement = - 'return wrapResponse(empty: true);'; - String call; - if (func.parameters.isEmpty) { - call = 'api.${func.name}()'; - } else { - indent.writeln('assert(message != null,'); - indent.writeln("'Argument for $channelName was null.');"); - const String argsArray = 'args'; - indent.writeln( - 'final List $argsArray = (message as List?)!;'); - String argNameFunc(int index, NamedType type) => - _getSafeArgumentName(index, type); - func.parameters.forEachIndexed((int count, NamedType arg) { - final String argType = _addGenericTypes(arg.type); - final String argName = argNameFunc(count, arg); - final String genericArgType = - _makeGenericTypeArguments(arg.type); - final String castCall = _makeGenericCastCall(arg.type); - - final String leftHandSide = 'final $argType? $argName'; - if (arg.type.isEnum) { - indent.writeln( - '$leftHandSide = $argsArray[$count] == null ? null : $argType.values[$argsArray[$count]! as int];'); - } else { - indent.writeln( - '$leftHandSide = ($argsArray[$count] as $genericArgType?)${castCall.isEmpty ? '' : '?$castCall'};'); - } - if (!arg.type.isNullable) { - indent.writeln('assert($argName != null,'); - indent.writeln( - " 'Argument for $channelName was null, expected non-null $argType.');"); - } - }); - final Iterable argNames = - func.parameters.mapIndexed((int index, Parameter field) { - final String name = _getSafeArgumentName(index, field); - return '${field.isNamed ? '${field.name}: ' : ''}$name${field.type.isNullable ? '' : '!'}'; - }); - call = 'api.${func.name}(${argNames.join(', ')})'; - } - indent.writeScoped('try {', '} ', () { - if (func.returnType.isVoid) { - if (isAsync) { - indent.writeln('await $call;'); - } else { - indent.writeln('$call;'); - } - indent.writeln(emptyReturnStatement); - } else { - if (isAsync) { - indent.writeln('final $returnType output = await $call;'); - } else { - indent.writeln('final $returnType output = $call;'); - } - - const String returnExpression = 'output'; - final String nullability = - func.returnType.isNullable ? '?' : ''; - final String valueExtraction = - func.returnType.isEnum ? '$nullability.index' : ''; - final String returnStatement = isMockHandler - ? 'return [$returnExpression$valueExtraction];' - : 'return wrapResponse(result: $returnExpression$valueExtraction);'; - indent.writeln(returnStatement); - } - }, addTrailingNewline: false); - indent.addScoped('on PlatformException catch (e) {', '}', () { - indent.writeln('return wrapResponse(error: e);'); - }, addTrailingNewline: false); - - indent.writeScoped('catch (e) {', '}', () { - indent.writeln( - "return wrapResponse(error: PlatformException(code: 'error', message: e.toString()));"); - }); - }); - }); - }); + : channelNameFunc(func), + isMockHandler: isMockHandler, + isAsynchronous: func.isAsynchronous, + ); } }); }); @@ -1440,6 +1342,12 @@ class $codecName extends StandardMessageCodec { cb.Code( 'final $codecName $_pigeonChannelCodec = $codecName(${classMemberNamePrefix}instanceManager ?? $instanceManagerClassName.instance);', ), + const cb.Code( + 'final BinaryMessenger? binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', + ), + const cb.Code( + 'int api = 4;', + ), if (!hasARequiredFlutterMethod) ...[ const cb.Code('{'), cb.Code( @@ -1559,137 +1467,50 @@ class $codecName extends StandardMessageCodec { ...flutterMethods.fold>( [], (List list, Method method) { - final String channelName = makeChannelNameWithStrings( - apiName: apiName, - methodName: method.name, - dartPackageName: dartPackageName, - ); - final cb.Expression call = cb - .refer( - '(${method.name} ?? instance!.${method.name})${method.required ? '' : '?'}.call', - ) - .call( - [ - cb.refer('instance').nullChecked, - ...method.parameters.mapIndexed( - (int index, NamedType parameter) { - final String name = _getSafeArgumentName( - index + 1, - parameter, - ); - return cb - .refer(name) - .nullCheckedIf(!parameter.type.isNullable); - }, - ), - ], + final StringBuffer messageHandlerSink = StringBuffer(); + const String instanceName = '${classMemberNamePrefix}instance'; + final String safeInstanceName = _getSafeArgumentName( + 0, + NamedType( + name: instanceName, + type: TypeDeclaration(baseName: apiName, isNullable: false), + ), ); - return list - ..addAll([ - const cb.Code('{'), - cb.Code( - "const String ${_varNamePrefix}channelName = r'$channelName';", + _writeFlutterMethodMessageHandler(Indent(messageHandlerSink), + name: method.name, + parameters: [ + Parameter( + name: instanceName, + type: TypeDeclaration( + baseName: apiName, + isNullable: false, + ), + ), + ...method.parameters, + ], + returnType: TypeDeclaration( + baseName: method.returnType.baseName, + isNullable: + !method.required || method.returnType.isNullable, + typeArguments: method.returnType.typeArguments, + associatedEnum: method.returnType.associatedEnum, + associatedClass: method.returnType.associatedClass, + associatedProxyApi: method.returnType.associatedProxyApi, ), - _basicMessageChannel( - binaryMessenger: - cb.refer('${classMemberNamePrefix}binaryMessenger'), + channelName: makeChannelNameWithStrings( + apiName: apiName, + methodName: method.name, + dartPackageName: dartPackageName, ), - cb.refer('${_varNamePrefix}channel.setMessageHandler').call( - [ - cb.Method( - (cb.MethodBuilder builder) => builder - ..modifier = cb.MethodModifier.async - ..requiredParameters.add( - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = 'message' - ..type = cb.refer('Object?'), - ), - ) - ..body = cb.Block((cb.BlockBuilder builder) { - builder.statements.addAll([ - _assert( - condition: cb - .refer('message') - .notEqualTo(cb.literalNull), - message: cb.literalString( - 'Argument for \$${_varNamePrefix}channelName was null.', - ), - ), - const cb.Code( - 'final List args = (message as List?)!;', - ), - cb.Code( - 'final $apiName? instance = (args[0] as $apiName?);', - ), - _assert( - condition: cb - .refer('instance') - .notEqualTo(cb.literalNull), - message: cb.literalString( - 'Argument for \$${_varNamePrefix}channelName was null, expected non-null $apiName.', - ), - ), - ...method.parameters.foldIndexed>( - [], - ( - int index, - List previous, - Parameter parameter, - ) { - return previous - ..addAll(_messageArg( - index + 1, - parameter, - )); - }, - ), - const cb.Code('try {'), - if (method.returnType.isVoid) ...[ - if (method.isAsynchronous) - call.awaited.statement - else - call.statement, - const cb.Code( - 'return wrapResponse(empty: true);', - ), - ] else ...[ - cb - .declareFinal( - 'output', - type: _refer( - _addGenericTypes(method.returnType), - isNullable: - method.returnType.isNullable || - !method.required, - ), - ) - .assign( - call.awaitedIf(method.isAsynchronous), - ) - .statement, - _wrapResultResponse(method) - .returned - .statement, - ], - const cb.Code( - '} on PlatformException catch (e) {', - ), - const cb.Code( - 'return wrapResponse(error: e);', - ), - const cb.Code('} catch (e) {'), - const cb.Code( - "return wrapResponse(error: PlatformException(code: 'error', message: e.toString()),);", - ), - const cb.Code('}') - ]); - }), - ).genericClosure - ], - ).statement, - const cb.Code('}'), - ]); + isMockHandler: false, + isAsynchronous: method.isAsynchronous, onCreateApiCall: ( + String methodName, + Iterable argNames, + ) { + final String nullability = method.required ? '' : '?'; + return '($methodName ?? $safeInstanceName!.$methodName)$nullability.call(${argNames.join(',')})'; + }); + return list..add(cb.Code(messageHandlerSink.toString())); }, ), ]), @@ -2165,30 +1986,135 @@ if (${_varNamePrefix}replyList == null) { \t$returnStatement }'''); } + + void _writeFlutterMethodMessageHandler( + Indent indent, { + required String name, + required Iterable parameters, + required TypeDeclaration returnType, + required String channelName, + required bool isMockHandler, + required bool isAsynchronous, + String Function(String methodName, Iterable argNames) + onCreateApiCall = _createFlutterApiMethodCall, + }) { + indent.write(''); + indent.addScoped('{', '}', () { + indent.writeln( + 'final BasicMessageChannel ${_varNamePrefix}channel = BasicMessageChannel(', + ); + indent.nest(2, () { + indent.writeln("'$channelName', $_pigeonChannelCodec,"); + indent.writeln( + 'binaryMessenger: binaryMessenger);', + ); + }); + final String messageHandlerSetterWithOpeningParentheses = isMockHandler + ? '_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(${_varNamePrefix}channel, ' + : '${_varNamePrefix}channel.setMessageHandler('; + indent.write('if (api == null) '); + indent.addScoped('{', '}', () { + indent.writeln('${messageHandlerSetterWithOpeningParentheses}null);'); + }, addTrailingNewline: false); + indent.add(' else '); + indent.addScoped('{', '}', () { + indent.write( + '$messageHandlerSetterWithOpeningParentheses(Object? message) async ', + ); + indent.addScoped('{', '});', () { + final String returnTypeString = _addGenericTypesNullable(returnType); + final bool isAsync = isAsynchronous; + const String emptyReturnStatement = + 'return wrapResponse(empty: true);'; + String call; + if (parameters.isEmpty) { + call = 'api.$name()'; + } else { + indent.writeln('assert(message != null,'); + indent.writeln("'Argument for $channelName was null.');"); + const String argsArray = 'args'; + indent.writeln( + 'final List $argsArray = (message as List?)!;'); + String argNameFunc(int index, NamedType type) => + _getSafeArgumentName(index, type); + parameters.forEachIndexed((int count, NamedType arg) { + final String argType = _addGenericTypes(arg.type); + final String argName = argNameFunc(count, arg); + final String genericArgType = _makeGenericTypeArguments(arg.type); + final String castCall = _makeGenericCastCall(arg.type); + + final String leftHandSide = 'final $argType? $argName'; + if (arg.type.isEnum) { + indent.writeln( + '$leftHandSide = $argsArray[$count] == null ? null : $argType.values[$argsArray[$count]! as int];'); + } else { + indent.writeln( + '$leftHandSide = ($argsArray[$count] as $genericArgType?)${castCall.isEmpty ? '' : '?$castCall'};'); + } + if (!arg.type.isNullable) { + indent.writeln('assert($argName != null,'); + indent.writeln( + " 'Argument for $channelName was null, expected non-null $argType.');"); + } + }); + final Iterable argNames = + parameters.mapIndexed((int index, Parameter field) { + final String name = _getSafeArgumentName(index, field); + return '${field.isNamed ? '${field.name}: ' : ''}$name${field.type.isNullable ? '' : '!'}'; + }); + call = onCreateApiCall(name, argNames); + } + indent.writeScoped('try {', '} ', () { + if (returnType.isVoid) { + if (isAsync) { + indent.writeln('await $call;'); + } else { + indent.writeln('$call;'); + } + indent.writeln(emptyReturnStatement); + } else { + if (isAsync) { + indent.writeln('final $returnTypeString output = await $call;'); + } else { + indent.writeln('final $returnTypeString output = $call;'); + } + + const String returnExpression = 'output'; + final String nullability = returnType.isNullable ? '?' : ''; + final String valueExtraction = + returnType.isEnum ? '$nullability.index' : ''; + final String returnStatement = isMockHandler + ? 'return [$returnExpression$valueExtraction];' + : 'return wrapResponse(result: $returnExpression$valueExtraction);'; + indent.writeln(returnStatement); + } + }, addTrailingNewline: false); + indent.addScoped('on PlatformException catch (e) {', '}', () { + indent.writeln('return wrapResponse(error: e);'); + }, addTrailingNewline: false); + + indent.writeScoped('catch (e) {', '}', () { + indent.writeln( + "return wrapResponse(error: PlatformException(code: 'error', message: e.toString()));"); + }); + }); + }); + }); + } + + static String _createFlutterApiMethodCall( + String methodName, + Iterable argNames, + ) { + return 'api.$methodName(${argNames.join(', ')})'; + } } // Adds support for conditional expressions. extension on cb.Expression { - cb.Expression awaitedIf(bool condition) => condition ? awaited : this; cb.Expression nullCheckedIf(bool condition) => condition ? nullChecked : this; } -cb.Expression _wrapResultResponse(Method method) { - final TypeDeclaration returnType = method.returnType; - return cb.refer('wrapResponse').call( - [], - { - if (returnType.isEnum) - if (returnType.isNullable || !method.required) - 'result': cb.refer('output?.index') - else - 'result': cb.refer('output.index') - else - 'result': cb.refer('output'), - }, - ); -} - /// final = ([] as ); Iterable _messageArg( int index, 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 504bee1cfa75..0ba7227cfeea 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 @@ -4784,6 +4784,8 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = _Pigeon_ProxyApiBaseCodec( pigeon_instanceManager ?? Pigeon_InstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + int api = 4; { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.pigeon_newInstance'; @@ -4916,1009 +4918,859 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass }); } { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterNoop'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - try { - (flutterNoop ?? instance!.flutterNoop)?.call(instance!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString()), - ); - } - }); - } - { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterThrowError'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - try { - final Object? output = - (flutterThrowError ?? instance!.flutterThrowError) - ?.call(instance!); - return wrapResponse(result: output); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString()), - ); - } - }); - } - { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterThrowErrorFromVoid'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - try { - (flutterThrowErrorFromVoid ?? instance!.flutterThrowErrorFromVoid) - ?.call(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.ProxyIntegrationCoreApi.flutterNoop', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterNoop was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterNoop was null, expected non-null ProxyIntegrationCoreApi.'); + 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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoBool'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final bool? arg_aBool = (args[1] as bool?); - assert( - arg_aBool != null, - 'Argument for $__pigeon_channelName was null, expected non-null bool.', - ); - try { - final bool? output = - (flutterEchoBool ?? instance!.flutterEchoBool)?.call( - 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.ProxyIntegrationCoreApi.flutterThrowError', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterThrowError was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterThrowError was null, expected non-null ProxyIntegrationCoreApi.'); + 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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoInt'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final int? arg_anInt = (args[1] as int?); - assert( - arg_anInt != null, - 'Argument for $__pigeon_channelName was null, expected non-null int.', - ); - try { - final int? output = - (flutterEchoInt ?? instance!.flutterEchoInt)?.call( - 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.ProxyIntegrationCoreApi.flutterThrowErrorFromVoid', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterThrowErrorFromVoid was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterThrowErrorFromVoid was null, expected non-null ProxyIntegrationCoreApi.'); + 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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoDouble'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final double? arg_aDouble = (args[1] as double?); - assert( - arg_aDouble != null, - 'Argument for $__pigeon_channelName was null, expected non-null double.', - ); - try { - final double? output = - (flutterEchoDouble ?? instance!.flutterEchoDouble)?.call( - 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.ProxyIntegrationCoreApi.flutterEchoBool', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoBool was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoBool was null, expected non-null ProxyIntegrationCoreApi.'); + final bool? arg_aBool = (args[1] as bool?); + assert(arg_aBool != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoString'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final String? arg_aString = (args[1] as String?); - assert( - arg_aString != null, - 'Argument for $__pigeon_channelName was null, expected non-null String.', - ); - try { - final String? output = - (flutterEchoString ?? instance!.flutterEchoString)?.call( - 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.ProxyIntegrationCoreApi.flutterEchoInt', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoInt was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoInt was null, expected non-null ProxyIntegrationCoreApi.'); + final int? arg_anInt = (args[1] as int?); + assert(arg_anInt != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoUint8List'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final Uint8List? arg_aList = (args[1] as Uint8List?); - assert( - arg_aList != null, - 'Argument for $__pigeon_channelName was null, expected non-null Uint8List.', - ); - try { - final Uint8List? output = - (flutterEchoUint8List ?? instance!.flutterEchoUint8List)?.call( - 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.ProxyIntegrationCoreApi.flutterEchoDouble', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoDouble was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoDouble was null, expected non-null ProxyIntegrationCoreApi.'); + final double? arg_aDouble = (args[1] as double?); + assert(arg_aDouble != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoList'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final List? arg_aList = - (args[1] as List?)?.cast(); - assert( - arg_aList != null, - 'Argument for $__pigeon_channelName was null, expected non-null List.', - ); - try { - final List? output = - (flutterEchoList ?? instance!.flutterEchoList)?.call( - 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.ProxyIntegrationCoreApi.flutterEchoString', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoString was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoString was null, expected non-null ProxyIntegrationCoreApi.'); + final String? arg_aString = (args[1] as String?); + assert(arg_aString != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoProxyApiList'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final List? arg_aList = - (args[1] as List?)?.cast(); - assert( - arg_aList != null, - 'Argument for $__pigeon_channelName was null, expected non-null List.', - ); - try { - final List? output = - (flutterEchoProxyApiList ?? instance!.flutterEchoProxyApiList) - ?.call( - 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.ProxyIntegrationCoreApi.flutterEchoUint8List', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoUint8List was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoUint8List was null, expected non-null ProxyIntegrationCoreApi.'); + final Uint8List? arg_aList = (args[1] as Uint8List?); + assert(arg_aList != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoMap'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final Map? arg_aMap = - (args[1] as Map?)?.cast(); - assert( - arg_aMap != null, - 'Argument for $__pigeon_channelName was null, expected non-null Map.', - ); - try { - final Map? output = - (flutterEchoMap ?? instance!.flutterEchoMap)?.call( - 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.ProxyIntegrationCoreApi.flutterEchoList', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoList was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoList was null, expected non-null ProxyIntegrationCoreApi.'); + final List? arg_aList = + (args[1] as List?)?.cast(); + assert(arg_aList != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoProxyApiMap'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final Map? arg_aMap = - (args[1] as Map?) - ?.cast(); - assert( - arg_aMap != null, - 'Argument for $__pigeon_channelName was null, expected non-null Map.', - ); - try { - final Map? output = - (flutterEchoProxyApiMap ?? instance!.flutterEchoProxyApiMap) - ?.call( - 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.ProxyIntegrationCoreApi.flutterEchoProxyApiList', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoProxyApiList was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoProxyApiList was null, expected non-null ProxyIntegrationCoreApi.'); + final List? arg_aList = + (args[1] as List?)?.cast(); + assert(arg_aList != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoEnum'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final AnEnum? arg_anEnum = - args[1] == null ? null : AnEnum.values[args[1]! as int]; - assert( - arg_anEnum != null, - 'Argument for $__pigeon_channelName was null, expected non-null AnEnum.', - ); - try { - final AnEnum? output = - (flutterEchoEnum ?? instance!.flutterEchoEnum)?.call( - 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.ProxyIntegrationCoreApi.flutterEchoMap', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoMap was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoMap was null, expected non-null ProxyIntegrationCoreApi.'); + final Map? arg_aMap = + (args[1] as Map?)?.cast(); + assert(arg_aMap != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoProxyApi'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final ProxyApiSuperClass? arg_aProxyApi = - (args[1] as ProxyApiSuperClass?); - assert( - arg_aProxyApi != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyApiSuperClass.', - ); - try { - final ProxyApiSuperClass? output = - (flutterEchoProxyApi ?? instance!.flutterEchoProxyApi)?.call( - 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.ProxyIntegrationCoreApi.flutterEchoProxyApiMap', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoProxyApiMap was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoProxyApiMap was null, expected non-null ProxyIntegrationCoreApi.'); + final Map? arg_aMap = + (args[1] as Map?) + ?.cast(); + assert(arg_aMap != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableBool'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final bool? arg_aBool = (args[1] as bool?); - try { - final bool? output = - (flutterEchoNullableBool ?? instance!.flutterEchoNullableBool) - ?.call( - 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.ProxyIntegrationCoreApi.flutterEchoEnum', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoEnum was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoEnum was null, expected non-null ProxyIntegrationCoreApi.'); + 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.ProxyIntegrationCoreApi.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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableInt'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final int? arg_anInt = (args[1] as int?); - try { - final int? output = - (flutterEchoNullableInt ?? instance!.flutterEchoNullableInt) - ?.call( - 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.ProxyIntegrationCoreApi.flutterEchoProxyApi', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoProxyApi was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoProxyApi was null, expected non-null ProxyIntegrationCoreApi.'); + final ProxyApiSuperClass? arg_aProxyApi = + (args[1] as ProxyApiSuperClass?); + assert(arg_aProxyApi != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableDouble'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final double? arg_aDouble = (args[1] as double?); - try { - final double? output = - (flutterEchoNullableDouble ?? instance!.flutterEchoNullableDouble) - ?.call( - 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.ProxyIntegrationCoreApi.flutterEchoNullableBool', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableBool was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableBool was null, expected non-null ProxyIntegrationCoreApi.'); + 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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableString'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final String? arg_aString = (args[1] as String?); - try { - final String? output = - (flutterEchoNullableString ?? instance!.flutterEchoNullableString) - ?.call( - 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.ProxyIntegrationCoreApi.flutterEchoNullableInt', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableInt was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableInt was null, expected non-null ProxyIntegrationCoreApi.'); + 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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableUint8List'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final Uint8List? arg_aList = (args[1] as Uint8List?); - try { - final Uint8List? output = (flutterEchoNullableUint8List ?? - instance!.flutterEchoNullableUint8List) - ?.call( - 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.ProxyIntegrationCoreApi.flutterEchoNullableDouble', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableDouble was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableDouble was null, expected non-null ProxyIntegrationCoreApi.'); + 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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableList'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final List? arg_aList = - (args[1] as List?)?.cast(); - try { - final List? output = - (flutterEchoNullableList ?? instance!.flutterEchoNullableList) - ?.call( - 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.ProxyIntegrationCoreApi.flutterEchoNullableString', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableString was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableString was null, expected non-null ProxyIntegrationCoreApi.'); + 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.ProxyIntegrationCoreApi.flutterEchoNullableUint8List', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableUint8List was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableUint8List was null, expected non-null ProxyIntegrationCoreApi.'); + 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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableMap'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final Map? arg_aMap = - (args[1] as Map?)?.cast(); - try { - final Map? output = - (flutterEchoNullableMap ?? instance!.flutterEchoNullableMap) - ?.call( - 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.ProxyIntegrationCoreApi.flutterEchoNullableList', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableList was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableList was null, expected non-null ProxyIntegrationCoreApi.'); + 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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableEnum'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final AnEnum? arg_anEnum = - args[1] == null ? null : AnEnum.values[args[1]! as int]; - try { - final AnEnum? output = - (flutterEchoNullableEnum ?? instance!.flutterEchoNullableEnum) - ?.call( - 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.ProxyIntegrationCoreApi.flutterEchoNullableMap', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableMap was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableMap was null, expected non-null ProxyIntegrationCoreApi.'); + 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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableProxyApi'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final ProxyApiSuperClass? arg_aProxyApi = - (args[1] as ProxyApiSuperClass?); - try { - final ProxyApiSuperClass? output = (flutterEchoNullableProxyApi ?? - instance!.flutterEchoNullableProxyApi) - ?.call( - 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.ProxyIntegrationCoreApi.flutterEchoNullableEnum', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableEnum was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableEnum was null, expected non-null ProxyIntegrationCoreApi.'); + 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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterNoopAsync'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - try { - await (flutterNoopAsync ?? instance!.flutterNoopAsync) - ?.call(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.ProxyIntegrationCoreApi.flutterEchoNullableProxyApi', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableProxyApi was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableProxyApi was null, expected non-null ProxyIntegrationCoreApi.'); + 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())); + } + }); + } } + { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoAsyncString'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyIntegrationCoreApi? instance = - (args[0] as ProxyIntegrationCoreApi?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyIntegrationCoreApi.', - ); - final String? arg_aString = (args[1] as String?); - assert( - arg_aString != null, - 'Argument for $__pigeon_channelName was null, expected non-null String.', - ); - try { - final String? output = - await (flutterEchoAsyncString ?? instance!.flutterEchoAsyncString) - ?.call( - 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.ProxyIntegrationCoreApi.flutterNoopAsync', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterNoopAsync was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterNoopAsync was null, expected non-null ProxyIntegrationCoreApi.'); + 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.ProxyIntegrationCoreApi.flutterEchoAsyncString', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoAsyncString was null.'); + final List args = (message as List?)!; + final ProxyIntegrationCoreApi? arg_pigeon_instance = + (args[0] as ProxyIntegrationCoreApi?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoAsyncString was null, expected non-null ProxyIntegrationCoreApi.'); + final String? arg_aString = (args[1] as String?); + assert(arg_aString != null, + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.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())); + } + }); + } } } @@ -8419,6 +8271,8 @@ class ProxyApiSuperClass extends Pigeon_ProxyApiBaseClass { final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = _Pigeon_ProxyApiBaseCodec( pigeon_instanceManager ?? Pigeon_InstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + int api = 4; { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.pigeon_newInstance'; @@ -8530,6 +8384,8 @@ class ProxyApiInterface extends Pigeon_ProxyApiBaseClass { final _Pigeon_ProxyApiBaseCodec pigeonChannelCodec = _Pigeon_ProxyApiBaseCodec( pigeon_instanceManager ?? Pigeon_InstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + int api = 4; { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.pigeon_newInstance'; @@ -8563,36 +8419,34 @@ class ProxyApiInterface extends Pigeon_ProxyApiBaseClass { }); } { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.anInterfaceMethod'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final ProxyApiInterface? instance = (args[0] as ProxyApiInterface?); - assert( - instance != null, - 'Argument for $__pigeon_channelName was null, expected non-null ProxyApiInterface.', - ); - try { - (anInterfaceMethod ?? instance!.anInterfaceMethod)?.call(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.ProxyApiInterface.anInterfaceMethod', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __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())); + } + }); + } } } From ec6b94f024f578691b76951640a42f78575a1101 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Sun, 7 Jan 2024 16:18:03 -0500 Subject: [PATCH 70/73] gross fix for whether to null out handlers --- packages/pigeon/lib/dart_generator.dart | 82 +++++++++++-------- .../lib/src/generated/core_tests.gen.dart | 58 ++++++------- 2 files changed, 75 insertions(+), 65 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 30138aebe655..1ba37868b406 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -1282,6 +1282,13 @@ class $codecName extends StandardMessageCodec { ..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' @@ -1345,9 +1352,6 @@ class $codecName extends StandardMessageCodec { const cb.Code( 'final BinaryMessenger? binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', ), - const cb.Code( - 'int api = 4;', - ), if (!hasARequiredFlutterMethod) ...[ const cb.Code('{'), cb.Code( @@ -1476,40 +1480,45 @@ class $codecName extends StandardMessageCodec { type: TypeDeclaration(baseName: apiName, isNullable: false), ), ); - _writeFlutterMethodMessageHandler(Indent(messageHandlerSink), - name: method.name, - parameters: [ - Parameter( - name: instanceName, - type: TypeDeclaration( - baseName: apiName, - isNullable: false, - ), + _writeFlutterMethodMessageHandler( + Indent(messageHandlerSink), + name: method.name, + parameters: [ + Parameter( + name: instanceName, + type: TypeDeclaration( + baseName: apiName, + isNullable: false, ), - ...method.parameters, - ], - returnType: TypeDeclaration( - baseName: method.returnType.baseName, - isNullable: - !method.required || 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, onCreateApiCall: ( - String methodName, - Iterable argNames, - ) { - final String nullability = method.required ? '' : '?'; - return '($methodName ?? $safeInstanceName!.$methodName)$nullability.call(${argNames.join(',')})'; - }); + ...method.parameters, + ], + returnType: TypeDeclaration( + baseName: method.returnType.baseName, + isNullable: + !method.required || 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 argNames, + ) { + final String nullability = method.required ? '' : '?'; + return '($methodName ?? $safeInstanceName!.$methodName)$nullability.call(${argNames.join(',')})'; + }, + ); return list..add(cb.Code(messageHandlerSink.toString())); }, ), @@ -1995,6 +2004,7 @@ if (${_varNamePrefix}replyList == null) { required String channelName, required bool isMockHandler, required bool isAsynchronous, + String nullHandlerExpression = 'api == null', String Function(String methodName, Iterable argNames) onCreateApiCall = _createFlutterApiMethodCall, }) { @@ -2012,7 +2022,7 @@ if (${_varNamePrefix}replyList == null) { final String messageHandlerSetterWithOpeningParentheses = isMockHandler ? '_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(${_varNamePrefix}channel, ' : '${_varNamePrefix}channel.setMessageHandler('; - indent.write('if (api == null) '); + indent.write('if ($nullHandlerExpression) '); indent.addScoped('{', '}', () { indent.writeln('${messageHandlerSetterWithOpeningParentheses}null);'); }, addTrailingNewline: false); 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 0ba7227cfeea..ff021fd996fa 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 @@ -4667,6 +4667,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass __pigeon_staticAttachedField(); static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, BinaryMessenger? pigeon_binaryMessenger, Pigeon_InstanceManager? pigeon_instanceManager, ProxyIntegrationCoreApi Function( @@ -4785,7 +4786,6 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass _Pigeon_ProxyApiBaseCodec( pigeon_instanceManager ?? Pigeon_InstanceManager.instance); final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; - int api = 4; { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.pigeon_newInstance'; @@ -4923,7 +4923,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterNoop', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -4954,7 +4954,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterThrowError', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -4986,7 +4986,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterThrowErrorFromVoid', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5018,7 +5018,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoBool', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5053,7 +5053,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoInt', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5088,7 +5088,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoDouble', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5123,7 +5123,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoString', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5158,7 +5158,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoUint8List', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5193,7 +5193,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoList', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5229,7 +5229,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoProxyApiList', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5266,7 +5266,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoMap', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5302,7 +5302,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoProxyApiMap', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5340,7 +5340,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoEnum', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5376,7 +5376,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoProxyApi', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5412,7 +5412,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableBool', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5445,7 +5445,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableInt', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5478,7 +5478,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableDouble', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5511,7 +5511,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableString', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5544,7 +5544,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableUint8List', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5577,7 +5577,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableList', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5611,7 +5611,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableMap', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5645,7 +5645,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableEnum', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5679,7 +5679,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoNullableProxyApi', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5713,7 +5713,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterNoopAsync', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -5744,7 +5744,7 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.flutterEchoAsyncString', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { @@ -8264,6 +8264,7 @@ class ProxyApiSuperClass extends Pigeon_ProxyApiBaseClass { _Pigeon_ProxyApiBaseCodec(pigeon_instanceManager); static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, BinaryMessenger? pigeon_binaryMessenger, Pigeon_InstanceManager? pigeon_instanceManager, ProxyApiSuperClass Function()? pigeon_newInstance, @@ -8272,7 +8273,6 @@ class ProxyApiSuperClass extends Pigeon_ProxyApiBaseClass { _Pigeon_ProxyApiBaseCodec( pigeon_instanceManager ?? Pigeon_InstanceManager.instance); final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; - int api = 4; { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.pigeon_newInstance'; @@ -8376,6 +8376,7 @@ class ProxyApiInterface extends Pigeon_ProxyApiBaseClass { 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, @@ -8385,7 +8386,6 @@ class ProxyApiInterface extends Pigeon_ProxyApiBaseClass { _Pigeon_ProxyApiBaseCodec( pigeon_instanceManager ?? Pigeon_InstanceManager.instance); final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; - int api = 4; { const String __pigeon_channelName = r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.pigeon_newInstance'; @@ -8424,7 +8424,7 @@ class ProxyApiInterface extends Pigeon_ProxyApiBaseClass { 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.anInterfaceMethod', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { + if (pigeon_clearHandlers) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { From 89daaea3568c1d0f16b1ca6ec21261a2a72e3703 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Sun, 7 Jan 2024 17:04:59 -0500 Subject: [PATCH 71/73] update setUpMessageHandler with same thing from the commit above --- packages/pigeon/lib/dart_generator.dart | 295 ++++---------- .../lib/src/generated/core_tests.gen.dart | 373 +++++++++--------- 2 files changed, 263 insertions(+), 405 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 1ba37868b406..caac9be7ac2e 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -8,6 +8,7 @@ import 'package:dart_style/dart_style.dart'; import 'package:path/path.dart' as path; import 'ast.dart'; +import 'functional.dart'; import 'generator.dart'; import 'generator_tools.dart'; @@ -872,13 +873,6 @@ class $codecName extends StandardMessageCodec { } } - final bool hasARequiredFlutterMethod = api.methods - .followedBy(superClassFlutterMethods) - .followedBy(interfacesMethods) - .any((Method method) { - return method.location == ApiLocation.flutter && method.required; - }); - // Ast class used by code_builder. final cb.Class proxyApi = cb.Class( (cb.ClassBuilder builder) => builder @@ -930,7 +924,14 @@ class $codecName extends StandardMessageCodec { unattachedFields: api.unattachedFields, attachedFields: api.attachedFields, interfacesApis: interfacesApis, - hasARequiredFlutterMethod: hasARequiredFlutterMethod, + hasCallbackConstructor: api.methods + .followedBy(superClassFlutterMethods) + .followedBy(interfacesMethods) + .every( + (Method method) { + return method.location != ApiLocation.flutter || !method.required; + }, + ), )), ); @@ -1272,10 +1273,10 @@ class $codecName extends StandardMessageCodec { required Iterable unattachedFields, required Iterable attachedFields, required Iterable interfacesApis, - required bool hasARequiredFlutterMethod, + required bool hasCallbackConstructor, }) { return [ - // Flutter methods message handler + // Flutter methods message handler `*setUpMessageHandlers()` cb.Method.returnsVoid( (cb.MethodBuilder builder) => builder ..name = '${classMemberNamePrefix}setUpMessageHandlers' @@ -1301,7 +1302,7 @@ class $codecName extends StandardMessageCodec { ..named = true ..type = cb.refer('$instanceManagerClassName?'), ), - if (!hasARequiredFlutterMethod) + if (hasCallbackConstructor) cb.Parameter( (cb.ParameterBuilder builder) => builder ..name = '${classMemberNamePrefix}newInstance' @@ -1352,134 +1353,69 @@ class $codecName extends StandardMessageCodec { const cb.Code( 'final BinaryMessenger? binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', ), - if (!hasARequiredFlutterMethod) ...[ - const cb.Code('{'), - cb.Code( - "const String ${_varNamePrefix}channelName = r'${makeChannelNameWithStrings( - apiName: apiName, - methodName: '${classMemberNamePrefix}newInstance', - dartPackageName: dartPackageName, - )}';", - ), - _basicMessageChannel( - binaryMessenger: - cb.refer('${classMemberNamePrefix}binaryMessenger'), - ), - cb.refer('${_varNamePrefix}channel.setMessageHandler').call( - [ - cb.Method( - (cb.MethodBuilder builder) => builder - ..modifier = cb.MethodModifier.async - ..requiredParameters.add( - cb.Parameter( - (cb.ParameterBuilder builder) => builder - ..name = 'message' - ..type = cb.refer('Object?'), - ), - ) - ..body = cb.Block((cb.BlockBuilder builder) { - builder.statements.addAll([ - _assert( - condition: - cb.refer('message').notEqualTo(cb.literalNull), - message: cb.literalString( - 'Argument for \$${_varNamePrefix}channelName was null.', - ), - ), - const cb.Code( - 'final List args = (message as List?)!;', - ), - const cb.Code( - 'final int? instanceIdentifier = (args[0] as int?);', - ), - _assert( - condition: cb - .refer('instanceIdentifier') - .notEqualTo(cb.literalNull), - message: cb.literalString( - 'Argument for \$${_varNamePrefix}channelName was null, expected non-null int.', - ), - ), - ...unattachedFields.foldIndexed>( - [], - (int index, List previous, Field field) { - return previous - ..addAll(_messageArg(index + 1, field)); - }, - ), - cb - .refer( - '(${classMemberNamePrefix}instanceManager ?? $instanceManagerClassName.instance)', - ) - .property('addHostCreatedInstance') - .call([ - cb - .refer( - '${classMemberNamePrefix}newInstance?.call') - .call(unattachedFields.mapIndexed( - (int index, Field field) { - // The calling instance is the first arg. - final String name = _getSafeArgumentName( - index + 1, - field, - ); - return cb.refer(name).nullCheckedIf( - !field.type.isNullable, - ); - }, - )).ifNullThen( - cb - .refer( - '$apiName.${classMemberNamePrefix}detached') - .call( - [], - { - '${classMemberNamePrefix}binaryMessenger': - cb.refer( - '${classMemberNamePrefix}binaryMessenger'), - '${classMemberNamePrefix}instanceManager': - cb.refer( - '${classMemberNamePrefix}instanceManager'), - ...unattachedFields.toList().asMap().map( - (int index, Field field) { - final String argName = - _getSafeArgumentName( - index + 1, - field, - ); - return MapEntry( - field.name, - cb.refer(argName).nullCheckedIf( - !field.type.isNullable, - ), - ); - }, - ) - }, - ), - ), - cb.refer('instanceIdentifier').nullChecked - ]).statement, - const cb.Code('return;'), - ]); - }), - ).genericClosure - ], - ).statement, - const cb.Code('}'), - ], + 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( + (Field 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 '(${classMemberNamePrefix}instanceManager ?? $instanceManagerClassName.instance)\n' + ' .addHostCreatedInstance(\n' + ' $methodName?.call(${safeArgumentNames.skip(1).join(',')}) ??\n' + ' $apiName.${classMemberNamePrefix}detached(' + ' ${classMemberNamePrefix}binaryMessenger: ${classMemberNamePrefix}binaryMessenger,\n' + ' ${classMemberNamePrefix}instanceManager: ${classMemberNamePrefix}instanceManager,\n' + ' $argsAsNamedParams\n' + ' ),\n' + ' ${safeArgumentNames.first},\n' + ')'; + }, + ); + builder.statements.add(cb.Code(messageHandlerSink.toString())); + }).statements, ...flutterMethods.fold>( [], (List list, Method method) { final StringBuffer messageHandlerSink = StringBuffer(); const String instanceName = '${classMemberNamePrefix}instance'; - final String safeInstanceName = _getSafeArgumentName( - 0, - NamedType( - name: instanceName, - type: TypeDeclaration(baseName: apiName, isNullable: false), - ), - ); _writeFlutterMethodMessageHandler( Indent(messageHandlerSink), name: method.name, @@ -1513,10 +1449,11 @@ class $codecName extends StandardMessageCodec { '${classMemberNamePrefix}clearHandlers', onCreateApiCall: ( String methodName, - Iterable argNames, + Iterable parameters, + Iterable safeArgumentNames, ) { final String nullability = method.required ? '' : '?'; - return '($methodName ?? $safeInstanceName!.$methodName)$nullability.call(${argNames.join(',')})'; + return '($methodName ?? ${safeArgumentNames.first}.$methodName)$nullability.call(${safeArgumentNames.join(',')})'; }, ); return list..add(cb.Code(messageHandlerSink.toString())); @@ -2005,7 +1942,8 @@ if (${_varNamePrefix}replyList == null) { required bool isMockHandler, required bool isAsynchronous, String nullHandlerExpression = 'api == null', - String Function(String methodName, Iterable argNames) + String Function(String methodName, Iterable parameters, + Iterable safeArgumentNames) onCreateApiCall = _createFlutterApiMethodCall, }) { indent.write(''); @@ -2072,7 +2010,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) { @@ -2114,86 +2052,11 @@ if (${_varNamePrefix}replyList == null) { static String _createFlutterApiMethodCall( String methodName, - Iterable argNames, + Iterable parameters, + Iterable safeArgumentNames, ) { - return 'api.$methodName(${argNames.join(', ')})'; - } -} - -// Adds support for conditional expressions. -extension on cb.Expression { - cb.Expression nullCheckedIf(bool condition) => condition ? nullChecked : this; -} - -/// final = ([] as ); -Iterable _messageArg( - int index, - NamedType parameter, { - String argsVariableName = 'args', -}) { - final String argType = _addGenericTypes(parameter.type); - final String argName = _getSafeArgumentName(index, parameter); - final String genericArgType = _makeGenericTypeArguments(parameter.type); - final String castCall = _makeGenericCastCall(parameter.type); - - late final cb.Expression assign; - if (parameter.type.isEnum) { - assign = cb - .refer( - '$argsVariableName[$index] == null ? null : $argType.values[$argsVariableName[$index]! as int]', - ) - .expression; - } else { - assign = cb - .refer( - '($argsVariableName[$index] as $genericArgType?)${castCall.isEmpty ? '' : '?$castCall'}', - ) - .expression; + return 'api.$methodName(${safeArgumentNames.join(', ')})'; } - - return [ - cb - .declareFinal(argName, type: cb.refer('$argType?')) - .assign(assign) - .statement, - if (!parameter.type.isNullable) - _assert( - condition: cb.refer(argName).notEqualTo(cb.literalNull), - message: cb.literalString( - 'Argument for \$${_varNamePrefix}channelName was null, expected non-null $argType.', - ), - ), - ]; -} - -cb.Code _assert({ - required cb.Expression condition, - required cb.Expression message, -}) { - return cb.refer('assert').call([condition, message]).statement; -} - -cb.Code _basicMessageChannel({ - cb.Expression codec = const cb.Reference(_pigeonChannelCodec), - cb.Expression? binaryMessenger = const cb.Reference('binaryMessenger'), -}) { - final cb.Reference basicMessageChannel = cb.refer( - 'BasicMessageChannel', - ); - return cb - .declareFinal('${_varNamePrefix}channel', type: basicMessageChannel) - .assign( - basicMessageChannel.newInstance( - [ - cb.refer('${_varNamePrefix}channelName'), - codec, - ], - { - if (binaryMessenger != null) 'binaryMessenger': binaryMessenger, - }, - ), - ) - .statement; } cb.Reference _refer( 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 ff021fd996fa..8d83750e71fc 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 @@ -4787,136 +4787,122 @@ class ProxyIntegrationCoreApi extends ProxyApiSuperClass pigeon_instanceManager ?? Pigeon_InstanceManager.instance); final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.pigeon_newInstance'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final int? instanceIdentifier = (args[0] as int?); - assert( - instanceIdentifier != null, - 'Argument for $__pigeon_channelName was null, expected non-null int.', - ); - final bool? arg_aBool = (args[1] as bool?); - assert( - arg_aBool != null, - 'Argument for $__pigeon_channelName was null, expected non-null bool.', - ); - final int? arg_anInt = (args[2] as int?); - assert( - arg_anInt != null, - 'Argument for $__pigeon_channelName was null, expected non-null int.', - ); - final double? arg_aDouble = (args[3] as double?); - assert( - arg_aDouble != null, - 'Argument for $__pigeon_channelName was null, expected non-null double.', - ); - final String? arg_aString = (args[4] as String?); - assert( - arg_aString != null, - 'Argument for $__pigeon_channelName was null, expected non-null String.', - ); - final Uint8List? arg_aUint8List = (args[5] as Uint8List?); - assert( - arg_aUint8List != null, - 'Argument for $__pigeon_channelName was null, expected non-null Uint8List.', - ); - final List? arg_aList = - (args[6] as List?)?.cast(); - assert( - arg_aList != null, - 'Argument for $__pigeon_channelName was null, expected non-null List.', - ); - final Map? arg_aMap = - (args[7] as Map?)?.cast(); - assert( - arg_aMap != null, - 'Argument for $__pigeon_channelName 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 $__pigeon_channelName was null, expected non-null AnEnum.', - ); - final ProxyApiSuperClass? arg_aProxyApi = - (args[9] as ProxyApiSuperClass?); - assert( - arg_aProxyApi != null, - 'Argument for $__pigeon_channelName 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?); - (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, - ) ?? - ProxyIntegrationCoreApi.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, - ), - instanceIdentifier!, - ); - return; - }); + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyIntegrationCoreApi.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.ProxyIntegrationCoreApi.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.ProxyIntegrationCoreApi.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.ProxyIntegrationCoreApi.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.ProxyIntegrationCoreApi.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.ProxyIntegrationCoreApi.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.ProxyIntegrationCoreApi.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.ProxyIntegrationCoreApi.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.ProxyIntegrationCoreApi.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.ProxyIntegrationCoreApi.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.ProxyIntegrationCoreApi.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.ProxyIntegrationCoreApi.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) ?? + ProxyIntegrationCoreApi.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?>( @@ -8274,36 +8260,40 @@ class ProxyApiSuperClass extends Pigeon_ProxyApiBaseClass { pigeon_instanceManager ?? Pigeon_InstanceManager.instance); final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.pigeon_newInstance'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final int? instanceIdentifier = (args[0] as int?); - assert( - instanceIdentifier != null, - 'Argument for $__pigeon_channelName was null, expected non-null int.', - ); - (pigeon_instanceManager ?? Pigeon_InstanceManager.instance) - .addHostCreatedInstance( - pigeon_newInstance?.call() ?? - ProxyApiSuperClass.pigeon_detached( - pigeon_binaryMessenger: pigeon_binaryMessenger, - pigeon_instanceManager: pigeon_instanceManager, - ), - instanceIdentifier!, - ); - return; - }); + 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())); + } + }); + } } } @@ -8387,37 +8377,42 @@ class ProxyApiInterface extends Pigeon_ProxyApiBaseClass { pigeon_instanceManager ?? Pigeon_InstanceManager.instance); final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; { - const String __pigeon_channelName = - r'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.pigeon_newInstance'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: pigeon_binaryMessenger, - ); - __pigeon_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for $__pigeon_channelName was null.', - ); - final List args = (message as List?)!; - final int? instanceIdentifier = (args[0] as int?); - assert( - instanceIdentifier != null, - 'Argument for $__pigeon_channelName was null, expected non-null int.', - ); - (pigeon_instanceManager ?? Pigeon_InstanceManager.instance) - .addHostCreatedInstance( - pigeon_newInstance?.call() ?? - ProxyApiInterface.pigeon_detached( - pigeon_binaryMessenger: pigeon_binaryMessenger, - pigeon_instanceManager: pigeon_instanceManager, - ), - instanceIdentifier!, - ); - return; - }); + 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?>( From 79f9afa6f4e44534d47c8fe8a771be3396beb4c8 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Sun, 7 Jan 2024 17:20:11 -0500 Subject: [PATCH 72/73] fix unit tests --- packages/pigeon/test/dart_generator_test.dart | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/pigeon/test/dart_generator_test.dart b/packages/pigeon/test/dart_generator_test.dart index 5439d6dbdecf..24fb50f39026 100644 --- a/packages/pigeon/test/dart_generator_test.dart +++ b/packages/pigeon/test/dart_generator_test.dart @@ -2092,14 +2092,13 @@ name: foobar expect( collapsedCode, contains( - r"const String __pigeon_channelName = r'dev.flutter.pigeon.test_package.Api.pigeon_defaultConstructor';", + r"const String __pigeon_channelName = 'dev.flutter.pigeon.test_package.Api.pigeon_defaultConstructor';", ), ); expect( collapsedCode, contains( - r'__pigeon_channel.send([ ' - r'pigeon_instanceManager.addDartCreatedInstance(this) ])', + r'__pigeon_channel .send([__pigeon_instanceIdentifier])', ), ); }); @@ -2200,9 +2199,9 @@ name: foobar collapsedCode, contains( r'__pigeon_channel.send([ ' - r'pigeon_instanceManager.addDartCreatedInstance(this), ' + r'__pigeon_instanceIdentifier, ' r'validType, enumType.index, proxyApiType, ' - r'nullableValidType, nullableEnumType?.index, nullableProxyApiType, ])', + r'nullableValidType, nullableEnumType?.index, nullableProxyApiType ])', ), ); }); @@ -2310,9 +2309,9 @@ name: foobar collapsedCode, contains( r'__pigeon_channel.send([ ' - r'pigeon_instanceManager.addDartCreatedInstance(this), ' + r'__pigeon_instanceIdentifier, ' r'validType, enumType.index, proxyApiType, ' - r'nullableValidType, nullableEnumType?.index, nullableProxyApiType, ])', + r'nullableValidType, nullableEnumType?.index, nullableProxyApiType ])', ), ); expect( @@ -2532,7 +2531,7 @@ name: foobar contains( r'await __pigeon_channel.send([ this, validType, ' r'enumType.index, proxyApiType, nullableValidType, ' - r'nullableEnumType?.index, nullableProxyApiType, ])', + r'nullableEnumType?.index, nullableProxyApiType ])', ), ); }); @@ -2578,7 +2577,7 @@ name: foobar ); expect( collapsedCode, - contains(r'await __pigeon_channel.send([])'), + contains(r'await __pigeon_channel.send(null)'), ); }); }); @@ -2680,7 +2679,7 @@ name: foobar ); expect( code, - contains(r'final Api? instance = (args[0] as Api?);'), + contains(r'final Api? arg_pigeon_instance = (args[0] as Api?);'), ); expect( code, @@ -2711,10 +2710,10 @@ name: foobar expect( collapsedCode, contains( - r'(doSomething ?? instance!.doSomething)?.call( instance!, ' + 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, );', + r'arg_nullableProxyApiType);', ), ); }); From cd58d505dfad65f4058a03a29778e016f240a248 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Sun, 7 Jan 2024 17:23:17 -0500 Subject: [PATCH 73/73] use param --- packages/pigeon/lib/dart_generator.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index caac9be7ac2e..9b9ea5afbe12 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -1415,13 +1415,12 @@ class $codecName extends StandardMessageCodec { [], (List list, Method method) { final StringBuffer messageHandlerSink = StringBuffer(); - const String instanceName = '${classMemberNamePrefix}instance'; _writeFlutterMethodMessageHandler( Indent(messageHandlerSink), name: method.name, parameters: [ Parameter( - name: instanceName, + name: '${classMemberNamePrefix}instance', type: TypeDeclaration( baseName: apiName, isNullable: false,