Accessing type annotations via annotation processor
Eric McCorkle
eric.mccorkle at oracle.com
Thu Aug 14 18:26:37 UTC 2014
Type annotations on type arguments, arrays, and wildcard bounds are
known to have issues in JDK8. Also, the language model only works for a
small number of cases in JDK8.
Type annotations on the base type of a declaration are the most reliable
in JDK8, and the language model should work correctly. More complicated
uses (anonymous classes, type arguments, arrays, wildcards, etc.)
probably won't at this time.
On 08/11/14 14:13, Alex Buckley wrote:
> There are some known problems with retrieving type annotations on type
> parameter declarations, in both the Core Reflection API and the Language
> Model API. I believe type annotations on types used in member
> declarations work OK. If you have the VariableElement for 'values', you
> can get the TypeMirror for 'List<@NotNull String>', then visit it as a
> DeclaredType and call getTypeArguments() to get a TypeMirror for
> '@NotNull String'. TypeMirror is an AnnotatedConstruct so it can return
> the annotations on the use of 'String'.
>
> Alex
>
> On 8/11/2014 3:22 AM, Gunnar Morling wrote:
>> Hi,
>>
>> I'm looking for a way to obtain annotations given on type uses using a
>> JSR 269 annotation processor.
>>
>> E.g. I'd like to obtain the @NotNull annotation from the following field
>> declaration:
>>
>> ...
>> private List<@NotNull String> values;
>>
>> Based on a post of Joe [1] I assumed this to be possible, but a
>> discussion on this list now makes me believe this cannot be done as of
>> Java 8. Is this true? If so, will this be the case in SE 9?
>>
>> On a tangent, Joe referenced a diff of the JavaDocs of two versions of
>> the JSR 269 API, containing nicely colored mark-up highlighting the
>> changes. What's the tool used for creating this diff?
>>
>> Thanks,
>>
>> --Gunnar
>>
>> [1] https://blogs.oracle.com/darcy/entry/jsr_269_mr_for_java
>> [2]
>> http://mail.openjdk.java.net/pipermail/compiler-dev/2014-May/008756.html
>>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: eric_mccorkle.vcf
Type: text/x-vcard
Size: 314 bytes
Desc: not available
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20140814/f647ffc6/eric_mccorkle.vcf>
More information about the compiler-dev
mailing list