1

我试图抑制 CheckStyle StrictDuplicateCode 警告,但它不起作用。在我的 Eclipse 项目中,我有两个具有相似字段的类:

public class MyClass {
    // CHECKSTYLE:OFF
    private String field1;

    private String field2;

    private String field3;

    private String field4;

    private String field5;

    private String field6;

    private String field7;

    private String field8;
}

public class MyDuplicateClass {
    // CHECKSTYLE:OFF
    private String field1;

    private String field2;

    private String field3;

    private String field4;

    private String field5;

    private String field6;

    private String field7;

    private String field8;
}

将“CHECKSTYLE:OFF”注释放在一个或两个类中不会抑制警告。我错过了什么吗?

4

1 回答 1

1

确保您正确配置了SuppressionCommentFilter,例如:

<module name="Checker">

  <module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="CHECKSTYLE\:OFF ([\w\|]+)"/>
    <property name="onCommentFormat" value="CHECKSTYLE\:ON ([\w\|]+)"/>
    <property name="checkFormat" value="$1"/>
  </module>

  <module name="TreeWalker">

...
于 2011-10-17T13:55:52.137 回答