Class NameGenerator
ClassName and a
feature name. Supports generating class names and resource paths.
This class is stateful, so the same instance should be used for all name generation.
- Since:
- 7.1
- Author:
- Phillip Webb, Stephane Nicoll
-
Constructor Summary
ConstructorsConstructorDescriptionNameGenerator(org.springframework.javapoet.ClassName defaultTarget) Create a new instance using the specifieddefaultTargetand no feature name prefix.NameGenerator(org.springframework.javapoet.ClassName defaultTarget, String featureNamePrefix) Create a new instance using the specifieddefaultTargetand feature name prefix. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.javapoet.ClassNamegenerateClassName(String featureName, @Nullable org.springframework.javapoet.ClassName target) Generate a uniqueClassNamebased on the specifiedfeatureNameandtarget.generateResourcePath(String extension, String featureName, @Nullable org.springframework.javapoet.ClassName target) Generate a unique resource path based on the specifiedextension,featureNameandtarget.
-
Constructor Details
-
NameGenerator
public NameGenerator(org.springframework.javapoet.ClassName defaultTarget) Create a new instance using the specifieddefaultTargetand no feature name prefix.- Parameters:
defaultTarget- the default target class to use
-
NameGenerator
public NameGenerator(org.springframework.javapoet.ClassName defaultTarget, String featureNamePrefix) Create a new instance using the specifieddefaultTargetand feature name prefix.- Parameters:
defaultTarget- the default target class to usefeatureNamePrefix- the prefix to use to qualify feature names
-
-
Method Details
-
generateClassName
public org.springframework.javapoet.ClassName generateClassName(String featureName, @Nullable org.springframework.javapoet.ClassName target) Generate a uniqueClassNamebased on the specifiedfeatureNameandtarget. If thetargetisnull, the configured main target of this instance is used.The class name is a suffixed version of the target. For instance, a
com.example.Demotarget with anInitializerfeature name leads to acom.example.Demo__Initializergenerated 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- the name of the feature that the generated class supportstarget- the class the newly generated class relates to, ornullto use the main target- Returns:
- a unique generated class name
-
generateResourcePath
public String generateResourcePath(String extension, String featureName, @Nullable org.springframework.javapoet.ClassName target) Generate a unique resource path based on the specifiedextension,featureNameandtarget. If thetargetisnull, the configured main target of this instance is used.The resource path is a suffixed version of the target. For instance, a
com.example.Demotarget with ametadatafeature name and ajsonextension leads to acom/example/Demo-metadata.jsongenerated resource path. The feature name is qualified by the configured feature name prefix, if any.Generated resource paths are unique. If such a feature was already requested for this target, a counter is used to ensure uniqueness.
- Parameters:
extension- the file extensionfeatureName- the name of the feature that the generated path supportstarget- the class the generated resource relates to, ornullto use the main target- Returns:
- a unique absolute path for the resource
-