Skip to content

Conversation

@jeffkwoh
Copy link

@jeffkwoh jeffkwoh commented Feb 4, 2026

Adds supports for a flag to add a javax.annotation.Generated annotation in the Kotlin generated code

Fixes flutter/flutter#181234

@jeffkwoh jeffkwoh changed the title [Do not review] Testing to see if I have permission to open pul request Support javax.annotation.Generated annotation in Kotlin generator Feb 4, 2026
@jeffkwoh jeffkwoh marked this pull request as ready for review February 4, 2026 07:53
@jeffkwoh jeffkwoh requested a review from tarrinneal as a code owner February 4, 2026 07:53
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a feature to add a javax.annotation.Generated annotation to the generated Kotlin code, controlled by a new useGeneratedAnnotation flag. The implementation correctly adds the flag to the options, parses it from command-line arguments, and conditionally adds the annotation in the Kotlin generator. The changes are accompanied by corresponding tests. My review includes suggestions to improve code maintainability by refactoring a magic string into a constant and reducing code duplication in the newly added tests.

@jeffkwoh
Copy link
Author

jeffkwoh commented Feb 4, 2026

Having difficulties executing

patch -p1 <<DONE
diff --git a/packages/pigeon/lib/src/pigeon_lib.dart b/packages/pigeon/lib/src/pigeon_lib.dart
index 7495903b9..e638629f3 100644
--- a/packages/pigeon/lib/src/pigeon_lib.dart
+++ b/packages/pigeon/lib/src/pigeon_lib.dart
@@ -547,8 +547,10 @@ ${_argParser.usage}''';
       help: 'The package that generated Kotlin code will be in.',
       aliases: const <String>['experimental_kotlin_package'],
     )
-    ..addFlag('kotlin_use_generated_annotation',
-        help: 'Adds javax.annotation.Generated annotation to the output.')
+    ..addFlag(
+      'kotlin_use_generated_annotation',
+      help: 'Adds javax.annotation.Generated annotation to the output.',
+    )
     ..addOption(
       'cpp_header_out',
       help: 'Path to generated C++ header file (.h).',
@@ -640,7 +642,8 @@ ${_argParser.usage}''';
       kotlinOut: results['kotlin_out'] as String?,
       kotlinOptions: KotlinOptions(
         package: results['kotlin_package'] as String?,
-        useGeneratedAnnotation: results['kotlin_use_generated_annotation'] as bool? ?? false,
+        useGeneratedAnnotation:
+            results['kotlin_use_generated_annotation'] as bool? ?? false,
       ),
       cppHeaderOut: results['cpp_header_out'] as String?,
       cppSourceOut: results['cpp_source_out'] as String?,
diff --git a/packages/pigeon/test/pigeon_lib_test.dart b/packages/pigeon/test/pigeon_lib_test.dart
index 4748c9caf..86b049855 100644
--- a/packages/pigeon/test/pigeon_lib_test.dart
+++ b/packages/pigeon/test/pigeon_lib_test.dart
@@ -136,7 +136,7 @@ void main() {
     ]);
     expect(opts.kotlinOptions?.package, equals('com.google.foo'));
   });
-  
+
   test('parse args - kotlin_use_generated_annotation', () {
     final PigeonOptions opts = Pigeon.parseArgs(<String>[
       '--kotlin_use_generated_annotation',
@@ -144,7 +144,6 @@ void main() {
     expect(opts.kotlinOptions!.useGeneratedAnnotation, isTrue);
   });
 
-
   test('parse args - cpp_header_out', () {
     final PigeonOptions opts = Pigeon.parseArgs(<String>[
       '--cpp_header_out',

DONE

will set up dart env locally and reformat or manually make changes

@tarrinneal
Copy link
Contributor

will set up dart env locally and reformat or manually make changes

There will be hundreds of changes if you can't run the formatter. I would highly recommend not doing it manually.

Or I can format your code and push it up. If that's easier for you.

@jeffkwoh
Copy link
Author

jeffkwoh commented Feb 6, 2026

Managed to install dart! PTAL! (I don't know how to trigger AI review again)

… setup

- Extract @javax.annotation.Generated("dev.flutter.pigeon") to shared constant in generator_tools.dart
- Update kotlin_generator.dart and java_generator.dart to use shared constant
- Refactor kotlin_generator_test.dart and java_generator_test.dart to use group() with setUp() pattern
- Eliminates code duplication in test initialization across generator tests
Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks good. The "magic strings" comment from the ai is pretty funny when you look at the rest of the generator files, but there will be some upcoming changes in that regard soon anyway, so might as well start here :)

I do think it would be a good idea to add the annotations to at least one of the generated test files, should be as simple as adding a parameter to the 'runPigeon' method in the 'generation.dart' file in the tool/shared directory. Then adding an argument to the call to that method in generateTestPigeons in the same file for one file.

jeffkwoh and others added 5 commits February 9, 2026 13:55
- Add kotlinUseGeneratedAnnotation parameter to runPigeon method
- Pass useGeneratedAnnotation to KotlinOptions
- Enable annotation for core_tests in generated test files
- Add javaUseGeneratedAnnotation parameter to runPigeon method
- Pass useGeneratedAnnotation to JavaOptions in PigeonOptions
- Update test case to enable annotation for both Kotlin and Java
- Generates CoreTestsWithAnnotation files for both languages
- Add type annotation for corePascalCaseName (String)
- Make generateCodeWithAnnotation variable final
- Remove redundant kotlinIncludeErrorClass: true (matches default)
@jeffkwoh jeffkwoh requested a review from tarrinneal February 9, 2026 06:29
@jeffkwoh jeffkwoh marked this pull request as draft February 9, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[pigeon] [Google3 Bug]: Support javax.annotation.Generated annotation in Kotlin generator

2 participants