Class ThrowStmt

  • All Implemented Interfaces:
    ASTNode, Statement

    public final class ThrowStmt
    extends Object
    implements Statement
    A throw statement, owning the thrown expression as its only child.
    • Constructor Detail

      • ThrowStmt

        public ThrowStmt​(Expression exception,
                         SourceLocation location)
        Creates a throw statement and adopts the thrown expression.
        Parameters:
        exception - the expression to throw
        location - source position, null for unknown
        Throws:
        NullPointerException - if the exception expression is null
      • ThrowStmt

        public ThrowStmt​(Expression exception)
        Creates a throw statement with an unknown source position.
        Parameters:
        exception - the expression to throw
        Throws:
        NullPointerException - if the exception expression is null
    • Method Detail

      • getException

        public Expression getException()
        Returns:
        the exception
      • setException

        public void setException​(Expression exception)
        Replaces the thrown expression, adopting the new one and detaching the old.
        Parameters:
        exception - the new expression to throw, may be null
      • getLocation

        public SourceLocation getLocation()
        Description copied from interface: ASTNode
        Gets the source location of this node.
        Specified by:
        getLocation in interface ASTNode
        Returns:
        the location
      • getParent

        public ASTNode getParent()
        Description copied from interface: ASTNode
        Gets the parent node in the AST tree.
        Specified by:
        getParent in interface ASTNode
        Returns:
        the parent
      • setParent

        public void setParent​(ASTNode parent)
        Sets the enclosing node.
        Specified by:
        setParent in interface ASTNode
        Parameters:
        parent - the new parent, may be null
      • withExpression

        public ThrowStmt withExpression​(Expression exception)
        Replaces the thrown expression in place, for chaining.
        Parameters:
        exception - the new expression to throw
        Returns:
        this statement
        Throws:
        NullPointerException - if the exception expression is null
      • getChildren

        public List<ASTNode> getChildren()
        Description copied from interface: ASTNode
        Lists the direct children a node holds, in source order.
        Specified by:
        getChildren in interface ASTNode
        Returns:
        the direct children, empty for a leaf
      • accept

        public <T> T accept​(SourceVisitor<T> visitor)
        Description copied from interface: ASTNode
        Accepts a visitor for this node.
        Specified by:
        accept in interface ASTNode
        Type Parameters:
        T - the return type of the visitor
        Parameters:
        visitor - the visitor to accept
        Returns:
        the result from the visitor