Skip to content

Commit

Permalink
[pigeon] Kotlin/Java method overloading for the setUp method (flutt…
Browse files Browse the repository at this point in the history
…er#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
  • Loading branch information
RobinCombrink authored Jun 3, 2024
1 parent 539a5f9 commit bb8c7b2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ interface ExampleHostApi {
/** The codec used by ExampleHostApi. */
val codec: MessageCodec<Any?> by lazy { ExampleHostApiCodec }
/** Sets up an instance of `ExampleHostApi` to handle messages through the `binaryMessenger`. */
@JvmOverloads
fun setUp(
binaryMessenger: BinaryMessenger,
api: ExampleHostApi?,
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/lib/generator_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
1 change: 1 addition & 0 deletions packages/pigeon/lib/kotlin_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
});
indent.writeln(
'/** Sets up an instance of `$apiName` to handle messages through the `binaryMessenger`. */');
indent.writeln('@JvmOverloads');
indent.write(
'fun setUp(binaryMessenger: BinaryMessenger, api: $apiName?, messageChannelSuffix: String = "") ');
indent.addScoped('{', '}', () {
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions packages/pigeon/test/kotlin_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit bb8c7b2

Please sign in to comment.