Class ConfigurationClassNameGenerator

java.lang.Object
me.bristermitten.mittenlib.annotations.compile.ConfigurationClassNameGenerator

public class ConfigurationClassNameGenerator extends Object
Responsible for generating proper class names for configuration classes. This class handles the conversion between DTO class names and their corresponding implementation class names, taking into account nesting, package names, and custom naming specified in annotations.
  • Field Details

  • Constructor Details

    • ConfigurationClassNameGenerator

      @Inject public ConfigurationClassNameGenerator(ConfigNameCache configNameCache)
  • Method Details

    • translateConfigClassName

      public static com.palantir.javapoet.ClassName translateConfigClassName(com.palantir.javapoet.ClassName dtoClassName)
      Creates a class name for the implementation of a DTO class. If the class name ends with "DTO", it removes that suffix. Otherwise, it appends "Impl" to the class name.
      Parameters:
      dtoClassName - The original DTO class name
      Returns:
      The implementation class name
    • translateConfigClassName

      public com.palantir.javapoet.ClassName translateConfigClassName(AbstractConfigStructure ast)
      Creates a class name for the implementation of a configuration structure. This method handles nested classes by checking if the structure is enclosed in another structure.
      Parameters:
      ast - The abstract configuration structure
      Returns:
      The implementation class name, properly nested if necessary
    • getPublicClassName

      public com.palantir.javapoet.ClassName getPublicClassName(AbstractConfigStructure ast)
      Get the public class name for a config structure. "Public" is defined as the type that the user should primarily interact with. For interfaces, this is the interface itself, and for classes, this is the generated implementation class (as the DTO class becomes mostly useless after code generation).
      Parameters:
      ast - The abstract configuration structure
      Returns:
      The public class name that should be used for interaction with this configuration
    • getConcreteConfigClassName

      public com.palantir.javapoet.ClassName getConcreteConfigClassName(AbstractConfigStructure ast)
      Get the concrete class name for a config structure. This is the actual implementation class that will be instantiated. For classes, this is the original DTO class, and for interfaces, this is the generated implementation class.
      Parameters:
      ast - The abstract configuration structure
      Returns:
      The concrete class name that will be instantiated
    • getConfigPropertyClassName

      public com.palantir.javapoet.TypeName getConfigPropertyClassName(TypeMirror mirror)
      Get the config property class name for a type mirror.
      Parameters:
      mirror - The type mirror
      Returns:
      The config property class name
    • publicPropertyClassName

      public com.palantir.javapoet.TypeName publicPropertyClassName(Property p)
      Get the public property class name for a property.
      Parameters:
      p - The property
      Returns:
      The public property class name
    • publicPropertyClassName

      public com.palantir.javapoet.TypeName publicPropertyClassName(TypeMirror mirror)
      Get the public property class name for a type mirror.
      Parameters:
      mirror - The type mirror
      Returns:
      The public property class name
    • generateConfigurationClassName

      public com.palantir.javapoet.ClassName generateConfigurationClassName(TypeElement configDTOType)
      Generates a ClassName for the actual generated configuration class from a given DTO, using the package of the given TypeElement. If the given type is not a config, its unchanged name is returned. The returned class name will be the same as the given type, but with the suffix removed. It can also be manually specified in the Config annotation with Config.className()
      Parameters:
      configDTOType - The DTO type
      Returns:
      The generated ClassName
    • getDeserializerProviderFieldName

      public String getDeserializerProviderFieldName(TypeMirror type)
    • getSerializerProviderFieldName

      public String getSerializerProviderFieldName(TypeMirror type)
    • getValidatorFieldName

      public String getValidatorFieldName(Property property)
    • getValidatorElementFieldName

      public String getValidatorElementFieldName(Property property)
    • getValidatorKeyFieldName

      public String getValidatorKeyFieldName(Property property)
    • getValidatorErrorFieldName

      public String getValidatorErrorFieldName(Property property)
    • getValidatorElementErrorFieldName

      public String getValidatorElementErrorFieldName(Property property)
    • getValidatorKeyErrorFieldName

      public String getValidatorKeyErrorFieldName(Property property)
    • getDefaultMethodAccessClassName

      public com.palantir.javapoet.ClassName getDefaultMethodAccessClassName(AbstractConfigStructure ast)
    • getLoaderModuleClassName

      public com.palantir.javapoet.ClassName getLoaderModuleClassName(String packageName)
    • getProvidesProviderMethodName

      public String getProvidesProviderMethodName(String simpleName)
    • getProvidesMethodName

      public String getProvidesMethodName(String simpleName)
    • getProvidesToConfigSetMethodName

      public String getProvidesToConfigSetMethodName(String simpleName)
    • getProvidesToProviderSetMethodName

      public String getProvidesToProviderSetMethodName(String simpleName)
    • getDeserializerClassName

      public com.palantir.javapoet.ClassName getDeserializerClassName(AbstractConfigStructure ast)
      Gets the ClassName of the deserializer for a given configuration structure. For MyConfig, the deserializer is MyConfigImpl. For nested class OuterConfig.InnerConfig, the loader is OuterConfigDeserializer.InnerConfigDeserializer.
    • getDeserializerClassName

      public com.palantir.javapoet.ClassName getDeserializerClassName(TypeMirror type)
      Gets the ClassName of the loader for a given TypeMirror.
    • getDeserializerFieldName

      public String getDeserializerFieldName(TypeMirror type)
      Gets the field name for a deserializer field based on the public config type. E.g., for InterfaceConfig, it returns interfaceConfigDeserializer.
    • getSerializerClassName

      public com.palantir.javapoet.ClassName getSerializerClassName(AbstractConfigStructure ast)
      Gets the ClassName of the serializer for a given configuration structure. For MyConfigImpl, the saver is MyConfigImplSerializer. For nested class OuterConfigImpl.InnerConfigImpl, the saver is OuterConfigImplSerializer.InnerConfigImplSerializer.
    • getSerializerFieldName

      public String getSerializerFieldName(TypeMirror type)
      Gets the field name for a serializer instance based on the public config type. E.g., for InterfaceConfig, it returns "interfaceConfigSerializer".
    • getValidatorClassName

      public com.palantir.javapoet.ClassName getValidatorClassName(AbstractConfigStructure ast)
    • getInnerDaoName

      public @Nullable com.palantir.javapoet.ClassName getInnerDaoName(AbstractConfigStructure ast)