Class WhileStmt
- java.lang.Object
-
- com.tonic.analysis.source.ast.stmt.WhileStmt
-
-
Constructor Summary
Constructors Constructor Description WhileStmt(Expression condition, Statement body)Creates an unlabeled while loop with an unknown location.WhileStmt(Expression condition, Statement body, String label)Creates a labeled while loop with an unknown location.WhileStmt(Expression condition, Statement body, String label, SourceLocation location)Creates a while loop, adopting the condition and body 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.StatementgetBody()List<ASTNode>getChildren()Lists the direct children a node holds, in source order.ExpressiongetCondition()StringgetLabel()Gets the label for this statement, if any.SourceLocationgetLocation()Gets the source location of this node.ASTNodegetParent()Gets the parent node in the AST tree.voidsetBody(Statement body)Replaces the loop body, reparenting it and releasing the previous one.voidsetCondition(Expression condition)Replaces the loop condition, reparenting it and releasing the previous one.voidsetLabel(String label)Sets the label targeted by labeled break and continue.voidsetLocation(SourceLocation location)Sets this statement's source location.voidsetParent(ASTNode parent)Sets the node this statement hangs from.StringtoString()WhileStmtwithBody(Statement body)Replaces the loop body in place, reparenting it and releasing the previous one.WhileStmtwithCondition(Expression condition)Replaces the loop condition in place, reparenting it and releasing the previous one.WhileStmtwithLabel(String label)Sets the label in place.-
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
-
WhileStmt
public WhileStmt(Expression condition, Statement body, String label, SourceLocation location)
Creates a while loop, adopting the condition and body as children.- Parameters:
condition- the loop conditionbody- the loop bodylabel- the loop label, or nulllocation- the source location, or null for unknown- Throws:
NullPointerException- if the condition or body is null
-
WhileStmt
public WhileStmt(Expression condition, Statement body, String label)
Creates a labeled while loop with an unknown location.- Parameters:
condition- the loop conditionbody- the loop bodylabel- the loop label, or null- Throws:
NullPointerException- if the condition or body is null
-
WhileStmt
public WhileStmt(Expression condition, Statement body)
Creates an unlabeled while loop with an unknown location.- Parameters:
condition- the loop conditionbody- the loop body- Throws:
NullPointerException- if the condition or body is null
-
-
Method Detail
-
getCondition
public Expression getCondition()
- Returns:
- the condition
-
setCondition
public void setCondition(Expression condition)
Replaces the loop condition, reparenting it and releasing the previous one.- Parameters:
condition- the new condition
-
getBody
public Statement getBody()
- Returns:
- the body
-
setBody
public void setBody(Statement body)
Replaces the loop body, reparenting it and releasing the previous one.- Parameters:
body- the new body
-
setLabel
public void setLabel(String label)
Sets the label targeted by labeled break and continue.- Parameters:
label- the new label, or null to drop 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 node this statement hangs from.
-
getLabel
public String getLabel()
Description copied from interface:StatementGets the label for this statement, if any.
-
withCondition
public WhileStmt withCondition(Expression condition)
Replaces the loop condition in place, reparenting it and releasing the previous one.- Parameters:
condition- the new condition, may be null- Returns:
- this statement
-
withBody
public WhileStmt withBody(Statement body)
Replaces the loop body in place, reparenting it and releasing the previous one.- Parameters:
body- the new body, may be null- Returns:
- this statement
-
withLabel
public WhileStmt withLabel(String label)
Sets the label in place.- Parameters:
label- the new label, or null to drop 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
-
-