Skip to content

Commit

Permalink
Config Doc - Clarify sourceClass/sourceType
Browse files Browse the repository at this point in the history
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 quarkusio#43175
  • Loading branch information
gsmet committed Sep 13, 2024
1 parent cc54a98 commit 3e4c8d0
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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");
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public String getQualifiedName() {
}

public void addProperty(DiscoveryConfigProperty discoveryConfigProperty) {
properties.put(discoveryConfigProperty.getSourceName(), discoveryConfigProperty);
properties.put(discoveryConfigProperty.getSourceElementName(), discoveryConfigProperty);
}

public Map<String, DiscoveryConfigProperty> getProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,36 @@
public sealed abstract class AbstractConfigItem implements Comparable<AbstractConfigItem>
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PropertyPath> additionalPaths, String type, String typeDescription, boolean map, boolean list,
boolean optional,
public ConfigProperty(ConfigPhase phase, String sourceType, String sourceElementName, SourceElementType sourceElementType,
PropertyPath path, List<PropertyPath> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public final class ConfigSection extends AbstractConfigItem implements ConfigIte
private final List<AbstractConfigItem> 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.quarkus.annotation.processor.documentation.config.model;

public enum SourceType {
public enum SourceElementType {

METHOD,
FIELD;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ private void resolveProperty(ConfigRoot configRoot, Map<String, ConfigSection> 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);
Expand Down Expand Up @@ -202,9 +202,9 @@ private void resolveProperty(ConfigRoot configRoot, Map<String, ConfigSection> 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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void onResolvedEnum(TypeElement enumTypeElement) {
}

protected void handleCommonPropertyAnnotations(DiscoveryConfigProperty.Builder builder,
Map<String, AnnotationMirror> propertyAnnotations, ResolvedType resolvedType, String sourceName) {
Map<String, AnnotationMirror> propertyAnnotations, ResolvedType resolvedType, String sourceElementName) {

AnnotationMirror deprecatedAnnotation = propertyAnnotations.get(Deprecated.class.getName());
if (deprecatedAnnotation != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -125,11 +125,11 @@ public void onEnclosedMethod(DiscoveryRootElement discoveryRootElement, TypeElem

Map<String, AnnotationMirror> 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();
Expand All @@ -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();
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -123,11 +123,11 @@ public void onEnclosedField(DiscoveryRootElement discoveryRootElement, TypeEleme

Map<String, AnnotationMirror> 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) {
Expand Down Expand Up @@ -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();
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public boolean displayConfigRootDescription(ConfigRootKey configRootKey, int map

@Override
public String formatDescription(ConfigProperty configProperty) {
Optional<JavadocElement> javadocElement = javadocRepository.getElement(configProperty.getSourceClass(),
configProperty.getSourceName());
Optional<JavadocElement> javadocElement = javadocRepository.getElement(configProperty.getSourceType(),
configProperty.getSourceElementName());

if (javadocElement.isEmpty()) {
return null;
Expand Down Expand Up @@ -192,19 +192,21 @@ public String toAnchor(String value) {

@Override
public String formatSectionTitle(ConfigSection configSection) {
Optional<JavadocElement> javadocElement = javadocRepository.getElement(configSection.getSourceClass(),
configSection.getSourceName());
Optional<JavadocElement> 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);
Expand Down
Loading

0 comments on commit 3e4c8d0

Please sign in to comment.