Package: org.codehaus.groovy.ast.stmt

## [Java] Class ReturnStatement

- org.codehaus.groovy.ast.stmt.ReturnStatement

-     public class ReturnStatement
      extends Statement

  Represents a return statement that terminates a method and optionally returns a value. A return statement evaluates the optional return expression and returns control and the resulting value to the calling code. A return with no expression returns null or void depending on the method signature.

  See Also:
    ExpressionStatement
    Statement

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static ReturnStatement` | `RETURN_NULL_OR_VOID` | Only used for synthetic return statements emitted by the compiler.

  - ### Constructor Summary

    Constructors
    Constructor and description
    `ReturnStatement(ExpressionStatement statement)` Constructs a return statement from an expression statement by extracting its expression.
    `ReturnStatement(Expression expression)` Constructs a return statement with the given return expression.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public Expression` | `getExpression()` Returns the expression whose value will be returned.
    `` | `public String` | `getText()`
    `` | `public boolean` | `isReturningNullOrVoid()` Checks whether this return statement returns null or void.
    `` | `public void` | `setExpression(Expression expression)` Sets the expression whose value will be returned.
    `` | `public String` | `toString()`
    `` | `public void` | `visit(GroovyCodeVisitor visitor)`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Statement` | `addStatementAnnotation, addStatementLabel, copyStatementLabels, getStatementAnnotations, getStatementLabel, getStatementLabels, isEmpty, setStatementLabel`
    `class ASTNode` | `copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit`

- - ### Field Detail

    - #### public static final ReturnStatement RETURN_NULL_OR_VOID

      Only used for synthetic return statements emitted by the compiler. For comparisons use isReturningNullOrVoid() instead.

  - ### Constructor Detail

    - #### public ReturnStatement(ExpressionStatement statement)

      Constructs a return statement from an expression statement by extracting its expression.

      Parameters:
        `statement` - the ExpressionStatement whose expression will be returned

    - #### public ReturnStatement(Expression expression)

      Constructs a return statement with the given return expression.

      Parameters:
        `expression` - the Expression to return, or null to return without a value

  - ### Method Detail

    - #### public Expression getExpression()

      Returns the expression whose value will be returned.

      Returns:
        the Expression to return, or null if returning without a value

    - #### public String getText()

    - #### public boolean isReturningNullOrVoid()

      Checks whether this return statement returns null or void. This method is used to identify implicit or synthetic return statements generated by the compiler.

      Returns:
        true if the return expression is a null constant; false otherwise

    - #### public void setExpression(Expression expression)

      Sets the expression whose value will be returned.

      Parameters:
        `expression` - the Expression to return

    - #### public String toString()

    - #### public void visit(GroovyCodeVisitor visitor)