package-info.java package annotations to affect all classes, including ones in sub packages

…衆ロ難τιáo~ 提交于 2019-12-22 10:38:46

问题


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?

thanks


回答1:


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.

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[/\\]"/>


来源:https://stackoverflow.com/questions/25391559/package-info-java-package-annotations-to-affect-all-classes-including-ones-in-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!