Class BlockStmt
- java.lang.Object
-
- com.tonic.analysis.source.ast.stmt.BlockStmt
-
-
Constructor Summary
Constructors Constructor Description BlockStmt()Creates an empty block.BlockStmt(List<Statement> statements)Creates a block containing the given statements with an unknown location.BlockStmt(List<Statement> statements, SourceLocation location)Creates a block containing the given statements, skipping null entries.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.voidaddStatement(Statement stmt)Appends a statement to this block, ignoring null.List<ASTNode>getChildren()Lists the direct children a node holds, in source order.SourceLocationgetLocation()Gets the source location of this node.ASTNodegetParent()Gets the parent node in the AST tree.NodeList<Statement>getStatements()voidinsertStatement(int index, Statement stmt)Inserts a statement at the given index, ignoring null.booleanisEmpty()booleanremoveStatement(Statement stmt)Removes a statement from this block.voidsetLocation(SourceLocation location)Sets this statement's source location.voidsetParent(ASTNode parent)Sets the enclosing AST node.intsize()StringtoString()-
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
-
BlockStmt
public BlockStmt(List<Statement> statements, SourceLocation location)
Creates a block containing the given statements, skipping null entries.- Parameters:
statements- initial statements, or null for nonelocation- source location, or null for unknown
-
BlockStmt
public BlockStmt(List<Statement> statements)
Creates a block containing the given statements with an unknown location.- Parameters:
statements- initial statements, or null for none
-
BlockStmt
public BlockStmt()
Creates an empty block.
-
-
Method Detail
-
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.
-
addStatement
public void addStatement(Statement stmt)
Appends a statement to this block, ignoring null.- Parameters:
stmt- the statement to append
-
insertStatement
public void insertStatement(int index, Statement stmt)Inserts a statement at the given index, ignoring null.- Parameters:
index- position at which to insertstmt- the statement to insert
-
removeStatement
public boolean removeStatement(Statement stmt)
Removes a statement from this block.- Parameters:
stmt- the statement to remove- Returns:
- true if the statement was present
-
isEmpty
public boolean isEmpty()
- Returns:
- true if this block has no statements
-
size
public int size()
- Returns:
- the number of statements in this block
-
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
-
-