Class ForEachStmt
- java.lang.Object
-
- com.tonic.analysis.source.ast.stmt.ForEachStmt
-
-
Constructor Summary
Constructors Constructor Description ForEachStmt(VarDeclStmt variable, Expression iterable, Statement body)Creates an unlabeled enhanced for loop with an unknown location.ForEachStmt(VarDeclStmt variable, Expression iterable, Statement body, String label, SourceLocation location)Creates an enhanced for loop 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.StatementgetBody()List<ASTNode>getChildren()Lists the direct children a node holds, in source order.ExpressiongetIterable()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.VarDeclStmtgetVariable()voidsetBody(Statement body)Replaces the loop body, reparenting old and new nodes.voidsetIterable(Expression iterable)Replaces the iterated expression, reparenting old and new nodes.voidsetLabel(String label)Sets the label used by labeled break and continue targeting this loop.voidsetLocation(SourceLocation location)Sets this statement's source location.voidsetParent(ASTNode parent)Sets the enclosing AST node.voidsetVariable(VarDeclStmt variable)Replaces the loop variable declaration, reparenting old and new nodes.StringtoString()ForEachStmtwithBody(Statement body)Replaces the loop body, reparenting old and new nodes.ForEachStmtwithIterable(Expression iterable)Replaces the iterated expression, reparenting old and new nodes.ForEachStmtwithLabel(String label)Sets the loop label.ForEachStmtwithVariable(VarDeclStmt variable)Replaces the loop variable declaration, 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
-
ForEachStmt
public ForEachStmt(VarDeclStmt variable, Expression iterable, Statement body, String label, SourceLocation location)
Creates an enhanced for loop and parents its children to it.- Parameters:
variable- declaration of the loop variableiterable- the iterated expressionbody- the loop bodylabel- loop label, or null for nonelocation- source location, or null for unknown- Throws:
NullPointerException- if variable, iterable, or body is null
-
ForEachStmt
public ForEachStmt(VarDeclStmt variable, Expression iterable, Statement body)
Creates an unlabeled enhanced for loop with an unknown location.- Parameters:
variable- declaration of the loop variableiterable- the iterated expressionbody- the loop body- Throws:
NullPointerException- if variable, iterable, or body is null
-
-
Method Detail
-
getVariable
public VarDeclStmt getVariable()
- Returns:
- the variable
-
setVariable
public void setVariable(VarDeclStmt variable)
Replaces the loop variable declaration, reparenting old and new nodes.- Parameters:
variable- the new loop variable declaration
-
getIterable
public Expression getIterable()
- Returns:
- the iterable
-
setIterable
public void setIterable(Expression iterable)
Replaces the iterated expression, reparenting old and new nodes.- Parameters:
iterable- the new iterated expression
-
getBody
public Statement getBody()
- Returns:
- the loop 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 label used by labeled break and continue targeting this loop.- Parameters:
label- the label, 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.
-
getLabel
public String getLabel()
Description copied from interface:StatementGets the label for this statement, if any.
-
withVariable
public ForEachStmt withVariable(VarDeclStmt variable)
Replaces the loop variable declaration, reparenting old and new nodes.- Parameters:
variable- the new loop variable declaration- Returns:
- this statement
-
withIterable
public ForEachStmt withIterable(Expression iterable)
Replaces the iterated expression, reparenting old and new nodes.- Parameters:
iterable- the new iterated expression- Returns:
- this statement
-
withBody
public ForEachStmt withBody(Statement body)
Replaces the loop body, reparenting old and new nodes.- Parameters:
body- the new body- Returns:
- this statement
-
withLabel
public ForEachStmt 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
-
-