Class ConfigurationMetadataBuilder<T>
- java.lang.Object
-
- io.micronaut.inject.configuration.ConfigurationMetadataBuilder<T>
-
- Type Parameters:
T- The type
public abstract class ConfigurationMetadataBuilder<T> extends java.lang.ObjectA 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 Summary
Constructors Constructor Description ConfigurationMetadataBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract java.lang.StringbuildPropertyPath(T owningType, T declaringType, java.lang.String propertyName)Build a property path for the given declaring type and property name.protected abstract java.lang.StringbuildTypePath(T owningType, T declaringType)Variation ofbuildPropertyPath(Object, Object, String)for types.protected abstract java.lang.StringbuildTypePath(T owningType, T declaringType, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)Variation ofbuildPropertyPath(Object, Object, String)for types.protected abstract io.micronaut.core.annotation.AnnotationMetadatagetAnnotationMetadata(T type)static java.util.Optional<ConfigurationMetadataBuilder<?>>getConfigurationMetadataBuilder()Obtains the currently active metadata builder.java.util.List<ConfigurationMetadata>getConfigurations()abstract Element[]getOriginatingElements()java.util.List<PropertyMetadata>getProperties()protected abstract java.lang.StringgetTypeString(T type)Convert the given type to a string.booleanhasMetadata()static voidsetConfigurationMetadataBuilder(ConfigurationMetadataBuilder<?> builder)Sets or clears the currentConfigurationMetadataBuilder.ConfigurationMetadatavisitProperties(T type, java.lang.String description)Visit aConfigurationPropertiesclass.ConfigurationMetadatavisitProperties(T type, java.lang.String description, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)Visit aConfigurationPropertiesclass.PropertyMetadatavisitProperty(java.lang.String propertyType, java.lang.String name, java.lang.String description, java.lang.String defaultValue)Visit a configuration property on the last declared properties instance.PropertyMetadatavisitProperty(T owningType, T declaringType, java.lang.String propertyType, java.lang.String name, java.lang.String description, java.lang.String defaultValue)Visit a configuration property.
-
-
-
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
-
visitProperties
public ConfigurationMetadata visitProperties(T type, @Nullable java.lang.String description)
Visit aConfigurationPropertiesclass.- Parameters:
type- The type of theConfigurationPropertiesdescription- A description- Returns:
- This
ConfigurationMetadata
-
visitProperties
public ConfigurationMetadata visitProperties(T type, @Nullable java.lang.String description, @NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)
Visit aConfigurationPropertiesclass.- Parameters:
type- The type of theConfigurationPropertiesdescription- A descriptionannotationMetadata- the annotation metadata- Returns:
- This
ConfigurationMetadata
-
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 propertydeclaringType- The declaring type of the propertypropertyType- The property typename- The property namedescription- A description for the propertydefaultValue- 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 typename- The property namedescription- A description for the propertydefaultValue- 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
ConfigurationPropertiesthat path is a property is established by looking at the value of theConfigurationPropertiesand 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
foowill be "parent.foo" whilst the path of the propertybarwill be "parent.child.bar" factoring in the class hierarchyInner classes hierarchies are also taken into account
- Parameters:
owningType- The owning typedeclaringType- The declaring typepropertyName- The property name- Returns:
- The property path
-
buildTypePath
protected abstract java.lang.String buildTypePath(T owningType, T declaringType)
Variation ofbuildPropertyPath(Object, Object, String)for types.- Parameters:
owningType- The owning typedeclaringType- The type- Returns:
- The type path
-
buildTypePath
protected abstract java.lang.String buildTypePath(T owningType, T declaringType, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)
Variation ofbuildPropertyPath(Object, Object, String)for types.- Parameters:
owningType- The owning typedeclaringType- The typeannotationMetadata- 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
-
setConfigurationMetadataBuilder
public static void setConfigurationMetadataBuilder(@Nullable ConfigurationMetadataBuilder<?> builder)Sets or clears the currentConfigurationMetadataBuilder.- Parameters:
builder- the builder
-
-