forked from phoedos/pmd
#1364 FieldDeclarationsShouldBeAtStartOfClass false positive using multiple annotations
This commit is contained in:
@ -51,11 +51,7 @@ public class FieldDeclarationsShouldBeAtStartOfClassRule extends AbstractJavaRul
|
||||
for (int i = 0; i < parent.jjtGetNumChildren(); i++) {
|
||||
Node child = parent.jjtGetChild(i);
|
||||
if (child.jjtGetNumChildren() > 0) {
|
||||
if (!(child.jjtGetChild(0) instanceof ASTAnnotation) || child.jjtGetNumChildren() == 1) {
|
||||
child = child.jjtGetChild(0);
|
||||
} else {
|
||||
child = child.jjtGetChild(1);
|
||||
}
|
||||
child = skipAnnotations(child);
|
||||
}
|
||||
if (child.equals(node)) {
|
||||
break;
|
||||
@ -80,4 +76,21 @@ public class FieldDeclarationsShouldBeAtStartOfClassRule extends AbstractJavaRul
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore all annotations, until anything, that is not an annotation and
|
||||
* return this node
|
||||
* @param child the node from where to start the search
|
||||
* @return the first child or the first child after annotations
|
||||
*/
|
||||
private Node skipAnnotations(Node child) {
|
||||
Node nextChild = child.jjtGetChild(0);
|
||||
for (int j = 0; j < child.jjtGetNumChildren(); j++) {
|
||||
if (!(child.jjtGetChild(j) instanceof ASTAnnotation)) {
|
||||
nextChild = child.jjtGetChild(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return nextChild;
|
||||
}
|
||||
}
|
||||
|
@ -170,6 +170,30 @@ public class MyClass {
|
||||
public void myPublicBean() {}
|
||||
|
||||
private static void myPrivateStatic() {}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>#1364 FieldDeclarationsShouldBeAtStartOfClass false positive using multiple annotations</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class MyEntity {
|
||||
|
||||
private static final String MY_STRING = "STRING";
|
||||
|
||||
@Id
|
||||
@Column
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@ManyToOne
|
||||
@JoinColumn
|
||||
@Valid
|
||||
private RelationEntity relation;
|
||||
|
||||
public MyEntity() {
|
||||
}
|
||||
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
@ -12,4 +12,6 @@
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* [#1364](https://sourceforge.net/p/pmd/bugs/1364/): FieldDeclarationsShouldBeAtStartOfClass false positive using multiple annotations
|
||||
|
||||
**API Changes:**
|
||||
|
Reference in New Issue
Block a user