Example usage for org.eclipse.jdt.core.dom ImportDeclaration isOnDemand

List of usage examples for org.eclipse.jdt.core.dom ImportDeclaration isOnDemand

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom ImportDeclaration isOnDemand.

Prototype

public boolean isOnDemand() 

Source Link

Document

Returns whether this import declaration is an on-demand or a single-type import.

Usage

From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java

License:Open Source License

@Override
public boolean visit(ImportDeclaration node) {
    this.fBuffer.append("import ");//$NON-NLS-1$
    if (node.getAST().apiLevel() >= JLS3) {
        if (node.isStatic()) {
            this.fBuffer.append("static ");//$NON-NLS-1$
        }//from w  ww  .ja v  a  2s .  c o  m
    }
    node.getName().accept(this);
    if (node.isOnDemand()) {
        this.fBuffer.append(".*");//$NON-NLS-1$
    }
    this.fBuffer.append(";");//$NON-NLS-1$
    return false;
}

From source file:boa.datagen.util.Java7Visitor.java

License:Apache License

@Override
public boolean visit(CompilationUnit node) {
    //      b.setPosition(pos.build());
    PackageDeclaration pkg = node.getPackage();
    if (pkg == null) {
        b.setName("");
    } else {/*from   w  w  w.j ava2s .c  o m*/
        b.setName(pkg.getName().getFullyQualifiedName());
        for (Object a : pkg.annotations()) {
            ((Annotation) a).accept(this);
            b.addModifiers(modifiers.pop());
        }
    }
    for (Object i : node.imports()) {
        ImportDeclaration id = (ImportDeclaration) i;
        String imp = "";
        if (id.isStatic())
            imp += "static ";
        imp += id.getName().getFullyQualifiedName();
        if (id.isOnDemand())
            imp += ".*";
        imports.add(imp);
    }
    for (Object t : node.types()) {
        declarations.push(new ArrayList<boa.types.Ast.Declaration>());
        ((AbstractTypeDeclaration) t).accept(this);
        for (boa.types.Ast.Declaration d : declarations.pop())
            b.addDeclarations(d);
    }
    for (Object c : node.getCommentList())
        ((org.eclipse.jdt.core.dom.Comment) c).accept(this);
    return false;
}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(ImportDeclaration node) {
    printIndent();//  w  ww  . jav  a2  s.  com
    this.buffer.append("import ");//$NON-NLS-1$
    if (node.getAST().apiLevel() >= AST.JLS3) {
        if (node.isStatic()) {
            this.buffer.append("static ");//$NON-NLS-1$
        }
    }
    node.getName().accept(this);
    if (node.isOnDemand()) {
        this.buffer.append(".*");//$NON-NLS-1$
    }
    this.buffer.append(";\n");//$NON-NLS-1$
    return false;
}

From source file:com.google.gdt.eclipse.appengine.rpc.util.CompilationUnitCreator.java

License:Open Source License

@SuppressWarnings("unchecked")
private void removeUnusedImports(ICompilationUnit cu, Set<String> existingImports, boolean needsSave)
        throws CoreException {
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(cu);//from   ww w.  ja  v  a2s.  c om
    parser.setResolveBindings(true);

    CompilationUnit root = (CompilationUnit) parser.createAST(null);
    if (root.getProblems().length == 0) {
        return;
    }

    List<ImportDeclaration> importsDecls = root.imports();
    if (importsDecls.isEmpty()) {
        return;
    }
    ImportsManager imports = new ImportsManager(root);

    int importsEnd = ASTNodes.getExclusiveEnd((ASTNode) importsDecls.get(importsDecls.size() - 1));
    IProblem[] problems = root.getProblems();
    for (int i = 0; i < problems.length; i++) {
        IProblem curr = problems[i];
        if (curr.getSourceEnd() < importsEnd) {
            int id = curr.getID();
            if (id == IProblem.UnusedImport || id == IProblem.NotVisibleType) {
                int pos = curr.getSourceStart();
                for (int k = 0; k < importsDecls.size(); k++) {
                    ImportDeclaration decl = importsDecls.get(k);
                    if (decl.getStartPosition() <= pos && pos < decl.getStartPosition() + decl.getLength()) {
                        if (existingImports.isEmpty() || !existingImports.contains(ASTNodes.asString(decl))) {
                            String name = decl.getName().getFullyQualifiedName();
                            if (decl.isOnDemand()) {
                                name += ".*"; //$NON-NLS-1$
                            }
                            if (decl.isStatic()) {
                                imports.removeStaticImport(name);
                            } else {
                                imports.removeImport(name);
                            }
                        }
                        break;
                    }
                }
            }
        }
    }
    imports.create(needsSave, null);
}

From source file:com.google.gdt.eclipse.appengine.rpc.wizards.helpers.RpcServiceLayerCreator.java

License:Open Source License

