Package org.codehaus.groovy.ast.stmt
Class WhileStatement
java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.stmt.Statement
org.codehaus.groovy.ast.stmt.WhileStatement
- All Implemented Interfaces:
NodeMetaDataHandler,LoopingStatement
Represents a while (condition) { ... } loop in Groovy.
The while loop repeatedly evaluates a
BooleanExpression at the start of each iteration
and executes the loop body only if the condition is true. If the condition is false on the first
evaluation, the loop body never executes.-
Constructor Summary
ConstructorsConstructorDescriptionWhileStatement(BooleanExpression booleanExpression, Statement loopBlock) Constructs a WhileStatement with a condition and loop body. -
Method Summary
Modifier and TypeMethodDescriptionReturns theBooleanExpressionthat is evaluated at the start of each iteration.Returns the loop bodyStatement}.voidsetBooleanExpression(BooleanExpression booleanExpression) Sets theBooleanExpression} to evaluate at the start of each iteration.voidsetLoopBlock(Statement loopBlock) Sets the loop bodyStatement}.voidvisit(GroovyCodeVisitor visitor) Accepts a code visitor for AST traversal and transformation.Methods inherited from class org.codehaus.groovy.ast.stmt.Statement
addStatementAnnotation, addStatementLabel, copyStatementLabels, getStatementAnnotations, getStatementLabel, getStatementLabels, isEmpty, setStatementLabelMethods inherited from class org.codehaus.groovy.ast.ASTNode
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePositionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler
copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData
-
Constructor Details
-
WhileStatement
Constructs a WhileStatement with a condition and loop body.- Parameters:
booleanExpression- theBooleanExpressionevaluated at the start of each iterationloopBlock- theStatementto execute while the condition is true
-
-
Method Details
-
visit
Description copied from class:ASTNodeAccepts a code visitor for AST traversal and transformation. Subclasses must implement this method to support visitor pattern-based processing. The visitor pattern enables decoupling of AST structure from processing logic.- Overrides:
visitin classASTNode- Parameters:
visitor- theGroovyCodeVisitorto process this node
-
getBooleanExpression
Returns theBooleanExpressionthat is evaluated at the start of each iteration.- Returns:
- the loop condition
BooleanExpression}
-
getLoopBlock
Returns the loop bodyStatement}.- Specified by:
getLoopBlockin interfaceLoopingStatement- Returns:
- the loop block
Statement}
-
setBooleanExpression
Sets theBooleanExpression} to evaluate at the start of each iteration.- Parameters:
booleanExpression- the loop conditionBooleanExpression}
-
setLoopBlock
Sets the loop bodyStatement}.- Specified by:
setLoopBlockin interfaceLoopingStatement- Parameters:
loopBlock- the loop blockStatement}
-