Package org.codehaus.groovy.ast.stmt

# Class ReturnStatement

java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.stmt.Statement
org.codehaus.groovy.ast.stmt.ReturnStatement

All Implemented Interfaces:
  `NodeMetaDataHandler`

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.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final ReturnStatement`
  `RETURN_NULL_OR_VOID`
  Only used for synthetic return statements emitted by the compiler.

- ## Constructor Summary

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

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Expression`
  `getExpression()`
  Returns the expression whose value will be returned.
  `String`
  `getText()`
  Returns a human-readable text representation of this AST node.
  `boolean`
  `isReturningNullOrVoid()`
  Checks whether this return statement returns null or void.
  `void`
  `setExpression(Expression expression)`
  Sets the expression whose value will be returned.
  `String`
  `toString()`
  `void`
  `visit(GroovyCodeVisitor visitor)`
  Accepts a code visitor for AST traversal and transformation.

  ### Methods inherited from class org.codehaus.groovy.ast.stmt.Statement

  `addStatementAnnotation, addStatementLabel, copyStatementLabels, getStatementAnnotations, getStatementLabel, getStatementLabels, isEmpty, setStatementLabel`

  ### Methods inherited from class org.codehaus.groovy.ast.ASTNode

  `copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler

  `copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData`

- ## Field Details

  - ### RETURN_NULL_OR_VOID

    public static final ReturnStatement RETURN_NULL_OR_VOID
    Only used for synthetic return statements emitted by the compiler. For comparisons use isReturningNullOrVoid() instead.

- ## Constructor Details

  - ### ReturnStatement

    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

  - ### ReturnStatement

    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 Details

  - ### getExpression

    public Expression getExpression()
    Returns the expression whose value will be returned.
    Returns:
      the `Expression` to return, or null if returning without a value

  - ### setExpression

    public void setExpression(Expression expression)
    Sets the expression whose value will be returned.
    Parameters:
      `expression` - the `Expression` to return

  - ### getText

    public String getText()
    Description copied from class: `ASTNode`
    Returns a human-readable text representation of this AST node. Used for debugging and error messages. Default implementation returns a message indicating the representation is not yet implemented for this node type.
    Overrides:
      `getText` in class `ASTNode`
    Returns:
      text representation of this node, or placeholder for unimplemented types

  - ### isReturningNullOrVoid

    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

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### visit

    public void visit(GroovyCodeVisitor visitor)
    Description copied from class: `ASTNode`
    Accepts a code visitor for AST traversal and transformation. Subclasses must implement this method to support visitor pattern-based processing. The visitor pattern enables decoupling of AST structure from processing logic.
    Overrides:
      `visit` in class `ASTNode`
    Parameters:
      `visitor` - the `GroovyCodeVisitor` to process this node