Javadoc 警告没有评论
如果没有为方法或类提供 javadoc 注释,是否有一种方法(最好通过参数、taglet、doclet 或类似方法)让 Javadoc 生成警告?我已经对这些选项进行了侦察,并在谷歌上进行了搜索,但看不到任何突出的相关内容。我目前正在开发一个项目,其中所有内容都需要某种形式的 Javadoc 注释,这对于该目的非常有用。
编辑:我知道这样的事情可以通过代码质量工具(例如 checkstyle)来强制执行,我只是想知道是否有一种方法可以配置 Javadoc 来警告诸如此类的不同事情。
Is there a way (preferably via an argument, taglet, doclet or similar) to get Javadoc to generate a warning if there is no javadoc comment provided for a method or class? I've had a scout around at the options and Googled but can't see anything that stands out as being relevant. I'm currently working on a project where everything needs to have some form of Javadoc comment and this would be really useful for that purpose.
EDIT: I know such things can be enforced via code quality tools such as checkstyle, I was just wondering if there was a way to configure Javadoc to warn about different things such as this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以尝试 checkstyle 来强制执行此类约定。
You might try checkstyle to enforce such conventions.
如果您确实想使用 Javadoc,那么自定义检查 doclet 将是最佳选择。
下面是一个示例:
运行 doclet 本身(使用 ant)给出以下输出:
如果我们希望在发现错误时不成功,则在这种情况下我们应该从启动方法返回 false。
If you really wanted to use Javadoc, a custom checking doclet would be the way to go.
Here is an example:
Running the doclet on itself (with ant) gives this output:
If we want this to be not successful whenever one error is found, we should return false from the start-method in this case.
较新的 JDK 支持显式的
-Xdoclint:missing
标志。例如,在 JDK 17 中:
请注意其中的
missing
选项。Newer JDK's support an explicit
-Xdoclint:missing
flag for this.E.g. in JDK 17:
Note the
missing
option in there.此任务最好使用 PMD 或 FindBug(可能是检查样式)等代码分析工具来完成,因为这些工具旨在查找此类问题以及更多问题。
IntelliJ 有一个内置检查器,可以帮助填充缺失的 javadoc 内容以及对其进行健全性检查/拼写检查。
This task is best done with a code analysis tool like PMD or FindBug (possibly check style) as these are designed find these sort of issues and much more.
IntelliJ has a builtin checker which can help populate missing javadoc content as well as sanity check/spell check it.