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);
}
Aggregations