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

查看:1043
本文介绍了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?

感谢

推荐答案

它看起来像有没有办法做到这一点。
我添加了一个静态分析的Checkstyle检查这些package-info.java以确保他们总是在那里。
请参阅: 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.

最后,用晚餐preSS上测试的Checkstyle的规则,并在其中包装标注的定义存在使用SUP pression规则包:

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天全站免登陆