Class ReturnStmt

  • All Implemented Interfaces:
    ASTNode, Statement

    public final class ReturnStmt
    extends Object
    implements Statement
    A return statement with an optional value expression.
    • Constructor Detail

      • ReturnStmt

        public ReturnStmt​(Expression value,
                          SourceLocation location)
        Creates a return statement and parents the value to it when present.
        Parameters:
        value - the returned expression, or null for a void return
        location - source location, or null for unknown
      • ReturnStmt

        public ReturnStmt​(Expression value)
        Creates a return statement with an unknown location.
        Parameters:
        value - the returned expression, or null for a void return
      • ReturnStmt

        public ReturnStmt()
        Creates a void return statement.
    • Method Detail

      • getValue

        public Expression getValue()
        Returns:
        the value
      • setValue

        public void setValue​(Expression value)
        Replaces the returned expression, reparenting old and new nodes.
        Parameters:
        value - the new value, or null for a void return
      • 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
      • getMethodReturnType

        public SourceType getMethodReturnType()
        Returns:
        the method return type
      • setMethodReturnType

        public void setMethodReturnType​(SourceType methodReturnType)
        Sets the declared return type of the enclosing method.
        Parameters:
        methodReturnType - the enclosing method's return type
      • isVoidReturn

        public boolean isVoidReturn()
        Returns:
        true if this return has no value
      • withValue

        public ReturnStmt withValue​(Expression value)
        Replaces the returned expression, reparenting old and new nodes.
        Parameters:
        value - the new value, or null for a void return
        Returns:
        this statement
      • 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