2010-11-07 72 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 [...] 

測試,工作