Skip to content

Commit

Permalink
strip Runtime suffix when dereving config root name in doc generation
Browse files Browse the repository at this point in the history
handle optional config group in doc generation

Fixes quarkusio#5703

Follows up quarkusio#5387
  • Loading branch information
machi1990 committed Nov 24, 2019
1 parent 3deedec commit 3568e65
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,15 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String p
} else {
final ConfigDocKey configDocKey = new ConfigDocKey();
configDocKey.setWithinAMap(withinAMap);
boolean optional = false;
boolean list = false;
boolean optional = false;
if (!typeMirror.getKind().isPrimitive()) {
DeclaredType declaredType = (DeclaredType) typeMirror;
TypeElement typeElement = (TypeElement) declaredType.asElement();
Name qualifiedName = typeElement.getQualifiedName();
optional = qualifiedName.toString().startsWith(Optional.class.getName());
list = qualifiedName.contentEquals(List.class.getName());
list = qualifiedName.contentEquals(List.class.getName())
|| qualifiedName.contentEquals(Set.class.getName());

List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
if (!typeArguments.isEmpty()) {
Expand All @@ -186,8 +187,7 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String p
if (configGroup != null) {
name += String.format(NAMED_MAP_CONFIG_ITEM_FORMAT, configDocMapKey);
List<ConfigDocItem> groupConfigItems = recordConfigItemsFromConfigGroup(configPhase, name,
configGroup,
configSection, true, sectionLevel);
configGroup, configSection, true, sectionLevel);
configDocItems.addAll(groupConfigItems);
continue;
} else {
Expand All @@ -198,13 +198,35 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String p
} else {
// FIXME: this is for Optional<T> and List<T>
TypeMirror realTypeMirror = typeArguments.get(0);
if (optional && (realTypeMirror.toString().startsWith(List.class.getName())
|| realTypeMirror.getKind() == TypeKind.ARRAY)) {
list = true;
DeclaredType declaredRealType = (DeclaredType) typeMirror;
typeArguments = declaredRealType.getTypeArguments();
if (!typeArguments.isEmpty()) {
realTypeMirror = typeArguments.get(0);
String typeInString = realTypeMirror.toString();

if (optional) {
configGroup = configGroups.get(typeInString);
if (configGroup != null) {
if (configSection == null) {
final JavaDocParser.SectionHolder sectionHolder = javaDocParser.parseConfigSection(
rawJavaDoc,
sectionLevel);
configSection = new ConfigDocSection();
configSection.setWithinAMap(withinAMap);
configSection.setConfigPhase(configPhase);
configSection.setSectionDetails(sectionHolder.details);
configSection.setSectionDetailsTitle(sectionHolder.title);
configSection.setName(parentName + Constants.DOT + hyphenatedFieldName);
}
configSection.setOptional(true);
List<ConfigDocItem> groupConfigItems = recordConfigItemsFromConfigGroup(configPhase, name,
configGroup, configSection, withinAMap, sectionLevel);
configDocItems.addAll(groupConfigItems);
} else if ((typeInString.startsWith(List.class.getName())
|| typeInString.startsWith(Set.class.getName())
|| realTypeMirror.getKind() == TypeKind.ARRAY)) {
list = true;
DeclaredType declaredRealType = (DeclaredType) typeMirror;
typeArguments = declaredRealType.getTypeArguments();
if (!typeArguments.isEmpty()) {
realTypeMirror = typeArguments.get(0);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

final public class ConfigDocSection implements ConfigDocElement, Comparable<ConfigDocElement> {
private String name;
private boolean optional;
private boolean withinAMap;
private String sectionDetails;
private String sectionDetailsTitle;
Expand Down Expand Up @@ -100,12 +101,13 @@ public int hashCode() {
public String toString() {
return "ConfigDocSection{" +
"name='" + name + '\'' +
", optional='" + optional + '\'' +
", withinAMap=" + withinAMap +
", sectionDetails='" + sectionDetails + '\'' +
", sectionDetailsTitle='" + sectionDetailsTitle + '\'' +
", configPhase=" + configPhase +
", configDocItems=" + configDocItems +
", anchorPrefix=" + anchorPrefix +
", anchorPrefix='" + anchorPrefix + '\'' +
'}';
}

Expand All @@ -132,4 +134,12 @@ public void setAnchorPrefix(String anchorPrefix) {
public String getAnchorPrefix() {
return anchorPrefix;
}

public boolean isOptional() {
return optional;
}

public void setOptional(boolean optional) {
this.optional = optional;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -458,18 +458,20 @@ private static String typeSimpleName(TypeMirror typeMirror) {
}

static String deriveConfigRootName(String simpleClassName, ConfigPhase configPhase) {
int length = simpleClassName.length();
String simpleNameInLowerCase = simpleClassName.toLowerCase();
int length = simpleNameInLowerCase.length();

if (simpleClassName.endsWith(CONFIG)) {
if (simpleNameInLowerCase.endsWith(CONFIG.toLowerCase())) {
String sanitized = simpleClassName.substring(0, length - CONFIG.length());
return deriveConfigRootName(sanitized, configPhase);
} else if (simpleClassName.endsWith(CONFIGURATION)) {
} else if (simpleNameInLowerCase.endsWith(CONFIGURATION.toLowerCase())) {
String sanitized = simpleClassName.substring(0, length - CONFIGURATION.length());
return deriveConfigRootName(sanitized, configPhase);
} else if (simpleClassName.endsWith(configPhase.getConfigSuffix())) {
} else if (simpleNameInLowerCase.endsWith(configPhase.getConfigSuffix().toLowerCase())) {
String sanitized = simpleClassName.substring(0, length - configPhase.getConfigSuffix().length());
return deriveConfigRootName(sanitized, configPhase);
}

return Constants.QUARKUS + Constants.DOT + hyphenate(simpleClassName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ final class SummaryTableDocFormatter implements DocFormatter {
public static final String SEARCHABLE_TABLE_CLASS = ".searchable"; // a css class indicating if a table is searchable
public static final String CONFIGURATION_TABLE_CLASS = ".configuration-reference";
private static final String TABLE_ROW_FORMAT = "\n\na|%s [[%s]]`link:#%s[%s]`\n\n[.description]\n--\n%s\n--|%s %s\n|%s\n";
private static final String TABLE_SECTION_ROW_FORMAT = "\n\nh|[[%s]]link:#%s[%s]\nh|Type\nh|Default";
private static final String SECTION_TITLE = "[[%s]]link:#%s[%s]";
private static final String TABLE_SECTION_ROW_FORMAT = "\n\nh|%s\n%s\nh|Type\nh|Default";
private static final String TABLE_HEADER_FORMAT = "[.configuration-legend]%s\n[%s, cols=\"80,.^10,.^10\"]\n|===";

private String anchorPrefix = "";
Expand Down Expand Up @@ -88,8 +89,10 @@ public void format(Writer writer, ConfigDocKey configDocKey) throws IOException
@Override
public void format(Writer writer, ConfigDocSection configDocSection) throws IOException {
String anchor = anchorPrefix + getAnchor(configDocSection.getName());
final String sectionRow = String.format(TABLE_SECTION_ROW_FORMAT, anchor, anchor,
configDocSection.getSectionDetailsTitle());
String sectionTitle = String.format(SECTION_TITLE, anchor, anchor, configDocSection.getSectionDetailsTitle());
final String sectionRow = String.format(TABLE_SECTION_ROW_FORMAT, sectionTitle,
configDocSection.isOptional() ? "This configuration section is optional" : Constants.EMPTY);

writer.append(sectionRow);

for (ConfigDocItem configDocItem : configDocSection.getConfigDocItems()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ public void derivingConfigRootNameTestCase() {
actual = deriveConfigRootName(simpleClassName, ConfigPhase.RUN_TIME);
assertEquals("quarkus.root-name", actual);

simpleClassName = "RootNameRuntimeConfig";
actual = deriveConfigRootName(simpleClassName, ConfigPhase.RUN_TIME);
assertEquals("quarkus.root-name", actual);

simpleClassName = "RootNameRunTimeConfiguration";
actual = deriveConfigRootName(simpleClassName, ConfigPhase.RUN_TIME);
assertEquals("quarkus.root-name", actual);
Expand Down

0 comments on commit 3568e65

Please sign in to comment.