Class TernaryExpr
- java.lang.Object
-
- com.tonic.analysis.source.ast.expr.TernaryExpr
-
- All Implemented Interfaces:
ASTNode,Expression
public final class TernaryExpr extends Object implements Expression
A conditional expression - condition ? thenExpr : elseExpr - whose three operands are children of this node.
-
-
Constructor Summary
Constructors Constructor Description TernaryExpr(Expression condition, Expression thenExpr, Expression elseExpr, SourceType type)Creates a conditional expression with an unknown source position.TernaryExpr(Expression condition, Expression thenExpr, Expression elseExpr, SourceType type, SourceLocation location)Creates a conditional expression and adopts the three operands as children.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.List<ASTNode>getChildren()Lists the direct children a node holds, in source order.ExpressiongetCondition()ExpressiongetElseExpr()SourceLocationgetLocation()Gets the source location of this node.ASTNodegetParent()Gets the parent node in the AST tree.ExpressiongetThenExpr()SourceTypegetType()Gets the inferred type of this expression.voidsetCondition(Expression condition)Replaces the test, reparenting it and releasing the old one.voidsetElseExpr(Expression elseExpr)Replaces the else-value, reparenting it and releasing the old one.voidsetParent(ASTNode parent)Sets the node this expression hangs under.voidsetThenExpr(Expression thenExpr)Replaces the then-value, reparenting it and releasing the old one.StringtoString()TernaryExprwithCondition(Expression condition)Replaces the test, reparenting it and releasing the old one.TernaryExprwithElseExpr(Expression elseExpr)Replaces the else-value, reparenting it and releasing the old one.TernaryExprwithThenExpr(Expression thenExpr)Replaces the then-value, reparenting it and releasing the old one.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.tonic.analysis.source.ast.ASTNode
deepClone, findAll, findAll, findAncestor, findFirst, findFirst, getRoot, isDescendantOf, remove, replaceWith, stream, stream, walk
-
-
-
-
Constructor Detail
-
TernaryExpr
public TernaryExpr(Expression condition, Expression thenExpr, Expression elseExpr, SourceType type, SourceLocation location)
Creates a conditional expression and adopts the three operands as children.- Parameters:
condition- the testthenExpr- the value when the test holdselseExpr- the value when it does nottype- the expression's static typelocation- source position, or null for an unknown one- Throws:
NullPointerException- if condition, thenExpr, elseExpr or type is null
-
TernaryExpr
public TernaryExpr(Expression condition, Expression thenExpr, Expression elseExpr, SourceType type)
Creates a conditional expression with an unknown source position.- Parameters:
condition- the testthenExpr- the value when the test holdselseExpr- the value when it does nottype- the expression's static type- Throws:
NullPointerException- if condition, thenExpr, elseExpr or type is null
-
-
Method Detail
-
getCondition
public Expression getCondition()
- Returns:
- the test expression
-
setCondition
public void setCondition(Expression condition)
Replaces the test, reparenting it and releasing the old one.- Parameters:
condition- the new test
-
getThenExpr
public Expression getThenExpr()
- Returns:
- the value taken when the test holds
-
setThenExpr
public void setThenExpr(Expression thenExpr)
Replaces the then-value, reparenting it and releasing the old one.- Parameters:
thenExpr- the new then-value
-
getElseExpr
public Expression getElseExpr()
- Returns:
- the else-value
-
setElseExpr
public void setElseExpr(Expression elseExpr)
Replaces the else-value, reparenting it and releasing the old one.- Parameters:
elseExpr- the new else-value
-
getType
public SourceType getType()
Description copied from interface:ExpressionGets the inferred type of this expression.- Specified by:
getTypein interfaceExpression- Returns:
- the static type of this expression
-
getLocation
public SourceLocation getLocation()
Description copied from interface:ASTNodeGets the source location of this node.- Specified by:
getLocationin interfaceASTNode- Returns:
- the location
-
getParent
public ASTNode getParent()
Description copied from interface:ASTNodeGets the parent node in the AST tree.
-
setParent
public void setParent(ASTNode parent)
Sets the node this expression hangs under.
-
withCondition
public TernaryExpr withCondition(Expression condition)
Replaces the test, reparenting it and releasing the old one.- Parameters:
condition- the new test, or null to clear it- Returns:
- this expression
-
withThenExpr
public TernaryExpr withThenExpr(Expression thenExpr)
Replaces the then-value, reparenting it and releasing the old one.- Parameters:
thenExpr- the new then-value, or null to clear it- Returns:
- this expression
-
withElseExpr
public TernaryExpr withElseExpr(Expression elseExpr)
Replaces the else-value, reparenting it and releasing the old one.- Parameters:
elseExpr- the new else-value, or null to clear it- Returns:
- this expression
-
getChildren
public List<ASTNode> getChildren()
Description copied from interface:ASTNodeLists the direct children a node holds, in source order.- Specified by:
getChildrenin interfaceASTNode- Returns:
- the direct children, empty for a leaf
-
accept
public <T> T accept(SourceVisitor<T> visitor)
Description copied from interface:ASTNodeAccepts a visitor for this node.
-
-