Class ExprStmt

  • All Implemented Interfaces:
    ASTNode, Statement

    public final class ExprStmt
    extends Object
    implements Statement
    An expression used as a statement, such as a call, assignment, or increment.
    • Constructor Detail

      • ExprStmt

        public ExprStmt​(Expression expression,
                        SourceLocation location)
        Creates an expression statement and parents the expression to it.
        Parameters:
        expression - the wrapped expression
        location - source location, or null for unknown
        Throws:
        NullPointerException - if expression is null
      • ExprStmt

        public ExprStmt​(Expression expression)
        Creates an expression statement with an unknown location.
        Parameters:
        expression - the wrapped expression
        Throws:
        NullPointerException - if expression is null
    • Method Detail

      • getExpression

        public Expression getExpression()
        Returns:
        the expression
      • setExpression

        public void setExpression​(Expression expression)
        Replaces the wrapped expression, reparenting old and new nodes.
        Parameters:
        expression - the new expression
      • 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 AST node.
        Specified by:
        setParent in interface ASTNode
        Parameters:
        parent - the new parent node
      • withExpression

        public ExprStmt withExpression​(Expression expression)
        Replaces the wrapped expression, reparenting old and new nodes.
        Parameters:
        expression - the new expression
        Returns:
        this statement
        Throws:
        NullPointerException - if 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