use of net.sourceforge.pmd.lang.java.ast.ASTPackageDeclaration in project pmd by pmd.
the class UnusedImportsRule method visit.
@Override
public Object visit(ASTCompilationUnit node, Object data) {
imports.clear();
super.visit(node, data);
visitComments(node);
/*
* special handling for Bug 2606609 : False "UnusedImports" positive in
* package-info.java package annotations are processed before the import
* clauses so they need to be examined again later on.
*/
if (node.jjtGetNumChildren() > 0 && node.jjtGetChild(0) instanceof ASTPackageDeclaration) {
visit((ASTPackageDeclaration) node.jjtGetChild(0), data);
}
for (ImportWrapper wrapper : imports) {
addViolation(data, wrapper.getNode(), wrapper.getFullName());
}
return data;
}
use of net.sourceforge.pmd.lang.java.ast.ASTPackageDeclaration in project pmd by pmd.
the class ScopeAndDeclarationFinder method createSourceFileScope.
/**
* Creates a new global scope for an AST node. The new scope is stored on
* the scope stack.
*
* @param node
* the AST node for which the scope has to be created.
*/
private void createSourceFileScope(ASTCompilationUnit node) {
// When we do full symbol resolution, we'll need to add a truly
// top-level GlobalScope.
SourceFileScope scope;
ASTPackageDeclaration n = node.getPackageDeclaration();
if (n != null) {
scope = new SourceFileScope(classLoader, n.jjtGetChild(0).getImage());
} else {
scope = new SourceFileScope(classLoader);
}
scope.configureImports(node.findChildrenOfType(ASTImportDeclaration.class));
scopes.push(scope);
node.setScope(scope);
}
Aggregations