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
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
FieldsModifier and TypeFieldDescriptionstatic final ReturnStatementOnly used for synthetic return statements emitted by the compiler. -
Constructor Summary
ConstructorsConstructorDescriptionReturnStatement(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 TypeMethodDescriptionReturns the expression whose value will be returned.getText()Returns a human-readable text representation of this AST node.booleanChecks whether this return statement returns null or void.voidsetExpression(Expression expression) Sets the expression whose value will be returned.toString()voidvisit(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, setStatementLabelMethods inherited from class org.codehaus.groovy.ast.ASTNode
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePositionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler
copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData
-
Field Details
-
RETURN_NULL_OR_VOID
Only used for synthetic return statements emitted by the compiler. For comparisons use isReturningNullOrVoid() instead.
-
-
Constructor Details
-
ReturnStatement
Constructs a return statement from an expression statement by extracting its expression.- Parameters:
statement- theExpressionStatementwhose expression will be returned
-
ReturnStatement
Constructs a return statement with the given return expression.- Parameters:
expression- theExpressionto return, or null to return without a value
-
-
Method Details
-
getExpression
Returns the expression whose value will be returned.- Returns:
- the
Expressionto return, or null if returning without a value
-
setExpression
Sets the expression whose value will be returned.- Parameters:
expression- theExpressionto return
-
getText
Description copied from class:ASTNodeReturns 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. -
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
-
visit
Description copied from class:ASTNodeAccepts 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:
visitin classASTNode- Parameters:
visitor- theGroovyCodeVisitorto process this node
-