Class TryStatement

All Implemented Interfaces:
Comparable<AstNode>, Iterable<Node>

public class TryStatement extends AstNode
Try/catch/finally statement. Node type is Token.TRY.
TryStatement :
        try Block Catch
        try Block Finally
        try Block Catch Finally
 Catch :
        catch ( Identifier ) Block
 Finally :
        finally Block
  • Constructor Details

    • TryStatement

      public TryStatement()
    • TryStatement

      public TryStatement(int pos)
    • TryStatement

      public TryStatement(int pos, int len)
  • Method Details

    • getTryBlock

      public AstNode getTryBlock()
    • setTryBlock

      public void setTryBlock(AstNode tryBlock)
      Sets try block. Also sets its parent to this node.
      Throws:
      IllegalArgumentException - } if tryBlock is null
    • getCatchClauses

      public List<CatchClause> getCatchClauses()
      Returns list of CatchClause nodes. If there are no catch clauses, returns an immutable empty list.
    • setCatchClauses

      public void setCatchClauses(List<CatchClause> catchClauses)
      Sets list of CatchClause nodes. Also sets their parents to this node. May be null. Replaces any existing catch clauses for this node.
    • addCatchClause

      public void addCatchClause(CatchClause clause)
      Add a catch-clause to the end of the list, and sets its parent to this node.
      Throws:
      IllegalArgumentException - } if clause is null
    • getFinallyBlock

      public AstNode getFinallyBlock()
      Returns finally block, or null if not present
    • setFinallyBlock

      public void setFinallyBlock(AstNode finallyBlock)
      Sets finally block, and sets its parent to this node. May be null.
    • getFinallyPosition

      public int getFinallyPosition()
      Returns position of finally keyword, if present, or -1
    • setFinallyPosition

      public void setFinallyPosition(int finallyPosition)
      Sets position of finally keyword, if present, or -1
    • toSource

      public String toSource(int depth)
      Description copied from class: AstNode
      Emits source code for this node. Callee is responsible for calling this function recursively on children, incrementing indent as appropriate.

      Note: if the parser was in error-recovery mode, some AST nodes may have null children that are expected to be non-null when no errors are present. In this situation, the behavior of the toSource method is undefined: toSource implementations may assume that the AST node is error-free, since it is intended to be invoked only at runtime after a successful parse.

      Specified by:
      toSource in class AstNode
      Parameters:
      depth - the current recursion depth, typically beginning at 0 when called on the root node.
    • visit

      public void visit(NodeVisitor v)
      Visits this node, then the try-block, then any catch clauses, and then any finally block.
      Specified by:
      visit in class AstNode
      Parameters:
      v - the object to call with this node and its children