[type-annos-observers] What annotations would I expect to see on the TypeMirror materialized from a TypeElement ?
Alex Buckley
alex.buckley at oracle.com
Tue Oct 8 18:33:16 PDT 2013
// cc'ing Leonid as JCK owns Language Model tests for Type Annotations
On 10/7/2013 8:35 PM, Srikanth S Adayapalam wrote:
>> Thanks in advance for your clarification.
>>
>> @TypeUseAnnotation
>> public class X {
>> }
>>
>> Experiments with 8b108 show that (typeElement.asType()).
>> getAnnotationMirrors()
>> return nothing. Is this warranted ?
>
> I should have added: we like this behavior :) it simplifies
> somethings in our implementation and imposes a model that
> from a TypeMirror you get annotations for the type-use site
> and from an Element you get annotations for a declaration
> site.
>
> Nevertheless checking to make sure this is intended.
I think it's a reasonable outcome.
Assuming TypeUseAnnotation is meta-annotated with
@Target(ElementType.TYPE_USE), the annotation @TypeUseAnnotation applies
to the class declaration, and I would expect
typeElement.getAnnotationMirrors() to return it.
But for typeElement.asType(), you're getting a representation of a
particular use of type X - but there isn't really such a use when X is
still being declared. I wouldn't expect the TypeMirror to be able to
tell you much. In particular, the javadoc for AnnotatedConstruct (which
both Element and TypeMirror implement) says "Annotations on an element
are on a declaration, whereas annotations on a type are on a specific
use of a type name." - and there are no annotation on the "X" which
appears after "class".
Alex
[1]
http://mail.openjdk.java.net/pipermail/type-annotations-spec-experts/2013-February/000064.html
More information about the type-annotations-spec-observers
mailing list