From 3e4c8d0cb20580bf9ab9a0abcd6bfa5bde6dd4ca Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Tue, 10 Sep 2024 15:50:31 +0200 Subject: [PATCH] Config Doc - Clarify sourceClass/sourceType In the light of the Spring config metadata, let's get rid of sourceClass and let's avoid using sourceType for the field/method type as it's confusing. Fixes #43175 --- .../discovery/DiscoveryConfigProperty.java | 51 ++++++++++--------- .../discovery/DiscoveryRootElement.java | 2 +- .../config/model/AbstractConfigItem.java | 25 ++++----- .../config/model/ConfigProperty.java | 8 +-- .../config/model/ConfigSection.java | 6 +-- ...SourceType.java => SourceElementType.java} | 2 +- .../config/resolver/ConfigResolver.java | 8 +-- .../scanner/AbstractConfigListener.java | 2 +- .../config/scanner/ConfigMappingListener.java | 12 ++--- .../scanner/LegacyConfigRootListener.java | 12 ++--- .../doc/generator/AbstractFormatter.java | 14 ++--- .../metadata/AttachConfigMetadataMojo.java | 46 +++++++++++------ 12 files changed, 105 insertions(+), 83 deletions(-) rename core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/{SourceType.java => SourceElementType.java} (74%) diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/discovery/DiscoveryConfigProperty.java b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/discovery/DiscoveryConfigProperty.java index cbff969922b77..636bde16d9671 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/discovery/DiscoveryConfigProperty.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/discovery/DiscoveryConfigProperty.java @@ -1,16 +1,16 @@ package io.quarkus.annotation.processor.documentation.config.discovery; import io.quarkus.annotation.processor.documentation.config.model.Deprecation; -import io.quarkus.annotation.processor.documentation.config.model.SourceType; +import io.quarkus.annotation.processor.documentation.config.model.SourceElementType; import io.quarkus.annotation.processor.documentation.config.util.TypeUtil; import io.quarkus.annotation.processor.util.Strings; public class DiscoveryConfigProperty { private final String path; - private final String sourceClass; - private final String sourceName; - private final SourceType sourceType; + private final String sourceType; + private final String sourceElementName; + private final SourceElementType sourceElementType; private final String defaultValue; private final String defaultValueForDoc; private final Deprecation deprecation; @@ -22,15 +22,16 @@ public class DiscoveryConfigProperty { private final boolean section; private final boolean sectionGenerated; - public DiscoveryConfigProperty(String path, String sourceClass, String sourceName, SourceType sourceType, + public DiscoveryConfigProperty(String path, String sourceType, String sourceElementName, + SourceElementType sourceElementType, String defaultValue, String defaultValueForDoc, Deprecation deprecation, String mapKey, boolean unnamedMapKey, ResolvedType type, boolean converted, boolean enforceHyphenateEnumValue, boolean section, boolean sectionGenerated) { this.path = path; - this.sourceClass = sourceClass; - this.sourceName = sourceName; this.sourceType = sourceType; + this.sourceElementName = sourceElementName; + this.sourceElementType = sourceElementType; this.defaultValue = defaultValue; this.defaultValueForDoc = defaultValueForDoc; this.deprecation = deprecation; @@ -47,16 +48,16 @@ public String getPath() { return path; } - public String getSourceClass() { - return sourceClass; + public String getSourceType() { + return sourceType; } - public String getSourceName() { - return sourceName; + public String getSourceElementName() { + return sourceElementName; } - public SourceType getSourceType() { - return sourceType; + public SourceElementType getSourceElementType() { + return sourceElementType; } public String getDefaultValue() { @@ -110,8 +111,8 @@ public String toString() { public String toString(String prefix) { StringBuilder sb = new StringBuilder(); sb.append(prefix + "name = " + path + "\n"); - sb.append(prefix + "sourceClass = " + sourceClass + "\n"); - sb.append(prefix + "sourceName = " + sourceName + "\n"); + sb.append(prefix + "sourceType = " + sourceType + "\n"); + sb.append(prefix + "sourceElementName = " + sourceElementName + "\n"); sb.append(prefix + "type = " + type + "\n"); if (defaultValue != null) { sb.append(prefix + "defaultValue = " + defaultValue + "\n"); @@ -135,16 +136,17 @@ public String toString(String prefix) { return sb.toString(); } - public static Builder builder(String sourceClass, String sourceName, SourceType sourceType, ResolvedType type) { - return new Builder(sourceClass, sourceName, sourceType, type); + public static Builder builder(String sourceType, String sourceElementName, SourceElementType sourceElementType, + ResolvedType type) { + return new Builder(sourceType, sourceElementName, sourceElementType, type); } public static class Builder { private String name; - private final String sourceClass; - private final String sourceName; - private final SourceType sourceType; + private final String sourceType; + private final String sourceElementName; + private final SourceElementType sourceElementType; private final ResolvedType type; private String defaultValue; private String defaultValueForDoc; @@ -156,10 +158,10 @@ public static class Builder { private boolean section = false; private boolean sectionGenerated = false; - public Builder(String sourceClass, String sourceName, SourceType sourceType, ResolvedType type) { - this.sourceClass = sourceClass; - this.sourceName = sourceName; + public Builder(String sourceType, String sourceElementName, SourceElementType sourceElementType, ResolvedType type) { this.sourceType = sourceType; + this.sourceElementName = sourceElementName; + this.sourceElementType = sourceElementType; this.type = type; } @@ -217,7 +219,8 @@ public DiscoveryConfigProperty build() { defaultValue = TypeUtil.normalizeDurationValue(defaultValue); } - return new DiscoveryConfigProperty(name, sourceClass, sourceName, sourceType, defaultValue, defaultValueForDoc, + return new DiscoveryConfigProperty(name, sourceType, sourceElementName, sourceElementType, defaultValue, + defaultValueForDoc, deprecation, mapKey, unnamedMapKey, type, converted, enforceHyphenateEnumValue, section, sectionGenerated); } } diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/discovery/DiscoveryRootElement.java b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/discovery/DiscoveryRootElement.java index 8a0b39ccd483c..001a04786cfc1 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/discovery/DiscoveryRootElement.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/discovery/DiscoveryRootElement.java @@ -38,7 +38,7 @@ public String getQualifiedName() { } public void addProperty(DiscoveryConfigProperty discoveryConfigProperty) { - properties.put(discoveryConfigProperty.getSourceName(), discoveryConfigProperty); + properties.put(discoveryConfigProperty.getSourceElementName(), discoveryConfigProperty); } public Map getProperties() { diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/AbstractConfigItem.java b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/AbstractConfigItem.java index 643ed96d28620..a454e64e58647 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/AbstractConfigItem.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/AbstractConfigItem.java @@ -7,35 +7,36 @@ public sealed abstract class AbstractConfigItem implements Comparable permits ConfigProperty, ConfigSection { - protected final String sourceClass; - protected final String sourceName; - protected final SourceType sourceType; + protected final String sourceType; + protected final String sourceElementName; + protected final SourceElementType sourceElementType; protected final Path path; protected final String type; protected Deprecation deprecation; - public AbstractConfigItem(String sourceClass, String sourceName, SourceType sourceType, Path path, String type, + public AbstractConfigItem(String sourceType, String sourceElementName, SourceElementType sourceElementType, Path path, + String type, Deprecation deprecation) { - this.sourceClass = sourceClass; - this.sourceName = sourceName; this.sourceType = sourceType; + this.sourceElementName = sourceElementName; + this.sourceElementType = sourceElementType; this.path = path; this.type = type; this.deprecation = deprecation; } - public String getSourceClass() { - return sourceClass; + public String getSourceType() { + return sourceType; } - public String getSourceName() { - return sourceName; + public String getSourceElementName() { + return sourceElementName; } - public SourceType getSourceType() { - return sourceType; + public SourceElementType getSourceElementType() { + return sourceElementType; } public Path getPath() { diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/ConfigProperty.java b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/ConfigProperty.java index 1be3576d4e27d..ab49c16be665a 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/ConfigProperty.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/ConfigProperty.java @@ -29,14 +29,14 @@ public final class ConfigProperty extends AbstractConfigItem { private final String javadocSiteLink; - public ConfigProperty(ConfigPhase phase, String sourceClass, String sourceName, SourceType sourceType, PropertyPath path, - List additionalPaths, String type, String typeDescription, boolean map, boolean list, - boolean optional, + public ConfigProperty(ConfigPhase phase, String sourceType, String sourceElementName, SourceElementType sourceElementType, + PropertyPath path, List additionalPaths, String type, String typeDescription, boolean map, + boolean list, boolean optional, String mapKey, boolean unnamedMapKey, boolean withinMap, boolean converted, @JsonProperty("enum") boolean isEnum, EnumAcceptedValues enumAcceptedValues, String defaultValue, String javadocSiteLink, Deprecation deprecation) { - super(sourceClass, sourceName, sourceType, path, type, deprecation); + super(sourceType, sourceElementName, sourceElementType, path, type, deprecation); this.phase = phase; this.additionalPaths = additionalPaths != null ? Collections.unmodifiableList(additionalPaths) : List.of(); this.typeDescription = typeDescription; diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/ConfigSection.java b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/ConfigSection.java index da33958996e84..4b0774ef6ac1c 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/ConfigSection.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/ConfigSection.java @@ -11,9 +11,9 @@ public final class ConfigSection extends AbstractConfigItem implements ConfigIte private final List items = new ArrayList<>(); private final int level; - public ConfigSection(String sourceClass, String sourceName, SourceType sourceType, SectionPath path, String type, int level, - boolean generated, Deprecation deprecation) { - super(sourceClass, sourceName, sourceType, path, type, deprecation); + public ConfigSection(String sourceType, String sourceElementName, SourceElementType sourceElementType, SectionPath path, + String type, int level, boolean generated, Deprecation deprecation) { + super(sourceType, sourceElementName, sourceElementType, path, type, deprecation); this.generated = generated; this.level = level; } diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/SourceType.java b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/SourceElementType.java similarity index 74% rename from core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/SourceType.java rename to core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/SourceElementType.java index 6da161b75714e..8d3fc0d573038 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/SourceType.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/SourceElementType.java @@ -1,6 +1,6 @@ package io.quarkus.annotation.processor.documentation.config.model; -public enum SourceType { +public enum SourceElementType { METHOD, FIELD; diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/resolver/ConfigResolver.java b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/resolver/ConfigResolver.java index d6fa963d6dd12..34131fcf17a6c 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/resolver/ConfigResolver.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/resolver/ConfigResolver.java @@ -134,8 +134,8 @@ private void resolveProperty(ConfigRoot configRoot, Map e if (configSection != null) { configSection.appendState(discoveryConfigProperty.isSectionGenerated(), deprecation); } else { - configSection = new ConfigSection(discoveryConfigProperty.getSourceClass(), - discoveryConfigProperty.getSourceName(), discoveryConfigProperty.getSourceType(), + configSection = new ConfigSection(discoveryConfigProperty.getSourceType(), + discoveryConfigProperty.getSourceElementName(), discoveryConfigProperty.getSourceElementType(), new SectionPath(path), typeQualifiedName, context.getSectionLevel(), discoveryConfigProperty.isSectionGenerated(), deprecation); context.getItemCollection().addItem(configSection); @@ -202,9 +202,9 @@ private void resolveProperty(ConfigRoot configRoot, Map e // this is a standard property ConfigProperty configProperty = new ConfigProperty(phase, - discoveryConfigProperty.getSourceClass(), - discoveryConfigProperty.getSourceName(), discoveryConfigProperty.getSourceType(), + discoveryConfigProperty.getSourceElementName(), + discoveryConfigProperty.getSourceElementType(), propertyPath, additionalPropertyPaths, typeQualifiedName, typeSimplifiedName, discoveryConfigProperty.getType().isMap(), discoveryConfigProperty.getType().isList(), diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/scanner/AbstractConfigListener.java b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/scanner/AbstractConfigListener.java index 4ab20e4ee24e3..4eb92d7e84277 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/scanner/AbstractConfigListener.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/scanner/AbstractConfigListener.java @@ -67,7 +67,7 @@ public void onResolvedEnum(TypeElement enumTypeElement) { } protected void handleCommonPropertyAnnotations(DiscoveryConfigProperty.Builder builder, - Map propertyAnnotations, ResolvedType resolvedType, String sourceName) { + Map propertyAnnotations, ResolvedType resolvedType, String sourceElementName) { AnnotationMirror deprecatedAnnotation = propertyAnnotations.get(Deprecated.class.getName()); if (deprecatedAnnotation != null) { diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/scanner/ConfigMappingListener.java b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/scanner/ConfigMappingListener.java index 1847c8e203503..cda99142c602e 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/scanner/ConfigMappingListener.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/scanner/ConfigMappingListener.java @@ -15,7 +15,7 @@ import io.quarkus.annotation.processor.documentation.config.discovery.DiscoveryRootElement; import io.quarkus.annotation.processor.documentation.config.discovery.ResolvedType; import io.quarkus.annotation.processor.documentation.config.model.ConfigPhase; -import io.quarkus.annotation.processor.documentation.config.model.SourceType; +import io.quarkus.annotation.processor.documentation.config.model.SourceElementType; import io.quarkus.annotation.processor.documentation.config.util.ConfigNamingUtil; import io.quarkus.annotation.processor.documentation.config.util.Markers; import io.quarkus.annotation.processor.documentation.config.util.Types; @@ -125,11 +125,11 @@ public void onEnclosedMethod(DiscoveryRootElement discoveryRootElement, TypeElem Map methodAnnotations = utils.element().getAnnotations(method); - String sourceName = method.getSimpleName().toString(); + String sourceElementName = method.getSimpleName().toString(); DiscoveryConfigProperty.Builder builder = DiscoveryConfigProperty.builder(clazz.getQualifiedName().toString(), - sourceName, SourceType.METHOD, resolvedType); + sourceElementName, SourceElementType.METHOD, resolvedType); - String name = ConfigNamingUtil.hyphenate(sourceName); + String name = ConfigNamingUtil.hyphenate(sourceElementName); AnnotationMirror withNameAnnotation = methodAnnotations.get(Types.ANNOTATION_CONFIG_WITH_NAME); if (withNameAnnotation != null) { name = withNameAnnotation.getElementValues().values().iterator().next().getValue().toString(); @@ -152,7 +152,7 @@ public void onEnclosedMethod(DiscoveryRootElement discoveryRootElement, TypeElem } if (resolvedType.isMap()) { - String mapKey = ConfigNamingUtil.hyphenate(sourceName); + String mapKey = ConfigNamingUtil.hyphenate(sourceElementName); AnnotationMirror configDocMapKeyAnnotation = methodAnnotations.get(Types.ANNOTATION_CONFIG_DOC_MAP_KEY); if (configDocMapKeyAnnotation != null) { mapKey = configDocMapKeyAnnotation.getElementValues().values().iterator().next().getValue().toString(); @@ -169,7 +169,7 @@ public void onEnclosedMethod(DiscoveryRootElement discoveryRootElement, TypeElem builder.converted(); } - handleCommonPropertyAnnotations(builder, methodAnnotations, resolvedType, sourceName); + handleCommonPropertyAnnotations(builder, methodAnnotations, resolvedType, sourceElementName); discoveryRootElement.addProperty(builder.build()); } diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/scanner/LegacyConfigRootListener.java b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/scanner/LegacyConfigRootListener.java index 6a1ca922d3da3..2410b8c62b9d6 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/scanner/LegacyConfigRootListener.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/scanner/LegacyConfigRootListener.java @@ -16,7 +16,7 @@ import io.quarkus.annotation.processor.documentation.config.discovery.DiscoveryRootElement; import io.quarkus.annotation.processor.documentation.config.discovery.ResolvedType; import io.quarkus.annotation.processor.documentation.config.model.ConfigPhase; -import io.quarkus.annotation.processor.documentation.config.model.SourceType; +import io.quarkus.annotation.processor.documentation.config.model.SourceElementType; import io.quarkus.annotation.processor.documentation.config.util.ConfigNamingUtil; import io.quarkus.annotation.processor.documentation.config.util.Markers; import io.quarkus.annotation.processor.documentation.config.util.Types; @@ -123,11 +123,11 @@ public void onEnclosedField(DiscoveryRootElement discoveryRootElement, TypeEleme Map fieldAnnotations = utils.element().getAnnotations(field); - String sourceName = field.getSimpleName().toString(); - String name = ConfigNamingUtil.hyphenate(sourceName); + String sourceElementName = field.getSimpleName().toString(); + String name = ConfigNamingUtil.hyphenate(sourceElementName); DiscoveryConfigProperty.Builder builder = DiscoveryConfigProperty.builder(clazz.getQualifiedName().toString(), - sourceName, SourceType.FIELD, resolvedType); + sourceElementName, SourceElementType.FIELD, resolvedType); AnnotationMirror configItemAnnotation = fieldAnnotations.get(Types.ANNOTATION_CONFIG_ITEM); if (configItemAnnotation != null) { @@ -158,7 +158,7 @@ public void onEnclosedField(DiscoveryRootElement discoveryRootElement, TypeEleme builder.name(name); if (resolvedType.isMap()) { - String mapKey = ConfigNamingUtil.hyphenate(sourceName); + String mapKey = ConfigNamingUtil.hyphenate(sourceElementName); AnnotationMirror configDocMapKeyAnnotation = fieldAnnotations.get(Types.ANNOTATION_CONFIG_DOC_MAP_KEY); if (configDocMapKeyAnnotation != null) { mapKey = configDocMapKeyAnnotation.getElementValues().values().iterator().next().getValue().toString(); @@ -171,7 +171,7 @@ public void onEnclosedField(DiscoveryRootElement discoveryRootElement, TypeEleme builder.converted(); } - handleCommonPropertyAnnotations(builder, fieldAnnotations, resolvedType, sourceName); + handleCommonPropertyAnnotations(builder, fieldAnnotations, resolvedType, sourceElementName); discoveryRootElement.addProperty(builder.build()); } diff --git a/devtools/config-doc-maven-plugin/src/main/java/io/quarkus/maven/config/doc/generator/AbstractFormatter.java b/devtools/config-doc-maven-plugin/src/main/java/io/quarkus/maven/config/doc/generator/AbstractFormatter.java index 49384bb924e52..47e41b599eaa4 100644 --- a/devtools/config-doc-maven-plugin/src/main/java/io/quarkus/maven/config/doc/generator/AbstractFormatter.java +++ b/devtools/config-doc-maven-plugin/src/main/java/io/quarkus/maven/config/doc/generator/AbstractFormatter.java @@ -36,8 +36,8 @@ public boolean displayConfigRootDescription(ConfigRootKey configRootKey, int map @Override public String formatDescription(ConfigProperty configProperty) { - Optional javadocElement = javadocRepository.getElement(configProperty.getSourceClass(), - configProperty.getSourceName()); + Optional javadocElement = javadocRepository.getElement(configProperty.getSourceType(), + configProperty.getSourceElementName()); if (javadocElement.isEmpty()) { return null; @@ -192,19 +192,21 @@ public String toAnchor(String value) { @Override public String formatSectionTitle(ConfigSection configSection) { - Optional javadocElement = javadocRepository.getElement(configSection.getSourceClass(), - configSection.getSourceName()); + Optional javadocElement = javadocRepository.getElement(configSection.getSourceType(), + configSection.getSourceElementName()); if (javadocElement.isEmpty()) { throw new IllegalStateException( - "Couldn't find section title for: " + configSection.getSourceClass() + "#" + configSection.getSourceName()); + "Couldn't find section title for: " + configSection.getSourceType() + "#" + + configSection.getSourceElementName()); } String javadoc = JavadocTransformer.transform(javadocElement.get().description(), javadocElement.get().format(), javadocFormat()); if (javadoc == null || javadoc.isBlank()) { throw new IllegalStateException( - "Couldn't find section title for: " + configSection.getSourceClass() + "#" + configSection.getSourceName()); + "Couldn't find section title for: " + configSection.getSourceType() + "#" + + configSection.getSourceElementName()); } return trimFinalDot(javadoc); diff --git a/devtools/extension-deployment-maven-plugin/src/main/java/io/quarkus/maven/extension/deployment/metadata/AttachConfigMetadataMojo.java b/devtools/extension-deployment-maven-plugin/src/main/java/io/quarkus/maven/extension/deployment/metadata/AttachConfigMetadataMojo.java index 2f5c221517eba..79705db38ca9e 100644 --- a/devtools/extension-deployment-maven-plugin/src/main/java/io/quarkus/maven/extension/deployment/metadata/AttachConfigMetadataMojo.java +++ b/devtools/extension-deployment-maven-plugin/src/main/java/io/quarkus/maven/extension/deployment/metadata/AttachConfigMetadataMojo.java @@ -10,6 +10,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Optional; import org.apache.maven.artifact.Artifact; import org.apache.maven.execution.MavenSession; @@ -24,6 +25,7 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; +import io.quarkus.annotation.processor.documentation.config.formatter.JavadocTransformer; import io.quarkus.annotation.processor.documentation.config.merger.JavadocMerger; import io.quarkus.annotation.processor.documentation.config.merger.JavadocRepository; import io.quarkus.annotation.processor.documentation.config.merger.MergedModel; @@ -37,7 +39,8 @@ import io.quarkus.annotation.processor.documentation.config.model.Extension; import io.quarkus.annotation.processor.documentation.config.model.Extension.NameSource; import io.quarkus.annotation.processor.documentation.config.model.JavadocElements.JavadocElement; -import io.quarkus.annotation.processor.documentation.config.model.SourceType; +import io.quarkus.annotation.processor.documentation.config.model.JavadocFormat; +import io.quarkus.annotation.processor.documentation.config.model.SourceElementType; import io.quarkus.annotation.processor.documentation.config.util.JacksonMappers; import io.quarkus.maven.extension.deployment.metadata.model.spring.QuarkusConfigAdditionalMetadataProperty; import io.quarkus.maven.extension.deployment.metadata.model.spring.QuarkusConfigAdditionalMetadataProperty.ConfigPhase; @@ -136,27 +139,29 @@ public void visit(AbstractConfigItem configItem) { configProperty.getDeprecation().since()) : null; - // TODO: be careful, this is asciidoc, we will discuss this further with the IDE teams - String description = javadocRepository - .getElement(configProperty.getSourceClass(), configProperty.getSourceName()) - .map(JavadocElement::description).orElse(null); + String description = getJavadoc(javadocRepository, configProperty.getSourceType(), + configProperty.getSourceElementName()); + List hintValues = List.of(); ConfigPhase phase = ConfigPhase.of(configProperty.getPhase()); properties.add(new SpringConfigMetadataProperty(configProperty.getPath().property(), configProperty.getType(), description, - configProperty.getSourceClass(), - configProperty.getSourceType() == SourceType.FIELD ? configProperty.getSourceName() : null, - configProperty.getSourceType() == SourceType.METHOD ? configProperty.getSourceName() : null, + configProperty.getSourceType(), + configProperty.getSourceElementType() == SourceElementType.FIELD + ? configProperty.getSourceElementName() + : null, + configProperty.getSourceElementType() == SourceElementType.METHOD + ? configProperty.getSourceElementName() + : null, configProperty.getDefaultValue(), deprecation, new QuarkusConfigAdditionalMetadataProperty(phase, configProperty.getPath().environmentVariable(), configProperty.isOptional()))); if (configProperty.isEnum()) { hintValues = configProperty.getEnumAcceptedValues().values().entrySet().stream() .map(e -> new SpringConfigMetadataHintValue(e.getValue().configValue(), - javadocRepository.getElement(configProperty.getType(), e.getKey()) - .map(JavadocElement::description).orElse(null))) + getJavadoc(javadocRepository, configProperty.getType(), e.getKey()))) .toList(); hints.add(new SpringConfigMetadataHint(configProperty.getPath().property(), hintValues)); } @@ -164,12 +169,12 @@ deprecation, new QuarkusConfigAdditionalMetadataProperty(phase, for (PropertyPath additionalPath : configProperty.getAdditionalPaths()) { properties.add( new SpringConfigMetadataProperty(additionalPath.property(), configProperty.getType(), - description, configProperty.getSourceClass(), - configProperty.getSourceType() == SourceType.FIELD - ? configProperty.getSourceName() + description, configProperty.getSourceType(), + configProperty.getSourceElementType() == SourceElementType.FIELD + ? configProperty.getSourceElementName() : null, - configProperty.getSourceType() == SourceType.METHOD - ? configProperty.getSourceName() + configProperty.getSourceElementType() == SourceElementType.METHOD + ? configProperty.getSourceElementName() : null, configProperty.getDefaultValue(), deprecation, new QuarkusConfigAdditionalMetadataProperty(phase, @@ -220,4 +225,15 @@ private Extension getExtension() { null, NameSource.NONE, true); } + + private String getJavadoc(JavadocRepository javadocRepository, String sourceType, String sourceElementName) { + Optional javadocElement = javadocRepository + .getElement(sourceType, sourceElementName); + if (javadocElement.isEmpty()) { + return null; + } + + return JavadocTransformer.transform(javadocElement.get().description(), + javadocElement.get().format(), JavadocFormat.MARKDOWN); + } }