2010-11-07 60 views
3

Java注释处理(自Java 6以来)是一个非常好的概念,因为它允许通过接口(和其他)访问大量关于类和方法的信息。Java注释处理:访问未注释类的“元素”可能吗?

但可悲的是,我不得不找出经验,非注释类永远不会传递给自定义注解处理器:

warning: No SupportedAnnotationTypes annotation found on 
    my.TESTProcessor, returning an empty set. 

是我的发现是真的吗?或者我可以“欺骗”编译器给我的定制注释处理器信息没有注释的类?

回答

4

太棒了!

这让我真的所有类,而不仅仅是那些注释:

@SupportedAnnotationTypes("*") 

是anotation的规范说:

[...] 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 [...] 

测试,工作