Class MethodReference

java.lang.Object
org.springframework.aot.generate.MethodReference

public final class MethodReference extends Object
A reference to a static or instance method.
Since:
6.0
Author:
Phillip Webb
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.javapoet.ClassName
    Return the referenced declaring class.
    Return the referenced method name.
    of(Class<?> declaringClass, String methodName)
    Create a new method reference that refers to the given instance method.
    of(String methodName)
    Create a new method reference that refers to the given instance method.
    of(org.springframework.javapoet.ClassName declaringClass, String methodName)
    Create a new method reference that refers to the given instance method.
    ofStatic(Class<?> declaringClass, String methodName)
    Create a new method reference that refers to the given static method.
    ofStatic(org.springframework.javapoet.ClassName declaringClass, String methodName)
    Create a new method reference that refers to the given static method.
    org.springframework.javapoet.CodeBlock
    Return this method reference as a CodeBlock.
    org.springframework.javapoet.CodeBlock
    toCodeBlock(String instanceVariable)
    Return this method reference as a CodeBlock.
    org.springframework.javapoet.CodeBlock
    toInvokeCodeBlock(String instanceVariable, org.springframework.javapoet.CodeBlock... arguments)
    Return this method reference as an invocation CodeBlock.
    org.springframework.javapoet.CodeBlock
    toInvokeCodeBlock(org.springframework.javapoet.CodeBlock... arguments)
    Return this method reference as an invocation CodeBlock.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Method Details

    • of

      public static MethodReference of(String methodName)
      Create a new method reference that refers to the given instance method.
      Parameters:
      methodName - the method name
      Returns:
      a new MethodReference instance
    • of

      public static MethodReference of(Class<?> declaringClass, String methodName)
      Create a new method reference that refers to the given instance method.
      Parameters:
      declaringClass - the declaring class
      methodName - the method name
      Returns:
      a new MethodReference instance
    • of

      public static MethodReference of(org.springframework.javapoet.ClassName declaringClass, String methodName)
      Create a new method reference that refers to the given instance method.
      Parameters:
      declaringClass - the declaring class
      methodName - the method name
      Returns:
      a new MethodReference instance
    • ofStatic

      public static MethodReference ofStatic(Class<?> declaringClass, String methodName)
      Create a new method reference that refers to the given static method.
      Parameters:
      declaringClass - the declaring class
      methodName - the method name
      Returns:
      a new MethodReference instance
    • ofStatic

      public static MethodReference ofStatic(org.springframework.javapoet.ClassName declaringClass, String methodName)
      Create a new method reference that refers to the given static method.
      Parameters:
      declaringClass - the declaring class
      methodName - the method name
      Returns:
      a new MethodReference instance
    • getDeclaringClass

      public org.springframework.javapoet.ClassName getDeclaringClass()
      Return the referenced declaring class.
      Returns:
      the declaring class
    • getMethodName

      public String getMethodName()
      Return the referenced method name.
      Returns:
      the method name
    • toCodeBlock

      public org.springframework.javapoet.CodeBlock toCodeBlock()
      Return this method reference as a CodeBlock. If the reference is to an instance method then this::<method name> will be returned.
      Returns:
      a code block for the method reference.
      See Also:
    • toCodeBlock

      public org.springframework.javapoet.CodeBlock toCodeBlock(@Nullable String instanceVariable)
      Return this method reference as a CodeBlock. If the reference is to an instance method and instanceVariable is null then this::<method name> will be returned. No instanceVariable can be specified for static method references.
      Parameters:
      instanceVariable - the instance variable or null
      Returns:
      a code block for the method reference.
      See Also:
    • toInvokeCodeBlock

      public org.springframework.javapoet.CodeBlock toInvokeCodeBlock(org.springframework.javapoet.CodeBlock... arguments)
      Return this method reference as an invocation CodeBlock.
      Parameters:
      arguments - the method arguments
      Returns:
      a code back to invoke the method
    • toInvokeCodeBlock

      public org.springframework.javapoet.CodeBlock toInvokeCodeBlock(@Nullable String instanceVariable, org.springframework.javapoet.CodeBlock... arguments)
      Return this method reference as an invocation CodeBlock.
      Parameters:
      instanceVariable - the instance variable or null
      arguments - the method arguments
      Returns:
      a code back to invoke the method
    • toString

      public String toString()
      Overrides:
      toString in class Object