Search in sources :

Example 1 with Annotatable

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

the class UnusedPrivateFieldRule method visit.

@Override
public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
    boolean classHasLombok = hasLombokAnnotation(node);
    Map<VariableNameDeclaration, List<NameOccurrence>> vars = node.getScope().getDeclarations(VariableNameDeclaration.class);
    for (Map.Entry<VariableNameDeclaration, List<NameOccurrence>> entry : vars.entrySet()) {
        VariableNameDeclaration decl = entry.getKey();
        AccessNode accessNodeParent = decl.getAccessNodeParent();
        if (!accessNodeParent.isPrivate() || isOK(decl.getImage()) || classHasLombok || hasIgnoredAnnotation((Annotatable) accessNodeParent)) {
            continue;
        }
        if (!actuallyUsed(entry.getValue())) {
            if (!usedInOuterClass(node, decl) && !usedInOuterEnum(node, decl)) {
                addViolation(data, decl.getNode(), decl.getImage());
            }
        }
    }
    return super.visit(node, data);
}
Also used : Annotatable(net.sourceforge.pmd.lang.java.ast.Annotatable) VariableNameDeclaration(net.sourceforge.pmd.lang.java.symboltable.VariableNameDeclaration) ArrayList(java.util.ArrayList) List(java.util.List) AccessNode(net.sourceforge.pmd.lang.java.ast.AccessNode) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 AccessNode (net.sourceforge.pmd.lang.java.ast.AccessNode)1 Annotatable (net.sourceforge.pmd.lang.java.ast.Annotatable)1 VariableNameDeclaration (net.sourceforge.pmd.lang.java.symboltable.VariableNameDeclaration)1