Add property to ignore interfaces in FieldDeclarationsShouldBeAtStartOfClassRule

This commit is contained in:
Alex Saveau
2017-04-30 09:47:09 -07:00
committed by GitHub
parent 98e1cc128b
commit fa1e54f87f

View File

@ -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}.
@ -67,11 +69,20 @@ public class FieldDeclarationsShouldBeAtStartOfClassRule extends AbstractJavaRul
&& 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;