Skip to content

Commit 1f3b5b1

Browse files
committed
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
1 parent e867fef commit 1f3b5b1

File tree

12 files changed

+88
-78
lines changed

12 files changed

+88
-78
lines changed

core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/discovery/DiscoveryConfigProperty.java

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package io.quarkus.annotation.processor.documentation.config.discovery;
22

33
import io.quarkus.annotation.processor.documentation.config.model.Deprecation;
4-
import io.quarkus.annotation.processor.documentation.config.model.SourceType;
4+
import io.quarkus.annotation.processor.documentation.config.model.SourceElementType;
55
import io.quarkus.annotation.processor.documentation.config.util.TypeUtil;
66
import io.quarkus.annotation.processor.util.Strings;
77

88
public class DiscoveryConfigProperty {
99

1010
private final String path;
11-
private final String sourceClass;
12-
private final String sourceName;
13-
private final SourceType sourceType;
11+
private final String sourceType;
12+
private final String sourceElementName;
13+
private final SourceElementType sourceElementType;
1414
private final String defaultValue;
1515
private final String defaultValueForDoc;
1616
private final Deprecation deprecation;
@@ -22,15 +22,16 @@ public class DiscoveryConfigProperty {
2222
private final boolean section;
2323
private final boolean sectionGenerated;
2424

25-
public DiscoveryConfigProperty(String path, String sourceClass, String sourceName, SourceType sourceType,
25+
public DiscoveryConfigProperty(String path, String sourceType, String sourceElementName,
26+
SourceElementType sourceElementType,
2627
String defaultValue,
2728
String defaultValueForDoc, Deprecation deprecation, String mapKey, boolean unnamedMapKey,
2829
ResolvedType type, boolean converted, boolean enforceHyphenateEnumValue,
2930
boolean section, boolean sectionGenerated) {
3031
this.path = path;
31-
this.sourceClass = sourceClass;
32-
this.sourceName = sourceName;
3332
this.sourceType = sourceType;
33+
this.sourceElementName = sourceElementName;
34+
this.sourceElementType = sourceElementType;
3435
this.defaultValue = defaultValue;
3536
this.defaultValueForDoc = defaultValueForDoc;
3637
this.deprecation = deprecation;
@@ -47,16 +48,16 @@ public String getPath() {
4748
return path;
4849
}
4950

50-
public String getSourceClass() {
51-
return sourceClass;
51+
public String getSourceType() {
52+
return sourceType;
5253
}
5354

54-
public String getSourceName() {
55-
return sourceName;
55+
public String getSourceElementName() {
56+
return sourceElementName;
5657
}
5758

58-
public SourceType getSourceType() {
59-
return sourceType;
59+
public SourceElementType getSourceElementType() {
60+
return sourceElementType;
6061
}
6162

6263
public String getDefaultValue() {
@@ -110,8 +111,8 @@ public String toString() {
110111
public String toString(String prefix) {
111112
StringBuilder sb = new StringBuilder();
112113
sb.append(prefix + "name = " + path + "\n");
113-
sb.append(prefix + "sourceClass = " + sourceClass + "\n");
114-
sb.append(prefix + "sourceName = " + sourceName + "\n");
114+
sb.append(prefix + "sourceType = " + sourceType + "\n");
115+
sb.append(prefix + "sourceElementName = " + sourceElementName + "\n");
115116
sb.append(prefix + "type = " + type + "\n");
116117
if (defaultValue != null) {
117118
sb.append(prefix + "defaultValue = " + defaultValue + "\n");
@@ -135,16 +136,17 @@ public String toString(String prefix) {
135136
return sb.toString();
136137
}
137138

138-
public static Builder builder(String sourceClass, String sourceName, SourceType sourceType, ResolvedType type) {
139-
return new Builder(sourceClass, sourceName, sourceType, type);
139+
public static Builder builder(String sourceType, String sourceElementName, SourceElementType sourceElementType,
140+
ResolvedType type) {
141+
return new Builder(sourceType, sourceElementName, sourceElementType, type);
140142
}
141143

142144
public static class Builder {
143145

144146
private String name;
145-
private final String sourceClass;
146-
private final String sourceName;
147-
private final SourceType sourceType;
147+
private final String sourceType;
148+
private final String sourceElementName;
149+
private final SourceElementType sourceElementType;
148150
private final ResolvedType type;
149151
private String defaultValue;
150152
private String defaultValueForDoc;
@@ -156,10 +158,10 @@ public static class Builder {
156158
private boolean section = false;
157159
private boolean sectionGenerated = false;
158160

159-
public Builder(String sourceClass, String sourceName, SourceType sourceType, ResolvedType type) {
160-
this.sourceClass = sourceClass;
161-
this.sourceName = sourceName;
161+
public Builder(String sourceType, String sourceElementName, SourceElementType sourceElementType, ResolvedType type) {
162162
this.sourceType = sourceType;
163+
this.sourceElementName = sourceElementName;
164+
this.sourceElementType = sourceElementType;
163165
this.type = type;
164166
}
165167

@@ -217,7 +219,8 @@ public DiscoveryConfigProperty build() {
217219
defaultValue = TypeUtil.normalizeDurationValue(defaultValue);
218220
}
219221

220-
return new DiscoveryConfigProperty(name, sourceClass, sourceName, sourceType, defaultValue, defaultValueForDoc,
222+
return new DiscoveryConfigProperty(name, sourceType, sourceElementName, sourceElementType, defaultValue,
223+
defaultValueForDoc,
221224
deprecation, mapKey, unnamedMapKey, type, converted, enforceHyphenateEnumValue, section, sectionGenerated);
222225
}
223226
}

core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/discovery/DiscoveryRootElement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public String getQualifiedName() {
3838
}
3939

4040
public void addProperty(DiscoveryConfigProperty discoveryConfigProperty) {
41-
properties.put(discoveryConfigProperty.getSourceName(), discoveryConfigProperty);
41+
properties.put(discoveryConfigProperty.getSourceElementName(), discoveryConfigProperty);
4242
}
4343

4444
public Map<String, DiscoveryConfigProperty> getProperties() {

core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/AbstractConfigItem.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,36 @@
77
public sealed abstract class AbstractConfigItem implements Comparable<AbstractConfigItem>
88
permits ConfigProperty, ConfigSection {
99

10-
protected final String sourceClass;
11-
protected final String sourceName;
12-
protected final SourceType sourceType;
10+
protected final String sourceType;
11+
protected final String sourceElementName;
12+
protected final SourceElementType sourceElementType;
1313
protected final Path path;
1414

1515
protected final String type;
1616

1717
protected Deprecation deprecation;
1818

19-
public AbstractConfigItem(String sourceClass, String sourceName, SourceType sourceType, Path path, String type,
19+
public AbstractConfigItem(String sourceType, String sourceElementName, SourceElementType sourceElementType, Path path,
20+
String type,
2021
Deprecation deprecation) {
21-
this.sourceClass = sourceClass;
22-
this.sourceName = sourceName;
2322
this.sourceType = sourceType;
23+
this.sourceElementName = sourceElementName;
24+
this.sourceElementType = sourceElementType;
2425
this.path = path;
2526
this.type = type;
2627
this.deprecation = deprecation;
2728
}
2829

29-
public String getSourceClass() {
30-
return sourceClass;
30+
public String getSourceType() {
31+
return sourceType;
3132
}
3233

33-
public String getSourceName() {
34-
return sourceName;
34+
public String getSourceElementName() {
35+
return sourceElementName;
3536
}
3637

37-
public SourceType getSourceType() {
38-
return sourceType;
38+
public SourceElementType getSourceElementType() {
39+
return sourceElementType;
3940
}
4041

4142
public Path getPath() {

core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/ConfigProperty.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ public final class ConfigProperty extends AbstractConfigItem {
2929

3030
private final String javadocSiteLink;
3131

32-
public ConfigProperty(ConfigPhase phase, String sourceClass, String sourceName, SourceType sourceType, PropertyPath path,
33-
List<PropertyPath> additionalPaths, String type, String typeDescription, boolean map, boolean list,
34-
boolean optional,
32+
public ConfigProperty(ConfigPhase phase, String sourceType, String sourceElementName, SourceElementType sourceElementType,
33+
PropertyPath path, List<PropertyPath> additionalPaths, String type, String typeDescription, boolean map,
34+
boolean list, boolean optional,
3535
String mapKey, boolean unnamedMapKey, boolean withinMap, boolean converted, @JsonProperty("enum") boolean isEnum,
3636
EnumAcceptedValues enumAcceptedValues,
3737
String defaultValue, String javadocSiteLink,
3838
Deprecation deprecation) {
39-
super(sourceClass, sourceName, sourceType, path, type, deprecation);
39+
super(sourceType, sourceElementName, sourceElementType, path, type, deprecation);
4040
this.phase = phase;
4141
this.additionalPaths = additionalPaths != null ? Collections.unmodifiableList(additionalPaths) : List.of();
4242
this.typeDescription = typeDescription;

core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/ConfigSection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public final class ConfigSection extends AbstractConfigItem implements ConfigIte
1111
private final List<AbstractConfigItem> items = new ArrayList<>();
1212
private final int level;
1313

14-
public ConfigSection(String sourceClass, String sourceName, SourceType sourceType, SectionPath path, String type, int level,
15-
boolean generated, Deprecation deprecation) {
16-
super(sourceClass, sourceName, sourceType, path, type, deprecation);
14+
public ConfigSection(String sourceType, String sourceElementName, SourceElementType sourceElementType, SectionPath path,
15+
String type, int level, boolean generated, Deprecation deprecation) {
16+
super(sourceType, sourceElementName, sourceElementType, path, type, deprecation);
1717
this.generated = generated;
1818
this.level = level;
1919
}

core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/SourceType.java renamed to core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/SourceElementType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.quarkus.annotation.processor.documentation.config.model;
22

3-
public enum SourceType {
3+
public enum SourceElementType {
44

55
METHOD,
66
FIELD;

core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/resolver/ConfigResolver.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ private void resolveProperty(ConfigRoot configRoot, Map<String, ConfigSection> e
134134
if (configSection != null) {
135135
configSection.appendState(discoveryConfigProperty.isSectionGenerated(), deprecation);
136136
} else {
137-
configSection = new ConfigSection(discoveryConfigProperty.getSourceClass(),
138-
discoveryConfigProperty.getSourceName(), discoveryConfigProperty.getSourceType(),
137+
configSection = new ConfigSection(discoveryConfigProperty.getSourceType(),
138+
discoveryConfigProperty.getSourceElementName(), discoveryConfigProperty.getSourceElementType(),
139139
new SectionPath(path), typeQualifiedName,
140140
context.getSectionLevel(), discoveryConfigProperty.isSectionGenerated(), deprecation);
141141
context.getItemCollection().addItem(configSection);
@@ -202,9 +202,9 @@ private void resolveProperty(ConfigRoot configRoot, Map<String, ConfigSection> e
202202

203203
// this is a standard property
204204
ConfigProperty configProperty = new ConfigProperty(phase,
205-
discoveryConfigProperty.getSourceClass(),
206-
discoveryConfigProperty.getSourceName(),
207205
discoveryConfigProperty.getSourceType(),
206+
discoveryConfigProperty.getSourceElementName(),
207+
discoveryConfigProperty.getSourceElementType(),
208208
propertyPath, additionalPropertyPaths,
209209
typeQualifiedName, typeSimplifiedName,
210210
discoveryConfigProperty.getType().isMap(), discoveryConfigProperty.getType().isList(),

core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/scanner/AbstractConfigListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void onResolvedEnum(TypeElement enumTypeElement) {
6767
}
6868

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

7272
AnnotationMirror deprecatedAnnotation = propertyAnnotations.get(Deprecated.class.getName());
7373
if (deprecatedAnnotation != null) {

core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/scanner/ConfigMappingListener.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import io.quarkus.annotation.processor.documentation.config.discovery.DiscoveryRootElement;
1616
import io.quarkus.annotation.processor.documentation.config.discovery.ResolvedType;
1717
import io.quarkus.annotation.processor.documentation.config.model.ConfigPhase;
18-
import io.quarkus.annotation.processor.documentation.config.model.SourceType;
18+
import io.quarkus.annotation.processor.documentation.config.model.SourceElementType;
1919
import io.quarkus.annotation.processor.documentation.config.util.ConfigNamingUtil;
2020
import io.quarkus.annotation.processor.documentation.config.util.Markers;
2121
import io.quarkus.annotation.processor.documentation.config.util.Types;
@@ -125,11 +125,11 @@ public void onEnclosedMethod(DiscoveryRootElement discoveryRootElement, TypeElem
125125

126126
Map<String, AnnotationMirror> methodAnnotations = utils.element().getAnnotations(method);
127127

128-
String sourceName = method.getSimpleName().toString();
128+
String sourceElementName = method.getSimpleName().toString();
129129
DiscoveryConfigProperty.Builder builder = DiscoveryConfigProperty.builder(clazz.getQualifiedName().toString(),
130-
sourceName, SourceType.METHOD, resolvedType);
130+
sourceElementName, SourceElementType.METHOD, resolvedType);
131131

132-
String name = ConfigNamingUtil.hyphenate(sourceName);
132+
String name = ConfigNamingUtil.hyphenate(sourceElementName);
133133
AnnotationMirror withNameAnnotation = methodAnnotations.get(Types.ANNOTATION_CONFIG_WITH_NAME);
134134
if (withNameAnnotation != null) {
135135
name = withNameAnnotation.getElementValues().values().iterator().next().getValue().toString();
@@ -152,7 +152,7 @@ public void onEnclosedMethod(DiscoveryRootElement discoveryRootElement, TypeElem
152152
}
153153

154154
if (resolvedType.isMap()) {
155-
String mapKey = ConfigNamingUtil.hyphenate(sourceName);
155+
String mapKey = ConfigNamingUtil.hyphenate(sourceElementName);
156156
AnnotationMirror configDocMapKeyAnnotation = methodAnnotations.get(Types.ANNOTATION_CONFIG_DOC_MAP_KEY);
157157
if (configDocMapKeyAnnotation != null) {
158158
mapKey = configDocMapKeyAnnotation.getElementValues().values().iterator().next().getValue().toString();
@@ -169,7 +169,7 @@ public void onEnclosedMethod(DiscoveryRootElement discoveryRootElement, TypeElem
169169
builder.converted();
170170
}
171171

172-
handleCommonPropertyAnnotations(builder, methodAnnotations, resolvedType, sourceName);
172+
handleCommonPropertyAnnotations(builder, methodAnnotations, resolvedType, sourceElementName);
173173

174174
discoveryRootElement.addProperty(builder.build());
175175
}

core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/scanner/LegacyConfigRootListener.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import io.quarkus.annotation.processor.documentation.config.discovery.DiscoveryRootElement;
1717
import io.quarkus.annotation.processor.documentation.config.discovery.ResolvedType;
1818
import io.quarkus.annotation.processor.documentation.config.model.ConfigPhase;
19-
import io.quarkus.annotation.processor.documentation.config.model.SourceType;
19+
import io.quarkus.annotation.processor.documentation.config.model.SourceElementType;
2020
import io.quarkus.annotation.processor.documentation.config.util.ConfigNamingUtil;
2121
import io.quarkus.annotation.processor.documentation.config.util.Markers;
2222
import io.quarkus.annotation.processor.documentation.config.util.Types;
@@ -123,11 +123,11 @@ public void onEnclosedField(DiscoveryRootElement discoveryRootElement, TypeEleme
123123

124124
Map<String, AnnotationMirror> fieldAnnotations = utils.element().getAnnotations(field);
125125

126-
String sourceName = field.getSimpleName().toString();
127-
String name = ConfigNamingUtil.hyphenate(sourceName);
126+
String sourceElementName = field.getSimpleName().toString();
127+
String name = ConfigNamingUtil.hyphenate(sourceElementName);
128128

129129
DiscoveryConfigProperty.Builder builder = DiscoveryConfigProperty.builder(clazz.getQualifiedName().toString(),
130-
sourceName, SourceType.FIELD, resolvedType);
130+
sourceElementName, SourceElementType.FIELD, resolvedType);
131131

132132
AnnotationMirror configItemAnnotation = fieldAnnotations.get(Types.ANNOTATION_CONFIG_ITEM);
133133
if (configItemAnnotation != null) {
@@ -158,7 +158,7 @@ public void onEnclosedField(DiscoveryRootElement discoveryRootElement, TypeEleme
158158
builder.name(name);
159159

160160
if (resolvedType.isMap()) {
161-
String mapKey = ConfigNamingUtil.hyphenate(sourceName);
161+
String mapKey = ConfigNamingUtil.hyphenate(sourceElementName);
162162
AnnotationMirror configDocMapKeyAnnotation = fieldAnnotations.get(Types.ANNOTATION_CONFIG_DOC_MAP_KEY);
163163
if (configDocMapKeyAnnotation != null) {
164164
mapKey = configDocMapKeyAnnotation.getElementValues().values().iterator().next().getValue().toString();
@@ -171,7 +171,7 @@ public void onEnclosedField(DiscoveryRootElement discoveryRootElement, TypeEleme
171171
builder.converted();
172172
}
173173

174-
handleCommonPropertyAnnotations(builder, fieldAnnotations, resolvedType, sourceName);
174+
handleCommonPropertyAnnotations(builder, fieldAnnotations, resolvedType, sourceElementName);
175175

176176
discoveryRootElement.addProperty(builder.build());
177177
}

0 commit comments

Comments
 (0)