Skip to content

Commit f52e1a9

Browse files
committed
GH-965 - Asciidoctor.toInlineCode(String) now renders local method references correctly.
Previously, the missing type caused the module lookup to fail with an exception.
1 parent 9dba3db commit f52e1a9

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

spring-modulith-docs/src/main/java/org/springframework/modulith/docs/Asciidoctor.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,14 @@ public String toInlineCode(String source) {
105105
var type = parts[0];
106106
var methodSignature = parts.length == 2 ? Optional.of(parts[1]) : Optional.<String> empty();
107107

108+
if (type.isBlank()) {
109+
return methodSignature.map(Asciidoctor::toCode).orElse(source);
110+
}
111+
108112
return modules.getModuleByType(type)
109113
.flatMap(it -> it.getType(type))
110114
.map(it -> toOptionalLink(it, methodSignature))
111-
.orElseGet(() -> String.format("`%s`", type));
115+
.orElseGet(() -> toCode(type));
112116
}
113117

114118
public String toInlineCode(JavaClass type) {
@@ -270,7 +274,7 @@ private String toBulletPoints(Stream<String> types) {
270274
}
271275

272276
public String toBulletPoint(String source) {
273-
return String.format("* %s", source);
277+
return "* ".concat(source);
274278
}
275279

276280
private String toOptionalLink(JavaClass source) {
@@ -355,7 +359,7 @@ private static String toLink(String source, String href) {
355359
}
356360

357361
private static String toCode(String source) {
358-
return String.format("`%s`", source);
362+
return wrap(source, "`");
359363
}
360364

361365
public static String startTable(String tableSpec) {
@@ -441,4 +445,8 @@ private static Optional<DocumentationSource> getSpringModulithDocsSource() {
441445
return it;
442446
});
443447
}
448+
449+
private static final String wrap(String source, String chars) {
450+
return chars + source + chars;
451+
}
444452
}

spring-modulith-docs/src/test/java/org/springframework/modulith/docs/AsciidoctorUnitTests.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
*/
3030
class AsciidoctorUnitTests {
3131

32-
Asciidoctor asciidoctor = Asciidoctor.withJavadocBase(ApplicationModules.of("org.springframework.modulith"), "{javadoc}");
32+
Asciidoctor asciidoctor = Asciidoctor.withJavadocBase(ApplicationModules.of("org.springframework.modulith"),
33+
"{javadoc}");
3334

3435
@Test
3536
void formatsInlineCode() {
@@ -64,8 +65,14 @@ void cleansUpJavadocForConfigurationProperties() {
6465

6566
ConfigurationProperties metadata = new ConfigurationProperties();
6667

67-
assertThat(metadata).containsExactly(new ConfigurationProperties.ConfigurationProperty("org.springframework.modulith.sample.test",
68-
"Some test property of type {@link java.lang.Boolean}.", "java.lang.Boolean",
69-
"com.acme.myproject.stereotypes.Stereotypes$SomeConfigurationProperties", "false"));
68+
assertThat(metadata)
69+
.containsExactly(new ConfigurationProperties.ConfigurationProperty("org.springframework.modulith.sample.test",
70+
"Some test property of type {@link java.lang.Boolean}.", "java.lang.Boolean",
71+
"com.acme.myproject.stereotypes.Stereotypes$SomeConfigurationProperties", "false"));
72+
}
73+
74+
@Test // GH-965
75+
void rendersLocalMethodReferencesCorrectly() {
76+
assertThat(asciidoctor.toInlineCode("#someMethod()")).isEqualTo("`someMethod()`");
7077
}
7178
}

0 commit comments

Comments
 (0)