Last active
August 29, 2015 14:21
-
-
Save doanduyhai/b11f9cd843f9be557382 to your computer and use it in GitHub Desktop.
Type Annotations on VariableElement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class SimpleEntityCodecFactoryTest { | |
private Map<@JSON Integer,Map<@Frozen Integer,@Enumerated(value = Enumerated.Encoding.NAME, test = "123") String>> map; | |
} | |
final TypeElement typeElement = elementUtils.getTypeElement(SimpleEntityCodecFactoryTest.class.getCanonicalName()); | |
final List<VariableElement> els = ElementFilter.fieldsIn(typeElement.getEnclosedElements()); | |
final VariableElement mapElt = els.stream().filter(x -> x.getSimpleName().contentEquals("map")).findFirst().get(); | |
final com.sun.tools.javac.util.List<Attribute.TypeCompound> typeAttributes = ((Symbol.VarSymbol) mapElt).getMetadata().getTypeAttributes(); | |
for (Attribute.TypeCompound typeAttribute : typeAttributes) { | |
final DeclaredType annotationType = typeAttribute.getAnnotationType(); | |
System.out.println(format("Accessing annotation '%s' at location : %s",annotationType.toString(),typeAttribute.getPosition().location)); | |
for (Map.Entry<Symbol.MethodSymbol,Attribute> entry : typeAttribute.getElementValues().entrySet()) { | |
final Symbol.MethodSymbol methodSymbol = entry.getKey(); | |
final Attribute attribute = entry.getValue(); | |
System.out.println(format("Attribute '%s' for annotation '%s' : %s", methodSymbol.name, annotationType.toString(), attribute.toString())); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output display: