Skip to content

Commit

Permalink
Merge branch 'patch-1' of https://github.com/SUPERCILEX/pmd into issu…
Browse files Browse the repository at this point in the history
…e-345
  • Loading branch information
adangel committed May 1, 2017
2 parents 72dc0ab + fa1e54f commit f60419c
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class FieldDeclarationsShouldBeAtStartOfClassRule extends AbstractJavaRul
"Ignore Enum Declarations that precede fields.", true, 1.0f);
private BooleanProperty ignoreAnonymousClassDeclarations = new BooleanProperty("ignoreAnonymousClassDeclarations",
"Ignore Field Declarations, that are initialized with anonymous class declarations", true, 2.0f);
private BooleanProperty ignoreInterfaceDeclarations = new BooleanProperty("ignoreInterfaceDeclarations",
"Ignore Interface Declarations that precede fields.", false, 3.0f);

/**
* Initializes the rule {@link FieldDeclarationsShouldBeAtStartOfClassRule}.
Expand Down Expand Up @@ -67,11 +69,20 @@ public Object visit(ASTFieldDeclaration node, Object data) {
&& getProperty(ignoreAnonymousClassDeclarations).booleanValue()) {
continue;
}
if (child instanceof ASTClassOrInterfaceDeclaration || child instanceof ASTMethodDeclaration
|| child instanceof ASTConstructorDeclaration || child instanceof ASTAnnotationTypeDeclaration) {
if (child instanceof ASTMethodDeclaration || child instanceof ASTConstructorDeclaration
|| child instanceof ASTAnnotationTypeDeclaration) {
addViolation(data, node);
break;
}
if (child instanceof ASTClassOrInterfaceDeclaration) {
ASTClassOrInterfaceDeclaration declaration = (ASTClassOrInterfaceDeclaration) child;
if (declaration.isInterface() && getProperty(ignoreInterfaceDeclarations).booleanValue()) {
continue;
} else {
addViolation(data, node);
break;
}
}
if (child instanceof ASTEnumDeclaration && !getProperty(ignoreEnumDeclarations).booleanValue()) {
addViolation(data, node);
break;
Expand Down

0 comments on commit f60419c

Please sign in to comment.