Example usage for org.eclipse.jdt.core.dom Statement accept

List of usage examples for org.eclipse.jdt.core.dom Statement accept

Introduction

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

Prototype

public final void accept(ASTVisitor visitor) 

Source Link

Document

Accepts the given visitor on a visit of the current node.

Usage

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

License:Open Source License

@Override
public boolean visit(Block node) {
    this.fBuffer.append("{");//$NON-NLS-1$
    for (Iterator<Statement> it = node.statements().iterator(); it.hasNext();) {
        Statement s = it.next();
        s.accept(this);
    }//from  w  w  w .  j  a v  a 2s .com
    this.fBuffer.append("}");//$NON-NLS-1$
    return false;
}

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

License:Open Source License

@Override
public boolean visit(SwitchStatement node) {
    this.fBuffer.append("switch (");//$NON-NLS-1$
    node.getExpression().accept(this);
    this.fBuffer.append(") ");//$NON-NLS-1$
    this.fBuffer.append("{");//$NON-NLS-1$
    for (Iterator<Statement> it = node.statements().iterator(); it.hasNext();) {
        Statement s = it.next();
        s.accept(this);
    }//from w  ww .jav a 2  s  .c  o  m
    this.fBuffer.append("}");//$NON-NLS-1$
    return false;
}

From source file:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java

License:Open Source License

@Override
public boolean visit(IfStatement node) {
    String expression = node.getExpression().toString();
    pushNode(node, expression/* , node.getStartPosition(), node.getLength() */);

    Statement stmt = node.getThenStatement();
    if (stmt != null) {
        pushNode(stmt, expression);//from w  w  w.j a va  2s .co  m
        stmt.accept(this);
        popNode();
    }

    stmt = node.getElseStatement();
    if (stmt != null) {
        pushNode(stmt, expression);
        node.getElseStatement().accept(this);
        popNode();
    }
    return false;
}

From source file:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override// w w  w . j  a  va 2  s  .c om
public boolean visit(TryStatement node) {
    pushNode(node, "");

    Statement stmt = node.getBody();
    pushNode(stmt, "");
    stmt.accept(this);
    popNode();

    visitListAsNode(EntityType.CATCH_CLAUSES, node.catchClauses());

    stmt = node.getFinally();
    if (stmt != null) {
        // @Inria
        pushNode(stmt, "");
        stmt.accept(this);
        popNode();
    }
    return false;
}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(Block node) {
    this.buffer.append("{\n");//$NON-NLS-1$
    this.indent++;
    for (Iterator it = node.statements().iterator(); it.hasNext();) {
        Statement s = (Statement) it.next();
        s.accept(this);
    }//from  w  w  w .j a v  a  2s .  c o m
    this.indent--;
    printIndent();
    this.buffer.append("}\n");//$NON-NLS-1$
    return false;
}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(SwitchStatement node) {
    this.buffer.append("switch (");//$NON-NLS-1$
    node.getExpression().accept(this);
    this.buffer.append(") ");//$NON-NLS-1$
    this.buffer.append("{\n");//$NON-NLS-1$
    this.indent++;
    for (Iterator it = node.statements().iterator(); it.hasNext();) {
        Statement s = (Statement) it.next();
        s.accept(this);
        this.indent--; // incremented in visit(SwitchCase)
    }// w w  w  .ja  va  2s. c  o  m
    this.indent--;
    printIndent();
    this.buffer.append("}\n");//$NON-NLS-1$
    return false;
}

From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java

License:Open Source License

private void printStatements(List<?> statements) {
    for (Iterator<?> it = statements.iterator(); it.hasNext();) {
        Statement s = (Statement) it.next();
        buffer.syncLineNumbers(s);/*from ww  w  . j a va  2 s. c  o m*/
        s.accept(this);
    }
}

From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java

License:Open Source License

