Skip to content

Commit bb8c7b2

Browse files
[pigeon] Kotlin/Java method overloading for the setUp method (flutter#6843)
This PR allows Java code to call the Kotlin `setUp` method without the optional `messageChannelSuffix` parameter. I am not 100% sure how the tests should be adjusted to accurately test the Java/Kotlin interop - any advice there would be welcome? ### Affected issues: flutter#149027
1 parent 539a5f9 commit bb8c7b2

File tree

6 files changed

+12
-2
lines changed

6 files changed

+12
-2
lines changed

packages/pigeon/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 19.0.2
2+
3+
* [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
4+
15
## 19.0.1
26

37
* [dart] Updates `PigeonInstanceMangerApi` to use the shared api channel code.

packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ interface ExampleHostApi {
118118
/** The codec used by ExampleHostApi. */
119119
val codec: MessageCodec<Any?> by lazy { ExampleHostApiCodec }
120120
/** Sets up an instance of `ExampleHostApi` to handle messages through the `binaryMessenger`. */
121+
@JvmOverloads
121122
fun setUp(
122123
binaryMessenger: BinaryMessenger,
123124
api: ExampleHostApi?,

packages/pigeon/lib/generator_tools.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'ast.dart';
1313
/// The current version of pigeon.
1414
///
1515
/// This must match the version in pubspec.yaml.
16-
const String pigeonVersion = '19.0.1';
16+
const String pigeonVersion = '19.0.2';
1717

1818
/// Prefix for all local variables in methods.
1919
///

packages/pigeon/lib/kotlin_generator.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
430430
});
431431
indent.writeln(
432432
'/** Sets up an instance of `$apiName` to handle messages through the `binaryMessenger`. */');
433+
indent.writeln('@JvmOverloads');
433434
indent.write(
434435
'fun setUp(binaryMessenger: BinaryMessenger, api: $apiName?, messageChannelSuffix: String = "") ');
435436
indent.addScoped('{', '}', () {

packages/pigeon/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: pigeon
22
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
33
repository: https://github.com/flutter/packages/tree/main/packages/pigeon
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+pigeon%22
5-
version: 19.0.1 # This must match the version in lib/generator_tools.dart
5+
version: 19.0.2 # This must match the version in lib/generator_tools.dart
66

77
environment:
88
sdk: ^3.2.0

packages/pigeon/test/kotlin_generator_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ void main() {
231231
final String code = sink.toString();
232232
expect(code, contains('interface Api'));
233233
expect(code, contains('fun doSomething(input: Input): Output'));
234+
expect(code, contains('''
235+
@JvmOverloads
236+
fun setUp(binaryMessenger: BinaryMessenger, api: Api?, messageChannelSuffix: String = "") {
237+
'''));
234238
expect(code, contains('channel.setMessageHandler'));
235239
expect(code, contains('''
236240
if (api != null) {

0 commit comments

Comments
 (0)