public final class LoopStatement extends GoloStatement<LoopStatement> implements BlockContainer<LoopStatement>, ReferencesHolder
This is used to represent both for
and while
loops, as well as the desugared foreach
loop.
Modifier and Type | Method and Description |
---|---|
void |
accept(GoloIrVisitor visitor)
Accept the visitor.
|
LoopStatement |
block(java.lang.Object innerBlock)
Defines the contained block.
|
java.util.List<GoloElement<?>> |
children()
Returns a list of all the direct children of this node.
|
ExpressionStatement<?> |
condition() |
LoopStatement |
condition(java.lang.Object expression)
Defines the loop condition.
|
static LoopStatement |
create(java.lang.Object init,
java.lang.Object condition,
java.lang.Object post,
java.lang.Object block)
Complete loop creation.
|
Block |
getBlock() |
LocalReference[] |
getReferences()
Returns the references contained in this element.
|
int |
getReferencesCount()
Returns the number of references contained in this element.
|
boolean |
hasInitStatement() |
boolean |
hasPostStatement() |
AssignmentStatement |
init() |
LoopStatement |
init(java.lang.Object assignment)
Defines the initialization of the loop variable.
|
static LoopStatement |
loop()
Creates a generic loop.
|
GoloStatement<?> |
post() |
LoopStatement |
post(java.lang.Object statement)
Define the post-loop statement.
|
protected void |
replaceElement(GoloElement<?> original,
GoloElement<?> newElement)
Replace a child.
|
protected LoopStatement |
self() |
of
ancestor, ancestor, ancestorOfType, cantConvert, cantReplace, cantReplace, children, children, descendants, descendants, descendants, documentation, documentation, doesNotContain, enclosingModule, getLocalReferenceTable, hasParent, hasPosition, makeParentOf, metadata, metadata, next, next, next, ofAST, parent, positionInSourceCode, positionInSourceCode, previous, previous, previous, replaceInParentBy, walk
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
body
getDeclaringReferences
public static LoopStatement loop()
public static LoopStatement create(java.lang.Object init, java.lang.Object condition, java.lang.Object post, java.lang.Object block)
protected LoopStatement self()
self
in class GoloElement<LoopStatement>
public LoopStatement init(java.lang.Object assignment)
For instance, the var i = 0
statement.
This can be null
in the case of while
loops.
This is a builder method.
assignment
- a AssignmentStatement
defining the loop variable.public LoopStatement condition(java.lang.Object expression)
For instance, the i < 10
expression.
This is a builder method.
expression
- a ExpressionStatement
evaluating to a boolean.public LoopStatement post(java.lang.Object statement)
For instance, the i = i + 1
statement.
This can be null
in the case of while
loops.
This is a builder method.
statement
- a GoloStatement
changing the loop variable.public LoopStatement block(java.lang.Object innerBlock)
This is a builder method.
block
in interface BlockContainer<LoopStatement>
innerBlock
- an object that can be converted into a Block
Block.of(Object)
public boolean hasInitStatement()
public AssignmentStatement init()
public ExpressionStatement<?> condition()
public Block getBlock()
getBlock
in interface BlockContainer<LoopStatement>
public GoloStatement<?> post()
public boolean hasPostStatement()
public LocalReference[] getReferences()
getReferences
in interface ReferencesHolder
public int getReferencesCount()
getReferencesCount
in interface ReferencesHolder
public void accept(GoloIrVisitor visitor)
This method should only call the visitor visitXXXX
method.
The children of this node will be visited by the
GoloElement.walk(GoloIrVisitor)
method.
accept
in class GoloElement<LoopStatement>
public java.util.List<GoloElement<?>> children()
children
in class GoloElement<LoopStatement>
protected void replaceElement(GoloElement<?> original, GoloElement<?> newElement)
Replace original
with newElement
if original
is a child of this node
and type matches.
replaceElement
in class GoloElement<LoopStatement>
original
- the original value to replace. Must be a child of this nodenewElement
- the element to replace with. Type must match.GoloElement.cantReplace()
,
GoloElement.cantReplace(GoloElement, GoloElement)
,
GoloElement.doesNotContain(GoloElement)
,
GoloElement.cantConvert(String, Object)