Class TryCatchStmt
- java.lang.Object
-
- com.tonic.analysis.source.ast.stmt.TryCatchStmt
-
-
Constructor Summary
Constructors Constructor Description TryCatchStmt(Statement tryBlock, List<CatchClause> catches)Creates a try statement with no finally block, no resources and an unknown location.TryCatchStmt(Statement tryBlock, List<CatchClause> catches, Statement finallyBlock)Creates a try statement with no resources and an unknown location.TryCatchStmt(Statement tryBlock, List<CatchClause> catches, Statement finallyBlock, List<Expression> resources, SourceLocation location)Creates a try statement, adopting the try block, catch bodies, finally block and resources 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.voidaddCatch(CatchClause clause)Appends a catch clause and adopts its body.voidaddResource(Expression resource)Appends a try-with-resources resource.List<CatchClause>getCatches()List<ASTNode>getChildren()Lists the direct children a node holds, in source order.StatementgetFinallyBlock()SourceLocationgetLocation()Gets the source location of this node.ASTNodegetParent()Gets the parent node in the AST tree.NodeList<Expression>getResources()StatementgetTryBlock()booleanhasCatch()booleanhasFinally()booleanhasResources()voidsetFinallyBlock(Statement finallyBlock)Replaces the finally block, reparenting it and releasing the previous one.voidsetLocation(SourceLocation location)Sets this statement's source location.voidsetParent(ASTNode parent)Sets the node this statement hangs from.voidsetTryBlock(Statement tryBlock)Replaces the guarded block, reparenting it and releasing the previous one.StringtoString()TryCatchStmtwithFinallyBlock(Statement finallyBlock)Replaces the finally block in place, reparenting it and releasing the previous one.TryCatchStmtwithTryBlock(Statement tryBlock)Replaces the guarded block in place, reparenting it and releasing the previous one.-
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
-
TryCatchStmt
public TryCatchStmt(Statement tryBlock, List<CatchClause> catches, Statement finallyBlock, List<Expression> resources, SourceLocation location)
Creates a try statement, adopting the try block, catch bodies, finally block and resources as children.- Parameters:
tryBlock- the guarded blockcatches- the catch clauses, may be null for nonefinallyBlock- the finally block, or nullresources- the try-with-resources expressions, may be null for nonelocation- the source location, or null for unknown- Throws:
NullPointerException- if the try block is null
-
TryCatchStmt
public TryCatchStmt(Statement tryBlock, List<CatchClause> catches, Statement finallyBlock)
Creates a try statement with no resources and an unknown location.- Parameters:
tryBlock- the guarded blockcatches- the catch clauses, may be null for nonefinallyBlock- the finally block, or null- Throws:
NullPointerException- if the try block is null
-
TryCatchStmt
public TryCatchStmt(Statement tryBlock, List<CatchClause> catches)
Creates a try statement with no finally block, no resources and an unknown location.- Parameters:
tryBlock- the guarded blockcatches- the catch clauses, may be null for none- Throws:
NullPointerException- if the try block is null
-
-
Method Detail
-
getTryBlock
public Statement getTryBlock()
- Returns:
- the try block
-
setTryBlock
public void setTryBlock(Statement tryBlock)
Replaces the guarded block, reparenting it and releasing the previous one.- Parameters:
tryBlock- the new try block
-
getCatches
public List<CatchClause> getCatches()
- Returns:
- the catches
-
getFinallyBlock
public Statement getFinallyBlock()
- Returns:
- the finally block
-
setFinallyBlock
public void setFinallyBlock(Statement finallyBlock)
Replaces the finally block, reparenting it and releasing the previous one.- Parameters:
finallyBlock- the new finally block, or null to drop it
-
getResources
public NodeList<Expression> getResources()
- Returns:
- the try-with-resources declarations, empty when there are 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 node this statement hangs from.
-
addCatch
public void addCatch(CatchClause clause)
Appends a catch clause and adopts its body.- Parameters:
clause- the clause to add
-
addResource
public void addResource(Expression resource)
Appends a try-with-resources resource.- Parameters:
resource- the resource expression
-
hasResources
public boolean hasResources()
- Returns:
- whether this is a try-with-resources statement
-
hasFinally
public boolean hasFinally()
- Returns:
- whether a finally block is present
-
hasCatch
public boolean hasCatch()
- Returns:
- whether any catch clause is present
-
withTryBlock
public TryCatchStmt withTryBlock(Statement tryBlock)
Replaces the guarded block in place, reparenting it and releasing the previous one.- Parameters:
tryBlock- the new try block, may be null- Returns:
- this statement
-
withFinallyBlock
public TryCatchStmt withFinallyBlock(Statement finallyBlock)
Replaces the finally block in place, reparenting it and releasing the previous one.- Parameters:
finallyBlock- the new finally block, 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
-
-