java - 如何让 checkstyle 跳过 eclipse 生成的 equals() 和 hashcode() 方法?

标签 java eclipse equals hashcode checkstyle

我们的项目包含几个类,我们有 Eclipse 生成的 equals() 和 hashCode() 方法(右键单击 -> 源代码 -> 生成 hashCode() 和 equals())。

例子:

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    final MyTO other = (MyTO) obj;
    if (num != other.num)
        return false;
    if (name == null) {
        if (other.name != null)
            return false;
    } else if (!name.equals(other.name))
        return false;
    if (table == null) {
        if (other.table != null)
            return false;
    } else if (!table.equals(other.table))
        return false;
    return true;
}

这些方法适用于我们的应用程序,但不幸的是没有通过我们使用 Checkstyle 的圈复杂度检查。由于这些方法是自动生成的,我们不关心它们的复杂性。我们可以从 Checkstyle 中抑制整个类,但我们更希望能够仅排除这两种方法。

有谁知道如何在 Checkstyle 中创建自定义规则,允许我们以任何方式排除生成的 equals() 和 hashCode() 方法,而不排除整个类?

最佳答案

您应该设置一个SupressionCommentFilter。关于此的更多信息 here .

Sometimes there are legitimate reasons for violating a check. When this is a matter of the code in question and not personal preference, the best place to override the policy is in the code itself. Semi-structured comments can be associated with the check.

关于java - 如何让 checkstyle 跳过 eclipse 生成的 equals() 和 hashcode() 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4158280/

相关文章:

java - 如何增强 Java 模式,使其在匹配项周围也包含特殊字符?

java - 更改 Eclipse Dock 图标

java - 暂停时终止应用程序

jquery选择器包含等号

java - 这是 hashCode() 的一个很好的实现吗?

java - 如果我在 Java 中使用字符串作为哈希表键,会出现错误吗?

java - 传递 * 作为参数时,可调用语句花费大量时间

Java swing 应用程序的外观和感觉在 netbean 和 eclipse 中显得不同

java - 在类路径中添加库后找不到 Jetty WebSocket 类

haskell - 模式匹配函数列表时没有 (Eq ([a] -> [a])) 的实例