RFR: 8336754: Remodel TypeAnnotation to "has" instead of "be" an Annotation

Alex Buckley alex.buckley at oracle.com
Fri Jul 19 17:59:00 UTC 2024


Logically, an annotation is either a declaration annotation or a type 
annotation. A declaration annotation _is_ an annotation. A type 
annotation _is_ an annotation. These terms come from JLS 9.7.4.

In the Class File API, `Annotation` is specified as "Models an 
annotation on a declaration." That's fair: you're using the "good" name 
`Annotation` for declaration annotations because they are more common 
than type annotations.

(It's not what the Core Reflection API does -- 
`java.lang.reflect.Annotation` denotes annotations at a very high level 
of abstraction, independent of appearance in declaration contexts or 
type contexts -- but that's a different API, so OK.)

However, I think it's wrong in Class File for `TypeAnnotation` to 
have/contain an `Annotation`. Logically, a type annotation does not 
have/contain a declaration annotation.

I don't know much the Class File API supports writing a `TypeAnnotation` 
into a class file (especially since WritableElement is on the way out), 
but the problem would be reifying a type annotation on (say) the type 
used in an `extends` clause, but with the annotation itself only being 
permitted on (say) a field declaration.

Alex

On 7/18/2024 7:01 PM, Chen Liang wrote:
> `TypeAnnotation` is not an annotation, as it should not be used in places like `AnnotationValue.ofAnnotation`. Thus it's remodeled to contain an annotation at a given location instead of to be an annotation.
> 
> Depends on #20205.
> 
> -------------
> 
> Depends on: https://git.openjdk.org/jdk/pull/20205
> 
> Commit messages:
>   - 8336754: Remodel TypeAnnotation to "has" instead of "be" an Annotation
> 
> Changes: https://git.openjdk.org/jdk/pull/20247/files
>    Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=20247&range=00
>    Issue: https://bugs.openjdk.org/browse/JDK-8336754
>    Stats: 218 lines in 18 files changed: 60 ins; 116 del; 42 mod
>    Patch: https://git.openjdk.org/jdk/pull/20247.diff
>    Fetch: git fetch https://git.openjdk.org/jdk.git pull/20247/head:pull/20247
> 
> PR: https://git.openjdk.org/jdk/pull/20247


More information about the compiler-dev mailing list