Skip to content

[NativeAOT] Forward JCW Java annotations - #12549

Merged
simonrozsival merged 8 commits into
mainfrom
jonathanpeppers-fix-nativeaot-jcw-annotations
Aug 29, 2026
Merged

[NativeAOT] Forward JCW Java annotations#12549
simonrozsival merged 8 commits into
mainfrom
jonathanpeppers-fix-nativeaot-jcw-annotations

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Fixes #12542

Summary

  • forward Java annotations from managed custom attributes through the trimmable NativeAOT JCW pipeline
  • preserve annotations on types, methods, registered constructors, property overrides, and exported fields
  • cache annotation metadata and support cross-assembly attribute definitions such as Android.Webkit.JavascriptInterfaceAttribute
  • add regression coverage matching the app-to-Mono.Android assembly boundary

Testing

  • dotnet test tests\Microsoft.Android.Sdk.TrimmableTypeMap.Tests\Microsoft.Android.Sdk.TrimmableTypeMap.Tests.csproj -v minimal (773 passed)

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
Copilot AI lite review requested due to automatic review settings August 27, 2026 20:49
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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 JavaAnnotationParser and 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
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: f220fb47-4647-44f6-9b3f-47f17a46c846
@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Aug 28, 2026
@simonrozsival
simonrozsival merged commit c88edf2 into main Aug 29, 2026
44 checks passed
@simonrozsival
simonrozsival deleted the jonathanpeppers-fix-nativeaot-jcw-annotations branch August 29, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java Callable Wrappers under Native AOT no longer forward C# attributes to Java annotations

3 participants