From bf55e6d85d82763899fb12d07066adf287c49047 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Thu, 22 Feb 2024 15:13:47 -0800 Subject: [PATCH 1/3] add logic to remove test class and update generation to use it --- packages/pigeon/CHANGELOG.md | 3 +- packages/pigeon/lib/generator_tools.dart | 2 +- packages/pigeon/lib/kotlin_generator.dart | 35 +++-- packages/pigeon/lib/pigeon_lib.dart | 1 + .../com/example/test_plugin/CoreTests.gen.kt | 123 ++++++------------ packages/pigeon/pubspec.yaml | 2 +- packages/pigeon/tool/shared/generation.dart | 16 ++- 7 files changed, 84 insertions(+), 98 deletions(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 967426ce7c2a..7f10b3a431c1 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,5 +1,6 @@ -## NEXT +## 17.0.1 +* [kotlin] Adds `includeErrorClass` to `KotlinOptions`. * Updates minimum supported SDK version to Flutter 3.13/Dart 3.1. ## 17.0.0 diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 99da7e0a4d56..dbf5e962d58b 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -13,7 +13,7 @@ import 'ast.dart'; /// The current version of pigeon. /// /// This must match the version in pubspec.yaml. -const String pigeonVersion = '17.0.0'; +const String pigeonVersion = '17.0.1'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/lib/kotlin_generator.dart b/packages/pigeon/lib/kotlin_generator.dart index 29e3e3662554..39697fa3242d 100644 --- a/packages/pigeon/lib/kotlin_generator.dart +++ b/packages/pigeon/lib/kotlin_generator.dart @@ -32,6 +32,7 @@ class KotlinOptions { this.package, this.copyrightHeader, this.errorClassName, + this.includeErrorClass = true, }); /// The package where the generated class will live. @@ -43,6 +44,12 @@ class KotlinOptions { /// The name of the error class used for passing custom error parameters. final String? errorClassName; + /// Whether to include the error class in generation. + /// + /// This should only ever be set to false if you have another generated + /// Kotlin file in the same directory. + final bool includeErrorClass; + /// Creates a [KotlinOptions] from a Map representation where: /// `x = KotlinOptions.fromMap(x.toMap())`. static KotlinOptions fromMap(Map map) { @@ -50,6 +57,7 @@ class KotlinOptions { package: map['package'] as String?, copyrightHeader: map['copyrightHeader'] as Iterable?, errorClassName: map['errorClassName'] as String?, + includeErrorClass: map['includeErrorClass'] as bool? ?? true, ); } @@ -60,6 +68,7 @@ class KotlinOptions { if (package != null) 'package': package!, if (copyrightHeader != null) 'copyrightHeader': copyrightHeader!, if (errorClassName != null) 'errorClassName': errorClassName!, + 'includeErrorClass': includeErrorClass, }; return result; } @@ -298,7 +307,7 @@ class KotlinGenerator extends StructuredGenerator { addDocumentationComments( indent, field.documentationComments, _docCommentSpec); indent.write( - 'val ${field.name}: ${_nullsafeKotlinTypeForDartType(field.type)}'); + 'val ${field.name}: ${_nullSafeKotlinTypeForDartType(field.type)}'); final String defaultNil = field.type.isNullable ? ' = null' : ''; indent.add(defaultNil); } @@ -361,16 +370,15 @@ class KotlinGenerator extends StructuredGenerator { }); }); - final String errorClassName = _getErrorClassName(generatorOptions); for (final Method method in api.methods) { _writeFlutterMethod( indent, + generatorOptions: generatorOptions, name: method.name, parameters: method.parameters, returnType: method.returnType, channelName: makeChannelName(api, method, dartPackageName), documentationComments: method.documentationComments, - errorClassName: errorClassName, dartPackageName: dartPackageName, ); } @@ -588,7 +596,9 @@ class KotlinGenerator extends StructuredGenerator { if (hasFlutterApi) { _writeCreateConnectionError(generatorOptions, indent); } - _writeErrorClass(generatorOptions, indent); + if (generatorOptions.includeErrorClass) { + _writeErrorClass(generatorOptions, indent); + } } static void _writeMethodDeclaration( @@ -606,7 +616,7 @@ class KotlinGenerator extends StructuredGenerator { final List argSignature = []; if (parameters.isNotEmpty) { final Iterable argTypes = parameters - .map((NamedType e) => _nullsafeKotlinTypeForDartType(e.type)); + .map((NamedType e) => _nullSafeKotlinTypeForDartType(e.type)); final Iterable argNames = indexMap(parameters, getArgumentName); argSignature.addAll( map2( @@ -620,7 +630,7 @@ class KotlinGenerator extends StructuredGenerator { } final String returnTypeString = - returnType.isVoid ? '' : _nullsafeKotlinTypeForDartType(returnType); + returnType.isVoid ? '' : _nullSafeKotlinTypeForDartType(returnType); final String resultType = returnType.isVoid ? 'Unit' : returnTypeString; addDocumentationComments(indent, documentationComments, _docCommentSpec); @@ -700,7 +710,7 @@ class KotlinGenerator extends StructuredGenerator { indent.write('$call '); final String resultType = returnType.isVoid ? 'Unit' - : _nullsafeKotlinTypeForDartType(returnType); + : _nullSafeKotlinTypeForDartType(returnType); indent.addScoped('{ result: Result<$resultType> ->', '}', () { indent.writeln('val error = result.exceptionOrNull()'); indent.writeScoped('if (error != null) {', '}', () { @@ -751,11 +761,11 @@ class KotlinGenerator extends StructuredGenerator { void _writeFlutterMethod( Indent indent, { + required KotlinOptions generatorOptions, required String name, required List parameters, required TypeDeclaration returnType, required String channelName, - required String errorClassName, required String dartPackageName, List documentationComments = const [], int? minApiRequirement, @@ -778,6 +788,7 @@ class KotlinGenerator extends StructuredGenerator { getArgumentName: _getSafeArgumentName, ); + final String errorClassName = _getErrorClassName(generatorOptions); indent.addScoped('{', '}', () { onWriteBody( indent, @@ -910,9 +921,9 @@ String _kotlinTypeForBuiltinGenericDartType(TypeDeclaration type) { } else { switch (type.baseName) { case 'List': - return 'List<${_nullsafeKotlinTypeForDartType(type.typeArguments.first)}>'; + return 'List<${_nullSafeKotlinTypeForDartType(type.typeArguments.first)}>'; case 'Map': - return 'Map<${_nullsafeKotlinTypeForDartType(type.typeArguments.first)}, ${_nullsafeKotlinTypeForDartType(type.typeArguments.last)}>'; + return 'Map<${_nullSafeKotlinTypeForDartType(type.typeArguments.first)}, ${_nullSafeKotlinTypeForDartType(type.typeArguments.last)}>'; default: return '${type.baseName}<${_flattenTypeArguments(type.typeArguments)}>'; } @@ -946,7 +957,7 @@ String _kotlinTypeForDartType(TypeDeclaration type) { return _kotlinTypeForBuiltinDartType(type) ?? type.baseName; } -String _nullsafeKotlinTypeForDartType(TypeDeclaration type) { +String _nullSafeKotlinTypeForDartType(TypeDeclaration type) { final String nullSafe = type.isNullable ? '?' : ''; return '${_kotlinTypeForDartType(type)}$nullSafe'; } @@ -969,7 +980,7 @@ String _cast(Indent indent, String variable, {required TypeDeclaration type}) { } return '${type.baseName}.ofRaw($variable as Int)!!'; } - return '$variable as ${_nullsafeKotlinTypeForDartType(type)}'; + return '$variable as ${_nullSafeKotlinTypeForDartType(type)}'; } String _castInt(bool isNullable) { diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 187aa3466b2a..8d6fc961c2ec 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -776,6 +776,7 @@ class KotlinGeneratorAdapter implements GeneratorAdapter { options.kotlinOptions ?? const KotlinOptions(); kotlinOptions = kotlinOptions.merge(KotlinOptions( errorClassName: kotlinOptions.errorClassName ?? 'FlutterError', + includeErrorClass: kotlinOptions.includeErrorClass, copyrightHeader: options.copyrightHeader != null ? _lineReader( path.posix.join(options.basePath ?? '', options.copyrightHeader)) 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 c3ec9d98caf6..b97e72c01469 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 @@ -20,7 +20,7 @@ private fun wrapResult(result: Any?): List { } private fun wrapError(exception: Throwable): List { - if (exception is CoreTestsError) { + if (exception is FlutterError) { return listOf(exception.code, exception.message, exception.details) } else { return listOf( @@ -30,24 +30,11 @@ private fun wrapError(exception: Throwable): List { } } -private fun createConnectionError(channelName: String): CoreTestsError { - return CoreTestsError( +private fun createConnectionError(channelName: String): FlutterError { + return FlutterError( "channel-error", "Unable to establish connection on channel: '$channelName'.", "") } -/** - * Error class for passing custom error details to Flutter via a thrown PlatformException. - * - * @property code The error code. - * @property message The error message. - * @property details The error details. Must be a datatype supported by the api codec. - */ -class CoreTestsError( - val code: String, - override val message: String? = null, - val details: Any? = null -) : Throwable() - enum class AnEnum(val raw: Int) { ONE(0), TWO(1), @@ -2399,8 +2386,7 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(null) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else { callback(Result.success(Unit)) } @@ -2417,8 +2403,7 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(null) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else { val output = it[0] callback(Result.success(output)) @@ -2436,8 +2421,7 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(null) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else { callback(Result.success(Unit)) } @@ -2454,12 +2438,11 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(everythingArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else if (it[0] == null) { callback( Result.failure( - CoreTestsError( + FlutterError( "null-error", "Flutter api returned null value for non-null return value.", ""))) @@ -2483,8 +2466,7 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(everythingArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else { val output = it[0] as AllNullableTypes? callback(Result.success(output)) @@ -2511,12 +2493,11 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(aNullableBoolArg, aNullableIntArg, aNullableStringArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else if (it[0] == null) { callback( Result.failure( - CoreTestsError( + FlutterError( "null-error", "Flutter api returned null value for non-null return value.", ""))) @@ -2537,12 +2518,11 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(aBoolArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else if (it[0] == null) { callback( Result.failure( - CoreTestsError( + FlutterError( "null-error", "Flutter api returned null value for non-null return value.", ""))) @@ -2563,12 +2543,11 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(anIntArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else if (it[0] == null) { callback( Result.failure( - CoreTestsError( + FlutterError( "null-error", "Flutter api returned null value for non-null return value.", ""))) @@ -2589,12 +2568,11 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(aDoubleArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else if (it[0] == null) { callback( Result.failure( - CoreTestsError( + FlutterError( "null-error", "Flutter api returned null value for non-null return value.", ""))) @@ -2615,12 +2593,11 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(aStringArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else if (it[0] == null) { callback( Result.failure( - CoreTestsError( + FlutterError( "null-error", "Flutter api returned null value for non-null return value.", ""))) @@ -2641,12 +2618,11 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(aListArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else if (it[0] == null) { callback( Result.failure( - CoreTestsError( + FlutterError( "null-error", "Flutter api returned null value for non-null return value.", ""))) @@ -2667,12 +2643,11 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(aListArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else if (it[0] == null) { callback( Result.failure( - CoreTestsError( + FlutterError( "null-error", "Flutter api returned null value for non-null return value.", ""))) @@ -2693,12 +2668,11 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(aMapArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else if (it[0] == null) { callback( Result.failure( - CoreTestsError( + FlutterError( "null-error", "Flutter api returned null value for non-null return value.", ""))) @@ -2719,12 +2693,11 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(anEnumArg.raw)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else if (it[0] == null) { callback( Result.failure( - CoreTestsError( + FlutterError( "null-error", "Flutter api returned null value for non-null return value.", ""))) @@ -2745,8 +2718,7 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(aBoolArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else { val output = it[0] as Boolean? callback(Result.success(output)) @@ -2764,8 +2736,7 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(anIntArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + 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? } callback(Result.success(output)) @@ -2783,8 +2754,7 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(aDoubleArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else { val output = it[0] as Double? callback(Result.success(output)) @@ -2802,8 +2772,7 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(aStringArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else { val output = it[0] as String? callback(Result.success(output)) @@ -2821,8 +2790,7 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(aListArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else { val output = it[0] as ByteArray? callback(Result.success(output)) @@ -2840,8 +2808,7 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(aListArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else { val output = it[0] as List? callback(Result.success(output)) @@ -2862,8 +2829,7 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(aMapArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else { val output = it[0] as Map? callback(Result.success(output)) @@ -2881,8 +2847,7 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(anEnumArg?.raw)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + 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) } callback(Result.success(output)) @@ -2903,8 +2868,7 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(null) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else { callback(Result.success(Unit)) } @@ -2921,12 +2885,11 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(aStringArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else if (it[0] == null) { callback( Result.failure( - CoreTestsError( + FlutterError( "null-error", "Flutter api returned null value for non-null return value.", ""))) @@ -3083,12 +3046,11 @@ class FlutterSmallApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(msgArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else if (it[0] == null) { callback( Result.failure( - CoreTestsError( + FlutterError( "null-error", "Flutter api returned null value for non-null return value.", ""))) @@ -3108,12 +3070,11 @@ class FlutterSmallApi(private val binaryMessenger: BinaryMessenger) { channel.send(listOf(aStringArg)) { if (it is List<*>) { if (it.size > 1) { - callback( - Result.failure(CoreTestsError(it[0] as String, it[1] as String, it[2] as String?))) + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else if (it[0] == null) { callback( Result.failure( - CoreTestsError( + FlutterError( "null-error", "Flutter api returned null value for non-null return value.", ""))) diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index 9693bac54588..2c799c7d66a8 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: 17.0.0 # This must match the version in lib/generator_tools.dart +version: 17.0.1 # This must match the version in lib/generator_tools.dart environment: sdk: ^3.1.0 diff --git a/packages/pigeon/tool/shared/generation.dart b/packages/pigeon/tool/shared/generation.dart index 9915e26aa57d..68bcc10d6163 100644 --- a/packages/pigeon/tool/shared/generation.dart +++ b/packages/pigeon/tool/shared/generation.dart @@ -81,6 +81,13 @@ Future generateTestPigeons({required String baseDir}) async { final Set skipLanguages = _unsupportedFiles[input] ?? {}; + final bool kotlinErrorClassGenerationTestFiles = + input == 'core_tests' || input == 'background_platform_channels'; + + final String kotlinErrorName = kotlinErrorClassGenerationTestFiles + ? 'FlutterError' + : '${pascalCaseName}Error'; + // Generate the default language test plugin output. int generateCode = await runPigeon( input: './pigeons/$input.dart', @@ -90,7 +97,8 @@ Future generateTestPigeons({required String baseDir}) async { ? null : '$outputBase/android/src/main/kotlin/com/example/test_plugin/$pascalCaseName.gen.kt', kotlinPackage: 'com.example.test_plugin', - kotlinErrorClassName: '${pascalCaseName}Error', + kotlinErrorClassName: kotlinErrorName, + kotlinIncludeErrorClass: input != 'core_tests', // iOS swiftOut: skipLanguages.contains(GeneratorLanguage.swift) ? null @@ -176,6 +184,7 @@ Future runPigeon({ String? kotlinOut, String? kotlinPackage, String? kotlinErrorClassName, + bool kotlinIncludeErrorClass = true, String? swiftOut, String? cppHeaderOut, String? cppSourceOut, @@ -217,7 +226,10 @@ Future runPigeon({ javaOptions: JavaOptions(package: javaPackage), kotlinOut: kotlinOut, kotlinOptions: KotlinOptions( - package: kotlinPackage, errorClassName: kotlinErrorClassName), + package: kotlinPackage, + errorClassName: kotlinErrorClassName, + includeErrorClass: kotlinIncludeErrorClass, + ), objcHeaderOut: objcHeaderOut, objcSourceOut: objcSourceOut, objcOptions: ObjcOptions(prefix: objcPrefix), From 9211412f9636eb78e20dfd0283052d5256d9f0c3 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Thu, 22 Feb 2024 15:29:46 -0800 Subject: [PATCH 2/3] update test file --- .../src/main/kotlin/com/example/test_plugin/TestPlugin.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 c14f7129e40d..8b4e8bc4fb18 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 @@ -39,7 +39,7 @@ class TestPlugin : FlutterPlugin, HostIntegrationCoreApi { } override fun throwFlutterError(): Any? { - throw CoreTestsError("code", "message", "details") + throw FlutterError("code", "message", "details") } override fun echoInt(anInt: Long): Long { @@ -170,7 +170,7 @@ class TestPlugin : FlutterPlugin, HostIntegrationCoreApi { } override fun throwAsyncFlutterError(callback: (Result) -> Unit) { - callback(Result.failure(CoreTestsError("code", "message", "details"))) + callback(Result.failure(FlutterError("code", "message", "details"))) } override fun echoAsyncAllTypes(everything: AllTypes, callback: (Result) -> Unit) { From c5fc5c9e3f1a891bf13795829048e48409defe39 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Tue, 27 Feb 2024 13:47:20 -0800 Subject: [PATCH 3/3] version --- packages/pigeon/CHANGELOG.md | 2 +- packages/pigeon/lib/generator_tools.dart | 2 +- packages/pigeon/pubspec.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 7f10b3a431c1..dd5c01fe48c9 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,4 +1,4 @@ -## 17.0.1 +## 17.1.0 * [kotlin] Adds `includeErrorClass` to `KotlinOptions`. * Updates minimum supported SDK version to Flutter 3.13/Dart 3.1. diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index dbf5e962d58b..54e980eb34a0 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -13,7 +13,7 @@ import 'ast.dart'; /// The current version of pigeon. /// /// This must match the version in pubspec.yaml. -const String pigeonVersion = '17.0.1'; +const String pigeonVersion = '17.1.0'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index 2c799c7d66a8..29c2b26595e3 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: 17.0.1 # This must match the version in lib/generator_tools.dart +version: 17.1.0 # This must match the version in lib/generator_tools.dart environment: sdk: ^3.1.0