开发者

Java annotation processing: Accessing "Element"s of non-annotated classes possible?

开发者 https://www.devze.com 2023-01-24 08:53 出处:网络
Java annotation processing (since Java 6) is a very good concept, because it allows to access lots of information about classes and methods through the Element interface (and others).

Java annotation processing (since Java 6) is a very good concept, because it allows to access lots of information about classes and methods through the Element interface (and others).

But sadly, I had to find out empirically, that non-annotated classes are never passed to a custom annotation processor:

warning: No SupportedAnnotationTypes annotation found on
    my.TESTProcessor, returning an empty 开发者_如何学编程set.

Are my findings true? Or can I "trick" the compiler to give my custom annotation processor information about non-annotated classes as well?


Great!

This gives me really all classes, not just annotated ones:

@SupportedAnnotationTypes("*")

The spec of that anotation says:

[...] Finally, "*" by itself represents the set of all annotation types,
including the empty set. Note that a processor should not claim "*"
unless it is actually processing all files [...] 

Tested, works!

0

精彩评论

暂无评论...
验证码 换一张
取 消