Package org.springframework.beans.factory.aot

# Class InstanceSupplierCodeGenerator

java.lang.Object
org.springframework.beans.factory.aot.InstanceSupplierCodeGenerator

public class InstanceSupplierCodeGenerator extends Object
Default code generator to create an `InstanceSupplier`, usually in the form of a `BeanInstanceSupplier` that retains the executable that is used to instantiate the bean. Takes care of registering the necessary hints if reflection or a JDK proxy is required.

Generated code is usually a method reference that generates the `BeanInstanceSupplier`, but some shortcut can be used as well such as:

     InstanceSupplier.of(TheGeneratedClass::getMyBeanInstance);

Since:
  6.0
Author:
  Phillip Webb, Stephane Nicoll, Juergen Hoeller, Sebastien Deleuze
See Also:
  - `BeanRegistrationCodeFragments`

## Constructor Summary

Constructors
Constructor
Description
`InstanceSupplierCodeGenerator(org.springframework.aot.generate.GenerationContext generationContext, org.springframework.javapoet.ClassName className, org.springframework.aot.generate.GeneratedMethods generatedMethods, boolean allowDirectSupplierShortcut)`
Create a new generator instance.

## Method Summary

Modifier and Type
Method
Description
`org.springframework.javapoet.CodeBlock`
`generateCode(RegisteredBean registeredBean, Executable constructorOrFactoryMethod)`
Deprecated.
in favor of `generateCode(RegisteredBean, InstantiationDescriptor)`
`org.springframework.javapoet.CodeBlock`
`generateCode(RegisteredBean registeredBean, RegisteredBean.InstantiationDescriptor instantiationDescriptor)`
Generate the instance supplier code.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### InstanceSupplierCodeGenerator

public InstanceSupplierCodeGenerator(org.springframework.aot.generate.GenerationContext generationContext, org.springframework.javapoet.ClassName className, org.springframework.aot.generate.GeneratedMethods generatedMethods, boolean allowDirectSupplierShortcut)
Create a new generator instance.

Parameters:
  `generationContext` - the generation context
  `className` - the class name of the bean to instantiate
  `generatedMethods` - the generated methods
  `allowDirectSupplierShortcut` - whether a direct supplier may be used rather than always needing an `InstanceSupplier`

## Method Details

### generateCode

@Deprecated(since="6.1.7") public org.springframework.javapoet.CodeBlock generateCode(RegisteredBean registeredBean, Executable constructorOrFactoryMethod)
Deprecated.
in favor of `generateCode(RegisteredBean, InstantiationDescriptor)`
Generate the instance supplier code.

Parameters:
  `registeredBean` - the bean to handle
  `constructorOrFactoryMethod` - the executable to use to create the bean
Returns:
  the generated code

### generateCode

public org.springframework.javapoet.CodeBlock generateCode(RegisteredBean registeredBean, RegisteredBean.InstantiationDescriptor instantiationDescriptor)
Generate the instance supplier code.

Parameters:
  `registeredBean` - the bean to handle
  `instantiationDescriptor` - the executable to use to create the bean
Returns:
  the generated code
Since:
  6.1.7