[NativeAOT] Forward JCW Java annotations - #12549
Merged
simonrozsival merged 8 commits intoAug 29, 2026
Merged
Conversation
Restore annotation metadata forwarding in the trimmable JCW pipeline for types, methods, constructors, and exported fields. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f220fb47-4647-44f6-9b3f-47f17a46c846
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f220fb47-4647-44f6-9b3f-47f17a46c846
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f220fb47-4647-44f6-9b3f-47f17a46c846
Contributor
There was a problem hiding this comment.
Pull request overview
This PR restores/extends forwarding of Java annotations from managed custom attributes into generated Java Callable Wrappers (JCWs) for the trimmable NativeAOT pipeline, including support for cross-assembly attribute definitions and additional member kinds.
Changes:
- Add
JavaAnnotationParserand plumb parsed annotations through the scanner model (JavaPeerInfo,MarshalMethodInfo, etc.). - Emit parsed annotations in the JCW Java source generator for types, constructors, methods, and exported fields.
- Add new fixture assemblies + regression tests covering cross-assembly annotation attributes (e.g.,
Android.Webkit.JavascriptInterfaceAttribute) and member scenarios (property override getter, constructor, export field).
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/TestFixtures/TestTypes.cs | Adds new managed fixture types/members exercising annotation forwarding scenarios (including JavascriptInterface). |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/TestFixtures/TestFixtures.csproj | References the new attribute-fixture project so fixture compilation can use cross-assembly attribute types. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/TestFixtures/StubAttributes.cs | Removes local stub attribute definitions now provided by the new shared attribute-fixture assembly. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/TestAttributeFixtures/TestAttributeFixtures.csproj | New project producing a dedicated assembly containing annotation/attribute type definitions for cross-assembly testing. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/TestAttributeFixtures/Attributes.cs | Defines AnnotationAttribute, RegisterAttribute, JavascriptInterfaceAttribute, and a custom annotation attribute with properties. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests.csproj | Ensures the new fixture assembly is built and copied beside the test output for scanner input. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/JcwJavaSourceGeneratorTests.cs | Adds assertions that generated Java includes expected forwarded annotations across multiple member kinds. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/FixtureTestBase.cs | Updates fixture scanning to include both fixture assemblies as scanner inputs. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/JavaPeerScanner.cs | Integrates annotation parsing into scan results for types, methods/ctors, property overrides, and export fields. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/JavaPeerInfo.cs | Extends scan model with JavaAnnotationInfo and annotation collections for relevant entities. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/JavaAnnotationParser.cs | New parser that detects annotation-decorated attributes and extracts Java annotation names + property assignments. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/AssemblyIndex.cs | Extends export metadata with IsField to support correct annotation routing for export fields. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/JcwJavaSourceGenerator.cs | Emits forwarded annotations into generated .java source for types/members/fields. |
Use Java string escapes and invariant numeric formatting when forwarding annotation properties. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f220fb47-4647-44f6-9b3f-47f17a46c846
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f220fb47-4647-44f6-9b3f-47f17a46c846
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f220fb47-4647-44f6-9b3f-47f17a46c846
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f220fb47-4647-44f6-9b3f-47f17a46c846
This was referenced Aug 28, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f220fb47-4647-44f6-9b3f-47f17a46c846
simonrozsival
approved these changes
Aug 29, 2026
simonrozsival
deleted the
jonathanpeppers-fix-nativeaot-jcw-annotations
branch
August 29, 2026 10:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #12542
Summary
Android.Webkit.JavascriptInterfaceAttributeMono.Androidassembly boundaryTesting
dotnet test tests\Microsoft.Android.Sdk.TrimmableTypeMap.Tests\Microsoft.Android.Sdk.TrimmableTypeMap.Tests.csproj -v minimal(773 passed)