I have the following annotation:
@Target(ElementType.METHOD)
public @interface MyAnn {
}
and a method annotated with @MyAnn:
@MyAnn
Object myMehtod(Object x) {
...
}
Using a Java annotation processor I get the annotated element as:
Element annotatedElement // = myMehtod
Here is my solution:
ExecutableType executableType = (ExecutableType)annotatedElement.asType();
List<? extends TypeMirror> parameters = executableType.getParameterTypes();
TypeMirror param1 = parameters.get(0);
DeclaredType declaredType = (DeclaredType)param1;
List<? extends AnnotationMirror> anns = ((TypeElement)declaredType.asElement()).getAnnotationMirrors( );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With