@Override
public boolean visit(EnhancedForStatement node) {
    SingleVariableDeclaration var = node.getParameter();
    boolean emitAutoreleasePool = Types.hasAutoreleasePoolAnnotation(Types.getBinding(var));
    String varName = NameTable.getName(var.getName());
    if (NameTable.isReservedName(varName)) {
        varName += "__";
        NameTable.rename(Types.getBinding(var.getName()), varName);
    }//from  www . j  ava  2s  .c o  m
    String arrayExpr = generate(node.getExpression(), fieldHiders, asFunction, buffer.getCurrentLine());
    ITypeBinding arrayType = Types.getTypeBinding(node.getExpression());
    if (arrayType.isArray()) {
        buffer.append("{\nint n__ = [");
        buffer.append(arrayExpr);
        buffer.append(" count];\n");
        buffer.append("for (int i__ = 0; i__ < n__; i__++) {\n");
        if (emitAutoreleasePool) {
            buffer.append("NSAutoreleasePool *pool__ = [[NSAutoreleasePool alloc] init];\n");
        }
        buffer.append(NameTable.javaRefToCpp(var.getType()));
        buffer.append(' ');
        buffer.append(varName);
        buffer.append(" = [");
        buffer.append(arrayExpr);
        buffer.append(' ');
        if (arrayType.getComponentType().isPrimitive()) {
            buffer.append(var.getType().toString());
        } else {
            buffer.append("object");
        }
        buffer.append("AtIndex:i__];\n");
        Statement body = node.getBody();
        if (body instanceof Block) {
            // strip surrounding braces
            printStatements(((Block) body).statements());
        } else {
            body.accept(this);
        }
        if (emitAutoreleasePool) {
            buffer.append("[pool__ release];\n");
        }
        buffer.append("}\n}\n");
    } else {
        // var must be an instance of an Iterable class.
        String objcType = NameTable.javaRefToCpp(var.getType());
        buffer.append("{\nid<JavaLangIterable> array__ = (id<JavaLangIterable>) ");
        buffer.append(arrayExpr);
        buffer.append(";\n");
        buffer.append("if (!array__) {\n");
        if (useReferenceCounting) {
            buffer.append("@throw [[[JavaLangNullPointerException alloc] init] autorelease];\n}\n");
        } else {
            buffer.append("@throw [[JavaLangNullPointerException alloc] init];\n}\n");
        }
        buffer.append("id<JavaUtilIterator> iter__ = [array__ iterator];\n");
        buffer.append("while ([iter__ hasNext]) {\n");
        if (emitAutoreleasePool) {
            buffer.append("NSAutoreleasePool *pool__ = [[NSAutoreleasePool alloc] init];\n");
        }
        buffer.append(objcType);
        buffer.append(' ');
        buffer.append(varName);
        buffer.append(" = (");
        buffer.append(objcType);
        buffer.append(") [iter__ next];\n");
        Statement body = node.getBody();
        if (body instanceof Block) {
            // strip surrounding braces
            printStatements(((Block) body).statements());
        } else {
            body.accept(this);
        }
        if (emitAutoreleasePool) {
            buffer.append("[pool__ release];\n");
        }
        buffer.append("}\n}\n");
    }
    return false;
}

From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from  w  ww  .  j  a v a 2 s . c o  m*/
public boolean visit(SwitchStatement node) {
    buffer.append("switch (");
    Expression expr = node.getExpression();
    ITypeBinding exprType = Types.getTypeBinding(expr);
    if (exprType.isEnum()) {
        buffer.append('[');
    }
    expr.accept(this);
    if (exprType.isEnum()) {
        buffer.append(" ordinal]");
    }
    buffer.append(") ");
    buffer.append("{\n");
    List<Statement> stmts = node.statements(); // safe by definition
    boolean needsClosingBrace = false;
    int nStatements = stmts.size();
    for (int i = 0; i < nStatements; i++) {
        Statement stmt = stmts.get(i);
        buffer.syncLineNumbers(stmt);
        if (stmt instanceof SwitchCase) {
            if (needsClosingBrace) {
                buffer.append("}\n");
                needsClosingBrace = false;
            }
            stmt.accept(this);
            if (declaresLocalVar(stmts, i + 1)) {
                buffer.append(" {\n");
                needsClosingBrace = true;
            } else {
                buffer.append('\n');
            }
        } else {
            stmt.accept(this);
        }
    }
    if (!stmts.isEmpty() && stmts.get(nStatements - 1) instanceof SwitchCase) {
        // Last switch case doesn't have an associated statement, so add
        // an empty one.
        buffer.append(";\n");
    }
    if (needsClosingBrace) {
        buffer.append("}\n");
    }
    buffer.append("}\n");
    return false;
}

From source file:com.google.devtools.j2cpp.translate.AnonymousClassConverter.java

License:Open Source License

private void getMethodVars(MethodDeclaration method, ASTNode node, final Set<IVariableBinding> methodVars) {
    @SuppressWarnings("unchecked")
    List<Statement> statements = method.getBody().statements(); // safe by definition
    Statement enclosingStatement = getEnclosingStatement(node);
    for (Statement stmt : statements) {
        if (stmt == enclosingStatement) {
            // Local variables declared after this statement cannot be
            // referenced by the anonymous class.
            break;
        }//  w w  w .j  a va 2  s.c o m
        stmt.accept(new ASTVisitor() {
            @Override
            public boolean visit(VariableDeclarationStatement node) {
                if (Modifier.isFinal(node.getModifiers())) {
                    @SuppressWarnings("unchecked") // safe by definition
                    List<VariableDeclarationFragment> localVars = node.fragments();
                    for (VariableDeclarationFragment localVar : localVars) {
                        IVariableBinding var = Types.getVariableBinding(localVar);
                        assert var != null;
                        methodVars.add(var);
                    }
                }
                return true;
            }

            @Override
            public boolean visit(SingleVariableDeclaration node) {
                IVariableBinding var = Types.getVariableBinding(node);
                assert var != null;
                if (Modifier.isFinal(var.getModifiers())) {
                    methodVars.add(var);
                }
                return true;
            }

            @Override
            public boolean visit(AnonymousClassDeclaration node) {
                return false;
            }
        });
    }
}