Top Description Inners Methods
org.springframework.aot.generate

public Interface MethodReference

Known Direct Implementers
org.springframework.aot.generate.DefaultMethodReference
Imports
java.util.function.Function, org.springframework.javapoet.ClassName, .CodeBlock, .TypeName, org.springframework.lang.Nullable

A reference to a method with convenient code generation for referencing, or invoking it.
Authors
Stephane Nicoll, Phillip Webb
Since
6.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
MethodReference.ArgumentCodeGenerator

Strategy for generating code for arguments based on their type.

Method Summary

Modifier and TypeMethod and Description
public CodeBlock

Returns:

a code block for the method reference.
toCodeBlock
()

Return this method reference as a CodeBlock.

public default CodeBlock

Returns:

a code block to invoke the method
toInvokeCodeBlock
(MethodReference.ArgumentCodeGenerator
the argument code generator to use
argumentCodeGenerator
)

Return this method reference as a CodeBlock using the specified ArgumentCodeGenerator.

public CodeBlock

Returns:

a code block to invoke the method
toInvokeCodeBlock
(MethodReference.ArgumentCodeGenerator
the argument code generator to use
argumentCodeGenerator
,
ClassName
the target class name
targetClassName
)

Return this method reference as a CodeBlock using the specified ArgumentCodeGenerator.

Method Detail

toCodeBlockback to summary
public 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:CodeBlock

a code block for the method reference.

toInvokeCodeBlockback to summary
public default CodeBlock toInvokeCodeBlock(MethodReference.ArgumentCodeGenerator argumentCodeGenerator)

Return this method reference as a CodeBlock using the specified ArgumentCodeGenerator.

Parameters
argumentCodeGenerator:MethodReference.ArgumentCodeGenerator

the argument code generator to use

Returns:CodeBlock

a code block to invoke the method

toInvokeCodeBlockback to summary
public CodeBlock toInvokeCodeBlock(MethodReference.ArgumentCodeGenerator argumentCodeGenerator, ClassName targetClassName)

Return this method reference as a CodeBlock using the specified 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.

Parameters
argumentCodeGenerator:MethodReference.ArgumentCodeGenerator

the argument code generator to use

targetClassName:ClassName

the target class name

Returns:CodeBlock

a code block to invoke the method

org.springframework.aot.generate back to summary

public Interface MethodReference.ArgumentCodeGenerator


Strategy for generating code for arguments based on their type.

Method Summary

Modifier and TypeMethod and Description
public default MethodReference.ArgumentCodeGenerator

Returns:

a new composite ArgumentCodeGenerator instance
and
(Class<?>
the argument type
argumentType
,
String
the code for an argument of that type
argumentCode
)

Create a new composed ArgumentCodeGenerator by combining this generator with supporting the given argument type.

public default MethodReference.ArgumentCodeGenerator

Returns:

a new composite ArgumentCodeGenerator instance
and
(MethodReference.ArgumentCodeGenerator
the argument generator to add
argumentCodeGenerator
)

Create a new composed ArgumentCodeGenerator by combining this generator with the given generator.

public static MethodReference.ArgumentCodeGenerator

Returns:

a new ArgumentCodeGenerator instance backed by the function
from
(Function<TypeName, CodeBlock>
the resolver function
function
)

Factory method that creates a new ArgumentCodeGenerator from a lambda friendly function.

public CodeBlock

Returns:

the code for this argument, or null
generateCode
(TypeName
the argument type
argumentType
)

Generate the code for the given argument type.

public static MethodReference.ArgumentCodeGenerator

Returns:

a new ArgumentCodeGenerator instance
none
()

Factory method that returns an ArgumentCodeGenerator that always returns null.

public static MethodReference.ArgumentCodeGenerator

Returns:

a new ArgumentCodeGenerator instance
of
(Class<?>
the argument type
argumentType
,
String
the code for an argument of that type
argumentCode
)

Factory method that can be used to create an ArgumentCodeGenerator that support only the given argument type.

Method Detail

andback to summary
public default MethodReference.ArgumentCodeGenerator and(Class<?> argumentType, String argumentCode)

Create a new composed ArgumentCodeGenerator by combining this generator with supporting the given argument type.

Parameters
argumentType:Class<?>

the argument type

argumentCode:String

the code for an argument of that type

Returns:MethodReference.ArgumentCodeGenerator

a new composite ArgumentCodeGenerator instance

andback to summary
public default MethodReference.ArgumentCodeGenerator and(MethodReference.ArgumentCodeGenerator argumentCodeGenerator)

Create a new composed ArgumentCodeGenerator by combining this generator with the given generator.

Parameters
argumentCodeGenerator:MethodReference.ArgumentCodeGenerator

the argument generator to add

Returns:MethodReference.ArgumentCodeGenerator

a new composite ArgumentCodeGenerator instance

fromback to summary
public static MethodReference.ArgumentCodeGenerator from(Function<TypeName, CodeBlock> function)

Factory method that creates a new ArgumentCodeGenerator from a lambda friendly function. The given function is provided with the argument type and must provide the code to use or null if the type is not supported.

Parameters
function:Function<TypeName, CodeBlock>

the resolver function

Returns:MethodReference.ArgumentCodeGenerator

a new ArgumentCodeGenerator instance backed by the function

generateCodeback to summary
public CodeBlock generateCode(TypeName argumentType)

Generate the code for the given argument type. If this type is not supported, return null.

Parameters
argumentType:TypeName

the argument type

Returns:CodeBlock

the code for this argument, or null

Annotations
@Nullable
noneback to summary
public static MethodReference.ArgumentCodeGenerator none()

Factory method that returns an ArgumentCodeGenerator that always returns null.

Returns:MethodReference.ArgumentCodeGenerator

a new ArgumentCodeGenerator instance

ofback to summary
public static MethodReference.ArgumentCodeGenerator of(Class<?> argumentType, String argumentCode)

Factory method that can be used to create an ArgumentCodeGenerator that support only the given argument type.

Parameters
argumentType:Class<?>

the argument type

argumentCode:String

the code for an argument of that type

Returns:MethodReference.ArgumentCodeGenerator

a new ArgumentCodeGenerator instance