Class IfStmt
- java.lang.Object
-
- com.tonic.analysis.source.ast.stmt.IfStmt
-
-
Constructor Summary
Constructors Constructor Description IfStmt(Expression condition, Statement thenBranch)Creates an if statement without an else branch.IfStmt(Expression condition, Statement thenBranch, Statement elseBranch)Creates an if statement with an unknown location.IfStmt(Expression condition, Statement thenBranch, Statement elseBranch, SourceLocation location)Creates an if statement and parents its children 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.List<ASTNode>getChildren()Lists the direct children a node holds, in source order.ExpressiongetCondition()StatementgetElseBranch()SourceLocationgetLocation()Gets the source location of this node.ASTNodegetParent()Gets the parent node in the AST tree.StatementgetThenBranch()booleanhasElse()booleanisElseIf()voidsetCondition(Expression condition)Replaces the branch condition, reparenting old and new nodes.voidsetElseBranch(Statement elseBranch)Replaces the else branch, reparenting old and new nodes.voidsetLocation(SourceLocation location)Sets this statement's source location.voidsetParent(ASTNode parent)Sets the enclosing AST node.voidsetThenBranch(Statement thenBranch)Replaces the then branch, reparenting old and new nodes.StringtoString()IfStmtwithCondition(Expression condition)Replaces the branch condition, reparenting old and new nodes.IfStmtwithElseBranch(Statement elseBranch)Replaces the else branch, reparenting old and new nodes.IfStmtwithThenBranch(Statement thenBranch)Replaces the then branch, 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
-
IfStmt
public IfStmt(Expression condition, Statement thenBranch, Statement elseBranch, SourceLocation location)
Creates an if statement and parents its children to it.- Parameters:
condition- the branch conditionthenBranch- statement executed when the condition holdselseBranch- statement executed otherwise, or null for nonelocation- source location, or null for unknown- Throws:
NullPointerException- if condition or thenBranch is null
-
IfStmt
public IfStmt(Expression condition, Statement thenBranch, Statement elseBranch)
Creates an if statement with an unknown location.- Parameters:
condition- the branch conditionthenBranch- statement executed when the condition holdselseBranch- statement executed otherwise, or null for none- Throws:
NullPointerException- if condition or thenBranch is null
-
IfStmt
public IfStmt(Expression condition, Statement thenBranch)
Creates an if statement without an else branch.- Parameters:
condition- the branch conditionthenBranch- statement executed when the condition holds- Throws:
NullPointerException- if condition or thenBranch is null
-
-
Method Detail
-
getCondition
public Expression getCondition()
- Returns:
- the condition
-
setCondition
public void setCondition(Expression condition)
Replaces the branch condition, reparenting old and new nodes.- Parameters:
condition- the new condition
-
getThenBranch
public Statement getThenBranch()
- Returns:
- the then branch
-
setThenBranch
public void setThenBranch(Statement thenBranch)
Replaces the then branch, reparenting old and new nodes.- Parameters:
thenBranch- the new then branch
-
getElseBranch
public Statement getElseBranch()
- Returns:
- the else branch
-
setElseBranch
public void setElseBranch(Statement elseBranch)
Replaces the else branch, reparenting old and new nodes.- Parameters:
elseBranch- the new else branch, or null to remove it
-
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.
-
hasElse
public boolean hasElse()
- Returns:
- true if this if statement has an else branch
-
isElseIf
public boolean isElseIf()
- Returns:
- true if the else branch is itself an if statement
-
withCondition
public IfStmt withCondition(Expression condition)
Replaces the branch condition, reparenting old and new nodes.- Parameters:
condition- the new condition- Returns:
- this statement
-
withThenBranch
public IfStmt withThenBranch(Statement thenBranch)
Replaces the then branch, reparenting old and new nodes.- Parameters:
thenBranch- the new then branch- Returns:
- this statement
-
withElseBranch
public IfStmt withElseBranch(Statement elseBranch)
Replaces the else branch, reparenting old and new nodes.- Parameters:
elseBranch- the new else branch, or null to remove it- 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
-
-