diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 32c08225e63..c916abf3f5a 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,6 +1,16 @@ +## 14.0.0 + +* **Breaking change** [dart] Renames locally defined host API variables. + * [dart] Host api static field `codec` changed to `pigeonChannelCodec`. +* [dart] Adds named parameters to host API methods. +* [dart] Adds optional parameters to host API methods. +* [dart] Adds default values for class constructors and host API methods. +* Adds `isEnum` and `isClass` to `TypeDeclaration`s. +* [cpp] Fixes `FlutterError` generation being tied to ErrorOr. + ## 13.1.2 -* Adds compatibilty with `analyzer` 6.x. +* Adds compatibility with `analyzer` 6.x. ## 13.1.1 @@ -159,7 +169,7 @@ * [java] Adds a `GeneratedApi.FlutterError` exception for passing custom error details (code, message, details). * [kotlin] Adds a `FlutterError` exception for passing custom error details (code, message, details). * [kotlin] Adds an `errorClassName` option in `KotlinOptions` for custom error class names. -* [java] Removes legacy try catch from async apis. +* [java] Removes legacy try catch from async APIs. * [java] Removes legacy null check on non-nullable method arguments. * [cpp] Fixes wrong order of items in `FlutterError`. * Adds `FlutterError` handling integration tests for all platforms. @@ -212,7 +222,7 @@ ## 7.2.1 -* [kotlin] Fixes Flutter api int errors with updated casting. +* [kotlin] Fixes Flutter API int errors with updated casting. ## 7.2.0 @@ -238,7 +248,7 @@ ## 7.1.2 -* [swift] Adds error handling to sync host api methods. +* [swift] Adds error handling to sync host API methods. ## 7.1.1 @@ -352,7 +362,7 @@ ## 4.2.4 -* [kotlin] Fixes Kotlin generated sync host api error. +* [kotlin] Fixes Kotlin generated sync host API error. ## 4.2.3 @@ -831,7 +841,7 @@ class Foo { ## 0.1.0-experimental.11 -* Fixed setting an api to null in Java. +* Fixed setting an API to null in Java. ## 0.1.0-experimental.10 diff --git a/packages/pigeon/example/app/lib/src/messages.g.dart b/packages/pigeon/example/app/lib/src/messages.g.dart index a07585d8bd0..59213e4ef2b 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 +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -98,111 +98,118 @@ class ExampleHostApi { /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. ExampleHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec codec = _ExampleHostApiCodec(); + static const MessageCodec pigeonChannelCodec = + _ExampleHostApiCodec(); Future getHostLanguage() async { - const String channelName = + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.getHostLanguage'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as String?)!; + return (__pigeon_replyList[0] as String?)!; } } - Future add(int arg_a, int arg_b) async { - const String channelName = + Future add(int a, int b) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.add'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_a, arg_b]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([a, b]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as int?)!; + return (__pigeon_replyList[0] as int?)!; } } - Future sendMessage(MessageData arg_message) async { - const String channelName = + Future sendMessage(MessageData message) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.sendMessage'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_message]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([message]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as bool?)!; + return (__pigeon_replyList[0] as bool?)!; } } } abstract class MessageFlutterApi { - static const MessageCodec codec = StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = + StandardMessageCodec(); String flutterMethod(String? aString); static void setup(MessageFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod was null.'); final List args = (message as List?)!; diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index 820cdee8416..261ba62040d 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -28,7 +28,7 @@ class Method extends Node { Method({ required this.name, required this.returnType, - required this.arguments, + required this.parameters, this.isAsynchronous = false, this.offset, this.objcSelector = '', @@ -43,8 +43,8 @@ class Method extends Node { /// The data-type of the return value. TypeDeclaration returnType; - /// The arguments passed into the [Method]. - List arguments; + /// The parameters passed into the [Method]. + List parameters; /// Whether the receiver of this method is expected to return synchronously or not. bool isAsynchronous; @@ -74,7 +74,7 @@ class Method extends Node { objcSelector.isEmpty ? '' : ' objcSelector:$objcSelector'; final String swiftFunctionStr = swiftFunction.isEmpty ? '' : ' swiftFunction:$swiftFunction'; - return '(Method name:$name returnType:$returnType arguments:$arguments isAsynchronous:$isAsynchronous$objcSelectorStr$swiftFunctionStr documentationComments:$documentationComments)'; + return '(Method name:$name returnType:$returnType parameters:$parameters isAsynchronous:$isAsynchronous$objcSelectorStr$swiftFunctionStr documentationComments:$documentationComments)'; } } @@ -121,6 +121,8 @@ class TypeDeclaration { const TypeDeclaration({ required this.baseName, required this.isNullable, + this.associatedEnum, + this.associatedClass, this.typeArguments = const [], }); @@ -128,20 +130,34 @@ class TypeDeclaration { const TypeDeclaration.voidDeclaration() : baseName = 'void', isNullable = false, + associatedEnum = null, + associatedClass = null, typeArguments = const []; /// The base name of the [TypeDeclaration] (ex 'Foo' to 'Foo?'). final String baseName; - /// Returns true if the declaration represents 'void'. + /// Whether the declaration represents 'void'. bool get isVoid => baseName == 'void'; - /// The type arguments to the entity (ex 'Bar' to 'Foo?'). + /// Whether the type arguments to the entity (ex 'Bar' to 'Foo?'). final List typeArguments; - /// True if the type is nullable. + /// Whether the type is nullable. final bool isNullable; + /// Whether the [TypeDeclaration] has an [associatedEnum]. + bool get isEnum => associatedEnum != null; + + /// Associated [Enum], if any. + final Enum? associatedEnum; + + /// Whether the [TypeDeclaration] has an [associatedClass]. + bool get isClass => associatedClass != null; + + /// Associated [Class], if any. + final Class? associatedClass; + @override int get hashCode { // This has to be implemented because TypeDeclaration is used as a Key to a @@ -163,47 +179,148 @@ class TypeDeclaration { return other is TypeDeclaration && baseName == other.baseName && isNullable == other.isNullable && - _listEquals(typeArguments, other.typeArguments); + _listEquals(typeArguments, other.typeArguments) && + isEnum == other.isEnum && + isClass == other.isClass && + associatedClass == other.associatedClass && + associatedEnum == other.associatedEnum; } } + /// Returns duplicated `TypeDeclaration` with attached `associatedEnum` value. + TypeDeclaration copyWithEnum(Enum enumDefinition) { + return TypeDeclaration( + baseName: baseName, + isNullable: isNullable, + associatedEnum: enumDefinition, + typeArguments: typeArguments, + ); + } + + /// Returns duplicated `TypeDeclaration` with attached `associatedClass` value. + TypeDeclaration copyWithClass(Class classDefinition) { + return TypeDeclaration( + baseName: baseName, + isNullable: isNullable, + associatedClass: classDefinition, + typeArguments: typeArguments, + ); + } + @override String toString() { final String typeArgumentsStr = typeArguments.isEmpty ? '' : 'typeArguments:$typeArguments'; - return '(TypeDeclaration baseName:$baseName isNullable:$isNullable$typeArgumentsStr)'; + return '(TypeDeclaration baseName:$baseName isNullable:$isNullable$typeArgumentsStr isEnum:$isEnum isClass:$isClass)'; } } /// Represents a named entity that has a type. +@immutable class NamedType extends Node { /// Parametric constructor for [NamedType]. NamedType({ required this.name, required this.type, this.offset, + this.defaultValue, this.documentationComments = const [], }); /// The name of the entity. - String name; + final String name; /// The type. - TypeDeclaration type; + final TypeDeclaration type; /// The offset in the source file where the [NamedType] appears. - int? offset; + final int? offset; + + /// Stringified version of the default value of types that have default values. + final String? defaultValue; /// 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; + final List documentationComments; + + /// Returns a copy of [NamedType] instance with new attached [TypeDeclaration]. + NamedType copyWithType(TypeDeclaration type) { + return NamedType( + name: name, + type: type, + offset: offset, + defaultValue: defaultValue, + documentationComments: documentationComments, + ); + } + + @override + String toString() { + return '(NamedType name:$name type:$type defaultValue:$defaultValue documentationComments:$documentationComments)'; + } +} + +/// Represents a [Method]'s parameter that has a type and a name. +@immutable +class Parameter extends NamedType { + /// Parametric constructor for [Parameter]. + Parameter({ + required super.name, + required super.type, + super.offset, + super.defaultValue, + bool? isNamed, + bool? isOptional, + bool? isPositional, + bool? isRequired, + super.documentationComments, + }) : isNamed = isNamed ?? true, + isOptional = isOptional ?? false, + isPositional = isPositional ?? true, + isRequired = isRequired ?? true; + + /// Whether this parameter is a named parameter. + /// + /// Defaults to `true`. + final bool isNamed; + + /// Whether this parameter is an optional parameter. + /// + /// Defaults to `false`. + final bool isOptional; + + /// Whether this parameter is a positional parameter. + /// + /// Defaults to `true`. + final bool isPositional; + + /// Whether this parameter is a required parameter. + /// + /// Defaults to `true`. + final bool isRequired; + + /// Returns a copy of [Parameter] instance with new attached [TypeDeclaration]. + @override + Parameter copyWithType(TypeDeclaration type) { + return Parameter( + name: name, + type: type, + offset: offset, + defaultValue: defaultValue, + isNamed: isNamed, + isOptional: isOptional, + isPositional: isPositional, + isRequired: isRequired, + documentationComments: documentationComments, + ); + } @override String toString() { - return '(NamedType name:$name type:$type documentationComments:$documentationComments)'; + return '(Parameter name:$name type:$type isNamed:$isNamed isOptional:$isOptional isPositional:$isPositional isRequired:$isRequired documentationComments:$documentationComments)'; } } diff --git a/packages/pigeon/lib/ast_generator.dart b/packages/pigeon/lib/ast_generator.dart index 4b6ecaade6e..2dff0bc4f32 100644 --- a/packages/pigeon/lib/ast_generator.dart +++ b/packages/pigeon/lib/ast_generator.dart @@ -5,7 +5,7 @@ import 'ast.dart'; import 'generator_tools.dart'; -/// Writes the AST represention of [root] to [sink]. +/// Writes the AST representation of [root] to [sink]. void generateAst(Root root, StringSink sink) { final Indent indent = Indent(sink); final String output = root.toString(); diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index fb52a13aa83..41c8226bb80 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -196,6 +196,7 @@ class CppHeaderGenerator extends StructuredGenerator { final bool hasFlutterApi = root.apis.any((Api api) => api.methods.isNotEmpty && api.location == ApiLocation.flutter); + _writeFlutterError(indent); if (hasHostApi) { _writeErrorOr(indent, friends: root.apis.map((Api api) => api.name)); } @@ -209,7 +210,7 @@ class CppHeaderGenerator extends StructuredGenerator { CppOptions generatorOptions, Root root, Indent indent, - Class klass, { + Class classDefinition, { required String dartPackageName, }) { // When generating for a Pigeon unit test, add a test fixture friend class to @@ -227,31 +228,31 @@ class CppHeaderGenerator extends StructuredGenerator { ]; addDocumentationComments( - indent, klass.documentationComments, _docCommentSpec, + indent, classDefinition.documentationComments, _docCommentSpec, generatorComments: generatedMessages); final Iterable orderedFields = - getFieldsInSerializationOrder(klass); + getFieldsInSerializationOrder(classDefinition); - indent.write('class ${klass.name} '); + indent.write('class ${classDefinition.name} '); indent.addScoped('{', '};', () { _writeAccessBlock(indent, _ClassAccess.public, () { final Iterable requiredFields = orderedFields.where((NamedType type) => !type.type.isNullable); // Minimal constructor, if needed. if (requiredFields.length != orderedFields.length) { - _writeClassConstructor(root, indent, klass, requiredFields, + _writeClassConstructor(root, indent, classDefinition, requiredFields, 'Constructs an object setting all non-nullable fields.'); } // All-field constructor. - _writeClassConstructor(root, indent, klass, orderedFields, + _writeClassConstructor(root, indent, classDefinition, orderedFields, 'Constructs an object setting all fields.'); for (final NamedType field in orderedFields) { addDocumentationComments( indent, field.documentationComments, _docCommentSpec); - final HostDatatype baseDatatype = getFieldHostDatatype( - field, root.classes, root.enums, _baseCppTypeForBuiltinDartType); + final HostDatatype baseDatatype = + getFieldHostDatatype(field, _baseCppTypeForBuiltinDartType); // Declare a getter and setter. _writeFunctionDeclaration(indent, _makeGetterName(field), returnType: _getterReturnType(baseDatatype), isConst: true); @@ -278,15 +279,15 @@ class CppHeaderGenerator extends StructuredGenerator { _writeAccessBlock(indent, _ClassAccess.private, () { _writeFunctionDeclaration(indent, 'FromEncodableList', - returnType: klass.name, + returnType: classDefinition.name, parameters: ['const flutter::EncodableList& list'], isStatic: true); _writeFunctionDeclaration(indent, 'ToEncodableList', returnType: 'flutter::EncodableList', isConst: true); for (final Class friend in root.classes) { - if (friend != klass && - friend.fields.any( - (NamedType element) => element.type.baseName == klass.name)) { + if (friend != classDefinition && + friend.fields.any((NamedType element) => + element.type.baseName == classDefinition.name)) { indent.writeln('friend class ${friend.name};'); } } @@ -301,8 +302,8 @@ class CppHeaderGenerator extends StructuredGenerator { } for (final NamedType field in orderedFields) { - final HostDatatype hostDatatype = getFieldHostDatatype( - field, root.classes, root.enums, _baseCppTypeForBuiltinDartType); + final HostDatatype hostDatatype = + getFieldHostDatatype(field, _baseCppTypeForBuiltinDartType); indent.writeln( '${_valueType(hostDatatype)} ${_makeInstanceVariableName(field)};'); } @@ -336,18 +337,19 @@ class CppHeaderGenerator extends StructuredGenerator { _writeFunctionDeclaration(indent, 'GetCodec', returnType: 'const flutter::StandardMessageCodec&', isStatic: true); for (final Method func in api.methods) { - final HostDatatype returnType = getHostDatatype(func.returnType, - root.classes, root.enums, _baseCppTypeForBuiltinDartType); + final HostDatatype returnType = + getHostDatatype(func.returnType, _baseCppTypeForBuiltinDartType); addDocumentationComments( indent, func.documentationComments, _docCommentSpec); - final Iterable argTypes = func.arguments.map((NamedType arg) { - final HostDatatype hostType = getFieldHostDatatype( - arg, root.classes, root.enums, _baseCppTypeForBuiltinDartType); + final Iterable argTypes = + func.parameters.map((NamedType arg) { + final HostDatatype hostType = + getFieldHostDatatype(arg, _baseCppTypeForBuiltinDartType); return _flutterApiArgumentType(hostType); }); final Iterable argNames = - indexMap(func.arguments, _getArgumentName); + indexMap(func.parameters, _getArgumentName); final List parameters = [ ...map2(argTypes, argNames, (String x, String y) => '$x $y'), ..._flutterApiCallbackParameters(returnType), @@ -394,20 +396,20 @@ class CppHeaderGenerator extends StructuredGenerator { _writeFunctionDeclaration(indent, '~${api.name}', isVirtual: true, inlineNoop: true); for (final Method method in api.methods) { - final HostDatatype returnType = getHostDatatype(method.returnType, - root.classes, root.enums, _baseCppTypeForBuiltinDartType); + final HostDatatype returnType = getHostDatatype( + method.returnType, _baseCppTypeForBuiltinDartType); final String returnTypeName = _hostApiReturnType(returnType); final List parameters = []; - if (method.arguments.isNotEmpty) { + if (method.parameters.isNotEmpty) { final Iterable argTypes = - method.arguments.map((NamedType arg) { - final HostDatatype hostType = getFieldHostDatatype(arg, - root.classes, root.enums, _baseCppTypeForBuiltinDartType); + method.parameters.map((NamedType arg) { + final HostDatatype hostType = + getFieldHostDatatype(arg, _baseCppTypeForBuiltinDartType); return _hostApiArgumentType(hostType); }); final Iterable argNames = - method.arguments.map((NamedType e) => _makeVariableName(e)); + method.parameters.map((NamedType e) => _makeVariableName(e)); parameters.addAll( map2(argTypes, argNames, (String argType, String argName) { return '$argType $argName'; @@ -457,15 +459,15 @@ class CppHeaderGenerator extends StructuredGenerator { }, nestCount: 0); } - void _writeClassConstructor(Root root, Indent indent, Class klass, + void _writeClassConstructor(Root root, Indent indent, Class classDefinition, Iterable params, String docComment) { final List paramStrings = params.map((NamedType param) { - final HostDatatype hostDatatype = getFieldHostDatatype( - param, root.classes, root.enums, _baseCppTypeForBuiltinDartType); + final HostDatatype hostDatatype = + getFieldHostDatatype(param, _baseCppTypeForBuiltinDartType); return '${_hostApiArgumentType(hostDatatype)} ${_makeVariableName(param)}'; }).toList(); indent.writeln('$_commentPrefix $docComment'); - _writeFunctionDeclaration(indent, klass.name, + _writeFunctionDeclaration(indent, classDefinition.name, isConstructor: true, parameters: paramStrings); indent.newln(); } @@ -509,11 +511,7 @@ class CppHeaderGenerator extends StructuredGenerator { indent.newln(); } - void _writeErrorOr(Indent indent, - {Iterable friends = const []}) { - final String friendLines = friends - .map((String className) => '\tfriend class $className;') - .join('\n'); + void _writeFlutterError(Indent indent) { indent.format(''' class FlutterError { @@ -533,7 +531,15 @@ class FlutterError { \tstd::string code_; \tstd::string message_; \tflutter::EncodableValue details_; -}; +};'''); + } + + void _writeErrorOr(Indent indent, + {Iterable friends = const []}) { + final String friendLines = friends + .map((String className) => '\tfriend class $className;') + .join('\n'); + indent.format(''' template class ErrorOr { public: @@ -664,31 +670,27 @@ class CppSourceGenerator extends StructuredGenerator { CppOptions generatorOptions, Root root, Indent indent, - Class klass, { + Class classDefinition, { required String dartPackageName, }) { - final Set customClassNames = - root.classes.map((Class x) => x.name).toSet(); - final Set customEnumNames = - root.enums.map((Enum x) => x.name).toSet(); - - indent.writeln('$_commentPrefix ${klass.name}'); + indent.writeln('$_commentPrefix ${classDefinition.name}'); indent.newln(); final Iterable orderedFields = - getFieldsInSerializationOrder(klass); + getFieldsInSerializationOrder(classDefinition); final Iterable requiredFields = orderedFields.where((NamedType type) => !type.type.isNullable); // Minimal constructor, if needed. if (requiredFields.length != orderedFields.length) { - _writeClassConstructor(root, indent, klass, requiredFields); + _writeClassConstructor(root, indent, classDefinition, requiredFields); } // All-field constructor. - _writeClassConstructor(root, indent, klass, orderedFields); + _writeClassConstructor(root, indent, classDefinition, orderedFields); // Getters and setters. for (final NamedType field in orderedFields) { - _writeCppSourceClassField(generatorOptions, root, indent, klass, field); + _writeCppSourceClassField( + generatorOptions, root, indent, classDefinition, field); } // Serialization. @@ -696,9 +698,7 @@ class CppSourceGenerator extends StructuredGenerator { generatorOptions, root, indent, - klass, - customClassNames, - customEnumNames, + classDefinition, dartPackageName: dartPackageName, ); @@ -707,9 +707,7 @@ class CppSourceGenerator extends StructuredGenerator { generatorOptions, root, indent, - klass, - customClassNames, - customEnumNames, + classDefinition, dartPackageName: dartPackageName, ); } @@ -719,20 +717,19 @@ class CppSourceGenerator extends StructuredGenerator { CppOptions generatorOptions, Root root, Indent indent, - Class klass, - Set customClassNames, - Set customEnumNames, { + Class classDefinition, { required String dartPackageName, }) { _writeFunctionDefinition(indent, 'ToEncodableList', - scope: klass.name, + scope: classDefinition.name, returnType: 'EncodableList', isConst: true, body: () { indent.writeln('EncodableList list;'); - indent.writeln('list.reserve(${klass.fields.length});'); - for (final NamedType field in getFieldsInSerializationOrder(klass)) { - final HostDatatype hostDatatype = getFieldHostDatatype(field, - root.classes, root.enums, _shortBaseCppTypeForBuiltinDartType); + indent.writeln('list.reserve(${classDefinition.fields.length});'); + for (final NamedType field + in getFieldsInSerializationOrder(classDefinition)) { + final HostDatatype hostDatatype = + getFieldHostDatatype(field, _shortBaseCppTypeForBuiltinDartType); final String encodableValue = _wrappedHostApiArgumentExpression( root, _makeInstanceVariableName(field), field.type, hostDatatype, preSerializeClasses: true); @@ -747,23 +744,21 @@ class CppSourceGenerator extends StructuredGenerator { CppOptions generatorOptions, Root root, Indent indent, - Class klass, - Set customClassNames, - Set customEnumNames, { + Class classDefinition, { required String dartPackageName, }) { // Returns the expression to convert the given EncodableValue to a field // value. String getValueExpression(NamedType field, String encodable) { - if (customEnumNames.contains(field.type.baseName)) { + if (field.type.isEnum) { return '(${field.type.baseName})(std::get($encodable))'; } else if (field.type.baseName == 'int') { return '$encodable.LongValue()'; } else if (field.type.baseName == 'Object') { return encodable; } else { - final HostDatatype hostDatatype = getFieldHostDatatype(field, - root.classes, root.enums, _shortBaseCppTypeForBuiltinDartType); + final HostDatatype hostDatatype = + getFieldHostDatatype(field, _shortBaseCppTypeForBuiltinDartType); if (!hostDatatype.isBuiltin && root.classes .map((Class x) => x.name) @@ -776,12 +771,12 @@ class CppSourceGenerator extends StructuredGenerator { } _writeFunctionDefinition(indent, 'FromEncodableList', - scope: klass.name, - returnType: klass.name, + scope: classDefinition.name, + returnType: classDefinition.name, parameters: ['const EncodableList& list'], body: () { const String instanceVariable = 'decoded'; final Iterable<_IndexedField> indexedFields = indexMap( - getFieldsInSerializationOrder(klass), + getFieldsInSerializationOrder(classDefinition), (int index, NamedType field) => _IndexedField(index, field)); final Iterable<_IndexedField> nullableFields = indexedFields .where((_IndexedField field) => field.field.type.isNullable); @@ -796,7 +791,8 @@ class CppSourceGenerator extends StructuredGenerator { if (constructorArgs.isNotEmpty) { constructorArgs = '(\n\t$constructorArgs)'; } - indent.format('${klass.name} $instanceVariable$constructorArgs;'); + indent + .format('${classDefinition.name} $instanceVariable$constructorArgs;'); // Add the nullable fields via setters, since converting the encodable // values to the pointer types that the convenience constructor uses for @@ -850,15 +846,15 @@ class CppSourceGenerator extends StructuredGenerator { 'return flutter::StandardMessageCodec::GetInstance(&$codeSerializerName::GetInstance());'); }); for (final Method func in api.methods) { - final HostDatatype returnType = getHostDatatype(func.returnType, - root.classes, root.enums, _shortBaseCppTypeForBuiltinDartType); + final HostDatatype returnType = + getHostDatatype(func.returnType, _shortBaseCppTypeForBuiltinDartType); // Determine the input parameter list, saved in a structured form for later // use as platform channel call arguments. final Iterable<_HostNamedType> hostParameters = - indexMap(func.arguments, (int i, NamedType arg) { - final HostDatatype hostType = getFieldHostDatatype( - arg, root.classes, root.enums, _shortBaseCppTypeForBuiltinDartType); + indexMap(func.parameters, (int i, NamedType arg) { + final HostDatatype hostType = + getFieldHostDatatype(arg, _shortBaseCppTypeForBuiltinDartType); return _HostNamedType(_getSafeArgumentName(i, arg), hostType, arg.type); }); final List parameters = [ @@ -880,7 +876,7 @@ class CppSourceGenerator extends StructuredGenerator { // Convert arguments to EncodableValue versions. const String argumentListVariableName = 'encoded_api_arguments'; indent.write('EncodableValue $argumentListVariableName = '); - if (func.arguments.isEmpty) { + if (func.parameters.isEmpty) { indent.addln('EncodableValue();'); } else { indent.addScoped('EncodableValue(EncodableList{', '});', () { @@ -981,15 +977,13 @@ class CppSourceGenerator extends StructuredGenerator { indent.addScoped('{', '});', () { indent.writeScoped('try {', '}', () { final List methodArgument = []; - if (method.arguments.isNotEmpty) { + if (method.parameters.isNotEmpty) { indent.writeln( 'const auto& args = std::get(message);'); - enumerate(method.arguments, (int index, NamedType arg) { + enumerate(method.parameters, (int index, NamedType arg) { final HostDatatype hostType = getHostDatatype( arg.type, - root.classes, - root.enums, (TypeDeclaration x) => _shortBaseCppTypeForBuiltinDartType(x)); final String argName = _getSafeArgumentName(index, arg); @@ -1015,7 +1009,7 @@ class CppSourceGenerator extends StructuredGenerator { apiType: ApiType.host, ); final String unwrapEnum = - isEnum(root, arg.type) && arg.type.isNullable + arg.type.isEnum && arg.type.isNullable ? ' ? &(*$argName) : nullptr' : ''; methodArgument.add('$argName$unwrapEnum'); @@ -1023,10 +1017,7 @@ class CppSourceGenerator extends StructuredGenerator { } final HostDatatype returnType = getHostDatatype( - method.returnType, - root.classes, - root.enums, - _shortBaseCppTypeForBuiltinDartType); + method.returnType, _shortBaseCppTypeForBuiltinDartType); final String returnTypeName = _hostApiReturnType(returnType); if (method.isAsynchronous) { methodArgument.add( @@ -1150,15 +1141,13 @@ return EncodableValue(EncodableList{ }); } - void _writeClassConstructor( - Root root, Indent indent, Class klass, Iterable params) { + void _writeClassConstructor(Root root, Indent indent, Class classDefinition, + Iterable params) { final Iterable<_HostNamedType> hostParams = params.map((NamedType param) { return _HostNamedType( _makeVariableName(param), getFieldHostDatatype( param, - root.classes, - root.enums, _shortBaseCppTypeForBuiltinDartType, ), param.type, @@ -1173,16 +1162,16 @@ return EncodableValue(EncodableList{ .map((_HostNamedType param) => '${param.name}_(${_fieldValueExpression(param.hostType, param.name)})') .toList(); - _writeFunctionDefinition(indent, klass.name, - scope: klass.name, + _writeFunctionDefinition(indent, classDefinition.name, + scope: classDefinition.name, parameters: paramStrings, initializers: initializerStrings); } void _writeCppSourceClassField(CppOptions generatorOptions, Root root, - Indent indent, Class klass, NamedType field) { - final HostDatatype hostDatatype = getFieldHostDatatype( - field, root.classes, root.enums, _shortBaseCppTypeForBuiltinDartType); + Indent indent, Class classDefinition, NamedType field) { + final HostDatatype hostDatatype = + getFieldHostDatatype(field, _shortBaseCppTypeForBuiltinDartType); final String instanceVariableName = _makeInstanceVariableName(field); final String setterName = _makeSetterName(field); final String returnExpression = hostDatatype.isNullable @@ -1196,7 +1185,7 @@ return EncodableValue(EncodableList{ _writeFunctionDefinition( indent, setterName, - scope: klass.name, + scope: classDefinition.name, returnType: _voidType, parameters: [ '${_unownedArgumentType(type)} $setterArgumentName' @@ -1211,7 +1200,7 @@ return EncodableValue(EncodableList{ _writeFunctionDefinition( indent, _makeGetterName(field), - scope: klass.name, + scope: classDefinition.name, returnType: _getterReturnType(hostDatatype), isConst: true, body: () { @@ -1247,7 +1236,7 @@ return EncodableValue(EncodableList{ const String nullValue = 'EncodableValue()'; String enumPrefix = ''; - if (isEnum(root, returnType)) { + if (returnType.isEnum) { enumPrefix = '(int) '; } if (returnType.isVoid) { @@ -1255,11 +1244,11 @@ return EncodableValue(EncodableList{ errorCondition = 'output.has_value()'; errorGetter = 'value'; } else { - final HostDatatype hostType = getHostDatatype(returnType, root.classes, - root.enums, _shortBaseCppTypeForBuiltinDartType); + final HostDatatype hostType = + getHostDatatype(returnType, _shortBaseCppTypeForBuiltinDartType); const String extractedValue = 'std::move(output).TakeValue()'; - final String wrapperType = hostType.isBuiltin || isEnum(root, returnType) + final String wrapperType = hostType.isBuiltin || returnType.isEnum ? 'EncodableValue' : 'CustomEncodableValue'; if (returnType.isNullable) { @@ -1818,8 +1807,8 @@ List validateCpp(CppOptions options, Root root) { final List result = []; for (final Api api in root.apis) { for (final Method method in api.methods) { - for (final NamedType arg in method.arguments) { - if (isEnum(root, arg.type)) { + for (final NamedType arg in method.parameters) { + if (arg.type.isEnum) { // TODO(gaaclarke): Add line number and filename. result.add(Error( message: diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 672cab1c070..1f0b4dac38c 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -12,6 +12,15 @@ import 'generator_tools.dart'; /// Documentation comment open symbol. const String _docCommentPrefix = '///'; +/// Prefix for all local variables in host API methods. +/// +/// This lowers the chances of variable name collisions with +/// user defined parameters. +const String _varNamePrefix = '__pigeon_'; + +/// Name of field used for host API codec. +const String _pigeonChannelCodec = 'pigeonChannelCodec'; + /// Documentation comment spec. const DocumentCommentSpecification _docCommentSpec = DocumentCommentSpecification(_docCommentPrefix); @@ -85,7 +94,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', + '// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers', ); indent.newln(); } @@ -133,23 +142,19 @@ class DartGenerator extends StructuredGenerator { DartOptions generatorOptions, Root root, Indent indent, - Class klass, { + Class classDefinition, { required String dartPackageName, }) { - final Set customClassNames = - root.classes.map((Class x) => x.name).toSet(); - final Set customEnumNames = - root.enums.map((Enum x) => x.name).toSet(); - indent.newln(); addDocumentationComments( - indent, klass.documentationComments, _docCommentSpec); + indent, classDefinition.documentationComments, _docCommentSpec); - indent.write('class ${klass.name} '); + indent.write('class ${classDefinition.name} '); indent.addScoped('{', '}', () { - _writeConstructor(indent, klass); + _writeConstructor(indent, classDefinition); indent.newln(); - for (final NamedType field in getFieldsInSerializationOrder(klass)) { + for (final NamedType field + in getFieldsInSerializationOrder(classDefinition)) { addDocumentationComments( indent, field.documentationComments, _docCommentSpec); @@ -161,9 +166,7 @@ class DartGenerator extends StructuredGenerator { generatorOptions, root, indent, - klass, - customClassNames, - customEnumNames, + classDefinition, dartPackageName: dartPackageName, ); indent.newln(); @@ -171,20 +174,24 @@ class DartGenerator extends StructuredGenerator { generatorOptions, root, indent, - klass, - customClassNames, - customEnumNames, + classDefinition, dartPackageName: dartPackageName, ); }); } - void _writeConstructor(Indent indent, Class klass) { - indent.write(klass.name); + void _writeConstructor(Indent indent, Class classDefinition) { + indent.write(classDefinition.name); indent.addScoped('({', '});', () { - for (final NamedType field in getFieldsInSerializationOrder(klass)) { - final String required = field.type.isNullable ? '' : 'required '; - indent.writeln('${required}this.${field.name},'); + for (final NamedType field + in getFieldsInSerializationOrder(classDefinition)) { + final String required = + !field.type.isNullable && field.defaultValue == null + ? 'required ' + : ''; + final String defaultValueString = + field.defaultValue == null ? '' : ' = ${field.defaultValue}'; + indent.writeln('${required}this.${field.name}$defaultValueString,'); } }); } @@ -194,9 +201,7 @@ class DartGenerator extends StructuredGenerator { DartOptions generatorOptions, Root root, Indent indent, - Class klass, - Set customClassNames, - Set customEnumNames, { + Class classDefinition, { required String dartPackageName, }) { indent.write('Object encode() '); @@ -205,13 +210,14 @@ class DartGenerator extends StructuredGenerator { 'return ', ); indent.addScoped('[', '];', () { - for (final NamedType field in getFieldsInSerializationOrder(klass)) { + for (final NamedType field + in getFieldsInSerializationOrder(classDefinition)) { final String conditional = field.type.isNullable ? '?' : ''; - if (customClassNames.contains(field.type.baseName)) { + if (field.type.isClass) { indent.writeln( '${field.name}$conditional.encode(),', ); - } else if (customEnumNames.contains(field.type.baseName)) { + } else if (field.type.isEnum) { indent.writeln( '${field.name}$conditional.index,', ); @@ -228,9 +234,7 @@ class DartGenerator extends StructuredGenerator { DartOptions generatorOptions, Root root, Indent indent, - Class klass, - Set customClassNames, - Set customEnumNames, { + Class classDefinition, { required String dartPackageName, }) { void writeValueDecode(NamedType field, int index) { @@ -239,7 +243,7 @@ class DartGenerator extends StructuredGenerator { final String genericType = _makeGenericTypeArguments(field.type); final String castCall = _makeGenericCastCall(field.type); final String nullableTag = field.type.isNullable ? '?' : ''; - if (customClassNames.contains(field.type.baseName)) { + if (field.type.isClass) { final String nonNullValue = '${field.type.baseName}.decode($resultAt! as List)'; if (field.type.isNullable) { @@ -250,7 +254,7 @@ $resultAt != null } else { indent.add(nonNullValue); } - } else if (customEnumNames.contains(field.type.baseName)) { + } else if (field.type.isEnum) { final String nonNullValue = '${field.type.baseName}.values[$resultAt! as int]'; if (field.type.isNullable) { @@ -278,13 +282,13 @@ $resultAt != null } indent.write( - 'static ${klass.name} decode(Object result) ', + 'static ${classDefinition.name} decode(Object result) ', ); indent.addScoped('{', '}', () { indent.writeln('result as List;'); - indent.write('return ${klass.name}'); + indent.write('return ${classDefinition.name}'); indent.addScoped('(', ');', () { - enumerate(getFieldsInSerializationOrder(klass), + enumerate(getFieldsInSerializationOrder(classDefinition), (int index, final NamedType field) { indent.write('${field.name}: '); writeValueDecode(field, index); @@ -314,8 +318,6 @@ $resultAt != null required String dartPackageName, }) { assert(api.location == ApiLocation.flutter); - final List customEnumNames = - root.enums.map((Enum x) => x.name).toList(); String codecName = _standardMessageCodec; if (getCodecClasses(api, root).isNotEmpty) { codecName = _getCodecName(api); @@ -331,8 +333,8 @@ $resultAt != null indent.writeln( 'static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance;'); } - indent - .writeln('static const MessageCodec codec = $codecName();'); + indent.writeln( + 'static const MessageCodec $_pigeonChannelCodec = $codecName();'); indent.newln(); for (final Method func in api.methods) { addDocumentationComments( @@ -342,10 +344,7 @@ $resultAt != null final String returnType = isAsync ? 'Future<${_addGenericTypesNullable(func.returnType)}>' : _addGenericTypesNullable(func.returnType); - final String argSignature = _getMethodArgumentsSignature( - func, - _getArgumentName, - ); + final String argSignature = _getMethodParameterSignature(func); indent.writeln('$returnType ${func.name}($argSignature);'); indent.newln(); } @@ -356,20 +355,20 @@ $resultAt != null indent.write(''); indent.addScoped('{', '}', () { indent.writeln( - 'final BasicMessageChannel channel = BasicMessageChannel(', + 'final BasicMessageChannel ${_varNamePrefix}channel = BasicMessageChannel(', ); final String channelName = channelNameFunc == null ? makeChannelName(api, func, dartPackageName) : channelNameFunc(func); indent.nest(2, () { - indent.writeln("'$channelName', codec,"); + indent.writeln("'$channelName', $_pigeonChannelCodec,"); indent.writeln( 'binaryMessenger: binaryMessenger);', ); }); final String messageHandlerSetterWithOpeningParentheses = isMockHandler - ? '_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, ' - : 'channel.setMessageHandler('; + ? '_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(${_varNamePrefix}channel, ' + : '${_varNamePrefix}channel.setMessageHandler('; indent.write('if (api == null) '); indent.addScoped('{', '}', () { indent.writeln( @@ -387,7 +386,7 @@ $resultAt != null const String emptyReturnStatement = 'return wrapResponse(empty: true);'; String call; - if (func.arguments.isEmpty) { + if (func.parameters.isEmpty) { call = 'api.${func.name}()'; } else { indent.writeln('assert(message != null,'); @@ -397,7 +396,7 @@ $resultAt != null 'final List $argsArray = (message as List?)!;'); String argNameFunc(int index, NamedType type) => _getSafeArgumentName(index, type); - enumerate(func.arguments, (int count, NamedType arg) { + enumerate(func.parameters, (int count, NamedType arg) { final String argType = _addGenericTypes(arg.type); final String argName = argNameFunc(count, arg); final String genericArgType = @@ -405,7 +404,7 @@ $resultAt != null final String castCall = _makeGenericCastCall(arg.type); final String leftHandSide = 'final $argType? $argName'; - if (customEnumNames.contains(arg.type.baseName)) { + if (arg.type.isEnum) { indent.writeln( '$leftHandSide = $argsArray[$count] == null ? null : $argType.values[$argsArray[$count]! as int];'); } else { @@ -419,7 +418,7 @@ $resultAt != null } }); final Iterable argNames = - indexMap(func.arguments, (int index, NamedType field) { + indexMap(func.parameters, (int index, NamedType field) { final String name = _getSafeArgumentName(index, field); return '$name${field.type.isNullable ? '' : '!'}'; }); @@ -443,9 +442,8 @@ $resultAt != null const String returnExpression = 'output'; final String nullability = func.returnType.isNullable ? '?' : ''; - final String valueExtraction = isEnum(root, func.returnType) - ? '$nullability.index' - : ''; + final String valueExtraction = + func.returnType.isEnum ? '$nullability.index' : ''; final String returnStatement = isMockHandler ? 'return [$returnExpression$valueExtraction];' : 'return wrapResponse(result: $returnExpression$valueExtraction);'; @@ -499,8 +497,6 @@ $resultAt != null codecName = _getCodecName(api); _writeCodec(indent, codecName, api, root); } - final List customEnumNames = - root.enums.map((Enum x) => x.name).toList(); indent.newln(); bool first = true; addDocumentationComments( @@ -512,12 +508,12 @@ $resultAt != null /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. ${api.name}({BinaryMessenger? binaryMessenger}) -\t\t: _binaryMessenger = binaryMessenger; -final BinaryMessenger? _binaryMessenger; +\t\t: ${_varNamePrefix}binaryMessenger = binaryMessenger; +final BinaryMessenger? ${_varNamePrefix}binaryMessenger; '''); - indent - .writeln('static const MessageCodec codec = $codecName();'); + indent.writeln( + 'static const MessageCodec $_pigeonChannelCodec = $codecName();'); indent.newln(); for (final Method func in api.methods) { if (!first) { @@ -529,39 +525,36 @@ final BinaryMessenger? _binaryMessenger; indent, func.documentationComments, _docCommentSpec); String argSignature = ''; String sendArgument = 'null'; - if (func.arguments.isNotEmpty) { - String argNameFunc(int index, NamedType type) => - _getSafeArgumentName(index, type); + if (func.parameters.isNotEmpty) { final Iterable argExpressions = - indexMap(func.arguments, (int index, NamedType type) { - final String name = argNameFunc(index, type); - if (root.enums - .map((Enum e) => e.name) - .contains(type.type.baseName)) { + indexMap(func.parameters, (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 = _getMethodArgumentsSignature(func, argNameFunc); + argSignature = _getMethodParameterSignature(func); } indent.write( 'Future<${_addGenericTypesNullable(func.returnType)}> ${func.name}($argSignature) async ', ); indent.addScoped('{', '}', () { indent.writeln( - "const String channelName = '${makeChannelName(api, func, dartPackageName)}';"); + "const String ${_varNamePrefix}channelName = '${makeChannelName(api, func, dartPackageName)}';"); indent.writeScoped( - 'final BasicMessageChannel channel = BasicMessageChannel(', + 'final BasicMessageChannel ${_varNamePrefix}channel = BasicMessageChannel(', ');', () { - indent.writeln('channelName,'); - indent.writeln('codec,'); - indent.writeln('binaryMessenger: _binaryMessenger,'); + 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 = 'replyList[0]'; + const String accessor = '${_varNamePrefix}replyList[0]'; // Avoid warnings from pointlessly casting to `Object?`. final String nullablyTypedAccessor = returnType == 'Object' ? accessor : '($accessor as $returnType?)'; @@ -569,7 +562,7 @@ final BinaryMessenger? _binaryMessenger; ? (genericCastCall.isEmpty ? '' : '?') : '!'; String returnStatement = 'return'; - if (customEnumNames.contains(returnType)) { + if (func.returnType.isEnum) { if (func.returnType.isNullable) { returnStatement = '$returnStatement ($accessor as int?) == null ? null : $returnType.values[$accessor! as int]'; @@ -584,22 +577,22 @@ final BinaryMessenger? _binaryMessenger; returnStatement = '$returnStatement;'; indent.format(''' -final List? replyList = -\t\tawait channel.send($sendArgument) as List?; -if (replyList == null) { -\tthrow _createConnectionError(channelName); -} else if (replyList.length > 1) { +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: replyList[0]! as String, -\t\tmessage: replyList[1] as String?, -\t\tdetails: replyList[2], +\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 (replyList[0] == null) { +} else if (${_varNamePrefix}replyList[0] == null) { \tthrow PlatformException( \t\tcode: 'null-error', \t\tmessage: 'Host platform returned null value for non-null return value.', @@ -678,7 +671,7 @@ if (replyList == null) { 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, unnecessary_import', + '// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import, no_leading_underscores_for_local_identifiers', ); indent.writeln('// ignore_for_file: avoid_relative_lib_imports'); } @@ -825,23 +818,67 @@ String _makeGenericCastCall(TypeDeclaration type) { String _getSafeArgumentName(int count, NamedType field) => field.name.isEmpty ? 'arg$count' : 'arg_${field.name}'; -/// Generates an argument name if one isn't defined. -String _getArgumentName(int count, NamedType field) => +/// Generates a parameter name if one isn't defined. +String _getParameterName(int count, NamedType field) => field.name.isEmpty ? 'arg$count' : field.name; -/// Generates the arguments code for [func] -/// Example: (func, getArgumentName) -> 'String? foo, int bar' -String _getMethodArgumentsSignature( - Method func, - String Function(int index, NamedType arg) getArgumentName, -) { - return func.arguments.isEmpty - ? '' - : indexMap(func.arguments, (int index, NamedType arg) { - final String type = _addGenericTypesNullable(arg.type); - final String argName = getArgumentName(index, arg); - return '$type $argName'; - }).join(', '); +/// Generates the parameters code for [func] +/// Example: (func, _getParameterName) -> 'String? foo, int bar' +String _getMethodParameterSignature(Method func) { + String signature = ''; + if (func.parameters.isEmpty) { + return signature; + } + + final List requiredPositionalParams = func.parameters + .where((Parameter p) => p.isPositional && !p.isOptional) + .toList(); + final List optionalPositionalParams = func.parameters + .where((Parameter p) => p.isPositional && p.isOptional) + .toList(); + final List namedParams = + func.parameters.where((Parameter p) => !p.isPositional).toList(); + + String getParameterString(Parameter p) { + final String required = p.isRequired && !p.isPositional ? 'required ' : ''; + + final String type = _addGenericTypesNullable(p.type); + + final String defaultValue = + p.defaultValue == null ? '' : ' = ${p.defaultValue}'; + return '$required$type ${p.name}$defaultValue'; + } + + final String baseParameterString = requiredPositionalParams + .map((Parameter p) => getParameterString(p)) + .join(', '); + final String optionalParameterString = optionalPositionalParams + .map((Parameter p) => getParameterString(p)) + .join(', '); + final String namedParameterString = + namedParams.map((Parameter p) => getParameterString(p)).join(', '); + + // Parameter lists can end with either named or optional positional parameters, but not both. + if (requiredPositionalParams.isNotEmpty) { + signature = baseParameterString; + } + final String trailingComma = + optionalPositionalParams.isNotEmpty || namedParams.isNotEmpty ? ',' : ''; + final String baseParams = + signature.isNotEmpty ? '$signature$trailingComma ' : ''; + if (optionalPositionalParams.isNotEmpty) { + final String trailingComma = + requiredPositionalParams.length + optionalPositionalParams.length > 2 + ? ',' + : ''; + return '$baseParams[$optionalParameterString$trailingComma]'; + } + if (namedParams.isNotEmpty) { + final String trailingComma = + requiredPositionalParams.length + namedParams.length > 2 ? ',' : ''; + return '$baseParams{$namedParameterString$trailingComma}'; + } + return signature; } /// Converts a [List] of [TypeDeclaration]s to a comma separated [String] to be diff --git a/packages/pigeon/lib/generator.dart b/packages/pigeon/lib/generator.dart index cf9dc78cdb2..1bd08307874 100644 --- a/packages/pigeon/lib/generator.dart +++ b/packages/pigeon/lib/generator.dart @@ -176,12 +176,12 @@ abstract class StructuredGenerator extends Generator { Indent indent, { required String dartPackageName, }) { - for (final Class klass in root.classes) { + for (final Class classDefinition in root.classes) { writeDataClass( generatorOptions, root, indent, - klass, + classDefinition, dartPackageName: dartPackageName, ); } @@ -192,7 +192,7 @@ abstract class StructuredGenerator extends Generator { T generatorOptions, Root root, Indent indent, - Class klass, { + Class classDefinition, { required String dartPackageName, }); @@ -201,9 +201,7 @@ abstract class StructuredGenerator extends Generator { T generatorOptions, Root root, Indent indent, - Class klass, - Set customClassNames, - Set customEnumNames, { + Class classDefinition, { required String dartPackageName, }) {} @@ -212,9 +210,7 @@ abstract class StructuredGenerator extends Generator { T generatorOptions, Root root, Indent indent, - Class klass, - Set customClassNames, - Set customEnumNames, { + Class classDefinition, { required String dartPackageName, }) {} diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index cd51c71affe..050bbacb974 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 = '13.1.2'; +const String pigeonVersion = '14.0.0'; /// Read all the content from [stdin] to a String. String readStdin() { @@ -169,6 +169,8 @@ String makeChannelName(Api api, Method func, String dartPackageName) { return 'dev.flutter.pigeon.$dartPackageName.${api.name}.${func.name}'; } +// TODO(tarrinneal): Determine whether HostDataType is needed. + /// Represents the mapping of a Dart datatype to a Host datatype. class HostDatatype { /// Parametric constructor for HostDatatype. @@ -199,10 +201,10 @@ class HostDatatype { /// datatype for the Dart datatype for builtin types. /// /// [customResolver] can modify the datatype of custom types. -HostDatatype getFieldHostDatatype(NamedType field, List classes, - List enums, String? Function(TypeDeclaration) builtinResolver, +HostDatatype getFieldHostDatatype( + NamedType field, String? Function(TypeDeclaration) builtinResolver, {String Function(String)? customResolver}) { - return _getHostDatatype(field.type, classes, enums, builtinResolver, + return _getHostDatatype(field.type, builtinResolver, customResolver: customResolver, fieldName: field.name); } @@ -213,19 +215,19 @@ HostDatatype getFieldHostDatatype(NamedType field, List classes, /// datatype for the Dart datatype for builtin types. /// /// [customResolver] can modify the datatype of custom types. -HostDatatype getHostDatatype(TypeDeclaration type, List classes, - List enums, String? Function(TypeDeclaration) builtinResolver, +HostDatatype getHostDatatype( + TypeDeclaration type, String? Function(TypeDeclaration) builtinResolver, {String Function(String)? customResolver}) { - return _getHostDatatype(type, classes, enums, builtinResolver, + return _getHostDatatype(type, builtinResolver, customResolver: customResolver); } -HostDatatype _getHostDatatype(TypeDeclaration type, List classes, - List enums, String? Function(TypeDeclaration) builtinResolver, +HostDatatype _getHostDatatype( + TypeDeclaration type, String? Function(TypeDeclaration) builtinResolver, {String Function(String)? customResolver, String? fieldName}) { final String? datatype = builtinResolver(type); if (datatype == null) { - if (classes.map((Class x) => x.name).contains(type.baseName)) { + if (type.isClass) { final String customName = customResolver != null ? customResolver(type.baseName) : type.baseName; @@ -235,7 +237,7 @@ HostDatatype _getHostDatatype(TypeDeclaration type, List classes, isNullable: type.isNullable, isEnum: false, ); - } else if (enums.map((Enum x) => x.name).contains(type.baseName)) { + } else if (type.isEnum) { final String customName = customResolver != null ? customResolver(type.baseName) : type.baseName; @@ -412,7 +414,7 @@ Map> getReferencedTypes( final _Bag references = _Bag(); for (final Api api in apis) { for (final Method method in api.methods) { - for (final NamedType field in method.arguments) { + for (final NamedType field in method.parameters) { references.addMany(_getTypeArguments(field.type), field.offset); } references.addMany(_getTypeArguments(method.returnType), method.offset); @@ -478,10 +480,6 @@ Iterable getCodecClasses(Api api, Root root) sync* { } } -/// Returns true if the [TypeDeclaration] represents an enum. -bool isEnum(Root root, TypeDeclaration type) => - root.enums.map((Enum e) => e.name).contains(type.baseName); - /// Describes how to format a document comment. class DocumentCommentSpecification { /// Constructor for [DocumentationCommentSpecification] @@ -542,9 +540,9 @@ void addDocumentationComments( } /// Returns an ordered list of fields to provide consistent serialization order. -Iterable getFieldsInSerializationOrder(Class klass) { +Iterable getFieldsInSerializationOrder(Class classDefinition) { // This returns the fields in the order they are declared in the pigeon file. - return klass.fields; + return classDefinition.fields; } /// Crawls up the path of [dartFilePath] until it finds a pubspec.yaml in a diff --git a/packages/pigeon/lib/java_generator.dart b/packages/pigeon/lib/java_generator.dart index ca1e3b5bd1a..16e806a170b 100644 --- a/packages/pigeon/lib/java_generator.dart +++ b/packages/pigeon/lib/java_generator.dart @@ -196,55 +196,47 @@ class JavaGenerator extends StructuredGenerator { JavaOptions generatorOptions, Root root, Indent indent, - Class klass, { + Class classDefinition, { required String dartPackageName, }) { - final Set customClassNames = - root.classes.map((Class x) => x.name).toSet(); - final Set customEnumNames = - root.enums.map((Enum x) => x.name).toSet(); - const List generatedMessages = [ ' Generated class from Pigeon that represents data sent in messages.' ]; indent.newln(); addDocumentationComments( - indent, klass.documentationComments, _docCommentSpec, + indent, classDefinition.documentationComments, _docCommentSpec, generatorComments: generatedMessages); - indent.write('public static final class ${klass.name} '); + indent.write('public static final class ${classDefinition.name} '); indent.addScoped('{', '}', () { - for (final NamedType field in getFieldsInSerializationOrder(klass)) { + for (final NamedType field + in getFieldsInSerializationOrder(classDefinition)) { _writeClassField(generatorOptions, root, indent, field); indent.newln(); } - if (getFieldsInSerializationOrder(klass) + if (getFieldsInSerializationOrder(classDefinition) .map((NamedType e) => !e.type.isNullable) .any((bool e) => e)) { indent.writeln( '$_docCommentPrefix Constructor is non-public to enforce null safety; use Builder.$_docCommentSuffix'); - indent.writeln('${klass.name}() {}'); + indent.writeln('${classDefinition.name}() {}'); indent.newln(); } - _writeClassBuilder(generatorOptions, root, indent, klass); + _writeClassBuilder(generatorOptions, root, indent, classDefinition); writeClassEncode( generatorOptions, root, indent, - klass, - customClassNames, - customEnumNames, + classDefinition, dartPackageName: dartPackageName, ); writeClassDecode( generatorOptions, root, indent, - klass, - customClassNames, - customEnumNames, + classDefinition, dartPackageName: dartPackageName, ); }); @@ -252,8 +244,8 @@ class JavaGenerator extends StructuredGenerator { void _writeClassField( JavaOptions generatorOptions, Root root, Indent indent, NamedType field) { - final HostDatatype hostDatatype = getFieldHostDatatype(field, root.classes, - root.enums, (TypeDeclaration x) => _javaTypeForBuiltinDartType(x)); + final HostDatatype hostDatatype = getFieldHostDatatype( + field, (TypeDeclaration x) => _javaTypeForBuiltinDartType(x)); final String nullability = field.type.isNullable ? '@Nullable' : '@NonNull'; addDocumentationComments( indent, field.documentationComments, _docCommentSpec); @@ -284,16 +276,14 @@ class JavaGenerator extends StructuredGenerator { JavaOptions generatorOptions, Root root, Indent indent, - Class klass, + Class classDefinition, ) { indent.write('public static final class Builder '); indent.addScoped('{', '}', () { - for (final NamedType field in getFieldsInSerializationOrder(klass)) { + for (final NamedType field + in getFieldsInSerializationOrder(classDefinition)) { final HostDatatype hostDatatype = getFieldHostDatatype( - field, - root.classes, - root.enums, - (TypeDeclaration x) => _javaTypeForBuiltinDartType(x)); + field, (TypeDeclaration x) => _javaTypeForBuiltinDartType(x)); final String nullability = field.type.isNullable ? '@Nullable' : '@NonNull'; indent.newln(); @@ -308,11 +298,13 @@ class JavaGenerator extends StructuredGenerator { }); } indent.newln(); - indent.write('public @NonNull ${klass.name} build() '); + indent.write('public @NonNull ${classDefinition.name} build() '); indent.addScoped('{', '}', () { const String returnVal = 'pigeonReturn'; - indent.writeln('${klass.name} $returnVal = new ${klass.name}();'); - for (final NamedType field in getFieldsInSerializationOrder(klass)) { + indent.writeln( + '${classDefinition.name} $returnVal = new ${classDefinition.name}();'); + for (final NamedType field + in getFieldsInSerializationOrder(classDefinition)) { indent.writeln('$returnVal.${_makeSetter(field)}(${field.name});'); } indent.writeln('return $returnVal;'); @@ -325,9 +317,7 @@ class JavaGenerator extends StructuredGenerator { JavaOptions generatorOptions, Root root, Indent indent, - Class klass, - Set customClassNames, - Set customEnumNames, { + Class classDefinition, { required String dartPackageName, }) { indent.newln(); @@ -335,20 +325,14 @@ class JavaGenerator extends StructuredGenerator { indent.write('ArrayList toList() '); indent.addScoped('{', '}', () { indent.writeln( - 'ArrayList toListResult = new ArrayList(${klass.fields.length});'); - for (final NamedType field in getFieldsInSerializationOrder(klass)) { - final HostDatatype hostDatatype = getFieldHostDatatype( - field, - root.classes, - root.enums, - (TypeDeclaration x) => _javaTypeForBuiltinDartType(x)); + 'ArrayList toListResult = new ArrayList(${classDefinition.fields.length});'); + for (final NamedType field + in getFieldsInSerializationOrder(classDefinition)) { String toWriteValue = ''; final String fieldName = field.name; - if (!hostDatatype.isBuiltin && - customClassNames.contains(field.type.baseName)) { + if (field.type.isClass) { toWriteValue = '($fieldName == null) ? null : $fieldName.toList()'; - } else if (!hostDatatype.isBuiltin && - customEnumNames.contains(field.type.baseName)) { + } else if (field.type.isEnum) { toWriteValue = '$fieldName == null ? null : $fieldName.index'; } else { toWriteValue = field.name; @@ -364,28 +348,27 @@ class JavaGenerator extends StructuredGenerator { JavaOptions generatorOptions, Root root, Indent indent, - Class klass, - Set customClassNames, - Set customEnumNames, { + Class classDefinition, { required String dartPackageName, }) { indent.newln(); indent.write( - 'static @NonNull ${klass.name} fromList(@NonNull ArrayList list) '); + 'static @NonNull ${classDefinition.name} fromList(@NonNull ArrayList list) '); indent.addScoped('{', '}', () { const String result = 'pigeonResult'; - indent.writeln('${klass.name} $result = new ${klass.name}();'); - enumerate(getFieldsInSerializationOrder(klass), + indent.writeln( + '${classDefinition.name} $result = new ${classDefinition.name}();'); + enumerate(getFieldsInSerializationOrder(classDefinition), (int index, final NamedType field) { final String fieldVariable = field.name; final String setter = _makeSetter(field); indent.writeln('Object $fieldVariable = list.get($index);'); - if (customEnumNames.contains(field.type.baseName)) { + if (field.type.isEnum) { indent.writeln( '$result.$setter(${_intToEnum(fieldVariable, field.type.baseName, field.type.isNullable)});'); } else { indent.writeln( - '$result.$setter(${_castObject(field, root.classes, root.enums, fieldVariable)});'); + '$result.$setter(${_castObject(field, fieldVariable)});'); } }); indent.writeln('return $result;'); @@ -412,7 +395,7 @@ class JavaGenerator extends StructuredGenerator { /// Returns an argument name that can be used in a context where it is possible to collide /// and append `.index` to enums. String getEnumSafeArgumentExpression(int count, NamedType argument) { - if (isEnum(root, argument.type)) { + if (argument.type.isEnum) { return argument.type.isNullable ? '${_getArgumentName(count, argument)}Arg == null ? null : ${_getArgumentName(count, argument)}Arg.index' : '${_getArgumentName(count, argument)}Arg.index'; @@ -462,18 +445,18 @@ class JavaGenerator extends StructuredGenerator { String sendArgument; addDocumentationComments( indent, func.documentationComments, _docCommentSpec); - if (func.arguments.isEmpty) { + if (func.parameters.isEmpty) { indent.write( 'public void ${func.name}(@NonNull $resultType<$returnType> result) '); sendArgument = 'null'; } else { - final Iterable argTypes = func.arguments + final Iterable argTypes = func.parameters .map((NamedType e) => _nullsafeJavaTypeForDartType(e.type)); final Iterable argNames = - indexMap(func.arguments, _getSafeArgumentName); + indexMap(func.parameters, _getSafeArgumentName); final Iterable enumSafeArgNames = - indexMap(func.arguments, getEnumSafeArgumentExpression); - if (func.arguments.length == 1) { + indexMap(func.parameters, getEnumSafeArgumentExpression); + if (func.parameters.length == 1) { sendArgument = 'new ArrayList(Collections.singletonList(${enumSafeArgNames.first}))'; } else { @@ -527,7 +510,7 @@ class JavaGenerator extends StructuredGenerator { if (func.returnType.baseName == 'int') { outputExpression = 'listReply.get(0) == null ? null : ((Number) listReply.get(0)).longValue();'; - } else if (isEnum(root, func.returnType)) { + } else if (func.returnType.isEnum) { if (func.returnType.isNullable) { outputExpression = 'listReply.get(0) == null ? null : $returnType.values()[(int) listReply.get(0)];'; @@ -648,11 +631,11 @@ class JavaGenerator extends StructuredGenerator { ? 'void' : _javaTypeForDartType(method.returnType); final List argSignature = []; - if (method.arguments.isNotEmpty) { - final Iterable argTypes = method.arguments + if (method.parameters.isNotEmpty) { + final Iterable argTypes = method.parameters .map((NamedType e) => _nullsafeJavaTypeForDartType(e.type)); final Iterable argNames = - method.arguments.map((NamedType e) => e.name); + method.parameters.map((NamedType e) => e.name); argSignature .addAll(map2(argTypes, argNames, (String argType, String argName) { return '$argType $argName'; @@ -721,10 +704,10 @@ class JavaGenerator extends StructuredGenerator { indent.writeln( 'ArrayList wrapped = new ArrayList();'); final List methodArgument = []; - if (method.arguments.isNotEmpty) { + if (method.parameters.isNotEmpty) { indent.writeln( 'ArrayList args = (ArrayList) message;'); - enumerate(method.arguments, (int index, NamedType arg) { + enumerate(method.parameters, (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. @@ -736,7 +719,7 @@ class JavaGenerator extends StructuredGenerator { ? '($argName == null) ? null : $argName.longValue()' : argName; String accessor = 'args.get($index)'; - if (isEnum(root, arg.type)) { + if (arg.type.isEnum) { accessor = _intToEnum( accessor, arg.type.baseName, arg.type.isNullable); } else if (argType != 'Object') { @@ -749,7 +732,7 @@ class JavaGenerator extends StructuredGenerator { if (method.isAsynchronous) { final String resultValue = method.returnType.isVoid ? 'null' : 'result'; - if (isEnum(root, method.returnType)) { + if (method.returnType.isEnum) { enumTag = method.returnType.isNullable ? ' == null ? null : $resultValue.index' : '.index'; @@ -784,7 +767,7 @@ $resultType<$returnType> $resultName = indent.writeln('$call;'); indent.writeln('wrapped.add(0, null);'); } else { - if (isEnum(root, method.returnType)) { + if (method.returnType.isEnum) { enumTag = method.returnType.isNullable ? ' == null ? null : output.index' : '.index'; @@ -1083,14 +1066,12 @@ String _cast(String variable, {required String javaType}) { /// Casts variable named [varName] to the correct host datatype for [field]. /// This is for use in codecs where we may have a map representation of an /// object. -String _castObject( - NamedType field, List classes, List enums, String varName) { - final HostDatatype hostDatatype = getFieldHostDatatype(field, classes, enums, - (TypeDeclaration x) => _javaTypeForBuiltinDartType(x)); +String _castObject(NamedType field, String varName) { + final HostDatatype hostDatatype = getFieldHostDatatype( + field, (TypeDeclaration x) => _javaTypeForBuiltinDartType(x)); if (field.type.baseName == 'int') { return '($varName == null) ? null : (($varName instanceof Integer) ? (Integer) $varName : (${hostDatatype.datatype}) $varName)'; - } else if (!hostDatatype.isBuiltin && - classes.map((Class x) => x.name).contains(field.type.baseName)) { + } else if (field.type.isClass) { return '($varName == null) ? null : ${hostDatatype.datatype}.fromList((ArrayList) $varName)'; } else { return _cast(varName, javaType: hostDatatype.datatype); diff --git a/packages/pigeon/lib/kotlin_generator.dart b/packages/pigeon/lib/kotlin_generator.dart index 6956cdcbe76..e8d69ebef5f 100644 --- a/packages/pigeon/lib/kotlin_generator.dart +++ b/packages/pigeon/lib/kotlin_generator.dart @@ -151,27 +151,23 @@ class KotlinGenerator extends StructuredGenerator { KotlinOptions generatorOptions, Root root, Indent indent, - Class klass, { + Class classDefinition, { required String dartPackageName, }) { - final Set customClassNames = - root.classes.map((Class x) => x.name).toSet(); - final Set customEnumNames = - root.enums.map((Enum x) => x.name).toSet(); - const List generatedMessages = [ ' Generated class from Pigeon that represents data sent in messages.' ]; indent.newln(); addDocumentationComments( - indent, klass.documentationComments, _docCommentSpec, + indent, classDefinition.documentationComments, _docCommentSpec, generatorComments: generatedMessages); - indent.write('data class ${klass.name} '); + indent.write('data class ${classDefinition.name} '); indent.addScoped('(', '', () { - for (final NamedType element in getFieldsInSerializationOrder(klass)) { + for (final NamedType element + in getFieldsInSerializationOrder(classDefinition)) { _writeClassField(indent, element); - if (getFieldsInSerializationOrder(klass).last != element) { + if (getFieldsInSerializationOrder(classDefinition).last != element) { indent.addln(','); } else { indent.newln(); @@ -184,18 +180,14 @@ class KotlinGenerator extends StructuredGenerator { generatorOptions, root, indent, - klass, - customClassNames, - customEnumNames, + classDefinition, dartPackageName: dartPackageName, ); writeClassEncode( generatorOptions, root, indent, - klass, - customClassNames, - customEnumNames, + classDefinition, dartPackageName: dartPackageName, ); }); @@ -206,25 +198,22 @@ class KotlinGenerator extends StructuredGenerator { KotlinOptions generatorOptions, Root root, Indent indent, - Class klass, - Set customClassNames, - Set customEnumNames, { + Class classDefinition, { required String dartPackageName, }) { indent.write('fun toList(): List '); indent.addScoped('{', '}', () { indent.write('return listOf'); indent.addScoped('(', ')', () { - for (final NamedType field in getFieldsInSerializationOrder(klass)) { + for (final NamedType field + in getFieldsInSerializationOrder(classDefinition)) { final HostDatatype hostDatatype = _getHostDatatype(root, field); String toWriteValue = ''; final String fieldName = field.name; final String safeCall = field.type.isNullable ? '?' : ''; - if (!hostDatatype.isBuiltin && - customClassNames.contains(field.type.baseName)) { + if (field.type.isClass) { toWriteValue = '$fieldName$safeCall.toList()'; - } else if (!hostDatatype.isBuiltin && - customEnumNames.contains(field.type.baseName)) { + } else if (!hostDatatype.isBuiltin && field.type.isEnum) { toWriteValue = '$fieldName$safeCall.raw'; } else { toWriteValue = fieldName; @@ -240,12 +229,10 @@ class KotlinGenerator extends StructuredGenerator { KotlinOptions generatorOptions, Root root, Indent indent, - Class klass, - Set customClassNames, - Set customEnumNames, { + Class classDefinition, { required String dartPackageName, }) { - final String className = klass.name; + final String className = classDefinition.name; indent.write('companion object '); indent.addScoped('{', '}', () { @@ -253,23 +240,19 @@ class KotlinGenerator extends StructuredGenerator { indent.write('fun fromList(list: List): $className '); indent.addScoped('{', '}', () { - enumerate(getFieldsInSerializationOrder(klass), + enumerate(getFieldsInSerializationOrder(classDefinition), (int index, final NamedType field) { - final HostDatatype hostDatatype = _getHostDatatype(root, field); - final String listValue = 'list[$index]'; final String fieldType = _kotlinTypeForDartType(field.type); if (field.type.isNullable) { - if (!hostDatatype.isBuiltin && - customClassNames.contains(field.type.baseName)) { + if (field.type.isClass) { indent.write('val ${field.name}: $fieldType? = '); indent.add('($listValue as List?)?.let '); indent.addScoped('{', '}', () { indent.writeln('$fieldType.fromList(it)'); }); - } else if (!hostDatatype.isBuiltin && - customEnumNames.contains(field.type.baseName)) { + } else if (field.type.isEnum) { indent.write('val ${field.name}: $fieldType? = '); indent.add('($listValue as Int?)?.let '); indent.addScoped('{', '}', () { @@ -277,28 +260,29 @@ class KotlinGenerator extends StructuredGenerator { }); } else { indent.writeln( - 'val ${field.name} = ${_cast(root, indent, listValue, type: field.type)}'); + 'val ${field.name} = ${_cast(indent, listValue, type: field.type)}'); } } else { - if (!hostDatatype.isBuiltin && - customClassNames.contains(field.type.baseName)) { + if (field.type.isClass) { indent.writeln( 'val ${field.name} = $fieldType.fromList($listValue as List)'); - } else if (!hostDatatype.isBuiltin && - customEnumNames.contains(field.type.baseName)) { + } else if (field.type.isEnum) { indent.writeln( 'val ${field.name} = $fieldType.ofRaw($listValue as Int)!!'); } else { indent.writeln( - 'val ${field.name} = ${_cast(root, indent, listValue, type: field.type)}'); + 'val ${field.name} = ${_cast(indent, listValue, type: field.type)}'); } } }); indent.write('return $className('); - for (final NamedType field in getFieldsInSerializationOrder(klass)) { + for (final NamedType field + in getFieldsInSerializationOrder(classDefinition)) { final String comma = - getFieldsInSerializationOrder(klass).last == field ? '' : ', '; + getFieldsInSerializationOrder(classDefinition).last == field + ? '' + : ', '; indent.add('${field.name}$comma'); } indent.addln(')'); @@ -383,19 +367,19 @@ class KotlinGenerator extends StructuredGenerator { addDocumentationComments( indent, func.documentationComments, _docCommentSpec); - if (func.arguments.isEmpty) { + if (func.parameters.isEmpty) { indent.write( 'fun ${func.name}(callback: (Result<$returnType>) -> Unit) '); sendArgument = 'null'; } else { - final Iterable argTypes = func.arguments + final Iterable argTypes = func.parameters .map((NamedType e) => _nullsafeKotlinTypeForDartType(e.type)); final Iterable argNames = - indexMap(func.arguments, _getSafeArgumentName); + indexMap(func.parameters, _getSafeArgumentName); final Iterable enumSafeArgNames = indexMap( - func.arguments, + func.parameters, (int count, NamedType type) => - _getEnumSafeArgumentExpression(root, count, type)); + _getEnumSafeArgumentExpression(count, type)); sendArgument = 'listOf(${enumSafeArgNames.join(', ')})'; final String argsSignature = map2(argTypes, argNames, (String type, String name) => '$name: $type').join(', '); @@ -426,15 +410,14 @@ class KotlinGenerator extends StructuredGenerator { } else { const String output = 'output'; // Nullable enums require special handling. - if (isEnum(root, func.returnType) && - func.returnType.isNullable) { + if (func.returnType.isEnum && func.returnType.isNullable) { indent.writeScoped( 'val $output = (it[0] as Int?)?.let {', '}', () { indent.writeln('${func.returnType.baseName}.ofRaw(it)'); }); } else { indent.writeln( - 'val $output = ${_cast(root, indent, 'it[0]', type: func.returnType)}'); + 'val $output = ${_cast(indent, 'it[0]', type: func.returnType)}'); } indent.writeln('callback(Result.success($output))'); } @@ -486,11 +469,11 @@ class KotlinGenerator extends StructuredGenerator { indent.addScoped('{', '}', () { for (final Method method in api.methods) { final List argSignature = []; - if (method.arguments.isNotEmpty) { - final Iterable argTypes = method.arguments + if (method.parameters.isNotEmpty) { + final Iterable argTypes = method.parameters .map((NamedType e) => _nullsafeKotlinTypeForDartType(e.type)); final Iterable argNames = - method.arguments.map((NamedType e) => e.name); + method.parameters.map((NamedType e) => e.name); argSignature.addAll( map2(argTypes, argNames, (String argType, String argName) { return '$argName: $argType'; @@ -560,18 +543,18 @@ class KotlinGenerator extends StructuredGenerator { indent.write('if (api != null) '); indent.addScoped('{', '}', () { final String messageVarName = - method.arguments.isNotEmpty ? 'message' : '_'; + method.parameters.isNotEmpty ? 'message' : '_'; indent.write('channel.setMessageHandler '); indent.addScoped('{ $messageVarName, reply ->', '}', () { final List methodArguments = []; - if (method.arguments.isNotEmpty) { + if (method.parameters.isNotEmpty) { indent.writeln('val args = message as List'); - enumerate(method.arguments, (int index, NamedType arg) { + enumerate(method.parameters, (int index, NamedType arg) { final String argName = _getSafeArgumentName(index, arg); final String argIndex = 'args[$index]'; indent.writeln( - 'val $argName = ${_castForceUnwrap(argIndex, arg.type, root, indent)}'); + 'val $argName = ${_castForceUnwrap(argIndex, arg.type, indent)}'); methodArguments.add(argName); }); } @@ -592,7 +575,7 @@ class KotlinGenerator extends StructuredGenerator { indent.addScoped(' else {', '}', () { final String enumTagNullablePrefix = method.returnType.isNullable ? '?' : '!!'; - final String enumTag = isEnum(root, method.returnType) + final String enumTag = method.returnType.isEnum ? '$enumTagNullablePrefix.raw' : ''; if (method.returnType.isVoid) { @@ -613,7 +596,7 @@ class KotlinGenerator extends StructuredGenerator { indent.writeln('wrapped = listOf(null)'); } else { String enumTag = ''; - if (isEnum(root, method.returnType)) { + if (method.returnType.isEnum) { final String safeUnwrap = method.returnType.isNullable ? '?' : ''; enumTag = '$safeUnwrap.raw'; @@ -773,8 +756,8 @@ class KotlinGenerator extends StructuredGenerator { } HostDatatype _getHostDatatype(Root root, NamedType field) { - return getFieldHostDatatype(field, root.classes, root.enums, - (TypeDeclaration x) => _kotlinTypeForBuiltinDartType(x)); + return getFieldHostDatatype( + field, (TypeDeclaration x) => _kotlinTypeForBuiltinDartType(x)); } /// Calculates the name of the codec that will be generated for [api]. @@ -785,9 +768,8 @@ String _getArgumentName(int count, NamedType argument) => /// Returns an argument name that can be used in a context where it is possible to collide /// and append `.index` to enums. -String _getEnumSafeArgumentExpression( - Root root, int count, NamedType argument) { - if (isEnum(root, argument.type)) { +String _getEnumSafeArgumentExpression(int count, NamedType argument) { + if (argument.type.isEnum) { return argument.type.isNullable ? '${_getArgumentName(count, argument)}Arg?.raw' : '${_getArgumentName(count, argument)}Arg.raw'; @@ -799,15 +781,14 @@ String _getEnumSafeArgumentExpression( String _getSafeArgumentName(int count, NamedType argument) => '${_getArgumentName(count, argument)}Arg'; -String _castForceUnwrap( - String value, TypeDeclaration type, Root root, Indent indent) { - if (isEnum(root, type)) { +String _castForceUnwrap(String value, TypeDeclaration type, Indent indent) { + if (type.isEnum) { final String forceUnwrap = type.isNullable ? '' : '!!'; final String nullableConditionPrefix = type.isNullable ? 'if ($value == null) null else ' : ''; return '$nullableConditionPrefix${_kotlinTypeForDartType(type)}.ofRaw($value as Int)$forceUnwrap'; } else { - return _cast(root, indent, value, type: type); + return _cast(indent, value, type: type); } } @@ -872,8 +853,7 @@ String _nullsafeKotlinTypeForDartType(TypeDeclaration type) { } /// Returns an expression to cast [variable] to [kotlinType]. -String _cast(Root root, Indent indent, String variable, - {required TypeDeclaration type}) { +String _cast(Indent indent, String variable, {required TypeDeclaration type}) { // Special-case Any, since no-op casts cause warnings. final String typeString = _kotlinTypeForDartType(type); if (type.isNullable && typeString == 'Any') { @@ -882,7 +862,7 @@ String _cast(Root root, Indent indent, String variable, if (typeString == 'Int' || typeString == 'Long') { return '$variable${_castInt(type.isNullable)}'; } - if (isEnum(root, type)) { + if (type.isEnum) { if (type.isNullable) { return '($variable as Int?)?.let {\n' '${indent.str} $typeString.ofRaw(it)\n' diff --git a/packages/pigeon/lib/objc_generator.dart b/packages/pigeon/lib/objc_generator.dart index 96c02bf26dd..903957d083c 100644 --- a/packages/pigeon/lib/objc_generator.dart +++ b/packages/pigeon/lib/objc_generator.dart @@ -178,9 +178,9 @@ class ObjcHeaderGenerator extends StructuredGenerator { required String dartPackageName, }) { indent.newln(); - for (final Class klass in root.classes) { + for (final Class classDefinition in root.classes) { indent.writeln( - '@class ${_className(generatorOptions.prefix, klass.name)};'); + '@class ${_className(generatorOptions.prefix, classDefinition.name)};'); } indent.newln(); super.writeDataClasses( @@ -196,20 +196,20 @@ class ObjcHeaderGenerator extends StructuredGenerator { ObjcOptions generatorOptions, Root root, Indent indent, - Class klass, { + Class classDefinition, { required String dartPackageName, }) { final List classes = root.classes; final List enums = root.enums; final String? prefix = generatorOptions.prefix; - final List customEnumNames = enums.map((Enum x) => x.name).toList(); addDocumentationComments( - indent, klass.documentationComments, _docCommentSpec); + indent, classDefinition.documentationComments, _docCommentSpec); - indent.writeln('@interface ${_className(prefix, klass.name)} : NSObject'); - if (getFieldsInSerializationOrder(klass).isNotEmpty) { - if (getFieldsInSerializationOrder(klass) + indent.writeln( + '@interface ${_className(prefix, classDefinition.name)} : NSObject'); + if (getFieldsInSerializationOrder(classDefinition).isNotEmpty) { + if (getFieldsInSerializationOrder(classDefinition) .map((NamedType e) => !e.type.isNullable) .any((bool e) => e)) { indent.writeln( @@ -220,31 +220,29 @@ class ObjcHeaderGenerator extends StructuredGenerator { indent, generatorOptions, root, - klass, + classDefinition, classes, enums, prefix, ); indent.addln(';'); } - for (final NamedType field in getFieldsInSerializationOrder(klass)) { + for (final NamedType field + in getFieldsInSerializationOrder(classDefinition)) { final HostDatatype hostDatatype = getFieldHostDatatype( field, - classes, - enums, (TypeDeclaration x) => _objcTypeStringForPrimitiveDartType(prefix, x, beforeString: true), - customResolver: customEnumNames.contains(field.type.baseName) + customResolver: field.type.isEnum ? (String x) => _enumName(x, prefix: prefix) : (String x) => '${_className(prefix, x)} *'); late final String propertyType; addDocumentationComments( indent, field.documentationComments, _docCommentSpec); propertyType = _propertyTypeForDartType(field.type, - isNullable: field.type.isNullable, - isEnum: customEnumNames.contains(field.type.baseName)); + isNullable: field.type.isNullable, isEnum: field.type.isEnum); final String nullability = field.type.isNullable ? ', nullable' : ''; - final String fieldType = isEnum(root, field.type) && field.type.isNullable + final String fieldType = field.type.isEnum && field.type.isNullable ? _enumName(field.type.baseName, suffix: ' *', prefix: generatorOptions.prefix, @@ -262,9 +260,7 @@ class ObjcHeaderGenerator extends StructuredGenerator { ObjcOptions generatorOptions, Root root, Indent indent, - Class klass, - Set customClassNames, - Set customEnumNames, { + Class classDefinition, { required String dartPackageName, }) {} @@ -273,9 +269,7 @@ class ObjcHeaderGenerator extends StructuredGenerator { ObjcOptions generatorOptions, Root root, Indent indent, - Class klass, - Set customClassNames, - Set customEnumNames, { + Class classDefinition, { required String dartPackageName, }) {} @@ -318,7 +312,7 @@ class ObjcHeaderGenerator extends StructuredGenerator { forceNullability: true, ); final String callbackType = - _callbackForType(root, func.returnType, returnType, generatorOptions); + _callbackForType(func.returnType, returnType, generatorOptions); addDocumentationComments( indent, func.documentationComments, _docCommentSpec); @@ -328,8 +322,6 @@ class ObjcHeaderGenerator extends StructuredGenerator { returnType: 'void', lastArgName: 'completion', lastArgType: callbackType, - isEnum: (TypeDeclaration t) => isEnum(root, t), - root: root, )};'); } indent.writeln('@end'); @@ -377,7 +369,7 @@ class ObjcHeaderGenerator extends StructuredGenerator { lastArgName = 'completion'; if (func.returnType.isVoid) { lastArgType = 'void (^)(FlutterError *_Nullable)'; - } else if (isEnum(root, func.returnType)) { + } else if (func.returnType.isEnum) { lastArgType = 'void (^)($enumReturnType, FlutterError *_Nullable)'; } else { lastArgType = @@ -386,7 +378,7 @@ class ObjcHeaderGenerator extends StructuredGenerator { } else { if (func.returnType.isVoid) { returnType = 'void'; - } else if (isEnum(root, func.returnType)) { + } else if (func.returnType.isEnum) { returnType = enumReturnType; } else { returnType = 'nullable $returnTypeName'; @@ -411,8 +403,6 @@ class ObjcHeaderGenerator extends StructuredGenerator { returnType: returnType, lastArgName: lastArgName, lastArgType: lastArgType, - isEnum: (TypeDeclaration t) => isEnum(root, t), - root: root, ); indent.writeln('$signature;'); } @@ -500,8 +490,9 @@ class ObjcSourceGenerator extends StructuredGenerator { Indent indent, { required String dartPackageName, }) { - for (final Class klass in root.classes) { - _writeObjcSourceDataClassExtension(generatorOptions, indent, klass); + for (final Class classDefinition in root.classes) { + _writeObjcSourceDataClassExtension( + generatorOptions, indent, classDefinition); } indent.newln(); super.writeDataClasses( @@ -517,34 +508,31 @@ class ObjcSourceGenerator extends StructuredGenerator { ObjcOptions generatorOptions, Root root, Indent indent, - Class klass, { + Class classDefinition, { required String dartPackageName, }) { final Set customClassNames = root.classes.map((Class x) => x.name).toSet(); final Set customEnumNames = root.enums.map((Enum x) => x.name).toSet(); - final String className = _className(generatorOptions.prefix, klass.name); + final String className = + _className(generatorOptions.prefix, classDefinition.name); indent.writeln('@implementation $className'); - _writeObjcSourceClassInitializer(generatorOptions, root, indent, klass, - customClassNames, customEnumNames, className); + _writeObjcSourceClassInitializer(generatorOptions, root, indent, + classDefinition, customClassNames, customEnumNames, className); writeClassDecode( generatorOptions, root, indent, - klass, - customClassNames, - customEnumNames, + classDefinition, dartPackageName: dartPackageName, ); writeClassEncode( generatorOptions, root, indent, - klass, - customClassNames, - customEnumNames, + classDefinition, dartPackageName: dartPackageName, ); indent.writeln('@end'); @@ -556,18 +544,15 @@ class ObjcSourceGenerator extends StructuredGenerator { ObjcOptions generatorOptions, Root root, Indent indent, - Class klass, - Set customClassNames, - Set customEnumNames, { + Class classDefinition, { required String dartPackageName, }) { indent.write('- (NSArray *)toList '); indent.addScoped('{', '}', () { indent.write('return'); indent.addScoped(' @[', '];', () { - for (final NamedType field in klass.fields) { - indent.writeln( - '${_arrayValue(customClassNames, customEnumNames, field)},'); + for (final NamedType field in classDefinition.fields) { + indent.writeln('${_arrayValue(field)},'); } }); }); @@ -578,23 +563,22 @@ class ObjcSourceGenerator extends StructuredGenerator { ObjcOptions generatorOptions, Root root, Indent indent, - Class klass, - Set customClassNames, - Set customEnumNames, { + Class classDefinition, { required String dartPackageName, }) { - final String className = _className(generatorOptions.prefix, klass.name); + final String className = + _className(generatorOptions.prefix, classDefinition.name); indent.write('+ ($className *)fromList:(NSArray *)list '); indent.addScoped('{', '}', () { const String resultName = 'pigeonResult'; indent.writeln('$className *$resultName = [[$className alloc] init];'); - enumerate(getFieldsInSerializationOrder(klass), + enumerate(getFieldsInSerializationOrder(classDefinition), (int index, final NamedType field) { - final bool isEnumType = customEnumNames.contains(field.type.baseName); - final String valueGetter = _listGetter( - customClassNames, 'list', field, index, generatorOptions.prefix); + final bool isEnumType = field.type.isEnum; + final String valueGetter = + _listGetter('list', field, index, generatorOptions.prefix); final String? primitiveExtractionMethod = - _nsnumberExtractionMethod(field.type, isEnum: isEnumType); + _nsnumberExtractionMethod(field.type); final String ivarValueExpression; if (primitiveExtractionMethod != null) { ivarValueExpression = '[$valueGetter $primitiveExtractionMethod]'; @@ -766,19 +750,19 @@ static FlutterError *createConnectionError(NSString *channelName) { void unpackArgs(String variable) { indent.writeln('NSArray *args = $variable;'); int count = 0; - for (final NamedType arg in func.arguments) { + for (final NamedType arg in func.parameters) { final String argName = _getSafeArgName(count, arg); - final bool isEnumType = isEnum(root, arg.type); final String valueGetter = 'GetNullableObjectAtIndex(args, $count)'; final String? primitiveExtractionMethod = - _nsnumberExtractionMethod(arg.type, isEnum: isEnumType); + _nsnumberExtractionMethod(arg.type); final _ObjcType objcArgType = _objcTypeForDartType( - generatorOptions.prefix, arg.type, - isEnum: isEnumType); + generatorOptions.prefix, + arg.type, + ); if (primitiveExtractionMethod != null) { indent.writeln( '${objcArgType.beforeString}$argName = [$valueGetter $primitiveExtractionMethod];'); - } else if (isEnumType) { + } else if (arg.type.isEnum) { indent.writeln('NSNumber *${argName}AsNumber = $valueGetter;'); indent.writeln( '${_enumName(arg.type.baseName, suffix: ' *', prefix: '', box: true)}$argName = ${argName}AsNumber == nil ? nil : [[${_enumName(arg.type.baseName, prefix: generatorOptions.prefix, box: true)} alloc] initWithValue:[${argName}AsNumber integerValue]];'); @@ -793,7 +777,7 @@ static FlutterError *createConnectionError(NSString *channelName) { String callSignature, _ObjcType returnType) { if (func.returnType.isVoid) { const String callback = 'callback(wrapResult(nil, error));'; - if (func.arguments.isEmpty) { + if (func.parameters.isEmpty) { indent.writeScoped( '[api ${selectorComponents.first}:^(FlutterError *_Nullable error) {', '}];', () { @@ -813,15 +797,15 @@ static FlutterError *createConnectionError(NSString *channelName) { const String enumConversionExpression = 'enumValue == nil ? nil : [NSNumber numberWithInteger:enumValue.value];'; - if (isEnum(root, func.returnType)) { + if (func.returnType.isEnum) { returnTypeString = '${_enumName(returnType.baseName, suffix: ' *_Nullable', prefix: generatorOptions.prefix, box: true)} enumValue'; } - if (func.arguments.isEmpty) { + if (func.parameters.isEmpty) { indent.writeScoped( '[api ${selectorComponents.first}:^($returnTypeString, FlutterError *_Nullable error) {', '}];', () { - if (isEnum(root, func.returnType)) { + if (func.returnType.isEnum) { indent.writeln('$numberOutput $enumConversionExpression'); } indent.writeln(callback); @@ -830,7 +814,7 @@ static FlutterError *createConnectionError(NSString *channelName) { indent.writeScoped( '[api $callSignature ${selectorComponents.last}:^($returnTypeString, FlutterError *_Nullable error) {', '}];', () { - if (isEnum(root, func.returnType)) { + if (func.returnType.isEnum) { indent.writeln('$numberOutput $enumConversionExpression'); } indent.writeln(callback); @@ -845,7 +829,7 @@ static FlutterError *createConnectionError(NSString *channelName) { indent.writeln('$call;'); indent.writeln('callback(wrapResult(nil, error));'); } else { - if (isEnum(root, func.returnType)) { + if (func.returnType.isEnum) { indent.writeln( '${_enumName(func.returnType.baseName, suffix: ' *', prefix: generatorOptions.prefix, box: true)} enumBox = $call;'); indent.writeln( @@ -874,19 +858,19 @@ static FlutterError *createConnectionError(NSString *channelName) { final Iterable selectorComponents = _getSelectorComponents(func, lastSelectorComponent); final Iterable argNames = - indexMap(func.arguments, _getSafeArgName); + indexMap(func.parameters, _getSafeArgName); final String callSignature = map2(selectorComponents.take(argNames.length), argNames, (String selectorComponent, String argName) { return '$selectorComponent:$argName'; }).join(' '); - if (func.arguments.isNotEmpty) { + if (func.parameters.isNotEmpty) { unpackArgs('message'); } if (func.isAsynchronous) { writeAsyncBindings(selectorComponents, callSignature, returnType); } else { - final String syncCall = func.arguments.isEmpty + final String syncCall = func.parameters.isEmpty ? '[api ${selectorComponents.first}:&error]' : '[api $callSignature error:&error]'; writeSyncBindings(syncCall, returnType); @@ -925,8 +909,9 @@ static FlutterError *createConnectionError(NSString *channelName) { } void _writeObjcSourceDataClassExtension( - ObjcOptions languageOptions, Indent indent, Class klass) { - final String className = _className(languageOptions.prefix, klass.name); + ObjcOptions languageOptions, Indent indent, Class classDefinition) { + final String className = + _className(languageOptions.prefix, classDefinition.name); indent.newln(); indent.writeln('@interface $className ()'); indent.writeln('+ ($className *)fromList:(NSArray *)list;'); @@ -940,7 +925,7 @@ static FlutterError *createConnectionError(NSString *channelName) { ObjcOptions languageOptions, Root root, Indent indent, - Class klass, + Class classDefinition, Set customClassNames, Set customEnumNames, String className, @@ -949,7 +934,7 @@ static FlutterError *createConnectionError(NSString *channelName) { indent, languageOptions, root, - klass, + classDefinition, root.classes, root.enums, languageOptions.prefix, @@ -957,7 +942,8 @@ static FlutterError *createConnectionError(NSString *channelName) { indent.writeScoped(' {', '}', () { const String result = 'pigeonResult'; indent.writeln('$className* $result = [[$className alloc] init];'); - for (final NamedType field in getFieldsInSerializationOrder(klass)) { + for (final NamedType field + in getFieldsInSerializationOrder(classDefinition)) { indent.writeln('$result.${field.name} = ${field.name};'); } indent.writeln('return $result;'); @@ -1082,20 +1068,18 @@ static FlutterError *createConnectionError(NSString *channelName) { forceNullability: true, ); final String callbackType = - _callbackForType(root, func.returnType, returnType, languageOptions); + _callbackForType(func.returnType, returnType, languageOptions); String argNameFunc(int count, NamedType arg) => _getSafeArgName(count, arg); String sendArgument; - if (func.arguments.isEmpty) { + if (func.parameters.isEmpty) { sendArgument = 'nil'; } else { int count = 0; String makeVarOrNSNullExpression(NamedType arg) { final String argName = argNameFunc(count, arg); - final bool isEnumType = isEnum(root, arg.type); - String varExpression = - _collectionSafeExpression(argName, arg.type, isEnum: isEnumType); - if (isEnumType) { + String varExpression = _collectionSafeExpression(argName, arg.type); + if (arg.type.isEnum) { if (arg.type.isNullable) { varExpression = '${argNameFunc(count, arg)} == nil ? [NSNull null] : [NSNumber numberWithInteger:$argName.value]'; @@ -1108,7 +1092,7 @@ static FlutterError *createConnectionError(NSString *channelName) { } sendArgument = - '@[${func.arguments.map(makeVarOrNSNullExpression).join(', ')}]'; + '@[${func.parameters.map(makeVarOrNSNullExpression).join(', ')}]'; } indent.write(_makeObjcSignature( func: func, @@ -1117,8 +1101,6 @@ static FlutterError *createConnectionError(NSString *channelName) { lastArgName: 'completion', lastArgType: callbackType, argNameFunc: argNameFunc, - isEnum: (TypeDeclaration t) => isEnum(root, t), - root: root, )); indent.addScoped(' {', '}', () { indent.writeln( @@ -1149,7 +1131,7 @@ static FlutterError *createConnectionError(NSString *channelName) { if (func.returnType.isVoid) { indent.writeln('completion(nil);'); } else { - if (isEnum(root, func.returnType)) { + if (func.returnType.isEnum) { final String enumName = _enumName(returnType.baseName, prefix: languageOptions.prefix, box: true); indent.writeln('NSNumber *outputAsNumber = $nullCheck;'); @@ -1179,15 +1161,15 @@ void _writeObjcSourceClassInitializerDeclaration( Indent indent, ObjcOptions generatorOptions, Root root, - Class klass, + Class classDefinition, List classes, List enums, String? prefix) { - final List customEnumNames = enums.map((Enum x) => x.name).toList(); indent.write('+ (instancetype)makeWith'); bool isFirst = true; indent.nest(2, () { - for (final NamedType field in getFieldsInSerializationOrder(klass)) { + for (final NamedType field + in getFieldsInSerializationOrder(classDefinition)) { final String label = isFirst ? _capitalize(field.name) : field.name; final void Function(String) printer = isFirst ? indent.add @@ -1198,11 +1180,9 @@ void _writeObjcSourceClassInitializerDeclaration( isFirst = false; final HostDatatype hostDatatype = getFieldHostDatatype( field, - classes, - enums, (TypeDeclaration x) => _objcTypeStringForPrimitiveDartType(prefix, x, beforeString: true), - customResolver: customEnumNames.contains(field.type.baseName) + customResolver: field.type.isEnum ? (String x) => field.type.isNullable ? _enumName(x, suffix: ' *', prefix: prefix, box: true) : _enumName(x, prefix: prefix) @@ -1228,10 +1208,10 @@ String _className(String? prefix, String className) { /// Calculates callback block signature for async methods. String _callbackForType( - Root root, TypeDeclaration type, _ObjcType objcType, ObjcOptions options) { + TypeDeclaration type, _ObjcType objcType, ObjcOptions options) { if (type.isVoid) { return 'void (^)(FlutterError *_Nullable)'; - } else if (isEnum(root, type)) { + } else if (type.isEnum) { return 'void (^)(${_enumName(objcType.baseName, suffix: ' *_Nullable', prefix: options.prefix, box: true)}, FlutterError *_Nullable)'; } else { return 'void (^)(${objcType.beforeString}_Nullable, FlutterError *_Nullable)'; @@ -1287,10 +1267,10 @@ const Map _objcTypeForNonNullableDartTypeMap = 'Object': _ObjcType(baseName: 'id'), }; -bool _usesPrimitive(TypeDeclaration type, {required bool isEnum}) { +bool _usesPrimitive(TypeDeclaration type) { // Only non-nullable types are unboxed. if (!type.isNullable) { - if (isEnum) { + if (type.isEnum) { return true; } switch (type.baseName) { @@ -1303,20 +1283,23 @@ bool _usesPrimitive(TypeDeclaration type, {required bool isEnum}) { return false; } -String _collectionSafeExpression(String expression, TypeDeclaration type, - {required bool isEnum}) { - return _usesPrimitive(type, isEnum: isEnum) +String _collectionSafeExpression( + String expression, + TypeDeclaration type, +) { + return _usesPrimitive(type) ? '@($expression)' : '$expression ?: [NSNull null]'; } /// Returns the method to convert [type] from a boxed NSNumber to its /// corresponding primitive value, if any. -String? _nsnumberExtractionMethod(TypeDeclaration type, - {required bool isEnum}) { +String? _nsnumberExtractionMethod( + TypeDeclaration type, +) { // Only non-nullable types are unboxed. if (!type.isNullable) { - if (isEnum) { + if (type.isEnum) { return 'integerValue'; } switch (type.baseName) { @@ -1368,14 +1351,14 @@ String? _objcTypeStringForPrimitiveDartType( /// Returns the Objective-C type for a Dart [field], prepending the /// [classPrefix] for generated classes. _ObjcType _objcTypeForDartType(String? classPrefix, TypeDeclaration field, - {bool isEnum = false, bool forceNullability = false}) { + {bool forceNullability = false}) { final _ObjcType? primitiveType = _objcTypeForPrimitiveDartType(field, forceNullability: forceNullability); return primitiveType == null ? _ObjcType( baseName: _className(classPrefix, field.baseName), // Non-nullable enums are non-pointer types. - isPointer: !isEnum || (field.isNullable || forceNullability)) + isPointer: !field.isEnum || (field.isNullable || forceNullability)) : field.typeArguments.isEmpty ? primitiveType : _ObjcType( @@ -1428,24 +1411,24 @@ String _capitalize(String str) => Iterable _getSelectorComponents( Method func, String lastSelectorComponent) sync* { if (func.objcSelector.isEmpty) { - final Iterator it = func.arguments.iterator; + final Iterator it = func.parameters.iterator; final bool hasArguments = it.moveNext(); final String namePostfix = - (lastSelectorComponent.isNotEmpty && func.arguments.isEmpty) + (lastSelectorComponent.isNotEmpty && func.parameters.isEmpty) ? 'With${_capitalize(lastSelectorComponent)}' : ''; - yield '${func.name}${hasArguments ? _capitalize(func.arguments[0].name) : namePostfix}'; + yield '${func.name}${hasArguments ? _capitalize(func.parameters[0].name) : namePostfix}'; while (it.moveNext()) { yield it.current.name; } } else { - assert(':'.allMatches(func.objcSelector).length == func.arguments.length); + assert(':'.allMatches(func.objcSelector).length == func.parameters.length); final Iterable customComponents = func.objcSelector .split(':') .where((String element) => element.isNotEmpty); yield* customComponents; } - if (lastSelectorComponent.isNotEmpty && func.arguments.isNotEmpty) { + if (lastSelectorComponent.isNotEmpty && func.parameters.isNotEmpty) { yield lastSelectorComponent; } } @@ -1457,27 +1440,25 @@ Iterable _getSelectorComponents( /// [func]. This is typically used for passing in 'error' or 'completion' /// arguments that don't exist in the pigeon file but are required in the objc /// output. [argNameFunc] is the function used to generate the argument name -/// [func.arguments]. +/// [func.parameters]. String _makeObjcSignature({ required Method func, required ObjcOptions options, required String returnType, required String lastArgType, required String lastArgName, - required bool Function(TypeDeclaration) isEnum, - required Root root, String Function(int, NamedType)? argNameFunc, }) { argNameFunc = argNameFunc ?? (int _, NamedType e) => - e.type.isNullable && isEnum(e.type) ? '${e.name}Boxed' : e.name; + e.type.isNullable && e.type.isEnum ? '${e.name}Boxed' : e.name; final Iterable argNames = - followedByOne(indexMap(func.arguments, argNameFunc), lastArgName); + followedByOne(indexMap(func.parameters, argNameFunc), lastArgName); final Iterable selectorComponents = _getSelectorComponents(func, lastArgName); final Iterable argTypes = followedByOne( - func.arguments.map((NamedType arg) { - if (isEnum(arg.type)) { + func.parameters.map((NamedType arg) { + if (arg.type.isEnum) { return '${arg.type.isNullable ? 'nullable ' : ''}${_enumName(arg.type.baseName, suffix: arg.type.isNullable ? ' *' : '', prefix: options.prefix, box: arg.type.isNullable)}'; } else { final String nullable = arg.type.isNullable ? 'nullable ' : ''; @@ -1503,9 +1484,8 @@ String _makeObjcSignature({ /// provided [options]. void generateObjcHeader(ObjcOptions options, Root root, Indent indent) {} -String _listGetter(Set customClassNames, String list, NamedType field, - int index, String? prefix) { - if (customClassNames.contains(field.type.baseName)) { +String _listGetter(String list, NamedType field, int index, String? prefix) { + if (field.type.isClass) { String className = field.type.baseName; if (prefix != null) { className = '$prefix$className'; @@ -1516,19 +1496,19 @@ String _listGetter(Set customClassNames, String list, NamedType field, } } -String _arrayValue(Set customClassNames, Set customEnumNames, - NamedType field) { - final bool isEnumType = customEnumNames.contains(field.type.baseName); - if (customClassNames.contains(field.type.baseName)) { +String _arrayValue(NamedType field) { + if (field.type.isClass) { return '(self.${field.name} ? [self.${field.name} toList] : [NSNull null])'; - } else if (isEnumType) { + } else if (field.type.isEnum) { if (field.type.isNullable) { return '(self.${field.name} == nil ? [NSNull null] : [NSNumber numberWithInteger:self.${field.name}.value])'; } return '@(self.${field.name})'; } else { - return _collectionSafeExpression('self.${field.name}', field.type, - isEnum: isEnumType); + return _collectionSafeExpression( + 'self.${field.name}', + field.type, + ); } } @@ -1565,8 +1545,8 @@ List validateObjc(ObjcOptions options, Root root) { final List errors = []; for (final Api api in root.apis) { for (final Method method in api.methods) { - for (final NamedType arg in method.arguments) { - if (isEnum(root, arg.type) && arg.type.isNullable) { + for (final NamedType arg in method.parameters) { + if (arg.type.isEnum && arg.type.isNullable) { // TODO(gaaclarke): Add line number. errors.add(Error( message: diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 81bbb90c04e..032cb691788 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -21,6 +21,7 @@ import 'package:analyzer/dart/ast/token.dart'; 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:path/path.dart' as path; import 'ast.dart'; @@ -756,20 +757,21 @@ List _validateAst(Root root, String source) { final List customClasses = root.classes.map((Class x) => x.name).toList(); final Iterable customEnums = root.enums.map((Enum x) => x.name); - for (final Class klass in root.classes) { - for (final NamedType field in getFieldsInSerializationOrder(klass)) { + for (final Class classDefinition in root.classes) { + for (final NamedType field + in getFieldsInSerializationOrder(classDefinition)) { for (final TypeDeclaration typeArgument in field.type.typeArguments) { if (!typeArgument.isNullable) { result.add(Error( message: - 'Generic type arguments must be nullable in field "${field.name}" in class "${klass.name}".', + 'Generic type parameters must be nullable in field "${field.name}" in class "${classDefinition.name}".', lineNumber: _calculateLineNumberNullable(source, field.offset), )); } if (customEnums.contains(typeArgument.baseName)) { result.add(Error( message: - 'Enum types aren\'t supported in type arguments in "${field.name}" in class "${klass.name}".', + 'Enum types aren\'t supported in type arguments in "${field.name}" in class "${classDefinition.name}".', lineNumber: _calculateLineNumberNullable(source, field.offset), )); } @@ -779,7 +781,7 @@ List _validateAst(Root root, String source) { customEnums.contains(field.type.baseName))) { result.add(Error( message: - 'Unsupported datatype:"${field.type.baseName}" in class "${klass.name}".', + 'Unsupported datatype:"${field.type.baseName}" in class "${classDefinition.name}".', lineNumber: _calculateLineNumberNullable(source, field.offset), )); } @@ -787,31 +789,44 @@ List _validateAst(Root root, String source) { } for (final Api api in root.apis) { for (final Method method in api.methods) { - for (final NamedType unnamedType in method.arguments - .where((NamedType element) => element.type.baseName.isEmpty)) { - result.add(Error( - message: - 'Arguments must specify their type in method "${method.name}" in API: "${api.name}"', - lineNumber: _calculateLineNumberNullable(source, unnamedType.offset), - )); + for (final Parameter param in method.parameters) { + if (param.type.baseName.isEmpty) { + result.add(Error( + message: + 'Parameters must specify their type in method "${method.name}" in API: "${api.name}"', + lineNumber: _calculateLineNumberNullable(source, param.offset), + )); + } else if (param.name.startsWith('__pigeon_')) { + result.add(Error( + message: + 'Parameter name must not begin with "__pigeon_" in method "${method.name}" in API: "${api.name}"', + lineNumber: _calculateLineNumberNullable(source, param.offset), + )); + } else if (param.name == 'pigeonChannelCodec') { + result.add(Error( + message: + 'Parameter name must not be "pigeonChannelCodec" in method "${method.name}" in API: "${api.name}"', + lineNumber: _calculateLineNumberNullable(source, param.offset), + )); + } } if (method.objcSelector.isNotEmpty) { if (':'.allMatches(method.objcSelector).length != - method.arguments.length) { + method.parameters.length) { result.add(Error( message: - 'Invalid selector, expected ${method.arguments.length} arguments.', + 'Invalid selector, expected ${method.parameters.length} parameters.', lineNumber: _calculateLineNumberNullable(source, method.offset), )); } } if (method.swiftFunction.isNotEmpty) { final RegExp signatureRegex = - RegExp('\\w+ *\\((\\w+:){${method.arguments.length}}\\)'); + RegExp('\\w+ *\\((\\w+:){${method.parameters.length}}\\)'); if (!signatureRegex.hasMatch(method.swiftFunction)) { result.add(Error( message: - 'Invalid function signature, expected ${method.arguments.length} arguments.', + 'Invalid function signature, expected ${method.parameters.length} parameters.', lineNumber: _calculateLineNumberNullable(source, method.offset), )); } @@ -850,6 +865,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { final String source; Class? _currentClass; + Map _currentClassDefaultValues = {}; Api? _currentApi; Map? _pigeonOptions; @@ -864,6 +880,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { if (_currentClass != null) { _classes.add(_currentClass!); _currentClass = null; + _currentClassDefaultValues = {}; } } @@ -908,6 +925,24 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { lineNumber: lineNumber)); } } + for (final Class classDefinition in referencedClasses) { + final List fields = []; + for (final NamedType field in classDefinition.fields) { + fields.add(field.copyWithType(_attachClassesAndEnums(field.type))); + } + classDefinition.fields = fields; + } + + for (final Api api in _apis) { + for (final Method func in api.methods) { + final List paramList = []; + for (final Parameter param in func.parameters) { + paramList.add(param.copyWithType(_attachClassesAndEnums(param.type))); + } + func.parameters = paramList; + func.returnType = _attachClassesAndEnums(func.returnType); + } + } return ParseResults( root: totalErrors.isEmpty @@ -918,6 +953,19 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { ); } + TypeDeclaration _attachClassesAndEnums(TypeDeclaration type) { + final Enum? assocEnum = _enums.firstWhereOrNull( + (Enum enumDefinition) => enumDefinition.name == type.baseName); + final Class? assocClass = _classes.firstWhereOrNull( + (Class classDefinition) => classDefinition.name == type.baseName); + if (assocClass != null) { + return type.copyWithClass(assocClass); + } else if (assocEnum != null) { + return type.copyWithEnum(assocEnum); + } + return type; + } + Object _expressionToMap(dart_ast.Expression expression) { if (expression is dart_ast.MethodInvocation) { final Map result = {}; @@ -1059,26 +1107,56 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { []; } - NamedType formalParameterToField(dart_ast.FormalParameter parameter) { - final dart_ast.NamedType? namedType = - getFirstChildOfType(parameter); - if (namedType != null) { - final String argTypeBaseName = _getNamedTypeQualifiedName(namedType); - final bool isNullable = namedType.question != null; + Parameter formalParameterToPigeonParameter( + dart_ast.FormalParameter formalParameter, { + bool? isNamed, + bool? isOptional, + bool? isPositional, + bool? isRequired, + String? defaultValue, + }) { + final dart_ast.NamedType? parameter = + getFirstChildOfType(formalParameter); + final dart_ast.SimpleFormalParameter? simpleFormalParameter = + getFirstChildOfType(formalParameter); + if (parameter != null) { + final String argTypeBaseName = _getNamedTypeQualifiedName(parameter); + final bool isNullable = parameter.question != null; final List argTypeArguments = - typeAnnotationsToTypeArguments(namedType.typeArguments); - return NamedType( - type: TypeDeclaration( - baseName: argTypeBaseName, - isNullable: isNullable, - typeArguments: argTypeArguments), - name: parameter.name?.lexeme ?? '', - offset: parameter.offset); + typeAnnotationsToTypeArguments(parameter.typeArguments); + return Parameter( + type: TypeDeclaration( + baseName: argTypeBaseName, + isNullable: isNullable, + typeArguments: argTypeArguments, + ), + name: formalParameter.name?.lexeme ?? '', + offset: formalParameter.offset, + isNamed: isNamed, + isOptional: isOptional, + isPositional: isPositional, + isRequired: isRequired, + defaultValue: defaultValue, + ); + } else if (simpleFormalParameter != null) { + String? defaultValue; + if (formalParameter is dart_ast.DefaultFormalParameter) { + defaultValue = formalParameter.defaultValue?.toString(); + } + + return formalParameterToPigeonParameter( + simpleFormalParameter, + isNamed: simpleFormalParameter.isNamed, + isOptional: simpleFormalParameter.isOptional, + isPositional: simpleFormalParameter.isPositional, + isRequired: simpleFormalParameter.isRequired, + defaultValue: defaultValue, + ); } else { - return NamedType( + return Parameter( name: '', type: const TypeDeclaration(baseName: '', isNullable: false), - offset: parameter.offset, + offset: formalParameter.offset, ); } } @@ -1108,8 +1186,8 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { @override Object? visitMethodDeclaration(dart_ast.MethodDeclaration node) { final dart_ast.FormalParameterList parameters = node.parameters!; - final List arguments = - parameters.parameters.map(formalParameterToField).toList(); + final List arguments = + parameters.parameters.map(formalParameterToPigeonParameter).toList(); final bool isAsynchronous = _hasMetadata(node.metadata, 'async'); final String objcSelector = _findMetadata(node.metadata, 'ObjCSelector') ?.arguments @@ -1149,7 +1227,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { typeArguments: typeAnnotationsToTypeArguments(returnType.typeArguments), isNullable: returnType.question != null), - arguments: arguments, + parameters: arguments, isAsynchronous: isAsynchronous, objcSelector: objcSelector, swiftFunction: swiftFunction, @@ -1222,17 +1300,20 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { lineNumber: _calculateLineNumber(source, node.offset))); } else { final dart_ast.TypeArgumentList? typeArguments = type.typeArguments; - _currentClass!.fields.add(NamedType( + final String name = node.fields.variables[0].name.lexeme; + final NamedType field = NamedType( type: TypeDeclaration( baseName: _getNamedTypeQualifiedName(type), isNullable: type.question != null, typeArguments: typeAnnotationsToTypeArguments(typeArguments), ), - name: node.fields.variables[0].name.lexeme, + name: name, offset: node.offset, + defaultValue: _currentClassDefaultValues[name], documentationComments: _documentationCommentsParser(node.documentationComment?.tokens), - )); + ); + _currentClass!.fields.add(field); } } else { _errors.add(Error( @@ -1265,6 +1346,16 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { message: 'Constructor initializers aren\'t supported in data classes (use "this.fieldName") ("$node").', lineNumber: _calculateLineNumber(source, node.offset))); + } else { + for (final dart_ast.FormalParameter param + in node.parameters.parameters) { + if (param is dart_ast.DefaultFormalParameter) { + if (param.name != null && param.defaultValue != null) { + _currentClassDefaultValues[param.name!.toString()] = + param.defaultValue!.toString(); + } + } + } } } node.visitChildren(this); diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index 9fe23f2ce77..ae869426e62 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -113,25 +113,20 @@ import FlutterMacOS SwiftOptions generatorOptions, Root root, Indent indent, - Class klass, { + Class classDefinition, { required String dartPackageName, }) { - final Set customClassNames = - root.classes.map((Class x) => x.name).toSet(); - final Set customEnumNames = - root.enums.map((Enum x) => x.name).toSet(); - const List generatedComments = [ ' Generated class from Pigeon that represents data sent in messages.' ]; indent.newln(); addDocumentationComments( - indent, klass.documentationComments, _docCommentSpec, + indent, classDefinition.documentationComments, _docCommentSpec, generatorComments: generatedComments); - indent.write('struct ${klass.name} '); + indent.write('struct ${classDefinition.name} '); indent.addScoped('{', '}', () { - getFieldsInSerializationOrder(klass).forEach((NamedType field) { + getFieldsInSerializationOrder(classDefinition).forEach((NamedType field) { _writeClassField(indent, field); }); @@ -140,18 +135,14 @@ import FlutterMacOS generatorOptions, root, indent, - klass, - customClassNames, - customEnumNames, + classDefinition, dartPackageName: dartPackageName, ); writeClassEncode( generatorOptions, root, indent, - klass, - customClassNames, - customEnumNames, + classDefinition, dartPackageName: dartPackageName, ); }); @@ -162,25 +153,21 @@ import FlutterMacOS SwiftOptions generatorOptions, Root root, Indent indent, - Class klass, - Set customClassNames, - Set customEnumNames, { + Class classDefinition, { required String dartPackageName, }) { indent.write('func toList() -> [Any?] '); indent.addScoped('{', '}', () { indent.write('return '); indent.addScoped('[', ']', () { - for (final NamedType field in getFieldsInSerializationOrder(klass)) { - final HostDatatype hostDatatype = _getHostDatatype(root, field); + for (final NamedType field + in getFieldsInSerializationOrder(classDefinition)) { String toWriteValue = ''; final String fieldName = field.name; final String nullsafe = field.type.isNullable ? '?' : ''; - if (!hostDatatype.isBuiltin && - customClassNames.contains(field.type.baseName)) { + if (field.type.isClass) { toWriteValue = '$fieldName$nullsafe.toList()'; - } else if (!hostDatatype.isBuiltin && - customEnumNames.contains(field.type.baseName)) { + } else if (field.type.isEnum) { toWriteValue = '$fieldName$nullsafe.rawValue'; } else { toWriteValue = field.name; @@ -197,36 +184,34 @@ import FlutterMacOS SwiftOptions generatorOptions, Root root, Indent indent, - Class klass, - Set customClassNames, - Set customEnumNames, { + Class classDefinition, { required String dartPackageName, }) { - final String className = klass.name; + final String className = classDefinition.name; indent.write('static func fromList(_ list: [Any?]) -> $className? '); indent.addScoped('{', '}', () { - enumerate(getFieldsInSerializationOrder(klass), + enumerate(getFieldsInSerializationOrder(classDefinition), (int index, final NamedType field) { final String listValue = 'list[$index]'; _writeDecodeCasting( - root: root, indent: indent, value: listValue, variableName: field.name, type: field.type, - listEncodedClassNames: customClassNames, - listEncodedEnumNames: customEnumNames, ); }); indent.newln(); indent.write('return '); indent.addScoped('$className(', ')', () { - for (final NamedType field in getFieldsInSerializationOrder(klass)) { + for (final NamedType field + in getFieldsInSerializationOrder(classDefinition)) { final String comma = - getFieldsInSerializationOrder(klass).last == field ? '' : ','; + getFieldsInSerializationOrder(classDefinition).last == field + ? '' + : ','; indent.writeln('${field.name}: ${field.name}$comma'); } }); @@ -280,7 +265,7 @@ import FlutterMacOS String getEnumSafeArgumentExpression( Root root, int count, NamedType argument) { String enumTag = ''; - if (isEnum(root, argument.type)) { + if (argument.type.isEnum) { enumTag = argument.type.isNullable ? '?.rawValue' : '.rawValue'; } @@ -326,12 +311,12 @@ import FlutterMacOS addDocumentationComments( indent, func.documentationComments, _docCommentSpec); indent.writeScoped('${_getMethodSignature(func)} {', '}', () { - final Iterable enumSafeArgNames = func.arguments + final Iterable enumSafeArgNames = func.parameters .asMap() .entries .map((MapEntry e) => getEnumSafeArgumentExpression(root, e.key, e.value)); - final String sendArgument = func.arguments.isEmpty + final String sendArgument = func.parameters.isEmpty ? 'nil' : '[${enumSafeArgNames.join(', ')}] as [Any?]'; const String channel = 'channel'; @@ -367,13 +352,15 @@ import FlutterMacOS if (func.returnType.isVoid) { indent.writeln('completion(.success(Void()))'); } else { - _writeDecodeCasting( - root: root, - indent: indent, - value: 'listResponse[0]', - variableName: 'result', - type: func.returnType, - ); + final String fieldType = _swiftTypeForDartType(func.returnType); + + _writeGenericCasting( + indent: indent, + value: 'listResponse[0]', + variableName: 'result', + fieldType: fieldType, + type: func.returnType); + indent.writeln('completion(.success(result))'); } }); @@ -481,7 +468,7 @@ import FlutterMacOS indent.addScoped('{', '}', () { indent.write('$varChannelName.setMessageHandler '); final String messageVarName = - method.arguments.isNotEmpty ? 'message' : '_'; + method.parameters.isNotEmpty ? 'message' : '_'; indent.addScoped('{ $messageVarName, reply in', '}', () { final List methodArgument = []; if (components.arguments.isNotEmpty) { @@ -491,13 +478,15 @@ import FlutterMacOS final String argName = _getSafeArgumentName(index, arg.namedType); final String argIndex = 'args[$index]'; - _writeDecodeCasting( - root: root, - indent: indent, - value: argIndex, - variableName: argName, - type: arg.type, - ); + final String fieldType = _swiftTypeForDartType(arg.type); + + _writeGenericCasting( + indent: indent, + value: argIndex, + variableName: argName, + fieldType: fieldType, + type: arg.type); + if (arg.label == '_') { methodArgument.add(argName); } else { @@ -520,9 +509,8 @@ import FlutterMacOS indent.addScoped('{', '}', () { final String nullsafe = method.returnType.isNullable ? '?' : ''; - final String enumTag = isEnum(root, method.returnType) - ? '$nullsafe.rawValue' - : ''; + final String enumTag = + method.returnType.isEnum ? '$nullsafe.rawValue' : ''; indent.writeln('case .success$successVariableInit:'); indent.nest(1, () { indent.writeln('reply(wrapResult($resultName$enumTag))'); @@ -541,13 +529,13 @@ import FlutterMacOS indent.writeln('reply(wrapResult(nil))'); } else { String enumTag = ''; - if (isEnum(root, method.returnType)) { + if (method.returnType.isEnum) { enumTag = '.rawValue'; } - enumTag = method.returnType.isNullable && - isEnum(root, method.returnType) - ? '?$enumTag' - : enumTag; + enumTag = + method.returnType.isNullable && method.returnType.isEnum + ? '?$enumTag' + : enumTag; indent.writeln('let result = $call'); indent.writeln('reply(wrapResult(result$enumTag))'); } @@ -654,49 +642,60 @@ import FlutterMacOS indent.newln(); } + String _castForceUnwrap(String value, TypeDeclaration type) { + assert(!type.isVoid); + if (type.isEnum) { + String output = + '${_swiftTypeForDartType(type)}(rawValue: $value as! Int)!'; + if (type.isNullable) { + output = 'isNullish($value) ? nil : $output'; + } + return output; + } else if (type.baseName == 'Object') { + return value + (type.isNullable ? '' : '!'); + } else if (type.baseName == 'int') { + if (type.isNullable) { + // Nullable ints need to check for NSNull, and Int32 before casting can be done safely. + // This nested ternary is a necessary evil to avoid less efficient conversions. + return 'isNullish($value) ? nil : ($value is Int64? ? $value as! Int64? : Int64($value as! Int32))'; + } else { + return '$value is Int64 ? $value as! Int64 : Int64($value as! Int32)'; + } + } else if (type.isNullable) { + return 'nilOrValue($value)'; + } else { + return '$value as! ${_swiftTypeForDartType(type)}'; + } + } + + void _writeGenericCasting({ + required Indent indent, + required String value, + required String variableName, + required String fieldType, + required TypeDeclaration type, + }) { + if (type.isNullable) { + indent.writeln( + 'let $variableName: $fieldType? = ${_castForceUnwrap(value, type)}'); + } else { + indent.writeln('let $variableName = ${_castForceUnwrap(value, type)}'); + } + } + /// Writes decode and casting code for any type. /// /// Optional parameters should only be used for class decoding. void _writeDecodeCasting({ - required Root root, required Indent indent, required String value, required String variableName, required TypeDeclaration type, - Set? listEncodedClassNames, - Set? listEncodedEnumNames, }) { - String castForceUnwrap(String value, TypeDeclaration type, Root root) { - assert(!type.isVoid); - if (isEnum(root, type)) { - String output = - '${_swiftTypeForDartType(type)}(rawValue: $value as! Int)!'; - if (type.isNullable) { - output = 'isNullish($value) ? nil : $output'; - } - return output; - } else if (type.baseName == 'Object') { - return value + (type.isNullable ? '' : '!'); - } else if (type.baseName == 'int') { - if (type.isNullable) { - // Nullable ints need to check for NSNull, and Int32 before casting can be done safely. - // This nested ternary is a necessary evil to avoid less efficient conversions. - return 'isNullish($value) ? nil : ($value is Int64? ? $value as! Int64? : Int64($value as! Int32))'; - } else { - return '$value is Int64 ? $value as! Int64 : Int64($value as! Int32)'; - } - } else if (type.isNullable) { - return 'nilOrValue($value)'; - } else { - return '$value as! ${_swiftTypeForDartType(type)}'; - } - } - final String fieldType = _swiftTypeForDartType(type); if (type.isNullable) { - if (listEncodedClassNames != null && - listEncodedClassNames.contains(type.baseName)) { + if (type.isClass) { indent.writeln('var $variableName: $fieldType? = nil'); indent .write('if let ${variableName}List: [Any?] = nilOrValue($value) '); @@ -704,11 +703,10 @@ import FlutterMacOS indent.writeln( '$variableName = $fieldType.fromList(${variableName}List)'); }); - } else if (listEncodedEnumNames != null && - listEncodedEnumNames.contains(type.baseName)) { + } else if (type.isEnum) { indent.writeln('var $variableName: $fieldType? = nil'); indent.writeln( - 'let ${variableName}EnumVal: Int? = ${castForceUnwrap(value, const TypeDeclaration(baseName: 'Int', isNullable: true), root)}'); + 'let ${variableName}EnumVal: Int? = ${_castForceUnwrap(value, const TypeDeclaration(baseName: 'Int', isNullable: true))}'); indent .write('if let ${variableName}RawValue = ${variableName}EnumVal '); indent.addScoped('{', '}', () { @@ -716,17 +714,26 @@ import FlutterMacOS '$variableName = $fieldType(rawValue: ${variableName}RawValue)!'); }); } else { - indent.writeln( - 'let $variableName: $fieldType? = ${castForceUnwrap(value, type, root)}'); + _writeGenericCasting( + indent: indent, + value: value, + variableName: variableName, + fieldType: fieldType, + type: type, + ); } } else { - if (listEncodedClassNames != null && - listEncodedClassNames.contains(type.baseName)) { + if (type.isClass) { indent.writeln( 'let $variableName = $fieldType.fromList($value as! [Any?])!'); } else { - indent.writeln( - 'let $variableName = ${castForceUnwrap(value, type, root)}'); + _writeGenericCasting( + indent: indent, + value: value, + variableName: variableName, + fieldType: fieldType, + type: type, + ); } } } @@ -812,11 +819,6 @@ private func nilOrValue(_ value: Any?) -> T? { } } -HostDatatype _getHostDatatype(Root root, NamedType field) { - return getFieldHostDatatype(field, root.classes, root.enums, - (TypeDeclaration x) => _swiftTypeForBuiltinDartType(x)); -} - /// Calculates the name of the codec that will be generated for [api]. String _getCodecName(Api api) => '${api.name}Codec'; @@ -899,17 +901,17 @@ String _getMethodSignature(Method func) { ? 'Void' : _nullsafeSwiftTypeForDartType(func.returnType); - if (func.arguments.isEmpty) { + if (func.parameters.isEmpty) { return 'func ${func.name}(completion: @escaping (Result<$returnType, FlutterError>) -> Void)'; } else { - final Iterable argTypes = func.arguments + final Iterable argTypes = func.parameters .map((NamedType e) => _nullsafeSwiftTypeForDartType(e.type)); final Iterable argLabels = indexMap(components.arguments, (int index, _SwiftFunctionArgument argument) { return argument.label ?? _getArgumentName(index, argument.namedType); }); final Iterable argNames = - indexMap(func.arguments, _getSafeArgumentName); + indexMap(func.parameters, _getSafeArgumentName); final String argsSignature = map3(argTypes, argLabels, argNames, (String type, String label, String name) => '$label $name: $type') .join(', '); @@ -957,7 +959,7 @@ class _SwiftFunctionComponents { return _SwiftFunctionComponents._( name: method.name, returnType: method.returnType, - arguments: method.arguments + arguments: method.parameters .map((NamedType field) => _SwiftFunctionArgument( name: field.name, type: field.type, @@ -969,20 +971,20 @@ class _SwiftFunctionComponents { } final String argsExtractor = - repeat(r'(\w+):', method.arguments.length).join(); + repeat(r'(\w+):', method.parameters.length).join(); final RegExp signatureRegex = RegExp(r'(\w+) *\(' + argsExtractor + r'\)'); final RegExpMatch match = signatureRegex.firstMatch(method.swiftFunction)!; final Iterable labels = match .groups(List.generate( - method.arguments.length, (int index) => index + 2)) + method.parameters.length, (int index) => index + 2)) .whereType(); return _SwiftFunctionComponents._( name: match.group(1)!, returnType: method.returnType, arguments: map2( - method.arguments, + method.parameters, labels, (NamedType field, String label) => _SwiftFunctionArgument( name: field.name, diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index 2f5ef13732b..a0c6a3ccf29 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -171,6 +171,21 @@ abstract class HostIntegrationCoreApi { @SwiftFunction('echo(_:)') AnEnum echoEnum(AnEnum anEnum); + /// Returns the default string. + @ObjCSelector('echoNamedDefaultString:') + @SwiftFunction('echoNamedDefault(_:)') + String echoNamedDefaultString({String aString = 'default'}); + + /// Returns passed in double. + @ObjCSelector('echoOptionalDefaultDouble:') + @SwiftFunction('echoOptionalDefault(_:)') + double echoOptionalDefaultDouble([double aDouble = 3.14]); + + /// Returns passed in int. + @ObjCSelector('echoRequiredInt:') + @SwiftFunction('echoRequired(_:)') + int echoRequiredInt({required int anInt}); + // ========== Synchronous nullable method tests ========== /// Returns the passed object, to test serialization and deserialization. @@ -240,6 +255,16 @@ abstract class HostIntegrationCoreApi { @SwiftFunction('echoNullable(_:)') AnEnum? echoNullableEnum(AnEnum? anEnum); + /// Returns passed in int. + @ObjCSelector('echoOptionalNullableInt:') + @SwiftFunction('echoOptional(_:)') + int? echoOptionalNullableInt([int? aNullableInt]); + + /// Returns the passed in string. + @ObjCSelector('echoNamedNullableString:') + @SwiftFunction('echoNamed(_:)') + String? echoNamedNullableString({String? aNullableString}); + // ========== Asynchronous method tests ========== /// A no-op function taking no arguments and returning no value, to sanity diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java index 694bbcaff9c..21037c5e99c 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java @@ -111,6 +111,21 @@ public void throwErrorFromVoid() { return anEnum; } + @Override + public @NonNull String echoNamedDefaultString(@NonNull String aString) { + return aString; + } + + @Override + public @NonNull Double echoOptionalDefaultDouble(@NonNull Double aDouble) { + return aDouble; + } + + @Override + public @NonNull Long echoRequiredInt(@NonNull Long anInt) { + return anInt; + } + @Override public @Nullable String extractNestedNullableString(@NonNull AllClassesWrapper wrapper) { return wrapper.getAllNullableTypes().getANullableString(); @@ -182,6 +197,16 @@ public void throwErrorFromVoid() { return anEnum; } + @Override + public @Nullable Long echoOptionalNullableInt(@Nullable Long aNullableInt) { + return aNullableInt; + } + + @Override + public @Nullable String echoNamedNullableString(@Nullable String aNullableString) { + return aNullableString; + } + @Override public void noopAsync(@NonNull Result result) { result.success(null); diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java index e508232de4c..60586828274 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java @@ -1033,6 +1033,15 @@ public interface HostIntegrationCoreApi { /** Returns the passed enum to test serialization and deserialization. */ @NonNull AnEnum echoEnum(@NonNull AnEnum anEnum); + /** Returns the default string. */ + @NonNull + String echoNamedDefaultString(@NonNull String aString); + /** Returns passed in double. */ + @NonNull + Double echoOptionalDefaultDouble(@NonNull Double aDouble); + /** Returns passed in int. */ + @NonNull + Long echoRequiredInt(@NonNull Long anInt); /** Returns the passed object, to test serialization and deserialization. */ @Nullable AllNullableTypes echoAllNullableTypes(@Nullable AllNullableTypes everything); @@ -1079,6 +1088,12 @@ AllNullableTypes sendMultipleNullableTypes( @Nullable AnEnum echoNullableEnum(@Nullable AnEnum anEnum); + /** Returns passed in int. */ + @Nullable + Long echoOptionalNullableInt(@Nullable Long aNullableInt); + /** Returns the passed in string. */ + @Nullable + String echoNamedNullableString(@Nullable String aNullableString); /** * A no-op function taking no arguments and returning no value, to sanity test basic * asynchronous calling. @@ -1570,6 +1585,82 @@ static void setUp( channel.setMessageHandler(null); } } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNamedDefaultString", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + String aStringArg = (String) args.get(0); + try { + String output = api.echoNamedDefaultString(aStringArg); + wrapped.add(0, output); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoOptionalDefaultDouble", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + Double aDoubleArg = (Double) args.get(0); + try { + Double output = api.echoOptionalDefaultDouble(aDoubleArg); + wrapped.add(0, output); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoRequiredInt", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + Number anIntArg = (Number) args.get(0); + try { + Long output = + api.echoRequiredInt((anIntArg == null) ? null : anIntArg.longValue()); + wrapped.add(0, output); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -1903,6 +1994,58 @@ static void setUp( channel.setMessageHandler(null); } } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoOptionalNullableInt", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + Number aNullableIntArg = (Number) args.get(0); + try { + Long output = + api.echoOptionalNullableInt( + (aNullableIntArg == null) ? null : aNullableIntArg.longValue()); + wrapped.add(0, output); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNamedNullableString", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + String aNullableStringArg = (String) args.get(0); + try { + String output = api.echoNamedNullableString(aNullableStringArg); + wrapped.add(0, output); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } { BasicMessageChannel channel = new BasicMessageChannel<>( diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m index d24bd629ba3..d1e42a10cca 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m @@ -95,6 +95,21 @@ - (AnEnumBox *_Nullable)echoEnum:(AnEnum)anEnum error:(FlutterError *_Nullable * return [[AnEnumBox alloc] initWithValue:anEnum]; } +- (nullable NSString *)echoNamedDefaultString:(NSString *)aString + error:(FlutterError *_Nullable *_Nonnull)error { + return aString; +} + +- (nullable NSNumber *)echoOptionalDefaultDouble:(double)aDouble + error:(FlutterError *_Nullable *_Nonnull)error { + return @(aDouble); +} + +- (nullable NSNumber *)echoRequiredInt:(NSInteger)anInt + error:(FlutterError *_Nullable *_Nonnull)error { + return @(anInt); +} + - (nullable NSString *)extractNestedNullableStringFrom:(AllClassesWrapper *)wrapper error:(FlutterError *_Nullable *_Nonnull)error { return wrapper.allNullableTypes.aNullableString; @@ -167,6 +182,16 @@ - (AnEnumBox *_Nullable)echoNullableEnum:(nullable AnEnumBox *)AnEnumBoxed return AnEnumBoxed; } +- (nullable NSNumber *)echoOptionalNullableInt:(nullable NSNumber *)aNullableInt + error:(FlutterError *_Nullable *_Nonnull)error { + return aNullableInt; +} + +- (nullable NSString *)echoNamedNullableString:(nullable NSString *)aNullableString + error:(FlutterError *_Nullable *_Nonnull)error { + return aNullableString; +} + - (void)noopAsyncWithCompletion:(void (^)(FlutterError *_Nullable))completion { completion(nil); } diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h index 36ead686fc2..782c3794a13 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h @@ -186,6 +186,21 @@ NSObject *HostIntegrationCoreApiGetCodec(void); /// /// @return `nil` only when `error != nil`. - (AnEnumBox *_Nullable)echoEnum:(AnEnum)anEnum error:(FlutterError *_Nullable *_Nonnull)error; +/// Returns the default string. +/// +/// @return `nil` only when `error != nil`. +- (nullable NSString *)echoNamedDefaultString:(NSString *)aString + error:(FlutterError *_Nullable *_Nonnull)error; +/// Returns passed in double. +/// +/// @return `nil` only when `error != nil`. +- (nullable NSNumber *)echoOptionalDefaultDouble:(double)aDouble + error:(FlutterError *_Nullable *_Nonnull)error; +/// Returns passed in int. +/// +/// @return `nil` only when `error != nil`. +- (nullable NSNumber *)echoRequiredInt:(NSInteger)anInt + error:(FlutterError *_Nullable *_Nonnull)error; /// Returns the passed object, to test serialization and deserialization. - (nullable AllNullableTypes *)echoAllNullableTypes:(nullable AllNullableTypes *)everything error:(FlutterError *_Nullable *_Nonnull)error; @@ -236,6 +251,12 @@ NSObject *HostIntegrationCoreApiGetCodec(void); error:(FlutterError *_Nullable *_Nonnull)error; - (AnEnumBox *_Nullable)echoNullableEnum:(nullable AnEnumBox *)anEnumBoxed error:(FlutterError *_Nullable *_Nonnull)error; +/// Returns passed in int. +- (nullable NSNumber *)echoOptionalNullableInt:(nullable NSNumber *)aNullableInt + error:(FlutterError *_Nullable *_Nonnull)error; +/// Returns the passed in string. +- (nullable NSString *)echoNamedNullableString:(nullable NSString *)aNullableString + error:(FlutterError *_Nullable *_Nonnull)error; /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. - (void)noopAsyncWithCompletion:(void (^)(FlutterError *_Nullable))completion; diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m index 99bf5a54d13..0cc5b059c04 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m @@ -672,6 +672,75 @@ void SetUpHostIntegrationCoreApi(id binaryMessenger, [channel setMessageHandler:nil]; } } + /// Returns the default string. + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi." + @"echoNamedDefaultString" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(echoNamedDefaultString:error:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(echoNamedDefaultString:error:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSString *arg_aString = GetNullableObjectAtIndex(args, 0); + FlutterError *error; + NSString *output = [api echoNamedDefaultString:arg_aString error:&error]; + callback(wrapResult(output, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } + /// Returns passed in double. + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi." + @"echoOptionalDefaultDouble" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(echoOptionalDefaultDouble:error:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(echoOptionalDefaultDouble:error:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + double arg_aDouble = [GetNullableObjectAtIndex(args, 0) doubleValue]; + FlutterError *error; + NSNumber *output = [api echoOptionalDefaultDouble:arg_aDouble error:&error]; + callback(wrapResult(output, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } + /// Returns passed in int. + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName: + @"dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoRequiredInt" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert( + [api respondsToSelector:@selector(echoRequiredInt:error:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoRequiredInt:error:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSInteger arg_anInt = [GetNullableObjectAtIndex(args, 0) integerValue]; + FlutterError *error; + NSNumber *output = [api echoRequiredInt:arg_anInt error:&error]; + callback(wrapResult(output, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } /// Returns the passed object, to test serialization and deserialization. { FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] @@ -985,6 +1054,52 @@ void SetUpHostIntegrationCoreApi(id binaryMessenger, [channel setMessageHandler:nil]; } } + /// Returns passed in int. + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi." + @"echoOptionalNullableInt" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(echoOptionalNullableInt:error:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(echoOptionalNullableInt:error:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSNumber *arg_aNullableInt = GetNullableObjectAtIndex(args, 0); + FlutterError *error; + NSNumber *output = [api echoOptionalNullableInt:arg_aNullableInt error:&error]; + callback(wrapResult(output, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } + /// Returns the passed in string. + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi." + @"echoNamedNullableString" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(echoNamedNullableString:error:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(echoNamedNullableString:error:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSString *arg_aNullableString = GetNullableObjectAtIndex(args, 0); + FlutterError *error; + NSString *output = [api echoNamedNullableString:arg_aNullableString error:&error]; + callback(wrapResult(output, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. { diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/AlternateLanguageTestPlugin.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/AlternateLanguageTestPlugin.m index 6c37758ccae..e9d679f4215 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/AlternateLanguageTestPlugin.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/AlternateLanguageTestPlugin.m @@ -94,6 +94,20 @@ - (nullable AllClassesWrapper *)echoClassWrapper:(AllClassesWrapper *)wrapper - (AnEnumBox *_Nullable)echoEnum:(AnEnum)anEnum error:(FlutterError *_Nullable *_Nonnull)error { return [[AnEnumBox alloc] initWithValue:anEnum]; } +- (nullable NSString *)echoNamedDefaultString:(NSString *)aString + error:(FlutterError *_Nullable *_Nonnull)error { + return aString; +} + +- (nullable NSNumber *)echoOptionalDefaultDouble:(double)aDouble + error:(FlutterError *_Nullable *_Nonnull)error { + return @(aDouble); +} + +- (nullable NSNumber *)echoRequiredInt:(NSInteger)anInt + error:(FlutterError *_Nullable *_Nonnull)error { + return @(anInt); +} - (nullable NSString *)extractNestedNullableStringFrom:(AllClassesWrapper *)wrapper error:(FlutterError *_Nullable *_Nonnull)error { @@ -167,6 +181,16 @@ - (AnEnumBox *_Nullable)echoNullableEnum:(nullable AnEnumBox *)AnEnumBoxed return AnEnumBoxed; } +- (nullable NSNumber *)echoOptionalNullableInt:(nullable NSNumber *)aNullableInt + error:(FlutterError *_Nullable *_Nonnull)error { + return aNullableInt; +} + +- (nullable NSString *)echoNamedNullableString:(nullable NSString *)aNullableString + error:(FlutterError *_Nullable *_Nonnull)error { + return aNullableString; +} + - (void)noopAsyncWithCompletion:(void (^)(FlutterError *_Nullable))completion { completion(nil); } diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h index 36ead686fc2..782c3794a13 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h @@ -186,6 +186,21 @@ NSObject *HostIntegrationCoreApiGetCodec(void); /// /// @return `nil` only when `error != nil`. - (AnEnumBox *_Nullable)echoEnum:(AnEnum)anEnum error:(FlutterError *_Nullable *_Nonnull)error; +/// Returns the default string. +/// +/// @return `nil` only when `error != nil`. +- (nullable NSString *)echoNamedDefaultString:(NSString *)aString + error:(FlutterError *_Nullable *_Nonnull)error; +/// Returns passed in double. +/// +/// @return `nil` only when `error != nil`. +- (nullable NSNumber *)echoOptionalDefaultDouble:(double)aDouble + error:(FlutterError *_Nullable *_Nonnull)error; +/// Returns passed in int. +/// +/// @return `nil` only when `error != nil`. +- (nullable NSNumber *)echoRequiredInt:(NSInteger)anInt + error:(FlutterError *_Nullable *_Nonnull)error; /// Returns the passed object, to test serialization and deserialization. - (nullable AllNullableTypes *)echoAllNullableTypes:(nullable AllNullableTypes *)everything error:(FlutterError *_Nullable *_Nonnull)error; @@ -236,6 +251,12 @@ NSObject *HostIntegrationCoreApiGetCodec(void); error:(FlutterError *_Nullable *_Nonnull)error; - (AnEnumBox *_Nullable)echoNullableEnum:(nullable AnEnumBox *)anEnumBoxed error:(FlutterError *_Nullable *_Nonnull)error; +/// Returns passed in int. +- (nullable NSNumber *)echoOptionalNullableInt:(nullable NSNumber *)aNullableInt + error:(FlutterError *_Nullable *_Nonnull)error; +/// Returns the passed in string. +- (nullable NSString *)echoNamedNullableString:(nullable NSString *)aNullableString + error:(FlutterError *_Nullable *_Nonnull)error; /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. - (void)noopAsyncWithCompletion:(void (^)(FlutterError *_Nullable))completion; diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m index 99bf5a54d13..0cc5b059c04 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m @@ -672,6 +672,75 @@ void SetUpHostIntegrationCoreApi(id binaryMessenger, [channel setMessageHandler:nil]; } } + /// Returns the default string. + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi." + @"echoNamedDefaultString" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(echoNamedDefaultString:error:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(echoNamedDefaultString:error:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSString *arg_aString = GetNullableObjectAtIndex(args, 0); + FlutterError *error; + NSString *output = [api echoNamedDefaultString:arg_aString error:&error]; + callback(wrapResult(output, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } + /// Returns passed in double. + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi." + @"echoOptionalDefaultDouble" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(echoOptionalDefaultDouble:error:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(echoOptionalDefaultDouble:error:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + double arg_aDouble = [GetNullableObjectAtIndex(args, 0) doubleValue]; + FlutterError *error; + NSNumber *output = [api echoOptionalDefaultDouble:arg_aDouble error:&error]; + callback(wrapResult(output, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } + /// Returns passed in int. + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName: + @"dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoRequiredInt" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert( + [api respondsToSelector:@selector(echoRequiredInt:error:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoRequiredInt:error:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSInteger arg_anInt = [GetNullableObjectAtIndex(args, 0) integerValue]; + FlutterError *error; + NSNumber *output = [api echoRequiredInt:arg_anInt error:&error]; + callback(wrapResult(output, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } /// Returns the passed object, to test serialization and deserialization. { FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] @@ -985,6 +1054,52 @@ void SetUpHostIntegrationCoreApi(id binaryMessenger, [channel setMessageHandler:nil]; } } + /// Returns passed in int. + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi." + @"echoOptionalNullableInt" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(echoOptionalNullableInt:error:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(echoOptionalNullableInt:error:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSNumber *arg_aNullableInt = GetNullableObjectAtIndex(args, 0); + FlutterError *error; + NSNumber *output = [api echoOptionalNullableInt:arg_aNullableInt error:&error]; + callback(wrapResult(output, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } + /// Returns the passed in string. + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi." + @"echoNamedNullableString" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(echoNamedNullableString:error:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(echoNamedNullableString:error:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSString *arg_aNullableString = GetNullableObjectAtIndex(args, 0); + FlutterError *error; + NSString *output = [api echoNamedNullableString:arg_aNullableString error:&error]; + callback(wrapResult(output, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. { diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart index 9daa7c9317f..6b60a87e146 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart @@ -139,7 +139,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { 'e': null }, anEnum: AnEnum.two, - anObject: 0, + anObject: 1, ); final AllNullableTypes genericAllNullableTypes = AllNullableTypes( @@ -337,7 +337,6 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { testWidgets('Int serialize and deserialize correctly', (WidgetTester _) async { final HostIntegrationCoreApi api = HostIntegrationCoreApi(); - const int sentInt = _regularInt; final int receivedInt = await api.echoInt(sentInt); expect(receivedInt, sentInt); @@ -374,7 +373,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { testWidgets('strings serialize and deserialize correctly', (WidgetTester _) async { final HostIntegrationCoreApi api = HostIntegrationCoreApi(); - const String sentString = "I'm a computer"; + const String sentString = 'default'; final String receivedString = await api.echoString(sentString); expect(receivedString, sentString); }); @@ -444,6 +443,49 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { expect(receivedEnum, sentEnum); }); + testWidgets('required named parameter', (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + // This number corresponds with the default value of this method. + const int sentInt = _regularInt; + final int receivedInt = await api.echoRequiredInt(anInt: sentInt); + expect(receivedInt, sentInt); + }); + + testWidgets('optional default parameter no arg', (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + // This number corresponds with the default value of this method. + const double sentDouble = 3.14; + final double receivedDouble = await api.echoOptionalDefaultDouble(); + expect(receivedDouble, sentDouble); + }); + + testWidgets('optional default parameter with arg', (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + const double sentDouble = 3.15; + final double receivedDouble = + await api.echoOptionalDefaultDouble(sentDouble); + expect(receivedDouble, sentDouble); + }); + + testWidgets('named default parameter no arg', (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + // This string corresponds with the default value of this method. + const String sentString = 'default'; + final String receivedString = await api.echoNamedDefaultString(); + expect(receivedString, sentString); + }); + + testWidgets('named default parameter with arg', (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + // This string corresponds with the default value of this method. + const String sentString = 'notDefault'; + final String receivedString = + await api.echoNamedDefaultString(aString: sentString); + expect(receivedString, sentString); + }); + testWidgets('Nullable Int serialize and deserialize correctly', (WidgetTester _) async { final HostIntegrationCoreApi api = HostIntegrationCoreApi(); @@ -630,6 +672,36 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AnEnum? echoEnum = await api.echoNullableEnum(sentEnum); expect(echoEnum, sentEnum); }); + + testWidgets('optional nullable parameter', (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + const int sentInt = _regularInt; + final int? receivedInt = await api.echoOptionalNullableInt(sentInt); + expect(receivedInt, sentInt); + }); + + testWidgets('Null optional nullable parameter', (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + final int? receivedNullInt = await api.echoOptionalNullableInt(); + expect(receivedNullInt, null); + }); + + testWidgets('named nullable parameter', (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + const String sentString = "I'm a computer"; + final String? receivedString = + await api.echoNamedNullableString(aNullableString: sentString); + expect(receivedString, sentString); + }); + + testWidgets('Null named nullable parameter', (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + final String? receivedNullString = await api.echoNamedNullableString(); + expect(receivedNullString, null); + }); }); group('Host async API tests', () { 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 e48af86c9af..7222e263b32 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 +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -24,36 +24,38 @@ class BackgroundApi2Host { /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. BackgroundApi2Host({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec codec = StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = + StandardMessageCodec(); - Future add(int arg_x, int arg_y) async { - const String channelName = + Future add(int x, int y) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.BackgroundApi2Host.add'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_x, arg_y]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([x, y]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as int?)!; + return (__pigeon_replyList[0] as int?)!; } } } 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 64b721bc2ee..6815f461c94 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 +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -39,19 +39,19 @@ enum AnEnum { /// A class containing all supported types. class AllTypes { AllTypes({ - required this.aBool, - required this.anInt, - required this.anInt64, - required this.aDouble, + this.aBool = false, + this.anInt = 0, + this.anInt64 = 0, + this.aDouble = 0, required this.aByteArray, required this.a4ByteArray, required this.a8ByteArray, required this.aFloatArray, - required this.aList, - required this.aMap, - required this.anEnum, - required this.aString, - required this.anObject, + this.aList = const [], + this.aMap = const {}, + this.anEnum = AnEnum.one, + this.aString = '', + this.anObject = 0, }); bool aBool; @@ -318,29 +318,32 @@ class HostIntegrationCoreApi { /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. HostIntegrationCoreApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec codec = _HostIntegrationCoreApiCodec(); + static const MessageCodec pigeonChannelCodec = + _HostIntegrationCoreApiCodec(); /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. Future noop() async { - const String channelName = + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.noop'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { return; @@ -348,74 +351,79 @@ class HostIntegrationCoreApi { } /// Returns the passed object, to test serialization and deserialization. - Future echoAllTypes(AllTypes arg_everything) async { - const String channelName = + Future echoAllTypes(AllTypes everything) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAllTypes'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_everything]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([everything]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as AllTypes?)!; + return (__pigeon_replyList[0] as AllTypes?)!; } } /// Returns an error, to test error handling. Future throwError() async { - const String channelName = + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.throwError'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return replyList[0]; + return __pigeon_replyList[0]; } } /// Returns an error from a void function, to test error handling. Future throwErrorFromVoid() async { - const String channelName = + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.throwErrorFromVoid'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { return; @@ -424,669 +432,835 @@ class HostIntegrationCoreApi { /// Returns a Flutter error, to test error handling. Future throwFlutterError() async { - const String channelName = + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.throwFlutterError'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return replyList[0]; + return __pigeon_replyList[0]; } } /// Returns passed in int. - Future echoInt(int arg_anInt) async { - const String channelName = + Future echoInt(int anInt) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoInt'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_anInt]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([anInt]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as int?)!; + return (__pigeon_replyList[0] as int?)!; } } /// Returns passed in double. - Future echoDouble(double arg_aDouble) async { - const String channelName = + Future echoDouble(double aDouble) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoDouble'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aDouble]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aDouble]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as double?)!; + return (__pigeon_replyList[0] as double?)!; } } /// Returns the passed in boolean. - Future echoBool(bool arg_aBool) async { - const String channelName = + Future echoBool(bool aBool) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoBool'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aBool]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aBool]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as bool?)!; + return (__pigeon_replyList[0] as bool?)!; } } /// Returns the passed in string. - Future echoString(String arg_aString) async { - const String channelName = + Future echoString(String aString) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoString'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aString]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + 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: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as String?)!; + return (__pigeon_replyList[0] as String?)!; } } /// Returns the passed in Uint8List. - Future echoUint8List(Uint8List arg_aUint8List) async { - const String channelName = + Future echoUint8List(Uint8List aUint8List) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoUint8List'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aUint8List]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aUint8List]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as Uint8List?)!; + return (__pigeon_replyList[0] as Uint8List?)!; } } /// Returns the passed in generic Object. - Future echoObject(Object arg_anObject) async { - const String channelName = + Future echoObject(Object anObject) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoObject'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_anObject]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([anObject]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return replyList[0]!; + return __pigeon_replyList[0]!; } } /// Returns the passed list, to test serialization and deserialization. - Future> echoList(List arg_aList) async { - const String channelName = + Future> echoList(List aList) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoList'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aList]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aList]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as List?)!.cast(); + return (__pigeon_replyList[0] as List?)!.cast(); } } /// Returns the passed map, to test serialization and deserialization. - Future> echoMap(Map arg_aMap) async { - const String channelName = + Future> echoMap(Map aMap) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoMap'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aMap]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aMap]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as Map?)!.cast(); + return (__pigeon_replyList[0] as Map?)! + .cast(); } } /// Returns the passed map to test nested class serialization and deserialization. - Future echoClassWrapper( - AllClassesWrapper arg_wrapper) async { - const String channelName = + Future echoClassWrapper(AllClassesWrapper wrapper) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoClassWrapper'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_wrapper]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([wrapper]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as AllClassesWrapper?)!; + return (__pigeon_replyList[0] as AllClassesWrapper?)!; } } /// Returns the passed enum to test serialization and deserialization. - Future echoEnum(AnEnum arg_anEnum) async { - const String channelName = + Future echoEnum(AnEnum anEnum) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoEnum'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_anEnum.index]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([anEnum.index]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } 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[replyList[0]! as int]; + return AnEnum.values[__pigeon_replyList[0]! as int]; + } + } + + /// Returns the default string. + Future echoNamedDefaultString({String aString = 'default'}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNamedDefaultString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([aString]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as String?)!; + } + } + + /// Returns passed in double. + Future echoOptionalDefaultDouble([double aDouble = 3.14]) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoOptionalDefaultDouble'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([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 passed in int. + Future echoRequiredInt({required int anInt}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoRequiredInt'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([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 the passed object, to test serialization and deserialization. Future echoAllNullableTypes( - AllNullableTypes? arg_everything) async { - const String channelName = + AllNullableTypes? everything) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAllNullableTypes'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_everything]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([everything]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as AllNullableTypes?); + return (__pigeon_replyList[0] as AllNullableTypes?); } } /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. - Future extractNestedNullableString( - AllClassesWrapper arg_wrapper) async { - const String channelName = + Future extractNestedNullableString(AllClassesWrapper wrapper) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.extractNestedNullableString'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_wrapper]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([wrapper]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as String?); + return (__pigeon_replyList[0] as String?); } } /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. Future createNestedNullableString( - String? arg_nullableString) async { - const String channelName = + String? nullableString) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.createNestedNullableString'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_nullableString]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = await __pigeon_channel + .send([nullableString]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as AllClassesWrapper?)!; + return (__pigeon_replyList[0] as AllClassesWrapper?)!; } } /// Returns passed in arguments of multiple types. - Future sendMultipleNullableTypes(bool? arg_aNullableBool, - int? arg_aNullableInt, String? arg_aNullableString) async { - const String channelName = + Future sendMultipleNullableTypes( + bool? aNullableBool, int? aNullableInt, String? aNullableString) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.sendMultipleNullableTypes'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, - ); - final List? replyList = await channel.send( - [arg_aNullableBool, arg_aNullableInt, arg_aNullableString]) + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([aNullableBool, aNullableInt, aNullableString]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as AllNullableTypes?)!; + return (__pigeon_replyList[0] as AllNullableTypes?)!; } } /// Returns passed in int. - Future echoNullableInt(int? arg_aNullableInt) async { - const String channelName = + Future echoNullableInt(int? aNullableInt) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableInt'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aNullableInt]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aNullableInt]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as int?); + return (__pigeon_replyList[0] as int?); } } /// Returns passed in double. - Future echoNullableDouble(double? arg_aNullableDouble) async { - const String channelName = + Future echoNullableDouble(double? aNullableDouble) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableDouble'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aNullableDouble]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = await __pigeon_channel + .send([aNullableDouble]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as double?); + return (__pigeon_replyList[0] as double?); } } /// Returns the passed in boolean. - Future echoNullableBool(bool? arg_aNullableBool) async { - const String channelName = + Future echoNullableBool(bool? aNullableBool) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableBool'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aNullableBool]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aNullableBool]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as bool?); + return (__pigeon_replyList[0] as bool?); } } /// Returns the passed in string. - Future echoNullableString(String? arg_aNullableString) async { - const String channelName = + Future echoNullableString(String? aNullableString) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableString'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aNullableString]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = await __pigeon_channel + .send([aNullableString]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as String?); + return (__pigeon_replyList[0] as String?); } } /// Returns the passed in Uint8List. Future echoNullableUint8List( - Uint8List? arg_aNullableUint8List) async { - const String channelName = + Uint8List? aNullableUint8List) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableUint8List'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aNullableUint8List]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = await __pigeon_channel + .send([aNullableUint8List]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as Uint8List?); + return (__pigeon_replyList[0] as Uint8List?); } } /// Returns the passed in generic Object. - Future echoNullableObject(Object? arg_aNullableObject) async { - const String channelName = + Future echoNullableObject(Object? aNullableObject) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableObject'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aNullableObject]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = await __pigeon_channel + .send([aNullableObject]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return replyList[0]; + return __pigeon_replyList[0]; } } /// Returns the passed list, to test serialization and deserialization. - Future?> echoNullableList( - List? arg_aNullableList) async { - const String channelName = + Future?> echoNullableList(List? aNullableList) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableList'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aNullableList]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aNullableList]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as List?)?.cast(); + return (__pigeon_replyList[0] as List?)?.cast(); } } /// Returns the passed map, to test serialization and deserialization. Future?> echoNullableMap( - Map? arg_aNullableMap) async { - const String channelName = + Map? aNullableMap) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableMap'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aNullableMap]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aNullableMap]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as Map?)?.cast(); + return (__pigeon_replyList[0] as Map?) + ?.cast(); } } - Future echoNullableEnum(AnEnum? arg_anEnum) async { - const String channelName = + Future echoNullableEnum(AnEnum? anEnum) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableEnum'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_anEnum?.index]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([anEnum?.index]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as int?) == null + return (__pigeon_replyList[0] as int?) == null ? null - : AnEnum.values[replyList[0]! as int]; + : AnEnum.values[__pigeon_replyList[0]! as int]; + } + } + + /// Returns passed in int. + Future echoOptionalNullableInt([int? aNullableInt]) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoOptionalNullableInt'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([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 the passed in string. + Future echoNamedNullableString({String? aNullableString}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNamedNullableString'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([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?); } } /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. Future noopAsync() async { - const String channelName = + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.noopAsync'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { return; @@ -1094,307 +1268,320 @@ class HostIntegrationCoreApi { } /// Returns passed in int asynchronously. - Future echoAsyncInt(int arg_anInt) async { - const String channelName = + Future echoAsyncInt(int anInt) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncInt'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_anInt]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([anInt]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as int?)!; + return (__pigeon_replyList[0] as int?)!; } } /// Returns passed in double asynchronously. - Future echoAsyncDouble(double arg_aDouble) async { - const String channelName = + Future echoAsyncDouble(double aDouble) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncDouble'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aDouble]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aDouble]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as double?)!; + return (__pigeon_replyList[0] as double?)!; } } /// Returns the passed in boolean asynchronously. - Future echoAsyncBool(bool arg_aBool) async { - const String channelName = + Future echoAsyncBool(bool aBool) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncBool'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aBool]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aBool]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as bool?)!; + return (__pigeon_replyList[0] as bool?)!; } } /// Returns the passed string asynchronously. - Future echoAsyncString(String arg_aString) async { - const String channelName = + Future echoAsyncString(String aString) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncString'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aString]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + 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: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as String?)!; + return (__pigeon_replyList[0] as String?)!; } } /// Returns the passed in Uint8List asynchronously. - Future echoAsyncUint8List(Uint8List arg_aUint8List) async { - const String channelName = + Future echoAsyncUint8List(Uint8List aUint8List) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncUint8List'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aUint8List]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aUint8List]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as Uint8List?)!; + return (__pigeon_replyList[0] as Uint8List?)!; } } /// Returns the passed in generic Object asynchronously. - Future echoAsyncObject(Object arg_anObject) async { - const String channelName = + Future echoAsyncObject(Object anObject) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncObject'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_anObject]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([anObject]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return replyList[0]!; + return __pigeon_replyList[0]!; } } /// Returns the passed list, to test asynchronous serialization and deserialization. - Future> echoAsyncList(List arg_aList) async { - const String channelName = + Future> echoAsyncList(List aList) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncList'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aList]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aList]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as List?)!.cast(); + return (__pigeon_replyList[0] as List?)!.cast(); } } /// Returns the passed map, to test asynchronous serialization and deserialization. - Future> echoAsyncMap( - Map arg_aMap) async { - const String channelName = + Future> echoAsyncMap(Map aMap) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncMap'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aMap]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aMap]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as Map?)!.cast(); + return (__pigeon_replyList[0] as Map?)! + .cast(); } } /// Returns the passed enum, to test asynchronous serialization and deserialization. - Future echoAsyncEnum(AnEnum arg_anEnum) async { - const String channelName = + Future echoAsyncEnum(AnEnum anEnum) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncEnum'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_anEnum.index]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([anEnum.index]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } 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[replyList[0]! as int]; + return AnEnum.values[__pigeon_replyList[0]! as int]; } } /// Responds with an error from an async function returning a value. Future throwAsyncError() async { - const String channelName = + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.throwAsyncError'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return replyList[0]; + return __pigeon_replyList[0]; } } /// Responds with an error from an async void function. Future throwAsyncErrorFromVoid() async { - const String channelName = + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.throwAsyncErrorFromVoid'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { return; @@ -1403,317 +1590,332 @@ class HostIntegrationCoreApi { /// Responds with a Flutter error from an async function returning a value. Future throwAsyncFlutterError() async { - const String channelName = + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.throwAsyncFlutterError'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return replyList[0]; + return __pigeon_replyList[0]; } } /// Returns the passed object, to test async serialization and deserialization. - Future echoAsyncAllTypes(AllTypes arg_everything) async { - const String channelName = + Future echoAsyncAllTypes(AllTypes everything) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncAllTypes'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_everything]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([everything]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as AllTypes?)!; + return (__pigeon_replyList[0] as AllTypes?)!; } } /// Returns the passed object, to test serialization and deserialization. Future echoAsyncNullableAllNullableTypes( - AllNullableTypes? arg_everything) async { - const String channelName = + AllNullableTypes? everything) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableAllNullableTypes'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_everything]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([everything]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as AllNullableTypes?); + return (__pigeon_replyList[0] as AllNullableTypes?); } } /// Returns passed in int asynchronously. - Future echoAsyncNullableInt(int? arg_anInt) async { - const String channelName = + Future echoAsyncNullableInt(int? anInt) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableInt'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_anInt]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([anInt]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as int?); + return (__pigeon_replyList[0] as int?); } } /// Returns passed in double asynchronously. - Future echoAsyncNullableDouble(double? arg_aDouble) async { - const String channelName = + Future echoAsyncNullableDouble(double? aDouble) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableDouble'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aDouble]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aDouble]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as double?); + return (__pigeon_replyList[0] as double?); } } /// Returns the passed in boolean asynchronously. - Future echoAsyncNullableBool(bool? arg_aBool) async { - const String channelName = + Future echoAsyncNullableBool(bool? aBool) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableBool'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aBool]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aBool]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as bool?); + return (__pigeon_replyList[0] as bool?); } } /// Returns the passed string asynchronously. - Future echoAsyncNullableString(String? arg_aString) async { - const String channelName = + Future echoAsyncNullableString(String? aString) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableString'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aString]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + 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: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as String?); + return (__pigeon_replyList[0] as String?); } } /// Returns the passed in Uint8List asynchronously. - Future echoAsyncNullableUint8List( - Uint8List? arg_aUint8List) async { - const String channelName = + Future echoAsyncNullableUint8List(Uint8List? aUint8List) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableUint8List'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aUint8List]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aUint8List]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as Uint8List?); + return (__pigeon_replyList[0] as Uint8List?); } } /// Returns the passed in generic Object asynchronously. - Future echoAsyncNullableObject(Object? arg_anObject) async { - const String channelName = + Future echoAsyncNullableObject(Object? anObject) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableObject'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_anObject]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([anObject]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return replyList[0]; + return __pigeon_replyList[0]; } } /// Returns the passed list, to test asynchronous serialization and deserialization. - Future?> echoAsyncNullableList(List? arg_aList) async { - const String channelName = + Future?> echoAsyncNullableList(List? aList) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableList'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aList]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aList]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as List?)?.cast(); + return (__pigeon_replyList[0] as List?)?.cast(); } } /// Returns the passed map, to test asynchronous serialization and deserialization. Future?> echoAsyncNullableMap( - Map? arg_aMap) async { - const String channelName = + Map? aMap) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableMap'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aMap]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aMap]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as Map?)?.cast(); + return (__pigeon_replyList[0] as Map?) + ?.cast(); } } /// Returns the passed enum, to test asynchronous serialization and deserialization. - Future echoAsyncNullableEnum(AnEnum? arg_anEnum) async { - const String channelName = + Future echoAsyncNullableEnum(AnEnum? anEnum) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableEnum'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_anEnum?.index]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([anEnum?.index]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as int?) == null + return (__pigeon_replyList[0] as int?) == null ? null - : AnEnum.values[replyList[0]! as int]; + : AnEnum.values[__pigeon_replyList[0]! as int]; } } Future callFlutterNoop() async { - const String channelName = + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterNoop'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { return; @@ -1721,544 +1923,566 @@ class HostIntegrationCoreApi { } Future callFlutterThrowError() async { - const String channelName = + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterThrowError'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return replyList[0]; + return __pigeon_replyList[0]; } } Future callFlutterThrowErrorFromVoid() async { - const String channelName = + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterThrowErrorFromVoid'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { return; } } - Future callFlutterEchoAllTypes(AllTypes arg_everything) async { - const String channelName = + Future callFlutterEchoAllTypes(AllTypes everything) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoAllTypes'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_everything]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([everything]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as AllTypes?)!; + return (__pigeon_replyList[0] as AllTypes?)!; } } Future callFlutterEchoAllNullableTypes( - AllNullableTypes? arg_everything) async { - const String channelName = + AllNullableTypes? everything) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoAllNullableTypes'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_everything]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([everything]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as AllNullableTypes?); + return (__pigeon_replyList[0] as AllNullableTypes?); } } Future callFlutterSendMultipleNullableTypes( - bool? arg_aNullableBool, - int? arg_aNullableInt, - String? arg_aNullableString) async { - const String channelName = + bool? aNullableBool, int? aNullableInt, String? aNullableString) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterSendMultipleNullableTypes'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, - ); - final List? replyList = await channel.send( - [arg_aNullableBool, arg_aNullableInt, arg_aNullableString]) + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([aNullableBool, aNullableInt, aNullableString]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as AllNullableTypes?)!; + return (__pigeon_replyList[0] as AllNullableTypes?)!; } } - Future callFlutterEchoBool(bool arg_aBool) async { - const String channelName = + Future callFlutterEchoBool(bool aBool) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoBool'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aBool]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aBool]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as bool?)!; + return (__pigeon_replyList[0] as bool?)!; } } - Future callFlutterEchoInt(int arg_anInt) async { - const String channelName = + Future callFlutterEchoInt(int anInt) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoInt'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_anInt]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([anInt]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as int?)!; + return (__pigeon_replyList[0] as int?)!; } } - Future callFlutterEchoDouble(double arg_aDouble) async { - const String channelName = + Future callFlutterEchoDouble(double aDouble) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoDouble'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aDouble]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aDouble]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as double?)!; + return (__pigeon_replyList[0] as double?)!; } } - Future callFlutterEchoString(String arg_aString) async { - const String channelName = + Future callFlutterEchoString(String aString) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoString'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aString]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + 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: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as String?)!; + return (__pigeon_replyList[0] as String?)!; } } - Future callFlutterEchoUint8List(Uint8List arg_aList) async { - const String channelName = + Future callFlutterEchoUint8List(Uint8List aList) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoUint8List'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aList]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aList]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as Uint8List?)!; + return (__pigeon_replyList[0] as Uint8List?)!; } } - Future> callFlutterEchoList(List arg_aList) async { - const String channelName = + Future> callFlutterEchoList(List aList) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoList'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aList]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aList]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as List?)!.cast(); + return (__pigeon_replyList[0] as List?)!.cast(); } } Future> callFlutterEchoMap( - Map arg_aMap) async { - const String channelName = + Map aMap) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoMap'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aMap]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aMap]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as Map?)!.cast(); + return (__pigeon_replyList[0] as Map?)! + .cast(); } } - Future callFlutterEchoEnum(AnEnum arg_anEnum) async { - const String channelName = + Future callFlutterEchoEnum(AnEnum anEnum) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoEnum'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_anEnum.index]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([anEnum.index]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } 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[replyList[0]! as int]; + return AnEnum.values[__pigeon_replyList[0]! as int]; } } - Future callFlutterEchoNullableBool(bool? arg_aBool) async { - const String channelName = + Future callFlutterEchoNullableBool(bool? aBool) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableBool'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aBool]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aBool]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as bool?); + return (__pigeon_replyList[0] as bool?); } } - Future callFlutterEchoNullableInt(int? arg_anInt) async { - const String channelName = + Future callFlutterEchoNullableInt(int? anInt) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableInt'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_anInt]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([anInt]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as int?); + return (__pigeon_replyList[0] as int?); } } - Future callFlutterEchoNullableDouble(double? arg_aDouble) async { - const String channelName = + Future callFlutterEchoNullableDouble(double? aDouble) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableDouble'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aDouble]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aDouble]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as double?); + return (__pigeon_replyList[0] as double?); } } - Future callFlutterEchoNullableString(String? arg_aString) async { - const String channelName = + Future callFlutterEchoNullableString(String? aString) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableString'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aString]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + 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: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as String?); + return (__pigeon_replyList[0] as String?); } } - Future callFlutterEchoNullableUint8List( - Uint8List? arg_aList) async { - const String channelName = + Future callFlutterEchoNullableUint8List(Uint8List? aList) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableUint8List'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aList]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aList]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as Uint8List?); + return (__pigeon_replyList[0] as Uint8List?); } } Future?> callFlutterEchoNullableList( - List? arg_aList) async { - const String channelName = + List? aList) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableList'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aList]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aList]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as List?)?.cast(); + return (__pigeon_replyList[0] as List?)?.cast(); } } Future?> callFlutterEchoNullableMap( - Map? arg_aMap) async { - const String channelName = + Map? aMap) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableMap'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aMap]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([aMap]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as Map?)?.cast(); + return (__pigeon_replyList[0] as Map?) + ?.cast(); } } - Future callFlutterEchoNullableEnum(AnEnum? arg_anEnum) async { - const String channelName = + Future callFlutterEchoNullableEnum(AnEnum? anEnum) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableEnum'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_anEnum?.index]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([anEnum?.index]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as int?) == null + return (__pigeon_replyList[0] as int?) == null ? null - : AnEnum.values[replyList[0]! as int]; + : AnEnum.values[__pigeon_replyList[0]! as int]; } } } @@ -2304,7 +2528,8 @@ class _FlutterIntegrationCoreApiCodec extends StandardMessageCodec { /// The core interface that the Dart platform_test code implements for host /// integration tests to call into. abstract class FlutterIntegrationCoreApi { - static const MessageCodec codec = _FlutterIntegrationCoreApiCodec(); + static const MessageCodec pigeonChannelCodec = + _FlutterIntegrationCoreApiCodec(); /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. @@ -2386,14 +2611,15 @@ abstract class FlutterIntegrationCoreApi { static void setup(FlutterIntegrationCoreApi? api, {BinaryMessenger? binaryMessenger}) { { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noop', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { try { api.noop(); return wrapResponse(empty: true); @@ -2407,14 +2633,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwError', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { try { final Object? output = api.throwError(); return wrapResponse(result: output); @@ -2428,14 +2655,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwErrorFromVoid', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { try { api.throwErrorFromVoid(); return wrapResponse(empty: true); @@ -2449,14 +2677,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllTypes', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllTypes was null.'); final List args = (message as List?)!; @@ -2476,14 +2705,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllNullableTypes', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllNullableTypes was null.'); final List args = (message as List?)!; @@ -2503,14 +2733,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.sendMultipleNullableTypes', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.sendMultipleNullableTypes was null.'); final List args = (message as List?)!; @@ -2531,14 +2762,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoBool', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoBool was null.'); final List args = (message as List?)!; @@ -2558,14 +2790,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoInt', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoInt was null.'); final List args = (message as List?)!; @@ -2585,14 +2818,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoDouble', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoDouble was null.'); final List args = (message as List?)!; @@ -2612,14 +2846,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoString', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoString was null.'); final List args = (message as List?)!; @@ -2639,14 +2874,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List was null.'); final List args = (message as List?)!; @@ -2666,14 +2902,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList was null.'); final List args = (message as List?)!; @@ -2694,14 +2931,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoMap', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoMap was null.'); final List args = (message as List?)!; @@ -2722,14 +2960,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum was null.'); final List args = (message as List?)!; @@ -2750,14 +2989,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableBool', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableBool was null.'); final List args = (message as List?)!; @@ -2775,14 +3015,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableInt', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableInt was null.'); final List args = (message as List?)!; @@ -2800,14 +3041,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableDouble', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableDouble was null.'); final List args = (message as List?)!; @@ -2825,14 +3067,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableString', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableString was null.'); final List args = (message as List?)!; @@ -2850,14 +3093,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List was null.'); final List args = (message as List?)!; @@ -2875,14 +3119,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList was null.'); final List args = (message as List?)!; @@ -2901,14 +3146,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableMap', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableMap was null.'); final List args = (message as List?)!; @@ -2927,14 +3173,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum was null.'); final List args = (message as List?)!; @@ -2953,14 +3200,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noopAsync', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { try { await api.noopAsync(); return wrapResponse(empty: true); @@ -2974,14 +3222,15 @@ abstract class FlutterIntegrationCoreApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAsyncString', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAsyncString was null.'); final List args = (message as List?)!; @@ -3009,27 +3258,30 @@ class HostTrivialApi { /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. HostTrivialApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec codec = StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = + StandardMessageCodec(); Future noop() async { - const String channelName = + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostTrivialApi.noop'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { return; @@ -3043,55 +3295,59 @@ class HostSmallApi { /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. HostSmallApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec codec = StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = + StandardMessageCodec(); - Future echo(String arg_aString) async { - const String channelName = + Future echo(String aString) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.echo'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_aString]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + 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: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as String?)!; + return (__pigeon_replyList[0] as String?)!; } } Future voidVoid() async { - const String channelName = + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.voidVoid'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { return; @@ -3124,7 +3380,8 @@ class _FlutterSmallApiCodec extends StandardMessageCodec { /// A simple API called in some unit tests. abstract class FlutterSmallApi { - static const MessageCodec codec = _FlutterSmallApiCodec(); + static const MessageCodec pigeonChannelCodec = + _FlutterSmallApiCodec(); TestMessage echoWrappedList(TestMessage msg); @@ -3132,14 +3389,15 @@ abstract class FlutterSmallApi { static void setup(FlutterSmallApi? api, {BinaryMessenger? binaryMessenger}) { { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoWrappedList', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoWrappedList was null.'); final List args = (message as List?)!; @@ -3159,14 +3417,15 @@ abstract class FlutterSmallApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoString', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoString was null.'); final List args = (message as List?)!; 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 9f3c469c9b8..8354d159d33 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 +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -94,37 +94,38 @@ class EnumApi2Host { /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. EnumApi2Host({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec codec = _EnumApi2HostCodec(); + static const MessageCodec pigeonChannelCodec = _EnumApi2HostCodec(); /// This comment is to test method documentation comments. - Future echo(DataWithEnum arg_data) async { - const String channelName = + Future echo(DataWithEnum data) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.EnumApi2Host.echo'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_data]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([data]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as DataWithEnum?)!; + return (__pigeon_replyList[0] as DataWithEnum?)!; } } } @@ -154,21 +155,23 @@ class _EnumApi2FlutterCodec extends StandardMessageCodec { /// This comment is to test api documentation comments. abstract class EnumApi2Flutter { - static const MessageCodec codec = _EnumApi2FlutterCodec(); + static const MessageCodec pigeonChannelCodec = + _EnumApi2FlutterCodec(); /// This comment is to test method documentation comments. DataWithEnum echo(DataWithEnum data); static void setup(EnumApi2Flutter? api, {BinaryMessenger? binaryMessenger}) { { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.EnumApi2Flutter.echo', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.EnumApi2Flutter.echo was null.'); final List args = (message as List?)!; 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 8b149d7942e..73f100cf28b 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 +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -150,121 +150,125 @@ class Api { /// Constructor for [Api]. 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. - Api({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + Api({BinaryMessenger? binaryMessenger}) + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec codec = _ApiCodec(); + static const MessageCodec pigeonChannelCodec = _ApiCodec(); - Future search(FlutterSearchRequest arg_request) async { - const String channelName = + Future search(FlutterSearchRequest request) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.Api.search'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_request]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([request]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as FlutterSearchReply?)!; + return (__pigeon_replyList[0] as FlutterSearchReply?)!; } } - Future doSearches( - FlutterSearchRequests arg_request) async { - const String channelName = + Future doSearches(FlutterSearchRequests request) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.Api.doSearches'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_request]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([request]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as FlutterSearchReplies?)!; + return (__pigeon_replyList[0] as FlutterSearchReplies?)!; } } - Future echo(FlutterSearchRequests arg_requests) async { - const String channelName = + Future echo(FlutterSearchRequests requests) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.Api.echo'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_requests]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([requests]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as FlutterSearchRequests?)!; + return (__pigeon_replyList[0] as FlutterSearchRequests?)!; } } - Future anInt(int arg_value) async { - const String channelName = + Future anInt(int value) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.Api.anInt'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_value]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([value]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as int?)!; + return (__pigeon_replyList[0] as int?)!; } } } 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 fa0084706ff..cc7b8b53c36 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 +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -180,30 +180,32 @@ class MessageApi { /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. MessageApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec codec = _MessageApiCodec(); + static const MessageCodec pigeonChannelCodec = _MessageApiCodec(); /// This comment is to test documentation comments. /// /// This comment also tests multiple line comments. Future initialize() async { - const String channelName = + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.MessageApi.initialize'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { return; @@ -211,31 +213,32 @@ class MessageApi { } /// This comment is to test method documentation comments. - Future search(MessageSearchRequest arg_request) async { - const String channelName = + Future search(MessageSearchRequest request) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.MessageApi.search'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_request]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([request]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as MessageSearchReply?)!; + return (__pigeon_replyList[0] as MessageSearchReply?)!; } } } @@ -279,39 +282,41 @@ class MessageNestedApi { /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. MessageNestedApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec codec = _MessageNestedApiCodec(); + static const MessageCodec pigeonChannelCodec = + _MessageNestedApiCodec(); /// This comment is to test method documentation comments. /// /// This comment also tests multiple line comments. - Future search(MessageNested arg_nested) async { - const String channelName = + Future search(MessageNested nested) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.MessageNestedApi.search'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_nested]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([nested]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as MessageSearchReply?)!; + return (__pigeon_replyList[0] as MessageSearchReply?)!; } } } @@ -346,7 +351,8 @@ class _MessageFlutterSearchApiCodec extends StandardMessageCodec { /// This comment is to test api documentation comments. abstract class MessageFlutterSearchApi { - static const MessageCodec codec = _MessageFlutterSearchApiCodec(); + static const MessageCodec pigeonChannelCodec = + _MessageFlutterSearchApiCodec(); /// This comment is to test method documentation comments. MessageSearchReply search(MessageSearchRequest request); @@ -354,14 +360,15 @@ abstract class MessageFlutterSearchApi { static void setup(MessageFlutterSearchApi? api, {BinaryMessenger? binaryMessenger}) { { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.MessageFlutterSearchApi.search', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.MessageFlutterSearchApi.search was null.'); final List args = (message as List?)!; 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 2922865d9aa..bec054b4be4 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 +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -35,56 +35,60 @@ class MultipleArityHostApi { /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. MultipleArityHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec codec = StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = + StandardMessageCodec(); - Future subtract(int arg_x, int arg_y) async { - const String channelName = + Future subtract(int x, int y) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.MultipleArityHostApi.subtract'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_x, arg_y]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([x, y]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as int?)!; + return (__pigeon_replyList[0] as int?)!; } } } abstract class MultipleArityFlutterApi { - static const MessageCodec codec = StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = + StandardMessageCodec(); int subtract(int x, int y); static void setup(MultipleArityFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.MultipleArityFlutterApi.subtract', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.MultipleArityFlutterApi.subtract was null.'); final List args = (message as List?)!; 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 3a40af18716..7279e85c40e 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 +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -161,37 +161,39 @@ class NonNullFieldHostApi { /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. NonNullFieldHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec codec = _NonNullFieldHostApiCodec(); + static const MessageCodec pigeonChannelCodec = + _NonNullFieldHostApiCodec(); Future search( - NonNullFieldSearchRequest arg_nested) async { - const String channelName = + NonNullFieldSearchRequest nested) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.NonNullFieldHostApi.search'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_nested]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([nested]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as NonNullFieldSearchReply?)!; + return (__pigeon_replyList[0] as NonNullFieldSearchReply?)!; } } } @@ -230,21 +232,23 @@ class _NonNullFieldFlutterApiCodec extends StandardMessageCodec { } abstract class NonNullFieldFlutterApi { - static const MessageCodec codec = _NonNullFieldFlutterApiCodec(); + static const MessageCodec pigeonChannelCodec = + _NonNullFieldFlutterApiCodec(); NonNullFieldSearchReply search(NonNullFieldSearchRequest request); static void setup(NonNullFieldFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.NonNullFieldFlutterApi.search', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.NonNullFieldFlutterApi.search was null.'); final List args = (message as List?)!; 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 863897535cb..ecf7c7f7e97 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 +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -139,37 +139,38 @@ class NullFieldsHostApi { /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. NullFieldsHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec codec = _NullFieldsHostApiCodec(); + static const MessageCodec pigeonChannelCodec = + _NullFieldsHostApiCodec(); - Future search( - NullFieldsSearchRequest arg_nested) async { - const String channelName = + Future search(NullFieldsSearchRequest nested) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.NullFieldsHostApi.search'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_nested]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([nested]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as NullFieldsSearchReply?)!; + return (__pigeon_replyList[0] as NullFieldsSearchReply?)!; } } } @@ -203,21 +204,23 @@ class _NullFieldsFlutterApiCodec extends StandardMessageCodec { } abstract class NullFieldsFlutterApi { - static const MessageCodec codec = _NullFieldsFlutterApiCodec(); + static const MessageCodec pigeonChannelCodec = + _NullFieldsFlutterApiCodec(); NullFieldsSearchReply search(NullFieldsSearchRequest request); static void setup(NullFieldsFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.NullFieldsFlutterApi.search', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.NullFieldsFlutterApi.search was null.'); final List args = (message as List?)!; 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 c7f71206ee3..dd1665a463c 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 +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -35,50 +35,55 @@ class NullableReturnHostApi { /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. NullableReturnHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec codec = StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = + StandardMessageCodec(); Future doit() async { - const String channelName = + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.NullableReturnHostApi.doit'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as int?); + return (__pigeon_replyList[0] as int?); } } } abstract class NullableReturnFlutterApi { - static const MessageCodec codec = StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = + StandardMessageCodec(); int? doit(); static void setup(NullableReturnFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.NullableReturnFlutterApi.doit', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { try { final int? output = api.doit(); return wrapResponse(result: output); @@ -99,56 +104,60 @@ class NullableArgHostApi { /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. NullableArgHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec codec = StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = + StandardMessageCodec(); - Future doit(int? arg_x) async { - const String channelName = + Future doit(int? x) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.NullableArgHostApi.doit'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_x]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([x]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as int?)!; + return (__pigeon_replyList[0] as int?)!; } } } abstract class NullableArgFlutterApi { - static const MessageCodec codec = StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = + StandardMessageCodec(); int? doit(int? x); static void setup(NullableArgFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.NullableArgFlutterApi.doit', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.NullableArgFlutterApi.doit was null.'); final List args = (message as List?)!; @@ -173,50 +182,55 @@ class NullableCollectionReturnHostApi { /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. NullableCollectionReturnHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec codec = StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = + StandardMessageCodec(); Future?> doit() async { - const String channelName = + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.NullableCollectionReturnHostApi.doit'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { - return (replyList[0] as List?)?.cast(); + return (__pigeon_replyList[0] as List?)?.cast(); } } } abstract class NullableCollectionReturnFlutterApi { - static const MessageCodec codec = StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = + StandardMessageCodec(); List? doit(); static void setup(NullableCollectionReturnFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.NullableCollectionReturnFlutterApi.doit', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { try { final List? output = api.doit(); return wrapResponse(result: output); @@ -237,56 +251,60 @@ class NullableCollectionArgHostApi { /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. NullableCollectionArgHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec codec = StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = + StandardMessageCodec(); - Future> doit(List? arg_x) async { - const String channelName = + Future> doit(List? x) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.NullableCollectionArgHostApi.doit'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_x]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([x]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as List?)!.cast(); + return (__pigeon_replyList[0] as List?)!.cast(); } } } abstract class NullableCollectionArgFlutterApi { - static const MessageCodec codec = StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = + StandardMessageCodec(); List doit(List? x); static void setup(NullableCollectionArgFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.NullableCollectionArgFlutterApi.doit', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.NullableCollectionArgFlutterApi.doit was null.'); final List args = (message as List?)!; 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 d5387984bab..72c115d6527 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 +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -35,266 +35,278 @@ class PrimitiveHostApi { /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. PrimitiveHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec codec = StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = + StandardMessageCodec(); - Future anInt(int arg_value) async { - const String channelName = + Future anInt(int value) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.anInt'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_value]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([value]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as int?)!; + return (__pigeon_replyList[0] as int?)!; } } - Future aBool(bool arg_value) async { - const String channelName = + Future aBool(bool value) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aBool'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_value]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([value]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as bool?)!; + return (__pigeon_replyList[0] as bool?)!; } } - Future aString(String arg_value) async { - const String channelName = + Future aString(String value) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aString'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_value]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([value]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as String?)!; + return (__pigeon_replyList[0] as String?)!; } } - Future aDouble(double arg_value) async { - const String channelName = + Future aDouble(double value) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aDouble'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_value]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([value]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as double?)!; + return (__pigeon_replyList[0] as double?)!; } } - Future> aMap(Map arg_value) async { - const String channelName = + Future> aMap(Map value) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aMap'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_value]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([value]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as Map?)!; + return (__pigeon_replyList[0] as Map?)!; } } - Future> aList(List arg_value) async { - const String channelName = + Future> aList(List value) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aList'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_value]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([value]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as List?)!; + return (__pigeon_replyList[0] as List?)!; } } - Future anInt32List(Int32List arg_value) async { - const String channelName = + Future anInt32List(Int32List value) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.anInt32List'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_value]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([value]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as Int32List?)!; + return (__pigeon_replyList[0] as Int32List?)!; } } - Future> aBoolList(List arg_value) async { - const String channelName = + Future> aBoolList(List value) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aBoolList'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_value]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([value]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as List?)!.cast(); + return (__pigeon_replyList[0] as List?)!.cast(); } } - Future> aStringIntMap(Map arg_value) async { - const String channelName = + Future> aStringIntMap(Map value) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aStringIntMap'; - final BasicMessageChannel channel = BasicMessageChannel( - channelName, - codec, - binaryMessenger: _binaryMessenger, + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, ); - final List? replyList = - await channel.send([arg_value]) as List?; - if (replyList == null) { - throw _createConnectionError(channelName); - } else if (replyList.length > 1) { + final List? __pigeon_replyList = + await __pigeon_channel.send([value]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as Map?)!.cast(); + return (__pigeon_replyList[0] as Map?)! + .cast(); } } } abstract class PrimitiveFlutterApi { - static const MessageCodec codec = StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = + StandardMessageCodec(); int anInt(int value); @@ -317,14 +329,15 @@ abstract class PrimitiveFlutterApi { static void setup(PrimitiveFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveFlutterApi.anInt', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.PrimitiveFlutterApi.anInt was null.'); final List args = (message as List?)!; @@ -344,14 +357,15 @@ abstract class PrimitiveFlutterApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveFlutterApi.aBool', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.PrimitiveFlutterApi.aBool was null.'); final List args = (message as List?)!; @@ -371,14 +385,15 @@ abstract class PrimitiveFlutterApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveFlutterApi.aString', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.PrimitiveFlutterApi.aString was null.'); final List args = (message as List?)!; @@ -398,14 +413,15 @@ abstract class PrimitiveFlutterApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveFlutterApi.aDouble', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.PrimitiveFlutterApi.aDouble was null.'); final List args = (message as List?)!; @@ -425,14 +441,15 @@ abstract class PrimitiveFlutterApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveFlutterApi.aMap', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.PrimitiveFlutterApi.aMap was null.'); final List args = (message as List?)!; @@ -453,14 +470,15 @@ abstract class PrimitiveFlutterApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveFlutterApi.aList', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.PrimitiveFlutterApi.aList was null.'); final List args = (message as List?)!; @@ -480,14 +498,15 @@ abstract class PrimitiveFlutterApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveFlutterApi.anInt32List', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.PrimitiveFlutterApi.anInt32List was null.'); final List args = (message as List?)!; @@ -507,14 +526,15 @@ abstract class PrimitiveFlutterApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveFlutterApi.aBoolList', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.PrimitiveFlutterApi.aBoolList was null.'); final List args = (message as List?)!; @@ -535,14 +555,15 @@ abstract class PrimitiveFlutterApi { } } { - final BasicMessageChannel channel = BasicMessageChannel( + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveFlutterApi.aStringIntMap', - codec, + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + __pigeon_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.PrimitiveFlutterApi.aStringIntMap was null.'); final List args = (message as List?)!; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/test/multiple_arity_test.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/test/multiple_arity_test.dart index d446a036f74..64063f84786 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/test/multiple_arity_test.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/test/multiple_arity_test.dart @@ -18,12 +18,13 @@ void main() { 'dev.flutter.pigeon.pigeon_integration_tests.MultipleArityHostApi.subtract', any)) .thenAnswer((Invocation realInvocation) async { - final Object input = MultipleArityHostApi.codec + final Object input = MultipleArityHostApi.pigeonChannelCodec .decodeMessage(realInvocation.positionalArguments[1] as ByteData?)!; final List args = input as List; final int x = (args[0] as int?)!; final int y = (args[1] as int?)!; - return MultipleArityHostApi.codec.encodeMessage([x - y]); + return MultipleArityHostApi.pigeonChannelCodec + .encodeMessage([x - y]); }); final MultipleArityHostApi api = diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/test/null_safe_test.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/test/null_safe_test.dart index 28c341d6f0d..966c8ac99b3 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/test/null_safe_test.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/test/null_safe_test.dart @@ -50,7 +50,7 @@ void main() { final FlutterSearchReply reply = FlutterSearchReply()..result = 'ho'; final BinaryMessenger mockMessenger = MockBinaryMessenger(); final Completer completer = Completer(); - completer.complete(Api.codec.encodeMessage([reply])); + completer.complete(Api.pigeonChannelCodec.encodeMessage([reply])); final Future sendResult = completer.future; when(mockMessenger.send( 'dev.flutter.pigeon.pigeon_integration_tests.Api.search', any)) @@ -69,7 +69,7 @@ void main() { echoOneArgument( mockMessenger, 'dev.flutter.pigeon.pigeon_integration_tests.Api.echo', - Api.codec, + Api.pigeonChannelCodec, ); final Api api = Api(binaryMessenger: mockMessenger); final FlutterSearchRequests echo = await api.echo(requests); @@ -82,7 +82,7 @@ void main() { echoOneArgument( mockMessenger, 'dev.flutter.pigeon.pigeon_integration_tests.Api.anInt', - Api.codec, + Api.pigeonChannelCodec, ); final Api api = Api(binaryMessenger: mockMessenger); final int result = await api.anInt(1); @@ -95,7 +95,7 @@ void main() { 'dev.flutter.pigeon.pigeon_integration_tests.Api.anInt'; when(mockMessenger.send(channel, any)) .thenAnswer((Invocation realInvocation) async { - return Api.codec.encodeMessage([null]); + return Api.pigeonChannelCodec.encodeMessage([null]); }); final Api api = Api(binaryMessenger: mockMessenger); expect(() async => api.anInt(1), @@ -108,7 +108,7 @@ void main() { 'dev.flutter.pigeon.pigeon_integration_tests.NullableArgHostApi.doit'; when(mockMessenger.send(channel, any)) .thenAnswer((Invocation realInvocation) async { - return Api.codec.encodeMessage([123]); + return Api.pigeonChannelCodec.encodeMessage([123]); }); final NullableArgHostApi api = NullableArgHostApi(binaryMessenger: mockMessenger); @@ -121,7 +121,7 @@ void main() { 'dev.flutter.pigeon.pigeon_integration_tests.NullableCollectionArgHostApi.doit'; when(mockMessenger.send(channel, any)) .thenAnswer((Invocation realInvocation) async { - return Api.codec.encodeMessage([ + return Api.pigeonChannelCodec.encodeMessage([ ['123'] ]); }); @@ -140,10 +140,11 @@ void main() { final Completer resultCompleter = Completer(); binding.defaultBinaryMessenger.handlePlatformMessage( 'dev.flutter.pigeon.pigeon_integration_tests.NullableArgFlutterApi.doit', - NullableArgFlutterApi.codec.encodeMessage([null]), + NullableArgFlutterApi.pigeonChannelCodec.encodeMessage([null]), (ByteData? data) { resultCompleter.complete( - (NullableArgFlutterApi.codec.decodeMessage(data)! as List) + (NullableArgFlutterApi.pigeonChannelCodec.decodeMessage(data)! + as List) .first! as int, ); }, @@ -165,11 +166,12 @@ void main() { final Completer> resultCompleter = Completer>(); binding.defaultBinaryMessenger.handlePlatformMessage( 'dev.flutter.pigeon.pigeon_integration_tests.NullableCollectionArgFlutterApi.doit', - NullableCollectionArgFlutterApi.codec.encodeMessage([null]), + NullableCollectionArgFlutterApi.pigeonChannelCodec + .encodeMessage([null]), (ByteData? data) { resultCompleter.complete( - ((NullableCollectionArgFlutterApi.codec.decodeMessage(data)! - as List) + ((NullableCollectionArgFlutterApi.pigeonChannelCodec + .decodeMessage(data)! as List) .first! as List) .cast(), ); @@ -188,7 +190,8 @@ void main() { 'dev.flutter.pigeon.pigeon_integration_tests.NullableReturnHostApi.doit'; when(mockMessenger.send(channel, any)) .thenAnswer((Invocation realInvocation) async { - return NullableReturnHostApi.codec.encodeMessage([null]); + return NullableReturnHostApi.pigeonChannelCodec + .encodeMessage([null]); }); final NullableReturnHostApi api = NullableReturnHostApi(binaryMessenger: mockMessenger); @@ -201,7 +204,7 @@ void main() { 'dev.flutter.pigeon.pigeon_integration_tests.NullableCollectionReturnHostApi.doit'; when(mockMessenger.send(channel, any)) .thenAnswer((Invocation realInvocation) async { - return NullableCollectionReturnHostApi.codec + return NullableCollectionReturnHostApi.pigeonChannelCodec .encodeMessage([null]); }); final NullableCollectionReturnHostApi api = @@ -219,7 +222,7 @@ void main() { final Completer resultCompleter = Completer(); unawaited(binding.defaultBinaryMessenger.handlePlatformMessage( 'dev.flutter.pigeon.pigeon_integration_tests.NullableReturnFlutterApi.doit', - NullableReturnFlutterApi.codec.encodeMessage([]), + NullableReturnFlutterApi.pigeonChannelCodec.encodeMessage([]), (ByteData? data) { resultCompleter.complete(null); }, @@ -242,7 +245,8 @@ void main() { Completer?>(); unawaited(binding.defaultBinaryMessenger.handlePlatformMessage( 'dev.flutter.pigeon.pigeon_integration_tests.NullableCollectionReturnFlutterApi.doit', - NullableCollectionReturnFlutterApi.codec.encodeMessage([]), + NullableCollectionReturnFlutterApi.pigeonChannelCodec + .encodeMessage([]), (ByteData? data) { resultCompleter.complete(null); }, diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/test/primitive_test.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/test/primitive_test.dart index e024f9c60d8..3623ee1f5e6 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/test/primitive_test.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/test/primitive_test.dart @@ -18,7 +18,7 @@ void main() { echoOneArgument( mockMessenger, 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.anInt', - PrimitiveHostApi.codec, + PrimitiveHostApi.pigeonChannelCodec, ); final PrimitiveHostApi api = PrimitiveHostApi(binaryMessenger: mockMessenger); @@ -31,7 +31,7 @@ void main() { echoOneArgument( mockMessenger, 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aBoolList', - PrimitiveHostApi.codec, + PrimitiveHostApi.pigeonChannelCodec, ); final PrimitiveHostApi api = PrimitiveHostApi(binaryMessenger: mockMessenger); @@ -49,7 +49,7 @@ void main() { .thenAnswer((Invocation realInvocation) { final MessageHandler? handler = realInvocation.positionalArguments[1] as MessageHandler?; - handler!(PrimitiveFlutterApi.codec.encodeMessage([ + handler!(PrimitiveFlutterApi.pigeonChannelCodec.encodeMessage([ [true, false] ])); }); @@ -62,7 +62,7 @@ void main() { echoOneArgument( mockMessenger, 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aStringIntMap', - PrimitiveHostApi.codec, + PrimitiveHostApi.pigeonChannelCodec, ); final PrimitiveHostApi api = PrimitiveHostApi(binaryMessenger: mockMessenger); diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt index 47e2008276e..e1c371cf1e0 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt @@ -348,6 +348,12 @@ interface HostIntegrationCoreApi { fun echoClassWrapper(wrapper: AllClassesWrapper): AllClassesWrapper /** Returns the passed enum to test serialization and deserialization. */ fun echoEnum(anEnum: AnEnum): AnEnum + /** Returns the default string. */ + fun echoNamedDefaultString(aString: String): String + /** Returns passed in double. */ + fun echoOptionalDefaultDouble(aDouble: Double): Double + /** Returns passed in int. */ + fun echoRequiredInt(anInt: Long): Long /** Returns the passed object, to test serialization and deserialization. */ fun echoAllNullableTypes(everything: AllNullableTypes?): AllNullableTypes? /** @@ -382,6 +388,10 @@ interface HostIntegrationCoreApi { fun echoNullableMap(aNullableMap: Map?): Map? fun echoNullableEnum(anEnum: AnEnum?): AnEnum? + /** Returns passed in int. */ + fun echoOptionalNullableInt(aNullableInt: Long?): Long? + /** Returns the passed in string. */ + fun echoNamedNullableString(aNullableString: String?): String? /** * A no-op function taking no arguments and returning no value, to sanity test basic asynchronous * calling. @@ -828,6 +838,72 @@ interface HostIntegrationCoreApi { channel.setMessageHandler(null) } } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNamedDefaultString", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val aStringArg = args[0] as String + var wrapped: List + try { + wrapped = listOf(api.echoNamedDefaultString(aStringArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoOptionalDefaultDouble", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val aDoubleArg = args[0] as Double + var wrapped: List + try { + wrapped = listOf(api.echoOptionalDefaultDouble(aDoubleArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoRequiredInt", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val anIntArg = args[0].let { if (it is Int) it.toLong() else it as Long } + var wrapped: List + try { + wrapped = listOf(api.echoRequiredInt(anIntArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } run { val channel = BasicMessageChannel( @@ -1119,6 +1195,50 @@ interface HostIntegrationCoreApi { channel.setMessageHandler(null) } } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoOptionalNullableInt", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val aNullableIntArg = args[0].let { if (it is Int) it.toLong() else it as Long? } + var wrapped: List + try { + wrapped = listOf(api.echoOptionalNullableInt(aNullableIntArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNamedNullableString", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val aNullableStringArg = args[0] as String? + var wrapped: List + try { + wrapped = listOf(api.echoNamedNullableString(aNullableStringArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } run { val channel = BasicMessageChannel( diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt index a5345170985..8b4e8bc4fb1 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt @@ -82,6 +82,18 @@ class TestPlugin : FlutterPlugin, HostIntegrationCoreApi { return anEnum } + override fun echoNamedDefaultString(aString: String): String { + return aString + } + + override fun echoOptionalDefaultDouble(aDouble: Double): Double { + return aDouble + } + + override fun echoRequiredInt(anInt: Long): Long { + return anInt + } + override fun extractNestedNullableString(wrapper: AllClassesWrapper): String? { return wrapper.allNullableTypes.aNullableString } @@ -137,6 +149,14 @@ class TestPlugin : FlutterPlugin, HostIntegrationCoreApi { return anEnum } + override fun echoOptionalNullableInt(aNullableInt: Long?): Long? { + return aNullableInt + } + + override fun echoNamedNullableString(aNullableString: String?): String? { + return aNullableString + } + override fun noopAsync(callback: (Result) -> Unit) { callback(Result.success(Unit)) } diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift index 40aee78946d..773b6e5c12e 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift @@ -342,6 +342,12 @@ protocol HostIntegrationCoreApi { func echo(_ wrapper: AllClassesWrapper) throws -> AllClassesWrapper /// Returns the passed enum to test serialization and deserialization. func echo(_ anEnum: AnEnum) throws -> AnEnum + /// Returns the default string. + func echoNamedDefault(_ aString: String) throws -> String + /// Returns passed in double. + func echoOptionalDefault(_ aDouble: Double) throws -> Double + /// Returns passed in int. + func echoRequired(_ anInt: Int64) throws -> Int64 /// Returns the passed object, to test serialization and deserialization. func echo(_ everything: AllNullableTypes?) throws -> AllNullableTypes? /// Returns the inner `aString` value from the wrapped object, to test @@ -369,6 +375,10 @@ protocol HostIntegrationCoreApi { /// Returns the passed map, to test serialization and deserialization. func echoNullable(_ aNullableMap: [String?: Any?]?) throws -> [String?: Any?]? func echoNullable(_ anEnum: AnEnum?) throws -> AnEnum? + /// Returns passed in int. + func echoOptional(_ aNullableInt: Int64?) throws -> Int64? + /// Returns the passed in string. + func echoNamed(_ aNullableString: String?) throws -> String? /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. func noopAsync(completion: @escaping (Result) -> Void) @@ -681,6 +691,54 @@ class HostIntegrationCoreApiSetup { } else { echoEnumChannel.setMessageHandler(nil) } + /// Returns the default string. + let echoNamedDefaultStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNamedDefaultString", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNamedDefaultStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aStringArg = args[0] as! String + do { + let result = try api.echoNamedDefault(aStringArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNamedDefaultStringChannel.setMessageHandler(nil) + } + /// Returns passed in double. + let echoOptionalDefaultDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoOptionalDefaultDouble", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoOptionalDefaultDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aDoubleArg = args[0] as! Double + do { + let result = try api.echoOptionalDefault(aDoubleArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoOptionalDefaultDoubleChannel.setMessageHandler(nil) + } + /// Returns passed in int. + let echoRequiredIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoRequiredInt", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoRequiredIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let anIntArg = args[0] is Int64 ? args[0] as! Int64 : Int64(args[0] as! Int32) + do { + let result = try api.echoRequired(anIntArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoRequiredIntChannel.setMessageHandler(nil) + } /// Returns the passed object, to test serialization and deserialization. let echoAllNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAllNullableTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { @@ -892,6 +950,38 @@ class HostIntegrationCoreApiSetup { } else { echoNullableEnumChannel.setMessageHandler(nil) } + /// Returns passed in int. + let echoOptionalNullableIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoOptionalNullableInt", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoOptionalNullableIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableIntArg: Int64? = isNullish(args[0]) ? nil : (args[0] is Int64? ? args[0] as! Int64? : Int64(args[0] as! Int32)) + do { + let result = try api.echoOptional(aNullableIntArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoOptionalNullableIntChannel.setMessageHandler(nil) + } + /// Returns the passed in string. + let echoNamedNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNamedNullableString", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNamedNullableStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableStringArg: String? = nilOrValue(args[0]) + do { + let result = try api.echoNamed(aNullableStringArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNamedNullableStringChannel.setMessageHandler(nil) + } /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. let noopAsyncChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.noopAsync", binaryMessenger: binaryMessenger, codec: codec) diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift index c29d1eef003..8b4daf5a08e 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift @@ -126,6 +126,18 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { return aNullableObject } + func echoNamedDefault(_ aString: String) throws -> String { + return aString + } + + func echoOptionalDefault(_ aDouble: Double) throws -> Double { + return aDouble + } + + func echoRequired(_ anInt: Int64) throws -> Int64 { + return anInt + } + func echoNullable(_ aNullableList: [Any?]?) throws -> [Any?]? { return aNullableList } @@ -138,6 +150,14 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { return anEnum } + func echoOptional(_ aNullableInt: Int64?) throws -> Int64? { + return aNullableInt + } + + func echoNamed(_ aNullableString: String?) throws -> String? { + return aNullableString + } + func noopAsync(completion: @escaping (Result) -> Void) { completion(.success(Void())) } diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift index 40aee78946d..773b6e5c12e 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift @@ -342,6 +342,12 @@ protocol HostIntegrationCoreApi { func echo(_ wrapper: AllClassesWrapper) throws -> AllClassesWrapper /// Returns the passed enum to test serialization and deserialization. func echo(_ anEnum: AnEnum) throws -> AnEnum + /// Returns the default string. + func echoNamedDefault(_ aString: String) throws -> String + /// Returns passed in double. + func echoOptionalDefault(_ aDouble: Double) throws -> Double + /// Returns passed in int. + func echoRequired(_ anInt: Int64) throws -> Int64 /// Returns the passed object, to test serialization and deserialization. func echo(_ everything: AllNullableTypes?) throws -> AllNullableTypes? /// Returns the inner `aString` value from the wrapped object, to test @@ -369,6 +375,10 @@ protocol HostIntegrationCoreApi { /// Returns the passed map, to test serialization and deserialization. func echoNullable(_ aNullableMap: [String?: Any?]?) throws -> [String?: Any?]? func echoNullable(_ anEnum: AnEnum?) throws -> AnEnum? + /// Returns passed in int. + func echoOptional(_ aNullableInt: Int64?) throws -> Int64? + /// Returns the passed in string. + func echoNamed(_ aNullableString: String?) throws -> String? /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. func noopAsync(completion: @escaping (Result) -> Void) @@ -681,6 +691,54 @@ class HostIntegrationCoreApiSetup { } else { echoEnumChannel.setMessageHandler(nil) } + /// Returns the default string. + let echoNamedDefaultStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNamedDefaultString", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNamedDefaultStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aStringArg = args[0] as! String + do { + let result = try api.echoNamedDefault(aStringArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNamedDefaultStringChannel.setMessageHandler(nil) + } + /// Returns passed in double. + let echoOptionalDefaultDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoOptionalDefaultDouble", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoOptionalDefaultDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aDoubleArg = args[0] as! Double + do { + let result = try api.echoOptionalDefault(aDoubleArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoOptionalDefaultDoubleChannel.setMessageHandler(nil) + } + /// Returns passed in int. + let echoRequiredIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoRequiredInt", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoRequiredIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let anIntArg = args[0] is Int64 ? args[0] as! Int64 : Int64(args[0] as! Int32) + do { + let result = try api.echoRequired(anIntArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoRequiredIntChannel.setMessageHandler(nil) + } /// Returns the passed object, to test serialization and deserialization. let echoAllNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAllNullableTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { @@ -892,6 +950,38 @@ class HostIntegrationCoreApiSetup { } else { echoNullableEnumChannel.setMessageHandler(nil) } + /// Returns passed in int. + let echoOptionalNullableIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoOptionalNullableInt", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoOptionalNullableIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableIntArg: Int64? = isNullish(args[0]) ? nil : (args[0] is Int64? ? args[0] as! Int64? : Int64(args[0] as! Int32)) + do { + let result = try api.echoOptional(aNullableIntArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoOptionalNullableIntChannel.setMessageHandler(nil) + } + /// Returns the passed in string. + let echoNamedNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNamedNullableString", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNamedNullableStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableStringArg: String? = nilOrValue(args[0]) + do { + let result = try api.echoNamed(aNullableStringArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNamedNullableStringChannel.setMessageHandler(nil) + } /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. let noopAsyncChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.noopAsync", binaryMessenger: binaryMessenger, codec: codec) diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift index 3ed31b60d65..c82f94b1c0b 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift @@ -89,6 +89,18 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { return anEnum } + func echoNamedDefault(_ aString: String) throws -> String { + return aString + } + + func echoOptionalDefault(_ aDouble: Double) throws -> Double { + return aDouble + } + + func echoRequired(_ anInt: Int64) throws -> Int64 { + return anInt + } + func extractNestedNullableString(from wrapper: AllClassesWrapper) -> String? { return wrapper.allNullableTypes.aNullableString; } @@ -138,6 +150,14 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { return anEnum } + func echoOptional(_ aNullableInt: Int64?) throws -> Int64? { + return aNullableInt + } + + func echoNamed(_ aNullableString: String?) throws -> String? { + return aNullableString + } + func noopAsync(completion: @escaping (Result) -> Void) { completion(.success(Void())) } diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp index 6acd3cb1866..2ca7340b0ce 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp @@ -1250,6 +1250,112 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, channel->SetMessageHandler(nullptr); } } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi." + "echoNamedDefaultString", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_a_string_arg = args.at(0); + if (encodable_a_string_arg.IsNull()) { + reply(WrapError("a_string_arg unexpectedly null.")); + return; + } + const auto& a_string_arg = + std::get(encodable_a_string_arg); + ErrorOr output = + api->EchoNamedDefaultString(a_string_arg); + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + EncodableList wrapped; + wrapped.push_back(EncodableValue(std::move(output).TakeValue())); + reply(EncodableValue(std::move(wrapped))); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi." + "echoOptionalDefaultDouble", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_a_double_arg = args.at(0); + if (encodable_a_double_arg.IsNull()) { + reply(WrapError("a_double_arg unexpectedly null.")); + return; + } + const auto& a_double_arg = + std::get(encodable_a_double_arg); + ErrorOr output = + api->EchoOptionalDefaultDouble(a_double_arg); + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + EncodableList wrapped; + wrapped.push_back(EncodableValue(std::move(output).TakeValue())); + reply(EncodableValue(std::move(wrapped))); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi." + "echoRequiredInt", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_an_int_arg = args.at(0); + if (encodable_an_int_arg.IsNull()) { + reply(WrapError("an_int_arg unexpectedly null.")); + return; + } + const int64_t an_int_arg = encodable_an_int_arg.LongValue(); + ErrorOr output = api->EchoRequiredInt(an_int_arg); + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + EncodableList wrapped; + wrapped.push_back(EncodableValue(std::move(output).TakeValue())); + reply(EncodableValue(std::move(wrapped))); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } { auto channel = std::make_unique>( binary_messenger, @@ -1767,6 +1873,88 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, channel->SetMessageHandler(nullptr); } } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi." + "echoOptionalNullableInt", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_a_nullable_int_arg = args.at(0); + const int64_t a_nullable_int_arg_value = + encodable_a_nullable_int_arg.IsNull() + ? 0 + : encodable_a_nullable_int_arg.LongValue(); + const auto* a_nullable_int_arg = + encodable_a_nullable_int_arg.IsNull() + ? nullptr + : &a_nullable_int_arg_value; + ErrorOr> output = + api->EchoOptionalNullableInt(a_nullable_int_arg); + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + EncodableList wrapped; + auto output_optional = std::move(output).TakeValue(); + if (output_optional) { + wrapped.push_back( + EncodableValue(std::move(output_optional).value())); + } else { + wrapped.push_back(EncodableValue()); + } + reply(EncodableValue(std::move(wrapped))); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi." + "echoNamedNullableString", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const EncodableValue& message, + const flutter::MessageReply& reply) { + try { + const auto& args = std::get(message); + const auto& encodable_a_nullable_string_arg = args.at(0); + const auto* a_nullable_string_arg = + std::get_if(&encodable_a_nullable_string_arg); + ErrorOr> output = + api->EchoNamedNullableString(a_nullable_string_arg); + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + EncodableList wrapped; + auto output_optional = std::move(output).TakeValue(); + if (output_optional) { + wrapped.push_back( + EncodableValue(std::move(output_optional).value())); + } else { + wrapped.push_back(EncodableValue()); + } + reply(EncodableValue(std::move(wrapped))); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } { auto channel = std::make_unique>( binary_messenger, 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 b579f9fa87e..53c3320b3cf 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 @@ -414,6 +414,13 @@ class HostIntegrationCoreApi { const AllClassesWrapper& wrapper) = 0; // Returns the passed enum to test serialization and deserialization. virtual ErrorOr EchoEnum(const AnEnum& an_enum) = 0; + // Returns the default string. + virtual ErrorOr EchoNamedDefaultString( + const std::string& a_string) = 0; + // Returns passed in double. + virtual ErrorOr EchoOptionalDefaultDouble(double a_double) = 0; + // Returns passed in int. + virtual ErrorOr EchoRequiredInt(int64_t an_int) = 0; // Returns the passed object, to test serialization and deserialization. virtual ErrorOr> EchoAllNullableTypes( const AllNullableTypes* everything) = 0; @@ -455,6 +462,12 @@ class HostIntegrationCoreApi { const flutter::EncodableMap* a_nullable_map) = 0; virtual ErrorOr> EchoNullableEnum( const AnEnum* an_enum) = 0; + // Returns passed in int. + virtual ErrorOr> EchoOptionalNullableInt( + const int64_t* a_nullable_int) = 0; + // Returns the passed in string. + virtual ErrorOr> EchoNamedNullableString( + const std::string* a_nullable_string) = 0; // A no-op function taking no arguments and returning no value, to sanity // test basic asynchronous calling. virtual void NoopAsync( diff --git a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp index ea71a076344..46535b3be80 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp @@ -106,6 +106,17 @@ ErrorOr TestPlugin::EchoClassWrapper( ErrorOr TestPlugin::EchoEnum(const AnEnum& an_enum) { return an_enum; } +ErrorOr TestPlugin::EchoNamedDefaultString( + const std::string& a_string) { + return a_string; +} + +ErrorOr TestPlugin::EchoOptionalDefaultDouble(double a_double) { + return a_double; +} + +ErrorOr TestPlugin::EchoRequiredInt(int64_t an_int) { return an_int; } + ErrorOr> TestPlugin::ExtractNestedNullableString( const AllClassesWrapper& wrapper) { const std::string* inner_string = @@ -218,6 +229,22 @@ ErrorOr> TestPlugin::EchoNullableEnum( return *an_enum; } +ErrorOr> TestPlugin::EchoOptionalNullableInt( + const int64_t* a_nullable_int) { + if (!a_nullable_int) { + return std::nullopt; + } + return *a_nullable_int; +} + +ErrorOr> TestPlugin::EchoNamedNullableString( + const std::string* a_nullable_string) { + if (!a_nullable_string) { + return std::nullopt; + } + return *a_nullable_string; +} + void TestPlugin::NoopAsync( std::function reply)> result) { result(std::nullopt); diff --git a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h index d66a8e5836a..e9fd9c6f2de 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h @@ -63,6 +63,12 @@ class TestPlugin : public flutter::Plugin, const core_tests_pigeontest::AllClassesWrapper& wrapper) override; core_tests_pigeontest::ErrorOr EchoEnum( const core_tests_pigeontest::AnEnum& an_enum) override; + core_tests_pigeontest::ErrorOr EchoNamedDefaultString( + const std::string& a_string) override; + core_tests_pigeontest::ErrorOr EchoOptionalDefaultDouble( + double a_double) override; + core_tests_pigeontest::ErrorOr EchoRequiredInt( + int64_t an_int) override; core_tests_pigeontest::ErrorOr> ExtractNestedNullableString( const core_tests_pigeontest::AllClassesWrapper& wrapper) override; @@ -91,6 +97,10 @@ class TestPlugin : public flutter::Plugin, EchoNullableMap(const flutter::EncodableMap* a_nullable_map) override; core_tests_pigeontest::ErrorOr> EchoNullableEnum(const core_tests_pigeontest::AnEnum* an_enum) override; + core_tests_pigeontest::ErrorOr> + EchoOptionalNullableInt(const int64_t* a_nullable_int) override; + core_tests_pigeontest::ErrorOr> + EchoNamedNullableString(const std::string* a_nullable_string) override; void NoopAsync(std::function< void(std::optional reply)> result) override; diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index e4d61388375..c20492d9dc0 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%3Apigeon -version: 13.1.2 # This must match the version in lib/generator_tools.dart +version: 14.0.0 # This must match the version in lib/generator_tools.dart environment: sdk: ">=2.19.0 <4.0.0" diff --git a/packages/pigeon/test/ast_generator_test.dart b/packages/pigeon/test/ast_generator_test.dart index 0718c94895c..01cf75beafd 100644 --- a/packages/pigeon/test/ast_generator_test.dart +++ b/packages/pigeon/test/ast_generator_test.dart @@ -8,7 +8,7 @@ import 'package:test/test.dart'; void main() { test('gen one class', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Foobar', fields: [ NamedType( @@ -21,7 +21,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [], ); final StringBuffer sink = StringBuffer(); diff --git a/packages/pigeon/test/cpp_generator_test.dart b/packages/pigeon/test/cpp_generator_test.dart index be426c1c395..cbd290b42fa 100644 --- a/packages/pigeon/test/cpp_generator_test.dart +++ b/packages/pigeon/test/cpp_generator_test.dart @@ -10,22 +10,38 @@ import 'package:test/test.dart'; const String DEFAULT_PACKAGE_NAME = 'test_package'; +final Class emptyClass = Class(name: 'className', fields: [ + NamedType( + name: 'namedTypeName', + type: const TypeDeclaration(baseName: 'baseName', isNullable: false), + ) +]); + +final Enum emptyEnum = Enum( + name: 'enumName', + members: [EnumMember(name: 'enumMemberName')], +); + void main() { test('gen one api', () { final Root root = Root(apis: [ Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', isNullable: false, + associatedClass: emptyClass, ), name: 'input') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + isNullable: false, + associatedClass: emptyClass, + ), ) ]) ], classes: [ @@ -88,16 +104,20 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', isNullable: false, + associatedClass: emptyClass, ), name: 'someInput') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + isNullable: false, + associatedClass: emptyClass, + ), ) ]) ], classes: [ @@ -162,8 +182,8 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'int', isNullable: false, @@ -213,8 +233,8 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'int', isNullable: false, @@ -256,16 +276,20 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', isNullable: false, + associatedClass: emptyClass, ), name: 'input') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + isNullable: false, + associatedClass: emptyClass, + ), ) ]) ], classes: [ @@ -329,8 +353,8 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'String', isNullable: true, @@ -402,8 +426,8 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'String', isNullable: true, @@ -457,11 +481,12 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', isNullable: false, + associatedClass: emptyClass, ), name: 'someInput') ], @@ -497,9 +522,10 @@ void main() { ), name: 'nullableString'), NamedType( - type: const TypeDeclaration( + type: TypeDeclaration( baseName: 'Nested', isNullable: true, + associatedClass: emptyClass, ), name: 'nullableNested'), ]), @@ -638,11 +664,12 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', isNullable: false, + associatedClass: emptyClass, ), name: 'someInput') ], @@ -678,9 +705,10 @@ void main() { ), name: 'nonNullableString'), NamedType( - type: const TypeDeclaration( + type: TypeDeclaration( baseName: 'Nested', isNullable: false, + associatedClass: emptyClass, ), name: 'nonNullableNested'), ]), @@ -779,7 +807,7 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'returnNullableBool', - arguments: [], + parameters: [], returnType: const TypeDeclaration( baseName: 'bool', isNullable: true, @@ -787,7 +815,7 @@ void main() { ), Method( name: 'returnNullableInt', - arguments: [], + parameters: [], returnType: const TypeDeclaration( baseName: 'int', isNullable: true, @@ -795,7 +823,7 @@ void main() { ), Method( name: 'returnNullableString', - arguments: [], + parameters: [], returnType: const TypeDeclaration( baseName: 'String', isNullable: true, @@ -803,7 +831,7 @@ void main() { ), Method( name: 'returnNullableList', - arguments: [], + parameters: [], returnType: const TypeDeclaration( baseName: 'List', typeArguments: [ @@ -817,7 +845,7 @@ void main() { ), Method( name: 'returnNullableMap', - arguments: [], + parameters: [], returnType: const TypeDeclaration( baseName: 'Map', typeArguments: [ @@ -835,10 +863,11 @@ void main() { ), Method( name: 'returnNullableDataClass', - arguments: [], - returnType: const TypeDeclaration( + parameters: [], + returnType: TypeDeclaration( baseName: 'ReturnData', isNullable: true, + associatedClass: emptyClass, ), ), ]) @@ -895,7 +924,7 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'returnBool', - arguments: [], + parameters: [], returnType: const TypeDeclaration( baseName: 'bool', isNullable: false, @@ -903,7 +932,7 @@ void main() { ), Method( name: 'returnInt', - arguments: [], + parameters: [], returnType: const TypeDeclaration( baseName: 'int', isNullable: false, @@ -911,7 +940,7 @@ void main() { ), Method( name: 'returnString', - arguments: [], + parameters: [], returnType: const TypeDeclaration( baseName: 'String', isNullable: false, @@ -919,7 +948,7 @@ void main() { ), Method( name: 'returnList', - arguments: [], + parameters: [], returnType: const TypeDeclaration( baseName: 'List', typeArguments: [ @@ -933,7 +962,7 @@ void main() { ), Method( name: 'returnMap', - arguments: [], + parameters: [], returnType: const TypeDeclaration( baseName: 'Map', typeArguments: [ @@ -951,10 +980,11 @@ void main() { ), Method( name: 'returnDataClass', - arguments: [], - returnType: const TypeDeclaration( + parameters: [], + returnType: TypeDeclaration( baseName: 'ReturnData', isNullable: false, + associatedClass: emptyClass, ), ), ]) @@ -997,26 +1027,26 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'aBool', type: const TypeDeclaration( baseName: 'bool', isNullable: true, )), - NamedType( + Parameter( name: 'anInt', type: const TypeDeclaration( baseName: 'int', isNullable: true, )), - NamedType( + Parameter( name: 'aString', type: const TypeDeclaration( baseName: 'String', isNullable: true, )), - NamedType( + Parameter( name: 'aList', type: const TypeDeclaration( baseName: 'List', @@ -1025,7 +1055,7 @@ void main() { ], isNullable: true, )), - NamedType( + Parameter( name: 'aMap', type: const TypeDeclaration( baseName: 'Map', @@ -1035,13 +1065,14 @@ void main() { ], isNullable: true, )), - NamedType( + Parameter( name: 'anObject', - type: const TypeDeclaration( + type: TypeDeclaration( baseName: 'ParameterObject', isNullable: true, + associatedClass: emptyClass, )), - NamedType( + Parameter( name: 'aGenericObject', type: const TypeDeclaration( baseName: 'Object', @@ -1123,7 +1154,7 @@ void main() { contains( 'const auto* a_map_arg = std::get_if(&encodable_a_map_arg);')); // Ints are complicated since there are two possible pointer types, but - // the paramter always needs an int64_t*. + // the parameter always needs an int64_t*. expect( code, contains( @@ -1151,26 +1182,26 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'aBool', type: const TypeDeclaration( baseName: 'bool', isNullable: false, )), - NamedType( + Parameter( name: 'anInt', type: const TypeDeclaration( baseName: 'int', isNullable: false, )), - NamedType( + Parameter( name: 'aString', type: const TypeDeclaration( baseName: 'String', isNullable: false, )), - NamedType( + Parameter( name: 'aList', type: const TypeDeclaration( baseName: 'List', @@ -1179,7 +1210,7 @@ void main() { ], isNullable: false, )), - NamedType( + Parameter( name: 'aMap', type: const TypeDeclaration( baseName: 'Map', @@ -1189,13 +1220,14 @@ void main() { ], isNullable: false, )), - NamedType( + Parameter( name: 'anObject', - type: const TypeDeclaration( + type: TypeDeclaration( baseName: 'ParameterObject', isNullable: false, + associatedClass: emptyClass, )), - NamedType( + Parameter( name: 'aGenericObject', type: const TypeDeclaration( baseName: 'Object', @@ -1275,7 +1307,7 @@ void main() { contains( 'const auto& a_map_arg = std::get(encodable_a_map_arg);')); // Ints use a copy since there are two possible reference types, but - // the paramter always needs an int64_t. + // the parameter always needs an int64_t. expect( code, contains( @@ -1300,26 +1332,26 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'aBool', type: const TypeDeclaration( baseName: 'bool', isNullable: true, )), - NamedType( + Parameter( name: 'anInt', type: const TypeDeclaration( baseName: 'int', isNullable: true, )), - NamedType( + Parameter( name: 'aString', type: const TypeDeclaration( baseName: 'String', isNullable: true, )), - NamedType( + Parameter( name: 'aList', type: const TypeDeclaration( baseName: 'List', @@ -1328,7 +1360,7 @@ void main() { ], isNullable: true, )), - NamedType( + Parameter( name: 'aMap', type: const TypeDeclaration( baseName: 'Map', @@ -1338,13 +1370,14 @@ void main() { ], isNullable: true, )), - NamedType( + Parameter( name: 'anObject', - type: const TypeDeclaration( + type: TypeDeclaration( baseName: 'ParameterObject', isNullable: true, + associatedClass: emptyClass, )), - NamedType( + Parameter( name: 'aGenericObject', type: const TypeDeclaration( baseName: 'Object', @@ -1458,26 +1491,26 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'aBool', type: const TypeDeclaration( baseName: 'bool', isNullable: false, )), - NamedType( + Parameter( name: 'anInt', type: const TypeDeclaration( baseName: 'int', isNullable: false, )), - NamedType( + Parameter( name: 'aString', type: const TypeDeclaration( baseName: 'String', isNullable: false, )), - NamedType( + Parameter( name: 'aList', type: const TypeDeclaration( baseName: 'List', @@ -1486,7 +1519,7 @@ void main() { ], isNullable: false, )), - NamedType( + Parameter( name: 'aMap', type: const TypeDeclaration( baseName: 'Map', @@ -1496,13 +1529,14 @@ void main() { ], isNullable: false, )), - NamedType( + Parameter( name: 'anObject', - type: const TypeDeclaration( + type: TypeDeclaration( baseName: 'ParameterObject', isNullable: false, + associatedClass: emptyClass, )), - NamedType( + Parameter( name: 'aGenericObject', type: const TypeDeclaration( baseName: 'Object', @@ -1590,8 +1624,8 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'anArg', type: const TypeDeclaration( baseName: 'int', @@ -1618,7 +1652,7 @@ void main() { ); final String code = sink.toString(); // A bare 'auto' here would create a copy, not a reference, which is - // ineffecient. + // inefficient. expect( code, contains('const auto& args = std::get(message);')); expect(code, contains('const auto& encodable_an_arg_arg = args.at(0);')); @@ -1631,11 +1665,15 @@ void main() { Method( name: 'bar', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( - name: 'foo', - type: const TypeDeclaration( - baseName: 'Foo', isNullable: false)) + parameters: [ + Parameter( + name: 'foo', + type: TypeDeclaration( + baseName: 'Foo', + isNullable: false, + associatedEnum: emptyEnum, + ), + ) ]) ]) ], @@ -1676,8 +1714,8 @@ void main() { name: 'method', returnType: const TypeDeclaration.voidDeclaration(), documentationComments: [comments[count++]], - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'field', type: const TypeDeclaration( baseName: 'int', @@ -1744,7 +1782,7 @@ void main() { expect(code, contains('// ///')); }); - test('doesnt create codecs if no custom datatypes', () { + test("doesn't create codecs if no custom datatypes", () { final Root root = Root( apis: [ Api( @@ -1754,8 +1792,8 @@ void main() { Method( name: 'method', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'field', type: const TypeDeclaration( baseName: 'int', @@ -1792,16 +1830,20 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', isNullable: false, + associatedClass: emptyClass, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + isNullable: false, + associatedClass: emptyClass, + ), isAsynchronous: true, ) ]) @@ -1845,26 +1887,26 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'aBool', type: const TypeDeclaration( baseName: 'bool', isNullable: false, )), - NamedType( + Parameter( name: 'anInt', type: const TypeDeclaration( baseName: 'int', isNullable: false, )), - NamedType( + Parameter( name: 'aString', type: const TypeDeclaration( baseName: 'String', isNullable: false, )), - NamedType( + Parameter( name: 'aList', type: const TypeDeclaration( baseName: 'List', @@ -1873,7 +1915,7 @@ void main() { ], isNullable: false, )), - NamedType( + Parameter( name: 'aMap', type: const TypeDeclaration( baseName: 'Map', @@ -1883,11 +1925,12 @@ void main() { ], isNullable: false, )), - NamedType( + Parameter( name: 'anObject', - type: const TypeDeclaration( + type: TypeDeclaration( baseName: 'ParameterObject', isNullable: false, + associatedClass: emptyClass, )), ], returnType: const TypeDeclaration.voidDeclaration(), @@ -1926,14 +1969,14 @@ void main() { Api(name: 'HostApi', location: ApiLocation.host, methods: [ Method( name: 'noop', - arguments: [], + parameters: [], returnType: const TypeDeclaration.voidDeclaration(), isAsynchronous: true, ), Method( name: 'doSomething', - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'int', isNullable: false, @@ -1948,14 +1991,14 @@ void main() { Api(name: 'FlutterApi', location: ApiLocation.flutter, methods: [ Method( name: 'noop', - arguments: [], + parameters: [], returnType: const TypeDeclaration.voidDeclaration(), isAsynchronous: true, ), Method( name: 'doSomething', - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'String', isNullable: false, @@ -2002,8 +2045,8 @@ void main() { Method( name: 'method', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'field', type: const TypeDeclaration( baseName: 'int', diff --git a/packages/pigeon/test/dart_generator_test.dart b/packages/pigeon/test/dart_generator_test.dart index fdf9c1d1b87..2ab5f3f8df0 100644 --- a/packages/pigeon/test/dart_generator_test.dart +++ b/packages/pigeon/test/dart_generator_test.dart @@ -12,22 +12,35 @@ import 'package:test/test.dart'; const String DEFAULT_PACKAGE_NAME = 'test_package'; +final Class emptyClass = Class(name: 'className', fields: [ + NamedType( + name: 'namedTypeName', + type: const TypeDeclaration(baseName: 'baseName', isNullable: false), + ) +]); + +final Enum emptyEnum = Enum( + name: 'enumName', + members: [EnumMember(name: 'enumMemberName')], +); + void main() { test('gen one class', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Foobar', fields: [ NamedType( - type: const TypeDeclaration( + type: TypeDeclaration( baseName: 'dataType1', isNullable: true, + associatedClass: emptyClass, ), name: 'field1'), ], ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [], ); final StringBuffer sink = StringBuffer(); @@ -75,16 +88,20 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', isNullable: false, + associatedClass: emptyClass, ), name: 'input') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + isNullable: false, + associatedClass: emptyClass, + ), ) ]) ], classes: [ @@ -115,7 +132,7 @@ void main() { ); final String code = sink.toString(); expect(code, contains('class Api')); - expect(code, contains('Future doSomething(Input arg_input)')); + expect(code, contains('Future doSomething(Input input)')); }); test('host multiple args', () { @@ -123,12 +140,12 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'add', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'x', type: const TypeDeclaration(isNullable: false, baseName: 'int')), - NamedType( + Parameter( name: 'y', type: const TypeDeclaration(isNullable: false, baseName: 'int')), @@ -147,8 +164,8 @@ void main() { ); final String code = sink.toString(); expect(code, contains('class Api')); - expect(code, contains('Future add(int arg_x, int arg_y)')); - expect(code, contains('await channel.send([arg_x, arg_y])')); + expect(code, contains('Future add(int x, int y)')); + expect(code, contains('await __pigeon_channel.send([x, y])')); }); test('flutter multiple args', () { @@ -156,12 +173,12 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'add', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'x', type: const TypeDeclaration(isNullable: false, baseName: 'int')), - NamedType( + Parameter( name: 'y', type: const TypeDeclaration(isNullable: false, baseName: 'int')), @@ -205,9 +222,10 @@ void main() { name: 'Nested', fields: [ NamedType( - type: const TypeDeclaration( + type: TypeDeclaration( baseName: 'Input', isNullable: true, + associatedClass: emptyClass, ), name: 'nested') ], @@ -253,9 +271,10 @@ void main() { name: 'Nested', fields: [ NamedType( - type: const TypeDeclaration( + type: TypeDeclaration( baseName: 'Input', isNullable: false, + associatedClass: emptyClass, ), name: 'nested') ], @@ -289,16 +308,20 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', isNullable: false, + associatedClass: emptyClass, ), name: 'input') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + isNullable: false, + associatedClass: emptyClass, + ), ) ]) ], classes: [ @@ -338,11 +361,12 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', isNullable: false, + associatedClass: emptyClass, ), name: '') ], @@ -377,11 +401,12 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', isNullable: false, + associatedClass: emptyClass, ), name: '') ], @@ -419,9 +444,12 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + parameters: [], + returnType: TypeDeclaration( + baseName: 'Output', + isNullable: false, + associatedClass: emptyClass, + ), ) ]) ], classes: [ @@ -452,24 +480,29 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'EnumClass', isNullable: false, + associatedClass: emptyClass, ), - name: '') + name: 'enumClass') ], - returnType: - const TypeDeclaration(baseName: 'EnumClass', isNullable: false), + returnType: TypeDeclaration( + baseName: 'EnumClass', + isNullable: false, + associatedClass: emptyClass, + ), ) ]) ], classes: [ Class(name: 'EnumClass', fields: [ NamedType( - type: const TypeDeclaration( + type: TypeDeclaration( baseName: 'Enum', isNullable: true, + associatedEnum: emptyEnum, ), name: 'enum1') ]), @@ -493,7 +526,7 @@ void main() { final String code = sink.toString(); expect(code, contains('enum1?.index,')); expect(code, contains('? Enum.values[result[0]! as int]')); - expect(code, contains('EnumClass doSomething(EnumClass arg0);')); + expect(code, contains('EnumClass doSomething(EnumClass enumClass);')); }); test('primitive enum host', () { @@ -502,11 +535,14 @@ void main() { Method( name: 'bar', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'foo', - type: - const TypeDeclaration(baseName: 'Foo', isNullable: true)) + type: TypeDeclaration( + baseName: 'Foo', + isNullable: true, + associatedEnum: emptyEnum, + )) ]) ]) ], classes: [], enums: [ @@ -525,8 +561,8 @@ void main() { ); final String code = sink.toString(); expect(code, contains('enum Foo {')); - expect(code, contains('Future bar(Foo? arg_foo) async')); - expect(code, contains('channel.send([arg_foo?.index])')); + expect(code, contains('Future bar(Foo? foo) async')); + expect(code, contains('__pigeon_channel.send([foo?.index])')); }); test('flutter non-nullable enum argument with enum class', () { @@ -534,24 +570,29 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'EnumClass', isNullable: false, + associatedClass: emptyClass, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'EnumClass', isNullable: false), + returnType: TypeDeclaration( + baseName: 'EnumClass', + isNullable: false, + associatedClass: emptyClass, + ), ) ]) ], classes: [ Class(name: 'EnumClass', fields: [ NamedType( - type: const TypeDeclaration( + type: TypeDeclaration( baseName: 'Enum', isNullable: false, + associatedEnum: emptyEnum, ), name: 'enum1') ]), @@ -582,9 +623,12 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + parameters: [], + returnType: TypeDeclaration( + baseName: 'Output', + isNullable: false, + associatedClass: emptyClass, + ), ) ]) ], classes: [ @@ -606,7 +650,7 @@ void main() { dartPackageName: DEFAULT_PACKAGE_NAME, ); final String code = sink.toString(); - expect(code, matches('channel.send[(]null[)]')); + expect(code, matches('__pigeon_channel.send[(]null[)]')); }); test('mock dart handler', () { @@ -618,24 +662,29 @@ void main() { methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', isNullable: false, + associatedClass: emptyClass, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + isNullable: false, + associatedClass: emptyClass, + ), ), Method( name: 'voidReturner', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', isNullable: false, + associatedClass: emptyClass, ), name: '') ], @@ -702,16 +751,20 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', isNullable: false, + associatedClass: emptyClass, ), - name: '') + name: 'input') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + isNullable: false, + associatedClass: emptyClass, + ), isAsynchronous: true, ) ]) @@ -743,9 +796,9 @@ void main() { ); final String code = sink.toString(); expect(code, contains('abstract class Api')); - expect(code, contains('Future doSomething(Input arg0);')); - expect( - code, contains('final Output output = await api.doSomething(arg0!);')); + expect(code, contains('Future doSomething(Input input);')); + expect(code, + contains('final Output output = await api.doSomething(arg_input!);')); }); test('gen one async Flutter Api with void return', () { @@ -753,11 +806,12 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', isNullable: false, + associatedClass: emptyClass, ), name: '') ], @@ -802,16 +856,20 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', isNullable: false, + associatedClass: emptyClass, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + isNullable: false, + associatedClass: emptyClass, + ), isAsynchronous: true, ) ]) @@ -851,9 +909,12 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + parameters: [], + returnType: TypeDeclaration( + baseName: 'Output', + isNullable: false, + associatedClass: emptyClass, + ), isAsynchronous: true, ) ]) @@ -876,7 +937,7 @@ void main() { dartPackageName: DEFAULT_PACKAGE_NAME, ); final String code = sink.toString(); - expect(code, matches('channel.send[(]null[)]')); + expect(code, matches('__pigeon_channel.send[(]null[)]')); }); Iterable makeIterable(String string) sync* { @@ -899,7 +960,7 @@ void main() { }); test('generics', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Foobar', fields: [ NamedType( @@ -914,7 +975,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [], ); final StringBuffer sink = StringBuffer(); @@ -931,7 +992,7 @@ void main() { }); test('map generics', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Foobar', fields: [ NamedType( @@ -947,7 +1008,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [], ); final StringBuffer sink = StringBuffer(); @@ -970,8 +1031,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -1004,8 +1065,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -1043,7 +1104,7 @@ void main() { typeArguments: [ TypeDeclaration(baseName: 'int', isNullable: true) ]), - arguments: []) + parameters: []) ]) ], classes: [], @@ -1059,8 +1120,10 @@ void main() { ); final String code = sink.toString(); expect(code, contains('Future> doit(')); - expect(code, - contains('return (replyList[0] as List?)!.cast();')); + expect( + code, + contains( + 'return (__pigeon_replyList[0] as List?)!.cast();')); }); test('flutter generics argument non void return', () { @@ -1075,8 +1138,8 @@ void main() { typeArguments: [ TypeDeclaration(baseName: 'int', isNullable: true) ]), - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -1117,7 +1180,7 @@ void main() { baseName: 'int', isNullable: true, ), - arguments: []) + parameters: []) ]) ], classes: [], @@ -1133,7 +1196,7 @@ void main() { ); final String code = sink.toString(); expect(code, contains('Future doit()')); - expect(code, contains('return (replyList[0] as int?);')); + expect(code, contains('return (__pigeon_replyList[0] as int?);')); }); test('return nullable collection host', () { @@ -1148,7 +1211,7 @@ void main() { typeArguments: [ TypeDeclaration(baseName: 'int', isNullable: true) ]), - arguments: []) + parameters: []) ]) ], classes: [], @@ -1164,8 +1227,10 @@ void main() { ); final String code = sink.toString(); expect(code, contains('Future?> doit()')); - expect(code, - contains('return (replyList[0] as List?)?.cast();')); + expect( + code, + contains( + 'return (__pigeon_replyList[0] as List?)?.cast();')); }); test('return nullable async host', () { @@ -1178,7 +1243,7 @@ void main() { baseName: 'int', isNullable: true, ), - arguments: [], + parameters: [], isAsynchronous: true) ]) ], @@ -1195,7 +1260,7 @@ void main() { ); final String code = sink.toString(); expect(code, contains('Future doit()')); - expect(code, contains('return (replyList[0] as int?);')); + expect(code, contains('return (__pigeon_replyList[0] as int?);')); }); test('return nullable flutter', () { @@ -1208,7 +1273,7 @@ void main() { baseName: 'int', isNullable: true, ), - arguments: []) + parameters: []) ]) ], classes: [], @@ -1237,7 +1302,7 @@ void main() { baseName: 'int', isNullable: true, ), - arguments: [], + parameters: [], isAsynchronous: true) ]) ], @@ -1267,7 +1332,7 @@ void main() { baseName: 'int', isNullable: false, ), - arguments: []) + parameters: []) ]) ], classes: [], @@ -1295,8 +1360,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'foo', type: const TypeDeclaration( baseName: 'int', @@ -1317,7 +1382,7 @@ void main() { dartPackageName: DEFAULT_PACKAGE_NAME, ); final String code = sink.toString(); - expect(code, contains('Future doit(int? arg_foo) async {')); + expect(code, contains('Future doit(int? foo) async {')); }); test('nullable argument flutter', () { @@ -1327,8 +1392,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'foo', type: const TypeDeclaration( baseName: 'int', @@ -1411,8 +1476,8 @@ name: foobar name: 'method', returnType: const TypeDeclaration.voidDeclaration(), documentationComments: [comments[count++]], - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'field', type: const TypeDeclaration( baseName: 'int', @@ -1484,8 +1549,8 @@ name: foobar Method( name: 'method', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'field', type: const TypeDeclaration( baseName: 'int', @@ -1518,16 +1583,20 @@ name: foobar Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', isNullable: false, + associatedClass: emptyClass, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + isNullable: false, + associatedClass: emptyClass, + ), isAsynchronous: true, ) ]) @@ -1572,11 +1641,12 @@ name: foobar Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Enum', isNullable: false, + associatedEnum: emptyEnum, ), name: 'anEnum') ]) @@ -1619,7 +1689,7 @@ name: foobar Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'method', - arguments: [], + parameters: [], returnType: const TypeDeclaration(baseName: 'Output', isNullable: false), ) @@ -1634,7 +1704,8 @@ name: foobar dartPackageName: DEFAULT_PACKAGE_NAME, ); final String code = sink.toString(); - expect(code, contains('throw _createConnectionError(channelName);')); + expect( + code, contains('throw _createConnectionError(__pigeon_channelName);')); expect( code, contains( diff --git a/packages/pigeon/test/generator_tools_test.dart b/packages/pigeon/test/generator_tools_test.dart index 82b23ae1c5e..4570ac633aa 100644 --- a/packages/pigeon/test/generator_tools_test.dart +++ b/packages/pigeon/test/generator_tools_test.dart @@ -37,6 +37,18 @@ bool _equalMaps(Map x, Map y) { return true; } +final Class emptyClass = Class(name: 'className', fields: [ + NamedType( + name: 'namedTypeName', + type: const TypeDeclaration(baseName: 'baseName', isNullable: false), + ) +]); + +final Enum emptyEnum = Enum( + name: 'enumName', + members: [EnumMember(name: 'enumMemberName')], +); + void main() { test('test merge maps', () { final Map source = { @@ -70,20 +82,27 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'List', isNullable: false, typeArguments: [ - TypeDeclaration(baseName: 'Input', isNullable: true) + TypeDeclaration( + baseName: 'Input', + isNullable: true, + associatedClass: emptyClass, + ) ], ), name: '', ) ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + isNullable: false, + associatedClass: emptyClass, + ), isAsynchronous: true, ) ]); @@ -108,17 +127,25 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration(baseName: 'Output', isNullable: false), + parameters: [ + Parameter( + type: TypeDeclaration( + baseName: 'Output', + isNullable: false, + associatedClass: emptyClass, + ), name: '', ) ], - returnType: const TypeDeclaration( + returnType: TypeDeclaration( baseName: 'List', isNullable: false, typeArguments: [ - TypeDeclaration(baseName: 'Input', isNullable: true) + TypeDeclaration( + baseName: 'Input', + isNullable: true, + associatedClass: emptyClass, + ) ], ), isAsynchronous: true, @@ -145,13 +172,21 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration(baseName: 'Foo', isNullable: false), + parameters: [ + Parameter( + type: TypeDeclaration( + baseName: 'Foo', + isNullable: false, + associatedClass: emptyClass, + ), name: '', ), - NamedType( - type: const TypeDeclaration(baseName: 'Bar', isNullable: false), + Parameter( + type: TypeDeclaration( + baseName: 'Bar', + isNullable: false, + associatedEnum: emptyEnum, + ), name: '', ), ], @@ -184,14 +219,18 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'foo', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'x', - type: const TypeDeclaration( + type: TypeDeclaration( isNullable: false, baseName: 'List', typeArguments: [ - TypeDeclaration(baseName: 'Foo', isNullable: true) + TypeDeclaration( + baseName: 'Foo', + isNullable: true, + associatedClass: emptyClass, + ) ])), ], returnType: const TypeDeclaration.voidDeclaration(), @@ -201,12 +240,19 @@ void main() { Class(name: 'Foo', fields: [ NamedType( name: 'bar', - type: const TypeDeclaration(baseName: 'Bar', isNullable: true)), + type: TypeDeclaration( + baseName: 'Bar', + isNullable: true, + associatedClass: emptyClass, + )), ]), Class(name: 'Bar', fields: [ NamedType( name: 'value', - type: const TypeDeclaration(baseName: 'int', isNullable: true)) + type: const TypeDeclaration( + baseName: 'int', + isNullable: true, + )) ]) ], enums: []); final List classes = @@ -232,8 +278,8 @@ void main() { methods: [ Method( name: 'foo', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'x', type: const TypeDeclaration( isNullable: false, @@ -271,11 +317,14 @@ void main() { methods: [ Method( name: 'foo', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'x', - type: const TypeDeclaration( - isNullable: false, baseName: 'Foo')), + type: TypeDeclaration( + isNullable: false, + baseName: 'Foo', + associatedClass: emptyClass, + )), ], returnType: const TypeDeclaration.voidDeclaration(), ) @@ -287,11 +336,14 @@ void main() { methods: [ Method( name: 'foo', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'x', - type: const TypeDeclaration( - isNullable: false, baseName: 'Foo')), + type: TypeDeclaration( + isNullable: false, + baseName: 'Foo', + associatedClass: emptyClass, + )), ], returnType: const TypeDeclaration.voidDeclaration(), ) diff --git a/packages/pigeon/test/java_generator_test.dart b/packages/pigeon/test/java_generator_test.dart index 15abd016a68..99936ca2b92 100644 --- a/packages/pigeon/test/java_generator_test.dart +++ b/packages/pigeon/test/java_generator_test.dart @@ -9,9 +9,21 @@ import 'package:test/test.dart'; const String DEFAULT_PACKAGE_NAME = 'test_package'; +final Class emptyClass = Class(name: 'className', fields: [ + NamedType( + name: 'namedTypeName', + type: const TypeDeclaration(baseName: 'baseName', isNullable: false), + ) +]); + +final Enum emptyEnum = Enum( + name: 'enumName', + members: [EnumMember(name: 'enumMemberName')], +); + void main() { test('gen one class', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Foobar', fields: [ NamedType( @@ -24,7 +36,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [], ); final StringBuffer sink = StringBuffer(); @@ -77,7 +89,7 @@ void main() { }); test('package', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Foobar', fields: [ NamedType( @@ -90,7 +102,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [], ); final StringBuffer sink = StringBuffer(); @@ -113,16 +125,20 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), ) ]) ], classes: [ @@ -251,16 +267,20 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), ) ]) ], classes: [ @@ -300,10 +320,11 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') @@ -340,10 +361,11 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') @@ -383,9 +405,12 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + parameters: [], + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), ) ]) ], classes: [ @@ -417,9 +442,12 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + parameters: [], + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), ) ]) ], classes: [ @@ -498,12 +526,13 @@ void main() { }); test('gen nested', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Outer', fields: [ NamedType( - type: const TypeDeclaration( + type: TypeDeclaration( baseName: 'Nested', + associatedClass: emptyClass, isNullable: true, ), name: 'nested') @@ -522,7 +551,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass, nestedClass], + classes: [classDefinition, nestedClass], enums: [], ); final StringBuffer sink = StringBuffer(); @@ -551,16 +580,20 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: 'arg') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), isAsynchronous: true, ) ]) @@ -608,16 +641,20 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), isAsynchronous: true, ) ]) @@ -662,12 +699,13 @@ void main() { EnumMember(name: 'remoteDB'), ], ); - final Class klass = Class( + final Class classDefinition = Class( name: 'EnumClass', fields: [ NamedType( - type: const TypeDeclaration( + type: TypeDeclaration( baseName: 'Enum1', + associatedEnum: emptyEnum, isNullable: true, ), name: 'enum1'), @@ -675,7 +713,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [anEnum], ); final StringBuffer sink = StringBuffer(); @@ -710,11 +748,15 @@ void main() { Method( name: 'bar', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( - name: 'foo', - type: - const TypeDeclaration(baseName: 'Foo', isNullable: true)) + parameters: [ + Parameter( + name: 'foo', + type: TypeDeclaration( + baseName: 'Foo', + isNullable: true, + associatedEnum: emptyEnum, + ), + ) ]) ]) ], classes: [], enums: [ @@ -763,7 +805,7 @@ void main() { }); test('generics', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Foobar', fields: [ NamedType( @@ -778,7 +820,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [], ); final StringBuffer sink = StringBuffer(); @@ -796,7 +838,7 @@ void main() { }); test('generics - maps', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Foobar', fields: [ NamedType( @@ -812,7 +854,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [], ); final StringBuffer sink = StringBuffer(); @@ -836,8 +878,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -871,8 +913,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -911,7 +953,7 @@ void main() { typeArguments: [ TypeDeclaration(baseName: 'int', isNullable: true) ]), - arguments: []) + parameters: []) ]) ], classes: [], @@ -943,7 +985,7 @@ void main() { typeArguments: [ TypeDeclaration(baseName: 'int', isNullable: true) ]), - arguments: []) + parameters: []) ]) ], classes: [], @@ -972,7 +1014,7 @@ void main() { name: 'doit', returnType: const TypeDeclaration(baseName: 'int', isNullable: false), - arguments: [], + parameters: [], isAsynchronous: true) ]) ], @@ -1001,12 +1043,12 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'add', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'x', type: const TypeDeclaration(isNullable: false, baseName: 'int')), - NamedType( + Parameter( name: 'y', type: const TypeDeclaration(isNullable: false, baseName: 'int')), @@ -1042,8 +1084,8 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'objectTest', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'x', type: const TypeDeclaration( isNullable: false, baseName: 'Object')), @@ -1070,12 +1112,12 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'add', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'x', type: const TypeDeclaration(isNullable: false, baseName: 'int')), - NamedType( + Parameter( name: 'y', type: const TypeDeclaration(isNullable: false, baseName: 'int')), @@ -1112,8 +1154,8 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'send', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'x', type: const TypeDeclaration(isNullable: false, baseName: 'int')), @@ -1148,7 +1190,7 @@ void main() { baseName: 'int', isNullable: true, ), - arguments: []) + parameters: []) ]) ], classes: [], @@ -1178,7 +1220,7 @@ void main() { isNullable: true, ), isAsynchronous: true, - arguments: []) + parameters: []) ]) ], classes: [], @@ -1205,8 +1247,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'foo', type: const TypeDeclaration( baseName: 'int', @@ -1238,8 +1280,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'foo', type: const TypeDeclaration( baseName: 'int', @@ -1274,8 +1316,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'foo', type: const TypeDeclaration( baseName: 'int', @@ -1309,13 +1351,13 @@ void main() { }); test('generated annotation', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Foobar', fields: [], ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [], ); final StringBuffer sink = StringBuffer(); @@ -1333,13 +1375,13 @@ void main() { }); test('no generated annotation', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Foobar', fields: [], ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [], ); final StringBuffer sink = StringBuffer(); @@ -1381,8 +1423,8 @@ void main() { name: 'method', returnType: const TypeDeclaration.voidDeclaration(), documentationComments: [comments[count++]], - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'field', type: const TypeDeclaration( baseName: 'int', @@ -1460,8 +1502,8 @@ void main() { Method( name: 'method', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'field', type: const TypeDeclaration( baseName: 'int', @@ -1495,16 +1537,20 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), isAsynchronous: true, ) ]) @@ -1570,8 +1616,8 @@ void main() { Method( name: 'method', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'field', type: const TypeDeclaration( baseName: 'int', diff --git a/packages/pigeon/test/kotlin_generator_test.dart b/packages/pigeon/test/kotlin_generator_test.dart index 9f2fb321816..606f47e3690 100644 --- a/packages/pigeon/test/kotlin_generator_test.dart +++ b/packages/pigeon/test/kotlin_generator_test.dart @@ -8,9 +8,21 @@ import 'package:test/test.dart'; const String DEFAULT_PACKAGE_NAME = 'test_package'; +final Class emptyClass = Class(name: 'className', fields: [ + NamedType( + name: 'namedTypeName', + type: const TypeDeclaration(baseName: 'baseName', isNullable: false), + ) +]); + +final Enum emptyEnum = Enum( + name: 'enumName', + members: [EnumMember(name: 'enumMemberName')], +); + void main() { test('gen one class', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Foobar', fields: [ NamedType( @@ -24,7 +36,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [], ); final StringBuffer sink = StringBuffer(); @@ -80,9 +92,10 @@ void main() { fields: [ NamedType( name: 'field1', - type: const TypeDeclaration( + type: TypeDeclaration( baseName: 'Foo', isNullable: false, + associatedEnum: emptyEnum, ), ), NamedType( @@ -131,11 +144,14 @@ void main() { Method( name: 'bar', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'foo', - type: - const TypeDeclaration(baseName: 'Foo', isNullable: false)) + type: TypeDeclaration( + baseName: 'Foo', + isNullable: false, + associatedEnum: emptyEnum, + )) ]) ]) ], classes: [], enums: [ @@ -163,17 +179,21 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: 'input', ) ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), ) ]) ], classes: [ @@ -388,17 +408,21 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '', ) ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), ) ]) ], classes: [ @@ -441,10 +465,11 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '', @@ -483,10 +508,11 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '', @@ -527,9 +553,12 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + parameters: [], + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), ) ]) ], classes: [ @@ -564,9 +593,12 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + parameters: [], + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), ) ]) ], classes: [ @@ -648,12 +680,13 @@ void main() { }); test('gen nested', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Outer', fields: [ NamedType( - type: const TypeDeclaration( + type: TypeDeclaration( baseName: 'Nested', + associatedClass: emptyClass, isNullable: true, ), name: 'nested', @@ -674,7 +707,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass, nestedClass], + classes: [classDefinition, nestedClass], enums: [], ); final StringBuffer sink = StringBuffer(); @@ -702,17 +735,21 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: 'arg', ) ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), isAsynchronous: true, ) ]) @@ -756,17 +793,21 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '', ) ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), isAsynchronous: true, ) ]) @@ -812,12 +853,13 @@ void main() { EnumMember(name: 'two'), ], ); - final Class klass = Class( + final Class classDefinition = Class( name: 'EnumClass', fields: [ NamedType( - type: const TypeDeclaration( + type: TypeDeclaration( baseName: 'Enum1', + associatedEnum: emptyEnum, isNullable: true, ), name: 'enum1', @@ -826,7 +868,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [anEnum], ); final StringBuffer sink = StringBuffer(); @@ -866,7 +908,7 @@ void main() { }); test('generics - list', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Foobar', fields: [ NamedType( @@ -882,7 +924,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [], ); final StringBuffer sink = StringBuffer(); @@ -900,7 +942,7 @@ void main() { }); test('generics - maps', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Foobar', fields: [ NamedType( @@ -917,7 +959,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [], ); final StringBuffer sink = StringBuffer(); @@ -941,8 +983,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -977,8 +1019,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -1018,7 +1060,7 @@ void main() { typeArguments: [ TypeDeclaration(baseName: 'int', isNullable: true) ]), - arguments: []) + parameters: []) ]) ], classes: [], @@ -1051,7 +1093,7 @@ void main() { typeArguments: [ TypeDeclaration(baseName: 'int', isNullable: true) ]), - arguments: []) + parameters: []) ]) ], classes: [], @@ -1077,12 +1119,12 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'add', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'x', type: const TypeDeclaration(isNullable: false, baseName: 'int')), - NamedType( + Parameter( name: 'y', type: const TypeDeclaration(isNullable: false, baseName: 'int')), @@ -1120,12 +1162,12 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'add', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'x', type: const TypeDeclaration(baseName: 'int', isNullable: false)), - NamedType( + Parameter( name: 'y', type: const TypeDeclaration(baseName: 'int', isNullable: false)), @@ -1168,7 +1210,7 @@ void main() { baseName: 'int', isNullable: true, ), - arguments: []) + parameters: []) ]) ], classes: [], @@ -1198,7 +1240,7 @@ void main() { isNullable: true, ), isAsynchronous: true, - arguments: []) + parameters: []) ]) ], classes: [], @@ -1224,8 +1266,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'foo', type: const TypeDeclaration( baseName: 'int', @@ -1260,8 +1302,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'foo', type: const TypeDeclaration( baseName: 'int', @@ -1294,10 +1336,11 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '', @@ -1355,8 +1398,8 @@ void main() { name: 'method', returnType: const TypeDeclaration.voidDeclaration(), documentationComments: [comments[count++]], - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'field', type: const TypeDeclaration( baseName: 'int', @@ -1434,8 +1477,8 @@ void main() { Method( name: 'method', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'field', type: const TypeDeclaration( baseName: 'int', @@ -1469,16 +1512,20 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), isAsynchronous: true, ) ]) @@ -1517,7 +1564,7 @@ void main() { final Method method = Method( name: 'doSomething', returnType: const TypeDeclaration.voidDeclaration(), - arguments: []); + parameters: []); final Api api = Api( name: 'SomeApi', location: ApiLocation.host, methods: [method]); final Root root = Root( @@ -1553,8 +1600,8 @@ void main() { Method( name: 'method', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'field', type: const TypeDeclaration( baseName: 'int', diff --git a/packages/pigeon/test/objc_generator_test.dart b/packages/pigeon/test/objc_generator_test.dart index ef1d91f1f70..f77f186ac8d 100644 --- a/packages/pigeon/test/objc_generator_test.dart +++ b/packages/pigeon/test/objc_generator_test.dart @@ -10,6 +10,18 @@ import 'package:test/test.dart'; const String DEFAULT_PACKAGE_NAME = 'test_package'; +final Class emptyClass = Class(name: 'className', fields: [ + NamedType( + name: 'namedTypeName', + type: const TypeDeclaration(baseName: 'baseName', isNullable: false), + ) +]); + +final Enum emptyEnum = Enum( + name: 'enumName', + members: [EnumMember(name: 'enumMemberName')], +); + void main() { test('gen one class header', () { final Root root = Root(apis: [], classes: [ @@ -133,8 +145,11 @@ void main() { const TypeDeclaration(baseName: 'String', isNullable: true), name: 'field1'), NamedType( - type: - const TypeDeclaration(baseName: 'Enum1', isNullable: true), + type: TypeDeclaration( + baseName: 'Enum1', + associatedEnum: emptyEnum, + isNullable: true, + ), name: 'enum1'), ], ), @@ -177,11 +192,14 @@ void main() { Method( name: 'bar', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'foo', - type: - const TypeDeclaration(baseName: 'Foo', isNullable: false)) + type: TypeDeclaration( + baseName: 'Foo', + associatedEnum: emptyEnum, + isNullable: false, + )) ]) ]) ], classes: [], enums: [ @@ -237,11 +255,14 @@ void main() { Method( name: 'bar', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'foo', - type: - const TypeDeclaration(baseName: 'Foo', isNullable: true)) + type: TypeDeclaration( + baseName: 'Foo', + associatedEnum: emptyEnum, + isNullable: true, + )) ]) ]) ], classes: [], enums: [ @@ -268,8 +289,11 @@ void main() { const TypeDeclaration(baseName: 'String', isNullable: true), name: 'field1'), NamedType( - type: - const TypeDeclaration(baseName: 'Enum1', isNullable: true), + type: TypeDeclaration( + baseName: 'Enum1', + associatedEnum: emptyEnum, + isNullable: true, + ), name: 'enum1'), ], ), @@ -307,14 +331,20 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( - baseName: 'Input', isNullable: false), + parameters: [ + Parameter( + type: TypeDeclaration( + baseName: 'Input', + associatedClass: emptyClass, + isNullable: false, + ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false)) + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + )) ]) ], classes: [ Class(name: 'Input', fields: [ @@ -356,16 +386,20 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false)) + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + )) ]) ], classes: [ Class(name: 'Input', fields: [ @@ -505,7 +539,11 @@ void main() { ]), Class(name: 'Nested', fields: [ NamedType( - type: const TypeDeclaration(baseName: 'Input', isNullable: true), + type: TypeDeclaration( + baseName: 'Input', + associatedClass: emptyClass, + isNullable: true, + ), name: 'nested') ]) ], enums: []); @@ -536,7 +574,11 @@ void main() { ]), Class(name: 'Nested', fields: [ NamedType( - type: const TypeDeclaration(baseName: 'Input', isNullable: true), + type: TypeDeclaration( + baseName: 'Input', + associatedClass: emptyClass, + isNullable: true, + ), name: 'nested') ]) ], enums: []); @@ -617,16 +659,20 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Nested', isNullable: false)) + returnType: TypeDeclaration( + baseName: 'Nested', + associatedClass: emptyClass, + isNullable: false, + )) ]) ], classes: [ Class(name: 'Input', fields: [ @@ -636,7 +682,11 @@ void main() { ]), Class(name: 'Nested', fields: [ NamedType( - type: const TypeDeclaration(baseName: 'Input', isNullable: true), + type: TypeDeclaration( + baseName: 'Input', + associatedClass: emptyClass, + isNullable: true, + ), name: 'nested') ]) ], enums: []); @@ -664,16 +714,20 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Nested', isNullable: false)) + returnType: TypeDeclaration( + baseName: 'Nested', + associatedClass: emptyClass, + isNullable: false, + )) ]) ], classes: [ Class(name: 'Input', fields: [ @@ -683,7 +737,11 @@ void main() { ]), Class(name: 'Nested', fields: [ NamedType( - type: const TypeDeclaration(baseName: 'Input', isNullable: true), + type: TypeDeclaration( + baseName: 'Input', + associatedClass: emptyClass, + isNullable: true, + ), name: 'nested') ]) ], enums: []); @@ -711,16 +769,20 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false)) + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + )) ]) ], classes: [ Class(name: 'Input', fields: [ @@ -762,16 +824,20 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false)) + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + )) ]) ], classes: [ Class(name: 'Input', fields: [ @@ -809,10 +875,11 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') @@ -849,10 +916,11 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') @@ -891,10 +959,11 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') @@ -931,10 +1000,11 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') @@ -972,9 +1042,12 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false)) + parameters: [], + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + )) ]) ], classes: [ Class(name: 'Output', fields: [ @@ -1006,9 +1079,12 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false)) + parameters: [], + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + )) ]) ], classes: [ Class(name: 'Output', fields: [ @@ -1040,9 +1116,12 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false)) + parameters: [], + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + )) ]) ], classes: [ Class(name: 'Output', fields: [ @@ -1077,9 +1156,12 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false)) + parameters: [], + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + )) ]) ], classes: [ Class(name: 'Output', fields: [ @@ -1203,8 +1285,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'foo', type: const TypeDeclaration( baseName: 'Map', @@ -1238,10 +1320,11 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: 'input') @@ -1287,16 +1370,20 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: 'input') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), isAsynchronous: true) ]) ], classes: [ @@ -1337,9 +1424,12 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + parameters: [], + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), isAsynchronous: true) ]) ], classes: [ @@ -1375,7 +1465,7 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [], + parameters: [], returnType: const TypeDeclaration.voidDeclaration(), isAsynchronous: true) ]) @@ -1406,16 +1496,20 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), isAsynchronous: true) ]) ], classes: [ @@ -1456,10 +1550,11 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: 'foo') @@ -1505,7 +1600,7 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [], + parameters: [], returnType: const TypeDeclaration.voidDeclaration(), isAsynchronous: true) ]) @@ -1536,9 +1631,12 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + parameters: [], + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), isAsynchronous: true) ]) ], classes: [ @@ -1618,7 +1716,7 @@ void main() { }); test('field generics', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Foobar', fields: [ NamedType( @@ -1633,7 +1731,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [], ); final StringBuffer sink = StringBuffer(); @@ -1661,8 +1759,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -1724,8 +1822,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -1784,8 +1882,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -1837,7 +1935,7 @@ void main() { typeArguments: [ TypeDeclaration(baseName: 'int', isNullable: true) ]), - arguments: []) + parameters: []) ]) ], classes: [], @@ -1894,7 +1992,7 @@ void main() { typeArguments: [ TypeDeclaration(baseName: 'int', isNullable: true) ]), - arguments: []) + parameters: []) ]) ], classes: [], @@ -1945,12 +2043,12 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'add', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'x', type: const TypeDeclaration(isNullable: false, baseName: 'int')), - NamedType( + Parameter( name: 'y', type: const TypeDeclaration(isNullable: false, baseName: 'int')), @@ -2015,12 +2113,12 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'add', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'x', type: const TypeDeclaration(isNullable: false, baseName: 'int')), - NamedType( + Parameter( name: 'y', type: const TypeDeclaration(isNullable: false, baseName: 'int')), @@ -2085,12 +2183,12 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'add', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'x', type: const TypeDeclaration(isNullable: false, baseName: 'int')), - NamedType( + Parameter( name: 'y', type: const TypeDeclaration(isNullable: false, baseName: 'int')), @@ -2151,13 +2249,13 @@ void main() { Method( name: 'divide', objcSelector: 'divideValue:by:', - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'int', isNullable: false), name: 'x', ), - NamedType( + Parameter( type: const TypeDeclaration( baseName: 'int', isNullable: false), name: 'y', @@ -2287,7 +2385,7 @@ void main() { baseName: 'int', isNullable: true, ), - arguments: []) + parameters: []) ]) ], classes: [], @@ -2323,7 +2421,7 @@ void main() { baseName: 'int', isNullable: true, ), - arguments: []) + parameters: []) ]) ], classes: [], @@ -2356,7 +2454,7 @@ void main() { baseName: 'int', isNullable: true, ), - arguments: []) + parameters: []) ]) ], classes: [], @@ -2386,8 +2484,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'foo', type: const TypeDeclaration( baseName: 'int', @@ -2443,8 +2541,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'foo', type: const TypeDeclaration( baseName: 'int', @@ -2502,7 +2600,7 @@ void main() { baseName: 'int', isNullable: true, ), - arguments: [], + parameters: [], taskQueueType: TaskQueueType.serialBackgroundThread) ]) ], @@ -2555,8 +2653,8 @@ void main() { name: 'method', returnType: const TypeDeclaration.voidDeclaration(), documentationComments: [comments[count++]], - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'field', type: const TypeDeclaration( baseName: 'int', @@ -2634,8 +2732,8 @@ void main() { Method( name: 'method', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'field', type: const TypeDeclaration( baseName: 'int', @@ -2672,16 +2770,20 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), isAsynchronous: true, ) ]) @@ -2730,8 +2832,8 @@ void main() { Method( name: 'method', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'field', type: const TypeDeclaration( baseName: 'int', diff --git a/packages/pigeon/test/pigeon_lib_test.dart b/packages/pigeon/test/pigeon_lib_test.dart index bf6e0ba33f5..dc0f6061e37 100644 --- a/packages/pigeon/test/pigeon_lib_test.dart +++ b/packages/pigeon/test/pigeon_lib_test.dart @@ -174,18 +174,18 @@ abstract class Api1 { expect(root.apis[0].name, equals('Api1')); expect(root.apis[0].methods.length, equals(1)); expect(root.apis[0].methods[0].name, equals('doit')); - expect(root.apis[0].methods[0].arguments[0].name, equals('input')); + expect(root.apis[0].methods[0].parameters[0].name, equals('input')); expect( - root.apis[0].methods[0].arguments[0].type.baseName, equals('Input1')); + root.apis[0].methods[0].parameters[0].type.baseName, equals('Input1')); expect(root.apis[0].methods[0].returnType.baseName, equals('Output1')); Class? input; Class? output; - for (final Class klass in root.classes) { - if (klass.name == 'Input1') { - input = klass; - } else if (klass.name == 'Output1') { - output = klass; + for (final Class classDefinition in root.classes) { + if (classDefinition.name == 'Input1') { + input = classDefinition; + } else if (classDefinition.name == 'Output1') { + output = classDefinition; } } expect(input, isNotNull); @@ -353,7 +353,7 @@ abstract class VoidArgApi { expect(results.root.apis[0].name, equals('VoidArgApi')); expect( results.root.apis[0].methods[0].returnType.baseName, equals('Output1')); - expect(results.root.apis[0].methods[0].arguments.isEmpty, isTrue); + expect(results.root.apis[0].methods[0].parameters.isEmpty, isTrue); }); test('mockDartClass', () { @@ -743,7 +743,7 @@ abstract class Api { final ParseResults parseResult = parseSource(code); expect(parseResult.errors.length, equals(1)); expect(parseResult.errors[0].message, - contains('Generic type arguments must be nullable')); + contains('Generic type parameters must be nullable')); expect(parseResult.errors[0].message, contains('"list"')); expect(parseResult.errors[0].lineNumber, 2); }); @@ -864,14 +864,14 @@ abstract class Api { } '''; final ParseResults parseResult = parseSource(code); + expect(parseResult.root.apis[0].methods[0].parameters[1].type.baseName, + 'List'); expect( - parseResult.root.apis[0].methods[0].arguments[1].type.baseName, 'List'); - expect( - parseResult.root.apis[0].methods[0].arguments[1].type.typeArguments[0] + parseResult.root.apis[0].methods[0].parameters[1].type.typeArguments[0] .baseName, 'double'); expect( - parseResult.root.apis[0].methods[0].arguments[1].type.typeArguments[0] + parseResult.root.apis[0].methods[0].parameters[1].type.typeArguments[0] .isNullable, isTrue); }); @@ -894,7 +894,7 @@ abstract class Api { expect(field.type.typeArguments[1].baseName, 'int'); }); - test('two arguments', () { + test('two parameters', () { const String code = ''' class Input { String? input; @@ -909,7 +909,7 @@ abstract class Api { 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].arguments.length, 2); + expect(results.root.apis[0].methods[0].parameters.length, 2); }); test('no type name argument', () { @@ -923,7 +923,7 @@ abstract class Api { expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 3); expect(results.errors[0].message, - contains('Arguments must specify their type')); + contains('Parameters must specify their type')); }); test('custom objc selector', () { @@ -954,10 +954,10 @@ abstract class Api { expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 3); expect(results.errors[0].message, - contains('Invalid selector, expected 2 arguments')); + contains('Invalid selector, expected 2 parameters')); }); - test('custom objc no arguments', () { + test('custom objc no parameters', () { const String code = ''' @HostApi() abstract class Api { @@ -1000,10 +1000,10 @@ abstract class Api { expect(results.errors.length, 1); expect(results.errors[0].lineNumber, 3); expect(results.errors[0].message, - contains('Invalid function signature, expected 2 arguments')); + contains('Invalid function signature, expected 2 parameters')); }); - test('custom swift function signature no arguments', () { + test('custom swift function signature no parameters', () { const String code = ''' @HostApi() abstract class Api { @@ -1066,7 +1066,7 @@ abstract class Api { expect(results.root.classes[0].name, 'Foo'); }); - test('recurse into type arguments', () { + test('recurse into type parameters', () { const String code = ''' class Foo { int? foo; @@ -1234,7 +1234,7 @@ abstract class Api { final ParseResults results = parseSource(code); expect(results.errors.length, 0); expect( - results.root.apis[0].methods[0].arguments[0].type.isNullable, isTrue); + results.root.apis[0].methods[0].parameters[0].type.isNullable, isTrue); }); test('task queue specified', () { diff --git a/packages/pigeon/test/swift_generator_test.dart b/packages/pigeon/test/swift_generator_test.dart index 622b51b6ec3..4c07b784eb7 100644 --- a/packages/pigeon/test/swift_generator_test.dart +++ b/packages/pigeon/test/swift_generator_test.dart @@ -8,9 +8,21 @@ import 'package:test/test.dart'; import 'dart_generator_test.dart'; +final Class emptyClass = Class(name: 'className', fields: [ + NamedType( + name: 'namedTypeName', + type: const TypeDeclaration(baseName: 'baseName', isNullable: false), + ) +]); + +final Enum emptyEnum = Enum( + name: 'enumName', + members: [EnumMember(name: 'enumMemberName')], +); + void main() { test('gen one class', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Foobar', fields: [ NamedType( @@ -23,7 +35,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [], ); final StringBuffer sink = StringBuffer(); @@ -76,11 +88,14 @@ void main() { Method( name: 'bar', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'foo', - type: - const TypeDeclaration(baseName: 'Foo', isNullable: false)) + type: TypeDeclaration( + baseName: 'Foo', + associatedEnum: emptyEnum, + isNullable: false, + )) ]) ]) ], classes: [], enums: [ @@ -108,16 +123,20 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), ) ]) ], classes: [ @@ -232,16 +251,20 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), ) ]) ], classes: [ @@ -282,10 +305,11 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') @@ -322,10 +346,11 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') @@ -363,9 +388,12 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + parameters: [], + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), ) ]) ], classes: [ @@ -398,9 +426,12 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + parameters: [], + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), ) ]) ], classes: [ @@ -481,12 +512,13 @@ void main() { }); test('gen nested', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Outer', fields: [ NamedType( - type: const TypeDeclaration( + type: TypeDeclaration( baseName: 'Nested', + associatedClass: emptyClass, isNullable: true, ), name: 'nested') @@ -505,7 +537,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass, nestedClass], + classes: [classDefinition, nestedClass], enums: [], ); final StringBuffer sink = StringBuffer(); @@ -531,16 +563,20 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: 'arg') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), isAsynchronous: true, ) ]) @@ -582,16 +618,20 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), isAsynchronous: true, ) ]) @@ -635,12 +675,13 @@ void main() { EnumMember(name: 'two'), ], ); - final Class klass = Class( + final Class classDefinition = Class( name: 'EnumClass', fields: [ NamedType( - type: const TypeDeclaration( + type: TypeDeclaration( baseName: 'Enum1', + associatedEnum: emptyEnum, isNullable: true, ), name: 'enum1'), @@ -648,7 +689,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [anEnum], ); final StringBuffer sink = StringBuffer(); @@ -688,7 +729,7 @@ void main() { }); test('generics - list', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Foobar', fields: [ NamedType( @@ -703,7 +744,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [], ); final StringBuffer sink = StringBuffer(); @@ -721,7 +762,7 @@ void main() { }); test('generics - maps', () { - final Class klass = Class( + final Class classDefinition = Class( name: 'Foobar', fields: [ NamedType( @@ -737,7 +778,7 @@ void main() { ); final Root root = Root( apis: [], - classes: [klass], + classes: [classDefinition], enums: [], ); final StringBuffer sink = StringBuffer(); @@ -761,8 +802,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -796,8 +837,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'List', isNullable: false, @@ -836,7 +877,7 @@ void main() { typeArguments: [ TypeDeclaration(baseName: 'int', isNullable: true) ]), - arguments: []) + parameters: []) ]) ], classes: [], @@ -869,7 +910,7 @@ void main() { typeArguments: [ TypeDeclaration(baseName: 'int', isNullable: true) ]), - arguments: []) + parameters: []) ]) ], classes: [], @@ -898,12 +939,12 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'add', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'x', type: const TypeDeclaration(isNullable: false, baseName: 'int')), - NamedType( + Parameter( name: 'y', type: const TypeDeclaration(isNullable: false, baseName: 'int')), @@ -941,12 +982,12 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'add', - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'x', type: const TypeDeclaration(baseName: 'int', isNullable: false)), - NamedType( + Parameter( name: 'y', type: const TypeDeclaration(baseName: 'int', isNullable: false)), @@ -989,7 +1030,7 @@ void main() { baseName: 'int', isNullable: true, ), - arguments: []) + parameters: []) ]) ], classes: [], @@ -1019,7 +1060,7 @@ void main() { isNullable: true, ), isAsynchronous: true, - arguments: []) + parameters: []) ]) ], classes: [], @@ -1048,8 +1089,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'foo', type: const TypeDeclaration( baseName: 'int', @@ -1084,8 +1125,8 @@ void main() { Method( name: 'doit', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'foo', type: const TypeDeclaration( baseName: 'int', @@ -1118,10 +1159,11 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') @@ -1177,8 +1219,8 @@ void main() { name: 'method', returnType: const TypeDeclaration.voidDeclaration(), documentationComments: [comments[count++]], - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'field', type: const TypeDeclaration( baseName: 'int', @@ -1252,8 +1294,8 @@ void main() { Method( name: 'method', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'field', type: const TypeDeclaration( baseName: 'int', @@ -1286,16 +1328,20 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doSomething', - arguments: [ - NamedType( - type: const TypeDeclaration( + parameters: [ + Parameter( + type: TypeDeclaration( baseName: 'Input', + associatedClass: emptyClass, isNullable: false, ), name: '') ], - returnType: - const TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: TypeDeclaration( + baseName: 'Output', + associatedClass: emptyClass, + isNullable: false, + ), isAsynchronous: true, ) ]) @@ -1336,15 +1382,15 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'set', - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'int', isNullable: false, ), name: 'value', ), - NamedType( + Parameter( type: const TypeDeclaration( baseName: 'String', isNullable: false, @@ -1379,8 +1425,8 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'set', - arguments: [ - NamedType( + parameters: [ + Parameter( type: const TypeDeclaration( baseName: 'String', isNullable: false, @@ -1415,7 +1461,7 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'clear', - arguments: [], + parameters: [], swiftFunction: 'removeAll()', returnType: const TypeDeclaration.voidDeclaration(), ) @@ -1447,8 +1493,8 @@ void main() { Method( name: 'method', returnType: const TypeDeclaration.voidDeclaration(), - arguments: [ - NamedType( + parameters: [ + Parameter( name: 'field', type: const TypeDeclaration( baseName: 'int',