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

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

Introduction

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

Prototype

public Name getName() 

Source Link

Document

Returns the name imported by this declaration.

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$
        }/* w  ww . j  a  va 2 s .co 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 {// www  .j  av a2  s. co  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:br.com.objectos.way.core.code.jdt.ImportDeclarationWrapper.java

License:Apache License

private ImportDeclarationWrapper(ImportDeclaration ast) {
    this.ast = ast;
    Name name = ast.getName();
    this.name = QualifiedName.class.cast(name);
}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(ImportDeclaration node) {
    printIndent();/*  w w  w .j a va  2  s  . co m*/
    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.crispico.flower.mp.metamodel.codesyncjava.algorithm.forward.ForwardJavaSrcDir_Files.java

License:Open Source License

/**
 * @throws CodeSyncException //from   ww w .j av  a 2s  . c  om
 * @flowerModelElementId _IEIN9erfEd6QaI9daHlzjA
 */
@SuppressWarnings("unchecked")
@Override
protected ReverseStatus forwardElement(Type modelElement, IContainer parentAstElement,
        CompilationUnit astElement) throws CodeSyncException {
    try {
        astElement.recordModifications();
    } catch (IllegalArgumentException e) {
        //it is ok, we swallow ,recordModification had been called already on creation of compilation unit 
    }
    // TODO :: should update only when something specific happens? moving in another package,renaming the package,moving the package?
    // this updates the package declaration
    AST ast = astElement.getAST();
    PackageDeclaration packageDeclaration = astElement.getPackage();
    if (packageDeclaration == null) {
        String fullyPackageName = SyncUtils.getFullyQualifiedPackageNameFromType(modelElement);
        // a java type in the default package can not have the package declaration
        if (fullyPackageName.length() > 0) {
            packageDeclaration = ast.newPackageDeclaration();
            astElement.setPackage(packageDeclaration);
            packageDeclaration.setName(ast.newName(fullyPackageName));
        }
    }

    // creating the list 
    HashSet<String> fullyQualifiedImports = new HashSet<String>();
    for (ImportDeclaration importDeclaration : (List<ImportDeclaration>) astElement.imports())
        fullyQualifiedImports.add(importDeclaration.getName().getFullyQualifiedName());
    setContextForImportDeclarations(astElement, fullyQualifiedImports, modelElement.getNearestPackage());

    ReverseStatus status = new ReverseStatus();
    if (modelElement instanceof Interface) {
        forwardJavaInterface.setParentPackage(parentAstElement);
        status.applyOr(forwardJavaInterface.forward((Interface) modelElement, astElement));
    } else if (modelElement instanceof Class) {
        forwardJavaClass.setParentPackage(parentAstElement);
        status.applyOr(forwardJavaClass.forward((Class) modelElement, astElement));
    } else
        throw new IllegalArgumentException("could not recognize instance of " + modelElement);

    IFile javaFile = (IFile) parentAstElement.getFile(new Path(modelElement.getName() + ".java"));

    try {
        JavaSyncUtils.writeJavafile(astElement, javaFile);
        codeSyncAlgorithm.addLogEntry(javaFile.getFullPath().toString() + " - file modified");
        ((TimeStampedSyncElement) modelElement).setSyncTimeStamp(Long.toString(javaFile.getLocalTimeStamp()));
    } catch (Exception e) {
        throw new RuntimeException("Error during file save: " + javaFile, e);
    }
    return status;
}

From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.reverse.ReversePackage_JavaTypes.java

License:Open Source License

/**
 * @throws CodeSyncException //from   w w  w.  ja  va 2 s.  c  o  m
 * @flowerModelElementId _IFwlserfEd6QaI9daHlzjA
 */
@SuppressWarnings("unchecked")
@Override
protected ReverseStatus reverseElement(Type modelElement, FileAndAST<CompilationUnit> astElement)
        throws CodeSyncException {
    ReverseStatus status = new ReverseStatus();
    TypeDeclaration typeDeclaration = JavaSyncUtils.getMasterClass(astElement.getAstElement());

    getFullyQualifiedImports().clear();
    for (ImportDeclaration id : (List<ImportDeclaration>) astElement.getAstElement().imports()) {
        Name importedName = id.getName();
        SimpleName name;
        if (importedName.isQualifiedName()) {
            name = ((QualifiedName) importedName).getName();
        } else {
            name = (SimpleName) importedName;
        }
        getFullyQualifiedImports().put(name.toString(), importedName.getFullyQualifiedName());
    }

    if (typeDeclaration.isInterface()) {
        reverseJavaInterface.currentElement = modelElement;
        status.applyOr(reverseJavaInterface.reverse((Interface) modelElement, astElement.getAstElement()));
        reverseJavaInterface.currentElement = null;
    } else {
        reverseJavaClass.currentElement = modelElement;
        status.applyOr(reverseJavaClass.reverse((org.eclipse.uml2.uml.Class) modelElement,
                astElement.getAstElement()));
        reverseJavaClass.currentElement = null;
    }

    updateSynchronizationTimeStamp(modelElement, astElement);
    return status;
}

From source file:com.google.devtools.j2objc.jdt.JdtJ2ObjCIncompatibleStripper.java

License:Apache License

private JdtJ2ObjCIncompatibleStripper(CompilationUnit unit) {
    @SuppressWarnings("unchecked")
    List<ImportDeclaration> imports = unit.imports();
    for (ImportDeclaration importNode : imports) {
        String name = getLastComponent(importNode.getName());
        if (importNode.isStatic()) {
            unusedStaticImports.put(name, importNode);
        } else {//from  w  w  w  .  j a  v a2s.  c o m
            unusedImports.put(name, importNode);
        }
    }
}

From source file:com.google.devtools.j2objc.pipeline.J2ObjCIncompatibleStripper.java

License:Apache License

private J2ObjCIncompatibleStripper(CompilationUnit unit) {
    @SuppressWarnings("unchecked")
    List<ImportDeclaration> imports = unit.imports();
    for (ImportDeclaration importNode : imports) {
        String name = getLastComponent(importNode.getName());
        if (importNode.isStatic()) {
            unusedStaticImports.put(name, importNode);
        } else {//w ww  .jav a2 s .  c o  m
            unusedImports.put(name, importNode);
        }
    }
}

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);/*www  . ja v a  2s .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. j av a  2 s. co  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);
}