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

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

Introduction

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

Prototype

public final AST getAST() 

Source Link

Document

Returns this node's AST.

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  w  w.ja v  a2 s  . 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:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(ImportDeclaration node) {
    printIndent();//from w w  w .ja v a  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:lang.java.jdt.internal.JdtAstToRascalAstConverter.java

License:Open Source License

public boolean visit(ImportDeclaration node) {
    IValue name = values.string(node.getName().getFullyQualifiedName());

    IValue staticImport = values.bool(false);
    if (node.getAST().apiLevel() >= AST.JLS3) {
        staticImport = values.bool(node.isStatic());
    }/*w w  w. j  ava  2 s  . c om*/
    IValue onDemand = values.bool(node.isOnDemand());

    ownValue = constructRascalNode(node, name, staticImport, onDemand);
    return false;
}

From source file:org.codemucker.jmutate.ast.JAstFlattener.java

License:Open Source License

public boolean visit(ImportDeclaration node) {
    printIndent();/*  w w w. j av a2s  . c  o  m*/
    this.buffer.append("import ");//$NON-NLS-1$
    if (node.getAST().apiLevel() >= 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:org.spoofax.interpreter.adapter.ecj.ECJFactory.java

License:LGPL

private ImportDeclaration asImportDeclaration(IStrategoTerm term) {
    ImportDeclaration x = ((WrappedImportDeclaration) term).getWrappee();
    return x.getParent() == null && x.getAST() == ast ? x : (ImportDeclaration) ASTNode.copySubtree(ast, x);
}

From source file:org.spoofax.interpreter.library.ecj.ECJ_rewrite_file.java

License:LGPL

@SuppressWarnings("unchecked")
@Override/*from w  w  w.  j a  v a  2s. c  o  m*/
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {

    if (!ECJTools.isIFile(tvars[0]))
        return false;

    final IFile file = ECJTools.asIFile(tvars[0]);
    final ICompilationUnit cu = JavaCore.createCompilationUnitFrom(file);
    final ECJLibrary ecj = (ECJLibrary) env.getOperatorRegistry(ECJLibrary.REGISTRY_NAME);
    final ECJFactory factory = (ECJFactory) env.getFactory();

    AST oldAST = factory.getAST();

    ecj.setCurrentProject(cu.getJavaProject().getProject());
    ecj.setCurrentJavaProject(cu.getJavaProject());

    try {
        final IBuffer buffer = cu.getBuffer();
        final boolean previouslyModified = buffer.hasUnsavedChanges();

        Document document = new Document(buffer.getContents());
        ASTParser p = ecj.getParser();
        p.setSource(cu);
        CompilationUnit root = (CompilationUnit) p.createAST(null);
        factory.setAST(root.getAST());

        //System.out.println("before: " + root);
        root.recordModifications();
        @SuppressWarnings("rawtypes")
        List newTds = new ArrayList();
        for (Object ob : root.types()) {
            TypeDeclaration td = (TypeDeclaration) ob;

            CallT s = (CallT) svars[0];
            env.setCurrent(ECJFactory.wrap(td));
            if (s.evaluate(env)) {
                final IStrategoTerm term = env.current();
                if (term instanceof WrappedASTNode)
                    newTds.add(((WrappedASTNode) term).getWrappee());
                else
                    ecj.log("Rewriting types resulted in an invalid tree");
            } else {
                newTds.add(td);
            }
        }
        root.types().clear();
        root.types().addAll(newTds);

        @SuppressWarnings("rawtypes")
        List newImports = new ArrayList();
        env.setCurrent(ECJFactory.wrap(root.imports()));
        CallT s = (CallT) svars[1];
        if (s.evaluate(env)) {
            final IStrategoTerm term = env.current();
            if (term instanceof IStrategoList) {
                for (IStrategoTerm t : ((IStrategoList) term).getAllSubterms()) {
                    if (t instanceof WrappedImportDeclaration) {
                        ImportDeclaration id = ((WrappedImportDeclaration) t).getWrappee();
                        // FIXME should this be handled elsewhere?
                        if (id.getAST() != root.getAST()) {
                            id = (ImportDeclaration) ASTNode.copySubtree(root.getAST(), id);
                        }
                        newImports.add(id);
                    } else {
                        ecj.log("Rewriting import did not give an ImportDeclaration");
                    }
                }
            } else {
                ecj.log("Rewriting imports did not give a list");
            }
        }
        root.imports().clear();
        root.imports().addAll(newImports);

        //System.out.println("after: " + root);
        TextEdit te = root.rewrite(document, cu.getJavaProject().getOptions(true));
        te.apply(document);
        cu.getBuffer().setContents(document.get());
        if (!previouslyModified)
            cu.getBuffer().save(null, false);
    } catch (JavaModelException e) {
        e.printStackTrace();
        ecj.log("Model exception");
    } catch (BadLocationException e) {
        e.printStackTrace();
        ecj.log("Bad location exception");
    }
    factory.setAST(oldAST);
    return true;
}

From source file:ptolemy.backtrack.eclipse.ast.ASTFormatter.java

License:Open Source License

/** Visit an ast node, and return whether its children should be further
 *  visited./*from  w w  w . j a  v  a 2s .com*/
 *
 *  @param node The AST node.
 *  @return Whether its children should be further visited.
 */
public boolean visit(ImportDeclaration node) {
    _output(_indent);
    _output("import ");

    if (node.getAST().apiLevel() >= AST.JLS3) {
        if (node.isStatic()) {
            _output("static ");
        }
    }

    node.getName().accept(this);

    if (node.isOnDemand()) {
        _output(".*");
    }

    _output(";\n");
    return false;
}