#1354 Complex FieldDeclarationsShouldBeAtStartOfClass false positive with Spring annotations

This commit is contained in:
Andreas Dangel
2015-05-15 16:06:29 +02:00
parent 3c316c2018
commit cc43e6f8be
3 changed files with 24 additions and 1 deletions

View File

@ -4,6 +4,7 @@
package net.sourceforge.pmd.lang.java.rule.design;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.ast.ASTAnnotation;
import net.sourceforge.pmd.lang.java.ast.ASTAnnotationTypeDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBodyDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
@ -50,7 +51,11 @@ public class FieldDeclarationsShouldBeAtStartOfClassRule extends AbstractJavaRul
for (int i = 0; i < parent.jjtGetNumChildren(); i++) {
Node child = parent.jjtGetChild(i);
if (child.jjtGetNumChildren() > 0) {
child = child.jjtGetChild(0);
if (!(child.jjtGetChild(0) instanceof ASTAnnotation) || child.jjtGetNumChildren() == 1) {
child = child.jjtGetChild(0);
} else {
child = child.jjtGetChild(1);
}
}
if (child.equals(node)) {
break;

View File

@ -153,6 +153,23 @@ public class MyClass {
// something
}
};
}
]]></code>
</test-code>
<test-code>
<description>#1354 Complex FieldDeclarationsShouldBeAtStartOfClass false positive with Spring annotations</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class MyClass {
private static final String MY_STRING = "STRING";
@Autowired
private MyPrivate myPrivate;
@Bean
public void myPublicBean() {}
private static void myPrivateStatic() {}
}
]]></code>
</test-code>