Skip to content

Commit

Permalink
Make generated Java enum fields final (#2899)
Browse files Browse the repository at this point in the history
* Make generated Java enum fields final

The enum should be immutable, so the fields should be final.

* Fix tests

* Update CHANGELOG.md

* Update generator_tools.dart

* Update pubspec.yaml
  • Loading branch information
ChristianEdwardPadilla committed Dec 7, 2022
1 parent 3a0cbad commit 02de151
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/pigeon/CHANGELOG.md
@@ -1,3 +1,7 @@
## 4.2.10

* Changes generated Java enum field to be final.

## 4.2.9

* [kotlin] Fixes a bug with some methods that return `void`.
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/lib/generator_tools.dart
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 = '4.2.9';
const String pigeonVersion = '4.2.10';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/lib/java_generator.dart
Expand Up @@ -578,7 +578,7 @@ void generateJava(JavaOptions options, Root root, StringSink sink) {
// discouraged. The toMap and fromMap API matches class API to allow
// the same code to work with enums and classes, but this
// can also be done directly in the host and flutter APIs.
indent.writeln('private int index;');
indent.writeln('private final int index;');
indent.write('private ${anEnum.name}(final int index) ');
indent.scoped('{', '}', () {
indent.writeln('this.index = index;');
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/pubspec.yaml
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%3Apigeon
version: 4.2.9 # This must match the version in lib/generator_tools.dart
version: 4.2.10 # This must match the version in lib/generator_tools.dart

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/pigeon/test/java_generator_test.dart
Expand Up @@ -61,7 +61,7 @@ void main() {
expect(code, contains(' ONE(0),'));
expect(code, contains(' TWO_THREE_FOUR(1),'));
expect(code, contains(' REMOTE_DB(2);'));
expect(code, contains('private int index;'));
expect(code, contains('private final int index;'));
expect(code, contains('private Foobar(final int index) {'));
expect(code, contains(' this.index = index;'));
});
Expand Down Expand Up @@ -587,7 +587,7 @@ void main() {
expect(code, contains(' ONE(0),'));
expect(code, contains(' TWO_THREE_FOUR(1),'));
expect(code, contains(' REMOTE_DB(2);'));
expect(code, contains('private int index;'));
expect(code, contains('private final int index;'));
expect(code, contains('private Enum1(final int index) {'));
expect(code, contains(' this.index = index;'));

Expand Down

0 comments on commit 02de151

Please sign in to comment.