interactions between type annotations and language model APIs.
alex.buckley at oracle.com
Mon May 5 20:48:38 UTC 2014
On 5/5/2014 12:52 PM, Jonathan Gibbons wrote:
> In particular, TypeMirror is now an AnnotatedConstruct, and various
> methods in javax.lang.model.util.Types return computed TypeMirrors --
> for example, capture(TypeMirror), directSupertypes(TypeMirror),
> erasure(TypeMirror), etc.
Right, because jx.l.m.t.TypeMirror always represented the use of a type
at a particular location in source - which can now usually be annotated.
> In cases where the argument has type annotations, what type annotations
> (if any) should appear on the return value?
> It would help to see clarification added to the specifications, either
> generally, or on a case-by-case basis for the affected methods.
To be specific, the "generator" methods in jx.l.m.u.Types are these ten:
Generally, the "correct" thing to do would be to inspect the TypeMirror
argument and thread its type annotations into the TypeMirror result. But
not always: just because '@Foo String' appears in source does not mean
that calling directSupertypes on its mirror should return '@Foo Object'.
There is also a limitation of the API for wildcard annotations:
getWildcardType could produce a mirror for '? extends @Foo ...' and '?
super @Foo ...' but not '@Foo ? extends ...' or '@Foo ? super ...'.
Joe, what is your view on retrofitting type annotations into Types?
More information about the compiler-dev