Class SwitchExpr
- java.lang.Object
-
- com.tonic.analysis.source.ast.expr.SwitchExpr
-
- All Implemented Interfaces:
ASTNode,Expression
public final class SwitchExpr extends Object implements Expression
A switch expression (Java 14, JEP 361):switch (sel) { case L -> result; default -> r; }.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSwitchExpr.ArmOne arm.static classSwitchExpr.ComponentOne component of a record-deconstruction pattern:type binding.
-
Constructor Summary
Constructors Constructor Description SwitchExpr(Expression selector, List<SwitchExpr.Arm> arms, SourceType type)Creates a switch expression with no source position.SwitchExpr(Expression selector, List<SwitchExpr.Arm> arms, SourceType type, SourceLocation location)Creates a switch expression and adopts the selector, every label, and every arm result 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<SwitchExpr.Arm>getArms()List<ASTNode>getChildren()Lists the direct children a node holds, in source order.SourceLocationgetLocation()Gets the source location of this node.ASTNodegetParent()Gets the parent node in the AST tree.ExpressiongetSelector()SourceTypegetType()Gets the inferred type of this expression.voidsetParent(ASTNode parent)Records the node this expression hangs under.voidsetSelector(Expression selector)Replaces the value switched on, adopting the new selector and releasing the old one.StringtoString()-
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
-
SwitchExpr
public SwitchExpr(Expression selector, List<SwitchExpr.Arm> arms, SourceType type, SourceLocation location)
Creates a switch expression and adopts the selector, every label, and every arm result as children.- Parameters:
selector- the value switched onarms- the arms, or null for nonetype- the type the expression yieldslocation- the source position, or null for UNKNOWN
-
SwitchExpr
public SwitchExpr(Expression selector, List<SwitchExpr.Arm> arms, SourceType type)
Creates a switch expression with no source position.- Parameters:
selector- the value switched onarms- the arms, or null for nonetype- the type the expression yields
-
-
Method Detail
-
getSelector
public Expression getSelector()
- Returns:
- the selector
-
setSelector
public void setSelector(Expression selector)
Replaces the value switched on, adopting the new selector and releasing the old one.- Parameters:
selector- the new selector, or null
-
getArms
public List<SwitchExpr.Arm> getArms()
- Returns:
- the arms
-
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)
Records the node this expression hangs under.
-
getType
public SourceType getType()
Description copied from interface:ExpressionGets the inferred type of this expression.- Specified by:
getTypein interfaceExpression- Returns:
- the type of 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.
-
-