Class ClassNameGenerator

java.lang.Object
org.springframework.aot.generate.ClassNameGenerator

public final class ClassNameGenerator extends Object
Generate unique class names based on target Class and a feature name. This class is stateful so the same instance should be used for all name generation.
Since:
6.0
Author:
Phillip Webb, Stephane Nicoll
  • Constructor Details

    • ClassNameGenerator

      public ClassNameGenerator(Class<?> defaultTarget)
      Create a new instance using the specified defaultTarget and no feature name prefix.
      Parameters:
      defaultTarget - the default target class to use
    • ClassNameGenerator

      public ClassNameGenerator(Class<?> defaultTarget, String featureNamePrefix)
      Create a new instance using the specified defaultTarget and feature name prefix.
      Parameters:
      defaultTarget - the default target class to use
      featureNamePrefix - the prefix to use to qualify feature names
  • Method Details

    • generateClassName

      public org.springframework.javapoet.ClassName generateClassName(@Nullable Class<?> target, String featureName)
      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:
      target - the class the newly generated class relates to, or null to use the main target
      featureName - the name of the feature that the generated class supports
      Returns:
      a unique generated class name