Top Description Fields Constructors Methods
org.springframework.aot.generate

public Class GeneratedMethods

extends Object
Class Inheritance
Imports
java.util.ArrayList, .List, java.util.function.Consumer, .Function, java.util.stream.Stream, org.springframework.javapoet.ClassName, .MethodSpec, .MethodSpec.Builder, org.springframework.util.Assert

A managed collection of generated methods.
Authors
Phillip Webb, Stephane Nicoll
Since
6.0
See Also
GeneratedMethod

Field Summary

Modifier and TypeField and Description
private final ClassName
private final List<GeneratedMethod>
private final Function<MethodName, String>
private final MethodName

Constructor Summary

AccessConstructor and Description
pack-priv
GeneratedMethods(ClassName
the declaring class name
className
,
Function<MethodName, String>
the method name generator
methodNameGenerator
)

Create a new GeneratedMethods using the specified method name generator.

private
GeneratedMethods(ClassName className, Function<MethodName, String> methodNameGenerator, MethodName prefix, List<GeneratedMethod> generatedMethods)

Method Summary

Modifier and TypeMethod and Description
public GeneratedMethod

Returns:

the newly added GeneratedMethod
add
(String
the suggested name for the method
suggestedName
,
Consumer<MethodSpec.Builder>
a Consumer used to build method
method
)

Add a new GeneratedMethod.

public GeneratedMethod

Returns:

the newly added GeneratedMethod
add
(String[]
the suggested name parts for the method
suggestedNameParts
,
Consumer<MethodSpec.Builder>
a Consumer used to build method
method
)

Add a new GeneratedMethod.

pack-priv void
doWithMethodSpecs(Consumer<MethodSpec>
the action to perform
action
)

Call the given action with each of the MethodSpecs that have been added to this collection.

pack-priv Stream<GeneratedMethod>
public GeneratedMethods

Returns:

a new instance with the specified prefix
withPrefix
(String
the prefix to add to suggested method names
prefix
)

Specify the prefix to use for method names.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classNameback to summary
private final ClassName className
generatedMethodsback to summary
private final List<GeneratedMethod> generatedMethods
methodNameGeneratorback to summary
private final Function<MethodName, String> methodNameGenerator
prefixback to summary
private final MethodName prefix

Constructor Detail

GeneratedMethodsback to summary
pack-priv GeneratedMethods(ClassName className, Function<MethodName, String> methodNameGenerator)

Create a new GeneratedMethods using the specified method name generator.

Parameters
className:ClassName

the declaring class name

methodNameGenerator:Function<MethodName, String>

the method name generator

GeneratedMethodsback to summary
private GeneratedMethods(ClassName className, Function<MethodName, String> methodNameGenerator, MethodName prefix, List<GeneratedMethod> generatedMethods)

Method Detail

addback to summary
public GeneratedMethod add(String suggestedName, Consumer<MethodSpec.Builder> method)

Add a new GeneratedMethod.

The suggestedName should provide the unqualified form of what the method does. For instance, if the method returns an instance of a given type, getInstance can be used as it is automatically qualified using the current prefix.

The prefix is applied a little differently for suggested names that start with get, set, or is. Taking the previous example with a myBean prefix, the actual method name is getMyBeanInstance. Further processing of the method can happen to ensure uniqueness within a class.

Parameters
suggestedName:String

the suggested name for the method

method:Consumer<MethodSpec.Builder>

a Consumer used to build method

Returns:GeneratedMethod

the newly added GeneratedMethod

addback to summary
public GeneratedMethod add(String[] suggestedNameParts, Consumer<MethodSpec.Builder> method)

Add a new GeneratedMethod.

The suggestedNameParts should provide the unqualified form of what the method does. For instance, if the method returns an instance of a given type, ["get", "instance"] can be used as it is automatically qualified using the current prefix.

The prefix is applied a little differently for suggested name parts that start with get, set, or is. Taking the previous example with a myBean prefix, the actual method name is getMyBeanInstance. Further processing of the method can happen to ensure uniqueness within a class.

Parameters
suggestedNameParts:String[]

the suggested name parts for the method

method:Consumer<MethodSpec.Builder>

a Consumer used to build method

Returns:GeneratedMethod

the newly added GeneratedMethod

doWithMethodSpecsback to summary
pack-priv void doWithMethodSpecs(Consumer<MethodSpec> action)

Call the given action with each of the MethodSpecs that have been added to this collection.

Parameters
action:Consumer<MethodSpec>

the action to perform

streamback to summary
pack-priv Stream<GeneratedMethod> stream()
withPrefixback to summary
public GeneratedMethods withPrefix(String prefix)

Specify the prefix to use for method names. The prefix applies to suggested method names, with special handling of get, set, and is prefixes in the suggested name itself.

Parameters
prefix:String

the prefix to add to suggested method names

Returns:GeneratedMethods

a new instance with the specified prefix