Skip to content

Commit 8d52d4e

Browse files
committed
strip Runtime suffix when dereving config root name in doc generation
handle optional config group in doc generation Fixes quarkusio#5703 Follows up quarkusio#5387
1 parent 5f82db6 commit 8d52d4e

File tree

3 files changed

+37
-20
lines changed

3 files changed

+37
-20
lines changed

core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDoItemFinder.java

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ ScannedConfigDocsItemHolder findInMemoryConfigurationItems() {
5656
*/
5757
final int sectionLevel = 2;
5858
final List<ConfigDocItem> configDocItems = recursivelyFindConfigItems(element, configRootInfo.getName(),
59-
configRootInfo.getConfigPhase(), false, sectionLevel);
59+
configRootInfo.getConfigPhase(), false, sectionLevel, false);
6060
holder.addConfigRootItems(configRootInfo.getClazz().getQualifiedName().toString(), configDocItems);
6161
}
6262

@@ -71,9 +71,10 @@ ScannedConfigDocsItemHolder findInMemoryConfigurationItems() {
7171
* @param configPhase - configuration phase see {@link ConfigPhase}
7272
* @param withinAMap - indicates if a a key is within a map or is a map configuration key
7373
* @param sectionLevel - section sectionLevel
74+
* @param optional - whether a group of config items is optional or not
7475
*/
7576
private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String parentName,
76-
ConfigPhase configPhase, boolean withinAMap, int sectionLevel) {
77+
ConfigPhase configPhase, boolean withinAMap, int sectionLevel, boolean optional) {
7778
List<ConfigDocItem> configDocItems = new ArrayList<>();
7879
for (Element enclosedElement : element.getEnclosedElements()) {
7980
if (!enclosedElement.getKind().isField()) {
@@ -162,19 +163,19 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String p
162163

163164
if (isConfigGroup) {
164165
List<ConfigDocItem> groupConfigItems = recordConfigItemsFromConfigGroup(configPhase, name, configGroup,
165-
configSection, withinAMap, sectionLevel);
166+
configSection, withinAMap, sectionLevel, optional);
166167
configDocItems.addAll(groupConfigItems);
167168
} else {
168169
final ConfigDocKey configDocKey = new ConfigDocKey();
169170
configDocKey.setWithinAMap(withinAMap);
170-
boolean optional = false;
171171
boolean list = false;
172172
if (!typeMirror.getKind().isPrimitive()) {
173173
DeclaredType declaredType = (DeclaredType) typeMirror;
174174
TypeElement typeElement = (TypeElement) declaredType.asElement();
175175
Name qualifiedName = typeElement.getQualifiedName();
176-
optional = qualifiedName.toString().startsWith(Optional.class.getName());
177-
list = qualifiedName.contentEquals(List.class.getName());
176+
optional |= qualifiedName.toString().startsWith(Optional.class.getName());
177+
list = qualifiedName.contentEquals(List.class.getName())
178+
|| qualifiedName.contentEquals(Set.class.getName());
178179

179180
List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
180181
if (!typeArguments.isEmpty()) {
@@ -187,7 +188,7 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String p
187188
name += String.format(NAMED_MAP_CONFIG_ITEM_FORMAT, configDocMapKey);
188189
List<ConfigDocItem> groupConfigItems = recordConfigItemsFromConfigGroup(configPhase, name,
189190
configGroup,
190-
configSection, true, sectionLevel);
191+
configSection, true, sectionLevel, optional);
191192
configDocItems.addAll(groupConfigItems);
192193
continue;
193194
} else {
@@ -198,13 +199,23 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String p
198199
} else {
199200
// FIXME: this is for Optional<T> and List<T>
200201
TypeMirror realTypeMirror = typeArguments.get(0);
201-
if (optional && (realTypeMirror.toString().startsWith(List.class.getName())
202-
|| realTypeMirror.getKind() == TypeKind.ARRAY)) {
203-
list = true;
204-
DeclaredType declaredRealType = (DeclaredType) typeMirror;
205-
typeArguments = declaredRealType.getTypeArguments();
206-
if (!typeArguments.isEmpty()) {
207-
realTypeMirror = typeArguments.get(0);
202+
String typeInString = realTypeMirror.toString();
203+
204+
if (optional) {
205+
configGroup = configGroups.get(typeInString);
206+
if (configGroup != null) {
207+
List<ConfigDocItem> groupConfigItems = recordConfigItemsFromConfigGroup(configPhase, name,
208+
configGroup, configSection, withinAMap, sectionLevel, true);
209+
configDocItems.addAll(groupConfigItems);
210+
} else if ((typeInString.startsWith(List.class.getName())
211+
|| typeInString.startsWith(Set.class.getName())
212+
|| realTypeMirror.getKind() == TypeKind.ARRAY)) {
213+
list = true;
214+
DeclaredType declaredRealType = (DeclaredType) typeMirror;
215+
typeArguments = declaredRealType.getTypeArguments();
216+
if (!typeArguments.isEmpty()) {
217+
realTypeMirror = typeArguments.get(0);
218+
}
208219
}
209220
}
210221

@@ -244,10 +255,10 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String p
244255
}
245256

246257
private List<ConfigDocItem> recordConfigItemsFromConfigGroup(ConfigPhase configPhase, String name, Element configGroup,
247-
ConfigDocSection configSection, boolean withinAMap, int sectionLevel) {
258+
ConfigDocSection configSection, boolean withinAMap, int sectionLevel, boolean optional) {
248259
final List<ConfigDocItem> configDocItems = new ArrayList<>();
249260
final List<ConfigDocItem> groupConfigItems = recursivelyFindConfigItems(configGroup, name, configPhase, withinAMap,
250-
sectionLevel + 1);
261+
sectionLevel + 1, optional);
251262
if (configSection == null) {
252263
configDocItems.addAll(groupConfigItems);
253264
} else {

core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/DocGeneratorUtil.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,18 +458,20 @@ private static String typeSimpleName(TypeMirror typeMirror) {
458458
}
459459

460460
static String deriveConfigRootName(String simpleClassName, ConfigPhase configPhase) {
461-
int length = simpleClassName.length();
461+
String simpleNameInLowerCase = simpleClassName.toLowerCase();
462+
int length = simpleNameInLowerCase.length();
462463

463-
if (simpleClassName.endsWith(CONFIG)) {
464+
if (simpleNameInLowerCase.endsWith(CONFIG.toLowerCase())) {
464465
String sanitized = simpleClassName.substring(0, length - CONFIG.length());
465466
return deriveConfigRootName(sanitized, configPhase);
466-
} else if (simpleClassName.endsWith(CONFIGURATION)) {
467+
} else if (simpleNameInLowerCase.endsWith(CONFIGURATION.toLowerCase())) {
467468
String sanitized = simpleClassName.substring(0, length - CONFIGURATION.length());
468469
return deriveConfigRootName(sanitized, configPhase);
469-
} else if (simpleClassName.endsWith(configPhase.getConfigSuffix())) {
470+
} else if (simpleNameInLowerCase.endsWith(configPhase.getConfigSuffix().toLowerCase())) {
470471
String sanitized = simpleClassName.substring(0, length - configPhase.getConfigSuffix().length());
471472
return deriveConfigRootName(sanitized, configPhase);
472473
}
474+
473475
return Constants.QUARKUS + Constants.DOT + hyphenate(simpleClassName);
474476
}
475477

core/processor/src/test/java/io/quarkus/annotation/processor/generate_doc/DocGeneratorUtilTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ public void derivingConfigRootNameTestCase() {
337337
actual = deriveConfigRootName(simpleClassName, ConfigPhase.RUN_TIME);
338338
assertEquals("quarkus.root-name", actual);
339339

340+
simpleClassName = "RootNameRuntimeConfig";
341+
actual = deriveConfigRootName(simpleClassName, ConfigPhase.RUN_TIME);
342+
assertEquals("quarkus.root-name", actual);
343+
340344
simpleClassName = "RootNameRunTimeConfiguration";
341345
actual = deriveConfigRootName(simpleClassName, ConfigPhase.RUN_TIME);
342346
assertEquals("quarkus.root-name", actual);

0 commit comments

Comments
 (0)