use of net.sourceforge.pmd.lang.java.ast.AccessNode in project pmd by pmd.
the class ConstructorCallsOverridableMethodRule method visit.
/**
* Create a MethodHolder to hold the method. Store the MethodHolder in the
* Map as the key Store each method called by the current method as a List
* in the Map as the Object
*/
@Override
public Object visit(ASTMethodDeclarator node, Object data) {
if (!(getCurrentEvalPackage() instanceof NullEvalPackage)) {
// only evaluate if we have an eval package for this class
AccessNode parent = (AccessNode) node.jjtGetParent();
MethodHolder h = new MethodHolder(node);
if (!parent.isAbstract() && !parent.isPrivate() && !parent.isStatic() && !parent.isFinal()) {
// Skip abstract methods, have a separate rule for that
// this method is overridable
h.setDangerous();
ASTMethodDeclaration decl = node.getFirstParentOfType(ASTMethodDeclaration.class);
h.setCalledMethod(decl.getMethodName());
}
List<MethodInvocation> l = new ArrayList<>();
addCalledMethodsOfNode(parent, l, getCurrentEvalPackage().className);
getCurrentEvalPackage().allMethodsOfClass.put(h, l);
}
return super.visit(node, data);
}
use of net.sourceforge.pmd.lang.java.ast.AccessNode in project pmd by pmd.
the class AssignmentToNonFinalStaticRule method visit.
public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
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 = (AccessNode) decl.getAccessNodeParent();
if (!accessNodeParent.isStatic() || accessNodeParent.isFinal()) {
continue;
}
if (initializedInConstructor(entry.getValue())) {
addViolation(data, decl.getNode(), decl.getImage());
}
}
return super.visit(node, data);
}
Aggregations