18
我們的項目包含幾個類,我們擁有由Eclipse(右鍵單擊 - >源代碼 - >生成hashCode()和equals())生成的equals()和hashCode()方法。如何獲取checkstyle以跳過由eclipse生成的equals()和hashcode()方法?
例子:
@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()方法,而不排除整個類?
我不太熟悉SupressionFilters。如何根據方法名稱確定要排除的每個文件的行號? – Brent 2010-11-11 20:01:11
看起來像['SuppressionCommentFilter'](http://checkstyle.sourceforge.net/config.html#SuppressionCommentFilter)(來自同一鏈接)是需要的。它甚至包括一個排除生成代碼的例子。 – matt 2010-11-11 20:01:17
Yup matt,我confused'em :)。在答案中編輯。 Ty – mgv 2010-11-11 20:02:17