Recent change in UseSingleton introduced a false + for methods with annotations

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6802 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Xavier Le Vourch 2009-01-27 23:43:03 +00:00
parent 240e548c36
commit 9b4b50560d
2 changed files with 21 additions and 3 deletions

View File

@ -163,6 +163,20 @@ public enum EnumTest {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(EnumTest.A); System.out.println(EnumTest.A);
} }
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
OK, method annotations
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
public Foo() { }
@Override
public void doSomething() { }
public static void main(String args[]) { }
} }
]]></code> ]]></code>
</test-code> </test-code>

View File

@ -4,6 +4,7 @@
package net.sourceforge.pmd.rules.design; package net.sourceforge.pmd.rules.design;
import net.sourceforge.pmd.AbstractRule; import net.sourceforge.pmd.AbstractRule;
import net.sourceforge.pmd.ast.ASTAnnotation;
import net.sourceforge.pmd.ast.ASTClassOrInterfaceBody; import net.sourceforge.pmd.ast.ASTClassOrInterfaceBody;
import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration; import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration;
import net.sourceforge.pmd.ast.ASTClassOrInterfaceType; import net.sourceforge.pmd.ast.ASTClassOrInterfaceType;
@ -26,11 +27,14 @@ public class UseSingleton extends AbstractRule {
int methodCount = 0; int methodCount = 0;
boolean isOK = false; boolean isOK = false;
while (i > 0) { while (i > 0) {
Node n = decl.jjtGetChild(--i); Node p = decl.jjtGetChild(--i);
if (n.jjtGetNumChildren() != 1) { if (p.jjtGetNumChildren() == 0) {
continue; continue;
} }
n = n.jjtGetChild(0); Node n = p.jjtGetChild(0);
if (n instanceof ASTAnnotation) {
n = p.jjtGetChild(1);
}
if (n instanceof ASTFieldDeclaration) { if (n instanceof ASTFieldDeclaration) {
if (!((ASTFieldDeclaration) n).isStatic()) { if (!((ASTFieldDeclaration) n).isStatic()) {
isOK = true; isOK = true;