MethodWithSameNameAsEnclosingClass now reports better line numbers

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2825 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2004-07-22 19:25:07 +00:00
parent 3aa557ad8b
commit 080b8511b1
4 changed files with 44 additions and 25 deletions

View File

@ -3,7 +3,8 @@ Moved development environment to Maven 1.0.
Moved development environment to Ant 1.6.2. This is nice because using the new JUnit task attribute "forkmode='perBatch'" cuts test runtime from 90 seconds to 7 seconds. Sweet.
Applied patch in RFE 992576 - Enhancements to VariableNamingConventionsRule
Fixed bug in SimplifyBooleanExpressions - now it catches more cases.
Fixed bugs in AvoidDuplicateLiterals - now it ignores small duplicate literals, its rule violation message is more helpful, and it catches more cases.
Fixed bugs in AvoidDuplicateLiterals - now it ignores small duplicate literals, its rule violation message is more helpful, and it catches more cases.
MethodWithSameNameAsEnclosingClass now reports a more helpful line number.
July 14, 2004 - 1.9:
New rules: CloneMethodMustImplementCloneable, CloneThrowsCloneNotSupportedException, EqualsNull, ConfusingTernary

View File

@ -18,6 +18,7 @@ public class MethodWithSameNameAsEnclosingClassRuleTest extends SimpleAggregator
runTests(new TestDescriptor[] {
new TestDescriptor(TEST1, "bad", 1, rule),
new TestDescriptor(TEST2, "ok", 0, rule),
new TestDescriptor(TEST3, "doesn't crash on interfaces", 0, rule),
});
}
@ -30,4 +31,9 @@ public class MethodWithSameNameAsEnclosingClassRuleTest extends SimpleAggregator
"public class Foo {" + PMD.EOL +
" public Foo() {}" + PMD.EOL +
"}";
private static final String TEST3 =
"public interface Foo {" + PMD.EOL +
" void voo();" + PMD.EOL +
"}";
}

View File

@ -219,8 +219,12 @@ public abstract class Foo { // should be AbstractFoo
<property name="xpath">
<value>
<![CDATA[
//UnmodifiedClassDeclaration[@Image = //MethodDeclarator/@Image]
]]>
//MethodDeclaration
[parent::ClassBodyDeclaration
[parent::ClassBody
[parent::UnmodifiedClassDeclaration/@Image = //MethodDeclarator/@Image
]]]
]]>
</value>
</property>
</properties>

View File

@ -5,30 +5,38 @@
These are new rules that are still in progress
</description>
<rule name="AvoidDuplicateLiterals"
message="The String literal {0} appears {1} times in this file; the first occurrence is on line {2}"
class="net.sourceforge.pmd.rules.AvoidDuplicateLiteralsRule">
<description>
Code containing duplicate String literals can usually be improved by declaring the String as a constant field.
</description>
<priority>3</priority>
<properties>
<property name="threshold" value="4"/>
</properties>
<example>
<rule name="MethodWithSameNameAsEnclosingClass"
message="Classes should not have non-constructor methods with the same name as the class"
class="net.sourceforge.pmd.rules.XPathRule">
<description>
Non-constructor methods should not have the same name as the enclosing class.
</description>
<properties>
<property name="xpath">
<value>
<![CDATA[
public class Foo {
private void bar() {
buz("Howdy");
buz("Howdy");
buz("Howdy");
buz("Howdy");
}
private void buz(String x) {}
//MethodDeclaration
[parent::ClassBodyDeclaration
[parent::ClassBody
[parent::UnmodifiedClassDeclaration/@Image = //MethodDeclarator/@Image
]]]
]]>
</value>
</property>
</properties>
<priority>3</priority>
<example>
<![CDATA[
public class MyClass {
// this is bad because it is a method
public void MyClass() {}
// this is OK because it is a constructor
public MyClass() {}
}
]]>
</example>
</rule>
]]>
</example>
</rule>