Package org.codehaus.groovy.ast.stmt
Class ForStatement
java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.stmt.Statement
org.codehaus.groovy.ast.stmt.ForStatement
- All Implemented Interfaces:
NodeMetaDataHandler,LoopingStatement
Represents a for loop in Groovy.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionForStatement(ClosureListExpression closureListExpression, Statement loopBlock) A constructor of classic (C-style) for loops.ForStatement(Parameter valueVariable, Expression collectionExpression, Statement loopBlock) A constructor of for-in loops without an index variable.ForStatement(Parameter indexVariable, Parameter valueVariable, Expression collectionExpression, Statement loopBlock) A constructor of for-in loops (possibly with an optional index variable). -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the collection expression of a for loop.Retrieves the index variable of for-in loops with an index variable or null in other cases.Gets the loop block.Retrieves the value variable of for-in loops or null for a classic for loop.Deprecated.Deprecated.voidsetCollectionExpression(Expression collectionExpression) voidsetLoopBlock(Statement loopBlock) Sets the loop block.voidsetVariableScope(VariableScope scope) voidvisit(GroovyCodeVisitor visitor) 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
-
Field Details
-
FOR_LOOP_DUMMY
Deprecated.
-
-
Constructor Details
-
ForStatement
public ForStatement(Parameter indexVariable, Parameter valueVariable, Expression collectionExpression, Statement loopBlock) A constructor of for-in loops (possibly with an optional index variable). An example with an index variable:for (int idx, int i in 10..12) { println "$idx $i" }- Since:
- 5.0.0
-
ForStatement
A constructor of for-in loops without an index variable. Variants using Java-style ":" or the Groovy reserved word "in" are equivalent:for (int i : 0..2) { println i } for (int j in 5..7) { println j }- Since:
- 5.0.0
-
ForStatement
A constructor of classic (C-style) for loops.for (int i = 20; i < 23; i++) { println i }Also handles multi-assignment for loops.for (def (String i, int j) = ['a', 30]; j < 33; i++, j++) { println "$i $j" }- Since:
- 6.0.0
-
-
Method Details
-
setCollectionExpression
-
setLoopBlock
Description copied from interface:LoopingStatementSets the loop block.- Specified by:
setLoopBlockin interfaceLoopingStatement
-
getIndexVariable
Retrieves the index variable of for-in loops with an index variable or null in other cases.- Since:
- 5.0.0
-
getValueVariable
Retrieves the value variable of for-in loops or null for a classic for loop.- Since:
- 5.0.0
-
getVariable
Deprecated. -
getVariableType
Deprecated. -
getCollectionExpression
Retrieves the collection expression of a for loop. Will be an instance ofClosureListExpressionfor a classic for loop. -
getLoopBlock
Description copied from interface:LoopingStatementGets the loop block.- Specified by:
getLoopBlockin interfaceLoopingStatement
-
getVariableScope
-
setVariableScope
-
visit
-