Skip to content

[pigeon] Support javax.annotation.Generated annotation in Kotlin generator#10961

Merged
auto-submit[bot] merged 33 commits intoflutter:mainfrom
jeffkwoh:pigeon-gen
Mar 9, 2026
Merged

[pigeon] Support javax.annotation.Generated annotation in Kotlin generator#10961
auto-submit[bot] merged 33 commits intoflutter:mainfrom
jeffkwoh:pigeon-gen

Conversation

@jeffkwoh
Copy link
Copy Markdown
Contributor

@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
Comment thread packages/pigeon/lib/src/pigeon_lib.dart Outdated
Copy link
Copy Markdown

@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.

Comment thread packages/pigeon/lib/src/kotlin/kotlin_generator.dart Outdated
Comment thread packages/pigeon/test/kotlin_generator_test.dart Outdated
@jeffkwoh
Copy link
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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
Comment thread packages/pigeon/tool/shared/generation.dart Outdated
Comment thread packages/pigeon/lib/src/generator_tools.dart Outdated
Comment thread packages/pigeon/tool/shared/generation.dart
@jeffkwoh jeffkwoh requested a review from tarrinneal March 3, 2026 04:42
@stuartmorgan-g stuartmorgan-g changed the title Support javax.annotation.Generated annotation in Kotlin generator [pigeon] Support javax.annotation.Generated annotation in Kotlin generator Mar 4, 2026
Copy link
Copy Markdown
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.

Sorry I forgot to approve last time

@tarrinneal tarrinneal added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 6, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 6, 2026
@auto-submit
Copy link
Copy Markdown
Contributor

auto-submit Bot commented Mar 6, 2026

autosubmit label was removed for flutter/packages/10961, because This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 1 more review(s) in order to merge this PR.

  • Merge guidelines: A PR needs at least one approved review if the author is already part of flutter-hackers or two member reviews if the author is not a flutter-hacker before re-applying the autosubmit label. Reviewers: If you left a comment approving, please use the "approve" review action instead.

Copy link
Copy Markdown
Collaborator

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

The code looks good, but since this is new API it needs to be a minor version bump since we use semver.

@jeffkwoh jeffkwoh requested a review from stuartmorgan-g March 9, 2026 03:51
Copy link
Copy Markdown
Collaborator

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 9, 2026
@auto-submit auto-submit Bot merged commit c717018 into flutter:main Mar 9, 2026
80 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 9, 2026
github-merge-queue Bot pushed a commit to flutter/flutter that referenced this pull request Mar 9, 2026
flutter/packages@fe3de64...c717018

