Class MethodReturn

java.lang.Object
org.springframework.data.repository.aot.generate.MethodReturn

public class MethodReturn extends Object
Value object that encapsulates introspection of a method's return type, providing convenient access to its characteristics such as projection, optionality, array status, and actual type information.

Designed to support repository method analysis in the context of Ahead-of-Time (AOT) processing, this class leverages ReturnedType, ResolvableType, and TypeInformation to expose both the declared and actual return types, including handling of wrapper types, projections, and primitive types.

Typical usage involves querying the return type characteristics to drive code generation or runtime behavior in repository infrastructure.

Since:
4.0
Author:
Mark Paluch
  • Constructor Details

    • MethodReturn

      public MethodReturn(ReturnedType returnedType, ResolvableType returnType)
      Create a new MethodReturn instance based on the given ReturnedType and its method return type.
      Parameters:
      returnedType - the returned type to inspect.
      returnType - the method return type.
  • Method Details

    • isProjecting

      public boolean isProjecting()
      Returns whether the method return type is a projection. Query projections (e.g. returning String or int are not considered.
      Returns:
      true if the return type is a projection.
    • isInterfaceProjection

      public boolean isInterfaceProjection()
      Returns whether the method return type is an interface-based projection.
      Returns:
      true if the return type is an interface-based projection.
    • isOptional

      public boolean isOptional()
      Returns whether the method return type is Optional.
      Returns:
      true if the return type is Optional.
    • isArray

      public boolean isArray()
      Returns whether the method return type is an array.
      Returns:
      true if the return type is an array.
    • isVoid

      public boolean isVoid()
      Returns whether the method return type is void. Considers also Void and Kotlin's Unit.
      Returns:
      true if the return type is void.
    • toClass

      public Class<?> toClass()
      Returns the Class representing the declared return type.
      Returns:
      the declared return class.
    • getActualType

      public ResolvableType getActualType()
      Returns the actual type (i.e. collection component type).
      Returns:
      the actual type.
    • getTypeName

      public org.springframework.javapoet.TypeName getTypeName()
      Returns the TypeName representing the declared return type.
      Returns:
      the declared return type name.
    • getClassName

      public org.springframework.javapoet.TypeName getClassName()
      Returns the TypeName representing the declared return class (i.e. without generics).
      Returns:
      the declared return class name.
    • getActualTypeName

      public org.springframework.javapoet.TypeName getActualTypeName()
      Returns the actual TypeName representing the declared return type (component type of collections).
      Returns:
      the actual return type name.
    • getActualClassName

      public org.springframework.javapoet.TypeName getActualClassName()
      Returns the actual TypeName representing the declared return class (component type of collections).
      Returns:
      the actual return class name.
    • getActualReturnClass

      public Class<?> getActualReturnClass()
      Returns the Class representing the actual return type.
      Returns:
      the actual return class.