Search in sources :

Example 1 with ASTPackageDeclaration

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;
}
Also used : ImportWrapper(net.sourceforge.pmd.lang.rule.ImportWrapper) ASTPackageDeclaration(net.sourceforge.pmd.lang.java.ast.ASTPackageDeclaration)

Example 2 with ASTPackageDeclaration

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);
}
Also used : ASTImportDeclaration(net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration) ASTPackageDeclaration(net.sourceforge.pmd.lang.java.ast.ASTPackageDeclaration)

Aggregations

ASTPackageDeclaration (net.sourceforge.pmd.lang.java.ast.ASTPackageDeclaration)2 ASTImportDeclaration (net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration)1 ImportWrapper (net.sourceforge.pmd.lang.rule.ImportWrapper)1