2026-03-09 23180853+jeffkwoh@users.noreply.github.com [pigeon] Support
javax.annotation.Generated annotation in Kotlin generator
(flutter/packages#10961)
2026-03-09 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump gradle-wrapper from 8.13 to 9.4.0 in
/packages/path_provider/path_provider/example/android/app
(flutter/packages#11206)
2026-03-09 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump com.android.tools.build:gradle from 8.9.1 to 9.1.0 in
/packages/shared_preferences/shared_preferences_android/example/android/app
(flutter/packages#11208)
2026-03-09 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump gradle-wrapper from 8.13 to 9.4.0 in
/packages/path_provider/path_provider_android/example/android/app
(flutter/packages#11207)
2026-03-06 stuartmorgan@google.com [various] Plugin Gradle pre-Kotlin
standardization (flutter/packages#11173)
2026-03-06 jessiewong401@gmail.com Updated AGP and KGP to align with
flutter/flutter templates (flutter/packages#10423)
2026-03-06 engine-flutter-autoroll@skia.org Roll Flutter from
d3dd774 to d182143 (33 revisions) (flutter/packages#11191)
2026-03-06 20989940+aednlaxer@users.noreply.github.com
[google_maps_flutter] Add Advanced Markers support
(flutter/packages#7882)
2026-03-06 47250617+linchen00@users.noreply.github.com
[in_app_purchase]Fixes StoreKit 2 purchase flow to send
cancelled/pending/unverified results to purchaseStream.
(flutter/packages#10736)
2026-03-06 theandroidseb@gmail.com [flutter_svg] Update README with an
example to scale images (flutter/packages#10547)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
xxxOVALxxx pushed a commit to xxxOVALxxx/flutter that referenced this pull request Mar 10, 2026
…er#183396)

flutter/packages@fe3de64...c717018

2026-03-09 23180853+jeffkwoh@users.noreply.github.com [pigeon] Support
javax.annotation.Generated annotation in Kotlin generator
(flutter/packages#10961)
2026-03-09 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump gradle-wrapper from 8.13 to 9.4.0 in
/packages/path_provider/path_provider/example/android/app
(flutter/packages#11206)
2026-03-09 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump com.android.tools.build:gradle from 8.9.1 to 9.1.0 in
/packages/shared_preferences/shared_preferences_android/example/android/app
(flutter/packages#11208)
2026-03-09 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump gradle-wrapper from 8.13 to 9.4.0 in
/packages/path_provider/path_provider_android/example/android/app
(flutter/packages#11207)
2026-03-06 stuartmorgan@google.com [various] Plugin Gradle pre-Kotlin
standardization (flutter/packages#11173)
2026-03-06 jessiewong401@gmail.com Updated AGP and KGP to align with
flutter/flutter templates (flutter/packages#10423)
2026-03-06 engine-flutter-autoroll@skia.org Roll Flutter from
d3dd774 to d182143 (33 revisions) (flutter/packages#11191)
2026-03-06 20989940+aednlaxer@users.noreply.github.com
[google_maps_flutter] Add Advanced Markers support
(flutter/packages#7882)
2026-03-06 47250617+linchen00@users.noreply.github.com
[in_app_purchase]Fixes StoreKit 2 purchase flow to send
cancelled/pending/unverified results to purchaseStream.
(flutter/packages#10736)
2026-03-06 theandroidseb@gmail.com [flutter_svg] Update README with an
example to scale images (flutter/packages#10547)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
okorohelijah pushed a commit to okorohelijah/packages that referenced this pull request Mar 26, 2026
…rator (flutter#10961)

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

Fixes flutter/flutter#181234
mboetger pushed a commit to mboetger/flutter that referenced this pull request Mar 26, 2026
…er#183396)

flutter/packages@fe3de64...c717018

2026-03-09 23180853+jeffkwoh@users.noreply.github.com [pigeon] Support
javax.annotation.Generated annotation in Kotlin generator
(flutter/packages#10961)
2026-03-09 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump gradle-wrapper from 8.13 to 9.4.0 in
/packages/path_provider/path_provider/example/android/app
(flutter/packages#11206)
2026-03-09 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump com.android.tools.build:gradle from 8.9.1 to 9.1.0 in
/packages/shared_preferences/shared_preferences_android/example/android/app
(flutter/packages#11208)
2026-03-09 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump gradle-wrapper from 8.13 to 9.4.0 in
/packages/path_provider/path_provider_android/example/android/app
(flutter/packages#11207)
2026-03-06 stuartmorgan@google.com [various] Plugin Gradle pre-Kotlin
standardization (flutter/packages#11173)
2026-03-06 jessiewong401@gmail.com Updated AGP and KGP to align with
flutter/flutter templates (flutter/packages#10423)
2026-03-06 engine-flutter-autoroll@skia.org Roll Flutter from
d3dd774 to d182143 (33 revisions) (flutter/packages#11191)
2026-03-06 20989940+aednlaxer@users.noreply.github.com
[google_maps_flutter] Add Advanced Markers support
(flutter/packages#7882)
2026-03-06 47250617+linchen00@users.noreply.github.com
[in_app_purchase]Fixes StoreKit 2 purchase flow to send
cancelled/pending/unverified results to purchaseStream.
(flutter/packages#10736)
2026-03-06 theandroidseb@gmail.com [flutter_svg] Update README with an
example to scale images (flutter/packages#10547)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
ahmedsameha1 pushed a commit to ahmedsameha1/flutter that referenced this pull request Apr 14, 2026
…er#183396)

flutter/packages@fe3de64...c717018

2026-03-09 23180853+jeffkwoh@users.noreply.github.com [pigeon] Support
javax.annotation.Generated annotation in Kotlin generator
(flutter/packages#10961)
2026-03-09 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump gradle-wrapper from 8.13 to 9.4.0 in
/packages/path_provider/path_provider/example/android/app
(flutter/packages#11206)
2026-03-09 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump com.android.tools.build:gradle from 8.9.1 to 9.1.0 in
/packages/shared_preferences/shared_preferences_android/example/android/app
(flutter/packages#11208)
2026-03-09 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump gradle-wrapper from 8.13 to 9.4.0 in
/packages/path_provider/path_provider_android/example/android/app
(flutter/packages#11207)
2026-03-06 stuartmorgan@google.com [various] Plugin Gradle pre-Kotlin
standardization (flutter/packages#11173)
2026-03-06 jessiewong401@gmail.com Updated AGP and KGP to align with
flutter/flutter templates (flutter/packages#10423)
2026-03-06 engine-flutter-autoroll@skia.org Roll Flutter from
d3dd774 to d182143 (33 revisions) (flutter/packages#11191)
2026-03-06 20989940+aednlaxer@users.noreply.github.com
[google_maps_flutter] Add Advanced Markers support
(flutter/packages#7882)
2026-03-06 47250617+linchen00@users.noreply.github.com
[in_app_purchase]Fixes StoreKit 2 purchase flow to send
cancelled/pending/unverified results to purchaseStream.
(flutter/packages#10736)
2026-03-06 theandroidseb@gmail.com [flutter_svg] Update README with an
example to scale images (flutter/packages#10547)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App p: pigeon platform-android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants