Class SwitchStmt
- java.lang.Object
-
- com.tonic.analysis.source.ast.stmt.SwitchStmt
-
-
Constructor Summary
Constructors Constructor Description SwitchStmt(Expression selector)Creates a switch statement with no cases.SwitchStmt(Expression selector, List<SwitchCase> cases)Creates a switch statement with an unknown location.SwitchStmt(Expression selector, List<SwitchCase> cases, SourceLocation location)Creates a switch statement and parents the selector to it.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.voidaddCase(SwitchCase switchCase)Appends a case to this switch.intgetCaseCount()List<SwitchCase>getCases()List<ASTNode>getChildren()Lists the direct children a node holds, in source order.SwitchCasegetDefaultCase()SourceLocationgetLocation()Gets the source location of this node.ASTNodegetParent()Gets the parent node in the AST tree.ExpressiongetSelector()booleanhasDefault()voidsetLocation(SourceLocation location)Sets this statement's source location.voidsetParent(ASTNode parent)Sets the enclosing AST node.voidsetSelector(Expression selector)Replaces the selector expression, reparenting old and new nodes.StringtoString()SwitchStmtwithSelector(Expression selector)Replaces the selector expression, reparenting old and new nodes.-
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
-
SwitchStmt
public SwitchStmt(Expression selector, List<SwitchCase> cases, SourceLocation location)
Creates a switch statement and parents the selector to it.- Parameters:
selector- the switched-on expressioncases- initial cases, or null for nonelocation- source location, or null for unknown- Throws:
NullPointerException- if selector is null
-
SwitchStmt
public SwitchStmt(Expression selector, List<SwitchCase> cases)
Creates a switch statement with an unknown location.- Parameters:
selector- the switched-on expressioncases- initial cases, or null for none- Throws:
NullPointerException- if selector is null
-
SwitchStmt
public SwitchStmt(Expression selector)
Creates a switch statement with no cases.- Parameters:
selector- the switched-on expression- Throws:
NullPointerException- if selector is null
-
-
Method Detail
-
getSelector
public Expression getSelector()
- Returns:
- the selector
-
setSelector
public void setSelector(Expression selector)
Replaces the selector expression, reparenting old and new nodes.- Parameters:
selector- the new selector
-
getCases
public List<SwitchCase> getCases()
- Returns:
- the cases
-
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 enclosing AST node.
-
addCase
public void addCase(SwitchCase switchCase)
Appends a case to this switch.- Parameters:
switchCase- the case to append
-
getDefaultCase
public SwitchCase getDefaultCase()
- Returns:
- the default case, or null if there is none
-
hasDefault
public boolean hasDefault()
- Returns:
- true if this switch has a default case
-
getCaseCount
public int getCaseCount()
- Returns:
- the number of cases
-
withSelector
public SwitchStmt withSelector(Expression selector)
Replaces the selector expression, reparenting old and new nodes.- Parameters:
selector- the new selector- Returns:
- this statement
-
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.
-
setLocation
public void setLocation(SourceLocation location)
Description copied from interface:StatementSets this statement's source location.- Specified by:
setLocationin interfaceStatement- Parameters:
location- the provenance to stamp, or null forSourceLocation.UNKNOWN
-
-