Record component annotations with target=PARAMETER
Brian Goetz
brian.goetz at oracle.com
Tue Dec 17 15:14:49 UTC 2019
There are several places that a declaration annotation on a record parameter can be "pushed down" to:
- The record component itself, stored in the Record attribute (if anno has target RECORD_COMPONENT)
- Parameters of an implicit canonical constructor (for target PARAMETER)
- An implicit accessor for the component (for target METHOD)
- The component field (for target FIELD)
If the anno has multiple of these targets, it is pushed down to multiple places.
> On Dec 17, 2019, at 5:10 AM, Tagir Valeev <amaembo at gmail.com> wrote:
>
> Hello!
>
> Current records JLS spec draft [1] says:
>
> a record component but T is not applicable to record component
> declarations, field declarations, method declarations, or type
> contexts.
>
> However, javac doesn't fail if the annotation target is parameter:
>
> import java.lang.annotation.*;
>
> record Foo(@Anno int x) {}
> @Target(ElementType.PARAMETER)
> @interface Anno {}
>
> This code compiles and the canonical constructor is annotated with
> Anno. To me, the javac behavior is expected and spec should be updated
> to include "parameters":
>
> a record component but T is not applicable to record component
> declarations, field declarations, method declarations, parameters, or
> type contexts.
>
> What do you think? I'm implementing error highlighting for records in
> IntelliJ now. Should I follow the spec or javac behavior?
>
> With best regards,
> Tagir Valeev.
>
> http://cr.openjdk.java.net/~gbierman/jep359/jep359-20191125/specs/records-jls.html#jls-9.7.4
More information about the amber-spec-experts
mailing list