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.
| Modifiers | Name | Description |
|---|---|---|
static ReturnStatement |
RETURN_NULL_OR_VOID |
Only used for synthetic return statements emitted by the compiler. |
| 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. |
| 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) |
| 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 |
Only used for synthetic return statements emitted by the compiler. For comparisons use isReturningNullOrVoid() instead.
Constructs a return statement from an expression statement by extracting its expression.
statement - the ExpressionStatement whose expression will be returnedConstructs a return statement with the given return expression.
expression - the Expression to return, or null to return without a valueReturns the expression whose value will be returned.
Checks whether this return statement returns null or void. This method is used to identify implicit or synthetic return statements generated by the compiler.
Sets the expression whose value will be returned.
expression - the Expression to returnCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.