How to build a list of classes annotated with my custom annotation?

后端 未结 8 1152
梦毁少年i
梦毁少年i 2020-12-23 16:52

I want to get a complete list of classes in the application which are annotated with @Custom annotation. What is the best mechanism for this operation?

8条回答
  •  孤城傲影
    2020-12-23 17:30

    The easiest way would be to use an IDE as Jesus suggested.

    But you could also

    • write an annotation processor that logs all occurrences of the annotation
    • write an AspectJ aspect and declare a warning for this annotation (I know, warning is probably not what you want, but there is no INFO in AspectJ)
    • use ASM to check the byte code for the annotation
    • use a Source Parser to check the source code for the annotation

    Beware: All of these are tricky. The AspectJ solution should be the simplest.

提交回复
热议问题