Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pigeon] java non null void #5786

Merged
merged 11 commits into from
Jan 5, 2024
4 changes: 4 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 15.0.3
tarrinneal marked this conversation as resolved.
Show resolved Hide resolved

* [java] Fixes `Void` result type bug.

## 15.0.2

* Prevents optional and non-positional parameters in Flutter APIs.
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 = '15.0.2';
const String pigeonVersion = '15.0.3';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down
12 changes: 9 additions & 3 deletions packages/pigeon/lib/java_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,9 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {

for (final Method func in api.methods) {
final String resultType =
func.returnType.isNullable ? 'NullableResult' : 'Result';
func.returnType.isNullable || func.returnType.isVoid
? 'NullableResult'
: 'Result';
tarrinneal marked this conversation as resolved.
Show resolved Hide resolved
final String returnType = func.returnType.isVoid
? 'Void'
: _javaTypeForDartType(func.returnType);
Expand Down Expand Up @@ -634,7 +636,9 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
void _writeInterfaceMethod(JavaOptions generatorOptions, Root root,
Indent indent, Api api, final Method method) {
final String resultType =
method.returnType.isNullable ? 'NullableResult' : 'Result';
method.returnType.isNullable || method.returnType.isVoid
? 'NullableResult'
: 'Result';
final String nullableType = method.isAsynchronous
? ''
: _nullabilityAnnotationFromType(method.returnType);
Expand Down Expand Up @@ -749,7 +753,9 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
: '.index';
}
final String resultType =
method.returnType.isNullable ? 'NullableResult' : 'Result';
method.returnType.isNullable || method.returnType.isVoid
? 'NullableResult'
: 'Result';
const String resultName = 'resultCallback';
indent.format('''
$resultType<$returnType> $resultName =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public void throwErrorFromVoid() {
}

@Override
public void noopAsync(@NonNull Result<Void> result) {
public void noopAsync(@NonNull NullableResult<Void> result) {
result.success(null);
}

Expand All @@ -218,7 +218,7 @@ public void throwAsyncError(@NonNull NullableResult<Object> result) {
}

@Override
public void throwAsyncErrorFromVoid(@NonNull Result<Void> result) {
public void throwAsyncErrorFromVoid(@NonNull NullableResult<Void> result) {
result.error(new RuntimeException("An error"));
}

Expand Down Expand Up @@ -338,7 +338,7 @@ public void echoAsyncNullableEnum(
}

@Override
public void callFlutterNoop(@NonNull Result<Void> result) {
public void callFlutterNoop(@NonNull NullableResult<Void> result) {
flutterApi.noop(result);
}

Expand All @@ -348,7 +348,7 @@ public void callFlutterThrowError(@NonNull NullableResult<Object> result) {
}

@Override
public void callFlutterThrowErrorFromVoid(@NonNull Result<Void> result) {
public void callFlutterThrowErrorFromVoid(@NonNull NullableResult<Void> result) {
flutterApi.throwErrorFromVoid(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ AllNullableTypes sendMultipleNullableTypes(
* A no-op function taking no arguments and returning no value, to sanity test basic
* asynchronous calling.
*/
void noopAsync(@NonNull Result<Void> result);
void noopAsync(@NonNull NullableResult<Void> result);
/** Returns passed in int asynchronously. */
void echoAsyncInt(@NonNull Long anInt, @NonNull Result<Long> result);
/** Returns passed in double asynchronously. */
Expand All @@ -1162,7 +1162,7 @@ void echoAsyncMap(
/** Responds with an error from an async function returning a value. */
void throwAsyncError(@NonNull NullableResult<Object> result);
/** Responds with an error from an async void function. */
void throwAsyncErrorFromVoid(@NonNull Result<Void> result);
void throwAsyncErrorFromVoid(@NonNull NullableResult<Void> result);
/** Responds with a Flutter error from an async function returning a value. */
void throwAsyncFlutterError(@NonNull NullableResult<Object> result);
/** Returns the passed object, to test async serialization and deserialization. */
Expand Down Expand Up @@ -1192,11 +1192,11 @@ void echoAsyncNullableMap(
/** Returns the passed enum, to test asynchronous serialization and deserialization. */
void echoAsyncNullableEnum(@Nullable AnEnum anEnum, @NonNull NullableResult<AnEnum> result);

void callFlutterNoop(@NonNull Result<Void> result);
void callFlutterNoop(@NonNull NullableResult<Void> result);

void callFlutterThrowError(@NonNull NullableResult<Object> result);

void callFlutterThrowErrorFromVoid(@NonNull Result<Void> result);
void callFlutterThrowErrorFromVoid(@NonNull NullableResult<Void> result);

void callFlutterEchoAllTypes(@NonNull AllTypes everything, @NonNull Result<AllTypes> result);

Expand Down Expand Up @@ -2097,8 +2097,8 @@ static void setUp(
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
Result<Void> resultCallback =
new Result<Void>() {
NullableResult<Void> resultCallback =
new NullableResult<Void>() {
public void success(Void result) {
wrapped.add(0, null);
reply.reply(wrapped);
Expand Down Expand Up @@ -2434,8 +2434,8 @@ public void error(Throwable error) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
Result<Void> resultCallback =
new Result<Void>() {
NullableResult<Void> resultCallback =
new NullableResult<Void>() {
public void success(Void result) {
wrapped.add(0, null);
reply.reply(wrapped);
Expand Down Expand Up @@ -2834,8 +2834,8 @@ public void error(Throwable error) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
Result<Void> resultCallback =
new Result<Void>() {
NullableResult<Void> resultCallback =
new NullableResult<Void>() {
public void success(Void result) {
wrapped.add(0, null);
reply.reply(wrapped);
Expand Down Expand Up @@ -2892,8 +2892,8 @@ public void error(Throwable error) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
Result<Void> resultCallback =
new Result<Void>() {
NullableResult<Void> resultCallback =
new NullableResult<Void>() {
public void success(Void result) {
wrapped.add(0, null);
reply.reply(wrapped);
Expand Down Expand Up @@ -3574,7 +3574,7 @@ public FlutterIntegrationCoreApi(@NonNull BinaryMessenger argBinaryMessenger) {
/**
* A no-op function taking no arguments and returning no value, to sanity test basic calling.
*/
public void noop(@NonNull Result<Void> result) {
public void noop(@NonNull NullableResult<Void> result) {
final String channelName =
"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noop";
BasicMessageChannel<Object> channel =
Expand Down Expand Up @@ -3626,7 +3626,7 @@ public void throwError(@NonNull NullableResult<Object> result) {
});
}
/** Responds with an error from an async void function. */
public void throwErrorFromVoid(@NonNull Result<Void> result) {
public void throwErrorFromVoid(@NonNull NullableResult<Void> result) {
final String channelName =
"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwErrorFromVoid";
BasicMessageChannel<Object> channel =
Expand Down Expand Up @@ -4251,7 +4251,7 @@ public void echoNullableEnum(
* A no-op function taking no arguments and returning no value, to sanity test basic
* asynchronous calling.
*/
public void noopAsync(@NonNull Result<Void> result) {
public void noopAsync(@NonNull NullableResult<Void> result) {
final String channelName =
"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noopAsync";
BasicMessageChannel<Object> channel =
Expand Down Expand Up @@ -4358,7 +4358,7 @@ public interface HostSmallApi {

void echo(@NonNull String aString, @NonNull Result<String> result);

void voidVoid(@NonNull Result<Void> result);
void voidVoid(@NonNull NullableResult<Void> result);

/** The codec used by HostSmallApi. */
static @NonNull MessageCodec<Object> getCodec() {
Expand Down Expand Up @@ -4407,8 +4407,8 @@ public void error(Throwable error) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
Result<Void> resultCallback =
new Result<Void>() {
NullableResult<Void> resultCallback =
new NullableResult<Void>() {
public void success(Void result) {
wrapped.add(0, null);
reply.reply(wrapped);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void echo(@NonNull String value, Result<String> result) {
}

@Override
public void voidVoid(Result<Void> result) {
public void voidVoid(NullableResult<Void> result) {
result.success(null);
}
}
Expand All @@ -36,7 +36,7 @@ public void echo(@NonNull String value, Result<String> result) {
}

@Override
public void voidVoid(Result<Void> result) {
public void voidVoid(NullableResult<Void> result) {
result.error(new Exception("error"));
}
}
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: 15.0.2 # This must match the version in lib/generator_tools.dart
version: 15.0.3 # This must match the version in lib/generator_tools.dart

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/pigeon/test/java_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ void main() {
expect(
code,
contains(
'public void doSomething(@NonNull Input arg0Arg, @NonNull Result<Void> result)'));
'public void doSomething(@NonNull Input arg0Arg, @NonNull NullableResult<Void> result)'));
expect(code, contains('result.success(null);'));
});

Expand Down Expand Up @@ -1307,7 +1307,7 @@ void main() {
expect(
code,
contains(
'public void doit(@Nullable Long fooArg, @NonNull Result<Void> result) {'));
'public void doit(@Nullable Long fooArg, @NonNull NullableResult<Void> result) {'));
});

test('background platform channel', () {
Expand Down