Package org.springframework.aot.generate

# Class DefaultMethodReference

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

All Implemented Interfaces:
  `MethodReference`

public class DefaultMethodReference extends Object implements MethodReference
Default `MethodReference` implementation based on a `MethodSpec`.

Since:
  6.0
Author:
  Stephane Nicoll, Phillip Webb

## Nested Class Summary

## Nested classes/interfaces inherited from interface org.springframework.aot.generate.MethodReference

`MethodReference.ArgumentCodeGenerator`

## Constructor Summary

Constructors
Constructor
Description
`DefaultMethodReference(org.springframework.javapoet.MethodSpec method, org.springframework.javapoet.ClassName declaringClass)`

## Method Summary

Modifier and Type
Method
Description
`protected void`
`addArguments(org.springframework.javapoet.CodeBlock.Builder code, MethodReference.ArgumentCodeGenerator argumentCodeGenerator)`
Add the code for the method arguments using the specified `MethodReference.ArgumentCodeGenerator` if necessary.
`protected org.springframework.javapoet.CodeBlock`
`instantiateDeclaringClass(org.springframework.javapoet.ClassName declaringClass)`
`org.springframework.javapoet.CodeBlock`
`toCodeBlock()`
Return this method reference as a `CodeBlock`.
`org.springframework.javapoet.CodeBlock`
`toInvokeCodeBlock(MethodReference.ArgumentCodeGenerator argumentCodeGenerator, org.springframework.javapoet.ClassName targetClassName)`
Return this method reference as a `CodeBlock` using the specified `MethodReference.ArgumentCodeGenerator`.
`String`
`toString()`

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

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

### Methods inherited from interface org.springframework.aot.generate.MethodReference

`toInvokeCodeBlock`

## Constructor Details

### DefaultMethodReference

public DefaultMethodReference(org.springframework.javapoet.MethodSpec method, @Nullable org.springframework.javapoet.ClassName declaringClass)

## Method Details

### toCodeBlock

public org.springframework.javapoet.CodeBlock toCodeBlock()
Description copied from interface: `MethodReference`
Return this method reference as a `CodeBlock`. If the reference is to an instance method then `this::<method name>` will be returned.

Specified by:
  `toCodeBlock` in interface `MethodReference`
Returns:
  a code block for the method reference.

### toInvokeCodeBlock

public org.springframework.javapoet.CodeBlock toInvokeCodeBlock(MethodReference.ArgumentCodeGenerator argumentCodeGenerator, @Nullable org.springframework.javapoet.ClassName targetClassName)
Description copied from interface: `MethodReference`
Return this method reference as a `CodeBlock` using the specified `MethodReference.ArgumentCodeGenerator`. The `targetClassName` defines the context in which the method invocation is added.

If the caller has an instance of the type in which this method is defined, it can hint that by specifying the type as a target class.

Specified by:
  `toInvokeCodeBlock` in interface `MethodReference`
Parameters:
  `argumentCodeGenerator` - the argument code generator to use
  `targetClassName` - the target class name
Returns:
  a code block to invoke the method

### addArguments

protected void addArguments(org.springframework.javapoet.CodeBlock.Builder code, MethodReference.ArgumentCodeGenerator argumentCodeGenerator)
Add the code for the method arguments using the specified `MethodReference.ArgumentCodeGenerator` if necessary.

Parameters:
  `code` - the code builder to use to add method arguments
  `argumentCodeGenerator` - the code generator to use

### instantiateDeclaringClass

protected org.springframework.javapoet.CodeBlock instantiateDeclaringClass(org.springframework.javapoet.ClassName declaringClass)

### toString

public String toString()

Overrides:
  `toString` in class `Object`