代码之家  ›  专栏  ›  技术社区  ›  java.is.for.desktop

Java注释处理:是否可以访问非注释类的“元素”?

  •  3
  • java.is.for.desktop  · 技术社区  · 15 年前

    Java注释处理(因为Java6)是一个非常好的概念,因为它允许通过 Element 接口(和其他)。

    但遗憾的是,我不得不从经验上发现,未注释的类从未传递给自定义注释处理器:

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

    我的发现是真的吗?或者我可以“欺骗”编译器,让它提供有关 无注释 还有课吗?

    1 回复  |  直到 15 年前
        1
  •  5
  •   java.is.for.desktop    15 年前

    伟大的!

    这让我真的 全部的 类,而不仅仅是注释类:

    @SupportedAnnotationTypes("*")
    

    这项法令的具体内容是:

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

    !