Search in sources :

Example 1 with ASTAnnotationTypeDeclaration

use of net.sourceforge.pmd.lang.java.ast.ASTAnnotationTypeDeclaration in project pmd by pmd.

the class UnnecessaryModifierRule method visit.

public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
    if (node.isInterface() && node.isAbstract()) {
        // an abstract interface
        addViolation(data, node, getMessage());
    }
    if (!node.isNested()) {
        return data;
    }
    Node parent = node.jjtGetParent().jjtGetParent().jjtGetParent();
    boolean isParentInterfaceOrAnnotation = parent instanceof ASTAnnotationTypeDeclaration || parent instanceof ASTClassOrInterfaceDeclaration && ((ASTClassOrInterfaceDeclaration) parent).isInterface();
    // a public interface within an interface or annotation
    if (node.isInterface() && node.isPublic() && isParentInterfaceOrAnnotation) {
        addViolation(data, node, getMessage());
    }
    if (node.isInterface() && node.isStatic()) {
        // a static interface
        addViolation(data, node, getMessage());
    }
    // a public and/or static class within an interface or annotation
    if (!node.isInterface() && (node.isPublic() || node.isStatic()) && isParentInterfaceOrAnnotation) {
        addViolation(data, node, getMessage());
    }
    return data;
}
Also used : ASTClassOrInterfaceDeclaration(net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration) Node(net.sourceforge.pmd.lang.ast.Node) ASTAnnotationTypeDeclaration(net.sourceforge.pmd.lang.java.ast.ASTAnnotationTypeDeclaration)

Example 2 with ASTAnnotationTypeDeclaration

use of net.sourceforge.pmd.lang.java.ast.ASTAnnotationTypeDeclaration in project pmd by pmd.

the class UnnecessaryModifierRule method visit.

public Object visit(ASTAnnotationTypeDeclaration node, Object data) {
    if (node.isAbstract()) {
        // an abstract annotation
        addViolation(data, node, getMessage());
    }
    if (!node.isNested()) {
        return data;
    }
    Node parent = node.jjtGetParent().jjtGetParent().jjtGetParent();
    boolean isParentInterfaceOrAnnotation = parent instanceof ASTAnnotationTypeDeclaration || parent instanceof ASTClassOrInterfaceDeclaration && ((ASTClassOrInterfaceDeclaration) parent).isInterface();
    // a public annotation within an interface or annotation
    if (node.isPublic() && isParentInterfaceOrAnnotation) {
        addViolation(data, node, getMessage());
    }
    if (node.isStatic()) {
        // a static annotation
        addViolation(data, node, getMessage());
    }
    return data;
}
Also used : ASTClassOrInterfaceDeclaration(net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration) Node(net.sourceforge.pmd.lang.ast.Node) ASTAnnotationTypeDeclaration(net.sourceforge.pmd.lang.java.ast.ASTAnnotationTypeDeclaration)

Example 3 with ASTAnnotationTypeDeclaration

use of net.sourceforge.pmd.lang.java.ast.ASTAnnotationTypeDeclaration in project pmd by pmd.

the class VariableNamingConventionsRule method visit.

public Object visit(ASTFieldDeclaration node, Object data) {
    if (!checkMembers) {
        return data;
    }
    boolean isStatic = node.isStatic();
    boolean isFinal = node.isFinal();
    Node type = node.jjtGetParent().jjtGetParent().jjtGetParent();
    // Anything inside an annotation type is also static and final
    if (type instanceof ASTClassOrInterfaceDeclaration && ((ASTClassOrInterfaceDeclaration) type).isInterface() || type instanceof ASTAnnotationTypeDeclaration) {
        isStatic = true;
        isFinal = true;
    }
    return checkVariableDeclarators(node.isStatic() ? staticPrefixes : memberPrefixes, isStatic ? staticSuffixes : memberSuffixes, node, isStatic, isFinal, data);
}
Also used : ASTClassOrInterfaceDeclaration(net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration) Node(net.sourceforge.pmd.lang.ast.Node) ASTAnnotationTypeDeclaration(net.sourceforge.pmd.lang.java.ast.ASTAnnotationTypeDeclaration)

Aggregations

Node (net.sourceforge.pmd.lang.ast.Node)3 ASTAnnotationTypeDeclaration (net.sourceforge.pmd.lang.java.ast.ASTAnnotationTypeDeclaration)3 ASTClassOrInterfaceDeclaration (net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration)3