Top Description Fields Constructors Methods
org.springframework.beans.factory.aot

pack-priv Class BeanDefinitionMethodGenerator

extends Object
Class Inheritance
Imports
java.util.List, javax.lang.model.element.Modifier, org.springframework.aot.generate.GeneratedClass, .GeneratedMethod, .GeneratedMethods, .GenerationContext, .MethodReference, org.springframework.beans.factory.config.BeanDefinition, org.springframework.beans.factory.support.RegisteredBean, org.springframework.javapoet.ClassName, org.springframework.lang.Nullable, org.springframework.util.StringUtils

Generates a method that returns a BeanDefinition to be registered.
Authors
Phillip Webb, Stephane Nicoll, Sebastien Deleuze
Since
6.0
See Also
BeanDefinitionMethodGeneratorFactory

Field Summary

Modifier and TypeField and Description
private final List<BeanRegistrationAotContribution>
private final String
private final BeanDefinitionMethodGeneratorFactory
private final RegisteredBean

Constructor Summary

AccessConstructor and Description
pack-priv
BeanDefinitionMethodGenerator(BeanDefinitionMethodGeneratorFactory
the method generator factory
methodGeneratorFactory
,
RegisteredBean
the registered bean
registeredBean
,
String
the current property name
currentPropertyName
,
List<BeanRegistrationAotContribution>
the AOT contributions
aotContributions
)

Create a new BeanDefinitionMethodGenerator instance.

Method Summary

Modifier and TypeMethod and Description
private static GeneratedClass
createInnerClass(GeneratedClass generatedClass, String name, ClassName target)

pack-priv MethodReference

Returns:

a reference to the generated method.
generateBeanDefinitionMethod
(GenerationContext
the generation context
generationContext
,
BeanRegistrationsCode
the bean registrations code
beanRegistrationsCode
)

Generate the method that returns the BeanDefinition to be registered.

private GeneratedMethod
generateBeanDefinitionMethod(GenerationContext generationContext, ClassName className, GeneratedMethods generatedMethods, BeanRegistrationCodeFragments codeFragments, Modifier modifier)

private BeanRegistrationCodeFragments
getCodeFragments(GenerationContext generationContext, BeanRegistrationsCode beanRegistrationsCode)

private String
private String
private boolean

Returns:

true if generated code in that package is allowed
isWritablePackageName
(ClassName
the target to check
target
)

Specify if the ClassName belongs to a writable package.

private static GeneratedClass

Returns:

the generated class to use
lookupGeneratedClass
(GenerationContext
the generation context to use
generationContext
,
ClassName
the chosen target class name for the bean definition
target
)

Return the GeneratedClass to use for the specified target.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aotContributionsback to summary
private final List<BeanRegistrationAotContribution> aotContributions
currentPropertyNameback to summary
private final String currentPropertyName
Annotations
@Nullable
methodGeneratorFactoryback to summary
private final BeanDefinitionMethodGeneratorFactory methodGeneratorFactory
registeredBeanback to summary
private final RegisteredBean registeredBean

Constructor Detail

BeanDefinitionMethodGeneratorback to summary
pack-priv BeanDefinitionMethodGenerator(BeanDefinitionMethodGeneratorFactory methodGeneratorFactory, RegisteredBean registeredBean, String currentPropertyName, List<BeanRegistrationAotContribution> aotContributions)

Create a new BeanDefinitionMethodGenerator instance.

Parameters
methodGeneratorFactory:BeanDefinitionMethodGeneratorFactory

the method generator factory

registeredBean:RegisteredBean

the registered bean

currentPropertyName:String

the current property name

aotContributions:List<BeanRegistrationAotContribution>

the AOT contributions

Exceptions
IllegalArgumentException:
if the bean definition defines an instance supplier since this can't be supported for code generation

Method Detail

createInnerClassback to summary
private static GeneratedClass createInnerClass(GeneratedClass generatedClass, String name, ClassName target)
generateBeanDefinitionMethodback to summary
pack-priv MethodReference generateBeanDefinitionMethod(GenerationContext generationContext, BeanRegistrationsCode beanRegistrationsCode)

Generate the method that returns the BeanDefinition to be registered.

Parameters
generationContext:GenerationContext

the generation context

beanRegistrationsCode:BeanRegistrationsCode

the bean registrations code

Returns:MethodReference

a reference to the generated method.

generateBeanDefinitionMethodback to summary
private GeneratedMethod generateBeanDefinitionMethod(GenerationContext generationContext, ClassName className, GeneratedMethods generatedMethods, BeanRegistrationCodeFragments codeFragments, Modifier modifier)
getCodeFragmentsback to summary
private BeanRegistrationCodeFragments getCodeFragments(GenerationContext generationContext, BeanRegistrationsCode beanRegistrationsCode)
getNameback to summary
private String getName()
getSimpleBeanNameback to summary
private String getSimpleBeanName(String beanName)
isWritablePackageNameback to summary
private boolean isWritablePackageName(ClassName target)

Specify if the ClassName belongs to a writable package.

Parameters
target:ClassName

the target to check

Returns:boolean

true if generated code in that package is allowed

lookupGeneratedClassback to summary
private static GeneratedClass lookupGeneratedClass(GenerationContext generationContext, ClassName target)

Return the GeneratedClass to use for the specified target.

If the target class is an inner class, a corresponding inner class in the original structure is created.

Parameters
generationContext:GenerationContext

the generation context to use

target:ClassName

the chosen target class name for the bean definition

Returns:GeneratedClass

the generated class to use