From 2f19ca1e35530afe9364af6e9d45b1155975fd98 Mon Sep 17 00:00:00 2001 From: RobinCombrink Date: Sat, 1 Jun 2024 00:01:38 +0200 Subject: [PATCH 1/5] Add @JvmOverloads to kotlin generation --- packages/pigeon/lib/kotlin_generator.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pigeon/lib/kotlin_generator.dart b/packages/pigeon/lib/kotlin_generator.dart index 18df439d740..bb1479957c3 100644 --- a/packages/pigeon/lib/kotlin_generator.dart +++ b/packages/pigeon/lib/kotlin_generator.dart @@ -431,7 +431,7 @@ class KotlinGenerator extends StructuredGenerator { indent.writeln( '/** Sets up an instance of `$apiName` to handle messages through the `binaryMessenger`. */'); indent.write( - 'fun setUp(binaryMessenger: BinaryMessenger, api: $apiName?, messageChannelSuffix: String = "") '); + '@JvmOverloads fun setUp(binaryMessenger: BinaryMessenger, api: $apiName?, messageChannelSuffix: String = "") '); indent.addScoped('{', '}', () { indent.writeln( r'val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""'); From d9b03755553876ce092f3be3354605cbb15783e4 Mon Sep 17 00:00:00 2001 From: RobinCombrink Date: Sat, 1 Jun 2024 00:02:39 +0200 Subject: [PATCH 2/5] Version Bump --- packages/pigeon/CHANGELOG.md | 4 ++++ packages/pigeon/lib/generator_tools.dart | 2 +- packages/pigeon/pubspec.yaml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 8b083f76704..13033b336a8 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,7 @@ +## 19.0.2 + +* [kotlin] Adds the `@JvmOverloads` to the `HostApi` setUp method. This prevents the calling Java code from having to provide an empty `String` as Kotlin provides it by default + ## 19.0.1 * [dart] Updates `PigeonInstanceMangerApi` to use the shared api channel code. diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 85c2a2c75ab..a02efc0fe84 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 = '19.0.1'; +const String pigeonVersion = '19.0.2'; /// Prefix for all local variables in methods. /// diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index fa7ffcc9ca9..edbba1f4027 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: 19.0.1 # This must match the version in lib/generator_tools.dart +version: 19.0.2 # This must match the version in lib/generator_tools.dart environment: sdk: ^3.2.0 From cbd618b09bfde70fe1122bbc24eda3a6b7e95362 Mon Sep 17 00:00:00 2001 From: RobinCombrink Date: Sat, 1 Jun 2024 14:04:47 +0200 Subject: [PATCH 3/5] Place the annotation in accordance with kotlin formatting --- packages/pigeon/lib/kotlin_generator.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/pigeon/lib/kotlin_generator.dart b/packages/pigeon/lib/kotlin_generator.dart index bb1479957c3..e805034ee2c 100644 --- a/packages/pigeon/lib/kotlin_generator.dart +++ b/packages/pigeon/lib/kotlin_generator.dart @@ -430,8 +430,9 @@ class KotlinGenerator extends StructuredGenerator { }); indent.writeln( '/** Sets up an instance of `$apiName` to handle messages through the `binaryMessenger`. */'); + indent.writeln('@JvmOverloads'); indent.write( - '@JvmOverloads fun setUp(binaryMessenger: BinaryMessenger, api: $apiName?, messageChannelSuffix: String = "") '); + 'fun setUp(binaryMessenger: BinaryMessenger, api: $apiName?, messageChannelSuffix: String = "") '); indent.addScoped('{', '}', () { indent.writeln( r'val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""'); From 1c3cc03a0658f975b6c5f44d24feb785b1a3d62d Mon Sep 17 00:00:00 2001 From: RobinCombrink Date: Sat, 1 Jun 2024 14:46:19 +0200 Subject: [PATCH 4/5] Include the `@JvmOverloads` annotation in the example app generated kotlin code --- .../src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt | 1 + 1 file changed, 1 insertion(+) 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 48981666f24..7f0e75cefa9 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 @@ -118,6 +118,7 @@ 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`. */ + @JvmOverloads fun setUp( binaryMessenger: BinaryMessenger, api: ExampleHostApi?, From acac28f46599adedab4be37bf81a5fe57e65da2f Mon Sep 17 00:00:00 2001 From: RobinCombrink Date: Sat, 1 Jun 2024 14:47:01 +0200 Subject: [PATCH 5/5] Include the `@JvmOverloads` annotation in the kotlin generator unit test --- packages/pigeon/test/kotlin_generator_test.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/pigeon/test/kotlin_generator_test.dart b/packages/pigeon/test/kotlin_generator_test.dart index 2051e4a12a5..40c1e75c3aa 100644 --- a/packages/pigeon/test/kotlin_generator_test.dart +++ b/packages/pigeon/test/kotlin_generator_test.dart @@ -231,6 +231,10 @@ void main() { final String code = sink.toString(); expect(code, contains('interface Api')); expect(code, contains('fun doSomething(input: Input): Output')); + expect(code, contains(''' + @JvmOverloads + fun setUp(binaryMessenger: BinaryMessenger, api: Api?, messageChannelSuffix: String = "") { + ''')); expect(code, contains('channel.setMessageHandler')); expect(code, contains(''' if (api != null) {