[Annotation Processor] Accessing type annotations on VariableElement at compile time (original) (raw)

DuyHai Doan doanduyhai at gmail.com
Tue May 12 13🔞47 UTC 2015


Hello

I've tried to play with the new JSR 308 feature (type annotations) and I'm facing a rather annoying limitation:

Suppose a class:

public static class SimpleEntityCodecFactoryTest {

    private Map<@JSON Integer,Map<@Frozen

Integer, at Enumerated(value = Enumerated.Encoding.NAME, test = "123") String>> map; }

What I need is to access all annotations set on type parameters as well as their attribute values. Right now the only way I find so far is to cast the VariableElement to "Symbol.VarSymbol" and then access the internal api getMetadata(). It works but it is far from being developer-friendly.

More details here: https://gist.github.com/doanduyhai/b11f9cd843f9be557382

I've tried with declareType.getTypeArguments().get(0).getAnnotationMirrors() but the returned list is empty.

Note: I'm using JDK 1.8.0_45. I also tried 1.8.0_u60 but same result ...

Am I missing something or is it really a bug in the javax.lang.model package ?

Thanks



More information about the core-libs-dev mailing list