public final class ConditionalBranching extends GoloStatement<ConditionalBranching>
Typically an if else
node.
Modifier and Type | Method and Description |
---|---|
void |
accept(GoloIrVisitor visitor)
Accept the visitor.
|
static ConditionalBranching |
branch()
Creates an empty conditional branch.
|
java.util.List<GoloElement<?>> |
children()
Returns a list of all the direct children of this node.
|
ConditionalBranching |
condition(java.lang.Object cond)
Defines the condition of the branching.
|
static ConditionalBranching |
create(java.lang.Object condition,
java.lang.Object trueBlock,
java.lang.Object falseBlock,
java.lang.Object elseBranch)
Full branch construction in one call.
|
ConditionalBranching |
elseBranch(java.lang.Object elseBranch)
Defines a nested conditional branch.
|
ExpressionStatement<?> |
getCondition() |
ConditionalBranching |
getElseConditionalBranching() |
Block |
getFalseBlock() |
Block |
getTrueBlock() |
boolean |
hasElseConditionalBranching() |
boolean |
hasFalseBlock() |
ConditionalBranching |
otherwise(java.lang.Object alternative)
Defines a block to execute when
false or a nested branch according to the given element. |
protected void |
replaceElement(GoloElement<?> original,
GoloElement<?> newElement)
Replace a child.
|
boolean |
returnsFromBothBranches() |
protected ConditionalBranching |
self() |
java.lang.String |
toString() |
ConditionalBranching |
whenFalse(java.lang.Object block)
Defines the block executed when the condition evaluates to
false . |
ConditionalBranching |
whenTrue(java.lang.Object block)
Defines the block executed when the condition evaluates to
true . |
of
ancestor, ancestor, ancestorOfType, cantConvert, cantReplace, cantReplace, children, children, descendants, descendants, descendants, documentation, documentation, doesNotContain, enclosingModule, getLocalReferenceTable, hasParent, hasPosition, inheritedMetadata, makeParentOf, metadata, metadata, next, next, next, ofAST, parent, positionInSourceCode, positionInSourceCode, previous, previous, previous, replaceInParentBy, walk
public static ConditionalBranching branch()
public static ConditionalBranching create(java.lang.Object condition, java.lang.Object trueBlock, java.lang.Object falseBlock, java.lang.Object elseBranch)
Less readable than the fluent API, but useful when doing meta-generation
condition
- the test conditiontrueBlock
- the block to execute when the condition is truefalseBlock
- the block to execute when the condition is falseelseBranch
- a nested conditional branchprotected ConditionalBranching self()
self
in class GoloElement<ConditionalBranching>
public ConditionalBranching condition(java.lang.Object cond)
This is a builder method.
cond
- the expression defining the condition. If null
, the condition is set to false
.public ConditionalBranching whenTrue(java.lang.Object block)
true
.
This is a builder method.
public ConditionalBranching whenFalse(java.lang.Object block)
false
.
This is a builder method.
otherwise(Object)
public ConditionalBranching elseBranch(java.lang.Object elseBranch)
This is a builder method.
This represents an else if
branch.
otherwise(Object)
public ConditionalBranching otherwise(java.lang.Object alternative)
false
or a nested branch according to the given element.
This is a builder method; it's the preferred way to define an alternative to the true block.
alternative
- a Block
to execute when false
or a ConditionalBranching
defining a
nested branch.public ExpressionStatement<?> getCondition()
public Block getTrueBlock()
public Block getFalseBlock()
public boolean hasFalseBlock()
public ConditionalBranching getElseConditionalBranching()
public boolean hasElseConditionalBranching()
public boolean returnsFromBothBranches()
public java.lang.String toString()
toString
in class java.lang.Object
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<ConditionalBranching>
public java.util.List<GoloElement<?>> children()
children
in class GoloElement<ConditionalBranching>
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<ConditionalBranching>
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)