[英]CheckStyle doesn't flag missing JavaDoc on Interface Methods
Does anyone know why CheckStyle doesn't flag missing JavaDoc on Interface Methods, only on actual implementing methods?有谁知道为什么 CheckStyle 没有在接口方法上标记缺失的 JavaDoc,只在实际实现方法上标记?
Suppose I have the following,假设我有以下内容,
<module name="JavadocMethod">
<property name="scope" value="public"/>
<property name="allowMissingParamTags" value="true"/>
<property name="allowMissingThrowsTags" value="true"/>
<property name="allowMissingReturnTag" value="true"/>
<property name="minLineCount" value="2"/>
<property name="allowedAnnotations" value="Override, Test"/>
<property name="allowThrowsTagsForSubclasses" value="true"/>
This will report missing JavaDoc in actual class method, but not in Interface methods.这将报告在实际类方法中缺少 JavaDoc,但不在接口方法中。
Also tried adding this, didn't work:也尝试添加这个,没有用:
<property name="tokens" value="INTERFACE_DEF"/>
<property name="tokens" value="INTERFACE_DEF, CLASS_DEF"/>
Similiar thread that I got this from (but not working): checkstyle JavadocType only on interfaces我从中得到的类似线程(但不起作用): checkstyle JavadocType only on interfaces
Any way to force the JavadocMethod
check on Interface Methods?有什么方法可以强制对接口方法进行
JavadocMethod
检查?
Reason: Spring Data , the JPA library, is based on Interface-only method names where implementation is provided behind the scenes based on @Query
annotation configurators.原因: Spring Data ,JPA 库,基于仅接口的方法名称,其中基于
@Query
注释配置器在幕后提供实现。 Thus we have no implementations of our own.因此,我们没有自己的实现。 So we need to check and require JavaDoc on Interface methods in this case.
因此,在这种情况下,我们需要检查并要求接口方法上的 JavaDoc。
<property name="minLineCount" value="2"/>
This is why.这就是为什么。 You specify a javadoc is needed if line count is 2 or greater.
如果行数为 2 或更大,则需要指定 javadoc。 Interfaces don't have any line counts, so that is why you aren't getting any violations.
接口没有任何行数,所以这就是为什么您没有收到任何违规的原因。
$ cat TestClass.java
public interface TestInterface {
void method();
}
$ cat TestConfig.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="charset" value="UTF-8"/>
<module name="TreeWalker">
<module name="JavadocMethod">
<property name="scope" value="public"/>
<property name="allowMissingParamTags" value="true"/>
<property name="allowMissingThrowsTags" value="true"/>
<property name="allowMissingReturnTag" value="true"/>
<property name="allowedAnnotations" value="Override, Test"/>
<property name="allowThrowsTagsForSubclasses" value="true"/>
</module>
</module>
</module>
$ java -jar checkstyle-8.18-all.jar -c TestConfig.xml TestClass.java
Starting audit...
[ERROR] TestClass.java:2:5: Missing a Javadoc comment. [JavadocMethod]
Audit done.
Checkstyle ends with 1 errors.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.