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

public final Class ClassNameGenerator

extends Object
Class Inheritance
Imports
java.util.Map, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.atomic.AtomicInteger, org.springframework.javapoet.ClassName, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .StringUtils

Generate unique class names based on a target ClassName and a feature name.

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

Authors
Phillip Webb, Stephane Nicoll
Since
6.0

Field Summary

Modifier and TypeField and Description
private static final String
private final ClassName
private final String
private static final String
private final Map<String, AtomicInteger>

Constructor Summary

AccessConstructor and Description
public
ClassNameGenerator(ClassName
the default target class to use
defaultTarget
)

Create a new instance using the specified defaultTarget and no feature name prefix.

public
ClassNameGenerator(ClassName
the default target class to use
defaultTarget
,
String
the prefix to use to qualify feature names
featureNamePrefix
)

Create a new instance using the specified defaultTarget and feature name prefix.

private
ClassNameGenerator(ClassName defaultTarget, String featureNamePrefix, Map<String, AtomicInteger> sequenceGenerator)

Method Summary

Modifier and TypeMethod and Description
private String
clean(String name)

public ClassName

Returns:

a unique generated class name
generateClassName
(String
the name of the feature that the generated class supports
featureName
,
ClassName
the class the newly generated class relates to, or null to use the main target
target
)

Generate a unique ClassName based on the specified featureName and target.

private ClassName
pack-priv String
private String
getRootName(String featureName, ClassName target)

private static String
toName(ClassName className)

pack-priv ClassNameGenerator

Returns:

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

Create a new ClassNameGenerator instance for the specified feature name prefix, keeping track of all the class names generated by this instance.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AOT_FEATUREback to summary
private static final String AOT_FEATURE
defaultTargetback to summary
private final ClassName defaultTarget
featureNamePrefixback to summary
private final String featureNamePrefix
SEPARATORback to summary
private static final String SEPARATOR
sequenceGeneratorback to summary
private final Map<String, AtomicInteger> sequenceGenerator

Constructor Detail

ClassNameGeneratorback to summary
public ClassNameGenerator(ClassName defaultTarget)

Create a new instance using the specified defaultTarget and no feature name prefix.

Parameters
defaultTarget:ClassName

the default target class to use

ClassNameGeneratorback to summary
public ClassNameGenerator(ClassName defaultTarget, String featureNamePrefix)

Create a new instance using the specified defaultTarget and feature name prefix.

Parameters
defaultTarget:ClassName

the default target class to use

featureNamePrefix:String

the prefix to use to qualify feature names

ClassNameGeneratorback to summary
private ClassNameGenerator(ClassName defaultTarget, String featureNamePrefix, Map<String, AtomicInteger> sequenceGenerator)

Method Detail

cleanback to summary
private String clean(String name)
generateClassNameback to summary
public ClassName generateClassName(String featureName, ClassName target)

Generate a unique ClassName based on the specified featureName and target. If the target is null, the configured main target of this instance is used.

The class name is a suffixed version of the target. For instance, a com.example.Demo target with an Initializer feature name leads to a com.example.Demo__Initializer generated class name. The feature name is qualified by the configured feature name prefix, if any.

Generated class names are unique. If such a feature was already requested for this target, a counter is used to ensure uniqueness.

Parameters
featureName:String

the name of the feature that the generated class supports

target:ClassName

the class the newly generated class relates to, or null to use the main target

Returns:ClassName

a unique generated class name

generateSequencedClassNameback to summary
private ClassName generateSequencedClassName(String name)
getFeatureNamePrefixback to summary
pack-priv String getFeatureNamePrefix()
getRootNameback to summary
private String getRootName(String featureName, ClassName target)
toNameback to summary
private static String toName(ClassName className)
withFeatureNamePrefixback to summary
pack-priv ClassNameGenerator withFeatureNamePrefix(String featureNamePrefix)

Create a new ClassNameGenerator instance for the specified feature name prefix, keeping track of all the class names generated by this instance.

Parameters
featureNamePrefix:String

the feature name prefix to use

Returns:ClassNameGenerator

a new instance for the specified feature name prefix