Reflecting
You can easily reflect all annotations from a class:
Class<T> clazz;
List<Annotation> annotations = new Mirror().on(clazz).reflectAll()
.annotations().atClass();
As you can also easily reflect all annotations from a field or from a method:
Class<T> clazz;
List<Annotation> methodAnnotations = new Mirror().on(clazz).reflectAll()
.annotations().atMethod("methodName").withoutArgs();
List<Annotation> fieldAnnotations = new Mirror().on(clazz).reflectAll()
.annotations().atField("fieldName");
It's also possible to retrieve a value from an annotation property,
just like the following snippet:
FooAnnotation annotation = new Mirror().on(clazz).reflect()
.annotation(FooAnnotation.class).atClass();
String propertyValue = annotation.aProperty();
And it also works similarly for fields and methods annotations:
FooAnnotation annotation = new Mirror().on(clazz).reflect()
.annotation(FooAnnotation.class).atField("fieldName");
String fieldPropertyValue = annotation.aProperty();
FooAnnotation annotation = new Mirror().on(clazz).reflect()
.annotation(FooAnnotation.class)
.atMethod("methodName").withoutArgs();
String methodPropertyValue = annotation.aProperty();