[pigeon] reved pigeon, tweaked contributors changes before publish (#304)
diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md
index 0e5faee..5497e80 100644
--- a/packages/pigeon/CHANGELOG.md
+++ b/packages/pigeon/CHANGELOG.md
@@ -1,3 +1,9 @@
+## 0.1.22
+
+* Java code generator enhancements:
+ * Added linter tests to CI.
+ * Fixed some linter issues in the Java code.
+
## 0.1.21
* Fixed decode method on generated Flutter classes that use null-safety and have
diff --git a/packages/pigeon/README.md b/packages/pigeon/README.md
index f597767..30fa261 100644
--- a/packages/pigeon/README.md
+++ b/packages/pigeon/README.md
@@ -68,6 +68,48 @@
Note: Generics for List and Map aren't supported yet.
+## Asynchronous Handlers
+
+By default Pigeon will generate synchronous handlers for messages. If you want
+to be able to respond to a message asynchronously you can use the `@async`
+annotation as of version 0.1.20.
+
+Example:
+
+```dart
+class Value {
+ int number;
+}
+
+@HostApi()
+abstract class Api2Host {
+ @async
+ Value calculate(Value value);
+}
+```
+
+Generates:
+
+```objc
+// Objc
+@protocol Api2Host
+-(void)calculate:(nullable Value *)input
+ completion:(void(^)(Value *_Nullable, FlutterError *_Nullable))completion;
+@end
+```
+
+```java
+// Java
+public interface Result<T> {
+ void success(T result);
+}
+
+/** Generated interface from Pigeon that represents a handler of messages from Flutter.*/
+public interface Api2Host {
+ void calculate(Value arg, Result<Value> result);
+}
+```
+
## Feedback
File an issue in [flutter/flutter](https://github.com/flutter/flutter) with the
diff --git a/packages/pigeon/example/README.md b/packages/pigeon/example/README.md
index 8b8409d..0c8fdb8 100644
--- a/packages/pigeon/example/README.md
+++ b/packages/pigeon/example/README.md
@@ -120,7 +120,7 @@
Kotlin can be found at
[gaaclarke/flutter_plugin_example](https://github.com/gaaclarke/pigeon_plugin_example).
-## Swift Add-to-app Example
+## Swift / Kotlin Add-to-app Example
A full example of using Pigeon for add-to-app with Swift on iOS can be found at
-[gaaclarke/GiantsA2A](https://github.com/gaaclarke/GiantsA2A).
+[samples/add_to_app/books](https://github.com/flutter/samples/tree/master/add_to_app/books).
diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart
index d196e26..294962c 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.1.21';
+const String pigeonVersion = '0.1.22';
/// 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 c79a18e..51d21f7 100644
--- a/packages/pigeon/lib/java_generator.dart
+++ b/packages/pigeon/lib/java_generator.dart
@@ -15,7 +15,7 @@
'Int64List': 'long[]',
'Float64List': 'double[]',
'List': 'List<Object>',
- 'Map': 'Map<String, Object>',
+ 'Map': 'Map<Object, Object>',
};
/// Options that control how Java code will be generated.
@@ -169,38 +169,18 @@
if (func.argType != 'void') {
indent.writeln('Map<String, Object> inputMap = argInput.toMap();');
}
- indent.write('if (callback != null)');
- indent.scoped('{', '}', () {
- indent.write('channel.send($sendArgument, channelReply -> ');
- indent.scoped('{', '});', () {
- if (func.returnType == 'void') {
- indent.writeln('callback.reply(null);');
- } else {
- indent.writeln('Map outputMap = (Map)channelReply;');
- indent.writeln('@SuppressWarnings("ConstantConditions")');
- indent.writeln(
- '${func.returnType} output = ${func.returnType}.fromMap(outputMap);');
- indent.writeln('callback.reply(output);');
- }
- });
+ indent.write('channel.send($sendArgument, channelReply -> ');
+ indent.scoped('{', '});', () {
+ if (func.returnType == 'void') {
+ indent.writeln('callback.reply(null);');
+ } else {
+ indent.writeln('Map outputMap = (Map)channelReply;');
+ indent.writeln('@SuppressWarnings("ConstantConditions")');
+ indent.writeln(
+ '${func.returnType} output = ${func.returnType}.fromMap(outputMap);');
+ indent.writeln('callback.reply(output);');
+ }
});
- indent.write(' else ');
- indent.scoped('{', '}', () {
- indent.writeln('channel.send($sendArgument, null);');
- });
- });
-
- if (func.argType == 'void') {
- indent.write('public void ${func.name}() ');
- } else {
- indent.write('public void ${func.name}(${func.argType} argInput) ');
- }
- indent.scoped('{', '}', () {
- if (func.argType == 'void') {
- indent.writeln('${func.name}(null);');
- } else {
- indent.writeln('${func.name}(argInput, null);');
- }
});
}
});
diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml
index e534e2d..7560a04 100644
--- a/packages/pigeon/pubspec.yaml
+++ b/packages/pigeon/pubspec.yaml
@@ -1,5 +1,5 @@
name: pigeon
-version: 0.1.21 # This must match the version in lib/generator_tools.dart
+version: 0.1.22 # 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 643a1ca..d3dbe0a 100755
--- a/packages/pigeon/run_tests.sh
+++ b/packages/pigeon/run_tests.sh
@@ -124,7 +124,7 @@
pub get
dart analyze bin
dart analyze lib
-pub run test test/
+dart --no-sound-null-safety test
###############################################################################
# Execute without arguments test
diff --git a/packages/pigeon/test/java_generator_test.dart b/packages/pigeon/test/java_generator_test.dart
index c453231..398ca69 100644
--- a/packages/pigeon/test/java_generator_test.dart
+++ b/packages/pigeon/test/java_generator_test.dart
@@ -257,7 +257,7 @@
generateJava(javaOptions, root, sink);
final String code = sink.toString();
expect(code, contains('public static class Foobar'));
- expect(code, contains('private Map<String, Object> field1;'));
+ expect(code, contains('private Map<Object, Object> field1;'));
});
test('gen nested', () {