Closed Bug 1674211 Opened 4 years ago Closed 4 years ago

Improve annotation processing for enums

Categories

(GeckoView :: General, task, P1)

Unspecified
All

Tracking

(firefox84 fixed)

RESOLVED FIXED
84 Branch
Tracking Status
firefox84 --- fixed

People

(Reporter: bugzilla, Assigned: bugzilla)

Details

(Whiteboard: [geckoview:m84])

Attachments

(2 files)

Our annotation processing for enums kind of sucks.

The typical use case is that we want to generate wrappers for the values of the enum.

On the one hand, we can annotate each individual value with @WrapForJNI which is noisy and error-prone.

On the other hand, we can mark the entire enum as @WrapForJNI, which causes all stuff in the enum to get JNI wrappers, including private fields etc that we typically don't need to wrap, thus polluting the generated JNI wrapper with noise and making it harder to find the right information when inspecting the C++ header.

I'd like to modify the annotation processor to special case enums so that when we mark an entire enum as @WrapForJNI, only the enumerated values will be wrapped. Any additional fields or methods that we want to wrap may then be annotated on a case-by-case basis.

This should give us cleaner Java and cleaner C++.

Our annotation processing for enums kind of sucks.

The typical use case is that we want to generate wrappers for the values of the
enum.

On the one hand, we can annotate each individual enumerated value with
@WrapForJNI which is noisy and error-prone.

On the other hand, we can mark the entire enum as @WrapForJNI, which causes
everything in the enum to get JNI wrappers, including private members that we
typically don't care about. This pollutes the generated JNI wrappers with noise
and makes it harder for somebody inspecting the generated C++ header to find
relevant information.

This patch modifies the annotation processor so that enums are treated as a
special case: when we mark an entire enum as @WrapForJNI, only the
enumerated values will be wrapped. Any additional fields or methods that we need
to wrap may then be annotated on a case-by-case basis.

This should give us both cleaner Java and cleaner generated C++.

As a result of part 1, we need to make this change, as this method needs to
be wrapped for the benefit of native code.

Not only does this patch fix the build error, but it also acts as an examplar
for how to explicitly annotate additional members of the enum.

Depends on D95203

Pushed by aklotz@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/bd58283adf50
Part 1 - Modify the annotation processor for enums to only include enumerated values by default; r=geckoview-reviewers,agi
https://hg.mozilla.org/integration/autoland/rev/581c733d3dab
Part 2 - Explicitly mark GeckoProcessType.fromInt as WrapForJNI; r=geckoview-reviewers,agi
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 84 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: