GH-967 - Asciidoctor.toInlineCode(String) now renders local method references correctly.

Previously, the missing type caused the module lookup to fail with an exception.
This commit is contained in:
Oliver Drotbohm
2024-11-25 12:11:23 +01:00
parent 3a0389a94f
commit d7efd19c25
2 changed files with 22 additions and 7 deletions

View File

@@ -105,10 +105,14 @@ class Asciidoctor {
var type = parts[0];
var methodSignature = parts.length == 2 ? Optional.of(parts[1]) : Optional.<String> empty();
if (type.isBlank()) {
return methodSignature.map(Asciidoctor::toCode).orElse(source);
}
return modules.getModuleByType(type)
.flatMap(it -> it.getType(type))
.map(it -> toOptionalLink(it, methodSignature))
.orElseGet(() -> String.format("`%s`", type));
.orElseGet(() -> toCode(type));
}
public String toInlineCode(JavaClass type) {
@@ -270,7 +274,7 @@ class Asciidoctor {
}
public String toBulletPoint(String source) {
return String.format("* %s", source);
return "* ".concat(source);
}
private String toOptionalLink(JavaClass source) {
@@ -355,7 +359,7 @@ class Asciidoctor {
}
private static String toCode(String source) {
return String.format("`%s`", source);
return wrap(source, "`");
}
public static String startTable(String tableSpec) {
@@ -441,4 +445,8 @@ class Asciidoctor {
return it;
});
}
private static final String wrap(String source, String chars) {
return chars + source + chars;
}
}

View File

@@ -29,7 +29,8 @@ import com.tngtech.archunit.core.importer.ClassFileImporter;
*/
class AsciidoctorUnitTests {
Asciidoctor asciidoctor = Asciidoctor.withJavadocBase(ApplicationModules.of("org.springframework.modulith"), "{javadoc}");
Asciidoctor asciidoctor = Asciidoctor.withJavadocBase(ApplicationModules.of("org.springframework.modulith"),
"{javadoc}");
@Test
void formatsInlineCode() {
@@ -64,8 +65,14 @@ class AsciidoctorUnitTests {
ConfigurationProperties metadata = new ConfigurationProperties();
assertThat(metadata).containsExactly(new ConfigurationProperties.ConfigurationProperty("org.springframework.modulith.sample.test",
"Some test property of type {@link java.lang.Boolean}.", "java.lang.Boolean",
"com.acme.myproject.stereotypes.Stereotypes$SomeConfigurationProperties", "false"));
assertThat(metadata)
.containsExactly(new ConfigurationProperties.ConfigurationProperty("org.springframework.modulith.sample.test",
"Some test property of type {@link java.lang.Boolean}.", "java.lang.Boolean",
"com.acme.myproject.stereotypes.Stereotypes$SomeConfigurationProperties", "false"));
}
@Test // GH-965
void rendersLocalMethodReferencesCorrectly() {
assertThat(asciidoctor.toInlineCode("#someMethod()")).isEqualTo("`someMethod()`");
}
}