How to get annotations of an annotation? #616
-
For example, some class is annotated by @RestController
@RequestMapping({"/rest/"})
public class DemoRestController {
@GetMapping({"/foo"})
public String foo() throws Exception {
return "foo";
}
} which @Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Controller
@ResponseBody
public @interface RestController {
@AliasFor(annotation = Controller.class)
String value() default "";
} I can get AnnotationUsage of a JavaSootClass via: cls.getAnnotations(Optional.of(view)); But how to get list of annotation of each annotation usage of above results? i.e. |
Beta Was this translation helpful? Give feedback.
Answered by
JonasKlauke
Jun 2, 2023
Replies: 2 comments 1 reply
-
Did you try getting the SootClass of RestController and then calling .getAnnotations on it? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah this works.
For example if au is your AnnotationUsage contained in the resulting list of cls.getAnnotations(Optional.of(view)); then you get the AnnotationType by calling
au.getAnnotation()
. The AnnotationType can be used to get the SootClass byview.getClass(au.getAnnotation())
and on this you can call getAnnotations() againview.getClass(au.getAnnotation()).ifPresent(javaSootClass -> javaSootClass.getAnnotations(Optional.of(view)));