Java 类com.sun.codemodel.JForLoop 实例源码

项目:kola    文件:StatementAdapter.java   
private void basicForStatement(PForInit init, Node cond, PForUpdate update, PStatement _do) {
    context.pushStatementScope();
    try {
        JForLoop loop = parent._for();
        if (init != null) {
            ForInitAdapter fia = new ForInitAdapter(loop, context);
            init.apply(fia);
        }
        if (update != null) {
            ForUpdateAdapter fua = new ForUpdateAdapter(loop, context);
            update.apply(fua);
        }
        if (cond != null) {
            ExpressionAdapter ea = new ExpressionAdapter(new JExprParent(), context);
            cond.apply(ea);
            loop.test(ea.expr);
        }
        JBlock tmpBlock = new JBlock();
        StatementAdapter sa = new StatementAdapter(new JBlockParent(tmpBlock, context), context);
        _do.apply(sa);
        JStatement stmt = (JStatement) tmpBlock.getContents().get(0);
        if (stmt instanceof JBlock) {
            JBlock stmtBlock = (JBlock) stmt;
            stmtBlock.setNewlineRequired(false);
        }
        loop.setBody(stmt);
    } finally {
        context.popScope();
    }
}
项目:LRPaGe    文件:MainGenerator.java   
/**
 * Defines the print visitor's print method, which prints an object
 * with the appropriate indentation.
 * @param model
 * @param printVisitor
 * @param delim
 * @param depth
 * @return
 * 
 * @author Tristan Bepler
 */
private static JMethod definePrintMethod(JCodeModel model,
        JDefinedClass printVisitor, JVar delim, JVar depth) {
    JMethod print = printVisitor.method(JMod.PRIVATE, void.class, "print");
    JVar obj = print.param(Object.class, "obj");
    JForLoop loop = print.body()._for();
    JVar i = loop.init(model.INT, "i", JExpr.lit(0));
    loop.test(i.lt(depth));
    loop.update(i.incr());
    loop.body().invoke(model.ref(System.class).staticRef("out"), "print").arg(delim);
    print.body().invoke(model.ref(System.class).staticRef("out"), "println").arg(obj);
    return print;
}
项目:kola    文件:JBlockParent.java   
@Override
public JForLoop _for() {
    return block._for();
}
项目:kola    文件:ForUpdateAdapter.java   
ForUpdateAdapter(JForLoop loop, ResolutionContext context) {
    this.context = context;
    this.loop = loop;
}
项目:kola    文件:ForInitAdapter.java   
ForInitAdapter(JForLoop loop, ResolutionContext context) {
    this.context = context;
    this.loop = loop;
}
项目:kola    文件:StatementAdapter.java   
public JForLoop _for();