[pigeon] fixed bug where we can generate duplicate Result interfaces for Java (#328)
diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md
index 0e3ace1..e611fa4 100644
--- a/packages/pigeon/CHANGELOG.md
+++ b/packages/pigeon/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.2.1
+
+* Java: Fixed issue where multiple async HostApis can generate multiple Result interfaces.
+
## 0.2.0
* **BREAKING CHANGE** - Pigeon files must be null-safe now. That means the
diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart
index c1cf021..44500fc 100644
--- a/packages/pigeon/lib/generator_tools.dart
+++ b/packages/pigeon/lib/generator_tools.dart
@@ -8,7 +8,7 @@
import 'ast.dart';
/// The current version of pigeon. This must match the version in pubspec.yaml.
-const String pigeonVersion = '0.2.0';
+const String pigeonVersion = '0.2.1';
/// 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 1d3a1de..5f8efca 100644
--- a/packages/pigeon/lib/java_generator.dart
+++ b/packages/pigeon/lib/java_generator.dart
@@ -36,14 +36,6 @@
void _writeHostApi(Indent indent, Api api) {
assert(api.location == ApiLocation.host);
- if (api.methods.any((Method it) => it.isAsynchronous)) {
- indent.write('public interface Result<T> ');
- indent.scoped('{', '}', () {
- indent.writeln('void success(T result);');
- });
- indent.addln('');
- }
-
indent.writeln(
'/** Generated interface from Pigeon that represents a handler of messages from Flutter.*/');
indent.write('public interface ${api.name} ');
@@ -297,6 +289,16 @@
});
}
+ if (root.apis.any((Api api) =>
+ api.location == ApiLocation.host &&
+ api.methods.any((Method it) => it.isAsynchronous))) {
+ indent.addln('');
+ indent.write('public interface Result<T> ');
+ indent.scoped('{', '}', () {
+ indent.writeln('void success(T result);');
+ });
+ }
+
for (final Api api in root.apis) {
indent.addln('');
if (api.location == ApiLocation.host) {
diff --git a/packages/pigeon/pigeons/java_double_host_api.dart b/packages/pigeon/pigeons/java_double_host_api.dart
new file mode 100644
index 0000000..b220947
--- /dev/null
+++ b/packages/pigeon/pigeons/java_double_host_api.dart
@@ -0,0 +1,17 @@
+import 'package:pigeon/pigeon.dart';
+
+class Response {
+ int? result;
+}
+
+@HostApi()
+abstract class BridgeApi1 {
+ @async
+ Response call();
+}
+
+@HostApi()
+abstract class BridgeApi2 {
+ @async
+ Response call();
+}
diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml
index 8d041a3..06278fc 100644
--- a/packages/pigeon/pubspec.yaml
+++ b/packages/pigeon/pubspec.yaml
@@ -1,5 +1,5 @@
name: pigeon
-version: 0.2.0 # This must match the version in lib/generator_tools.dart
+version: 0.2.1 # This must match the version in lib/generator_tools.dart
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
homepage: https://github.com/flutter/packages/tree/master/packages/pigeon
dependencies:
diff --git a/packages/pigeon/run_tests.sh b/packages/pigeon/run_tests.sh
index bc6ce58..d76d5f8 100755
--- a/packages/pigeon/run_tests.sh
+++ b/packages/pigeon/run_tests.sh
@@ -244,6 +244,7 @@
test_pigeon_android ./pigeons/all_datatypes.dart
test_pigeon_android ./pigeons/async_handlers.dart
test_pigeon_android ./pigeons/host2flutter.dart
+ test_pigeon_android ./pigeons/java_double_host_api.dart
test_pigeon_android ./pigeons/list.dart
test_pigeon_android ./pigeons/message.dart
test_pigeon_android ./pigeons/void_arg_flutter.dart