コード例 #1
0
 @Override
 public boolean visit(ForStatement node) {
   List<Expression> initializers = node.getInitializers();
   // The for-loop initializers can either be a single variable declaration
   // expression or a list of initializer expressions.
   if (initializers.size() == 1 && initializers.get(0) instanceof VariableDeclarationExpression) {
     VariableDeclarationExpression decl = (VariableDeclarationExpression) initializers.get(0);
     extractVariableDeclarationFragments(
         decl.getFragments(), TreeUtil.asStatementList(node).subList(0, 0));
   } else {
     extractExpressionList(initializers, TreeUtil.asStatementList(node).subList(0, 0), false);
   }
   Expression expr = node.getExpression();
   if (expr != null) {
     newExpression(expr);
     expr.accept(this);
     List<VariableAccess> toExtract = getUnsequencedAccesses();
     if (!toExtract.isEmpty()) {
       // Convert "if (;cond;)" into "if (;;) { if (!(cond)) break; ...}".
       List<Statement> stmtList = TreeUtil.asStatementList(node.getBody()).subList(0, 0);
       extractOrderedAccesses(stmtList, currentTopNode, toExtract);
       stmtList.add(createLoopTermination(node.getExpression()));
       node.setExpression(null);
     }
   }
   extractExpressionList(node.getUpdaters(), TreeUtil.asStatementList(node.getBody()), true);
   node.getBody().accept(this);
   return false;
 }
コード例 #2
0
ファイル: ForStatement.java プロジェクト: nelsonnan/j2objc
 public ForStatement(ForStatement other) {
   super(other);
   initializers.copyFrom(other.getInitializers());
   expression.copyFrom(other.getExpression());
   updaters.copyFrom(other.getUpdaters());
   body.copyFrom(other.getBody());
 }
コード例 #3
0
ファイル: RewriterTest.java プロジェクト: natanovia/j2objc
 public void testLabeledBreak() throws IOException {
   List<Statement> stmts =
       translateStatements(
           "int i = 0; outer: for (; i < 10; i++) { "
               + "for (int j = 0; j < 10; j++) { break outer; }}");
   assertEquals(3, stmts.size());
   Statement s = stmts.get(1);
   assertTrue(s instanceof ForStatement); // not LabeledStatement
   ForStatement fs = (ForStatement) s;
   Statement forStmt = fs.getBody();
   assertTrue(forStmt instanceof Block);
   assertEquals(1, ((Block) forStmt).getStatements().size());
   Statement lastStmt = stmts.get(2);
   assertTrue(lastStmt instanceof LabeledStatement);
   assertTrue(((LabeledStatement) lastStmt).getBody() instanceof EmptyStatement);
 }