protected Statement whileStatement(AST whileNode) { AST node = whileNode.getFirstChild(); assertNodeType(EXPR, node); // TODO remove this once we support declarations in the while condition if (isType(VARIABLE_DEF, node.getFirstChild())) { throw new ASTRuntimeException(whileNode, "While loop condition contains a declaration; this is currently unsupported."); } BooleanExpression booleanExpression = booleanExpression(node); node = node.getNextSibling(); Statement block; if (isType(SEMI, node)) { block = EmptyStatement.INSTANCE; } else { block = statement(node); } WhileStatement whileStatement = new WhileStatement(booleanExpression, block); configureAST(whileStatement, whileNode); return whileStatement; }
/** * Represents a while statement. A while loop is a control flow * statement that executes maybe repeatedly a code block, * depending on a given boolean condition. * * @param booleanExpr boolean condition * @param loopBlock the block that could be repeated * @return an instance of type {@link DoWhileStatement} * @since 0.2.7 */ public static WhileStatement whileS(final BooleanExpression booleanExpr, final Statement loopBlock) { return new WhileStatement(booleanExpr, loopBlock); }
protected Statement whileStatement(AST whileNode) { AST node = whileNode.getFirstChild(); assertNodeType(EXPR, node); // TODO remove this once we support declarations in the while condition if (isType(VARIABLE_DEF, node.getFirstChild())) { throw new ASTRuntimeException(whileNode, "While loop condition contains a declaration; this is currently unsupported."); } BooleanExpression booleanExpression = booleanExpression(node); node = node.getNextSibling(); Statement block; if (isType(SEMI, node)) { block = EmptyStatement.INSTANCE; } else { block = statement(node); } WhileStatement whileStatement = new WhileStatement(booleanExpression, block); configureAST(whileStatement, whileNode); return whileStatement; }
protected Statement whileStatement(AST whileNode) { AST node = whileNode.getFirstChild(); assertNodeType(EXPR, node); // TODO remove this once we support declarations in the while condition if (isType(VARIABLE_DEF, node.getFirstChild())) { throw new ASTRuntimeException(whileNode, "While loop condition contains a declaration; this is currently unsupported."); } BooleanExpression booleanExpression = booleanExpression(node); node = node.getNextSibling(); Statement block; if (isType(SEMI, node)) { block = EmptyStatement.INSTANCE; } else { block = statement(node); } WhileStatement whileStatement = new WhileStatement(booleanExpression, block); configureAST(whileStatement, whileNode); return whileStatement; }
protected Statement whileStatement(AST whileNode) { AST node = whileNode.getFirstChild(); assertNodeType(EXPR, node); // TODO remove this once we support declarations in the while condition if (isType(VARIABLE_DEF, node.getFirstChild())) { throw new ASTRuntimeException(whileNode, "While loop condition contains a declaration; this is currently unsupported."); } BooleanExpression booleanExpression = booleanExpression(node); node = node.getNextSibling(); Statement block; if (isType(SEMI, node)) { block = EmptyStatement.INSTANCE; } else { block = statement(node); } WhileStatement whileStatement = new WhileStatement(booleanExpression, block); configureAST(whileStatement, whileNode); return whileStatement; }
protected Statement whileStatement(AST whileNode) { AST node = whileNode.getFirstChild(); assertNodeType(EXPR, node); // TODO remove this once we support declarations in the while condition if (isType(VARIABLE_DEF, node.getFirstChild())) { throw new ASTRuntimeException(whileNode, "While loop condition contains a declaration; this is currently unsupported."); } BooleanExpression booleanExpression = booleanExpression(node); node = node.getNextSibling(); Statement block; if (isType(SEMI, node)) { block = EmptyStatement.INSTANCE; } else { block = statement(node); } WhileStatement whileStatement = new WhileStatement(booleanExpression, block); configureAST(whileStatement, whileNode); return whileStatement; }