Fixed EqualsHashCodeCheck to ignore generics in determination of check failure.

This commit is contained in:
Michael Studman 2005-04-17 11:13:17 +00:00
parent 7b2966e2a5
commit 8a518cb679
3 changed files with 20 additions and 2 deletions

View File

@ -78,8 +78,8 @@ public class EqualsHashCodeCheck
public void visitToken(DetailAST aAST)
{
final DetailAST modifiers = (DetailAST) aAST.getFirstChild();
final AST type = modifiers.getNextSibling();
final AST methodName = type.getNextSibling();
final AST type = aAST.findFirstToken(TokenTypes.TYPE);
final AST methodName = aAST.findFirstToken(TokenTypes.IDENT);
final DetailAST parameters = aAST.findFirstToken(TokenTypes.PARAMETERS);
if (type.getFirstChild().getType() == TokenTypes.LITERAL_BOOLEAN

View File

@ -177,4 +177,21 @@ class InputSemantic
// empty instance initializer
{
}
public class EqualsVsHashCode5
{
public <A> boolean equals(int a) // wrong arg type, don't flag even with generics
{
return a == 1;
}
}
public class EqualsVsHashCode6
{
public <A> boolean equals(Comparable<A> a) // flag, weven with generics
{
return true;
}
}
}

View File

@ -13,6 +13,7 @@ public class EqualsHashCodeCheckTest
final String[] expected = {
"126:9: Definition of 'equals()' without corresponding definition of 'hashCode()'.",
"163:13: Definition of 'equals()' without corresponding definition of 'hashCode()'.",
"191:9: Definition of 'equals()' without corresponding definition of 'hashCode()'.",
};
verify(checkConfig, getPath("InputSemantic.java"), expected);
}