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

public Class GeneratedClasses

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Comparator, .List, .Map, java.util.concurrent.ConcurrentHashMap, java.util.function.Consumer, org.springframework.javapoet.ClassName, .TypeSpec, org.springframework.lang.Nullable, org.springframework.util.Assert

A managed collection of generated classes.

This class is stateful, so the same instance should be used for all class generation.

Authors
Phillip Webb, Stephane Nicoll
Since
6.0
See Also
GeneratedClass

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record

Field Summary

Modifier and TypeField and Description
private final List<GeneratedClass>
private final Map<GeneratedClasses.Owner, GeneratedClass>
private final ClassNameGenerator

Constructor Summary

AccessConstructor and Description
pack-priv
GeneratedClasses(ClassNameGenerator
the class name generator to use
classNameGenerator
)

Create a new instance using the specified naming conventions.

private

Method Summary

Modifier and TypeMethod and Description
public GeneratedClass

Returns:

the newly generated class
addForFeature
(String
the name of the feature to associate with the generated class
featureName
,
Consumer<TypeSpec.Builder>
a Consumer used to build the type
type
)

Add a new generated class for the specified featureName and no particular component.

public GeneratedClass

Returns:

the newly generated class
addForFeatureComponent
(String
the name of the feature to associate with the generated class
featureName
,
ClassName
the target component
targetComponent
,
Consumer<TypeSpec.Builder>
a Consumer used to build the type
type
)

Add a new generated class for the specified featureName targeting the specified component.

public GeneratedClass

Returns:

the newly generated class
addForFeatureComponent
(String
the name of the feature to associate with the generated class
featureName
,
Class<?>
the target component
targetComponent
,
Consumer<TypeSpec.Builder>
a Consumer used to build the type
type
)

Add a new generated class for the specified featureName targeting the specified component.

private GeneratedClass
createAndAddGeneratedClass(String featureName, ClassName targetComponent, Consumer<TypeSpec.Builder> type)

public GeneratedClass

Returns:

an existing or newly generated class
getOrAddForFeature
(String
the name of the feature to associate with the generated class
featureName
,
Consumer<TypeSpec.Builder>
a Consumer used to build the type
type
)

Get or add a generated class for the specified featureName and no particular component.

public GeneratedClass

Returns:

an existing or newly generated class
getOrAddForFeatureComponent
(String
the name of the feature to associate with the generated class
featureName
,
ClassName
the target component
targetComponent
,
Consumer<TypeSpec.Builder>
a Consumer used to build the type
type
)

Get or add a generated class for the specified featureName targeting the specified component.

public GeneratedClass

Returns:

an existing or newly generated class
getOrAddForFeatureComponent
(String
the name of the feature to associate with the generated class
featureName
,
Class<?>
the target component
targetComponent
,
Consumer<TypeSpec.Builder>
a Consumer used to build the type
type
)

Get or add a generated class for the specified featureName targeting the specified component.

pack-priv GeneratedClasses

Returns:

a new instance for the specified feature name prefix
withFeatureNamePrefix
(String
the feature name prefix to use
featureNamePrefix
)

Create a new GeneratedClasses instance using the specified feature name prefix to qualify generated class names for a dedicated round of code generation.

pack-priv void
writeTo(GeneratedFiles
where to write the generated classes
generatedFiles
)

Write the generated classes using the given GeneratedFiles instance.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classesback to summary
private final List<GeneratedClass> classes
classesByOwnerback to summary
private final Map<GeneratedClasses.Owner, GeneratedClass> classesByOwner
classNameGeneratorback to summary
private final ClassNameGenerator classNameGenerator

Constructor Detail

GeneratedClassesback to summary
pack-priv GeneratedClasses(ClassNameGenerator classNameGenerator)

Create a new instance using the specified naming conventions.

Parameters
classNameGenerator:ClassNameGenerator

the class name generator to use

GeneratedClassesback to summary
private GeneratedClasses(ClassNameGenerator classNameGenerator, List<GeneratedClass> classes, Map<GeneratedClasses.Owner, GeneratedClass> classesByOwner)

Method Detail

addForFeatureback to summary
public GeneratedClass addForFeature(String featureName, Consumer<TypeSpec.Builder> type)

Add a new generated class for the specified featureName and no particular component.

Parameters
featureName:String

the name of the feature to associate with the generated class

type:Consumer<TypeSpec.Builder>

a Consumer used to build the type

Returns:GeneratedClass

the newly generated class

addForFeatureComponentback to summary
public GeneratedClass addForFeatureComponent(String featureName, ClassName targetComponent, Consumer<TypeSpec.Builder> type)

Add a new generated class for the specified featureName targeting the specified component.

Parameters
featureName:String

