RFR: JDK-8057804: AnnotatedType interfaces provide no way to get annotations on owner type
joshua at bluegosling.com
Wed Mar 30 14:12:29 UTC 2016
I know it's been months since this patch was integrated. I apologize that I
had talked about contributing some changes in this area and then never
In any event, I had some questions about the patch and possibly some
suggestions for further changes before the API is "sealed" for Java 9 (not
sure if that has already happened or not):
- I see you had to override the new method on most of AnnotatedType's
sub-interfaces to indicate that it should return null. The new method
really only applies to "declared types" and thus had to be spec'ed to
return null for arrays, wildcards, and type variables.
- With both java.lang.reflect.Type and javax.lang.model.type.TypeMirror,
all actual instances will implement some sub-interfaces (or, in the case of
Type -> Class, be an instance of a known concrete class). So usages can
generally use instanceof tests to learn more about the object and then
down-cast. However, when working with AnnotatedTypes, there is no such
sub-interface for a non-parameterized declared type. So the type-switch
idiom is left with a default that must make assumptions about the
AnnotatedType instance (which could be invalidated by future API
changes, like introduction of new sub-interfaces).
Given the above, I think it makes sense to introduce a new interface,
AnnotatedRawType, that extends AnnotatedType. Instead of having
getAnnotatedOwnerType() on AnnotatedType, it could just exist on
AnnotatedRawType and AnnotatedParameterizedType.
(FWIW, getting a development environment setup for Java 9 was very
difficult circa 12 months ago. I had made several changes in a local
checkout of the jdk8 repo. But I never got a chance to forward-patch my
changes to jdk9. Also, I'm a mercurial n00b, so lack of comfort with the
tools was a major impediment. Anyhow, I'd still like to contribute but was
stymied by the amount of free time it would take me to push through these
challenges. Maybe I'll get some motivation to revisit before it's too late
to contribute to jdk9.)
joshua at bluegosling.com
On Tue, Nov 17, 2015 at 2:15 PM, Joel Borggrén-Franck <
joel.borggren.franck at gmail.com> wrote:
> When reflecting over annotated types, there is currently no way to get
> the potentially annotated owner of a type. For example, given you have
> an instance of '@A Outer . @B Inner' you can't traverse it to get '@A
> Outer' .
> This API addition fixes this. Because both parameterized and
> non-generic types can have an owner, this addition goes into the base
> AnnotatedType interface together with a default implementation. CCC
> has been filed.
> The parsing code and annotated type factory had to be fixed to deal
> with navigating inside nested types.
> Bug: https://bugs.openjdk.java.net/browse/JDK-8057804
> Webrev: http://cr.openjdk.java.net/~rbackman/jbf/8057804/webrev.00/
> (OCA is signed and processed).
More information about the core-libs-dev