From 9ec97b1245d6c684bfaade2f1e99d0bd43fad9e3 Mon Sep 17 00:00:00 2001 From: Tarrin Neal Date: Mon, 6 May 2024 04:55:21 -0700 Subject: [PATCH] Fix unnecessary toList/fromList calls during encode/decode process (#6426) Fix unnecessary toList/fromList calls during encode/decode process. also makes some kotlin code more idiomatic. removes the ability to have collisions with the name `list`. fixes https://github.com/flutter/flutter/issues/119351 --- packages/pigeon/CHANGELOG.md | 6 + .../java/io/flutter/plugins/Messages.java | 10 +- .../flutter/pigeon_example_app/Messages.g.kt | 50 +- .../example/app/ios/Runner/Messages.g.swift | 11 +- packages/pigeon/lib/ast.dart | 2 +- packages/pigeon/lib/cpp_generator.dart | 63 +- packages/pigeon/lib/dart_generator.dart | 73 +- packages/pigeon/lib/generator_tools.dart | 8 +- packages/pigeon/lib/java_generator.dart | 11 +- packages/pigeon/lib/kotlin_generator.dart | 71 +- packages/pigeon/lib/objc_generator.dart | 19 +- packages/pigeon/lib/swift_generator.dart | 68 +- packages/pigeon/pigeons/core_tests.dart | 28 +- .../AlternateLanguageTestPlugin.java | 76 +- .../CoreTests.java | 222 +++--- .../AllDatatypesTest.java | 4 +- .../NullFieldsTest.java | 41 +- .../example/ios/RunnerTests/NullFieldsTest.m | 25 +- .../ios/Classes/AlternateLanguageTestPlugin.m | 28 +- .../ios/Classes/CoreTests.gen.h | 26 +- .../ios/Classes/CoreTests.gen.m | 72 +- .../Classes/AlternateLanguageTestPlugin.m | 28 +- .../macos/Classes/CoreTests.gen.h | 26 +- .../macos/Classes/CoreTests.gen.m | 72 +- .../lib/integration_tests.dart | 12 +- .../lib/src/generated/core_tests.gen.dart | 87 ++- .../lib/src/generated/message.gen.dart | 6 +- .../src/generated/non_null_fields.gen.dart | 4 +- .../lib/src/generated/null_fields.gen.dart | 6 +- .../test/null_fields_test.dart | 30 +- .../com/example/test_plugin/CoreTests.gen.kt | 683 +++++++++--------- .../com/example/test_plugin/TestPlugin.kt | 28 +- .../example/test_plugin/AllDatatypesTest.kt | 2 +- .../ios/Classes/CoreTests.gen.swift | 220 +++--- .../test_plugin/ios/Classes/TestPlugin.swift | 28 +- .../macos/Classes/CoreTests.gen.swift | 220 +++--- .../macos/Classes/TestPlugin.swift | 28 +- .../test_plugin/windows/CMakeLists.txt | 8 + .../windows/pigeon/core_tests.gen.cpp | 125 ++-- .../windows/pigeon/core_tests.gen.h | 30 +- .../windows/test/null_fields_test.cpp | 17 +- packages/pigeon/pubspec.yaml | 2 +- packages/pigeon/test/cpp_generator_test.dart | 13 +- packages/pigeon/test/dart_generator_test.dart | 12 +- packages/pigeon/test/java_generator_test.dart | 6 +- .../pigeon/test/kotlin_generator_test.dart | 42 +- packages/pigeon/test/objc_generator_test.dart | 8 +- .../pigeon/test/swift_generator_test.dart | 9 +- 48 files changed, 1309 insertions(+), 1357 deletions(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index fb01483089c5..59a4bd93380a 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,9 @@ +## 18.0.1 + +* Fixes unnecessary calls of `toList` and `fromList` when encoding/decoding data classes. +* [kotlin] Changes to some code to make it more idiomatic. +* Removes collisions with the word `list`. + ## 18.0.0 * Adds message channel suffix option to all APIs. diff --git a/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java b/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java index 897f40e9beed..f8029ebcd923 100644 --- a/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java +++ b/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java @@ -186,15 +186,15 @@ ArrayList toList() { return toListResult; } - static @NonNull MessageData fromList(@NonNull ArrayList list) { + static @NonNull MessageData fromList(@NonNull ArrayList __pigeon_list) { MessageData pigeonResult = new MessageData(); - Object name = list.get(0); + Object name = __pigeon_list.get(0); pigeonResult.setName((String) name); - Object description = list.get(1); + Object description = __pigeon_list.get(1); pigeonResult.setDescription((String) description); - Object code = list.get(2); + Object code = __pigeon_list.get(2); pigeonResult.setCode(Code.values()[(int) code]); - Object data = list.get(3); + Object data = __pigeon_list.get(3); pigeonResult.setData((Map) data); return pigeonResult; } diff --git a/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt b/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt index 350895738d62..48981666f24b 100644 --- a/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt +++ b/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt @@ -3,6 +3,7 @@ // found in the LICENSE file. // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon +@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass") import android.util.Log import io.flutter.plugin.common.BasicMessageChannel @@ -17,10 +18,10 @@ private fun wrapResult(result: Any?): List { } private fun wrapError(exception: Throwable): List { - if (exception is FlutterError) { - return listOf(exception.code, exception.message, exception.details) + return if (exception is FlutterError) { + listOf(exception.code, exception.message, exception.details) } else { - return listOf( + listOf( exception.javaClass.simpleName, exception.toString(), "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception)) @@ -64,12 +65,12 @@ data class MessageData( val data: Map ) { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): MessageData { - val name = list[0] as String? - val description = list[1] as String? - val code = Code.ofRaw(list[2] as Int)!! - val data = list[3] as Map + @Suppress("LocalVariableName") + fun fromList(__pigeon_list: List): MessageData { + val name = __pigeon_list[0] as String? + val description = __pigeon_list[1] as String? + val code = Code.ofRaw(__pigeon_list[2] as Int)!! + val data = __pigeon_list[3] as Map return MessageData(name, description, code, data) } } @@ -84,7 +85,6 @@ data class MessageData( } } -@Suppress("UNCHECKED_CAST") private object ExampleHostApiCodec : StandardMessageCodec() { override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { return when (type) { @@ -118,7 +118,6 @@ interface ExampleHostApi { /** The codec used by ExampleHostApi. */ val codec: MessageCodec by lazy { ExampleHostApiCodec } /** Sets up an instance of `ExampleHostApi` to handle messages through the `binaryMessenger`. */ - @Suppress("UNCHECKED_CAST") fun setUp( binaryMessenger: BinaryMessenger, api: ExampleHostApi?, @@ -134,12 +133,12 @@ interface ExampleHostApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - var wrapped: List - try { - wrapped = listOf(api.getHostLanguage()) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.getHostLanguage()) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -155,14 +154,14 @@ interface ExampleHostApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val aArg = args[0].let { if (it is Int) it.toLong() else it as Long } - val bArg = args[1].let { if (it is Int) it.toLong() else it as Long } - var wrapped: List - try { - wrapped = listOf(api.add(aArg, bArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val aArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long } + val bArg = args[1].let { num -> if (num is Int) num.toLong() else num as Long } + val wrapped: List = + try { + listOf(api.add(aArg, bArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -197,7 +196,6 @@ interface ExampleHostApi { } } /** Generated class from Pigeon that represents Flutter messages that can be called from Kotlin. */ -@Suppress("UNCHECKED_CAST") class MessageFlutterApi( private val binaryMessenger: BinaryMessenger, private val messageChannelSuffix: String = "" diff --git a/packages/pigeon/example/app/ios/Runner/Messages.g.swift b/packages/pigeon/example/app/ios/Runner/Messages.g.swift index 313c1974e024..7155583cfab3 100644 --- a/packages/pigeon/example/app/ios/Runner/Messages.g.swift +++ b/packages/pigeon/example/app/ios/Runner/Messages.g.swift @@ -60,11 +60,12 @@ struct MessageData { var code: Code var data: [String?: String?] - static func fromList(_ list: [Any?]) -> MessageData? { - let name: String? = nilOrValue(list[0]) - let description: String? = nilOrValue(list[1]) - let code = Code(rawValue: list[2] as! Int)! - let data = list[3] as! [String?: String?] + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> MessageData? { + let name: String? = nilOrValue(__pigeon_list[0]) + let description: String? = nilOrValue(__pigeon_list[1]) + let code = Code(rawValue: __pigeon_list[2] as! Int)! + let data = __pigeon_list[3] as! [String?: String?] return MessageData( name: name, diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index 08eef8cc6c7c..d7bc2139729f 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -518,7 +518,7 @@ class TypeDeclaration { @override String toString() { final String typeArgumentsStr = - typeArguments.isEmpty ? '' : 'typeArguments:$typeArguments'; + typeArguments.isEmpty ? '' : ' typeArguments:$typeArguments'; return '(TypeDeclaration baseName:$baseName isNullable:$isNullable$typeArgumentsStr isEnum:$isEnum isClass:$isClass isProxyApi:$isProxyApi)'; } } diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index 92d6fd56d1fc..00a156b0c5db 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -787,8 +787,12 @@ class CppSourceGenerator extends StructuredGenerator { final HostDatatype hostDatatype = getFieldHostDatatype(field, _shortBaseCppTypeForBuiltinDartType); final String encodableValue = _wrappedHostApiArgumentExpression( - root, _makeInstanceVariableName(field), field.type, hostDatatype, - preSerializeClasses: true); + root, + _makeInstanceVariableName(field), + field.type, + hostDatatype, + true, + ); indent.writeln('list.push_back($encodableValue);'); } indent.writeln('return list;'); @@ -815,11 +819,8 @@ class CppSourceGenerator extends StructuredGenerator { } else { final HostDatatype hostDatatype = getFieldHostDatatype(field, _shortBaseCppTypeForBuiltinDartType); - if (!hostDatatype.isBuiltin && - root.classes - .map((Class x) => x.name) - .contains(field.type.baseName)) { - return '${hostDatatype.datatype}::FromEncodableList(std::get($encodable))'; + if (field.type.isClass) { + return _classReferenceFromEncodableValue(hostDatatype, encodable); } else { return 'std::get<${hostDatatype.datatype}>($encodable)'; } @@ -960,8 +961,12 @@ class CppSourceGenerator extends StructuredGenerator { indent.addScoped('EncodableValue(EncodableList{', '});', () { for (final _HostNamedType param in hostParameters) { final String encodedArgument = _wrappedHostApiArgumentExpression( - root, param.name, param.originalType, param.hostType, - preSerializeClasses: false); + root, + param.name, + param.originalType, + param.hostType, + false, + ); indent.writeln('$encodedArgument,'); } }); @@ -1452,27 +1457,20 @@ ${prefix}reply(EncodableValue(std::move(wrapped)));'''; /// Returns the expression to create an EncodableValue from a host API argument /// with the given [variableName] and types. - /// - /// If [preSerializeClasses] is true, custom classes will be returned as - /// encodable lists rather than CustomEncodableValues; see - /// https://github.com/flutter/flutter/issues/119351 for why this is currently - /// needed. - String _wrappedHostApiArgumentExpression(Root root, String variableName, - TypeDeclaration dartType, HostDatatype hostType, - {required bool preSerializeClasses}) { + String _wrappedHostApiArgumentExpression( + Root root, + String variableName, + TypeDeclaration dartType, + HostDatatype hostType, + bool isNestedClass, + ) { final String encodableValue; if (!hostType.isBuiltin && root.classes.any((Class c) => c.name == dartType.baseName)) { - if (preSerializeClasses) { - final String operator = - hostType.isNullable || _isPointerField(hostType) ? '->' : '.'; - encodableValue = - 'EncodableValue($variableName${operator}ToEncodableList())'; - } else { - final String nonNullValue = - hostType.isNullable ? '*$variableName' : variableName; - encodableValue = 'CustomEncodableValue($nonNullValue)'; - } + final String nonNullValue = hostType.isNullable || isNestedClass + ? '*$variableName' + : variableName; + encodableValue = 'CustomEncodableValue($nonNullValue)'; } else if (!hostType.isBuiltin && root.enums.any((Enum e) => e.name == dartType.baseName)) { final String nonNullValue = @@ -1537,7 +1535,7 @@ ${prefix}reply(EncodableValue(std::move(wrapped)));'''; } } else { indent.writeln( - 'const auto* $argName = &(std::any_cast(std::get($encodableArgName)));'); + 'const auto* $argName = &(${_classReferenceFromEncodableValue(hostType, encodableArgName)});'); } } else { // Non-nullable arguments are either passed by value or reference, but the @@ -1562,7 +1560,7 @@ ${prefix}reply(EncodableValue(std::move(wrapped)));'''; 'const ${hostType.datatype}& $argName = (${hostType.datatype})$encodableArgName.LongValue();'); } else { indent.writeln( - 'const auto& $argName = std::any_cast(std::get($encodableArgName));'); + 'const auto& $argName = ${_classReferenceFromEncodableValue(hostType, encodableArgName)};'); } } } @@ -1573,6 +1571,13 @@ ${prefix}reply(EncodableValue(std::move(wrapped)));'''; String? _shortBaseCppTypeForBuiltinDartType(TypeDeclaration type) { return _baseCppTypeForBuiltinDartType(type, includeFlutterNamespace: false); } + + /// Returns the code to extract a `const {type.datatype}&` from an EncodableValue + /// variable [variableName] that contains an instance of [type]. + String _classReferenceFromEncodableValue( + HostDatatype type, String variableName) { + return 'std::any_cast(std::get($variableName))'; + } } /// Contains information about a host function argument. diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index adc0aef5cc96..0129ae4210da 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -230,11 +230,7 @@ class DartGenerator extends StructuredGenerator { for (final NamedType field in getFieldsInSerializationOrder(classDefinition)) { final String conditional = field.type.isNullable ? '?' : ''; - if (field.type.isClass) { - indent.writeln( - '${field.name}$conditional.encode(),', - ); - } else if (field.type.isEnum) { + if (field.type.isEnum) { indent.writeln( '${field.name}$conditional.index,', ); @@ -260,18 +256,7 @@ class DartGenerator extends StructuredGenerator { final String genericType = _makeGenericTypeArguments(field.type); final String castCall = _makeGenericCastCall(field.type); final String nullableTag = field.type.isNullable ? '?' : ''; - if (field.type.isClass) { - final String nonNullValue = - '${field.type.baseName}.decode($resultAt! as List)'; - if (field.type.isNullable) { - indent.format(''' -$resultAt != null -\t\t? $nonNullValue -\t\t: null''', leadingSpace: false, trailingNewline: false); - } else { - indent.add(nonNullValue); - } - } else if (field.type.isEnum) { + if (field.type.isEnum) { final String nonNullValue = '${field.type.baseName}.values[$resultAt! as int]'; if (field.type.isNullable) { @@ -512,7 +497,7 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; // Each API has a private codec instance used by every host method, // constructor, or non-static field. - final String codecInstanceName = '${_varNamePrefix}codec${api.name}'; + final String codecInstanceName = '${varNamePrefix}codec${api.name}'; // AST class used by code_builder to generate the code. final cb.Class proxyApi = cb.Class( @@ -795,15 +780,15 @@ PlatformException _createConnectionError(String channelName) { indent.writeln( "$constOrFinal String ${_varNamePrefix}channelName = '$channelName$channelSuffix';"); indent.writeScoped( - 'final BasicMessageChannel ${_varNamePrefix}channel = BasicMessageChannel(', + 'final BasicMessageChannel ${varNamePrefix}channel = BasicMessageChannel(', ');', () { - indent.writeln('${_varNamePrefix}channelName,'); + indent.writeln('${varNamePrefix}channelName,'); indent.writeln('$_pigeonChannelCodec,'); - indent.writeln('binaryMessenger: ${_varNamePrefix}binaryMessenger,'); + indent.writeln('binaryMessenger: ${varNamePrefix}binaryMessenger,'); }); final String returnTypeName = _makeGenericTypeArguments(returnType); final String genericCastCall = _makeGenericCastCall(returnType); - const String accessor = '${_varNamePrefix}replyList[0]'; + const String accessor = '${varNamePrefix}replyList[0]'; // Avoid warnings from pointlessly casting to `Object?`. final String nullablyTypedAccessor = returnTypeName == 'Object' ? accessor @@ -826,22 +811,22 @@ PlatformException _createConnectionError(String channelName) { returnStatement = '$returnStatement;'; indent.format(''' -final List? ${_varNamePrefix}replyList = -\t\tawait ${_varNamePrefix}channel.send($sendArgument) as List?; -if (${_varNamePrefix}replyList == null) { -\tthrow _createConnectionError(${_varNamePrefix}channelName); -} else if (${_varNamePrefix}replyList.length > 1) { +final List? ${varNamePrefix}replyList = +\t\tawait ${varNamePrefix}channel.send($sendArgument) as List?; +if (${varNamePrefix}replyList == null) { +\tthrow _createConnectionError(${varNamePrefix}channelName); +} else if (${varNamePrefix}replyList.length > 1) { \tthrow PlatformException( -\t\tcode: ${_varNamePrefix}replyList[0]! as String, -\t\tmessage: ${_varNamePrefix}replyList[1] as String?, -\t\tdetails: ${_varNamePrefix}replyList[2], +\t\tcode: ${varNamePrefix}replyList[0]! as String, +\t\tmessage: ${varNamePrefix}replyList[1] as String?, +\t\tdetails: ${varNamePrefix}replyList[2], \t);'''); // On iOS we can return nil from functions to accommodate error // handling. Returning a nil value and not returning an error is an // exception. if (!returnType.isNullable && !returnType.isVoid) { indent.format(''' -} else if (${_varNamePrefix}replyList[0] == null) { +} else if (${varNamePrefix}replyList[0] == null) { \tthrow PlatformException( \t\tcode: 'null-error', \t\tmessage: 'Host platform returned null value for non-null return value.', @@ -870,7 +855,7 @@ if (${_varNamePrefix}replyList == null) { indent.write(''); indent.addScoped('{', '}', () { indent.writeln( - 'final BasicMessageChannel ${_varNamePrefix}channel = BasicMessageChannel(', + 'final BasicMessageChannel ${varNamePrefix}channel = BasicMessageChannel(', ); indent.nest(2, () { final String channelSuffix = @@ -881,8 +866,8 @@ if (${_varNamePrefix}replyList == null) { ); }); final String messageHandlerSetterWithOpeningParentheses = isMockHandler - ? '_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(${_varNamePrefix}channel, ' - : '${_varNamePrefix}channel.setMessageHandler('; + ? '_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(${varNamePrefix}channel, ' + : '${varNamePrefix}channel.setMessageHandler('; indent.write('if ($nullHandlerExpression) '); indent.addScoped('{', '}', () { indent.writeln('${messageHandlerSetterWithOpeningParentheses}null);'); @@ -1079,7 +1064,7 @@ if (${_varNamePrefix}replyList == null) { channelName: channelName, parameters: [ Parameter( - name: '${_varNamePrefix}instanceIdentifier', + name: '${varNamePrefix}instanceIdentifier', type: const TypeDeclaration( baseName: 'int', isNullable: false, @@ -1098,12 +1083,12 @@ if (${_varNamePrefix}replyList == null) { builder.statements.addAll([ const cb.Code( - 'final int ${_varNamePrefix}instanceIdentifier = $_instanceManagerVarName.addDartCreatedInstance(this);', + 'final int ${varNamePrefix}instanceIdentifier = $_instanceManagerVarName.addDartCreatedInstance(this);', ), cb.Code('final $codecName $_pigeonChannelCodec =\n' ' $codecInstanceName;'), cb.Code( - 'final BinaryMessenger? ${_varNamePrefix}binaryMessenger = ${binaryMessengerParameter.name};', + 'final BinaryMessenger? ${varNamePrefix}binaryMessenger = ${binaryMessengerParameter.name};', ), const cb.Code('() async {'), cb.Code(messageCallSink.toString()), @@ -1356,7 +1341,7 @@ if (${_varNamePrefix}replyList == null) { field.documentationComments, _docCommentSpec, )) - ..assignment = cb.Code('$_varNamePrefix${field.name}()'), + ..assignment = cb.Code('$varNamePrefix${field.name}()'), ); } } @@ -1581,11 +1566,11 @@ if (${_varNamePrefix}replyList == null) { yield cb.Method( (cb.MethodBuilder builder) { final String type = _addGenericTypesNullable(field.type); - const String instanceName = '${_varNamePrefix}instance'; + const String instanceName = '${varNamePrefix}instance'; const String identifierInstanceName = - '${_varNamePrefix}instanceIdentifier'; + '${varNamePrefix}instanceIdentifier'; builder - ..name = '$_varNamePrefix${field.name}' + ..name = '$varNamePrefix${field.name}' ..static = field.isStatic ..returns = cb.refer(type) ..body = cb.Block( @@ -1629,7 +1614,7 @@ if (${_varNamePrefix}replyList == null) { cb.Code('final $codecName $_pigeonChannelCodec =\n' ' $codecInstanceName;'), const cb.Code( - 'final BinaryMessenger? ${_varNamePrefix}binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', + 'final BinaryMessenger? ${varNamePrefix}binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', ), const cb.Code( 'final int $identifierInstanceName = $_instanceManagerVarName.addDartCreatedInstance($instanceName);', @@ -1642,7 +1627,7 @@ if (${_varNamePrefix}replyList == null) { 'final $codecName $_pigeonChannelCodec = $codecName($instanceManagerClassName.instance);', ), const cb.Code( - 'final BinaryMessenger ${_varNamePrefix}binaryMessenger = ServicesBinding.instance.defaultBinaryMessenger;', + 'final BinaryMessenger ${varNamePrefix}binaryMessenger = ServicesBinding.instance.defaultBinaryMessenger;', ), const cb.Code( 'final int $identifierInstanceName = $instanceManagerClassName.instance.addDartCreatedInstance($instanceName);', @@ -1743,7 +1728,7 @@ if (${_varNamePrefix}replyList == null) { 'final $codecName $_pigeonChannelCodec = $codecName($_instanceManagerVarName ?? $instanceManagerClassName.instance);', ), const cb.Code( - 'final BinaryMessenger? ${_varNamePrefix}binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', + 'final BinaryMessenger? ${varNamePrefix}binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', ), cb.Code(messageCallSink.toString()), ]); diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 76c9abf18865..98f27ad0fec2 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -13,7 +13,13 @@ import 'ast.dart'; /// The current version of pigeon. /// /// This must match the version in pubspec.yaml. -const String pigeonVersion = '18.0.0'; +const String pigeonVersion = '18.0.1'; + +/// Prefix for all local variables in methods. +/// +/// This lowers the chances of variable name collisions with +/// user defined parameters. +const String varNamePrefix = '__pigeon_'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/lib/java_generator.dart b/packages/pigeon/lib/java_generator.dart index 5e8fbb2c045c..f8e15bb24f9f 100644 --- a/packages/pigeon/lib/java_generator.dart +++ b/packages/pigeon/lib/java_generator.dart @@ -341,9 +341,7 @@ class JavaGenerator extends StructuredGenerator { in getFieldsInSerializationOrder(classDefinition)) { String toWriteValue = ''; final String fieldName = field.name; - if (field.type.isClass) { - toWriteValue = '($fieldName == null) ? null : $fieldName.toList()'; - } else if (field.type.isEnum) { + if (field.type.isEnum) { toWriteValue = '$fieldName == null ? null : $fieldName.index'; } else { toWriteValue = field.name; @@ -364,7 +362,7 @@ class JavaGenerator extends StructuredGenerator { }) { indent.newln(); indent.write( - 'static @NonNull ${classDefinition.name} fromList(@NonNull ArrayList list) '); + 'static @NonNull ${classDefinition.name} fromList(@NonNull ArrayList ${varNamePrefix}list) '); indent.addScoped('{', '}', () { const String result = 'pigeonResult'; indent.writeln( @@ -373,7 +371,8 @@ class JavaGenerator extends StructuredGenerator { (int index, final NamedType field) { final String fieldVariable = field.name; final String setter = _makeSetter(field); - indent.writeln('Object $fieldVariable = list.get($index);'); + indent.writeln( + 'Object $fieldVariable = ${varNamePrefix}list.get($index);'); if (field.type.isEnum) { indent.writeln( '$result.$setter(${_intToEnum(fieldVariable, field.type.baseName, field.type.isNullable)});'); @@ -1123,8 +1122,6 @@ String _castObject(NamedType field, String varName) { field, (TypeDeclaration x) => _javaTypeForBuiltinDartType(x)); if (field.type.baseName == 'int') { return '($varName == null) ? null : (($varName instanceof Integer) ? (Integer) $varName : (${hostDatatype.datatype}) $varName)'; - } 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 c81df1295ed1..18df439d740d 100644 --- a/packages/pigeon/lib/kotlin_generator.dart +++ b/packages/pigeon/lib/kotlin_generator.dart @@ -97,6 +97,7 @@ class KotlinGenerator extends StructuredGenerator { } indent.writeln('// ${getGeneratedCodeWarning()}'); indent.writeln('// $seeAlsoWarning'); + indent.writeln('@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass")'); } @override @@ -174,7 +175,6 @@ class KotlinGenerator extends StructuredGenerator { addDocumentationComments( indent, classDefinition.documentationComments, _docCommentSpec, generatorComments: generatedMessages); - indent.write('data class ${classDefinition.name} '); indent.addScoped('(', '', () { for (final NamedType element @@ -220,13 +220,10 @@ class KotlinGenerator extends StructuredGenerator { indent.addScoped('(', ')', () { 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 (field.type.isClass) { - toWriteValue = '$fieldName$safeCall.toList()'; - } else if (!hostDatatype.isBuiltin && field.type.isEnum) { + if (field.type.isEnum) { toWriteValue = '$fieldName$safeCall.raw'; } else { toWriteValue = fieldName; @@ -249,37 +246,29 @@ class KotlinGenerator extends StructuredGenerator { indent.write('companion object '); indent.addScoped('{', '}', () { - indent.writeln('@Suppress("UNCHECKED_CAST")'); - indent.write('fun fromList(list: List): $className '); + indent.writeln('@Suppress("LocalVariableName")'); + indent + .write('fun fromList(${varNamePrefix}list: List): $className '); indent.addScoped('{', '}', () { enumerate(getFieldsInSerializationOrder(classDefinition), (int index, final NamedType field) { - final String listValue = 'list[$index]'; + final String listValue = '${varNamePrefix}list[$index]'; final String fieldType = _kotlinTypeForDartType(field.type); if (field.type.isNullable) { - 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 (field.type.isEnum) { + if (field.type.isEnum) { indent.write('val ${field.name}: $fieldType? = '); indent.add('($listValue as Int?)?.let '); - indent.addScoped('{', '}', () { - indent.writeln('$fieldType.ofRaw(it)'); + indent.addScoped('{ num ->', '}', () { + indent.writeln('$fieldType.ofRaw(num)'); }); } else { indent.writeln( 'val ${field.name} = ${_cast(indent, listValue, type: field.type)}'); } } else { - if (field.type.isClass) { - indent.writeln( - 'val ${field.name} = $fieldType.fromList($listValue as List)'); - } else if (field.type.isEnum) { + if (field.type.isEnum) { indent.writeln( 'val ${field.name} = $fieldType.ofRaw($listValue as Int)!!'); } else { @@ -353,7 +342,6 @@ class KotlinGenerator extends StructuredGenerator { generatorComments: generatedMessages); final String apiName = api.name; - indent.writeln('@Suppress("UNCHECKED_CAST")'); indent.write( 'class $apiName(private val binaryMessenger: BinaryMessenger, private val messageChannelSuffix: String = "") '); indent.addScoped('{', '}', () { @@ -442,7 +430,6 @@ class KotlinGenerator extends StructuredGenerator { }); indent.writeln( '/** Sets up an instance of `$apiName` to handle messages through the `binaryMessenger`. */'); - indent.writeln('@Suppress("UNCHECKED_CAST")'); indent.write( 'fun setUp(binaryMessenger: BinaryMessenger, api: $apiName?, messageChannelSuffix: String = "") '); indent.addScoped('{', '}', () { @@ -472,7 +459,6 @@ class KotlinGenerator extends StructuredGenerator { assert(getCodecClasses(api, root).isNotEmpty); final Iterable codecClasses = getCodecClasses(api, root); final String codecName = _getCodecName(api); - indent.writeln('@Suppress("UNCHECKED_CAST")'); indent.write('private object $codecName : StandardMessageCodec() '); indent.addScoped('{', '}', () { indent.write( @@ -524,19 +510,17 @@ class KotlinGenerator extends StructuredGenerator { indent.newln(); indent.write('private fun wrapError(exception: Throwable): List '); indent.addScoped('{', '}', () { - indent - .write('if (exception is ${_getErrorClassName(generatorOptions)}) '); + indent.write( + 'return if (exception is ${_getErrorClassName(generatorOptions)}) '); indent.addScoped('{', '}', () { - indent.write('return '); - indent.addScoped('listOf(', ')', () { + indent.writeScoped('listOf(', ')', () { indent.writeln('exception.code,'); indent.writeln('exception.message,'); indent.writeln('exception.details'); }); }, addTrailingNewline: false); indent.addScoped(' else {', '}', () { - indent.write('return '); - indent.addScoped('listOf(', ')', () { + indent.writeScoped('listOf(', ')', () { indent.writeln('exception.javaClass.simpleName,'); indent.writeln('exception.toString(),'); indent.writeln( @@ -731,24 +715,22 @@ class KotlinGenerator extends StructuredGenerator { }); }); } else { - indent.writeln('var wrapped: List'); - indent.write('try '); - indent.addScoped('{', '}', () { + indent.writeScoped('val wrapped: List = try {', '}', () { if (returnType.isVoid) { indent.writeln(call); - indent.writeln('wrapped = listOf(null)'); + indent.writeln('listOf(null)'); } else { String enumTag = ''; if (returnType.isEnum) { final String safeUnwrap = returnType.isNullable ? '?' : ''; enumTag = '$safeUnwrap.raw'; } - indent.writeln('wrapped = listOf($call$enumTag)'); + indent.writeln('listOf($call$enumTag)'); } }, addTrailingNewline: false); indent.add(' catch (exception: Throwable) '); indent.addScoped('{', '}', () { - indent.writeln('wrapped = wrapError(exception)'); + indent.writeln('wrapError(exception)'); }); indent.writeln('reply.reply(wrapped)'); } @@ -839,9 +821,9 @@ class KotlinGenerator extends StructuredGenerator { const String output = 'output'; // Nullable enums require special handling. if (returnType.isEnum && returnType.isNullable) { - indent.writeScoped('val $output = (it[0] as Int?)?.let {', '}', - () { - indent.writeln('${returnType.baseName}.ofRaw(it)'); + indent.writeScoped( + 'val $output = (it[0] as Int?)?.let { num ->', '}', () { + indent.writeln('${returnType.baseName}.ofRaw(num)'); }); } else { indent.writeln( @@ -859,11 +841,6 @@ class KotlinGenerator extends StructuredGenerator { } } -HostDatatype _getHostDatatype(Root root, NamedType field) { - return getFieldHostDatatype( - field, (TypeDeclaration x) => _kotlinTypeForBuiltinDartType(x)); -} - /// Calculates the name of the codec that will be generated for [api]. String _getCodecName(Api api) => '${api.name}Codec'; @@ -971,8 +948,8 @@ String _cast(Indent indent, String variable, {required TypeDeclaration type}) { } if (type.isEnum) { if (type.isNullable) { - return '($variable as Int?)?.let {\n' - '${indent.str} $typeString.ofRaw(it)\n' + return '($variable as Int?)?.let { num ->\n' + '${indent.str} $typeString.ofRaw(num)\n' '${indent.str}}'; } return '${type.baseName}.ofRaw($variable as Int)!!'; @@ -982,5 +959,5 @@ String _cast(Indent indent, String variable, {required TypeDeclaration type}) { String _castInt(bool isNullable) { final String nullability = isNullable ? '?' : ''; - return '.let { if (it is Int) it.toLong() else it as Long$nullability }'; + return '.let { num -> if (num is Int) num.toLong() else num as Long$nullability }'; } diff --git a/packages/pigeon/lib/objc_generator.dart b/packages/pigeon/lib/objc_generator.dart index c40869a9b249..5e7784bf8ba3 100644 --- a/packages/pigeon/lib/objc_generator.dart +++ b/packages/pigeon/lib/objc_generator.dart @@ -580,8 +580,7 @@ class ObjcSourceGenerator extends StructuredGenerator { enumerate(getFieldsInSerializationOrder(classDefinition), (int index, final NamedType field) { final bool isEnumType = field.type.isEnum; - final String valueGetter = - _listGetter('list', field, index, generatorOptions.prefix); + final String valueGetter = 'GetNullableObjectAtIndex(list, $index)'; final String? primitiveExtractionMethod = _nsnumberExtractionMethod(field.type); final String ivarValueExpression; @@ -1500,22 +1499,8 @@ String _makeObjcSignature({ /// provided [options]. void generateObjcHeader(ObjcOptions options, Root root, Indent indent) {} -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'; - } - return '[$className nullableFromList:(GetNullableObjectAtIndex($list, $index))]'; - } else { - return 'GetNullableObjectAtIndex($list, $index)'; - } -} - String _arrayValue(NamedType field) { - if (field.type.isClass) { - return '(self.${field.name} ? [self.${field.name} toList] : [NSNull null])'; - } else if (field.type.isEnum) { + if (field.type.isEnum) { if (field.type.isNullable) { return '(self.${field.name} == nil ? [NSNull null] : [NSNumber numberWithInteger:self.${field.name}.value])'; } diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index 854c2c835f2f..b644e561d5e4 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -213,9 +213,7 @@ class SwiftGenerator extends StructuredGenerator { String toWriteValue = ''; final String fieldName = field.name; final String nullsafe = field.type.isNullable ? '?' : ''; - if (field.type.isClass) { - toWriteValue = '$fieldName$nullsafe.toList()'; - } else if (field.type.isEnum) { + if (field.type.isEnum) { toWriteValue = '$fieldName$nullsafe.rawValue'; } else { toWriteValue = field.name; @@ -236,12 +234,14 @@ class SwiftGenerator extends StructuredGenerator { required String dartPackageName, }) { final String className = classDefinition.name; - indent.write('static func fromList(_ list: [Any?]) -> $className? '); + indent.writeln('// swift-format-ignore: AlwaysUseLowerCamelCase'); + indent.write( + 'static func fromList(_ ${varNamePrefix}list: [Any?]) -> $className? '); indent.addScoped('{', '}', () { enumerate(getFieldsInSerializationOrder(classDefinition), (int index, final NamedType field) { - final String listValue = 'list[$index]'; + final String listValue = '${varNamePrefix}list[$index]'; _writeDecodeCasting( indent: indent, @@ -578,48 +578,23 @@ class SwiftGenerator extends StructuredGenerator { required TypeDeclaration type, }) { final String fieldType = _swiftTypeForDartType(type); - - if (type.isNullable) { - if (type.isClass) { - indent.writeln('var $variableName: $fieldType? = nil'); - indent - .write('if let ${variableName}List: [Any?] = nilOrValue($value) '); - indent.addScoped('{', '}', () { - indent.writeln( - '$variableName = $fieldType.fromList(${variableName}List)'); - }); - } else if (type.isEnum) { - indent.writeln('var $variableName: $fieldType? = nil'); + if (type.isNullable && type.isEnum) { + indent.writeln('var $variableName: $fieldType? = nil'); + indent.writeln( + 'let ${variableName}EnumVal: Int? = ${_castForceUnwrap(value, const TypeDeclaration(baseName: 'Int', isNullable: true))}'); + indent.write('if let ${variableName}RawValue = ${variableName}EnumVal '); + indent.addScoped('{', '}', () { indent.writeln( - 'let ${variableName}EnumVal: Int? = ${_castForceUnwrap(value, const TypeDeclaration(baseName: 'Int', isNullable: true))}'); - indent - .write('if let ${variableName}RawValue = ${variableName}EnumVal '); - indent.addScoped('{', '}', () { - indent.writeln( - '$variableName = $fieldType(rawValue: ${variableName}RawValue)!'); - }); - } else { - _writeGenericCasting( - indent: indent, - value: value, - variableName: variableName, - fieldType: fieldType, - type: type, - ); - } + '$variableName = $fieldType(rawValue: ${variableName}RawValue)!'); + }); } else { - if (type.isClass) { - indent.writeln( - 'let $variableName = $fieldType.fromList($value as! [Any?])!'); - } else { - _writeGenericCasting( - indent: indent, - value: value, - variableName: variableName, - fieldType: fieldType, - type: type, - ); - } + _writeGenericCasting( + indent: indent, + value: value, + variableName: variableName, + fieldType: fieldType, + type: type, + ); } } @@ -921,7 +896,8 @@ String _flattenTypeArguments(List args) { } String _swiftTypeForBuiltinGenericDartType(TypeDeclaration type) { - if (type.typeArguments.isEmpty) { + if (type.typeArguments.isEmpty || + (type.typeArguments.first.baseName == 'Object')) { if (type.baseName == 'List') { return '[Any?]'; } else if (type.baseName == 'Map') { diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index 3107bc55353f..50f8d4760140 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -23,7 +23,7 @@ class AllTypes { required this.a4ByteArray, required this.a8ByteArray, required this.aFloatArray, - this.aList = const [], + this.list = const [], this.aMap = const {}, this.anEnum = AnEnum.one, this.aString = '', @@ -38,8 +38,10 @@ class AllTypes { Int32List a4ByteArray; Int64List a8ByteArray; Float64List aFloatArray; + // This name is in a different format than the others to ensure that name + // collision with the work 'list' doesn't occur in the generated files. // ignore: always_specify_types, strict_raw_type - List aList; + List list; // ignore: always_specify_types, strict_raw_type Map aMap; AnEnum anEnum; @@ -204,7 +206,7 @@ abstract class HostIntegrationCoreApi { /// Returns the passed list, to test serialization and deserialization. @ObjCSelector('echoList:') @SwiftFunction('echo(_:)') - List echoList(List aList); + List echoList(List list); /// Returns the passed map, to test serialization and deserialization. @ObjCSelector('echoMap:') @@ -375,7 +377,7 @@ abstract class HostIntegrationCoreApi { @async @ObjCSelector('echoAsyncList:') @SwiftFunction('echoAsync(_:)') - List echoAsyncList(List aList); + List echoAsyncList(List list); /// Returns the passed map, to test asynchronous serialization and deserialization. @async @@ -462,7 +464,7 @@ abstract class HostIntegrationCoreApi { @async @ObjCSelector('echoAsyncNullableList:') @SwiftFunction('echoAsyncNullable(_:)') - List? echoAsyncNullableList(List? aList); + List? echoAsyncNullableList(List? list); /// Returns the passed map, to test asynchronous serialization and deserialization. @async @@ -543,12 +545,12 @@ abstract class HostIntegrationCoreApi { @async @ObjCSelector('callFlutterEchoUint8List:') @SwiftFunction('callFlutterEcho(_:)') - Uint8List callFlutterEchoUint8List(Uint8List aList); + Uint8List callFlutterEchoUint8List(Uint8List list); @async @ObjCSelector('callFlutterEchoList:') @SwiftFunction('callFlutterEcho(_:)') - List callFlutterEchoList(List aList); + List callFlutterEchoList(List list); @async @ObjCSelector('callFlutterEchoMap:') @@ -583,12 +585,12 @@ abstract class HostIntegrationCoreApi { @async @ObjCSelector('callFlutterEchoNullableUint8List:') @SwiftFunction('callFlutterEchoNullable(_:)') - Uint8List? callFlutterEchoNullableUint8List(Uint8List? aList); + Uint8List? callFlutterEchoNullableUint8List(Uint8List? list); @async @ObjCSelector('callFlutterEchoNullableList:') @SwiftFunction('callFlutterEchoNullable(_:)') - List? callFlutterEchoNullableList(List? aList); + List? callFlutterEchoNullableList(List? list); @async @ObjCSelector('callFlutterEchoNullableMap:') @@ -679,12 +681,12 @@ abstract class FlutterIntegrationCoreApi { /// Returns the passed byte list, to test serialization and deserialization. @ObjCSelector('echoUint8List:') @SwiftFunction('echo(_:)') - Uint8List echoUint8List(Uint8List aList); + Uint8List echoUint8List(Uint8List list); /// Returns the passed list, to test serialization and deserialization. @ObjCSelector('echoList:') @SwiftFunction('echo(_:)') - List echoList(List aList); + List echoList(List list); /// Returns the passed map, to test serialization and deserialization. @ObjCSelector('echoMap:') @@ -721,12 +723,12 @@ abstract class FlutterIntegrationCoreApi { /// Returns the passed byte list, to test serialization and deserialization. @ObjCSelector('echoNullableUint8List:') @SwiftFunction('echoNullable(_:)') - Uint8List? echoNullableUint8List(Uint8List? aList); + Uint8List? echoNullableUint8List(Uint8List? list); /// Returns the passed list, to test serialization and deserialization. @ObjCSelector('echoNullableList:') @SwiftFunction('echoNullable(_:)') - List? echoNullableList(List? aList); + List? echoNullableList(List? list); /// Returns the passed map, to test serialization and deserialization. @ObjCSelector('echoNullableMap:') 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 04f607922932..ef8c57873382 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 @@ -109,8 +109,8 @@ public void throwErrorFromVoid() { } @Override - public @NonNull List echoList(@NonNull List aList) { - return aList; + public @NonNull List echoList(@NonNull List list) { + return list; } @Override @@ -160,13 +160,11 @@ public void throwErrorFromVoid() { @Nullable Boolean aNullableBool, @Nullable Long aNullableInt, @Nullable String aNullableString) { - AllNullableTypes someThings = - new AllNullableTypes.Builder() - .setANullableBool(aNullableBool) - .setANullableInt(aNullableInt) - .setANullableString(aNullableString) - .build(); - return someThings; + return new AllNullableTypes.Builder() + .setANullableBool(aNullableBool) + .setANullableInt(aNullableInt) + .setANullableString(aNullableString) + .build(); } @Override @@ -174,13 +172,11 @@ public void throwErrorFromVoid() { @Nullable Boolean aNullableBool, @Nullable Long aNullableInt, @Nullable String aNullableString) { - AllNullableTypesWithoutRecursion someThings = - new AllNullableTypesWithoutRecursion.Builder() - .setANullableBool(aNullableBool) - .setANullableInt(aNullableInt) - .setANullableString(aNullableString) - .build(); - return someThings; + return new AllNullableTypesWithoutRecursion.Builder() + .setANullableBool(aNullableBool) + .setANullableInt(aNullableInt) + .setANullableString(aNullableString) + .build(); } @Override @@ -307,8 +303,8 @@ public void echoAsyncObject(@NonNull Object anObject, @NonNull Result re } @Override - public void echoAsyncList(@NonNull List aList, @NonNull Result> result) { - result.success(aList); + public void echoAsyncList(@NonNull List list, @NonNull Result> result) { + result.success(list); } @Override @@ -359,8 +355,8 @@ public void echoAsyncNullableObject( @Override public void echoAsyncNullableList( - @Nullable List aList, @NonNull NullableResult> result) { - result.success(aList); + @Nullable List list, @NonNull NullableResult> result) { + result.success(list); } @Override @@ -377,28 +373,33 @@ public void echoAsyncNullableEnum( @Override public void callFlutterNoop(@NonNull VoidResult result) { + assert flutterApi != null; flutterApi.noop(result); } @Override public void callFlutterThrowError(@NonNull NullableResult result) { + assert flutterApi != null; flutterApi.throwError(result); } @Override public void callFlutterThrowErrorFromVoid(@NonNull VoidResult result) { + assert flutterApi != null; flutterApi.throwErrorFromVoid(result); } @Override public void callFlutterEchoAllTypes( @NonNull AllTypes everything, @NonNull Result result) { + assert flutterApi != null; flutterApi.echoAllTypes(everything, result); } @Override public void callFlutterEchoAllNullableTypes( @Nullable AllNullableTypes everything, @NonNull NullableResult result) { + assert flutterApi != null; flutterApi.echoAllNullableTypes(everything, result); } @@ -408,6 +409,7 @@ public void callFlutterSendMultipleNullableTypes( @Nullable Long aNullableInt, @Nullable String aNullableString, @NonNull Result result) { + assert flutterApi != null; flutterApi.sendMultipleNullableTypes(aNullableBool, aNullableInt, aNullableString, result); } @@ -415,6 +417,7 @@ public void callFlutterSendMultipleNullableTypes( public void callFlutterEchoAllNullableTypesWithoutRecursion( @Nullable AllNullableTypesWithoutRecursion everything, @NonNull NullableResult result) { + assert flutterApi != null; flutterApi.echoAllNullableTypesWithoutRecursion(everything, result); } @@ -424,97 +427,114 @@ public void callFlutterSendMultipleNullableTypesWithoutRecursion( @Nullable Long aNullableInt, @Nullable String aNullableString, @NonNull Result result) { + assert flutterApi != null; flutterApi.sendMultipleNullableTypesWithoutRecursion( aNullableBool, aNullableInt, aNullableString, result); } @Override public void callFlutterEchoBool(@NonNull Boolean aBool, @NonNull Result result) { + assert flutterApi != null; flutterApi.echoBool(aBool, result); } @Override public void callFlutterEchoInt(@NonNull Long anInt, @NonNull Result result) { + assert flutterApi != null; flutterApi.echoInt(anInt, result); } @Override public void callFlutterEchoDouble(@NonNull Double aDouble, @NonNull Result result) { + assert flutterApi != null; flutterApi.echoDouble(aDouble, result); } @Override public void callFlutterEchoString(@NonNull String aString, @NonNull Result result) { + assert flutterApi != null; flutterApi.echoString(aString, result); } @Override - public void callFlutterEchoUint8List(@NonNull byte[] aList, @NonNull Result result) { - flutterApi.echoUint8List(aList, result); + public void callFlutterEchoUint8List(@NonNull byte[] list, @NonNull Result result) { + assert flutterApi != null; + flutterApi.echoUint8List(list, result); } @Override public void callFlutterEchoList( - @NonNull List aList, @NonNull Result> result) { - flutterApi.echoList(aList, result); + @NonNull List list, @NonNull Result> result) { + assert flutterApi != null; + flutterApi.echoList(list, result); } @Override public void callFlutterEchoMap( @NonNull Map aMap, @NonNull Result> result) { + assert flutterApi != null; flutterApi.echoMap(aMap, result); } @Override public void callFlutterEchoEnum(@NonNull AnEnum anEnum, @NonNull Result result) { + assert flutterApi != null; flutterApi.echoEnum(anEnum, result); } @Override public void callFlutterEchoNullableBool( @Nullable Boolean aBool, @NonNull NullableResult result) { + assert flutterApi != null; flutterApi.echoNullableBool(aBool, result); } @Override public void callFlutterEchoNullableInt( @Nullable Long anInt, @NonNull NullableResult result) { + assert flutterApi != null; flutterApi.echoNullableInt(anInt, result); } @Override public void callFlutterEchoNullableDouble( @Nullable Double aDouble, @NonNull NullableResult result) { + assert flutterApi != null; flutterApi.echoNullableDouble(aDouble, result); } @Override public void callFlutterEchoNullableString( @Nullable String aString, @NonNull NullableResult result) { + assert flutterApi != null; flutterApi.echoNullableString(aString, result); } @Override public void callFlutterEchoNullableUint8List( - @Nullable byte[] aList, @NonNull NullableResult result) { - flutterApi.echoNullableUint8List(aList, result); + @Nullable byte[] list, @NonNull NullableResult result) { + assert flutterApi != null; + flutterApi.echoNullableUint8List(list, result); } @Override public void callFlutterEchoNullableList( - @Nullable List aList, @NonNull NullableResult> result) { - flutterApi.echoNullableList(aList, result); + @Nullable List list, @NonNull NullableResult> result) { + assert flutterApi != null; + flutterApi.echoNullableList(list, result); } @Override public void callFlutterEchoNullableMap( @Nullable Map aMap, @NonNull NullableResult> result) { + assert flutterApi != null; flutterApi.echoNullableMap(aMap, result); } @Override public void callFlutterEchoNullableEnum( @Nullable AnEnum anEnum, @NonNull NullableResult result) { + assert flutterApi != null; flutterApi.echoNullableEnum(anEnum, result); } 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 1d5bde23a341..2c8f609bf783 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 @@ -198,17 +198,17 @@ public void setAFloatArray(@NonNull double[] setterArg) { this.aFloatArray = setterArg; } - private @NonNull List aList; + private @NonNull List list; - public @NonNull List getAList() { - return aList; + public @NonNull List getList() { + return list; } - public void setAList(@NonNull List setterArg) { + public void setList(@NonNull List setterArg) { if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"aList\" is null."); + throw new IllegalStateException("Nonnull field \"list\" is null."); } - this.aList = setterArg; + this.list = setterArg; } private @NonNull Map aMap; @@ -332,11 +332,11 @@ public static final class Builder { return this; } - private @Nullable List aList; + private @Nullable List list; @CanIgnoreReturnValue - public @NonNull Builder setAList(@NonNull List setterArg) { - this.aList = setterArg; + public @NonNull Builder setList(@NonNull List setterArg) { + this.list = setterArg; return this; } @@ -382,7 +382,7 @@ public static final class Builder { pigeonReturn.setA4ByteArray(a4ByteArray); pigeonReturn.setA8ByteArray(a8ByteArray); pigeonReturn.setAFloatArray(aFloatArray); - pigeonReturn.setAList(aList); + pigeonReturn.setList(list); pigeonReturn.setAMap(aMap); pigeonReturn.setAnEnum(anEnum); pigeonReturn.setAString(aString); @@ -402,7 +402,7 @@ ArrayList toList() { toListResult.add(a4ByteArray); toListResult.add(a8ByteArray); toListResult.add(aFloatArray); - toListResult.add(aList); + toListResult.add(list); toListResult.add(aMap); toListResult.add(anEnum == null ? null : anEnum.index); toListResult.add(aString); @@ -410,37 +410,37 @@ ArrayList toList() { return toListResult; } - static @NonNull AllTypes fromList(@NonNull ArrayList list) { + static @NonNull AllTypes fromList(@NonNull ArrayList __pigeon_list) { AllTypes pigeonResult = new AllTypes(); - Object aBool = list.get(0); + Object aBool = __pigeon_list.get(0); pigeonResult.setABool((Boolean) aBool); - Object anInt = list.get(1); + Object anInt = __pigeon_list.get(1); pigeonResult.setAnInt( (anInt == null) ? null : ((anInt instanceof Integer) ? (Integer) anInt : (Long) anInt)); - Object anInt64 = list.get(2); + Object anInt64 = __pigeon_list.get(2); pigeonResult.setAnInt64( (anInt64 == null) ? null : ((anInt64 instanceof Integer) ? (Integer) anInt64 : (Long) anInt64)); - Object aDouble = list.get(3); + Object aDouble = __pigeon_list.get(3); pigeonResult.setADouble((Double) aDouble); - Object aByteArray = list.get(4); + Object aByteArray = __pigeon_list.get(4); pigeonResult.setAByteArray((byte[]) aByteArray); - Object a4ByteArray = list.get(5); + Object a4ByteArray = __pigeon_list.get(5); pigeonResult.setA4ByteArray((int[]) a4ByteArray); - Object a8ByteArray = list.get(6); + Object a8ByteArray = __pigeon_list.get(6); pigeonResult.setA8ByteArray((long[]) a8ByteArray); - Object aFloatArray = list.get(7); + Object aFloatArray = __pigeon_list.get(7); pigeonResult.setAFloatArray((double[]) aFloatArray); - Object aList = list.get(8); - pigeonResult.setAList((List) aList); - Object aMap = list.get(9); + Object list = __pigeon_list.get(8); + pigeonResult.setList((List) list); + Object aMap = __pigeon_list.get(9); pigeonResult.setAMap((Map) aMap); - Object anEnum = list.get(10); + Object anEnum = __pigeon_list.get(10); pigeonResult.setAnEnum(AnEnum.values()[(int) anEnum]); - Object aString = list.get(11); + Object aString = __pigeon_list.get(11); pigeonResult.setAString((String) aString); - Object anObject = list.get(12); + Object anObject = __pigeon_list.get(12); pigeonResult.setAnObject(anObject); return pigeonResult; } @@ -803,58 +803,55 @@ ArrayList toList() { toListResult.add(aNullableEnum == null ? null : aNullableEnum.index); toListResult.add(aNullableString); toListResult.add(aNullableObject); - toListResult.add((allNullableTypes == null) ? null : allNullableTypes.toList()); + toListResult.add(allNullableTypes); return toListResult; } - static @NonNull AllNullableTypes fromList(@NonNull ArrayList list) { + static @NonNull AllNullableTypes fromList(@NonNull ArrayList __pigeon_list) { AllNullableTypes pigeonResult = new AllNullableTypes(); - Object aNullableBool = list.get(0); + Object aNullableBool = __pigeon_list.get(0); pigeonResult.setANullableBool((Boolean) aNullableBool); - Object aNullableInt = list.get(1); + Object aNullableInt = __pigeon_list.get(1); pigeonResult.setANullableInt( (aNullableInt == null) ? null : ((aNullableInt instanceof Integer) ? (Integer) aNullableInt : (Long) aNullableInt)); - Object aNullableInt64 = list.get(2); + Object aNullableInt64 = __pigeon_list.get(2); pigeonResult.setANullableInt64( (aNullableInt64 == null) ? null : ((aNullableInt64 instanceof Integer) ? (Integer) aNullableInt64 : (Long) aNullableInt64)); - Object aNullableDouble = list.get(3); + Object aNullableDouble = __pigeon_list.get(3); pigeonResult.setANullableDouble((Double) aNullableDouble); - Object aNullableByteArray = list.get(4); + Object aNullableByteArray = __pigeon_list.get(4); pigeonResult.setANullableByteArray((byte[]) aNullableByteArray); - Object aNullable4ByteArray = list.get(5); + Object aNullable4ByteArray = __pigeon_list.get(5); pigeonResult.setANullable4ByteArray((int[]) aNullable4ByteArray); - Object aNullable8ByteArray = list.get(6); + Object aNullable8ByteArray = __pigeon_list.get(6); pigeonResult.setANullable8ByteArray((long[]) aNullable8ByteArray); - Object aNullableFloatArray = list.get(7); + Object aNullableFloatArray = __pigeon_list.get(7); pigeonResult.setANullableFloatArray((double[]) aNullableFloatArray); - Object aNullableList = list.get(8); + Object aNullableList = __pigeon_list.get(8); pigeonResult.setANullableList((List) aNullableList); - Object aNullableMap = list.get(9); + Object aNullableMap = __pigeon_list.get(9); pigeonResult.setANullableMap((Map) aNullableMap); - Object nullableNestedList = list.get(10); + Object nullableNestedList = __pigeon_list.get(10); pigeonResult.setNullableNestedList((List>) nullableNestedList); - Object nullableMapWithAnnotations = list.get(11); + Object nullableMapWithAnnotations = __pigeon_list.get(11); pigeonResult.setNullableMapWithAnnotations((Map) nullableMapWithAnnotations); - Object nullableMapWithObject = list.get(12); + Object nullableMapWithObject = __pigeon_list.get(12); pigeonResult.setNullableMapWithObject((Map) nullableMapWithObject); - Object aNullableEnum = list.get(13); + Object aNullableEnum = __pigeon_list.get(13); pigeonResult.setANullableEnum( aNullableEnum == null ? null : AnEnum.values()[(int) aNullableEnum]); - Object aNullableString = list.get(14); + Object aNullableString = __pigeon_list.get(14); pigeonResult.setANullableString((String) aNullableString); - Object aNullableObject = list.get(15); + Object aNullableObject = __pigeon_list.get(15); pigeonResult.setANullableObject(aNullableObject); - Object allNullableTypes = list.get(16); - pigeonResult.setAllNullableTypes( - (allNullableTypes == null) - ? null - : AllNullableTypes.fromList((ArrayList) allNullableTypes)); + Object allNullableTypes = __pigeon_list.get(16); + pigeonResult.setAllNullableTypes((AllNullableTypes) allNullableTypes); return pigeonResult; } } @@ -1201,48 +1198,49 @@ ArrayList toList() { return toListResult; } - static @NonNull AllNullableTypesWithoutRecursion fromList(@NonNull ArrayList list) { + static @NonNull AllNullableTypesWithoutRecursion fromList( + @NonNull ArrayList __pigeon_list) { AllNullableTypesWithoutRecursion pigeonResult = new AllNullableTypesWithoutRecursion(); - Object aNullableBool = list.get(0); + Object aNullableBool = __pigeon_list.get(0); pigeonResult.setANullableBool((Boolean) aNullableBool); - Object aNullableInt = list.get(1); + Object aNullableInt = __pigeon_list.get(1); pigeonResult.setANullableInt( (aNullableInt == null) ? null : ((aNullableInt instanceof Integer) ? (Integer) aNullableInt : (Long) aNullableInt)); - Object aNullableInt64 = list.get(2); + Object aNullableInt64 = __pigeon_list.get(2); pigeonResult.setANullableInt64( (aNullableInt64 == null) ? null : ((aNullableInt64 instanceof Integer) ? (Integer) aNullableInt64 : (Long) aNullableInt64)); - Object aNullableDouble = list.get(3); + Object aNullableDouble = __pigeon_list.get(3); pigeonResult.setANullableDouble((Double) aNullableDouble); - Object aNullableByteArray = list.get(4); + Object aNullableByteArray = __pigeon_list.get(4); pigeonResult.setANullableByteArray((byte[]) aNullableByteArray); - Object aNullable4ByteArray = list.get(5); + Object aNullable4ByteArray = __pigeon_list.get(5); pigeonResult.setANullable4ByteArray((int[]) aNullable4ByteArray); - Object aNullable8ByteArray = list.get(6); + Object aNullable8ByteArray = __pigeon_list.get(6); pigeonResult.setANullable8ByteArray((long[]) aNullable8ByteArray); - Object aNullableFloatArray = list.get(7); + Object aNullableFloatArray = __pigeon_list.get(7); pigeonResult.setANullableFloatArray((double[]) aNullableFloatArray); - Object aNullableList = list.get(8); + Object aNullableList = __pigeon_list.get(8); pigeonResult.setANullableList((List) aNullableList); - Object aNullableMap = list.get(9); + Object aNullableMap = __pigeon_list.get(9); pigeonResult.setANullableMap((Map) aNullableMap); - Object nullableNestedList = list.get(10); + Object nullableNestedList = __pigeon_list.get(10); pigeonResult.setNullableNestedList((List>) nullableNestedList); - Object nullableMapWithAnnotations = list.get(11); + Object nullableMapWithAnnotations = __pigeon_list.get(11); pigeonResult.setNullableMapWithAnnotations((Map) nullableMapWithAnnotations); - Object nullableMapWithObject = list.get(12); + Object nullableMapWithObject = __pigeon_list.get(12); pigeonResult.setNullableMapWithObject((Map) nullableMapWithObject); - Object aNullableEnum = list.get(13); + Object aNullableEnum = __pigeon_list.get(13); pigeonResult.setANullableEnum( aNullableEnum == null ? null : AnEnum.values()[(int) aNullableEnum]); - Object aNullableString = list.get(14); + Object aNullableString = __pigeon_list.get(14); pigeonResult.setANullableString((String) aNullableString); - Object aNullableObject = list.get(15); + Object aNullableObject = __pigeon_list.get(15); pigeonResult.setANullableObject(aNullableObject); return pigeonResult; } @@ -1334,31 +1332,21 @@ public static final class Builder { @NonNull ArrayList toList() { ArrayList toListResult = new ArrayList(3); - toListResult.add((allNullableTypes == null) ? null : allNullableTypes.toList()); - toListResult.add( - (allNullableTypesWithoutRecursion == null) - ? null - : allNullableTypesWithoutRecursion.toList()); - toListResult.add((allTypes == null) ? null : allTypes.toList()); + toListResult.add(allNullableTypes); + toListResult.add(allNullableTypesWithoutRecursion); + toListResult.add(allTypes); return toListResult; } - static @NonNull AllClassesWrapper fromList(@NonNull ArrayList list) { + static @NonNull AllClassesWrapper fromList(@NonNull ArrayList __pigeon_list) { AllClassesWrapper pigeonResult = new AllClassesWrapper(); - Object allNullableTypes = list.get(0); - pigeonResult.setAllNullableTypes( - (allNullableTypes == null) - ? null - : AllNullableTypes.fromList((ArrayList) allNullableTypes)); - Object allNullableTypesWithoutRecursion = list.get(1); + Object allNullableTypes = __pigeon_list.get(0); + pigeonResult.setAllNullableTypes((AllNullableTypes) allNullableTypes); + Object allNullableTypesWithoutRecursion = __pigeon_list.get(1); pigeonResult.setAllNullableTypesWithoutRecursion( - (allNullableTypesWithoutRecursion == null) - ? null - : AllNullableTypesWithoutRecursion.fromList( - (ArrayList) allNullableTypesWithoutRecursion)); - Object allTypes = list.get(2); - pigeonResult.setAllTypes( - (allTypes == null) ? null : AllTypes.fromList((ArrayList) allTypes)); + (AllNullableTypesWithoutRecursion) allNullableTypesWithoutRecursion); + Object allTypes = __pigeon_list.get(2); + pigeonResult.setAllTypes((AllTypes) allTypes); return pigeonResult; } } @@ -1403,9 +1391,9 @@ ArrayList toList() { return toListResult; } - static @NonNull TestMessage fromList(@NonNull ArrayList list) { + static @NonNull TestMessage fromList(@NonNull ArrayList __pigeon_list) { TestMessage pigeonResult = new TestMessage(); - Object testList = list.get(0); + Object testList = __pigeon_list.get(0); pigeonResult.setTestList((List) testList); return pigeonResult; } @@ -1524,7 +1512,7 @@ public interface HostIntegrationCoreApi { Object echoObject(@NonNull Object anObject); /** Returns the passed list, to test serialization and deserialization. */ @NonNull - List echoList(@NonNull List aList); + List echoList(@NonNull List list); /** Returns the passed map, to test serialization and deserialization. */ @NonNull Map echoMap(@NonNull Map aMap); @@ -1623,7 +1611,7 @@ AllNullableTypesWithoutRecursion sendMultipleNullableTypesWithoutRecursion( /** Returns the passed in generic Object asynchronously. */ void echoAsyncObject(@NonNull Object anObject, @NonNull Result result); /** Returns the passed list, to test asynchronous serialization and deserialization. */ - void echoAsyncList(@NonNull List aList, @NonNull Result> result); + void echoAsyncList(@NonNull List list, @NonNull Result> result); /** Returns the passed map, to test asynchronous serialization and deserialization. */ void echoAsyncMap( @NonNull Map aMap, @NonNull Result> result); @@ -1659,7 +1647,7 @@ void echoAsyncNullableUint8List( void echoAsyncNullableObject(@Nullable Object anObject, @NonNull NullableResult result); /** Returns the passed list, to test asynchronous serialization and deserialization. */ void echoAsyncNullableList( - @Nullable List aList, @NonNull NullableResult> result); + @Nullable List list, @NonNull NullableResult> result); /** Returns the passed map, to test asynchronous serialization and deserialization. */ void echoAsyncNullableMap( @Nullable Map aMap, @NonNull NullableResult> result); @@ -1701,9 +1689,9 @@ void callFlutterSendMultipleNullableTypesWithoutRecursion( void callFlutterEchoString(@NonNull String aString, @NonNull Result result); - void callFlutterEchoUint8List(@NonNull byte[] aList, @NonNull Result result); + void callFlutterEchoUint8List(@NonNull byte[] list, @NonNull Result result); - void callFlutterEchoList(@NonNull List aList, @NonNull Result> result); + void callFlutterEchoList(@NonNull List list, @NonNull Result> result); void callFlutterEchoMap( @NonNull Map aMap, @NonNull Result> result); @@ -1722,10 +1710,10 @@ void callFlutterEchoNullableString( @Nullable String aString, @NonNull NullableResult result); void callFlutterEchoNullableUint8List( - @Nullable byte[] aList, @NonNull NullableResult result); + @Nullable byte[] list, @NonNull NullableResult result); void callFlutterEchoNullableList( - @Nullable List aList, @NonNull NullableResult> result); + @Nullable List list, @NonNull NullableResult> result); void callFlutterEchoNullableMap( @Nullable Map aMap, @NonNull NullableResult> result); @@ -2043,9 +2031,9 @@ static void setUp( (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - List aListArg = (List) args.get(0); + List listArg = (List) args.get(0); try { - List output = api.echoList(aListArg); + List output = api.echoList(listArg); wrapped.add(0, output); } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); @@ -2908,7 +2896,7 @@ public void error(Throwable error) { (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - List aListArg = (List) args.get(0); + List listArg = (List) args.get(0); Result> resultCallback = new Result>() { public void success(List result) { @@ -2922,7 +2910,7 @@ public void error(Throwable error) { } }; - api.echoAsyncList(aListArg, resultCallback); + api.echoAsyncList(listArg, resultCallback); }); } else { channel.setMessageHandler(null); @@ -3385,7 +3373,7 @@ public void error(Throwable error) { (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - List aListArg = (List) args.get(0); + List listArg = (List) args.get(0); NullableResult> resultCallback = new NullableResult>() { public void success(List result) { @@ -3399,7 +3387,7 @@ public void error(Throwable error) { } }; - api.echoAsyncNullableList(aListArg, resultCallback); + api.echoAsyncNullableList(listArg, resultCallback); }); } else { channel.setMessageHandler(null); @@ -3873,7 +3861,7 @@ public void error(Throwable error) { (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - byte[] aListArg = (byte[]) args.get(0); + byte[] listArg = (byte[]) args.get(0); Result resultCallback = new Result() { public void success(byte[] result) { @@ -3887,7 +3875,7 @@ public void error(Throwable error) { } }; - api.callFlutterEchoUint8List(aListArg, resultCallback); + api.callFlutterEchoUint8List(listArg, resultCallback); }); } else { channel.setMessageHandler(null); @@ -3905,7 +3893,7 @@ public void error(Throwable error) { (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - List aListArg = (List) args.get(0); + List listArg = (List) args.get(0); Result> resultCallback = new Result>() { public void success(List result) { @@ -3919,7 +3907,7 @@ public void error(Throwable error) { } }; - api.callFlutterEchoList(aListArg, resultCallback); + api.callFlutterEchoList(listArg, resultCallback); }); } else { channel.setMessageHandler(null); @@ -4130,7 +4118,7 @@ public void error(Throwable error) { (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - byte[] aListArg = (byte[]) args.get(0); + byte[] listArg = (byte[]) args.get(0); NullableResult resultCallback = new NullableResult() { public void success(byte[] result) { @@ -4144,7 +4132,7 @@ public void error(Throwable error) { } }; - api.callFlutterEchoNullableUint8List(aListArg, resultCallback); + api.callFlutterEchoNullableUint8List(listArg, resultCallback); }); } else { channel.setMessageHandler(null); @@ -4162,7 +4150,7 @@ public void error(Throwable error) { (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - List aListArg = (List) args.get(0); + List listArg = (List) args.get(0); NullableResult> resultCallback = new NullableResult>() { public void success(List result) { @@ -4176,7 +4164,7 @@ public void error(Throwable error) { } }; - api.callFlutterEchoNullableList(aListArg, resultCallback); + api.callFlutterEchoNullableList(listArg, resultCallback); }); } else { channel.setMessageHandler(null); @@ -4755,14 +4743,14 @@ public void echoString(@NonNull String aStringArg, @NonNull Result resul }); } /** Returns the passed byte list, to test serialization and deserialization. */ - public void echoUint8List(@NonNull byte[] aListArg, @NonNull Result result) { + public void echoUint8List(@NonNull byte[] listArg, @NonNull Result result) { final String channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List" + messageChannelSuffix; BasicMessageChannel channel = new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( - new ArrayList(Collections.singletonList(aListArg)), + new ArrayList(Collections.singletonList(listArg)), channelReply -> { if (channelReply instanceof List) { List listReply = (List) channelReply; @@ -4789,14 +4777,14 @@ public void echoUint8List(@NonNull byte[] aListArg, @NonNull Result resu }); } /** Returns the passed list, to test serialization and deserialization. */ - public void echoList(@NonNull List aListArg, @NonNull Result> result) { + public void echoList(@NonNull List listArg, @NonNull Result> result) { final String channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList" + messageChannelSuffix; BasicMessageChannel channel = new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( - new ArrayList(Collections.singletonList(aListArg)), + new ArrayList(Collections.singletonList(listArg)), channelReply -> { if (channelReply instanceof List) { List listReply = (List) channelReply; @@ -5009,14 +4997,14 @@ public void echoNullableString( } /** Returns the passed byte list, to test serialization and deserialization. */ public void echoNullableUint8List( - @Nullable byte[] aListArg, @NonNull NullableResult result) { + @Nullable byte[] listArg, @NonNull NullableResult result) { final String channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List" + messageChannelSuffix; BasicMessageChannel channel = new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( - new ArrayList(Collections.singletonList(aListArg)), + new ArrayList(Collections.singletonList(listArg)), channelReply -> { if (channelReply instanceof List) { List listReply = (List) channelReply; @@ -5038,14 +5026,14 @@ public void echoNullableUint8List( } /** Returns the passed list, to test serialization and deserialization. */ public void echoNullableList( - @Nullable List aListArg, @NonNull NullableResult> result) { + @Nullable List listArg, @NonNull NullableResult> result) { final String channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList" + messageChannelSuffix; BasicMessageChannel channel = new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( - new ArrayList(Collections.singletonList(aListArg)), + new ArrayList(Collections.singletonList(listArg)), channelReply -> { if (channelReply instanceof List) { List listReply = (List) channelReply; diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java index 6f2fdf16e909..b15c2bfa6827 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java @@ -33,7 +33,7 @@ void compareAllTypes(AllTypes firstTypes, AllTypes secondTypes) { assertArrayEquals(firstTypes.getA4ByteArray(), secondTypes.getA4ByteArray()); assertArrayEquals(firstTypes.getA8ByteArray(), secondTypes.getA8ByteArray()); assertTrue(floatArraysEqual(firstTypes.getAFloatArray(), secondTypes.getAFloatArray())); - assertArrayEquals(firstTypes.getAList().toArray(), secondTypes.getAList().toArray()); + assertArrayEquals(firstTypes.getList().toArray(), secondTypes.getList().toArray()); assertArrayEquals( firstTypes.getAMap().keySet().toArray(), secondTypes.getAMap().keySet().toArray()); assertArrayEquals( @@ -154,7 +154,7 @@ public void hasValues() { .setA4ByteArray(new int[] {1, 2, 3, 4}) .setA8ByteArray(new long[] {1, 2, 3, 4}) .setAFloatArray(new double[] {0.5, 0.25, 1.5, 1.25}) - .setAList(Arrays.asList(new int[] {1, 2, 3})) + .setList(Arrays.asList(new int[] {1, 2, 3})) .setAMap(makeMap("hello", 1234)) .setAnEnum(CoreTests.AnEnum.ONE) .setAnObject(0) diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullFieldsTest.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullFieldsTest.java index d581c2d8bc2b..621a8a64f836 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullFieldsTest.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullFieldsTest.java @@ -81,20 +81,23 @@ public void requestFromMapWithNulls() { @Test public void replyFromMapWithValues() { - ArrayList requestList = new ArrayList(); - - requestList.add("hello"); - requestList.add(1L); - - ArrayList list = new ArrayList(); + NullFields.NullFieldsSearchRequest request = + new NullFields.NullFieldsSearchRequest.Builder() + .setQuery("hello") + .setIdentifier(1L) + .build(); - list.add("result"); - list.add("error"); - list.add(Arrays.asList(1L, 2L, 3L)); - list.add(requestList); - list.add(NullFields.NullFieldsSearchReplyType.SUCCESS.ordinal()); + NullFields.NullFieldsSearchReply input = + new NullFields.NullFieldsSearchReply.Builder() + .setResult("result") + .setError("error") + .setIndices(Arrays.asList(1L, 2L, 3L)) + .setRequest(request) + .setType(NullFields.NullFieldsSearchReplyType.SUCCESS) + .build(); - NullFields.NullFieldsSearchReply reply = NullFields.NullFieldsSearchReply.fromList(list); + NullFields.NullFieldsSearchReply reply = + NullFields.NullFieldsSearchReply.fromList(input.toList()); assertEquals(reply.getResult(), "result"); assertEquals(reply.getError(), "error"); assertEquals(reply.getIndices(), Arrays.asList(1L, 2L, 3L)); @@ -143,16 +146,18 @@ public void requestToMapWithNulls() { @Test public void replyToMapWithValues() { + NullFields.NullFieldsSearchRequest request = + new NullFields.NullFieldsSearchRequest.Builder() + .setQuery("hello") + .setIdentifier(1L) + .build(); + NullFields.NullFieldsSearchReply reply = new NullFields.NullFieldsSearchReply.Builder() .setResult("result") .setError("error") .setIndices(Arrays.asList(1L, 2L, 3L)) - .setRequest( - new NullFields.NullFieldsSearchRequest.Builder() - .setQuery("hello") - .setIdentifier(1L) - .build()) + .setRequest(request) .setType(NullFields.NullFieldsSearchReplyType.SUCCESS) .build(); @@ -160,7 +165,7 @@ public void replyToMapWithValues() { assertEquals(list.get(0), "result"); assertEquals(list.get(1), "error"); assertEquals(list.get(2), Arrays.asList(1L, 2L, 3L)); - assertEquals(list.get(3), reply.getRequest().toList()); + assertEquals(list.get(3), reply.getRequest()); assertEquals(list.get(4), NullFields.NullFieldsSearchReplyType.SUCCESS.ordinal()); } diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullFieldsTest.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullFieldsTest.m index e4032dc4cb5b..48b48b61a685 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullFieldsTest.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullFieldsTest.m @@ -84,19 +84,18 @@ - (void)testRequestFromListWithNulls { } - (void)testReplyFromListWithValues { - NSArray *list = @[ - @"result", - @"error", - @[ @1, @2, @3 ], - @[ - @"hello", - @1, - ], - @0, - ]; - NSArray *indices = @[ @1, @2, @3 ]; - NullFieldsSearchReply *reply = [NullFieldsSearchReply fromList:list]; + NullFieldsSearchRequest *request = [NullFieldsSearchRequest makeWithQuery:@"hello" identifier:1]; + + NullFieldsSearchReplyTypeBox *typeWrapper = + [[NullFieldsSearchReplyTypeBox alloc] initWithValue:NullFieldsSearchReplyTypeSuccess]; + NullFieldsSearchReply *input = [NullFieldsSearchReply makeWithResult:@"result" + error:@"error" + indices:indices + request:request + type:typeWrapper]; + + NullFieldsSearchReply *reply = [NullFieldsSearchReply fromList:[input toList]]; XCTAssertEqualObjects(@"result", reply.result); XCTAssertEqualObjects(@"error", reply.error); XCTAssertEqualObjects(indices, reply.indices); @@ -146,7 +145,7 @@ - (void)testReplyToListWithValuess { XCTAssertEqualObjects(@"result", list[0]); XCTAssertEqualObjects(@"error", list[1]); XCTAssertEqualObjects(indices, list[2]); - XCTAssertEqualObjects(@"hello", list[3][0]); + XCTAssertEqualObjects(@"hello", ((NullFieldsSearchRequest *)list[3]).query); NSNumber *typeNumber = list[4]; NullFieldsSearchReplyTypeBox *output = [[NullFieldsSearchReplyTypeBox alloc] initWithValue:[typeNumber integerValue]]; 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 e3f26dcb8d75..4ea9519033c7 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 @@ -90,9 +90,9 @@ - (nullable id)echoObject:(id)anObject error:(FlutterError *_Nullable *_Nonnull) return anObject; } -- (nullable NSArray *)echoList:(NSArray *)aList +- (nullable NSArray *)echoList:(NSArray *)list error:(FlutterError *_Nullable *_Nonnull)error { - return aList; + return list; } - (nullable NSDictionary *)echoMap:(NSDictionary *)aMap @@ -293,9 +293,9 @@ - (void)echoAsyncObject:(id)anObject completion(anObject, nil); } -- (void)echoAsyncList:(NSArray *)aList +- (void)echoAsyncList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - completion(aList, nil); + completion(list, nil); } - (void)echoAsyncMap:(NSDictionary *)aMap @@ -340,10 +340,10 @@ - (void)echoAsyncNullableObject:(nullable id)anObject completion(anObject, nil); } -- (void)echoAsyncNullableList:(nullable NSArray *)aList +- (void)echoAsyncNullableList:(nullable NSArray *)list completion: (void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - completion(aList, nil); + completion(list, nil); } - (void)echoAsyncNullableMap:(nullable NSDictionary *)aMap @@ -451,18 +451,18 @@ - (void)callFlutterEchoString:(NSString *)aString }]; } -- (void)callFlutterEchoUint8List:(FlutterStandardTypedData *)aList +- (void)callFlutterEchoUint8List:(FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { - [self.flutterAPI echoUint8List:aList + [self.flutterAPI echoUint8List:list completion:^(FlutterStandardTypedData *value, FlutterError *error) { completion(value, error); }]; } -- (void)callFlutterEchoList:(NSArray *)aList +- (void)callFlutterEchoList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - [self.flutterAPI echoList:aList + [self.flutterAPI echoList:list completion:^(NSArray *value, FlutterError *error) { completion(value, error); }]; @@ -544,19 +544,19 @@ - (void)callFlutterEchoNullableString:(nullable NSString *)aString }]; } -- (void)callFlutterEchoNullableUint8List:(nullable FlutterStandardTypedData *)aList +- (void)callFlutterEchoNullableUint8List:(nullable FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { - [self.flutterAPI echoNullableUint8List:aList + [self.flutterAPI echoNullableUint8List:list completion:^(FlutterStandardTypedData *value, FlutterError *error) { completion(value, error); }]; } -- (void)callFlutterEchoNullableList:(nullable NSArray *)aList +- (void)callFlutterEchoNullableList:(nullable NSArray *)list completion: (void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - [self.flutterAPI echoNullableList:aList + [self.flutterAPI echoNullableList:list completion:^(NSArray *value, FlutterError *error) { completion(value, error); }]; 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 8e44380d7890..ada05bf3801f 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 @@ -46,7 +46,7 @@ typedef NS_ENUM(NSUInteger, FLTAnEnum) { a4ByteArray:(FlutterStandardTypedData *)a4ByteArray a8ByteArray:(FlutterStandardTypedData *)a8ByteArray aFloatArray:(FlutterStandardTypedData *)aFloatArray - aList:(NSArray *)aList + list:(NSArray *)list aMap:(NSDictionary *)aMap anEnum:(FLTAnEnum)anEnum aString:(NSString *)aString @@ -59,7 +59,7 @@ typedef NS_ENUM(NSUInteger, FLTAnEnum) { @property(nonatomic, strong) FlutterStandardTypedData *a4ByteArray; @property(nonatomic, strong) FlutterStandardTypedData *a8ByteArray; @property(nonatomic, strong) FlutterStandardTypedData *aFloatArray; -@property(nonatomic, copy) NSArray *aList; +@property(nonatomic, copy) NSArray *list; @property(nonatomic, copy) NSDictionary *aMap; @property(nonatomic, assign) FLTAnEnum anEnum; @property(nonatomic, copy) NSString *aString; @@ -219,7 +219,7 @@ NSObject *FLTHostIntegrationCoreApiGetCodec(void); /// Returns the passed list, to test serialization and deserialization. /// /// @return `nil` only when `error != nil`. -- (nullable NSArray *)echoList:(NSArray *)aList +- (nullable NSArray *)echoList:(NSArray *)list error:(FlutterError *_Nullable *_Nonnull)error; /// Returns the passed map, to test serialization and deserialization. /// @@ -342,7 +342,7 @@ NSObject *FLTHostIntegrationCoreApiGetCodec(void); - (void)echoAsyncObject:(id)anObject completion:(void (^)(id _Nullable, FlutterError *_Nullable))completion; /// Returns the passed list, to test asynchronous serialization and deserialization. -- (void)echoAsyncList:(NSArray *)aList +- (void)echoAsyncList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed map, to test asynchronous serialization and deserialization. - (void)echoAsyncMap:(NSDictionary *)aMap @@ -392,7 +392,7 @@ NSObject *FLTHostIntegrationCoreApiGetCodec(void); - (void)echoAsyncNullableObject:(nullable id)anObject completion:(void (^)(id _Nullable, FlutterError *_Nullable))completion; /// Returns the passed list, to test asynchronous serialization and deserialization. -- (void)echoAsyncNullableList:(nullable NSArray *)aList +- (void)echoAsyncNullableList:(nullable NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed map, to test asynchronous serialization and deserialization. - (void)echoAsyncNullableMap:(nullable NSDictionary *)aMap @@ -440,10 +440,10 @@ NSObject *FLTHostIntegrationCoreApiGetCodec(void); completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion; - (void)callFlutterEchoString:(NSString *)aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; -- (void)callFlutterEchoUint8List:(FlutterStandardTypedData *)aList +- (void)callFlutterEchoUint8List:(FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion; -- (void)callFlutterEchoList:(NSArray *)aList +- (void)callFlutterEchoList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; - (void)callFlutterEchoMap:(NSDictionary *)aMap completion:(void (^)(NSDictionary *_Nullable, @@ -462,10 +462,10 @@ NSObject *FLTHostIntegrationCoreApiGetCodec(void); - (void)callFlutterEchoNullableString:(nullable NSString *)aString completion: (void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; -- (void)callFlutterEchoNullableUint8List:(nullable FlutterStandardTypedData *)aList +- (void)callFlutterEchoNullableUint8List:(nullable FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion; -- (void)callFlutterEchoNullableList:(nullable NSArray *)aList +- (void)callFlutterEchoNullableList:(nullable NSArray *)list completion: (void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; - (void)callFlutterEchoNullableMap:(nullable NSDictionary *)aMap @@ -545,11 +545,11 @@ NSObject *FLTFlutterIntegrationCoreApiGetCodec(void); - (void)echoString:(NSString *)aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed byte list, to test serialization and deserialization. -- (void)echoUint8List:(FlutterStandardTypedData *)aList +- (void)echoUint8List:(FlutterStandardTypedData *)list completion: (void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed list, to test serialization and deserialization. -- (void)echoList:(NSArray *)aList +- (void)echoList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed map, to test serialization and deserialization. - (void)echoMap:(NSDictionary *)aMap @@ -571,11 +571,11 @@ NSObject *FLTFlutterIntegrationCoreApiGetCodec(void); - (void)echoNullableString:(nullable NSString *)aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed byte list, to test serialization and deserialization. -- (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)aList +- (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed list, to test serialization and deserialization. -- (void)echoNullableList:(nullable NSArray *)aList +- (void)echoNullableList:(nullable NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed map, to test serialization and deserialization. - (void)echoNullableMap:(nullable NSDictionary *)aMap 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 eecb44f2eaf8..92c72d595982 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 @@ -89,7 +89,7 @@ + (instancetype)makeWithABool:(BOOL)aBool a4ByteArray:(FlutterStandardTypedData *)a4ByteArray a8ByteArray:(FlutterStandardTypedData *)a8ByteArray aFloatArray:(FlutterStandardTypedData *)aFloatArray - aList:(NSArray *)aList + list:(NSArray *)list aMap:(NSDictionary *)aMap anEnum:(FLTAnEnum)anEnum aString:(NSString *)aString @@ -103,7 +103,7 @@ + (instancetype)makeWithABool:(BOOL)aBool pigeonResult.a4ByteArray = a4ByteArray; pigeonResult.a8ByteArray = a8ByteArray; pigeonResult.aFloatArray = aFloatArray; - pigeonResult.aList = aList; + pigeonResult.list = list; pigeonResult.aMap = aMap; pigeonResult.anEnum = anEnum; pigeonResult.aString = aString; @@ -120,7 +120,7 @@ + (FLTAllTypes *)fromList:(NSArray *)list { pigeonResult.a4ByteArray = GetNullableObjectAtIndex(list, 5); pigeonResult.a8ByteArray = GetNullableObjectAtIndex(list, 6); pigeonResult.aFloatArray = GetNullableObjectAtIndex(list, 7); - pigeonResult.aList = GetNullableObjectAtIndex(list, 8); + pigeonResult.list = GetNullableObjectAtIndex(list, 8); pigeonResult.aMap = GetNullableObjectAtIndex(list, 9); pigeonResult.anEnum = [GetNullableObjectAtIndex(list, 10) integerValue]; pigeonResult.aString = GetNullableObjectAtIndex(list, 11); @@ -140,7 +140,7 @@ - (NSArray *)toList { self.a4ByteArray ?: [NSNull null], self.a8ByteArray ?: [NSNull null], self.aFloatArray ?: [NSNull null], - self.aList ?: [NSNull null], + self.list ?: [NSNull null], self.aMap ?: [NSNull null], @(self.anEnum), self.aString ?: [NSNull null], @@ -211,8 +211,7 @@ + (FLTAllNullableTypes *)fromList:(NSArray *)list { pigeonResult.aNullableEnum = aNullableEnum; pigeonResult.aNullableString = GetNullableObjectAtIndex(list, 14); pigeonResult.aNullableObject = GetNullableObjectAtIndex(list, 15); - pigeonResult.allNullableTypes = - [FLTAllNullableTypes nullableFromList:(GetNullableObjectAtIndex(list, 16))]; + pigeonResult.allNullableTypes = GetNullableObjectAtIndex(list, 16); return pigeonResult; } + (nullable FLTAllNullableTypes *)nullableFromList:(NSArray *)list { @@ -237,7 +236,7 @@ - (NSArray *)toList { : [NSNumber numberWithInteger:self.aNullableEnum.value]), self.aNullableString ?: [NSNull null], self.aNullableObject ?: [NSNull null], - (self.allNullableTypes ? [self.allNullableTypes toList] : [NSNull null]), + self.allNullableTypes ?: [NSNull null], ]; } @end @@ -345,11 +344,9 @@ + (instancetype)makeWithAllNullableTypes:(FLTAllNullableTypes *)allNullableTypes } + (FLTAllClassesWrapper *)fromList:(NSArray *)list { FLTAllClassesWrapper *pigeonResult = [[FLTAllClassesWrapper alloc] init]; - pigeonResult.allNullableTypes = - [FLTAllNullableTypes nullableFromList:(GetNullableObjectAtIndex(list, 0))]; - pigeonResult.allNullableTypesWithoutRecursion = - [FLTAllNullableTypesWithoutRecursion nullableFromList:(GetNullableObjectAtIndex(list, 1))]; - pigeonResult.allTypes = [FLTAllTypes nullableFromList:(GetNullableObjectAtIndex(list, 2))]; + pigeonResult.allNullableTypes = GetNullableObjectAtIndex(list, 0); + pigeonResult.allNullableTypesWithoutRecursion = GetNullableObjectAtIndex(list, 1); + pigeonResult.allTypes = GetNullableObjectAtIndex(list, 2); return pigeonResult; } + (nullable FLTAllClassesWrapper *)nullableFromList:(NSArray *)list { @@ -357,10 +354,9 @@ + (nullable FLTAllClassesWrapper *)nullableFromList:(NSArray *)list { } - (NSArray *)toList { return @[ - (self.allNullableTypes ? [self.allNullableTypes toList] : [NSNull null]), - (self.allNullableTypesWithoutRecursion ? [self.allNullableTypesWithoutRecursion toList] - : [NSNull null]), - (self.allTypes ? [self.allTypes toList] : [NSNull null]), + self.allNullableTypes ?: [NSNull null], + self.allNullableTypesWithoutRecursion ?: [NSNull null], + self.allTypes ?: [NSNull null], ]; } @end @@ -745,9 +741,9 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); FlutterError *error; - NSArray *output = [api echoList:arg_aList error:&error]; + NSArray *output = [api echoList:arg_list error:&error]; callback(wrapResult(output, error)); }]; } else { @@ -1557,8 +1553,8 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); - [api echoAsyncList:arg_aList + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); + [api echoAsyncList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); }]; @@ -1955,8 +1951,8 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); - [api echoAsyncNullableList:arg_aList + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); + [api echoAsyncNullableList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); }]; @@ -2364,8 +2360,8 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - FlutterStandardTypedData *arg_aList = GetNullableObjectAtIndex(args, 0); - [api callFlutterEchoUint8List:arg_aList + FlutterStandardTypedData *arg_list = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoUint8List:arg_list completion:^(FlutterStandardTypedData *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); @@ -2390,8 +2386,8 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); - [api callFlutterEchoList:arg_aList + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); }]; @@ -2578,8 +2574,8 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - FlutterStandardTypedData *arg_aList = GetNullableObjectAtIndex(args, 0); - [api callFlutterEchoNullableUint8List:arg_aList + FlutterStandardTypedData *arg_list = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoNullableUint8List:arg_list completion:^(FlutterStandardTypedData *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); @@ -2605,8 +2601,8 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); - [api callFlutterEchoNullableList:arg_aList + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoNullableList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); @@ -3131,7 +3127,7 @@ - (void)echoString:(NSString *)arg_aString } }]; } -- (void)echoUint8List:(FlutterStandardTypedData *)arg_aList +- (void)echoUint8List:(FlutterStandardTypedData *)arg_list completion: (void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { NSString *channelName = [NSString @@ -3143,7 +3139,7 @@ - (void)echoUint8List:(FlutterStandardTypedData *)arg_aList [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger codec:FLTFlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { @@ -3160,7 +3156,7 @@ - (void)echoUint8List:(FlutterStandardTypedData *)arg_aList } }]; } -- (void)echoList:(NSArray *)arg_aList +- (void)echoList:(NSArray *)arg_list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { NSString *channelName = [NSString stringWithFormat: @@ -3171,7 +3167,7 @@ - (void)echoList:(NSArray *)arg_aList [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger codec:FLTFlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { @@ -3354,7 +3350,7 @@ - (void)echoNullableString:(nullable NSString *)arg_aString } }]; } -- (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_aList +- (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { NSString *channelName = @@ -3366,7 +3362,7 @@ - (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_aList [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger codec:FLTFlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { @@ -3383,7 +3379,7 @@ - (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_aList } }]; } -- (void)echoNullableList:(nullable NSArray *)arg_aList +- (void)echoNullableList:(nullable NSArray *)arg_list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { NSString *channelName = [NSString stringWithFormat: @@ -3394,7 +3390,7 @@ - (void)echoNullableList:(nullable NSArray *)arg_aList [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger codec:FLTFlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { 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 b35ac7907ec0..0cdec98b9ed1 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 @@ -88,9 +88,9 @@ - (nullable id)echoObject:(id)anObject error:(FlutterError *_Nullable *_Nonnull) return anObject; } -- (nullable NSArray *)echoList:(NSArray *)aList +- (nullable NSArray *)echoList:(NSArray *)list error:(FlutterError *_Nullable *_Nonnull)error { - return aList; + return list; } - (nullable NSDictionary *)echoMap:(NSDictionary *)aMap @@ -288,9 +288,9 @@ - (void)echoAsyncObject:(id)anObject completion(anObject, nil); } -- (void)echoAsyncList:(NSArray *)aList +- (void)echoAsyncList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - completion(aList, nil); + completion(list, nil); } - (void)echoAsyncMap:(NSDictionary *)aMap @@ -335,10 +335,10 @@ - (void)echoAsyncNullableObject:(nullable id)anObject completion(anObject, nil); } -- (void)echoAsyncNullableList:(nullable NSArray *)aList +- (void)echoAsyncNullableList:(nullable NSArray *)list completion: (void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - completion(aList, nil); + completion(list, nil); } - (void)echoAsyncNullableMap:(nullable NSDictionary *)aMap @@ -443,18 +443,18 @@ - (void)callFlutterEchoString:(NSString *)aString }]; } -- (void)callFlutterEchoUint8List:(FlutterStandardTypedData *)aList +- (void)callFlutterEchoUint8List:(FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { - [self.flutterAPI echoUint8List:aList + [self.flutterAPI echoUint8List:list completion:^(FlutterStandardTypedData *value, FlutterError *error) { completion(value, error); }]; } -- (void)callFlutterEchoList:(NSArray *)aList +- (void)callFlutterEchoList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - [self.flutterAPI echoList:aList + [self.flutterAPI echoList:list completion:^(NSArray *value, FlutterError *error) { completion(value, error); }]; @@ -535,19 +535,19 @@ - (void)callFlutterEchoNullableString:(nullable NSString *)aString }]; } -- (void)callFlutterEchoNullableUint8List:(nullable FlutterStandardTypedData *)aList +- (void)callFlutterEchoNullableUint8List:(nullable FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { - [self.flutterAPI echoNullableUint8List:aList + [self.flutterAPI echoNullableUint8List:list completion:^(FlutterStandardTypedData *value, FlutterError *error) { completion(value, error); }]; } -- (void)callFlutterEchoNullableList:(nullable NSArray *)aList +- (void)callFlutterEchoNullableList:(nullable NSArray *)list completion: (void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - [self.flutterAPI echoNullableList:aList + [self.flutterAPI echoNullableList:list completion:^(NSArray *value, FlutterError *error) { completion(value, error); }]; 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 4d6fc8de326b..ee54d035eb60 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 @@ -46,7 +46,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) { a4ByteArray:(FlutterStandardTypedData *)a4ByteArray a8ByteArray:(FlutterStandardTypedData *)a8ByteArray aFloatArray:(FlutterStandardTypedData *)aFloatArray - aList:(NSArray *)aList + list:(NSArray *)list aMap:(NSDictionary *)aMap anEnum:(AnEnum)anEnum aString:(NSString *)aString @@ -59,7 +59,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @property(nonatomic, strong) FlutterStandardTypedData *a4ByteArray; @property(nonatomic, strong) FlutterStandardTypedData *a8ByteArray; @property(nonatomic, strong) FlutterStandardTypedData *aFloatArray; -@property(nonatomic, copy) NSArray *aList; +@property(nonatomic, copy) NSArray *list; @property(nonatomic, copy) NSDictionary *aMap; @property(nonatomic, assign) AnEnum anEnum; @property(nonatomic, copy) NSString *aString; @@ -219,7 +219,7 @@ NSObject *HostIntegrationCoreApiGetCodec(void); /// Returns the passed list, to test serialization and deserialization. /// /// @return `nil` only when `error != nil`. -- (nullable NSArray *)echoList:(NSArray *)aList +- (nullable NSArray *)echoList:(NSArray *)list error:(FlutterError *_Nullable *_Nonnull)error; /// Returns the passed map, to test serialization and deserialization. /// @@ -341,7 +341,7 @@ NSObject *HostIntegrationCoreApiGetCodec(void); - (void)echoAsyncObject:(id)anObject completion:(void (^)(id _Nullable, FlutterError *_Nullable))completion; /// Returns the passed list, to test asynchronous serialization and deserialization. -- (void)echoAsyncList:(NSArray *)aList +- (void)echoAsyncList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed map, to test asynchronous serialization and deserialization. - (void)echoAsyncMap:(NSDictionary *)aMap @@ -391,7 +391,7 @@ NSObject *HostIntegrationCoreApiGetCodec(void); - (void)echoAsyncNullableObject:(nullable id)anObject completion:(void (^)(id _Nullable, FlutterError *_Nullable))completion; /// Returns the passed list, to test asynchronous serialization and deserialization. -- (void)echoAsyncNullableList:(nullable NSArray *)aList +- (void)echoAsyncNullableList:(nullable NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed map, to test asynchronous serialization and deserialization. - (void)echoAsyncNullableMap:(nullable NSDictionary *)aMap @@ -437,10 +437,10 @@ NSObject *HostIntegrationCoreApiGetCodec(void); completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion; - (void)callFlutterEchoString:(NSString *)aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; -- (void)callFlutterEchoUint8List:(FlutterStandardTypedData *)aList +- (void)callFlutterEchoUint8List:(FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion; -- (void)callFlutterEchoList:(NSArray *)aList +- (void)callFlutterEchoList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; - (void)callFlutterEchoMap:(NSDictionary *)aMap completion:(void (^)(NSDictionary *_Nullable, @@ -459,10 +459,10 @@ NSObject *HostIntegrationCoreApiGetCodec(void); - (void)callFlutterEchoNullableString:(nullable NSString *)aString completion: (void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; -- (void)callFlutterEchoNullableUint8List:(nullable FlutterStandardTypedData *)aList +- (void)callFlutterEchoNullableUint8List:(nullable FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion; -- (void)callFlutterEchoNullableList:(nullable NSArray *)aList +- (void)callFlutterEchoNullableList:(nullable NSArray *)list completion: (void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; - (void)callFlutterEchoNullableMap:(nullable NSDictionary *)aMap @@ -541,11 +541,11 @@ NSObject *FlutterIntegrationCoreApiGetCodec(void); - (void)echoString:(NSString *)aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed byte list, to test serialization and deserialization. -- (void)echoUint8List:(FlutterStandardTypedData *)aList +- (void)echoUint8List:(FlutterStandardTypedData *)list completion: (void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed list, to test serialization and deserialization. -- (void)echoList:(NSArray *)aList +- (void)echoList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed map, to test serialization and deserialization. - (void)echoMap:(NSDictionary *)aMap @@ -567,11 +567,11 @@ NSObject *FlutterIntegrationCoreApiGetCodec(void); - (void)echoNullableString:(nullable NSString *)aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed byte list, to test serialization and deserialization. -- (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)aList +- (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed list, to test serialization and deserialization. -- (void)echoNullableList:(nullable NSArray *)aList +- (void)echoNullableList:(nullable NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed map, to test serialization and deserialization. - (void)echoNullableMap:(nullable NSDictionary *)aMap 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 7d1fbdae8248..fafcbcf7d732 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 @@ -89,7 +89,7 @@ + (instancetype)makeWithABool:(BOOL)aBool a4ByteArray:(FlutterStandardTypedData *)a4ByteArray a8ByteArray:(FlutterStandardTypedData *)a8ByteArray aFloatArray:(FlutterStandardTypedData *)aFloatArray - aList:(NSArray *)aList + list:(NSArray *)list aMap:(NSDictionary *)aMap anEnum:(AnEnum)anEnum aString:(NSString *)aString @@ -103,7 +103,7 @@ + (instancetype)makeWithABool:(BOOL)aBool pigeonResult.a4ByteArray = a4ByteArray; pigeonResult.a8ByteArray = a8ByteArray; pigeonResult.aFloatArray = aFloatArray; - pigeonResult.aList = aList; + pigeonResult.list = list; pigeonResult.aMap = aMap; pigeonResult.anEnum = anEnum; pigeonResult.aString = aString; @@ -120,7 +120,7 @@ + (AllTypes *)fromList:(NSArray *)list { pigeonResult.a4ByteArray = GetNullableObjectAtIndex(list, 5); pigeonResult.a8ByteArray = GetNullableObjectAtIndex(list, 6); pigeonResult.aFloatArray = GetNullableObjectAtIndex(list, 7); - pigeonResult.aList = GetNullableObjectAtIndex(list, 8); + pigeonResult.list = GetNullableObjectAtIndex(list, 8); pigeonResult.aMap = GetNullableObjectAtIndex(list, 9); pigeonResult.anEnum = [GetNullableObjectAtIndex(list, 10) integerValue]; pigeonResult.aString = GetNullableObjectAtIndex(list, 11); @@ -140,7 +140,7 @@ - (NSArray *)toList { self.a4ByteArray ?: [NSNull null], self.a8ByteArray ?: [NSNull null], self.aFloatArray ?: [NSNull null], - self.aList ?: [NSNull null], + self.list ?: [NSNull null], self.aMap ?: [NSNull null], @(self.anEnum), self.aString ?: [NSNull null], @@ -211,8 +211,7 @@ + (AllNullableTypes *)fromList:(NSArray *)list { pigeonResult.aNullableEnum = aNullableEnum; pigeonResult.aNullableString = GetNullableObjectAtIndex(list, 14); pigeonResult.aNullableObject = GetNullableObjectAtIndex(list, 15); - pigeonResult.allNullableTypes = - [AllNullableTypes nullableFromList:(GetNullableObjectAtIndex(list, 16))]; + pigeonResult.allNullableTypes = GetNullableObjectAtIndex(list, 16); return pigeonResult; } + (nullable AllNullableTypes *)nullableFromList:(NSArray *)list { @@ -237,7 +236,7 @@ - (NSArray *)toList { : [NSNumber numberWithInteger:self.aNullableEnum.value]), self.aNullableString ?: [NSNull null], self.aNullableObject ?: [NSNull null], - (self.allNullableTypes ? [self.allNullableTypes toList] : [NSNull null]), + self.allNullableTypes ?: [NSNull null], ]; } @end @@ -343,11 +342,9 @@ + (instancetype)makeWithAllNullableTypes:(AllNullableTypes *)allNullableTypes } + (AllClassesWrapper *)fromList:(NSArray *)list { AllClassesWrapper *pigeonResult = [[AllClassesWrapper alloc] init]; - pigeonResult.allNullableTypes = - [AllNullableTypes nullableFromList:(GetNullableObjectAtIndex(list, 0))]; - pigeonResult.allNullableTypesWithoutRecursion = - [AllNullableTypesWithoutRecursion nullableFromList:(GetNullableObjectAtIndex(list, 1))]; - pigeonResult.allTypes = [AllTypes nullableFromList:(GetNullableObjectAtIndex(list, 2))]; + pigeonResult.allNullableTypes = GetNullableObjectAtIndex(list, 0); + pigeonResult.allNullableTypesWithoutRecursion = GetNullableObjectAtIndex(list, 1); + pigeonResult.allTypes = GetNullableObjectAtIndex(list, 2); return pigeonResult; } + (nullable AllClassesWrapper *)nullableFromList:(NSArray *)list { @@ -355,10 +352,9 @@ + (nullable AllClassesWrapper *)nullableFromList:(NSArray *)list { } - (NSArray *)toList { return @[ - (self.allNullableTypes ? [self.allNullableTypes toList] : [NSNull null]), - (self.allNullableTypesWithoutRecursion ? [self.allNullableTypesWithoutRecursion toList] - : [NSNull null]), - (self.allTypes ? [self.allTypes toList] : [NSNull null]), + self.allNullableTypes ?: [NSNull null], + self.allNullableTypesWithoutRecursion ?: [NSNull null], + self.allTypes ?: [NSNull null], ]; } @end @@ -740,9 +736,9 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); FlutterError *error; - NSArray *output = [api echoList:arg_aList error:&error]; + NSArray *output = [api echoList:arg_list error:&error]; callback(wrapResult(output, error)); }]; } else { @@ -1552,8 +1548,8 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); - [api echoAsyncList:arg_aList + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); + [api echoAsyncList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); }]; @@ -1950,8 +1946,8 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); - [api echoAsyncNullableList:arg_aList + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); + [api echoAsyncNullableList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); }]; @@ -2358,8 +2354,8 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - FlutterStandardTypedData *arg_aList = GetNullableObjectAtIndex(args, 0); - [api callFlutterEchoUint8List:arg_aList + FlutterStandardTypedData *arg_list = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoUint8List:arg_list completion:^(FlutterStandardTypedData *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); @@ -2384,8 +2380,8 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); - [api callFlutterEchoList:arg_aList + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); }]; @@ -2571,8 +2567,8 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - FlutterStandardTypedData *arg_aList = GetNullableObjectAtIndex(args, 0); - [api callFlutterEchoNullableUint8List:arg_aList + FlutterStandardTypedData *arg_list = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoNullableUint8List:arg_list completion:^(FlutterStandardTypedData *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); @@ -2598,8 +2594,8 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); - [api callFlutterEchoNullableList:arg_aList + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoNullableList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); @@ -3123,7 +3119,7 @@ - (void)echoString:(NSString *)arg_aString } }]; } -- (void)echoUint8List:(FlutterStandardTypedData *)arg_aList +- (void)echoUint8List:(FlutterStandardTypedData *)arg_list completion: (void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { NSString *channelName = [NSString @@ -3135,7 +3131,7 @@ - (void)echoUint8List:(FlutterStandardTypedData *)arg_aList [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger codec:FlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { @@ -3152,7 +3148,7 @@ - (void)echoUint8List:(FlutterStandardTypedData *)arg_aList } }]; } -- (void)echoList:(NSArray *)arg_aList +- (void)echoList:(NSArray *)arg_list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { NSString *channelName = [NSString stringWithFormat: @@ -3163,7 +3159,7 @@ - (void)echoList:(NSArray *)arg_aList [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger codec:FlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { @@ -3346,7 +3342,7 @@ - (void)echoNullableString:(nullable NSString *)arg_aString } }]; } -- (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_aList +- (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { NSString *channelName = @@ -3358,7 +3354,7 @@ - (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_aList [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger codec:FlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { @@ -3375,7 +3371,7 @@ - (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_aList } }]; } -- (void)echoNullableList:(nullable NSArray *)arg_aList +- (void)echoNullableList:(nullable NSArray *)arg_list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { NSString *channelName = [NSString stringWithFormat: @@ -3386,7 +3382,7 @@ - (void)echoNullableList:(nullable NSArray *)arg_aList [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger codec:FlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { 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 caa448cac366..85484362b3a4 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 @@ -49,7 +49,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { expect(allTypesOne.a4ByteArray, allTypesTwo.a4ByteArray); expect(allTypesOne.a8ByteArray, allTypesTwo.a8ByteArray); expect(allTypesOne.aFloatArray, allTypesTwo.aFloatArray); - expect(listEquals(allTypesOne.aList, allTypesTwo.aList), true); + expect(listEquals(allTypesOne.list, allTypesTwo.list), true); expect(mapEquals(allTypesOne.aMap, allTypesTwo.aMap), true); expect(allTypesOne.anEnum, allTypesTwo.anEnum); expect(allTypesOne.anObject, allTypesTwo.anObject); @@ -190,7 +190,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { a4ByteArray: Int32List.fromList([4, 5, 6]), a8ByteArray: Int64List.fromList([7, 8, 9]), aFloatArray: Float64List.fromList([2.71828, _doublePi]), - aList: ['Thing 1', 2, true, 3.14, null], + list: ['Thing 1', 2, true, 3.14, null], aMap: { 'a': 1, 'b': 2.0, @@ -1863,10 +1863,10 @@ class _FlutterApiTestImplementation implements FlutterIntegrationCoreApi { String echoString(String aString) => aString; @override - Uint8List echoUint8List(Uint8List aList) => aList; + Uint8List echoUint8List(Uint8List list) => list; @override - List echoList(List aList) => aList; + List echoList(List list) => list; @override Map echoMap(Map aMap) => aMap; @@ -1884,7 +1884,7 @@ class _FlutterApiTestImplementation implements FlutterIntegrationCoreApi { int? echoNullableInt(int? anInt) => anInt; @override - List? echoNullableList(List? aList) => aList; + List? echoNullableList(List? list) => list; @override Map? echoNullableMap(Map? aMap) => aMap; @@ -1893,7 +1893,7 @@ class _FlutterApiTestImplementation implements FlutterIntegrationCoreApi { String? echoNullableString(String? aString) => aString; @override - Uint8List? echoNullableUint8List(Uint8List? aList) => aList; + Uint8List? echoNullableUint8List(Uint8List? list) => list; @override AnEnum? echoNullableEnum(AnEnum? anEnum) => anEnum; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart index 9c1649466262..2f24cdcb2ca3 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 @@ -49,7 +49,7 @@ class AllTypes { required this.a4ByteArray, required this.a8ByteArray, required this.aFloatArray, - this.aList = const [], + this.list = const [], this.aMap = const {}, this.anEnum = AnEnum.one, this.aString = '', @@ -72,7 +72,7 @@ class AllTypes { Float64List aFloatArray; - List aList; + List list; Map aMap; @@ -92,7 +92,7 @@ class AllTypes { a4ByteArray, a8ByteArray, aFloatArray, - aList, + list, aMap, anEnum.index, aString, @@ -111,7 +111,7 @@ class AllTypes { a4ByteArray: result[5]! as Int32List, a8ByteArray: result[6]! as Int64List, aFloatArray: result[7]! as Float64List, - aList: result[8]! as List, + list: result[8]! as List, aMap: result[9]! as Map, anEnum: AnEnum.values[result[10]! as int], aString: result[11]! as String, @@ -194,7 +194,7 @@ class AllNullableTypes { aNullableEnum?.index, aNullableString, aNullableObject, - allNullableTypes?.encode(), + allNullableTypes, ]; } @@ -220,9 +220,7 @@ class AllNullableTypes { result[13] != null ? AnEnum.values[result[13]! as int] : null, aNullableString: result[14] as String?, aNullableObject: result[15], - allNullableTypes: result[16] != null - ? AllNullableTypes.decode(result[16]! as List) - : null, + allNullableTypes: result[16] as AllNullableTypes?, ); } } @@ -349,22 +347,19 @@ class AllClassesWrapper { Object encode() { return [ - allNullableTypes.encode(), - allNullableTypesWithoutRecursion?.encode(), - allTypes?.encode(), + allNullableTypes, + allNullableTypesWithoutRecursion, + allTypes, ]; } static AllClassesWrapper decode(Object result) { result as List; return AllClassesWrapper( - allNullableTypes: AllNullableTypes.decode(result[0]! as List), - allNullableTypesWithoutRecursion: result[1] != null - ? AllNullableTypesWithoutRecursion.decode(result[1]! as List) - : null, - allTypes: result[2] != null - ? AllTypes.decode(result[2]! as List) - : null, + allNullableTypes: result[0]! as AllNullableTypes, + allNullableTypesWithoutRecursion: + result[1] as AllNullableTypesWithoutRecursion?, + allTypes: result[2] as AllTypes?, ); } } @@ -764,7 +759,7 @@ class HostIntegrationCoreApi { } /// Returns the passed list, to test serialization and deserialization. - Future> echoList(List aList) async { + Future> echoList(List list) async { final String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoList$__pigeon_messageChannelSuffix'; final BasicMessageChannel __pigeon_channel = @@ -774,7 +769,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([aList]) as List?; + await __pigeon_channel.send([list]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -1636,7 +1631,7 @@ class HostIntegrationCoreApi { } /// Returns the passed list, to test asynchronous serialization and deserialization. - Future> echoAsyncList(List aList) async { + Future> echoAsyncList(List list) async { final String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncList$__pigeon_messageChannelSuffix'; final BasicMessageChannel __pigeon_channel = @@ -1646,7 +1641,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([aList]) as List?; + await __pigeon_channel.send([list]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2035,7 +2030,7 @@ class HostIntegrationCoreApi { } /// Returns the passed list, to test asynchronous serialization and deserialization. - Future?> echoAsyncNullableList(List? aList) async { + Future?> echoAsyncNullableList(List? list) async { final String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableList$__pigeon_messageChannelSuffix'; final BasicMessageChannel __pigeon_channel = @@ -2045,7 +2040,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([aList]) as List?; + await __pigeon_channel.send([list]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2444,7 +2439,7 @@ class HostIntegrationCoreApi { } } - Future callFlutterEchoUint8List(Uint8List aList) async { + Future callFlutterEchoUint8List(Uint8List list) async { final String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoUint8List$__pigeon_messageChannelSuffix'; final BasicMessageChannel __pigeon_channel = @@ -2454,7 +2449,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([aList]) as List?; + await __pigeon_channel.send([list]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2473,7 +2468,7 @@ class HostIntegrationCoreApi { } } - Future> callFlutterEchoList(List aList) async { + Future> callFlutterEchoList(List list) async { final String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoList$__pigeon_messageChannelSuffix'; final BasicMessageChannel __pigeon_channel = @@ -2483,7 +2478,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([aList]) as List?; + await __pigeon_channel.send([list]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2658,7 +2653,7 @@ class HostIntegrationCoreApi { } } - Future callFlutterEchoNullableUint8List(Uint8List? aList) async { + Future callFlutterEchoNullableUint8List(Uint8List? list) async { final String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableUint8List$__pigeon_messageChannelSuffix'; final BasicMessageChannel __pigeon_channel = @@ -2668,7 +2663,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([aList]) as List?; + await __pigeon_channel.send([list]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2683,7 +2678,7 @@ class HostIntegrationCoreApi { } Future?> callFlutterEchoNullableList( - List? aList) async { + List? list) async { final String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableList$__pigeon_messageChannelSuffix'; final BasicMessageChannel __pigeon_channel = @@ -2693,7 +2688,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([aList]) as List?; + await __pigeon_channel.send([list]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2883,10 +2878,10 @@ abstract class FlutterIntegrationCoreApi { String echoString(String aString); /// Returns the passed byte list, to test serialization and deserialization. - Uint8List echoUint8List(Uint8List aList); + Uint8List echoUint8List(Uint8List list); /// Returns the passed list, to test serialization and deserialization. - List echoList(List aList); + List echoList(List list); /// Returns the passed map, to test serialization and deserialization. Map echoMap(Map aMap); @@ -2907,10 +2902,10 @@ abstract class FlutterIntegrationCoreApi { String? echoNullableString(String? aString); /// Returns the passed byte list, to test serialization and deserialization. - Uint8List? echoNullableUint8List(Uint8List? aList); + Uint8List? echoNullableUint8List(Uint8List? list); /// Returns the passed list, to test serialization and deserialization. - List? echoNullableList(List? aList); + List? echoNullableList(List? list); /// Returns the passed map, to test serialization and deserialization. Map? echoNullableMap(Map? aMap); @@ -3266,11 +3261,11 @@ abstract class FlutterIntegrationCoreApi { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List was null.'); final List args = (message as List?)!; - final Uint8List? arg_aList = (args[0] as Uint8List?); - assert(arg_aList != null, + final Uint8List? arg_list = (args[0] as Uint8List?); + assert(arg_list != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List was null, expected non-null Uint8List.'); try { - final Uint8List output = api.echoUint8List(arg_aList!); + final Uint8List output = api.echoUint8List(arg_list!); return wrapResponse(result: output); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -3294,12 +3289,12 @@ abstract class FlutterIntegrationCoreApi { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList was null.'); final List args = (message as List?)!; - final List? arg_aList = + final List? arg_list = (args[0] as List?)?.cast(); - assert(arg_aList != null, + assert(arg_list != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList was null, expected non-null List.'); try { - final List output = api.echoList(arg_aList!); + final List output = api.echoList(arg_list!); return wrapResponse(result: output); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -3485,9 +3480,9 @@ abstract class FlutterIntegrationCoreApi { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List was null.'); final List args = (message as List?)!; - final Uint8List? arg_aList = (args[0] as Uint8List?); + final Uint8List? arg_list = (args[0] as Uint8List?); try { - final Uint8List? output = api.echoNullableUint8List(arg_aList); + final Uint8List? output = api.echoNullableUint8List(arg_list); return wrapResponse(result: output); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -3511,10 +3506,10 @@ abstract class FlutterIntegrationCoreApi { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList was null.'); final List args = (message as List?)!; - final List? arg_aList = + final List? arg_list = (args[0] as List?)?.cast(); try { - final List? output = api.echoNullableList(arg_aList); + final List? output = api.echoNullableList(arg_list); return wrapResponse(result: output); } on PlatformException catch (e) { return wrapResponse(error: e); 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 044b792995e0..c4f744b5fb83 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 @@ -130,16 +130,14 @@ class MessageNested { Object encode() { return [ - request?.encode(), + request, ]; } static MessageNested decode(Object result) { result as List; return MessageNested( - request: result[0] != null - ? MessageSearchRequest.decode(result[0]! as List) - : null, + request: result[0] as MessageSearchRequest?, ); } } 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 dcfe61bb0ade..8f3560363e06 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 @@ -106,7 +106,7 @@ class NonNullFieldSearchReply { result, error, indices, - extraData.encode(), + extraData, type.index, ]; } @@ -117,7 +117,7 @@ class NonNullFieldSearchReply { result: result[0]! as String, error: result[1]! as String, indices: (result[2] as List?)!.cast(), - extraData: ExtraData.decode(result[3]! as List), + extraData: result[3]! as ExtraData, type: ReplyType.values[result[4]! as int], ); } 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 940dd315b489..3af44e616836 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 @@ -85,7 +85,7 @@ class NullFieldsSearchReply { result, error, indices, - request?.encode(), + request, type?.index, ]; } @@ -96,9 +96,7 @@ class NullFieldsSearchReply { result: result[0] as String?, error: result[1] as String?, indices: (result[2] as List?)?.cast(), - request: result[3] != null - ? NullFieldsSearchRequest.decode(result[3]! as List) - : null, + request: result[3] as NullFieldsSearchRequest?, type: result[4] != null ? NullFieldsSearchReplyType.values[result[4]! as int] : null, diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/test/null_fields_test.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/test/null_fields_test.dart index 112317a38950..aa0ecb024246 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/test/null_fields_test.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/test/null_fields_test.dart @@ -63,16 +63,17 @@ void main() { }); test('test reply decode with values', () { - final NullFieldsSearchReply reply = NullFieldsSearchReply.decode([ - 'result', - 'error', - [1, 2, 3], - [ - 'query', - 1, - ], - NullFieldsSearchReplyType.success.index, - ]); + final NullFieldsSearchReply reply = + NullFieldsSearchReply.decode(NullFieldsSearchReply( + result: 'result', + error: 'error', + indices: [1, 2, 3], + request: NullFieldsSearchRequest( + query: 'query', + identifier: 1, + ), + type: NullFieldsSearchReplyType.success, + ).encode()); expect(reply.result, 'result'); expect(reply.error, 'error'); @@ -118,11 +119,13 @@ void main() { }); test('test reply encode with values', () { + final NullFieldsSearchRequest request = + NullFieldsSearchRequest(query: 'query', identifier: 1); final NullFieldsSearchReply reply = NullFieldsSearchReply( result: 'result', error: 'error', indices: [1, 2, 3], - request: NullFieldsSearchRequest(query: 'query', identifier: 1), + request: request, type: NullFieldsSearchReplyType.success, ); @@ -130,10 +133,7 @@ void main() { 'result', 'error', [1, 2, 3], - [ - 'query', - 1, - ], + request, NullFieldsSearchReplyType.success.index, ]); }); 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 2d462d760ccb..3668ec947384 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 @@ -4,6 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon +@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass") package com.example.test_plugin @@ -20,10 +21,10 @@ private fun wrapResult(result: Any?): List { } private fun wrapError(exception: Throwable): List { - if (exception is FlutterError) { - return listOf(exception.code, exception.message, exception.details) + return if (exception is FlutterError) { + listOf(exception.code, exception.message, exception.details) } else { - return listOf( + listOf( exception.javaClass.simpleName, exception.toString(), "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception)) @@ -63,28 +64,28 @@ data class AllTypes( val a4ByteArray: IntArray, val a8ByteArray: LongArray, val aFloatArray: DoubleArray, - val aList: List, + val list: List, val aMap: Map, val anEnum: AnEnum, val aString: String, val anObject: Any ) { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): AllTypes { - val aBool = list[0] as Boolean - val anInt = list[1].let { if (it is Int) it.toLong() else it as Long } - val anInt64 = list[2].let { if (it is Int) it.toLong() else it as Long } - val aDouble = list[3] as Double - val aByteArray = list[4] as ByteArray - val a4ByteArray = list[5] as IntArray - val a8ByteArray = list[6] as LongArray - val aFloatArray = list[7] as DoubleArray - val aList = list[8] as List - val aMap = list[9] as Map - val anEnum = AnEnum.ofRaw(list[10] as Int)!! - val aString = list[11] as String - val anObject = list[12] as Any + @Suppress("LocalVariableName") + fun fromList(__pigeon_list: List): AllTypes { + val aBool = __pigeon_list[0] as Boolean + val anInt = __pigeon_list[1].let { num -> if (num is Int) num.toLong() else num as Long } + val anInt64 = __pigeon_list[2].let { num -> if (num is Int) num.toLong() else num as Long } + val aDouble = __pigeon_list[3] as Double + val aByteArray = __pigeon_list[4] as ByteArray + val a4ByteArray = __pigeon_list[5] as IntArray + val a8ByteArray = __pigeon_list[6] as LongArray + val aFloatArray = __pigeon_list[7] as DoubleArray + val list = __pigeon_list[8] as List + val aMap = __pigeon_list[9] as Map + val anEnum = AnEnum.ofRaw(__pigeon_list[10] as Int)!! + val aString = __pigeon_list[11] as String + val anObject = __pigeon_list[12] as Any return AllTypes( aBool, anInt, @@ -94,7 +95,7 @@ data class AllTypes( a4ByteArray, a8ByteArray, aFloatArray, - aList, + list, aMap, anEnum, aString, @@ -112,7 +113,7 @@ data class AllTypes( a4ByteArray, a8ByteArray, aFloatArray, - aList, + list, aMap, anEnum.raw, aString, @@ -146,26 +147,27 @@ data class AllNullableTypes( val allNullableTypes: AllNullableTypes? = null ) { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): AllNullableTypes { - val aNullableBool = list[0] as Boolean? - val aNullableInt = list[1].let { if (it is Int) it.toLong() else it as Long? } - val aNullableInt64 = list[2].let { if (it is Int) it.toLong() else it as Long? } - val aNullableDouble = list[3] as Double? - val aNullableByteArray = list[4] as ByteArray? - val aNullable4ByteArray = list[5] as IntArray? - val aNullable8ByteArray = list[6] as LongArray? - val aNullableFloatArray = list[7] as DoubleArray? - val aNullableList = list[8] as List? - val aNullableMap = list[9] as Map? - val nullableNestedList = list[10] as List?>? - val nullableMapWithAnnotations = list[11] as Map? - val nullableMapWithObject = list[12] as Map? - val aNullableEnum: AnEnum? = (list[13] as Int?)?.let { AnEnum.ofRaw(it) } - val aNullableString = list[14] as String? - val aNullableObject = list[15] - val allNullableTypes: AllNullableTypes? = - (list[16] as List?)?.let { AllNullableTypes.fromList(it) } + @Suppress("LocalVariableName") + fun fromList(__pigeon_list: List): AllNullableTypes { + val aNullableBool = __pigeon_list[0] as Boolean? + val aNullableInt = + __pigeon_list[1].let { num -> if (num is Int) num.toLong() else num as Long? } + val aNullableInt64 = + __pigeon_list[2].let { num -> if (num is Int) num.toLong() else num as Long? } + val aNullableDouble = __pigeon_list[3] as Double? + val aNullableByteArray = __pigeon_list[4] as ByteArray? + val aNullable4ByteArray = __pigeon_list[5] as IntArray? + val aNullable8ByteArray = __pigeon_list[6] as LongArray? + val aNullableFloatArray = __pigeon_list[7] as DoubleArray? + val aNullableList = __pigeon_list[8] as List? + val aNullableMap = __pigeon_list[9] as Map? + val nullableNestedList = __pigeon_list[10] as List?>? + val nullableMapWithAnnotations = __pigeon_list[11] as Map? + val nullableMapWithObject = __pigeon_list[12] as Map? + val aNullableEnum: AnEnum? = (__pigeon_list[13] as Int?)?.let { num -> AnEnum.ofRaw(num) } + val aNullableString = __pigeon_list[14] as String? + val aNullableObject = __pigeon_list[15] + val allNullableTypes = __pigeon_list[16] as AllNullableTypes? return AllNullableTypes( aNullableBool, aNullableInt, @@ -205,7 +207,7 @@ data class AllNullableTypes( aNullableEnum?.raw, aNullableString, aNullableObject, - allNullableTypes?.toList(), + allNullableTypes, ) } } @@ -235,24 +237,26 @@ data class AllNullableTypesWithoutRecursion( val aNullableObject: Any? = null ) { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): AllNullableTypesWithoutRecursion { - val aNullableBool = list[0] as Boolean? - val aNullableInt = list[1].let { if (it is Int) it.toLong() else it as Long? } - val aNullableInt64 = list[2].let { if (it is Int) it.toLong() else it as Long? } - val aNullableDouble = list[3] as Double? - val aNullableByteArray = list[4] as ByteArray? - val aNullable4ByteArray = list[5] as IntArray? - val aNullable8ByteArray = list[6] as LongArray? - val aNullableFloatArray = list[7] as DoubleArray? - val aNullableList = list[8] as List? - val aNullableMap = list[9] as Map? - val nullableNestedList = list[10] as List?>? - val nullableMapWithAnnotations = list[11] as Map? - val nullableMapWithObject = list[12] as Map? - val aNullableEnum: AnEnum? = (list[13] as Int?)?.let { AnEnum.ofRaw(it) } - val aNullableString = list[14] as String? - val aNullableObject = list[15] + @Suppress("LocalVariableName") + fun fromList(__pigeon_list: List): AllNullableTypesWithoutRecursion { + val aNullableBool = __pigeon_list[0] as Boolean? + val aNullableInt = + __pigeon_list[1].let { num -> if (num is Int) num.toLong() else num as Long? } + val aNullableInt64 = + __pigeon_list[2].let { num -> if (num is Int) num.toLong() else num as Long? } + val aNullableDouble = __pigeon_list[3] as Double? + val aNullableByteArray = __pigeon_list[4] as ByteArray? + val aNullable4ByteArray = __pigeon_list[5] as IntArray? + val aNullable8ByteArray = __pigeon_list[6] as LongArray? + val aNullableFloatArray = __pigeon_list[7] as DoubleArray? + val aNullableList = __pigeon_list[8] as List? + val aNullableMap = __pigeon_list[9] as Map? + val nullableNestedList = __pigeon_list[10] as List?>? + val nullableMapWithAnnotations = __pigeon_list[11] as Map? + val nullableMapWithObject = __pigeon_list[12] as Map? + val aNullableEnum: AnEnum? = (__pigeon_list[13] as Int?)?.let { num -> AnEnum.ofRaw(num) } + val aNullableString = __pigeon_list[14] as String? + val aNullableObject = __pigeon_list[15] return AllNullableTypesWithoutRecursion( aNullableBool, aNullableInt, @@ -310,21 +314,20 @@ data class AllClassesWrapper( val allTypes: AllTypes? = null ) { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): AllClassesWrapper { - val allNullableTypes = AllNullableTypes.fromList(list[0] as List) - val allNullableTypesWithoutRecursion: AllNullableTypesWithoutRecursion? = - (list[1] as List?)?.let { AllNullableTypesWithoutRecursion.fromList(it) } - val allTypes: AllTypes? = (list[2] as List?)?.let { AllTypes.fromList(it) } + @Suppress("LocalVariableName") + fun fromList(__pigeon_list: List): AllClassesWrapper { + val allNullableTypes = __pigeon_list[0] as AllNullableTypes + val allNullableTypesWithoutRecursion = __pigeon_list[1] as AllNullableTypesWithoutRecursion? + val allTypes = __pigeon_list[2] as AllTypes? return AllClassesWrapper(allNullableTypes, allNullableTypesWithoutRecursion, allTypes) } } fun toList(): List { return listOf( - allNullableTypes.toList(), - allNullableTypesWithoutRecursion?.toList(), - allTypes?.toList(), + allNullableTypes, + allNullableTypesWithoutRecursion, + allTypes, ) } } @@ -337,9 +340,9 @@ data class AllClassesWrapper( data class TestMessage(val testList: List? = null) { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): TestMessage { - val testList = list[0] as List? + @Suppress("LocalVariableName") + fun fromList(__pigeon_list: List): TestMessage { + val testList = __pigeon_list[0] as List? return TestMessage(testList) } } @@ -351,7 +354,6 @@ data class TestMessage(val testList: List? = null) { } } -@Suppress("UNCHECKED_CAST") private object HostIntegrationCoreApiCodec : StandardMessageCodec() { override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { return when (type) { @@ -433,7 +435,7 @@ interface HostIntegrationCoreApi { /** Returns the passed in generic Object. */ fun echoObject(anObject: Any): Any /** Returns the passed list, to test serialization and deserialization. */ - fun echoList(aList: List): List + fun echoList(list: List): List /** Returns the passed map, to test serialization and deserialization. */ fun echoMap(aMap: Map): Map /** Returns the passed map to test nested class serialization and deserialization. */ @@ -512,7 +514,7 @@ interface HostIntegrationCoreApi { /** Returns the passed in generic Object asynchronously. */ fun echoAsyncObject(anObject: Any, callback: (Result) -> Unit) /** Returns the passed list, to test asynchronous serialization and deserialization. */ - fun echoAsyncList(aList: List, callback: (Result>) -> Unit) + fun echoAsyncList(list: List, callback: (Result>) -> Unit) /** Returns the passed map, to test asynchronous serialization and deserialization. */ fun echoAsyncMap(aMap: Map, callback: (Result>) -> Unit) /** Returns the passed enum, to test asynchronous serialization and deserialization. */ @@ -548,7 +550,7 @@ interface HostIntegrationCoreApi { /** Returns the passed in generic Object asynchronously. */ fun echoAsyncNullableObject(anObject: Any?, callback: (Result) -> Unit) /** Returns the passed list, to test asynchronous serialization and deserialization. */ - fun echoAsyncNullableList(aList: List?, callback: (Result?>) -> Unit) + fun echoAsyncNullableList(list: List?, callback: (Result?>) -> Unit) /** Returns the passed map, to test asynchronous serialization and deserialization. */ fun echoAsyncNullableMap( aMap: Map?, @@ -597,9 +599,9 @@ interface HostIntegrationCoreApi { fun callFlutterEchoString(aString: String, callback: (Result) -> Unit) - fun callFlutterEchoUint8List(aList: ByteArray, callback: (Result) -> Unit) + fun callFlutterEchoUint8List(list: ByteArray, callback: (Result) -> Unit) - fun callFlutterEchoList(aList: List, callback: (Result>) -> Unit) + fun callFlutterEchoList(list: List, callback: (Result>) -> Unit) fun callFlutterEchoMap(aMap: Map, callback: (Result>) -> Unit) @@ -613,9 +615,9 @@ interface HostIntegrationCoreApi { fun callFlutterEchoNullableString(aString: String?, callback: (Result) -> Unit) - fun callFlutterEchoNullableUint8List(aList: ByteArray?, callback: (Result) -> Unit) + fun callFlutterEchoNullableUint8List(list: ByteArray?, callback: (Result) -> Unit) - fun callFlutterEchoNullableList(aList: List?, callback: (Result?>) -> Unit) + fun callFlutterEchoNullableList(list: List?, callback: (Result?>) -> Unit) fun callFlutterEchoNullableMap( aMap: Map?, @@ -633,7 +635,6 @@ interface HostIntegrationCoreApi { * Sets up an instance of `HostIntegrationCoreApi` to handle messages through the * `binaryMessenger`. */ - @Suppress("UNCHECKED_CAST") fun setUp( binaryMessenger: BinaryMessenger, api: HostIntegrationCoreApi?, @@ -649,13 +650,13 @@ interface HostIntegrationCoreApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - var wrapped: List - try { - api.noop() - wrapped = listOf(null) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + api.noop() + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -672,12 +673,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val everythingArg = args[0] as AllTypes - var wrapped: List - try { - wrapped = listOf(api.echoAllTypes(everythingArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoAllTypes(everythingArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -692,12 +693,12 @@ interface HostIntegrationCoreApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - var wrapped: List - try { - wrapped = listOf(api.throwError()) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.throwError()) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -712,13 +713,13 @@ interface HostIntegrationCoreApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - var wrapped: List - try { - api.throwErrorFromVoid() - wrapped = listOf(null) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + api.throwErrorFromVoid() + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -733,12 +734,12 @@ interface HostIntegrationCoreApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - var wrapped: List - try { - wrapped = listOf(api.throwFlutterError()) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.throwFlutterError()) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -754,13 +755,13 @@ interface HostIntegrationCoreApi { 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.echoInt(anIntArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val anIntArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long } + val wrapped: List = + try { + listOf(api.echoInt(anIntArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -777,12 +778,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aDoubleArg = args[0] as Double - var wrapped: List - try { - wrapped = listOf(api.echoDouble(aDoubleArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoDouble(aDoubleArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -799,12 +800,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aBoolArg = args[0] as Boolean - var wrapped: List - try { - wrapped = listOf(api.echoBool(aBoolArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoBool(aBoolArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -821,12 +822,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aStringArg = args[0] as String - var wrapped: List - try { - wrapped = listOf(api.echoString(aStringArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoString(aStringArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -843,12 +844,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aUint8ListArg = args[0] as ByteArray - var wrapped: List - try { - wrapped = listOf(api.echoUint8List(aUint8ListArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoUint8List(aUint8ListArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -865,12 +866,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val anObjectArg = args[0] as Any - var wrapped: List - try { - wrapped = listOf(api.echoObject(anObjectArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoObject(anObjectArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -886,13 +887,13 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val aListArg = args[0] as List - var wrapped: List - try { - wrapped = listOf(api.echoList(aListArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val listArg = args[0] as List + val wrapped: List = + try { + listOf(api.echoList(listArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -909,12 +910,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aMapArg = args[0] as Map - var wrapped: List - try { - wrapped = listOf(api.echoMap(aMapArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoMap(aMapArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -931,12 +932,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val wrapperArg = args[0] as AllClassesWrapper - var wrapped: List - try { - wrapped = listOf(api.echoClassWrapper(wrapperArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoClassWrapper(wrapperArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -953,12 +954,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val anEnumArg = AnEnum.ofRaw(args[0] as Int)!! - var wrapped: List - try { - wrapped = listOf(api.echoEnum(anEnumArg).raw) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoEnum(anEnumArg).raw) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -975,12 +976,12 @@ interface HostIntegrationCoreApi { 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) - } + val wrapped: List = + try { + listOf(api.echoNamedDefaultString(aStringArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -997,12 +998,12 @@ interface HostIntegrationCoreApi { 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) - } + val wrapped: List = + try { + listOf(api.echoOptionalDefaultDouble(aDoubleArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1018,13 +1019,13 @@ interface HostIntegrationCoreApi { 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) - } + val anIntArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long } + val wrapped: List = + try { + listOf(api.echoRequiredInt(anIntArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1041,12 +1042,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val everythingArg = args[0] as AllNullableTypes? - var wrapped: List - try { - wrapped = listOf(api.echoAllNullableTypes(everythingArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoAllNullableTypes(everythingArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1063,12 +1064,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val everythingArg = args[0] as AllNullableTypesWithoutRecursion? - var wrapped: List - try { - wrapped = listOf(api.echoAllNullableTypesWithoutRecursion(everythingArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoAllNullableTypesWithoutRecursion(everythingArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1085,12 +1086,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val wrapperArg = args[0] as AllClassesWrapper - var wrapped: List - try { - wrapped = listOf(api.extractNestedNullableString(wrapperArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.extractNestedNullableString(wrapperArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1107,12 +1108,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val nullableStringArg = args[0] as String? - var wrapped: List - try { - wrapped = listOf(api.createNestedNullableString(nullableStringArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.createNestedNullableString(nullableStringArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1129,17 +1130,17 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableBoolArg = args[0] as Boolean? - val aNullableIntArg = args[1].let { if (it is Int) it.toLong() else it as Long? } + val aNullableIntArg = + args[1].let { num -> if (num is Int) num.toLong() else num as Long? } val aNullableStringArg = args[2] as String? - var wrapped: List - try { - wrapped = + val wrapped: List = + try { listOf( api.sendMultipleNullableTypes( aNullableBoolArg, aNullableIntArg, aNullableStringArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1156,17 +1157,17 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableBoolArg = args[0] as Boolean? - val aNullableIntArg = args[1].let { if (it is Int) it.toLong() else it as Long? } + val aNullableIntArg = + args[1].let { num -> if (num is Int) num.toLong() else num as Long? } val aNullableStringArg = args[2] as String? - var wrapped: List - try { - wrapped = + val wrapped: List = + try { listOf( api.sendMultipleNullableTypesWithoutRecursion( aNullableBoolArg, aNullableIntArg, aNullableStringArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1182,13 +1183,14 @@ interface HostIntegrationCoreApi { 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.echoNullableInt(aNullableIntArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val aNullableIntArg = + args[0].let { num -> if (num is Int) num.toLong() else num as Long? } + val wrapped: List = + try { + listOf(api.echoNullableInt(aNullableIntArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1205,12 +1207,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableDoubleArg = args[0] as Double? - var wrapped: List - try { - wrapped = listOf(api.echoNullableDouble(aNullableDoubleArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoNullableDouble(aNullableDoubleArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1227,12 +1229,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableBoolArg = args[0] as Boolean? - var wrapped: List - try { - wrapped = listOf(api.echoNullableBool(aNullableBoolArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoNullableBool(aNullableBoolArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1249,12 +1251,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableStringArg = args[0] as String? - var wrapped: List - try { - wrapped = listOf(api.echoNullableString(aNullableStringArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoNullableString(aNullableStringArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1271,12 +1273,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableUint8ListArg = args[0] as ByteArray? - var wrapped: List - try { - wrapped = listOf(api.echoNullableUint8List(aNullableUint8ListArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoNullableUint8List(aNullableUint8ListArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1293,12 +1295,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableObjectArg = args[0] - var wrapped: List - try { - wrapped = listOf(api.echoNullableObject(aNullableObjectArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoNullableObject(aNullableObjectArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1315,12 +1317,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableListArg = args[0] as List? - var wrapped: List - try { - wrapped = listOf(api.echoNullableList(aNullableListArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoNullableList(aNullableListArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1337,12 +1339,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableMapArg = args[0] as Map? - var wrapped: List - try { - wrapped = listOf(api.echoNullableMap(aNullableMapArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoNullableMap(aNullableMapArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1359,12 +1361,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val anEnumArg = if (args[0] == null) null else AnEnum.ofRaw(args[0] as Int) - var wrapped: List - try { - wrapped = listOf(api.echoNullableEnum(anEnumArg)?.raw) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoNullableEnum(anEnumArg)?.raw) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1380,13 +1382,14 @@ interface HostIntegrationCoreApi { 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) - } + val aNullableIntArg = + args[0].let { num -> if (num is Int) num.toLong() else num as Long? } + val wrapped: List = + try { + listOf(api.echoOptionalNullableInt(aNullableIntArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1403,12 +1406,12 @@ interface HostIntegrationCoreApi { 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) - } + val wrapped: List = + try { + listOf(api.echoNamedNullableString(aNullableStringArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1445,7 +1448,7 @@ interface HostIntegrationCoreApi { 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 } + val anIntArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long } api.echoAsyncInt(anIntArg) { result: Result -> val error = result.exceptionOrNull() if (error != null) { @@ -1589,8 +1592,8 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val aListArg = args[0] as List - api.echoAsyncList(aListArg) { result: Result> -> + val listArg = args[0] as List + api.echoAsyncList(listArg) { result: Result> -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -1800,7 +1803,7 @@ interface HostIntegrationCoreApi { 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? } + val anIntArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long? } api.echoAsyncNullableInt(anIntArg) { result: Result -> val error = result.exceptionOrNull() if (error != null) { @@ -1944,8 +1947,8 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val aListArg = args[0] as List? - api.echoAsyncNullableList(aListArg) { result: Result?> -> + val listArg = args[0] as List? + api.echoAsyncNullableList(listArg) { result: Result?> -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -2130,7 +2133,8 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableBoolArg = args[0] as Boolean? - val aNullableIntArg = args[1].let { if (it is Int) it.toLong() else it as Long? } + val aNullableIntArg = + args[1].let { num -> if (num is Int) num.toLong() else num as Long? } val aNullableStringArg = args[2] as String? api.callFlutterSendMultipleNullableTypes( aNullableBoolArg, aNullableIntArg, aNullableStringArg) { @@ -2183,7 +2187,8 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableBoolArg = args[0] as Boolean? - val aNullableIntArg = args[1].let { if (it is Int) it.toLong() else it as Long? } + val aNullableIntArg = + args[1].let { num -> if (num is Int) num.toLong() else num as Long? } val aNullableStringArg = args[2] as String? api.callFlutterSendMultipleNullableTypesWithoutRecursion( aNullableBoolArg, aNullableIntArg, aNullableStringArg) { @@ -2234,7 +2239,7 @@ interface HostIntegrationCoreApi { 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 } + val anIntArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long } api.callFlutterEchoInt(anIntArg) { result: Result -> val error = result.exceptionOrNull() if (error != null) { @@ -2306,8 +2311,8 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val aListArg = args[0] as ByteArray - api.callFlutterEchoUint8List(aListArg) { result: Result -> + val listArg = args[0] as ByteArray + api.callFlutterEchoUint8List(listArg) { result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -2330,8 +2335,8 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val aListArg = args[0] as List - api.callFlutterEchoList(aListArg) { result: Result> -> + val listArg = args[0] as List + api.callFlutterEchoList(listArg) { result: Result> -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -2426,7 +2431,7 @@ interface HostIntegrationCoreApi { 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? } + val anIntArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long? } api.callFlutterEchoNullableInt(anIntArg) { result: Result -> val error = result.exceptionOrNull() if (error != null) { @@ -2498,8 +2503,8 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val aListArg = args[0] as ByteArray? - api.callFlutterEchoNullableUint8List(aListArg) { result: Result -> + val listArg = args[0] as ByteArray? + api.callFlutterEchoNullableUint8List(listArg) { result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -2522,8 +2527,8 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val aListArg = args[0] as List? - api.callFlutterEchoNullableList(aListArg) { result: Result?> -> + val listArg = args[0] as List? + api.callFlutterEchoNullableList(listArg) { result: Result?> -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -2613,7 +2618,6 @@ interface HostIntegrationCoreApi { } } -@Suppress("UNCHECKED_CAST") private object FlutterIntegrationCoreApiCodec : StandardMessageCodec() { override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { return when (type) { @@ -2671,7 +2675,6 @@ private object FlutterIntegrationCoreApiCodec : StandardMessageCodec() { * * Generated class from Pigeon that represents Flutter messages that can be called from Kotlin. */ -@Suppress("UNCHECKED_CAST") class FlutterIntegrationCoreApi( private val binaryMessenger: BinaryMessenger, private val messageChannelSuffix: String = "" @@ -2929,7 +2932,7 @@ class FlutterIntegrationCoreApi( "Flutter api returned null value for non-null return value.", ""))) } else { - val output = it[0].let { if (it is Int) it.toLong() else it as Long } + val output = it[0].let { num -> if (num is Int) num.toLong() else num as Long } callback(Result.success(output)) } } else { @@ -2992,13 +2995,13 @@ class FlutterIntegrationCoreApi( } } /** Returns the passed byte list, to test serialization and deserialization. */ - fun echoUint8List(aListArg: ByteArray, callback: (Result) -> Unit) { + fun echoUint8List(listArg: ByteArray, callback: (Result) -> Unit) { val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List$separatedMessageChannelSuffix" val channel = BasicMessageChannel(binaryMessenger, channelName, codec) - channel.send(listOf(aListArg)) { + channel.send(listOf(listArg)) { if (it is List<*>) { if (it.size > 1) { callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) @@ -3019,13 +3022,13 @@ class FlutterIntegrationCoreApi( } } /** Returns the passed list, to test serialization and deserialization. */ - fun echoList(aListArg: List, callback: (Result>) -> Unit) { + fun echoList(listArg: List, callback: (Result>) -> Unit) { val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList$separatedMessageChannelSuffix" val channel = BasicMessageChannel(binaryMessenger, channelName, codec) - channel.send(listOf(aListArg)) { + channel.send(listOf(listArg)) { if (it is List<*>) { if (it.size > 1) { callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) @@ -3131,7 +3134,7 @@ class FlutterIntegrationCoreApi( if (it.size > 1) { callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else { - val output = it[0].let { if (it is Int) it.toLong() else it as Long? } + val output = it[0].let { num -> if (num is Int) num.toLong() else num as Long? } callback(Result.success(output)) } } else { @@ -3180,13 +3183,13 @@ class FlutterIntegrationCoreApi( } } /** Returns the passed byte list, to test serialization and deserialization. */ - fun echoNullableUint8List(aListArg: ByteArray?, callback: (Result) -> Unit) { + fun echoNullableUint8List(listArg: ByteArray?, callback: (Result) -> Unit) { val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List$separatedMessageChannelSuffix" val channel = BasicMessageChannel(binaryMessenger, channelName, codec) - channel.send(listOf(aListArg)) { + channel.send(listOf(listArg)) { if (it is List<*>) { if (it.size > 1) { callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) @@ -3200,13 +3203,13 @@ class FlutterIntegrationCoreApi( } } /** Returns the passed list, to test serialization and deserialization. */ - fun echoNullableList(aListArg: List?, callback: (Result?>) -> Unit) { + fun echoNullableList(listArg: List?, callback: (Result?>) -> Unit) { val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList$separatedMessageChannelSuffix" val channel = BasicMessageChannel(binaryMessenger, channelName, codec) - channel.send(listOf(aListArg)) { + channel.send(listOf(listArg)) { if (it is List<*>) { if (it.size > 1) { callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) @@ -3254,7 +3257,7 @@ class FlutterIntegrationCoreApi( if (it.size > 1) { callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else { - val output = (it[0] as Int?)?.let { AnEnum.ofRaw(it) } + val output = (it[0] as Int?)?.let { num -> AnEnum.ofRaw(num) } callback(Result.success(output)) } } else { @@ -3324,7 +3327,6 @@ interface HostTrivialApi { /** The codec used by HostTrivialApi. */ val codec: MessageCodec by lazy { StandardMessageCodec() } /** Sets up an instance of `HostTrivialApi` to handle messages through the `binaryMessenger`. */ - @Suppress("UNCHECKED_CAST") fun setUp( binaryMessenger: BinaryMessenger, api: HostTrivialApi?, @@ -3340,13 +3342,13 @@ interface HostTrivialApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - var wrapped: List - try { - api.noop() - wrapped = listOf(null) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + api.noop() + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -3370,7 +3372,6 @@ interface HostSmallApi { /** The codec used by HostSmallApi. */ val codec: MessageCodec by lazy { StandardMessageCodec() } /** Sets up an instance of `HostSmallApi` to handle messages through the `binaryMessenger`. */ - @Suppress("UNCHECKED_CAST") fun setUp( binaryMessenger: BinaryMessenger, api: HostSmallApi?, @@ -3427,7 +3428,6 @@ interface HostSmallApi { } } -@Suppress("UNCHECKED_CAST") private object FlutterSmallApiCodec : StandardMessageCodec() { override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { return when (type) { @@ -3454,7 +3454,6 @@ private object FlutterSmallApiCodec : StandardMessageCodec() { * * Generated class from Pigeon that represents Flutter messages that can be called from Kotlin. */ -@Suppress("UNCHECKED_CAST") class FlutterSmallApi( private val binaryMessenger: BinaryMessenger, private val messageChannelSuffix: String = "" 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 8453a1cae2c3..97236e316bb3 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 @@ -80,8 +80,8 @@ class TestPlugin : FlutterPlugin, HostIntegrationCoreApi { return anObject } - override fun echoList(aList: List): List { - return aList + override fun echoList(list: List): List { + return list } override fun echoMap(aMap: Map): Map { @@ -240,8 +240,8 @@ class TestPlugin : FlutterPlugin, HostIntegrationCoreApi { callback(Result.success(anObject)) } - override fun echoAsyncList(aList: List, callback: (Result>) -> Unit) { - callback(Result.success(aList)) + override fun echoAsyncList(list: List, callback: (Result>) -> Unit) { + callback(Result.success(list)) } override fun echoAsyncMap( @@ -282,8 +282,8 @@ class TestPlugin : FlutterPlugin, HostIntegrationCoreApi { callback(Result.success(anObject)) } - override fun echoAsyncNullableList(aList: List?, callback: (Result?>) -> Unit) { - callback(Result.success(aList)) + override fun echoAsyncNullableList(list: List?, callback: (Result?>) -> Unit) { + callback(Result.success(list)) } override fun echoAsyncNullableMap( @@ -359,12 +359,12 @@ class TestPlugin : FlutterPlugin, HostIntegrationCoreApi { flutterApi!!.echoString(aString) { echo -> callback(echo) } } - override fun callFlutterEchoUint8List(aList: ByteArray, callback: (Result) -> Unit) { - flutterApi!!.echoUint8List(aList) { echo -> callback(echo) } + override fun callFlutterEchoUint8List(list: ByteArray, callback: (Result) -> Unit) { + flutterApi!!.echoUint8List(list) { echo -> callback(echo) } } - override fun callFlutterEchoList(aList: List, callback: (Result>) -> Unit) { - flutterApi!!.echoList(aList) { echo -> callback(echo) } + override fun callFlutterEchoList(list: List, callback: (Result>) -> Unit) { + flutterApi!!.echoList(list) { echo -> callback(echo) } } override fun callFlutterEchoMap( @@ -408,17 +408,17 @@ class TestPlugin : FlutterPlugin, HostIntegrationCoreApi { } override fun callFlutterEchoNullableUint8List( - aList: ByteArray?, + list: ByteArray?, callback: (Result) -> Unit ) { - flutterApi!!.echoNullableUint8List(aList) { echo -> callback(echo) } + flutterApi!!.echoNullableUint8List(list) { echo -> callback(echo) } } override fun callFlutterEchoNullableList( - aList: List?, + list: List?, callback: (Result?>) -> Unit ) { - flutterApi!!.echoNullableList(aList) { echo -> callback(echo) } + flutterApi!!.echoNullableList(list) { echo -> callback(echo) } } override fun callFlutterEchoNullableMap( diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt index 81207b03f586..2560efb65b2c 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt @@ -27,7 +27,7 @@ internal class AllDatatypesTest : TestCase() { assertTrue(firstTypes.a4ByteArray.contentEquals(secondTypes.a4ByteArray)) assertTrue(firstTypes.a8ByteArray.contentEquals(secondTypes.a8ByteArray)) assertTrue(firstTypes.aFloatArray.contentEquals(secondTypes.aFloatArray)) - assertEquals(firstTypes.aList, secondTypes.aList) + assertEquals(firstTypes.list, secondTypes.list) assertEquals(firstTypes.aMap, secondTypes.aMap) assertEquals(firstTypes.anEnum, secondTypes.anEnum) assertEquals(firstTypes.anObject, secondTypes.anObject) 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 f02daf701672..717985e7a4bc 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 @@ -69,26 +69,29 @@ struct AllTypes { var a4ByteArray: FlutterStandardTypedData var a8ByteArray: FlutterStandardTypedData var aFloatArray: FlutterStandardTypedData - var aList: [Any?] + var list: [Any?] var aMap: [AnyHashable: Any?] var anEnum: AnEnum var aString: String var anObject: Any - static func fromList(_ list: [Any?]) -> AllTypes? { - let aBool = list[0] as! Bool - let anInt = list[1] is Int64 ? list[1] as! Int64 : Int64(list[1] as! Int32) - let anInt64 = list[2] is Int64 ? list[2] as! Int64 : Int64(list[2] as! Int32) - let aDouble = list[3] as! Double - let aByteArray = list[4] as! FlutterStandardTypedData - let a4ByteArray = list[5] as! FlutterStandardTypedData - let a8ByteArray = list[6] as! FlutterStandardTypedData - let aFloatArray = list[7] as! FlutterStandardTypedData - let aList = list[8] as! [Any?] - let aMap = list[9] as! [AnyHashable: Any?] - let anEnum = AnEnum(rawValue: list[10] as! Int)! - let aString = list[11] as! String - let anObject = list[12]! + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> AllTypes? { + let aBool = __pigeon_list[0] as! Bool + let anInt = + __pigeon_list[1] is Int64 ? __pigeon_list[1] as! Int64 : Int64(__pigeon_list[1] as! Int32) + let anInt64 = + __pigeon_list[2] is Int64 ? __pigeon_list[2] as! Int64 : Int64(__pigeon_list[2] as! Int32) + let aDouble = __pigeon_list[3] as! Double + let aByteArray = __pigeon_list[4] as! FlutterStandardTypedData + let a4ByteArray = __pigeon_list[5] as! FlutterStandardTypedData + let a8ByteArray = __pigeon_list[6] as! FlutterStandardTypedData + let aFloatArray = __pigeon_list[7] as! FlutterStandardTypedData + let list = __pigeon_list[8] as! [Any?] + let aMap = __pigeon_list[9] as! [AnyHashable: Any?] + let anEnum = AnEnum(rawValue: __pigeon_list[10] as! Int)! + let aString = __pigeon_list[11] as! String + let anObject = __pigeon_list[12]! return AllTypes( aBool: aBool, @@ -99,7 +102,7 @@ struct AllTypes { a4ByteArray: a4ByteArray, a8ByteArray: a8ByteArray, aFloatArray: aFloatArray, - aList: aList, + list: list, aMap: aMap, anEnum: anEnum, aString: aString, @@ -116,7 +119,7 @@ struct AllTypes { a4ByteArray, a8ByteArray, aFloatArray, - aList, + list, aMap, anEnum.rawValue, aString, @@ -184,33 +187,37 @@ class AllNullableTypes { var aNullableObject: Any? var allNullableTypes: AllNullableTypes? - static func fromList(_ list: [Any?]) -> AllNullableTypes? { - let aNullableBool: Bool? = nilOrValue(list[0]) + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> AllNullableTypes? { + let aNullableBool: Bool? = nilOrValue(__pigeon_list[0]) let aNullableInt: Int64? = - isNullish(list[1]) ? nil : (list[1] is Int64? ? list[1] as! Int64? : Int64(list[1] as! Int32)) + isNullish(__pigeon_list[1]) + ? nil + : (__pigeon_list[1] is Int64? + ? __pigeon_list[1] as! Int64? : Int64(__pigeon_list[1] as! Int32)) let aNullableInt64: Int64? = - isNullish(list[2]) ? nil : (list[2] is Int64? ? list[2] as! Int64? : Int64(list[2] as! Int32)) - let aNullableDouble: Double? = nilOrValue(list[3]) - let aNullableByteArray: FlutterStandardTypedData? = nilOrValue(list[4]) - let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(list[5]) - let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(list[6]) - let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(list[7]) - let aNullableList: [Any?]? = nilOrValue(list[8]) - let aNullableMap: [AnyHashable: Any?]? = nilOrValue(list[9]) - let nullableNestedList: [[Bool?]?]? = nilOrValue(list[10]) - let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(list[11]) - let nullableMapWithObject: [String?: Any?]? = nilOrValue(list[12]) + isNullish(__pigeon_list[2]) + ? nil + : (__pigeon_list[2] is Int64? + ? __pigeon_list[2] as! Int64? : Int64(__pigeon_list[2] as! Int32)) + let aNullableDouble: Double? = nilOrValue(__pigeon_list[3]) + let aNullableByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[4]) + let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[5]) + let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[6]) + let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[7]) + let aNullableList: [Any?]? = nilOrValue(__pigeon_list[8]) + let aNullableMap: [AnyHashable: Any?]? = nilOrValue(__pigeon_list[9]) + let nullableNestedList: [[Bool?]?]? = nilOrValue(__pigeon_list[10]) + let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(__pigeon_list[11]) + let nullableMapWithObject: [String?: Any?]? = nilOrValue(__pigeon_list[12]) var aNullableEnum: AnEnum? = nil - let aNullableEnumEnumVal: Int? = nilOrValue(list[13]) + let aNullableEnumEnumVal: Int? = nilOrValue(__pigeon_list[13]) if let aNullableEnumRawValue = aNullableEnumEnumVal { aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue)! } - let aNullableString: String? = nilOrValue(list[14]) - let aNullableObject: Any? = list[15] - var allNullableTypes: AllNullableTypes? = nil - if let allNullableTypesList: [Any?] = nilOrValue(list[16]) { - allNullableTypes = AllNullableTypes.fromList(allNullableTypesList) - } + let aNullableString: String? = nilOrValue(__pigeon_list[14]) + let aNullableObject: Any? = __pigeon_list[15] + let allNullableTypes: AllNullableTypes? = nilOrValue(__pigeon_list[16]) return AllNullableTypes( aNullableBool: aNullableBool, @@ -250,7 +257,7 @@ class AllNullableTypes { aNullableEnum?.rawValue, aNullableString, aNullableObject, - allNullableTypes?.toList(), + allNullableTypes, ] } } @@ -278,29 +285,36 @@ struct AllNullableTypesWithoutRecursion { var aNullableString: String? = nil var aNullableObject: Any? = nil - static func fromList(_ list: [Any?]) -> AllNullableTypesWithoutRecursion? { - let aNullableBool: Bool? = nilOrValue(list[0]) + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> AllNullableTypesWithoutRecursion? { + let aNullableBool: Bool? = nilOrValue(__pigeon_list[0]) let aNullableInt: Int64? = - isNullish(list[1]) ? nil : (list[1] is Int64? ? list[1] as! Int64? : Int64(list[1] as! Int32)) + isNullish(__pigeon_list[1]) + ? nil + : (__pigeon_list[1] is Int64? + ? __pigeon_list[1] as! Int64? : Int64(__pigeon_list[1] as! Int32)) let aNullableInt64: Int64? = - isNullish(list[2]) ? nil : (list[2] is Int64? ? list[2] as! Int64? : Int64(list[2] as! Int32)) - let aNullableDouble: Double? = nilOrValue(list[3]) - let aNullableByteArray: FlutterStandardTypedData? = nilOrValue(list[4]) - let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(list[5]) - let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(list[6]) - let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(list[7]) - let aNullableList: [Any?]? = nilOrValue(list[8]) - let aNullableMap: [AnyHashable: Any?]? = nilOrValue(list[9]) - let nullableNestedList: [[Bool?]?]? = nilOrValue(list[10]) - let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(list[11]) - let nullableMapWithObject: [String?: Any?]? = nilOrValue(list[12]) + isNullish(__pigeon_list[2]) + ? nil + : (__pigeon_list[2] is Int64? + ? __pigeon_list[2] as! Int64? : Int64(__pigeon_list[2] as! Int32)) + let aNullableDouble: Double? = nilOrValue(__pigeon_list[3]) + let aNullableByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[4]) + let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[5]) + let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[6]) + let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[7]) + let aNullableList: [Any?]? = nilOrValue(__pigeon_list[8]) + let aNullableMap: [AnyHashable: Any?]? = nilOrValue(__pigeon_list[9]) + let nullableNestedList: [[Bool?]?]? = nilOrValue(__pigeon_list[10]) + let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(__pigeon_list[11]) + let nullableMapWithObject: [String?: Any?]? = nilOrValue(__pigeon_list[12]) var aNullableEnum: AnEnum? = nil - let aNullableEnumEnumVal: Int? = nilOrValue(list[13]) + let aNullableEnumEnumVal: Int? = nilOrValue(__pigeon_list[13]) if let aNullableEnumRawValue = aNullableEnumEnumVal { aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue)! } - let aNullableString: String? = nilOrValue(list[14]) - let aNullableObject: Any? = list[15] + let aNullableString: String? = nilOrValue(__pigeon_list[14]) + let aNullableObject: Any? = __pigeon_list[15] return AllNullableTypesWithoutRecursion( aNullableBool: aNullableBool, @@ -355,17 +369,12 @@ struct AllClassesWrapper { var allNullableTypesWithoutRecursion: AllNullableTypesWithoutRecursion? = nil var allTypes: AllTypes? = nil - static func fromList(_ list: [Any?]) -> AllClassesWrapper? { - let allNullableTypes = AllNullableTypes.fromList(list[0] as! [Any?])! - var allNullableTypesWithoutRecursion: AllNullableTypesWithoutRecursion? = nil - if let allNullableTypesWithoutRecursionList: [Any?] = nilOrValue(list[1]) { - allNullableTypesWithoutRecursion = AllNullableTypesWithoutRecursion.fromList( - allNullableTypesWithoutRecursionList) - } - var allTypes: AllTypes? = nil - if let allTypesList: [Any?] = nilOrValue(list[2]) { - allTypes = AllTypes.fromList(allTypesList) - } + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> AllClassesWrapper? { + let allNullableTypes = __pigeon_list[0] as! AllNullableTypes + let allNullableTypesWithoutRecursion: AllNullableTypesWithoutRecursion? = nilOrValue( + __pigeon_list[1]) + let allTypes: AllTypes? = nilOrValue(__pigeon_list[2]) return AllClassesWrapper( allNullableTypes: allNullableTypes, @@ -375,9 +384,9 @@ struct AllClassesWrapper { } func toList() -> [Any?] { return [ - allNullableTypes.toList(), - allNullableTypesWithoutRecursion?.toList(), - allTypes?.toList(), + allNullableTypes, + allNullableTypesWithoutRecursion, + allTypes, ] } } @@ -388,8 +397,9 @@ struct AllClassesWrapper { struct TestMessage { var testList: [Any?]? = nil - static func fromList(_ list: [Any?]) -> TestMessage? { - let testList: [Any?]? = nilOrValue(list[0]) + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> TestMessage? { + let testList: [Any?]? = nilOrValue(__pigeon_list[0]) return TestMessage( testList: testList @@ -488,7 +498,7 @@ protocol HostIntegrationCoreApi { /// Returns the passed in generic Object. func echo(_ anObject: Any) throws -> Any /// Returns the passed list, to test serialization and deserialization. - func echo(_ aList: [Any?]) throws -> [Any?] + func echo(_ list: [Any?]) throws -> [Any?] /// Returns the passed map, to test serialization and deserialization. func echo(_ aMap: [String?: Any?]) throws -> [String?: Any?] /// Returns the passed map to test nested class serialization and deserialization. @@ -559,7 +569,7 @@ protocol HostIntegrationCoreApi { /// Returns the passed in generic Object asynchronously. func echoAsync(_ anObject: Any, completion: @escaping (Result) -> Void) /// Returns the passed list, to test asynchronous serialization and deserialization. - func echoAsync(_ aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) + func echoAsync(_ list: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) /// Returns the passed map, to test asynchronous serialization and deserialization. func echoAsync( _ aMap: [String?: Any?], completion: @escaping (Result<[String?: Any?], Error>) -> Void) @@ -596,7 +606,7 @@ protocol HostIntegrationCoreApi { /// Returns the passed in generic Object asynchronously. func echoAsyncNullable(_ anObject: Any?, completion: @escaping (Result) -> Void) /// Returns the passed list, to test asynchronous serialization and deserialization. - func echoAsyncNullable(_ aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) + func echoAsyncNullable(_ list: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) /// Returns the passed map, to test asynchronous serialization and deserialization. func echoAsyncNullable( _ aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) @@ -624,9 +634,9 @@ protocol HostIntegrationCoreApi { func callFlutterEcho(_ aDouble: Double, completion: @escaping (Result) -> Void) func callFlutterEcho(_ aString: String, completion: @escaping (Result) -> Void) func callFlutterEcho( - _ aList: FlutterStandardTypedData, + _ list: FlutterStandardTypedData, completion: @escaping (Result) -> Void) - func callFlutterEcho(_ aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) + func callFlutterEcho(_ list: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) func callFlutterEcho( _ aMap: [String?: Any?], completion: @escaping (Result<[String?: Any?], Error>) -> Void) func callFlutterEcho(_ anEnum: AnEnum, completion: @escaping (Result) -> Void) @@ -638,10 +648,10 @@ protocol HostIntegrationCoreApi { func callFlutterEchoNullable( _ aString: String?, completion: @escaping (Result) -> Void) func callFlutterEchoNullable( - _ aList: FlutterStandardTypedData?, + _ list: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) func callFlutterEchoNullable( - _ aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) + _ list: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) func callFlutterEchoNullable( _ aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) func callFlutterNullableEcho( @@ -870,9 +880,9 @@ class HostIntegrationCoreApiSetup { if let api = api { echoListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg = args[0] as! [Any?] + let listArg = args[0] as! [Any?] do { - let result = try api.echo(aListArg) + let result = try api.echo(listArg) reply(wrapResult(result)) } catch { reply(wrapError(error)) @@ -1487,8 +1497,8 @@ class HostIntegrationCoreApiSetup { if let api = api { echoAsyncListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg = args[0] as! [Any?] - api.echoAsync(aListArg) { result in + let listArg = args[0] as! [Any?] + api.echoAsync(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -1798,8 +1808,8 @@ class HostIntegrationCoreApiSetup { if let api = api { echoAsyncNullableListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg: [Any?]? = nilOrValue(args[0]) - api.echoAsyncNullable(aListArg) { result in + let listArg: [Any?]? = nilOrValue(args[0]) + api.echoAsyncNullable(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2107,8 +2117,8 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoUint8ListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg = args[0] as! FlutterStandardTypedData - api.callFlutterEcho(aListArg) { result in + let listArg = args[0] as! FlutterStandardTypedData + api.callFlutterEcho(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2127,8 +2137,8 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg = args[0] as! [Any?] - api.callFlutterEcho(aListArg) { result in + let listArg = args[0] as! [Any?] + api.callFlutterEcho(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2269,8 +2279,8 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoNullableUint8ListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg: FlutterStandardTypedData? = nilOrValue(args[0]) - api.callFlutterEchoNullable(aListArg) { result in + let listArg: FlutterStandardTypedData? = nilOrValue(args[0]) + api.callFlutterEchoNullable(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2289,8 +2299,8 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoNullableListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg: [Any?]? = nilOrValue(args[0]) - api.callFlutterEchoNullable(aListArg) { result in + let listArg: [Any?]? = nilOrValue(args[0]) + api.callFlutterEchoNullable(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2468,10 +2478,10 @@ protocol FlutterIntegrationCoreApiProtocol { func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) /// Returns the passed byte list, to test serialization and deserialization. func echo( - _ aListArg: FlutterStandardTypedData, + _ listArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void) /// Returns the passed list, to test serialization and deserialization. - func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) + func echo(_ listArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) /// Returns the passed map, to test serialization and deserialization. func echo( _ aMapArg: [String?: Any?], @@ -2491,11 +2501,11 @@ protocol FlutterIntegrationCoreApiProtocol { _ aStringArg: String?, completion: @escaping (Result) -> Void) /// Returns the passed byte list, to test serialization and deserialization. func echoNullable( - _ aListArg: FlutterStandardTypedData?, + _ listArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) /// Returns the passed list, to test serialization and deserialization. func echoNullable( - _ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) + _ listArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) /// Returns the passed map, to test serialization and deserialization. func echoNullable( _ aMapArg: [String?: Any?]?, @@ -2849,14 +2859,14 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// Returns the passed byte list, to test serialization and deserialization. func echo( - _ aListArg: FlutterStandardTypedData, + _ listArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void ) { let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([aListArg] as [Any?]) { response in + channel.sendMessage([listArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return @@ -2879,12 +2889,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed list, to test serialization and deserialization. - func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) { + func echo(_ listArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) { let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([aListArg] as [Any?]) { response in + channel.sendMessage([listArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return @@ -3066,14 +3076,14 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// Returns the passed byte list, to test serialization and deserialization. func echoNullable( - _ aListArg: FlutterStandardTypedData?, + _ listArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void ) { let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([aListArg] as [Any?]) { response in + channel.sendMessage([listArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return @@ -3091,13 +3101,13 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// Returns the passed list, to test serialization and deserialization. func echoNullable( - _ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void + _ listArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void ) { let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([aListArg] as [Any?]) { response in + channel.sendMessage([listArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return 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 dd88abb5a2a9..a00affe70401 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift @@ -85,8 +85,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { return anObject } - func echo(_ aList: [Any?]) throws -> [Any?] { - return aList + func echo(_ list: [Any?]) throws -> [Any?] { + return list } func echo(_ aMap: [String?: Any?]) throws -> [String?: Any?] { @@ -242,8 +242,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { completion(.success(anObject)) } - func echoAsync(_ aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { - completion(.success(aList)) + func echoAsync(_ list: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { + completion(.success(list)) } func echoAsync( @@ -285,8 +285,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { completion(.success(anObject)) } - func echoAsyncNullable(_ aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) { - completion(.success(aList)) + func echoAsyncNullable(_ list: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) { + completion(.success(list)) } func echoAsyncNullable( @@ -457,10 +457,10 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func callFlutterEcho( - _ aList: FlutterStandardTypedData, + _ list: FlutterStandardTypedData, completion: @escaping (Result) -> Void ) { - flutterAPI.echo(aList) { response in + flutterAPI.echo(list) { response in switch response { case .success(let res): completion(.success(res)) @@ -470,8 +470,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } } - func callFlutterEcho(_ aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { - flutterAPI.echo(aList) { response in + func callFlutterEcho(_ list: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { + flutterAPI.echo(list) { response in switch response { case .success(let res): completion(.success(res)) @@ -557,10 +557,10 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func callFlutterEchoNullable( - _ aList: FlutterStandardTypedData?, + _ list: FlutterStandardTypedData?, completion: @escaping (Result) -> Void ) { - flutterAPI.echoNullable(aList) { response in + flutterAPI.echoNullable(list) { response in switch response { case .success(let res): completion(.success(res)) @@ -571,9 +571,9 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func callFlutterEchoNullable( - _ aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void + _ list: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void ) { - flutterAPI.echoNullable(aList) { response in + flutterAPI.echoNullable(list) { response in switch response { case .success(let res): completion(.success(res)) 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 f02daf701672..717985e7a4bc 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 @@ -69,26 +69,29 @@ struct AllTypes { var a4ByteArray: FlutterStandardTypedData var a8ByteArray: FlutterStandardTypedData var aFloatArray: FlutterStandardTypedData - var aList: [Any?] + var list: [Any?] var aMap: [AnyHashable: Any?] var anEnum: AnEnum var aString: String var anObject: Any - static func fromList(_ list: [Any?]) -> AllTypes? { - let aBool = list[0] as! Bool - let anInt = list[1] is Int64 ? list[1] as! Int64 : Int64(list[1] as! Int32) - let anInt64 = list[2] is Int64 ? list[2] as! Int64 : Int64(list[2] as! Int32) - let aDouble = list[3] as! Double - let aByteArray = list[4] as! FlutterStandardTypedData - let a4ByteArray = list[5] as! FlutterStandardTypedData - let a8ByteArray = list[6] as! FlutterStandardTypedData - let aFloatArray = list[7] as! FlutterStandardTypedData - let aList = list[8] as! [Any?] - let aMap = list[9] as! [AnyHashable: Any?] - let anEnum = AnEnum(rawValue: list[10] as! Int)! - let aString = list[11] as! String - let anObject = list[12]! + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> AllTypes? { + let aBool = __pigeon_list[0] as! Bool + let anInt = + __pigeon_list[1] is Int64 ? __pigeon_list[1] as! Int64 : Int64(__pigeon_list[1] as! Int32) + let anInt64 = + __pigeon_list[2] is Int64 ? __pigeon_list[2] as! Int64 : Int64(__pigeon_list[2] as! Int32) + let aDouble = __pigeon_list[3] as! Double + let aByteArray = __pigeon_list[4] as! FlutterStandardTypedData + let a4ByteArray = __pigeon_list[5] as! FlutterStandardTypedData + let a8ByteArray = __pigeon_list[6] as! FlutterStandardTypedData + let aFloatArray = __pigeon_list[7] as! FlutterStandardTypedData + let list = __pigeon_list[8] as! [Any?] + let aMap = __pigeon_list[9] as! [AnyHashable: Any?] + let anEnum = AnEnum(rawValue: __pigeon_list[10] as! Int)! + let aString = __pigeon_list[11] as! String + let anObject = __pigeon_list[12]! return AllTypes( aBool: aBool, @@ -99,7 +102,7 @@ struct AllTypes { a4ByteArray: a4ByteArray, a8ByteArray: a8ByteArray, aFloatArray: aFloatArray, - aList: aList, + list: list, aMap: aMap, anEnum: anEnum, aString: aString, @@ -116,7 +119,7 @@ struct AllTypes { a4ByteArray, a8ByteArray, aFloatArray, - aList, + list, aMap, anEnum.rawValue, aString, @@ -184,33 +187,37 @@ class AllNullableTypes { var aNullableObject: Any? var allNullableTypes: AllNullableTypes? - static func fromList(_ list: [Any?]) -> AllNullableTypes? { - let aNullableBool: Bool? = nilOrValue(list[0]) + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> AllNullableTypes? { + let aNullableBool: Bool? = nilOrValue(__pigeon_list[0]) let aNullableInt: Int64? = - isNullish(list[1]) ? nil : (list[1] is Int64? ? list[1] as! Int64? : Int64(list[1] as! Int32)) + isNullish(__pigeon_list[1]) + ? nil + : (__pigeon_list[1] is Int64? + ? __pigeon_list[1] as! Int64? : Int64(__pigeon_list[1] as! Int32)) let aNullableInt64: Int64? = - isNullish(list[2]) ? nil : (list[2] is Int64? ? list[2] as! Int64? : Int64(list[2] as! Int32)) - let aNullableDouble: Double? = nilOrValue(list[3]) - let aNullableByteArray: FlutterStandardTypedData? = nilOrValue(list[4]) - let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(list[5]) - let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(list[6]) - let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(list[7]) - let aNullableList: [Any?]? = nilOrValue(list[8]) - let aNullableMap: [AnyHashable: Any?]? = nilOrValue(list[9]) - let nullableNestedList: [[Bool?]?]? = nilOrValue(list[10]) - let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(list[11]) - let nullableMapWithObject: [String?: Any?]? = nilOrValue(list[12]) + isNullish(__pigeon_list[2]) + ? nil + : (__pigeon_list[2] is Int64? + ? __pigeon_list[2] as! Int64? : Int64(__pigeon_list[2] as! Int32)) + let aNullableDouble: Double? = nilOrValue(__pigeon_list[3]) + let aNullableByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[4]) + let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[5]) + let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[6]) + let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[7]) + let aNullableList: [Any?]? = nilOrValue(__pigeon_list[8]) + let aNullableMap: [AnyHashable: Any?]? = nilOrValue(__pigeon_list[9]) + let nullableNestedList: [[Bool?]?]? = nilOrValue(__pigeon_list[10]) + let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(__pigeon_list[11]) + let nullableMapWithObject: [String?: Any?]? = nilOrValue(__pigeon_list[12]) var aNullableEnum: AnEnum? = nil - let aNullableEnumEnumVal: Int? = nilOrValue(list[13]) + let aNullableEnumEnumVal: Int? = nilOrValue(__pigeon_list[13]) if let aNullableEnumRawValue = aNullableEnumEnumVal { aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue)! } - let aNullableString: String? = nilOrValue(list[14]) - let aNullableObject: Any? = list[15] - var allNullableTypes: AllNullableTypes? = nil - if let allNullableTypesList: [Any?] = nilOrValue(list[16]) { - allNullableTypes = AllNullableTypes.fromList(allNullableTypesList) - } + let aNullableString: String? = nilOrValue(__pigeon_list[14]) + let aNullableObject: Any? = __pigeon_list[15] + let allNullableTypes: AllNullableTypes? = nilOrValue(__pigeon_list[16]) return AllNullableTypes( aNullableBool: aNullableBool, @@ -250,7 +257,7 @@ class AllNullableTypes { aNullableEnum?.rawValue, aNullableString, aNullableObject, - allNullableTypes?.toList(), + allNullableTypes, ] } } @@ -278,29 +285,36 @@ struct AllNullableTypesWithoutRecursion { var aNullableString: String? = nil var aNullableObject: Any? = nil - static func fromList(_ list: [Any?]) -> AllNullableTypesWithoutRecursion? { - let aNullableBool: Bool? = nilOrValue(list[0]) + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> AllNullableTypesWithoutRecursion? { + let aNullableBool: Bool? = nilOrValue(__pigeon_list[0]) let aNullableInt: Int64? = - isNullish(list[1]) ? nil : (list[1] is Int64? ? list[1] as! Int64? : Int64(list[1] as! Int32)) + isNullish(__pigeon_list[1]) + ? nil + : (__pigeon_list[1] is Int64? + ? __pigeon_list[1] as! Int64? : Int64(__pigeon_list[1] as! Int32)) let aNullableInt64: Int64? = - isNullish(list[2]) ? nil : (list[2] is Int64? ? list[2] as! Int64? : Int64(list[2] as! Int32)) - let aNullableDouble: Double? = nilOrValue(list[3]) - let aNullableByteArray: FlutterStandardTypedData? = nilOrValue(list[4]) - let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(list[5]) - let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(list[6]) - let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(list[7]) - let aNullableList: [Any?]? = nilOrValue(list[8]) - let aNullableMap: [AnyHashable: Any?]? = nilOrValue(list[9]) - let nullableNestedList: [[Bool?]?]? = nilOrValue(list[10]) - let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(list[11]) - let nullableMapWithObject: [String?: Any?]? = nilOrValue(list[12]) + isNullish(__pigeon_list[2]) + ? nil + : (__pigeon_list[2] is Int64? + ? __pigeon_list[2] as! Int64? : Int64(__pigeon_list[2] as! Int32)) + let aNullableDouble: Double? = nilOrValue(__pigeon_list[3]) + let aNullableByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[4]) + let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[5]) + let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[6]) + let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[7]) + let aNullableList: [Any?]? = nilOrValue(__pigeon_list[8]) + let aNullableMap: [AnyHashable: Any?]? = nilOrValue(__pigeon_list[9]) + let nullableNestedList: [[Bool?]?]? = nilOrValue(__pigeon_list[10]) + let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(__pigeon_list[11]) + let nullableMapWithObject: [String?: Any?]? = nilOrValue(__pigeon_list[12]) var aNullableEnum: AnEnum? = nil - let aNullableEnumEnumVal: Int? = nilOrValue(list[13]) + let aNullableEnumEnumVal: Int? = nilOrValue(__pigeon_list[13]) if let aNullableEnumRawValue = aNullableEnumEnumVal { aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue)! } - let aNullableString: String? = nilOrValue(list[14]) - let aNullableObject: Any? = list[15] + let aNullableString: String? = nilOrValue(__pigeon_list[14]) + let aNullableObject: Any? = __pigeon_list[15] return AllNullableTypesWithoutRecursion( aNullableBool: aNullableBool, @@ -355,17 +369,12 @@ struct AllClassesWrapper { var allNullableTypesWithoutRecursion: AllNullableTypesWithoutRecursion? = nil var allTypes: AllTypes? = nil - static func fromList(_ list: [Any?]) -> AllClassesWrapper? { - let allNullableTypes = AllNullableTypes.fromList(list[0] as! [Any?])! - var allNullableTypesWithoutRecursion: AllNullableTypesWithoutRecursion? = nil - if let allNullableTypesWithoutRecursionList: [Any?] = nilOrValue(list[1]) { - allNullableTypesWithoutRecursion = AllNullableTypesWithoutRecursion.fromList( - allNullableTypesWithoutRecursionList) - } - var allTypes: AllTypes? = nil - if let allTypesList: [Any?] = nilOrValue(list[2]) { - allTypes = AllTypes.fromList(allTypesList) - } + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> AllClassesWrapper? { + let allNullableTypes = __pigeon_list[0] as! AllNullableTypes + let allNullableTypesWithoutRecursion: AllNullableTypesWithoutRecursion? = nilOrValue( + __pigeon_list[1]) + let allTypes: AllTypes? = nilOrValue(__pigeon_list[2]) return AllClassesWrapper( allNullableTypes: allNullableTypes, @@ -375,9 +384,9 @@ struct AllClassesWrapper { } func toList() -> [Any?] { return [ - allNullableTypes.toList(), - allNullableTypesWithoutRecursion?.toList(), - allTypes?.toList(), + allNullableTypes, + allNullableTypesWithoutRecursion, + allTypes, ] } } @@ -388,8 +397,9 @@ struct AllClassesWrapper { struct TestMessage { var testList: [Any?]? = nil - static func fromList(_ list: [Any?]) -> TestMessage? { - let testList: [Any?]? = nilOrValue(list[0]) + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> TestMessage? { + let testList: [Any?]? = nilOrValue(__pigeon_list[0]) return TestMessage( testList: testList @@ -488,7 +498,7 @@ protocol HostIntegrationCoreApi { /// Returns the passed in generic Object. func echo(_ anObject: Any) throws -> Any /// Returns the passed list, to test serialization and deserialization. - func echo(_ aList: [Any?]) throws -> [Any?] + func echo(_ list: [Any?]) throws -> [Any?] /// Returns the passed map, to test serialization and deserialization. func echo(_ aMap: [String?: Any?]) throws -> [String?: Any?] /// Returns the passed map to test nested class serialization and deserialization. @@ -559,7 +569,7 @@ protocol HostIntegrationCoreApi { /// Returns the passed in generic Object asynchronously. func echoAsync(_ anObject: Any, completion: @escaping (Result) -> Void) /// Returns the passed list, to test asynchronous serialization and deserialization. - func echoAsync(_ aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) + func echoAsync(_ list: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) /// Returns the passed map, to test asynchronous serialization and deserialization. func echoAsync( _ aMap: [String?: Any?], completion: @escaping (Result<[String?: Any?], Error>) -> Void) @@ -596,7 +606,7 @@ protocol HostIntegrationCoreApi { /// Returns the passed in generic Object asynchronously. func echoAsyncNullable(_ anObject: Any?, completion: @escaping (Result) -> Void) /// Returns the passed list, to test asynchronous serialization and deserialization. - func echoAsyncNullable(_ aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) + func echoAsyncNullable(_ list: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) /// Returns the passed map, to test asynchronous serialization and deserialization. func echoAsyncNullable( _ aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) @@ -624,9 +634,9 @@ protocol HostIntegrationCoreApi { func callFlutterEcho(_ aDouble: Double, completion: @escaping (Result) -> Void) func callFlutterEcho(_ aString: String, completion: @escaping (Result) -> Void) func callFlutterEcho( - _ aList: FlutterStandardTypedData, + _ list: FlutterStandardTypedData, completion: @escaping (Result) -> Void) - func callFlutterEcho(_ aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) + func callFlutterEcho(_ list: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) func callFlutterEcho( _ aMap: [String?: Any?], completion: @escaping (Result<[String?: Any?], Error>) -> Void) func callFlutterEcho(_ anEnum: AnEnum, completion: @escaping (Result) -> Void) @@ -638,10 +648,10 @@ protocol HostIntegrationCoreApi { func callFlutterEchoNullable( _ aString: String?, completion: @escaping (Result) -> Void) func callFlutterEchoNullable( - _ aList: FlutterStandardTypedData?, + _ list: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) func callFlutterEchoNullable( - _ aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) + _ list: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) func callFlutterEchoNullable( _ aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) func callFlutterNullableEcho( @@ -870,9 +880,9 @@ class HostIntegrationCoreApiSetup { if let api = api { echoListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg = args[0] as! [Any?] + let listArg = args[0] as! [Any?] do { - let result = try api.echo(aListArg) + let result = try api.echo(listArg) reply(wrapResult(result)) } catch { reply(wrapError(error)) @@ -1487,8 +1497,8 @@ class HostIntegrationCoreApiSetup { if let api = api { echoAsyncListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg = args[0] as! [Any?] - api.echoAsync(aListArg) { result in + let listArg = args[0] as! [Any?] + api.echoAsync(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -1798,8 +1808,8 @@ class HostIntegrationCoreApiSetup { if let api = api { echoAsyncNullableListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg: [Any?]? = nilOrValue(args[0]) - api.echoAsyncNullable(aListArg) { result in + let listArg: [Any?]? = nilOrValue(args[0]) + api.echoAsyncNullable(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2107,8 +2117,8 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoUint8ListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg = args[0] as! FlutterStandardTypedData - api.callFlutterEcho(aListArg) { result in + let listArg = args[0] as! FlutterStandardTypedData + api.callFlutterEcho(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2127,8 +2137,8 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg = args[0] as! [Any?] - api.callFlutterEcho(aListArg) { result in + let listArg = args[0] as! [Any?] + api.callFlutterEcho(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2269,8 +2279,8 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoNullableUint8ListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg: FlutterStandardTypedData? = nilOrValue(args[0]) - api.callFlutterEchoNullable(aListArg) { result in + let listArg: FlutterStandardTypedData? = nilOrValue(args[0]) + api.callFlutterEchoNullable(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2289,8 +2299,8 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoNullableListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg: [Any?]? = nilOrValue(args[0]) - api.callFlutterEchoNullable(aListArg) { result in + let listArg: [Any?]? = nilOrValue(args[0]) + api.callFlutterEchoNullable(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2468,10 +2478,10 @@ protocol FlutterIntegrationCoreApiProtocol { func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) /// Returns the passed byte list, to test serialization and deserialization. func echo( - _ aListArg: FlutterStandardTypedData, + _ listArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void) /// Returns the passed list, to test serialization and deserialization. - func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) + func echo(_ listArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) /// Returns the passed map, to test serialization and deserialization. func echo( _ aMapArg: [String?: Any?], @@ -2491,11 +2501,11 @@ protocol FlutterIntegrationCoreApiProtocol { _ aStringArg: String?, completion: @escaping (Result) -> Void) /// Returns the passed byte list, to test serialization and deserialization. func echoNullable( - _ aListArg: FlutterStandardTypedData?, + _ listArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) /// Returns the passed list, to test serialization and deserialization. func echoNullable( - _ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) + _ listArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) /// Returns the passed map, to test serialization and deserialization. func echoNullable( _ aMapArg: [String?: Any?]?, @@ -2849,14 +2859,14 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// Returns the passed byte list, to test serialization and deserialization. func echo( - _ aListArg: FlutterStandardTypedData, + _ listArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void ) { let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([aListArg] as [Any?]) { response in + channel.sendMessage([listArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return @@ -2879,12 +2889,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed list, to test serialization and deserialization. - func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) { + func echo(_ listArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) { let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([aListArg] as [Any?]) { response in + channel.sendMessage([listArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return @@ -3066,14 +3076,14 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// Returns the passed byte list, to test serialization and deserialization. func echoNullable( - _ aListArg: FlutterStandardTypedData?, + _ listArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void ) { let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([aListArg] as [Any?]) { response in + channel.sendMessage([listArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return @@ -3091,13 +3101,13 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// Returns the passed list, to test serialization and deserialization. func echoNullable( - _ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void + _ listArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void ) { let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([aListArg] as [Any?]) { response in + channel.sendMessage([listArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return 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 759b4ac21ac9..2c415135bcc3 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift @@ -84,8 +84,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { return anObject } - func echo(_ aList: [Any?]) throws -> [Any?] { - return aList + func echo(_ list: [Any?]) throws -> [Any?] { + return list } func echo(_ aMap: [String?: Any?]) throws -> [String?: Any?] { @@ -241,8 +241,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { completion(.success(anObject)) } - func echoAsync(_ aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { - completion(.success(aList)) + func echoAsync(_ list: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { + completion(.success(list)) } func echoAsync( @@ -284,8 +284,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { completion(.success(anObject)) } - func echoAsyncNullable(_ aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) { - completion(.success(aList)) + func echoAsyncNullable(_ list: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) { + completion(.success(list)) } func echoAsyncNullable( @@ -456,10 +456,10 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func callFlutterEcho( - _ aList: FlutterStandardTypedData, + _ list: FlutterStandardTypedData, completion: @escaping (Result) -> Void ) { - flutterAPI.echo(aList) { response in + flutterAPI.echo(list) { response in switch response { case .success(let res): completion(.success(res)) @@ -469,8 +469,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } } - func callFlutterEcho(_ aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { - flutterAPI.echo(aList) { response in + func callFlutterEcho(_ list: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { + flutterAPI.echo(list) { response in switch response { case .success(let res): completion(.success(res)) @@ -556,10 +556,10 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func callFlutterEchoNullable( - _ aList: FlutterStandardTypedData?, + _ list: FlutterStandardTypedData?, completion: @escaping (Result) -> Void ) { - flutterAPI.echoNullable(aList) { response in + flutterAPI.echoNullable(list) { response in switch response { case .success(let res): completion(.success(res)) @@ -570,9 +570,9 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func callFlutterEchoNullable( - _ aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void + _ list: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void ) { - flutterAPI.echoNullable(aList) { response in + flutterAPI.echoNullable(list) { response in switch response { case .success(let res): completion(.success(res)) diff --git a/packages/pigeon/platform_tests/test_plugin/windows/CMakeLists.txt b/packages/pigeon/platform_tests/test_plugin/windows/CMakeLists.txt index 30e26d2bb1b5..e69e6bc75130 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/CMakeLists.txt +++ b/packages/pigeon/platform_tests/test_plugin/windows/CMakeLists.txt @@ -62,6 +62,10 @@ target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) +# Override apply_standard_settings for exceptions due to +# https://developercommunity.visualstudio.com/t/stdany-doesnt-link-when-exceptions-are-disabled/376072 +# TODO(stuartmorgan): Remove this once CI is using VS 2022 or later. +target_compile_definitions(${PLUGIN_NAME} PRIVATE "_HAS_EXCEPTIONS=1") # List of absolute paths to libraries that should be bundled with the plugin. # This list could contain prebuilt libraries, or libraries created by an @@ -118,6 +122,10 @@ add_custom_command(TARGET ${TEST_RUNNER} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${FLUTTER_LIBRARY}" $ ) +# Override apply_standard_settings for exceptions due to +# https://developercommunity.visualstudio.com/t/stdany-doesnt-link-when-exceptions-are-disabled/376072 +# TODO(stuartmorgan): Remove this once CI is using VS 2022 or later. +target_compile_definitions(${TEST_RUNNER} PRIVATE "_HAS_EXCEPTIONS=1") include(GoogleTest) gtest_discover_tests(${TEST_RUNNER}) 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 a1cff580e06e..c4e74f451192 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 @@ -39,7 +39,7 @@ AllTypes::AllTypes(bool a_bool, int64_t an_int, int64_t an_int64, const std::vector& a4_byte_array, const std::vector& a8_byte_array, const std::vector& a_float_array, - const EncodableList& a_list, const EncodableMap& a_map, + const EncodableList& list, const EncodableMap& a_map, const AnEnum& an_enum, const std::string& a_string, const EncodableValue& an_object) : a_bool_(a_bool), @@ -50,7 +50,7 @@ AllTypes::AllTypes(bool a_bool, int64_t an_int, int64_t an_int64, a4_byte_array_(a4_byte_array), a8_byte_array_(a8_byte_array), a_float_array_(a_float_array), - a_list_(a_list), + list_(list), a_map_(a_map), an_enum_(an_enum), a_string_(a_string), @@ -104,11 +104,9 @@ void AllTypes::set_a_float_array(const std::vector& value_arg) { a_float_array_ = value_arg; } -const EncodableList& AllTypes::a_list() const { return a_list_; } +const EncodableList& AllTypes::list() const { return list_; } -void AllTypes::set_a_list(const EncodableList& value_arg) { - a_list_ = value_arg; -} +void AllTypes::set_list(const EncodableList& value_arg) { list_ = value_arg; } const EncodableMap& AllTypes::a_map() const { return a_map_; } @@ -141,7 +139,7 @@ EncodableList AllTypes::ToEncodableList() const { list.push_back(EncodableValue(a4_byte_array_)); list.push_back(EncodableValue(a8_byte_array_)); list.push_back(EncodableValue(a_float_array_)); - list.push_back(EncodableValue(a_list_)); + list.push_back(EncodableValue(list_)); list.push_back(EncodableValue(a_map_)); list.push_back(EncodableValue((int)an_enum_)); list.push_back(EncodableValue(a_string_)); @@ -605,7 +603,7 @@ EncodableList AllNullableTypes::ToEncodableList() const { : EncodableValue()); list.push_back(a_nullable_object_ ? *a_nullable_object_ : EncodableValue()); list.push_back(all_nullable_types_ - ? EncodableValue(all_nullable_types_->ToEncodableList()) + ? CustomEncodableValue(*all_nullable_types_) : EncodableValue()); return list; } @@ -691,8 +689,8 @@ AllNullableTypes AllNullableTypes::FromEncodableList( } auto& encodable_all_nullable_types = list[16]; if (!encodable_all_nullable_types.IsNull()) { - decoded.set_all_nullable_types(AllNullableTypes::FromEncodableList( - std::get(encodable_all_nullable_types))); + decoded.set_all_nullable_types(std::any_cast( + std::get(encodable_all_nullable_types))); } return decoded; } @@ -1226,32 +1224,31 @@ void AllClassesWrapper::set_all_types(const AllTypes& value_arg) { EncodableList AllClassesWrapper::ToEncodableList() const { EncodableList list; list.reserve(3); - list.push_back(EncodableValue(all_nullable_types_->ToEncodableList())); + list.push_back(CustomEncodableValue(*all_nullable_types_)); list.push_back( all_nullable_types_without_recursion_ - ? EncodableValue( - all_nullable_types_without_recursion_->ToEncodableList()) + ? CustomEncodableValue(*all_nullable_types_without_recursion_) : EncodableValue()); - list.push_back(all_types_ ? EncodableValue(all_types_->ToEncodableList()) + list.push_back(all_types_ ? CustomEncodableValue(*all_types_) : EncodableValue()); return list; } AllClassesWrapper AllClassesWrapper::FromEncodableList( const EncodableList& list) { - AllClassesWrapper decoded( - AllNullableTypes::FromEncodableList(std::get(list[0]))); + AllClassesWrapper decoded(std::any_cast( + std::get(list[0]))); auto& encodable_all_nullable_types_without_recursion = list[1]; if (!encodable_all_nullable_types_without_recursion.IsNull()) { decoded.set_all_nullable_types_without_recursion( - AllNullableTypesWithoutRecursion::FromEncodableList( - std::get( + std::any_cast( + std::get( encodable_all_nullable_types_without_recursion))); } auto& encodable_all_types = list[2]; if (!encodable_all_types.IsNull()) { - decoded.set_all_types(AllTypes::FromEncodableList( - std::get(encodable_all_types))); + decoded.set_all_types(std::any_cast( + std::get(encodable_all_types))); } return decoded; } @@ -1763,14 +1760,14 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, const flutter::MessageReply& reply) { try { const auto& args = std::get(message); - const auto& encodable_a_list_arg = args.at(0); - if (encodable_a_list_arg.IsNull()) { - reply(WrapError("a_list_arg unexpectedly null.")); + const auto& encodable_list_arg = args.at(0); + if (encodable_list_arg.IsNull()) { + reply(WrapError("list_arg unexpectedly null.")); return; } - const auto& a_list_arg = - std::get(encodable_a_list_arg); - ErrorOr output = api->EchoList(a_list_arg); + const auto& list_arg = + std::get(encodable_list_arg); + ErrorOr output = api->EchoList(list_arg); if (output.has_error()) { reply(WrapError(output.error())); return; @@ -2961,15 +2958,15 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, const flutter::MessageReply& reply) { try { const auto& args = std::get(message); - const auto& encodable_a_list_arg = args.at(0); - if (encodable_a_list_arg.IsNull()) { - reply(WrapError("a_list_arg unexpectedly null.")); + const auto& encodable_list_arg = args.at(0); + if (encodable_list_arg.IsNull()) { + reply(WrapError("list_arg unexpectedly null.")); return; } - const auto& a_list_arg = - std::get(encodable_a_list_arg); + const auto& list_arg = + std::get(encodable_list_arg); api->EchoAsyncList( - a_list_arg, [reply](ErrorOr&& output) { + list_arg, [reply](ErrorOr&& output) { if (output.has_error()) { reply(WrapError(output.error())); return; @@ -3551,11 +3548,11 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, const flutter::MessageReply& reply) { try { const auto& args = std::get(message); - const auto& encodable_a_list_arg = args.at(0); - const auto* a_list_arg = - std::get_if(&encodable_a_list_arg); + const auto& encodable_list_arg = args.at(0); + const auto* list_arg = + std::get_if(&encodable_list_arg); api->EchoAsyncNullableList( - a_list_arg, + list_arg, [reply](ErrorOr>&& output) { if (output.has_error()) { reply(WrapError(output.error())); @@ -4153,15 +4150,15 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, const flutter::MessageReply& reply) { try { const auto& args = std::get(message); - const auto& encodable_a_list_arg = args.at(0); - if (encodable_a_list_arg.IsNull()) { - reply(WrapError("a_list_arg unexpectedly null.")); + const auto& encodable_list_arg = args.at(0); + if (encodable_list_arg.IsNull()) { + reply(WrapError("list_arg unexpectedly null.")); return; } - const auto& a_list_arg = - std::get>(encodable_a_list_arg); + const auto& list_arg = + std::get>(encodable_list_arg); api->CallFlutterEchoUint8List( - a_list_arg, [reply](ErrorOr>&& output) { + list_arg, [reply](ErrorOr>&& output) { if (output.has_error()) { reply(WrapError(output.error())); return; @@ -4191,15 +4188,15 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, const flutter::MessageReply& reply) { try { const auto& args = std::get(message); - const auto& encodable_a_list_arg = args.at(0); - if (encodable_a_list_arg.IsNull()) { - reply(WrapError("a_list_arg unexpectedly null.")); + const auto& encodable_list_arg = args.at(0); + if (encodable_list_arg.IsNull()) { + reply(WrapError("list_arg unexpectedly null.")); return; } - const auto& a_list_arg = - std::get(encodable_a_list_arg); + const auto& list_arg = + std::get(encodable_list_arg); api->CallFlutterEchoList( - a_list_arg, [reply](ErrorOr&& output) { + list_arg, [reply](ErrorOr&& output) { if (output.has_error()) { reply(WrapError(output.error())); return; @@ -4472,11 +4469,11 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, const flutter::MessageReply& reply) { try { const auto& args = std::get(message); - const auto& encodable_a_list_arg = args.at(0); - const auto* a_list_arg = - std::get_if>(&encodable_a_list_arg); + const auto& encodable_list_arg = args.at(0); + const auto* list_arg = + std::get_if>(&encodable_list_arg); api->CallFlutterEchoNullableUint8List( - a_list_arg, + list_arg, [reply]( ErrorOr>>&& output) { if (output.has_error()) { @@ -4514,11 +4511,11 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, const flutter::MessageReply& reply) { try { const auto& args = std::get(message); - const auto& encodable_a_list_arg = args.at(0); - const auto* a_list_arg = - std::get_if(&encodable_a_list_arg); + const auto& encodable_list_arg = args.at(0); + const auto* list_arg = + std::get_if(&encodable_list_arg); api->CallFlutterEchoNullableList( - a_list_arg, + list_arg, [reply](ErrorOr>&& output) { if (output.has_error()) { reply(WrapError(output.error())); @@ -5228,7 +5225,7 @@ void FlutterIntegrationCoreApi::EchoString( } void FlutterIntegrationCoreApi::EchoUint8List( - const std::vector& a_list_arg, + const std::vector& list_arg, std::function&)>&& on_success, std::function&& on_error) { const std::string channel_name = @@ -5237,7 +5234,7 @@ void FlutterIntegrationCoreApi::EchoUint8List( message_channel_suffix_; BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ - EncodableValue(a_list_arg), + EncodableValue(list_arg), }); channel.Send( encoded_api_arguments, [channel_name, on_success = std::move(on_success), @@ -5266,7 +5263,7 @@ void FlutterIntegrationCoreApi::EchoUint8List( } void FlutterIntegrationCoreApi::EchoList( - const EncodableList& a_list_arg, + const EncodableList& list_arg, std::function&& on_success, std::function&& on_error) { const std::string channel_name = @@ -5275,7 +5272,7 @@ void FlutterIntegrationCoreApi::EchoList( message_channel_suffix_; BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ - EncodableValue(a_list_arg), + EncodableValue(list_arg), }); channel.Send( encoded_api_arguments, [channel_name, on_success = std::move(on_success), @@ -5531,7 +5528,7 @@ void FlutterIntegrationCoreApi::EchoNullableString( } void FlutterIntegrationCoreApi::EchoNullableUint8List( - const std::vector* a_list_arg, + const std::vector* list_arg, std::function*)>&& on_success, std::function&& on_error) { const std::string channel_name = @@ -5540,7 +5537,7 @@ void FlutterIntegrationCoreApi::EchoNullableUint8List( message_channel_suffix_; BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ - a_list_arg ? EncodableValue(*a_list_arg) : EncodableValue(), + list_arg ? EncodableValue(*list_arg) : EncodableValue(), }); channel.Send( encoded_api_arguments, [channel_name, on_success = std::move(on_success), @@ -5569,7 +5566,7 @@ void FlutterIntegrationCoreApi::EchoNullableUint8List( } void FlutterIntegrationCoreApi::EchoNullableList( - const EncodableList* a_list_arg, + const EncodableList* list_arg, std::function&& on_success, std::function&& on_error) { const std::string channel_name = @@ -5578,7 +5575,7 @@ void FlutterIntegrationCoreApi::EchoNullableList( message_channel_suffix_; BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ - a_list_arg ? EncodableValue(*a_list_arg) : EncodableValue(), + list_arg ? EncodableValue(*list_arg) : EncodableValue(), }); channel.Send( encoded_api_arguments, [channel_name, on_success = std::move(on_success), 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 15a98bf6bba0..7ee944538268 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 @@ -84,7 +84,7 @@ class AllTypes { const std::vector& a4_byte_array, const std::vector& a8_byte_array, const std::vector& a_float_array, - const flutter::EncodableList& a_list, + const flutter::EncodableList& list, const flutter::EncodableMap& a_map, const AnEnum& an_enum, const std::string& a_string, const flutter::EncodableValue& an_object); @@ -113,8 +113,8 @@ class AllTypes { const std::vector& a_float_array() const; void set_a_float_array(const std::vector& value_arg); - const flutter::EncodableList& a_list() const; - void set_a_list(const flutter::EncodableList& value_arg); + const flutter::EncodableList& list() const; + void set_list(const flutter::EncodableList& value_arg); const flutter::EncodableMap& a_map() const; void set_a_map(const flutter::EncodableMap& value_arg); @@ -151,7 +151,7 @@ class AllTypes { std::vector a4_byte_array_; std::vector a8_byte_array_; std::vector a_float_array_; - flutter::EncodableList a_list_; + flutter::EncodableList list_; flutter::EncodableMap a_map_; AnEnum an_enum_; std::string a_string_; @@ -563,7 +563,7 @@ class HostIntegrationCoreApi { const flutter::EncodableValue& an_object) = 0; // Returns the passed list, to test serialization and deserialization. virtual ErrorOr EchoList( - const flutter::EncodableList& a_list) = 0; + const flutter::EncodableList& list) = 0; // Returns the passed map, to test serialization and deserialization. virtual ErrorOr EchoMap( const flutter::EncodableMap& a_map) = 0; @@ -664,7 +664,7 @@ class HostIntegrationCoreApi { // Returns the passed list, to test asynchronous serialization and // deserialization. virtual void EchoAsyncList( - const flutter::EncodableList& a_list, + const flutter::EncodableList& list, std::function reply)> result) = 0; // Returns the passed map, to test asynchronous serialization and // deserialization. @@ -732,7 +732,7 @@ class HostIntegrationCoreApi { // Returns the passed list, to test asynchronous serialization and // deserialization. virtual void EchoAsyncNullableList( - const flutter::EncodableList* a_list, + const flutter::EncodableList* list, std::function> reply)> result) = 0; // Returns the passed map, to test asynchronous serialization and @@ -784,10 +784,10 @@ class HostIntegrationCoreApi { const std::string& a_string, std::function reply)> result) = 0; virtual void CallFlutterEchoUint8List( - const std::vector& a_list, + const std::vector& list, std::function> reply)> result) = 0; virtual void CallFlutterEchoList( - const flutter::EncodableList& a_list, + const flutter::EncodableList& list, std::function reply)> result) = 0; virtual void CallFlutterEchoMap( const flutter::EncodableMap& a_map, @@ -809,11 +809,11 @@ class HostIntegrationCoreApi { std::function> reply)> result) = 0; virtual void CallFlutterEchoNullableUint8List( - const std::vector* a_list, + const std::vector* list, std::function>> reply)> result) = 0; virtual void CallFlutterEchoNullableList( - const flutter::EncodableList* a_list, + const flutter::EncodableList* list, std::function> reply)> result) = 0; virtual void CallFlutterEchoNullableMap( @@ -926,11 +926,11 @@ class FlutterIntegrationCoreApi { std::function&& on_error); // Returns the passed byte list, to test serialization and deserialization. void EchoUint8List( - const std::vector& a_list, + const std::vector& list, std::function&)>&& on_success, std::function&& on_error); // Returns the passed list, to test serialization and deserialization. - void EchoList(const flutter::EncodableList& a_list, + void EchoList(const flutter::EncodableList& list, std::function&& on_success, std::function&& on_error); // Returns the passed map, to test serialization and deserialization. @@ -959,12 +959,12 @@ class FlutterIntegrationCoreApi { std::function&& on_error); // Returns the passed byte list, to test serialization and deserialization. void EchoNullableUint8List( - const std::vector* a_list, + const std::vector* list, std::function*)>&& on_success, std::function&& on_error); // Returns the passed list, to test serialization and deserialization. void EchoNullableList( - const flutter::EncodableList* a_list, + const flutter::EncodableList* list, std::function&& on_success, std::function&& on_error); // Returns the passed map, to test serialization and deserialization. diff --git a/packages/pigeon/platform_tests/test_plugin/windows/test/null_fields_test.cpp b/packages/pigeon/platform_tests/test_plugin/windows/test/null_fields_test.cpp index fa21a9619ac3..d0c045618820 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test/null_fields_test.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/test/null_fields_test.cpp @@ -11,6 +11,7 @@ namespace null_fields_pigeontest { namespace { +using flutter::CustomEncodableValue; using flutter::EncodableList; using flutter::EncodableMap; using flutter::EncodableValue; @@ -113,6 +114,8 @@ TEST_F(NullFieldsTest, RequestFromListWithNulls) { } TEST_F(NullFieldsTest, ReplyFromListWithValues) { + NullFieldsSearchRequest request(1); + request.set_query("hello"); EncodableList list{ EncodableValue("result"), EncodableValue("error"), @@ -121,10 +124,7 @@ TEST_F(NullFieldsTest, ReplyFromListWithValues) { EncodableValue(2), EncodableValue(3), }), - EncodableValue(EncodableList{ - EncodableValue("hello"), - EncodableValue(1), - }), + CustomEncodableValue(request), EncodableValue(0), }; NullFieldsSearchReply reply = ReplyFromList(list); @@ -194,10 +194,11 @@ TEST_F(NullFieldsTest, ReplyToMapWithValues) { EXPECT_EQ(indices[0].LongValue(), 1L); EXPECT_EQ(indices[1].LongValue(), 2L); EXPECT_EQ(indices[2].LongValue(), 3L); - const EncodableList& request_list = - *ExpectAndGetIndex(list, 3); - EXPECT_EQ(*ExpectAndGetIndex(request_list, 0), "hello"); - EXPECT_EQ(*ExpectAndGetIndex(request_list, 1), 1); + const NullFieldsSearchRequest& request_from_list = + std::any_cast( + *ExpectAndGetIndex(list, 3)); + EXPECT_EQ(*request_from_list.query(), "hello"); + EXPECT_EQ(request_from_list.identifier(), 1); } TEST_F(NullFieldsTest, ReplyToListWithNulls) { diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index f368b97536ae..ab80e97230d9 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -2,7 +2,7 @@ name: pigeon description: Code generator tool to make communication between Flutter and the host platform type-safe and easier. repository: https://github.com/flutter/packages/tree/main/packages/pigeon issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+pigeon%22 -version: 18.0.0 # This must match the version in lib/generator_tools.dart +version: 18.0.1 # This must match the version in lib/generator_tools.dart environment: sdk: ^3.1.0 diff --git a/packages/pigeon/test/cpp_generator_test.dart b/packages/pigeon/test/cpp_generator_test.dart index c2fdcd68f689..8695ae45e96c 100644 --- a/packages/pigeon/test/cpp_generator_test.dart +++ b/packages/pigeon/test/cpp_generator_test.dart @@ -651,8 +651,7 @@ void main() { expect( code, contains( - 'nullable_nested_ ? EncodableValue(nullable_nested_->ToEncodableList()) ' - ': EncodableValue()')); + 'nullable_nested_ ? CustomEncodableValue(*nullable_nested_) : EncodableValue())')); // Serialization should use push_back, not initializer lists, to avoid // copies. @@ -805,13 +804,15 @@ void main() { 'non_nullable_nested_ = std::make_unique(value_arg);')); // Serialization uses the value directly. expect(code, contains('EncodableValue(non_nullable_bool_)')); - expect(code, contains('non_nullable_nested_->ToEncodableList()')); + expect(code, contains('CustomEncodableValue(*non_nullable_nested_)')); // Serialization should use push_back, not initializer lists, to avoid // copies. expect(code, contains('list.reserve(4)')); expect( - code, contains('list.push_back(EncodableValue(non_nullable_bool_))')); + code, + contains( + 'list.push_back(CustomEncodableValue(*non_nullable_nested_))')); } }); @@ -1637,13 +1638,13 @@ void main() { dartPackageName: DEFAULT_PACKAGE_NAME, ); final String code = sink.toString(); - // Standard types are wrapped an EncodableValues. + // Standard types are wrapped in EncodableValues. expect(code, contains('EncodableValue(a_bool_arg)')); expect(code, contains('EncodableValue(an_int_arg)')); expect(code, contains('EncodableValue(a_string_arg)')); expect(code, contains('EncodableValue(a_list_arg)')); expect(code, contains('EncodableValue(a_map_arg)')); - // Class types use ToEncodableList. + // Class types are wrapped in CustomEncodableValues. expect(code, contains('CustomEncodableValue(an_object_arg)')); } }); diff --git a/packages/pigeon/test/dart_generator_test.dart b/packages/pigeon/test/dart_generator_test.dart index bdb8ece598f0..a1470427c7f0 100644 --- a/packages/pigeon/test/dart_generator_test.dart +++ b/packages/pigeon/test/dart_generator_test.dart @@ -246,13 +246,13 @@ void main() { expect( code, contains( - 'nested?.encode(),', + 'nested,', ), ); expect( - code.replaceAll('\n', ' ').replaceAll(' ', ''), + code, contains( - 'nested: result[0] != null ? Input.decode(result[0]! as List) : null', + 'nested: result[0] as Input?', ), ); }); @@ -295,13 +295,13 @@ void main() { expect( code, contains( - 'nested.encode(),', + 'nested,', ), ); expect( - code.replaceAll('\n', ' ').replaceAll(' ', ''), + code, contains( - 'nested: Input.decode(result[0]! as List)', + 'nested: result[0]! as Input', ), ); }); diff --git a/packages/pigeon/test/java_generator_test.dart b/packages/pigeon/test/java_generator_test.dart index d620ee6c182c..c3bb560279d9 100644 --- a/packages/pigeon/test/java_generator_test.dart +++ b/packages/pigeon/test/java_generator_test.dart @@ -575,11 +575,7 @@ void main() { expect(code, contains('public static final class Outer')); expect(code, contains('public static final class Nested')); expect(code, contains('private @Nullable Nested nested;')); - expect( - code, - contains( - '(nested == null) ? null : Nested.fromList((ArrayList) nested)')); - expect(code, contains('add((nested == null) ? null : nested.toList());')); + expect(code, contains('add(nested);')); }); test('gen one async Host Api', () { diff --git a/packages/pigeon/test/kotlin_generator_test.dart b/packages/pigeon/test/kotlin_generator_test.dart index d0fcb1e3bc5c..2051e4a12a52 100644 --- a/packages/pigeon/test/kotlin_generator_test.dart +++ b/packages/pigeon/test/kotlin_generator_test.dart @@ -51,7 +51,7 @@ void main() { final String code = sink.toString(); expect(code, contains('data class Foobar (')); expect(code, contains('val field1: Long? = null')); - expect(code, contains('fun fromList(list: List): Foobar')); + expect(code, contains('fun fromList(__pigeon_list: List): Foobar')); expect(code, contains('fun toList(): List')); }); @@ -132,9 +132,10 @@ void main() { expect(code, contains('data class Bar (')); expect(code, contains('val field1: Foo,')); expect(code, contains('val field2: String')); - expect(code, contains('fun fromList(list: List): Bar')); - expect(code, contains('val field1 = Foo.ofRaw(list[0] as Int)!!\n')); - expect(code, contains('val field2 = list[1] as String\n')); + expect(code, contains('fun fromList(__pigeon_list: List): Bar')); + expect( + code, contains('val field1 = Foo.ofRaw(__pigeon_list[0] as Int)!!\n')); + expect(code, contains('val field2 = __pigeon_list[1] as String\n')); expect(code, contains('fun toList(): List')); }); @@ -236,11 +237,10 @@ void main() { channel.setMessageHandler { message, reply -> val args = message as List val inputArg = args[0] as Input - var wrapped: List - try { - wrapped = listOf(api.doSomething(inputArg)) + val wrapped: List = try { + listOf(api.doSomething(inputArg)) } catch (exception: Throwable) { - wrapped = wrapError(exception) + wrapError(exception) } reply.reply(wrapped) } @@ -390,7 +390,7 @@ void main() { expect( code, contains( - 'val aInt = list[1].let { if (it is Int) it.toLong() else it as Long }')); + 'val aInt = __pigeon_list[1].let { num -> if (num is Int) num.toLong() else num as Long }')); expect(code, contains('val aNullableBool: Boolean? = null')); expect(code, contains('val aNullableInt: Long? = null')); expect(code, contains('val aNullableDouble: Double? = null')); @@ -402,7 +402,7 @@ void main() { expect( code, contains( - 'val aNullableInt = list[9].let { if (it is Int) it.toLong() else it as Long? }')); + 'val aNullableInt = __pigeon_list[9].let { num -> if (num is Int) num.toLong() else num as Long? }')); }); test('gen one flutter api', () { @@ -591,8 +591,8 @@ void main() { ); final String code = sink.toString(); expect(code, contains('fun doSomething(): Output')); - expect(code, contains('wrapped = listOf(api.doSomething())')); - expect(code, contains('wrapped = wrapError(exception)')); + expect(code, contains('listOf(api.doSomething())')); + expect(code, contains('wrapError(exception)')); expect(code, contains('reply(wrapped)')); }); @@ -732,10 +732,8 @@ void main() { expect(code, contains('data class Outer')); expect(code, contains('data class Nested')); expect(code, contains('val nested: Nested? = null')); - expect(code, contains('fun fromList(list: List): Outer')); - expect( - code, contains('val nested: Nested? = (list[0] as List?)?.let')); - expect(code, contains('Nested.fromList(it)')); + expect(code, contains('fun fromList(__pigeon_list: List): Outer')); + expect(code, contains('val nested = __pigeon_list[0] as Nested?')); expect(code, contains('fun toList(): List')); }); @@ -1091,7 +1089,7 @@ void main() { ); final String code = sink.toString(); expect(code, contains('fun doit(): List')); - expect(code, contains('wrapped = listOf(api.doit())')); + expect(code, contains('listOf(api.doit())')); expect(code, contains('reply.reply(wrapped)')); }); @@ -1164,12 +1162,12 @@ void main() { expect( code, contains( - 'val xArg = args[0].let { if (it is Int) it.toLong() else it as Long }')); + 'val xArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long }')); expect( code, contains( - 'val yArg = args[1].let { if (it is Int) it.toLong() else it as Long }')); - expect(code, contains('wrapped = listOf(api.add(xArg, yArg))')); + 'val yArg = args[1].let { num -> if (num is Int) num.toLong() else num as Long }')); + expect(code, contains('listOf(api.add(xArg, yArg))')); expect(code, contains('reply.reply(wrapped)')); }); @@ -1207,7 +1205,7 @@ void main() { expect( code, contains( - 'val output = it[0].let { if (it is Int) it.toLong() else it as Long }'), + 'val output = it[0].let { num -> if (num is Int) num.toLong() else num as Long }'), ); expect(code, contains('callback(Result.success(output))')); expect( @@ -1312,7 +1310,7 @@ void main() { expect( code, contains( - 'val fooArg = args[0].let { if (it is Int) it.toLong() else it as Long? }')); + 'val fooArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long? }')); }); test('nullable argument flutter', () { diff --git a/packages/pigeon/test/objc_generator_test.dart b/packages/pigeon/test/objc_generator_test.dart index 7717f0ca8779..49ab94b78bc7 100644 --- a/packages/pigeon/test/objc_generator_test.dart +++ b/packages/pigeon/test/objc_generator_test.dart @@ -600,12 +600,8 @@ void main() { dartPackageName: DEFAULT_PACKAGE_NAME, ); final String code = sink.toString(); - expect( - code, - contains( - 'pigeonResult.nested = [Input nullableFromList:(GetNullableObjectAtIndex(list, 0))];')); - expect( - code, contains('self.nested ? [self.nested toList] : [NSNull null]')); + expect(code, + contains('pigeonResult.nested = GetNullableObjectAtIndex(list, 0);')); }); test('prefix class header', () { diff --git a/packages/pigeon/test/swift_generator_test.dart b/packages/pigeon/test/swift_generator_test.dart index a4eb67427b93..8fb544bbedb2 100644 --- a/packages/pigeon/test/swift_generator_test.dart +++ b/packages/pigeon/test/swift_generator_test.dart @@ -50,7 +50,8 @@ void main() { final String code = sink.toString(); expect(code, contains('struct Foobar')); expect(code, contains('var field1: Int64? = nil')); - expect(code, contains('static func fromList(_ list: [Any?]) -> Foobar?')); + expect(code, + contains('static func fromList(_ __pigeon_list: [Any?]) -> Foobar?')); expect(code, contains('func toList() -> [Any?]')); expect(code, isNot(contains('if ('))); }); @@ -575,8 +576,10 @@ void main() { expect(code, contains('struct Outer')); expect(code, contains('struct Nested')); expect(code, contains('var nested: Nested? = nil')); - expect(code, contains('static func fromList(_ list: [Any?]) -> Outer?')); - expect(code, contains('nested = Nested.fromList(nestedList)')); + expect(code, + contains('static func fromList(_ __pigeon_list: [Any?]) -> Outer?')); + expect( + code, contains('let nested: Nested? = nilOrValue(__pigeon_list[0])')); expect(code, contains('func toList() -> [Any?]')); expect(code, isNot(contains('if ('))); // Single-element list serializations should not have a trailing comma.