Now it catches 'public boolean equals(Object foo) {}', thanks to Dave Brosius for the suggestion

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2843 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2004-07-29 20:02:50 +00:00
parent 50f8b40058
commit 46d3730678
2 changed files with 20 additions and 6 deletions

View File

@ -17,6 +17,7 @@ public class SuspiciousEqualsMethodNameRuleTest extends SimpleAggregatorTst {
runTests(new TestDescriptor[] {
new TestDescriptor(TEST1, "bad, equals(Foo foo)", 1, rule),
new TestDescriptor(TEST2, "ok, equals(Object foo)", 0, rule),
new TestDescriptor(TEST3, "bad, equal(Object foo)", 1, rule),
});
}
@ -30,4 +31,9 @@ public class SuspiciousEqualsMethodNameRuleTest extends SimpleAggregatorTst {
" public boolean equals(Object foo) {return true;}" + PMD.EOL +
"}";
private static final String TEST3 =
"public class Foo {" + PMD.EOL +
" public boolean equal(Object foo) {return true;}" + PMD.EOL +
"}";
}

View File

@ -68,12 +68,20 @@ class Foo {
<property name="xpath">
<value>
<![CDATA[
//ClassDeclaration//MethodDeclarator
[@Image = 'equals']
[count(FormalParameters/*) = 1 ]
[ not (FormalParameters//Type/Name
[@Image = 'Object' or @Image = 'java.lang.Object'])
]
//MethodDeclarator [
(
@Image = 'equals'
and count(FormalParameters/*) = 1
and not (FormalParameters/FormalParameter/Type/Name
[@Image = 'Object' or @Image = 'java.lang.Object'])
)
or
@Image='equal'
and count(FormalParameters/*) = 1
and (FormalParameters/FormalParameter/Type/Name
[@Image = 'Object' or @Image = 'java.lang.Object'])
]
]]>
</value>
</property>