the name of the feature to associate with the generated class

targetComponent:ClassName

the target component

type:Consumer<TypeSpec.Builder>

a Consumer used to build the type

Returns:GeneratedClass

the newly generated class

addForFeatureComponentback to summary
public GeneratedClass addForFeatureComponent(String featureName, Class<?> targetComponent, Consumer<TypeSpec.Builder> type)

Add a new generated class for the specified featureName targeting the specified component.

Parameters
featureName:String

the name of the feature to associate with the generated class

targetComponent:Class<?>

the target component

type:Consumer<TypeSpec.Builder>

a Consumer used to build the type

Returns:GeneratedClass

the newly generated class

createAndAddGeneratedClassback to summary
private GeneratedClass createAndAddGeneratedClass(String featureName, ClassName targetComponent, Consumer<TypeSpec.Builder> type)
getOrAddForFeatureback to summary
public GeneratedClass getOrAddForFeature(String featureName, Consumer<TypeSpec.Builder> type)

Get or add a generated class for the specified featureName and no particular component. If this method has previously been called with the given featureName the existing class will be returned, otherwise a new class will be generated.

Parameters
featureName:String

the name of the feature to associate with the generated class

type:Consumer<TypeSpec.Builder>

a Consumer used to build the type

Returns:GeneratedClass

an existing or newly generated class

getOrAddForFeatureComponentback to summary
public GeneratedClass getOrAddForFeatureComponent(String featureName, ClassName targetComponent, Consumer<TypeSpec.Builder> type)

Get or add a generated class for the specified featureName targeting the specified component. If this method has previously been called with the given featureName/target the existing class will be returned, otherwise a new class will be generated, otherwise a new class will be generated.

Parameters
featureName:String

the name of the feature to associate with the generated class

targetComponent:ClassName

the target component

type:Consumer<TypeSpec.Builder>

a Consumer used to build the type

Returns:GeneratedClass

an existing or newly generated class

getOrAddForFeatureComponentback to summary
public GeneratedClass getOrAddForFeatureComponent(String featureName, Class<?> targetComponent, Consumer<TypeSpec.Builder> type)

Get or add a generated class for the specified featureName targeting the specified component. If this method has previously been called with the given featureName/target the existing class will be returned, otherwise a new class will be generated, otherwise a new class will be generated.

Parameters
featureName:String

the name of the feature to associate with the generated class

targetComponent:Class<?>

the target component

type:Consumer<TypeSpec.Builder>

a Consumer used to build the type

Returns:GeneratedClass

an existing or newly generated class

withFeatureNamePrefixback to summary
pack-priv GeneratedClasses withFeatureNamePrefix(String featureNamePrefix)

Create a new GeneratedClasses instance using the specified feature name prefix to qualify generated class names for a dedicated round of code generation.

Parameters
featureNamePrefix:String

the feature name prefix to use

Returns:GeneratedClasses

a new instance for the specified feature name prefix

writeToback to summary
pack-priv void writeTo(GeneratedFiles generatedFiles)

Write the generated classes using the given GeneratedFiles instance.

Parameters
generatedFiles:GeneratedFiles

where to write the generated classes

org.springframework.aot.generate back to summary

private final Record GeneratedClasses.Owner

extends Record
Class Inheritance
Record Components
featureNamePrefix:String 
featureName:String 
target:ClassName 

Field Summary

Modifier and TypeField and Description
private final String
featureName

Record Component accessed by featureName().

private final String
featureNamePrefix

Record Component accessed by featureNamePrefix().

private final ClassName
target

Record Component accessed by target().

Constructor Summary

AccessConstructor and Description
private
Owner(String featureNamePrefix, String featureName, ClassName target)

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object
the reference object with which to compare.
o
)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.
public String
featureName()

Record Component getter of featureName.

public String
featureNamePrefix()

Record Component getter of featureNamePrefix.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.
public ClassName
target()

Record Component getter of target.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

featureNameback to summary
private final String featureName

Record Component accessed by featureName().

featureNamePrefixback to summary
private final String featureNamePrefix

Record Component accessed by featureNamePrefix().

targetback to summary
private final ClassName target

Record Component accessed by target().

Annotations
@Nullable

Constructor Detail

Ownerback to summary
private Owner(String featureNamePrefix, String featureName, ClassName target)

Method Detail

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this record is equal to the argument; false otherwise.

featureNameback to summary
public String featureName()

Record Component getter of featureName.

featureNamePrefixback to summary
public String featureNamePrefix()

Record Component getter of featureNamePrefix.

hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

Returns:int

a hash code value for this record.

targetback to summary
public ClassName target()

Record Component getter of target.

Annotations
@Nullable
toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

Returns:String

a string representation of the object.