Example usage for org.eclipse.jdt.core.dom ForStatement getBody

List of usage examples for org.eclipse.jdt.core.dom ForStatement getBody

Introduction

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

Prototype

public Statement getBody() 

Source Link

Document

Returns the body of this for statement.

Usage

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

License:Open Source License

@Override
public boolean visit(ForStatement node) {
    this.fBuffer.append("for (");//$NON-NLS-1$
    for (Iterator<Expression> it = node.initializers().iterator(); it.hasNext();) {
        Expression e = it.next();
        e.accept(this);
    }//w w w .j a  v  a  2 s.com
    this.fBuffer.append("; ");//$NON-NLS-1$
    if (node.getExpression() != null) {
        node.getExpression().accept(this);
    }
    this.fBuffer.append("; ");//$NON-NLS-1$
    for (Iterator<Expression> it = node.updaters().iterator(); it.hasNext();) {
        Expression e = it.next();
        e.accept(this);
    }
    this.fBuffer.append(") ");//$NON-NLS-1$
    node.getBody().accept(this);
    return false;
}

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

License:Apache License

@Override
public boolean visit(ForStatement node) {
    boa.types.Ast.Statement.Builder b = boa.types.Ast.Statement.newBuilder();
    //      b.setPosition(pos.build());
    List<boa.types.Ast.Statement> list = statements.peek();
    b.setKind(boa.types.Ast.Statement.StatementKind.FOR);
    for (Object e : node.initializers()) {
        ((org.eclipse.jdt.core.dom.Expression) e).accept(this);
        b.addInitializations(expressions.pop());
    }//from  w  w w .  j a  va 2s . co  m
    for (Object e : node.updaters()) {
        ((org.eclipse.jdt.core.dom.Expression) e).accept(this);
        b.addUpdates(expressions.pop());
    }
    if (node.getExpression() != null) {
        node.getExpression().accept(this);
        b.setExpression(expressions.pop());
    }
    statements.push(new ArrayList<boa.types.Ast.Statement>());
    node.getBody().accept(this);
    for (boa.types.Ast.Statement s : statements.pop())
        b.addStatements(s);
    list.add(b.build());
    return false;
}

From source file:br.uff.ic.gems.resources.ast.Visitor.java

@Override
public boolean visit(ForStatement node) {
    int beginLine = cu.getLineNumber(node.getStartPosition());
    int endLine = cu.getLineNumber(node.getStartPosition() + node.getLength());
    int beginColumn = cu.getColumnNumber(node.getStartPosition());
    int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength());

    Statement body = node.getBody();
    if (body != null) {

        int beginLineBody = cu.getLineNumber(body.getStartPosition());
        int endLineBody = cu.getLineNumber(body.getStartPosition() + body.getLength());
        int beginColumnBody = cu.getColumnNumber(body.getStartPosition());
        int endColumnBody = cu.getColumnNumber(body.getStartPosition() + body.getLength());

        languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine,
                beginColumn, endColumn, beginLineBody, endLineBody, beginColumnBody, endColumnBody, null));
    } else {//from  w  ww  .j  av a  2  s  .c  om
        languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine,
                beginColumn, endColumn));
    }
    return true;
}

From source file:cc.kave.eclipse.commons.analysis.transformer.BodyVisitor.java

License:Apache License

@Override
public boolean visit(ForStatement stmt) {
    if (isTargetMatch(stmt, CompletionCase.EmptyCompletionBefore)) {
        body.add(getEmptyCompletionExpression());
    }//from w  w  w  .  j a v  a 2s . c om

    ForLoop forLoop = new ForLoop();
    body.add(forLoop);

    if (isTargetMatch(stmt, CompletionCase.InBody)) {
        forLoop.getBody().add(getEmptyCompletionExpression());
    }

    // TODO: Lsung finden...
    // VisitForStatement_Init(stmt.Initializer, forLoop.Init, body);
    // forLoop.Condition =
    // _exprVisitor.ToLoopHeaderExpression(stmt.Condition, body);
    //
    // foreach (var expr in stmt.IteratorExpressionsEnumerable)
    // {
    // expr.Accept(this, forLoop.getStep());
    // }

    if (stmt.getBody() != null) {
        stmt.getBody().accept(new BodyVisitor(nameGen, marker, forLoop.getBody()));
    }

    if (isTargetMatch(stmt, CompletionCase.EmptyCompletionAfter)) {
        body.add(getEmptyCompletionExpression());
    }
    return super.visit(stmt);
}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(ForStatement node) {
    printIndent();/*from w ww.  j a v a2 s .co m*/
    this.buffer.append("for (");//$NON-NLS-1$
    for (Iterator it = node.initializers().iterator(); it.hasNext();) {
        Expression e = (Expression) it.next();
        e.accept(this);
        if (it.hasNext())
            buffer.append(", ");//$NON-NLS-1$
    }
    this.buffer.append("; ");//$NON-NLS-1$
    if (node.getExpression() != null) {
        node.getExpression().accept(this);
    }
    this.buffer.append("; ");//$NON-NLS-1$
    for (Iterator it = node.updaters().iterator(); it.hasNext();) {
        Expression e = (Expression) it.next();
        e.accept(this);
        if (it.hasNext())
            buffer.append(", ");//$NON-NLS-1$
    }
    this.buffer.append(") ");//$NON-NLS-1$
    node.getBody().accept(this);
    return false;
}

