Type Annotations on VariableElement
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
This comment has been minimized.
Output display: