Class ConfigurationMetadataBuilder<T>

  • Type Parameters:
    T - The type

    public abstract class ConfigurationMetadataBuilder<T>
    extends java.lang.Object

    A builder for producing metadata for the available ConfigurationProperties.

    This data can then be subsequently written to a format readable by IDEs (like spring-configuration-metadata.json for example).

    Since:
    1.0
    • Constructor Detail

      • ConfigurationMetadataBuilder

        public ConfigurationMetadataBuilder()
    • Method Detail

      • getOriginatingElements

        @NonNull
        public abstract Element[] getOriginatingElements()
        Returns:
        The originating elements for the builder.
      • getProperties

        public java.util.List<PropertyMetadata> getProperties()
        Returns:
        The properties
      • getConfigurations

        public java.util.List<ConfigurationMetadata> getConfigurations()
        Returns:
        The configurations
      • hasMetadata

        public boolean hasMetadata()
        Returns:
        Whether any metadata is present
      • visitProperty

        public PropertyMetadata visitProperty​(T owningType,
                                              T declaringType,
                                              java.lang.String propertyType,
                                              java.lang.String name,
                                              @Nullable
                                              java.lang.String description,
                                              @Nullable
                                              java.lang.String defaultValue)
        Visit a configuration property.
        Parameters:
        owningType - The type that owns the property
        declaringType - The declaring type of the property
        propertyType - The property type
        name - The property name
        description - A description for the property
        defaultValue - The default value of the property (only used for constant values such as strings, numbers, enums etc.)
        Returns:
        This property metadata
      • visitProperty

        public PropertyMetadata visitProperty​(java.lang.String propertyType,
                                              java.lang.String name,
                                              @Nullable
                                              java.lang.String description,
                                              @Nullable
                                              java.lang.String defaultValue)
        Visit a configuration property on the last declared properties instance.
        Parameters:
        propertyType - The property type
        name - The property name
        description - A description for the property
        defaultValue - The default value of the property (only used for constant values such as strings, numbers, enums etc.)
        Returns:
        This property metadata or null if no existing configuration is active
      • buildPropertyPath

        protected abstract java.lang.String buildPropertyPath​(T owningType,
                                                              T declaringType,
                                                              java.lang.String propertyName)

        Build a property path for the given declaring type and property name.

        For ConfigurationProperties that path is a property is established by looking at the value of the ConfigurationProperties and then calculating the path based on the inheritance tree.

        For example consider the following classes:

        
          @ConfigurationProperties("parent")
           public class ParentProperties {
              String foo;
           }
        
          @ConfigurationProperties("child")
           public class ChildProperties extends ParentProperties {
              String bar;
           }
         

        The path of the property foo will be "parent.foo" whilst the path of the property bar will be "parent.child.bar" factoring in the class hierarchy

        Inner classes hierarchies are also taken into account

        Parameters:
        owningType - The owning type
        declaringType - The declaring type
        propertyName - The property name
        Returns:
        The property path
      • buildTypePath

        protected abstract java.lang.String buildTypePath​(T owningType,
                                                          T declaringType)
        Parameters:
        owningType - The owning type
        declaringType - The type
        Returns:
        The type path
      • buildTypePath

        protected abstract java.lang.String buildTypePath​(T owningType,
                                                          T declaringType,
                                                          io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)
        Parameters:
        owningType - The owning type
        declaringType - The type
        annotationMetadata - The annotation metadata
        Returns:
        The type path
      • getTypeString

        protected abstract java.lang.String getTypeString​(T type)
        Convert the given type to a string.
        Parameters:
        type - The type
        Returns:
        The string
      • getAnnotationMetadata

        protected abstract io.micronaut.core.annotation.AnnotationMetadata getAnnotationMetadata​(T type)
        Parameters:
        type - The type
        Returns:
        The annotation metadata for the type
      • getConfigurationMetadataBuilder

        public static java.util.Optional<ConfigurationMetadataBuilder<?>> getConfigurationMetadataBuilder()
        Obtains the currently active metadata builder.
        Returns:
        The builder