Package org.springframework.beans.factory.aot

# Interface BeanRegistrationCodeFragments

All Known Implementing Classes:
  `BeanRegistrationCodeFragmentsDecorator`

public interface BeanRegistrationCodeFragments
Generate the various fragments of code needed to register a bean.

A default implementation is provided that suits most needs and custom code fragments are only expected to be used by library authors having built custom arrangement on top of the core container.

Users are not expected to implement this interface directly, but rather extends from `BeanRegistrationCodeFragmentsDecorator` and only override the necessary method(s).

Since:
  6.0
Author:
  Phillip Webb, Stephane Nicoll
See Also:
  - `BeanRegistrationCodeFragmentsDecorator`
  - `BeanRegistrationAotContribution.withCustomCodeFragments(UnaryOperator)`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`BEAN_DEFINITION_VARIABLE`
The variable name used when creating the bean definition.
`static final String`
`INSTANCE_SUPPLIER_VARIABLE`
The variable name used when creating the bean definition.

## Method Summary

Modifier and Type
Method
Description
`org.springframework.javapoet.CodeBlock`
`generateInstanceSupplierCode(org.springframework.aot.generate.GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode, boolean allowDirectSupplierShortcut)`
Generate the instance supplier code.
`org.springframework.javapoet.CodeBlock`
`generateNewBeanDefinitionCode(org.springframework.aot.generate.GenerationContext generationContext, org.springframework.core.ResolvableType beanType, BeanRegistrationCode beanRegistrationCode)`
Generate the code that defines the new bean definition instance.
`org.springframework.javapoet.CodeBlock`
`generateReturnCode(org.springframework.aot.generate.GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode)`
Generate the return statement.
`org.springframework.javapoet.CodeBlock`
`generateSetBeanDefinitionPropertiesCode(org.springframework.aot.generate.GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode, RootBeanDefinition beanDefinition, Predicate<String> attributeFilter)`
Generate the code that sets the properties of the bean definition.
`org.springframework.javapoet.CodeBlock`
`generateSetBeanInstanceSupplierCode(org.springframework.aot.generate.GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode, org.springframework.javapoet.CodeBlock instanceSupplierCode, List<org.springframework.aot.generate.MethodReference> postProcessors)`
Generate the code that sets the instance supplier on the bean definition.
`org.springframework.javapoet.ClassName`
`getTarget(RegisteredBean registeredBean)`
Return the target for the registration.

## Field Details

### BEAN_DEFINITION_VARIABLE

static final String BEAN_DEFINITION_VARIABLE
The variable name used when creating the bean definition.

See Also:
  - Constant Field Values

### INSTANCE_SUPPLIER_VARIABLE

static final String INSTANCE_SUPPLIER_VARIABLE
The variable name used when creating the bean definition.

See Also:
  - Constant Field Values

## Method Details

### getTarget

org.springframework.javapoet.ClassName getTarget(RegisteredBean registeredBean)
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` - the registered bean
Returns:
  the target `ClassName`

### generateNewBeanDefinitionCode

org.springframework.javapoet.CodeBlock generateNewBeanDefinitionCode(org.springframework.aot.generate.GenerationContext generationContext, org.springframework.core.ResolvableType beanType, BeanRegistrationCode beanRegistrationCode)
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` - the generation context
  `beanType` - the bean type
  `beanRegistrationCode` - the bean registration code
Returns:
  the generated code

### generateSetBeanDefinitionPropertiesCode

org.springframework.javapoet.CodeBlock generateSetBeanDefinitionPropertiesCode(org.springframework.aot.generate.GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode, RootBeanDefinition beanDefinition, Predicate<String> attributeFilter)
Generate the code that sets the properties of the bean definition.

Parameters:
  `generationContext` - the generation context
  `beanRegistrationCode` - the bean registration code
  `attributeFilter` - any attribute filtering that should be applied
Returns:
  the generated code

### generateSetBeanInstanceSupplierCode

org.springframework.javapoet.CodeBlock generateSetBeanInstanceSupplierCode(org.springframework.aot.generate.GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode, org.springframework.javapoet.CodeBlock instanceSupplierCode, List<org.springframework.aot.generate.MethodReference> postProcessors)
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` - the generation context
  `beanRegistrationCode` - the bean registration code
  `instanceSupplierCode` - the instance supplier code
  `postProcessors` - any instance post processors that should be applied
Returns:
  the generated code
See Also:
  - `generateInstanceSupplierCode(org.springframework.aot.generate.GenerationContext, org.springframework.beans.factory.aot.BeanRegistrationCode, boolean)`

### generateInstanceSupplierCode

org.springframework.javapoet.CodeBlock generateInstanceSupplierCode(org.springframework.aot.generate.GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode, boolean allowDirectSupplierShortcut)
Generate the instance supplier code.

Parameters:
  `generationContext` - the generation context
  `beanRegistrationCode` - the bean registration code
  `allowDirectSupplierShortcut` - if direct suppliers may be used rather than always needing an `InstanceSupplier`
Returns:
  the generated code

### generateReturnCode

org.springframework.javapoet.CodeBlock generateReturnCode(org.springframework.aot.generate.GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode)
Generate the return statement.

Parameters:
  `generationContext` - the generation context
  `beanRegistrationCode` - the bean registration code
Returns:
  the generated code