@SuppressWarnings("unchecked")
private void removeUnusedImports(ICompilationUnit cu, Set<String> existingImports, boolean needsSave)
        throws CoreException {
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(cu);//from  w w  w  .  ja  v a  2s.  c o  m
    parser.setResolveBindings(true);

    CompilationUnit root = (CompilationUnit) parser.createAST(null);
    if (root.getProblems().length == 0) {
        return;
    }

    List<ImportDeclaration> importsDecls = root.imports();
    if (importsDecls.isEmpty()) {
        return;
    }
    ImportsManager imports = new ImportsManager(root);

    int importsEnd = ASTNodes.getExclusiveEnd(importsDecls.get(importsDecls.size() - 1));
    IProblem[] problems = root.getProblems();
    for (int i = 0; i < problems.length; i++) {
        IProblem curr = problems[i];
        if (curr.getSourceEnd() < importsEnd) {
            int id = curr.getID();
            if (id == IProblem.UnusedImport || id == IProblem.NotVisibleType) {
                int pos = curr.getSourceStart();
                for (int k = 0; k < importsDecls.size(); k++) {
                    ImportDeclaration decl = importsDecls.get(k);
                    if (decl.getStartPosition() <= pos && pos < decl.getStartPosition() + decl.getLength()) {
                        if (existingImports.isEmpty() || !existingImports.contains(ASTNodes.asString(decl))) {
                            String name = decl.getName().getFullyQualifiedName();
                            if (decl.isOnDemand()) {
                                name += ".*"; //$NON-NLS-1$
                            }
                            if (decl.isStatic()) {
                                imports.removeStaticImport(name);
                            } else {
                                imports.removeImport(name);
                            }
                        }
                        break;
                    }
                }
            }
        }
    }
    imports.create(needsSave, null);
}

From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java

License:Apache License

/** Visitor method for {@link ImportDeclaration}s. */
@Override/*from www  . j  a  va 2  s  .c o m*/
public boolean visit(ImportDeclaration node) {
    sync(node);
    token("import");
    builder.space();
    if (node.isStatic()) {
        token("static");
        builder.space();
    }
    visitName(node.getName(), BreakOrNot.NO);
    if (node.isOnDemand()) {
        token(".");
        token("*");
    }
    token(";");
    return false;
}

From source file:com.intel.ide.eclipse.mpt.ast.UnresolvedElementsSubProcessor.java

License:Open Source License

public static void importNotFoundProposals(IInvocationContext context, IProblemLocation problem,
        Map<String, LinkedCorrectionProposal> proposals) throws CoreException {
    ICompilationUnit cu = context.getCompilationUnit();

    ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
    if (selectedNode == null) {
        return;//  w  w  w .j  a va  2 s  .  co m
    }
    ImportDeclaration importDeclaration = (ImportDeclaration) ASTNodes.getParent(selectedNode,
            ASTNode.IMPORT_DECLARATION);
    if (importDeclaration == null) {
        return;
    }
    if (!importDeclaration.isOnDemand()) {
        Name name = importDeclaration.getName();
        if (importDeclaration.isStatic() && name.isQualifiedName()) {
            name = ((QualifiedName) name).getQualifier();
        }
        int kind = JavaModelUtil.is50OrHigher(cu.getJavaProject()) ? SimilarElementsRequestor.REF_TYPES
                : SimilarElementsRequestor.CLASSES | SimilarElementsRequestor.INTERFACES;
        UnresolvedElementsSubProcessor.addNewTypeProposals(cu, name, kind,
                IProposalRelevance.IMPORT_NOT_FOUND_NEW_TYPE, proposals);
    }
}

From source file:com.windowtester.eclipse.ui.convert.rule.WTExpandImportsRule.java

License:Open Source License

/**
 * Expand any on demand imports of WindowTester packages.
 *//*from   w  w  w  .  j ava 2 s. c o m*/
public boolean visit(ImportDeclaration node) {
    String fullyQualifiedName = node.getName().getFullyQualifiedName();
    if (!node.isOnDemand() || !packageToExpand.equals(fullyQualifiedName))
        return false;
    if (node.isStatic()) {
        // TODO [Dan] Expand static imports?
    } else {
        context.expandImport(node);
    }
    return false;
}

From source file:com.windowtester.eclipse.ui.convert.rule.WTReplaceTypeRule.java

License:Open Source License

public boolean visit(ImportDeclaration node) {
    String typeName = node.getName().getFullyQualifiedName();
    if (node.isStatic()) {
        if (node.isOnDemand()) {
            if (oldTypeName.equals(typeName))
                context.replaceImport(node, newTypeName);
        } else {//from w  ww .  j  a  v  a  2  s  . com
            String methodName = WTAPIUtil.simpleTypeName(typeName);
            typeName = WTAPIUtil.packageNameForType(typeName);
            if (oldTypeName.equals(typeName)) {
                context.replaceImport(node, newTypeName + "." + methodName);
            }
        }
    } else {
        if (node.isOnDemand()) {
            // Nothing to do
        } else {
            if (oldTypeName.equals(typeName)) {
                if (replacedImport) {
                    context.removeImport(node);
                } else {
                    context.replaceImport(node, newTypeName);
                    replacedImport = true;
                }
            } else if (newTypeName.equals(typeName)) {
                if (replacedImport) {
                    context.removeImport(node);
                } else {
                    replacedImport = true;
                }
            }
        }
    }
    return false;
}

From source file:com.windowtester.eclipse.ui.convert.WTAPIUsageVisitor.java

License:Open Source License

/**
 * Record any referenced WindowTester classes
 *//*w w  w .  j  a  va 2s .c  o m*/
public void endVisit(ImportDeclaration node) {
    super.endVisit(node);
    if (node.isStatic()) {
        String typeName = node.getName().getFullyQualifiedName();
        String methodName = "*";
        if (!node.isOnDemand()) {
            methodName = WTAPIUtil.simpleTypeName(typeName);
            typeName = WTAPIUtil.packageNameForType(typeName);
        }
        if (context.isWTType(typeName))
            apiUsed(typeName + "#" + methodName);
    }
}