Skip to content

Commit 428ba3e

Browse files
[pigeon] Remove semicolons from Kotlin generation (flutter#5375)
Callback calls were generating unnecessary semicolons at the end of the line, which was inconsistent with the rest of the file and with Kotlin style in general (as highlighted by experiments with `ktfmt`).
1 parent 72de224 commit 428ba3e

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

packages/pigeon/CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
## 13.1.1
2+
3+
* [kotlin] Removes unnecessary `;`s in generated code.
4+
15
## 13.1.0
26

37
* [swift] Fixes Flutter Api void return error handling.
4-
* This shouldn't be breaking for anyone, but if you were incorrectly getting
8+
* This shouldn't be breaking for anyone, but if you were incorrectly getting
59
success responses, you may now be failing (correctly).
610
* Adds method channel name to error response when channel fails to connect.
711
* Reduces code generation duplication.

packages/pigeon/lib/generator_tools.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'ast.dart';
1313
/// The current version of pigeon.
1414
///
1515
/// This must match the version in pubspec.yaml.
16-
const String pigeonVersion = '13.1.0';
16+
const String pigeonVersion = '13.1.1';
1717

1818
/// Read all the content from [stdin] to a String.
1919
String readStdin() {

packages/pigeon/lib/kotlin_generator.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -412,17 +412,17 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
412412
indent.writeScoped('if (it is List<*>) {', '} ', () {
413413
indent.writeScoped('if (it.size > 1) {', '} ', () {
414414
indent.writeln(
415-
'callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?)));');
415+
'callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?)))');
416416
}, addTrailingNewline: false);
417417
if (!func.returnType.isNullable && !func.returnType.isVoid) {
418418
indent.addScoped('else if (it[0] == null) {', '} ', () {
419419
indent.writeln(
420-
'callback(Result.failure(FlutterError("null-error", "Flutter api returned null value for non-null return value.", "")));');
420+
'callback(Result.failure(FlutterError("null-error", "Flutter api returned null value for non-null return value.", "")))');
421421
}, addTrailingNewline: false);
422422
}
423423
indent.addScoped('else {', '}', () {
424424
if (func.returnType.isVoid) {
425-
indent.writeln('callback(Result.success(Unit));');
425+
indent.writeln('callback(Result.success(Unit))');
426426
} else {
427427
const String output = 'output';
428428
// Nullable enums require special handling.
@@ -436,13 +436,13 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
436436
indent.writeln(
437437
'val $output = ${_cast(root, indent, 'it[0]', type: func.returnType)}');
438438
}
439-
indent.writeln('callback(Result.success($output));');
439+
indent.writeln('callback(Result.success($output))');
440440
}
441441
});
442442
}, addTrailingNewline: false);
443443
indent.addScoped('else {', '} ', () {
444444
indent.writeln(
445-
'callback(Result.failure(createConnectionError(channelName)));');
445+
'callback(Result.failure(createConnectionError(channelName)))');
446446
});
447447
});
448448
});

packages/pigeon/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: pigeon
22
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
33
repository: https://github.com/flutter/packages/tree/main/packages/pigeon
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon
5-
version: 13.1.0 # This must match the version in lib/generator_tools.dart
5+
version: 13.1.1 # This must match the version in lib/generator_tools.dart
66

77
environment:
88
sdk: ">=2.19.0 <4.0.0"

packages/pigeon/test/kotlin_generator_test.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ void main() {
518518
final String code = sink.toString();
519519
expect(code, contains('callback: (Result<Unit>) -> Unit'));
520520
expect(code, contains('callback(Result.success(Unit))'));
521+
// Lines should not end in semicolons.
522+
expect(code, isNot(contains(RegExp(r';\n'))));
521523
});
522524

523525
test('gen host void argument api', () {
@@ -1584,6 +1586,6 @@ void main() {
15841586
expect(
15851587
code,
15861588
contains(
1587-
'callback(Result.failure(createConnectionError(channelName)));'));
1589+
'callback(Result.failure(createConnectionError(channelName)))'));
15881590
});
15891591
}

0 commit comments

Comments
 (0)