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

pack-priv Class DefaultBeanRegistrationCodeFragments

extends Object
implements BeanRegistrationCodeFragments
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.aot.BeanRegistrationCodeFragments
Imports
java.lang.reflect.Constructor, .Executable, .Modifier, java.util.List, java.util.function.Predicate, .Supplier, org.springframework.aot.generate.AccessControl, .GenerationContext, .MethodReference, .MethodReference.ArgumentCodeGenerator, .ValueCodeGenerator, .ValueCodeGenerator.Delegate, org.springframework.beans.factory.FactoryBean, org.springframework.beans.factory.aot.AotServices.Loader, org.springframework.beans.factory.config.BeanDefinition, .BeanDefinitionHolder, org.springframework.beans.factory.support.InstanceSupplier, .RegisteredBean, .RootBeanDefinition, org.springframework.core.ResolvableType, org.springframework.javapoet.ClassName, .CodeBlock, .ParameterizedTypeName, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, org.springframework.util.function.SingletonSupplier

Internal BeanRegistrationCodeFragments implementation used by default.
Authors
Phillip Webb, Stephane Nicoll

Field Summary

Modifier and TypeField and Description
private final BeanDefinitionMethodGeneratorFactory
private final BeanRegistrationsCode
private final Supplier<Executable>
private final RegisteredBean
private static final ValueCodeGenerator

Constructor Summary

AccessConstructor and Description
pack-priv
DefaultBeanRegistrationCodeFragments(BeanRegistrationsCode beanRegistrationsCode, RegisteredBean registeredBean, BeanDefinitionMethodGeneratorFactory beanDefinitionMethodGeneratorFactory)

Method Summary

Modifier and TypeMethod and Description
private Class<?>
private Class<?>

Returns:

the target class to use
extractTargetClassFromFactoryBean
(Class<?>
the factory bean type
factoryBeanType
,
ResolvableType
the bean type
beanType
)

Extract the target class of a public FactoryBean based on its constructor.

private CodeBlock
generateBeanClassCode(String targetPackage, Class<?> beanClass)

private CodeBlock
public CodeBlock
generateInstanceSupplierCode(GenerationContext
the generation context
generationContext
,
BeanRegistrationCode
the bean registration code
beanRegistrationCode
,
boolean
if direct suppliers may be used rather than always needing an InstanceSupplier
allowDirectSupplierShortcut
)

Implements org.springframework.beans.factory.aot.BeanRegistrationCodeFragments.generateInstanceSupplierCode.

Generate the instance supplier code.

public CodeBlock
generateNewBeanDefinitionCode(GenerationContext
the generation context
generationContext
,
ResolvableType
the bean type
beanType
,
BeanRegistrationCode
the bean registration code
beanRegistrationCode
)

Implements org.springframework.beans.factory.aot.BeanRegistrationCodeFragments.generateNewBeanDefinitionCode.

Generate the code that defines the new bean definition instance.

public CodeBlock
generateReturnCode(GenerationContext
the generation context
generationContext
,
BeanRegistrationCode
the bean registration code
beanRegistrationCode
)

Implements org.springframework.beans.factory.aot.BeanRegistrationCodeFragments.generateReturnCode.

Generate the return statement.

public CodeBlock
generateSetBeanDefinitionPropertiesCode(GenerationContext
the generation context
generationContext
,
BeanRegistrationCode
the bean registration code
beanRegistrationCode
,
RootBeanDefinition beanDefinition, Predicate<String>
any attribute filtering that should be applied
attributeFilter
)

Implements org.springframework.beans.factory.aot.BeanRegistrationCodeFragments.generateSetBeanDefinitionPropertiesCode.

Generate the code that sets the properties of the bean definition.

public CodeBlock
generateSetBeanInstanceSupplierCode(GenerationContext
the generation context
generationContext
,
BeanRegistrationCode
the bean registration code
beanRegistrationCode
,
CodeBlock
the instance supplier code supplier code
instanceSupplierCode
,
List<MethodReference>
any instance post processors that should be applied
postProcessors
)

Implements org.springframework.beans.factory.aot.BeanRegistrationCodeFragments.generateSetBeanInstanceSupplierCode.

Generate the code that sets the instance supplier on the bean definition.

protected CodeBlock
generateValueCode(GenerationContext generationContext, String name, Object value)

private RegisteredBean
public ClassName
getTarget(RegisteredBean
the registered bean
registeredBean
)

Implements org.springframework.beans.factory.aot.BeanRegistrationCodeFragments.getTarget.

Return the target for the registration.

private boolean
private boolean
targetTypeNecessary(ResolvableType beanType, Class<?> beanClass)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beanDefinitionMethodGeneratorFactoryback to summary
private final BeanDefinitionMethodGeneratorFactory beanDefinitionMethodGeneratorFactory
beanRegistrationsCodeback to summary
private final BeanRegistrationsCode beanRegistrationsCode
constructorOrFactoryMethodback to summary
private final Supplier<Executable> constructorOrFactoryMethod
registeredBeanback to summary
private final RegisteredBean registeredBean
valueCodeGeneratorback to summary
private static final ValueCodeGenerator valueCodeGenerator

Constructor Detail

DefaultBeanRegistrationCodeFragmentsback to summary
pack-priv DefaultBeanRegistrationCodeFragments(BeanRegistrationsCode beanRegistrationsCode, RegisteredBean registeredBean, BeanDefinitionMethodGeneratorFactory beanDefinitionMethodGeneratorFactory)

Method Detail

