use of net.sourceforge.pmd.lang.java.ast.JavaNode in project pmd by pmd.
the class ScopeAndDeclarationFinder method createClassScope.
/**
* Creates a new class scope for an AST node. The scope on top of the stack
* is set as the parent of the new scope, which is then also stored on the
* scope stack.
*
* @param node
* the AST node for which the scope has to be created.
* @throws java.util.EmptyStackException
* if the scope stack is empty.
*/
private void createClassScope(JavaNode node) {
Scope s = ((JavaNode) node.jjtGetParent()).getScope();
ClassNameDeclaration classNameDeclaration = new ClassNameDeclaration(node);
s.addDeclaration(classNameDeclaration);
if (node instanceof ASTClassOrInterfaceBody) {
addScope(new ClassScope(classNameDeclaration), node);
} else {
addScope(new ClassScope(node.getImage(), classNameDeclaration), node);
}
}
use of net.sourceforge.pmd.lang.java.ast.JavaNode in project pmd by pmd.
the class UnusedFormalParameterRule method check.
private void check(Node node, Object data) {
Node parent = node.jjtGetParent().jjtGetParent().jjtGetParent();
if (parent instanceof ASTClassOrInterfaceDeclaration && !((ASTClassOrInterfaceDeclaration) parent).isInterface()) {
Map<VariableNameDeclaration, List<NameOccurrence>> vars = ((JavaNode) node).getScope().getDeclarations(VariableNameDeclaration.class);
for (Map.Entry<VariableNameDeclaration, List<NameOccurrence>> entry : vars.entrySet()) {
VariableNameDeclaration nameDecl = entry.getKey();
if (actuallyUsed(nameDecl, entry.getValue())) {
continue;
}
addViolation(data, nameDecl.getNode(), new Object[] { node instanceof ASTMethodDeclaration ? "method" : "constructor", nameDecl.getImage() });
}
}
}
use of net.sourceforge.pmd.lang.java.ast.JavaNode in project pmd by pmd.
the class AbstractNcssCountRule method countNodeChildren.
/**
* Count the number of children of the given Java node. Adds one to count
* the node itself.
*
* @param node
* java node having children counted
* @param data
* node data
* @return count of the number of children of the node, plus one
*/
protected Integer countNodeChildren(Node node, Object data) {
Integer nodeCount = null;
int lineCount = 0;
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
nodeCount = (Integer) ((JavaNode) node.jjtGetChild(i)).jjtAccept(this, data);
lineCount += nodeCount.intValue();
}
return ++lineCount;
}
Aggregations