Skip to content

Commit

Permalink
[pigeon] Fixes some Java lint issues (flutter#3060)
Browse files Browse the repository at this point in the history
* sets classes to final, and other lint issues

* breaking change
  • Loading branch information
tarrinneal authored Jan 19, 2023
1 parent 88859a8 commit 69954f2
Show file tree
Hide file tree
Showing 23 changed files with 439 additions and 50 deletions.
5 changes: 5 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 7.0.0

* [java] **BREAKING CHANGE**: Makes data classes final.
Updates generators for 1p linters.

## 6.0.3

* [docs] Updates README.md.
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 @@ -9,7 +9,7 @@ import 'dart:mirrors';
import 'ast.dart';

/// The current version of pigeon. This must match the version in pubspec.yaml.
const String pigeonVersion = '6.0.3';
const String pigeonVersion = '7.0.0';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down
19 changes: 10 additions & 9 deletions packages/pigeon/lib/java_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
indent, klass.documentationComments, _docCommentSpec,
generatorComments: generatedMessages);

indent.write('public static class ${klass.name} ');
indent.write('public static final class ${klass.name} ');
indent.scoped('{', '}', () {
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
_writeClassField(generatorOptions, root, indent, field);
Expand Down Expand Up @@ -340,7 +340,7 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {

/// Writes the code for a flutter [Api], [api].
/// Example:
/// public static class Foo {
/// public static final class Foo {
/// public Foo(BinaryMessenger argBinaryMessenger) {...}
/// public interface Reply<T> {
/// void reply(T reply);
Expand All @@ -364,13 +364,14 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
addDocumentationComments(indent, api.documentationComments, _docCommentSpec,
generatorComments: generatedMessages);

indent.write('public static class ${api.name} ');
indent.write('public static final class ${api.name} ');
indent.scoped('{', '}', () {
indent.writeln('private final BinaryMessenger binaryMessenger;');
indent.write('public ${api.name}(BinaryMessenger argBinaryMessenger)');
indent.scoped('{', '}', () {
indent.writeln('this.binaryMessenger = argBinaryMessenger;');
});
indent.write('/** Public interface for sending reply. */ ');
indent.write('public interface Reply<T> ');
indent.scoped('{', '}', () {
indent.writeln('void reply(T reply);');
Expand Down Expand Up @@ -427,10 +428,10 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
indent.dec();
indent.dec();
indent.write('$channel.send($sendArgument, channelReply -> ');
indent.scoped('{', '});', () {
if (func.returnType.isVoid) {
indent.writeln('callback.reply(null);');
} else {
if (func.returnType.isVoid) {
indent.addln('callback.reply(null));');
} else {
indent.scoped('{', '});', () {
const String output = 'output';
indent.writeln('@SuppressWarnings("ConstantConditions")');
if (func.returnType.baseName == 'int') {
Expand All @@ -441,8 +442,8 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
'$returnType $output = ($returnType)channelReply;');
}
indent.writeln('callback.reply($output);');
}
});
});
}
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/mock_handler_tester/test/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v6.0.3), do not edit directly.
// Autogenerated from Pigeon (v7.0.0), 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, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import

Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/mock_handler_tester/test/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v6.0.3), do not edit directly.
// Autogenerated from Pigeon (v7.0.0), 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, unnecessary_parenthesis, unnecessary_import
// ignore_for_file: avoid_relative_lib_imports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v6.0.3), do not edit directly.
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package com.example.alternate_language_test_plugin;
Expand Down Expand Up @@ -48,7 +48,7 @@ private AnEnum(final int index) {
}

/** Generated class from Pigeon that represents data sent in messages. */
public static class AllTypes {
public static final class AllTypes {
private @NonNull Boolean aBool;

public @NonNull Boolean getABool() {
Expand Down Expand Up @@ -337,7 +337,7 @@ ArrayList<Object> toList() {
}

/** Generated class from Pigeon that represents data sent in messages. */
public static class AllNullableTypes {
public static final class AllNullableTypes {
private @Nullable Boolean aNullableBool;

public @Nullable Boolean getANullableBool() {
Expand Down Expand Up @@ -657,7 +657,7 @@ ArrayList<Object> toList() {
}

/** Generated class from Pigeon that represents data sent in messages. */
public static class AllNullableTypesWrapper {
public static final class AllNullableTypesWrapper {
private @NonNull AllNullableTypes values;

public @NonNull AllNullableTypes getValues() {
Expand Down Expand Up @@ -2171,13 +2171,13 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) {
*
* <p>Generated class from Pigeon that represents Flutter messages that can be called from Java.
*/
public static class FlutterIntegrationCoreApi {
public static final class FlutterIntegrationCoreApi {
private final BinaryMessenger binaryMessenger;

public FlutterIntegrationCoreApi(BinaryMessenger argBinaryMessenger) {
this.binaryMessenger = argBinaryMessenger;
}

/** Public interface for sending reply. */
public interface Reply<T> {
void reply(T reply);
}
Expand All @@ -2192,11 +2192,7 @@ public void noop(Reply<Void> callback) {
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.noop", getCodec());
channel.send(
null,
channelReply -> {
callback.reply(null);
});
channel.send(null, channelReply -> callback.reply(null));
}
/** Returns the passed object, to test serialization and deserialization. */
public void echoAllTypes(@NonNull AllTypes everythingArg, Reply<AllTypes> callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v6.0.3), do not edit directly.
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import <Foundation/Foundation.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v6.0.3), do not edit directly.
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import "CoreTests.gen.h"
Expand Down
Loading

0 comments on commit 69954f2

Please sign in to comment.