开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