[pigeon] reved pigeon, tweaked contributors changes before publish (#304)

This commit is contained in:
gaaclarke
2021-03-10 11:22:08 -08:00
committed by GitHub
parent c38b3d3ef9
commit a50a64fb89
8 changed files with 66 additions and 38 deletions

View File

@ -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

View File

@ -68,6 +68,48 @@ channels supports
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

View File

@ -120,7 +120,7 @@ A downloadable example of using Pigeon to create a Flutter Plugin with Swift and
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).

View File

@ -8,7 +8,7 @@ import 'dart:mirrors';
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() {

View File

@ -15,7 +15,7 @@ const Map<String, String> _javaTypeForDartTypeMap = <String, String>{
'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 @@ void _writeFlutterApi(Indent indent, Api api) {
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);');
}
});
}
});

View File

@ -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:

View File

@ -124,7 +124,7 @@ fi
pub get
dart analyze bin
dart analyze lib
pub run test test/
dart --no-sound-null-safety test
###############################################################################
# Execute without arguments test

View File

@ -257,7 +257,7 @@ void main() {
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', () {