started handling null correctly for setup methods in java (#155)

This commit is contained in:
gaaclarke
2020-05-13 13:51:04 -07:00
committed by GitHub
parent ed004de397
commit c41258ea35
8 changed files with 51 additions and 36 deletions

View File

@ -1,3 +1,7 @@
## 0.1.0-experimental.11
* Fixed setting an api to null in Java.
## 0.1.0-experimental.10
* Added support for void argument functions.

View File

@ -1,4 +1,4 @@
// Autogenerated from Pigeon (v0.1.0-experimental.10), do not edit directly.
// Autogenerated from Pigeon (v0.1.0-experimental.11), do not edit directly.
// See also: https://pub.dev/packages/pigeon
#import <Foundation/Foundation.h>
@protocol FlutterBinaryMessenger;

View File

@ -1,4 +1,4 @@
// Autogenerated from Pigeon (v0.1.0-experimental.10), do not edit directly.
// Autogenerated from Pigeon (v0.1.0-experimental.11), do not edit directly.
// See also: https://pub.dev/packages/pigeon
#import "dartle.h"
#import <Flutter/Flutter.h>

View File

@ -1,4 +1,4 @@
// Autogenerated from Pigeon (v0.1.0-experimental.10), do not edit directly.
// Autogenerated from Pigeon (v0.1.0-experimental.11), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import
import 'dart:async';

View File

@ -8,7 +8,7 @@ import 'dart:mirrors';
import 'ast.dart';
/// The current version of pigeon.
const String pigeonVersion = '0.1.0-experimental.10';
const String pigeonVersion = '0.1.0-experimental.11';
/// Read all the content from [stdin] to a String.
String readStdin() {
@ -64,12 +64,16 @@ class Indent {
/// Scoped increase of the ident level. For the execution of [func] the
/// indentation will be incremented.
void scoped(String begin, String end, Function func) {
if (begin != null) {
_sink.write(begin + newline);
}
inc();
func();
dec();
if (end != null) {
_sink.write(str() + end + newline);
}
}
/// Add [str] with indentation and a newline.
void writeln(String str) {

View File

@ -53,6 +53,8 @@ void _writeHostApi(Indent indent, Api api) {
'new BasicMessageChannel<Object>(binaryMessenger, "$channelName", new StandardMessageCodec());');
indent.dec();
indent.dec();
indent.write('if (api != null) ');
indent.scoped('{', '} else {', () {
indent.write(
'channel.setMessageHandler(new BasicMessageChannel.MessageHandler<Object>() ');
indent.scoped('{', '});', () {
@ -92,6 +94,10 @@ void _writeHostApi(Indent indent, Api api) {
});
});
});
indent.scoped(null, '}', () {
indent.writeln('channel.setMessageHandler(null);');
});
});
}
});
});

View File

@ -1,5 +1,5 @@
name: pigeon
version: 0.1.0-experimental.10
version: 0.1.0-experimental.11
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

@ -69,6 +69,7 @@ void main() {
final String code = sink.toString();
expect(code, contains('public interface Api'));
expect(code, matches('Output.*doSomething.*Input'));
expect(code, contains('channel.setMessageHandler(null)'));
});
test('all the simple datatypes header', () {