RFR: 8292275: javac does not emit SYNTHETIC and MANDATED flags for parameters by default [v4]

Joe Darcy darcy at openjdk.org
Mon Aug 22 21:21:35 UTC 2022


On Fri, 19 Aug 2022 13:05:10 GMT, Hannes Greule <duke at openjdk.org> wrote:

>> With this change, javac emits the MethodParameters attribute in cases where the JLS requires the information about synthetic and mandated parameters to be stored (see issue).
>> Parameter names are *not* emitted unless the `-parameter` flag is set.
>> 
>> The relevant changes are in `ClassWriter`, where we go through the params to see if we need the attribute if the `-parameter` flag is not set (if it is set, both names and flags will be emitted).
>> For records, the mandated flag wasn't set at all, this is solved by the one line fix in `JavacParser`.
>> 
>> The changes to `CreateSymbols` and `ClassReader` are needed as they weren't able to deal with missing names in the attribute.
>> I also had to update some tests as they got a new constant pool entry.
>> 
>> Only the mandated flag is covered by tests at the moment, as the occurrences are well-specified in the JLS.
>> Please let me know if you want tests for specific appearances of synthetic parameters.
>
> Hannes Greule has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - cleanup
>  - add annotation processing test

test/langtools/tools/javac/processing/model/util/elements/MethodParameters/ImplicitParametersProcessor.java line 33:

> 31:  * @build   JavacTestingAbstractProcessor ImplicitParametersProcessor
> 32:  * @compile -processor ImplicitParametersProcessor -proc:only ClassContainer.java
> 33:  */

Good start on the annotation processor. From personal experience writing such tests and then looking at them months later, I recommend adding some kind of brief comment describing the intended semantics of the test, e.g.

"Verify enum classes and record classes have expected mandated executables."

To make the test more extensible, the expected information could be encoded in annotations; e.g. something like

@interface ExpectedInfo {
    String methodName();
    Elements.Origin origin();
}

where the record and enum were annotated in turn:

@ExpectedInfo(name="<init>", origin=MANDATED)
MyEnum {..}

etc.

-------------

PR: https://git.openjdk.org/jdk/pull/9862


More information about the compiler-dev mailing list