java - 如何启用 checkstyle 的 MissingOverride 检查?

标签 java maven checkstyle maven-checkstyle-plugin

我有一个

public interface Interface0 {

    void method0();
}

和一个

public class Implementation0 implements Interface0 {

    public void method0() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}

我通过声明使用 maven-checkstyle-plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
        <execution>
            <id>checkstyle</id>
            <phase>validate</phase>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <configLocation>${basedir}/check_style.xml</configLocation>
    </configuration>
</plugin>

最后,我在 check_style.xml 中激活了 MissingOverride:

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
   "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
   "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
    <module name="TreeWalker">
        <module name="MissingOverride"/>
    </module>
</module>

这是我在许多项目中的经验摘录,所有检查工作正常,除了 MissingOverride 没有效果,即没有检测到单个丢失的 @Override 注释。

最佳答案

MissingOverride 模块的文档指出:

Verifies that the java.lang.Override annotation is present when the {@inheritDoc} javadoc tag is present.

Documentation link

换句话说,它不打算检查你想要它检查的内容 - 它只检查 Javadoc 注释中 {@inheritDoc} 标记的使用是否与 配对@Override注解。

关于java - 如何启用 checkstyle 的 MissingOverride 检查?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50440968/

相关文章:

java - Android 应用程序关闭后从设备中删除照片

java - 如何在 Android 中使用切换按钮停止后台服务?

java - JNI - 如何为 OSGI 包生成头文件

maven - jgitflow :release-finish is not deleting the release branch

java - 由 : java. sql.SQLSyntaxErrorException 引起:ORA-01722:JPA HIBERNATE HQL 中的数字无效

java - 如何将 JPopup 移动到 Glasspane

java - Maven 无法部署 Artifact ReasonPhrase :Forbidden

java - Checkstyle 和泛型

java - 如何在 CheckStyle 中抑制警告?

sbt - 在 Play 2.2 项目中运行 Checkstyle 5.5 时是否出现 NoSuchMethodError?