From source file:com.bsiag.eclipse.jdt.java.formatter.LineBreaksPreparator.java

License:Open Source License

@Override
public boolean visit(ForStatement node) {
    handleLoopBody(node.getBody());
    return true;
}

From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java

License:Open Source License

@Override
public boolean visit(ForStatement node) {
    handleToken(node, TokenNameLPAREN, this.options.insert_space_before_opening_paren_in_for,
            this.options.insert_space_after_opening_paren_in_for);
    handleTokenBefore(node.getBody(), TokenNameRPAREN, this.options.insert_space_before_closing_paren_in_for,
            false);//  w  w w.j  a  v  a 2  s . c o m
    handleCommas(node.initializers(), this.options.insert_space_before_comma_in_for_inits,
            this.options.insert_space_after_comma_in_for_inits);
    handleCommas(node.updaters(), this.options.insert_space_before_comma_in_for_increments,
            this.options.insert_space_after_comma_in_for_increments);

    boolean part1Empty = node.initializers().isEmpty();
    boolean part2Empty = node.getExpression() == null;
    boolean part3Empty = node.updaters().isEmpty();
    handleToken(node, TokenNameSEMICOLON, this.options.insert_space_before_semicolon_in_for && !part1Empty,
            this.options.insert_space_after_semicolon_in_for && !part2Empty);
    handleTokenBefore(node.getBody(), TokenNameSEMICOLON,
            this.options.insert_space_before_semicolon_in_for && !part2Empty,
            this.options.insert_space_after_semicolon_in_for && !part3Empty);
    return true;
}

From source file:com.google.dart.java2dart.SyntaxTranslator.java

License:Open Source License

@Override
public boolean visit(org.eclipse.jdt.core.dom.ForStatement node) {
    Expression condition = translateExpression(node.getExpression());
    List<Expression> updaters = translateExpressionList(node.updaters());
    Statement body = (Statement) translate(node.getBody());
    Object javaInitializer = !node.initializers().isEmpty() ? node.initializers().get(0) : null;
    if (javaInitializer instanceof org.eclipse.jdt.core.dom.VariableDeclarationExpression) {
        org.eclipse.jdt.core.dom.VariableDeclarationExpression javaVDE = (org.eclipse.jdt.core.dom.VariableDeclarationExpression) javaInitializer;
        List<VariableDeclaration> variables = Lists.newArrayList();
        for (Iterator<?> I = javaVDE.fragments().iterator(); I.hasNext();) {
            org.eclipse.jdt.core.dom.VariableDeclarationFragment fragment = (org.eclipse.jdt.core.dom.VariableDeclarationFragment) I
                    .next();/*from  w  w w .j av  a2s  .  c o m*/
            variables.add((VariableDeclaration) translate(fragment));
        }
        VariableDeclarationList variableList = variableDeclarationList(null,
                (TypeName) translate(javaVDE.getType()), variables);
        return done(forStatement(variableList, condition, updaters, body));
    } else {
        Expression initializer = translate((org.eclipse.jdt.core.dom.ASTNode) javaInitializer);
        return done(forStatement(initializer, condition, updaters, body));
    }
}

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

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from  w w w .  j a  v a  2s .  c  o  m*/
public boolean visit(ForStatement node) {
    boolean emitAutoreleasePool = false;
    buffer.append("for (");
    for (Iterator<Expression> it = node.initializers().iterator(); it.hasNext();) {
        Expression next = it.next();
        if (next instanceof VariableDeclarationExpression) {
            List<VariableDeclarationFragment> vars = ((VariableDeclarationExpression) next).fragments();
            for (VariableDeclarationFragment fragment : vars) {
                emitAutoreleasePool |= Types.hasAutoreleasePoolAnnotation(Types.getBinding(fragment));
            }
        }
        next.accept(this);
        if (it.hasNext()) {
            buffer.append(", ");
        }
    }
    buffer.append("; ");
    if (node.getExpression() != null) {
        node.getExpression().accept(this);
    }
    buffer.append("; ");
    for (Iterator<Expression> it = node.updaters().iterator(); it.hasNext();) {
        it.next().accept(this);
        if (it.hasNext()) {
            buffer.append(", ");
        }
    }
    buffer.append(") ");
    if (emitAutoreleasePool) {
        buffer.append("{\nNSAutoreleasePool *pool__ = [[NSAutoreleasePool alloc] init];\n");
    }
    node.getBody().accept(this);
    if (emitAutoreleasePool) {
        buffer.append("[pool__ release];\n}\n");
    }
    return false;
}

From source file:com.google.devtools.j2objc.ast.DebugASTPrinter.java

License:Apache License

@Override
public boolean visit(ForStatement node) {
    sb.printIndent();// w  w w  .  ja v a2s.  co  m
    sb.print("for (");
    for (Iterator<Expression> it = node.getInitializers().iterator(); it.hasNext();) {
        it.next().accept(this);
        if (it.hasNext()) {
            sb.print(", ");
        }
    }
    sb.print("; ");
    if (node.getExpression() != null) {
        node.getExpression().accept(this);
    }
    sb.print("; ");
    for (Iterator<Expression> it = node.getUpdaters().iterator(); it.hasNext();) {
        it.next().accept(this);
        if (it.hasNext()) {
            sb.print(", ");
        }
    }
    sb.print(") ");
    node.getBody().accept(this);
    return false;
}