Class ForStmt
- java.lang.Object
-
- com.tonic.analysis.source.ast.stmt.ForStmt
-
-
Constructor Summary
Constructors Constructor Description ForStmt(List<Statement> init, Expression condition, List<Expression> update, Statement body)Creates an unlabeled for loop with an unknown location.ForStmt(List<Statement> init, Expression condition, List<Expression> update, Statement body, String label, SourceLocation location)Creates a for loop, skipping null init and update entries and parenting children to it.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.voidaddInit(Statement stmt)Appends an initializer statement, ignoring null.voidaddUpdate(Expression expr)Appends an update expression, ignoring null.StatementgetBody()List<ASTNode>getChildren()Lists the direct children a node holds, in source order.ExpressiongetCondition()NodeList<Statement>getInit()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.NodeList<Expression>getUpdate()static ForStmtinfinite(Statement body)Creates a conditionless for loop.booleanisInfinite()voidsetBody(Statement body)Replaces the loop body, reparenting old and new nodes.voidsetCondition(Expression condition)Replaces the loop condition, reparenting old and new nodes.voidsetLabel(String label)Sets the loop label.voidsetLocation(SourceLocation location)Sets this statement's source location.voidsetParent(ASTNode parent)Sets the enclosing AST node.StringtoString()ForStmtwithBody(Statement body)Replaces the loop body, reparenting old and new nodes.ForStmtwithCondition(Expression condition)Replaces the loop condition, reparenting old and new nodes.ForStmtwithLabel(String label)Sets the loop label.-
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
-
ForStmt
public ForStmt(List<Statement> init, Expression condition, List<Expression> update, Statement body, String label, SourceLocation location)
Creates a for loop, skipping null init and update entries and parenting children to it.- Parameters:
init- initializer statements, or null for nonecondition- loop condition, or null for an infinite loopupdate- update expressions, or null for nonebody- the loop bodylabel- loop label, or null for nonelocation- source location, or null for unknown- Throws:
NullPointerException- if body is null
-
ForStmt
public ForStmt(List<Statement> init, Expression condition, List<Expression> update, Statement body)
Creates an unlabeled for loop with an unknown location.- Parameters:
init- initializer statements, or null for nonecondition- loop condition, or null for an infinite loopupdate- update expressions, or null for nonebody- the loop body- Throws:
NullPointerException- if body is null
-
-
Method Detail
-
getCondition
public Expression getCondition()
- Returns:
- the condition
-
setCondition
public void setCondition(Expression condition)
Replaces the loop condition, reparenting old and new nodes.- Parameters:
condition- the new condition, or null for an infinite loop
-
getUpdate
public NodeList<Expression> getUpdate()
- Returns:
- the update
-
getBody
public Statement getBody()
- Returns:
- the body
-
setBody
public void setBody(Statement body)
Replaces the loop body, reparenting old and new nodes.- Parameters:
body- the new body
-
setLabel
public void setLabel(String label)
Sets the loop label.- Parameters:
label- the new label, or null for none
-
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.
-
infinite
public static ForStmt infinite(Statement body)
Creates a conditionless for loop.- Parameters:
body- the loop body- Returns:
- a new infinite for loop
-
isInfinite
public boolean isInfinite()
- Returns:
- true if this loop has no condition
-
addInit
public void addInit(Statement stmt)
Appends an initializer statement, ignoring null.- Parameters:
stmt- the statement to append
-
addUpdate
public void addUpdate(Expression expr)
Appends an update expression, ignoring null.- Parameters:
expr- the expression to append
-
getLabel
public String getLabel()
Description copied from interface:StatementGets the label for this statement, if any.
-
withCondition
public ForStmt withCondition(Expression condition)
Replaces the loop condition, reparenting old and new nodes.- Parameters:
condition- the new condition, or null for an infinite loop- Returns:
- this statement
-
withBody
public ForStmt withBody(Statement body)
Replaces the loop body, reparenting old and new nodes.- Parameters:
body- the new body- Returns:
- this statement
-
withLabel
public ForStmt withLabel(String label)
Sets the loop label.- Parameters:
label- the new label, or null for none- 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
-
-