package-info.java 包注释以影响所有类,包括子包中的类 [英] package-info.java package annotations to affect all classes, including ones in sub packages

查看:34
本文介绍了package-info.java 包注释以影响所有类,包括子包中的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的所有类上应用注释,我正在尝试最好的方法.到目前为止,我坚持使用可以注释整个包的 package-info.java 文件,而不是包含在子包中的类文件.除了在我的项目中添加 100 个相同的 package-info.java 文件只包含一个注释之外,还有没有更有效的方法?

I want to apply an annotation on all of my classes and I am trying the best way to do so. So far I am stuck with the package-info.java file that can annotate a whole package, but not the class files contained in the sub-packages. Is there a more efficient way other than adding 100 identical package-info.java files in my project that only contain a single annotation?

谢谢

推荐答案

看起来没有办法做到这一点.我为那些 package-info.java 添加了一个静态分析 checkstyle 检查,以确保它们始终存在.请参阅:http://checkstyle.sourceforge.net/config_javadoc.html 了解更多详情.然后,如果您对项目运行 checkstyle 静态分析,它会抱怨缺少 package-info.java 文件.

It looks like there is no way to do this. I have added a static analysis checkstyle check for those package-info.java to make sure they are always there. See: http://checkstyle.sourceforge.net/config_javadoc.html for more details. Then if you run checkstyle static analysis on the project, it will complain for any missing package-info.java file.

最后,要抑制测试中的 checkstyle 规则,以及存在包注释定义的包,请使用此抑制规则:

Finally, to suppress the checkstyle rule on the tests, and on the package where the package annotation definition exists use this suppression rule:

<suppress checks="JavadocPackage" files="PackageNonnull.java|[/\\]src[/\\]test[/\\]java[/\\]"/>

这篇关于package-info.java 包注释以影响所有类,包括子包中的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