TYPE_USE annotations on type parameter declarations
Alex Buckley
alex.buckley at oracle.com
Wed Dec 9 19:31:35 UTC 2015
On 12/8/2015 5:48 PM, Alex Buckley wrote:
> Unfortunately, while reviewing 9.7.4:
>
> ---
> A declaration annotation is an annotation that applies to a declaration,
> and whose own type is applicable in the declaration context (§9.6.4.1)
> represented by that declaration.
>
> A type annotation is an annotation that applies to a type (or any part
> of a type), and whose own type is applicable in type contexts (§4.11).
> ---
>
> I found a hole:
>
> - The annotation @TU is not a "declaration annotation" because while it
> applies to a declaration, its own type TU is not applicable in the
> declaration context represented by the
> class/interface/enum/annotation-type/type-parameter declaration.
>
> - The annotation @TU is not considered a "type annotation" because it
> does not apply to a type use.
>
> This failure to classify the annotation is bad. Let's see what javac
> emits for a TYPE_USE annotation like @TU:
>
> - On a class/interface/enum/annotation-type declaration, javac emits a
> Runtime[In]VisibleAnnotations attribute -- this makes sense as it's
> basically a traditional declaration annotation.
>
> - On a type-parameter declaration, javac emits a
> Runtime[In]VisibleTypeAnnotations attribute -- that's the only way to
> encode the annotation, but still we should regard it as a declaration
> annotation (that's how Core Reflection exposes it).
>
> Consequently, 9.7.4 should add a paragraph:
>
> ---
> ***Additionally, an annotation that applies to either:
>
> - a class, interface, enum, or annotation type declaration, or
> - a type parameter declaration of a generic class, interface, method, or
> constructor
>
> and whose own type is applicable in type contexts, is deemed to be a
> declaration annotation.***
> ---
Tracked via https://bugs.openjdk.java.net/browse/JDK-8145032.
Alex
More information about the compiler-dev
mailing list