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

public final Class ValueCodeGenerator

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Arrays, .List, org.springframework.javapoet.CodeBlock, org.springframework.lang.Nullable, org.springframework.util.Assert

Code generator for a single value. Delegates code generation to a list of configurable Delegate implementations.
Author
Stephane Nicoll
Since
6.1.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ValueCodeGenerator.Delegate

Strategy interface that can be used to implement code generation for a particular value type.

Field Summary

Modifier and TypeField and Description
private final List<ValueCodeGenerator.Delegate>
private final GeneratedMethods
private static final ValueCodeGenerator
private static final CodeBlock

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public ValueCodeGenerator
add(List<ValueCodeGenerator.Delegate> additionalDelegates)

public CodeBlock

Returns:

the code that represents the specified value
generateCode
(Object
the value to generate
value
)

Generate the code that represents the specified value.

public GeneratedMethods

Returns:

the generated methods to use for code generation
getGeneratedMethods
()

Return the GeneratedMethods that represents the scope in which code generated by this instance will be added, or null if no specific scope is set.

public ValueCodeGenerator

Returns:

an instance scoped to the specified generated methods
scoped
(GeneratedMethods
the generated methods to use
generatedMethods
)

Return a ValueCodeGenerator that is scoped for the specified GeneratedMethods.

public static ValueCodeGenerator

Returns:

an instance with the specified delegates
with
(ValueCodeGenerator.Delegate...
the delegates to use
delegates
)

Create an instance with the specified Delegate implementations.

public static ValueCodeGenerator

Returns:

an instance with the specified delegates
with
(List<ValueCodeGenerator.Delegate>
the delegates to use
delegates
)

Create an instance with the specified Delegate implementations.

public static ValueCodeGenerator

Returns:

an instance with support for common value types
withDefaults
()

Return an instance that provides support for common value types.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

delegatesback to summary
private final List<ValueCodeGenerator.Delegate> delegates
generatedMethodsback to summary
private final GeneratedMethods generatedMethods
Annotations
@Nullable
INSTANCEback to summary
private static final ValueCodeGenerator INSTANCE
NULL_VALUE_CODE_BLOCKback to summary
private static final CodeBlock NULL_VALUE_CODE_BLOCK

Constructor Detail

ValueCodeGeneratorback to summary
private ValueCodeGenerator(List<ValueCodeGenerator.Delegate> delegates, GeneratedMethods generatedMethods)

Method Detail

addback to summary
public ValueCodeGenerator add(List<ValueCodeGenerator.Delegate> additionalDelegates)
generateCodeback to summary
public CodeBlock generateCode(Object value)

Generate the code that represents the specified value.

Parameters
value:Object

the value to generate

Returns:CodeBlock

the code that represents the specified value

getGeneratedMethodsback to summary
public GeneratedMethods getGeneratedMethods()

Return the GeneratedMethods that represents the scope in which code generated by this instance will be added, or null if no specific scope is set.

Returns:GeneratedMethods

the generated methods to use for code generation

Annotations
@Nullable
scopedback to summary
public ValueCodeGenerator scoped(GeneratedMethods generatedMethods)

Return a ValueCodeGenerator that is scoped for the specified GeneratedMethods. This allows code generation to generate additional methods if necessary, or perform some optimization in case of visibility issues.

Parameters
generatedMethods:GeneratedMethods

the generated methods to use

Returns:ValueCodeGenerator

an instance scoped to the specified generated methods

withback to summary
public static ValueCodeGenerator with(ValueCodeGenerator.Delegate... delegates)

Create an instance with the specified Delegate implementations.

Parameters
delegates:ValueCodeGenerator.Delegate[]

the delegates to use

Returns:ValueCodeGenerator

an instance with the specified delegates

withback to summary
public static ValueCodeGenerator with(List<ValueCodeGenerator.Delegate> delegates)

Create an instance with the specified Delegate implementations.

Parameters
delegates:List<ValueCodeGenerator.Delegate>

the delegates to use

Returns:ValueCodeGenerator

an instance with the specified delegates

withDefaultsback to summary
public static ValueCodeGenerator withDefaults()

Return an instance that provides support for common value types.

Returns:ValueCodeGenerator

an instance with support for common value types

org.springframework.aot.generate back to summary

public Interface ValueCodeGenerator.Delegate

Known Direct Implementers
org.springframework.aot.generate.ValueCodeGeneratorDelegates.CollectionDelegate, org.springframework.aot.generate.ValueCodeGeneratorDelegates.MapDelegate, org.springframework.aot.generate.ValueCodeGeneratorDelegates.PrimitiveDelegate, org.springframework.aot.generate.ValueCodeGeneratorDelegates.StringDelegate, org.springframework.aot.generate.ValueCodeGeneratorDelegates.CharsetDelegate, org.springframework.aot.generate.ValueCodeGeneratorDelegates.EnumDelegate, org.springframework.aot.generate.ValueCodeGeneratorDelegates.ClassDelegate, org.springframework.aot.generate.ValueCodeGeneratorDelegates.ResolvableTypeDelegate, org.springframework.aot.generate.ValueCodeGeneratorDelegates.ArrayDelegate

Strategy interface that can be used to implement code generation for a particular value type.

Method Summary

Modifier and TypeMethod and Description
public CodeBlock

Returns:

the code that represents the specified value or null if the specified value is not supported.
generateCode
(ValueCodeGenerator
the code generator to use for embedded values
valueCodeGenerator
,
Object
the value to generate
value
)

Generate the code for the specified non-null value.

Method Detail

generateCodeback to summary
public CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object value)

Generate the code for the specified non-null value. If this instance does not support the value, it should return null to indicate so.

Parameters
valueCodeGenerator:ValueCodeGenerator

the code generator to use for embedded values

value:Object

the value to generate

Returns:CodeBlock

the code that represents the specified value or null if the specified value is not supported.

Annotations
@Nullable