extractDeclaringClassback to summary
private Class<?> extractDeclaringClass(ResolvableType beanType, Executable executable)
extractTargetClassFromFactoryBeanback to summary
private Class<?> extractTargetClassFromFactoryBean(Class<?> factoryBeanType, ResolvableType beanType)

Extract the target class of a public FactoryBean based on its constructor. If the implementation does not resolve the target class because it itself uses a generic, attempt to extract it from the bean type.

Parameters
factoryBeanType:Class<?>

the factory bean type

beanType:ResolvableType

the bean type

Returns:Class<?>

the target class to use

generateBeanClassCodeback to summary
private CodeBlock generateBeanClassCode(String targetPackage, Class<?> beanClass)
generateBeanTypeCodeback to summary
private CodeBlock generateBeanTypeCode(ResolvableType beanType)
generateInstanceSupplierCodeback to summary
public CodeBlock generateInstanceSupplierCode(GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode, boolean allowDirectSupplierShortcut)

Implements org.springframework.beans.factory.aot.BeanRegistrationCodeFragments.generateInstanceSupplierCode.

Doc from org.springframework.beans.factory.aot.BeanRegistrationCodeFragments.generateInstanceSupplierCode.

Generate the instance supplier code.

Parameters
generationContext:GenerationContext

the generation context

beanRegistrationCode:BeanRegistrationCode

the bean registration code

allowDirectSupplierShortcut:boolean

if direct suppliers may be used rather than always needing an InstanceSupplier

Returns:CodeBlock

the generated code

Annotations
@Override
generateNewBeanDefinitionCodeback to summary
public CodeBlock generateNewBeanDefinitionCode(GenerationContext generationContext, ResolvableType beanType, BeanRegistrationCode beanRegistrationCode)

Implements org.springframework.beans.factory.aot.BeanRegistrationCodeFragments.generateNewBeanDefinitionCode.

Doc from org.springframework.beans.factory.aot.BeanRegistrationCodeFragments.generateNewBeanDefinitionCode.

Generate the code that defines the new bean definition instance.

This should declare a variable named beanDefinition so that further fragments can refer to the variable to further tune the bean definition.

Parameters
generationContext:GenerationContext

the generation context

beanType:ResolvableType

the bean type

beanRegistrationCode:BeanRegistrationCode

the bean registration code

Returns:CodeBlock

the generated code

Annotations
@Override
generateReturnCodeback to summary
public CodeBlock generateReturnCode(GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode)

Implements org.springframework.beans.factory.aot.BeanRegistrationCodeFragments.generateReturnCode.

Doc from org.springframework.beans.factory.aot.BeanRegistrationCodeFragments.generateReturnCode.

Generate the return statement.

Parameters
generationContext:GenerationContext

the generation context

beanRegistrationCode:BeanRegistrationCode

the bean registration code

Returns:CodeBlock

the generated code

Annotations
@Override
generateSetBeanDefinitionPropertiesCodeback to summary
public CodeBlock generateSetBeanDefinitionPropertiesCode(GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode, RootBeanDefinition beanDefinition, Predicate<String> attributeFilter)

Implements org.springframework.beans.factory.aot.BeanRegistrationCodeFragments.generateSetBeanDefinitionPropertiesCode.

Doc from org.springframework.beans.factory.aot.BeanRegistrationCodeFragments.generateSetBeanDefinitionPropertiesCode.

Generate the code that sets the properties of the bean definition.

Parameters
generationContext:GenerationContext

the generation context

beanRegistrationCode:BeanRegistrationCode

the bean registration code

attributeFilter:Predicate<String>

any attribute filtering that should be applied

Returns:CodeBlock

the generated code

Annotations
@Override
generateSetBeanInstanceSupplierCodeback to summary
public CodeBlock generateSetBeanInstanceSupplierCode(GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode, CodeBlock instanceSupplierCode, List<MethodReference> postProcessors)

Implements org.springframework.beans.factory.aot.BeanRegistrationCodeFragments.generateSetBeanInstanceSupplierCode.

Doc from org.springframework.beans.factory.aot.BeanRegistrationCodeFragments.generateSetBeanInstanceSupplierCode.

Generate the code that sets the instance supplier on the bean definition.

The postProcessors represent methods to be exposed once the instance has been created to further configure it. Each method should accept two parameters, the RegisteredBean and the bean instance, and should return the modified bean instance.

Parameters
generationContext:GenerationContext

the generation context

beanRegistrationCode:BeanRegistrationCode

the bean registration code

instanceSupplierCode:CodeBlock

the instance supplier code supplier code

postProcessors:List<MethodReference>

any instance post processors that should be applied

Returns:CodeBlock

the generated code

Annotations
@Override
generateValueCodeback to summary
protected CodeBlock generateValueCode(GenerationContext generationContext, String name, Object value)
Annotations
@Nullable
getInnerRegisteredBeanback to summary
private RegisteredBean getInnerRegisteredBean(Object value)
Annotations
@Nullable
getTargetback to summary
public ClassName getTarget(RegisteredBean registeredBean)

Implements org.springframework.beans.factory.aot.BeanRegistrationCodeFragments.getTarget.

Doc from org.springframework.beans.factory.aot.BeanRegistrationCodeFragments.getTarget.

Return the target for the registration. Used to determine where to write the code. This should take into account visibility issue, such as package access of an element of the bean to register.

Parameters
registeredBean:RegisteredBean

the registered bean

Returns:ClassName

the target ClassName

Annotations
@Override
hasInstanceSupplierback to summary
private boolean hasInstanceSupplier()
targetTypeNecessaryback to summary
private boolean targetTypeNecessary(ResolvableType beanType, Class<?> beanClass)