Skip to content

Commit cb3f503

Browse files
committed
GH-965 - Polishing.
1 parent f52e1a9 commit cb3f503

File tree

1 file changed

+30
-28
lines changed
  • spring-modulith-docs/src/main/java/org/springframework/modulith/docs

1 file changed

+30
-28
lines changed

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

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
*/
1616
package org.springframework.modulith.docs;
1717

18+
import static java.util.stream.Collectors.*;
1819
import static org.springframework.util.ClassUtils.*;
1920

2021
import java.util.List;
2122
import java.util.Optional;
2223
import java.util.regex.Matcher;
2324
import java.util.regex.Pattern;
24-
import java.util.stream.Collectors;
2525
import java.util.stream.Stream;
2626

2727
import org.slf4j.Logger;
@@ -131,7 +131,7 @@ public String toInlineCode(SpringBean bean) {
131131

132132
var interfacesAsString = interfaces.stream() //
133133
.map(this::toInlineCode) //
134-
.collect(Collectors.joining(", "));
134+
.collect(joining(", "));
135135

136136
return "%s (via %s)".formatted(interfacesAsString, base);
137137
}
@@ -159,7 +159,8 @@ public String renderSpringBeans(ApplicationModule module, CanvasOptions options)
159159
}
160160

161161
if (builder.length() != 0) {
162-
builder.append("\n\n");
162+
builder.append(System.lineSeparator());
163+
builder.append(System.lineSeparator());
163164
}
164165

165166
builder.append("_").append(grouping.getName()).append("_");
@@ -168,7 +169,8 @@ public String renderSpringBeans(ApplicationModule module, CanvasOptions options)
168169
builder.append(" -- ").append(grouping.getDescription());
169170
}
170171

171-
builder.append("\n\n");
172+
builder.append(System.lineSeparator());
173+
builder.append(System.lineSeparator());
172174
builder.append(toBulletPoints(beans));
173175

174176
});
@@ -196,16 +198,17 @@ public String renderPublishedEvents(ApplicationModule module) {
196198
documentation.ifPresent(builder::append);
197199

198200
if (!eventType.hasSources()) {
199-
builder.append("\n");
201+
builder.append(System.lineSeparator());
200202
} else {
201-
builder.append((documentation.isPresent() ? " C" : " c") + "reated by:\n");
203+
builder.append((documentation.isPresent() ? " C" : " c") + "reated by:");
204+
builder.append(System.lineSeparator());
202205
}
203206

204207
for (Source source : eventType.getSources()) {
205208

206209
builder.append("** ")
207210
.append(toInlineCode(source.toString(module)))
208-
.append("\n");
211+
.append(System.lineSeparator());
209212
}
210213
}
211214

@@ -219,7 +222,7 @@ public String renderEventsListenedTo(ApplicationModule module) {
219222
.filter(ArchitecturallyEvidentType::isEventListener)
220223
.flatMap(ArchitecturallyEvidentType::getReferenceMethods)
221224
.map(it -> renderReferenceMethod(it, 0))
222-
.collect(Collectors.joining(System.lineSeparator()));
225+
.collect(joining(System.lineSeparator()));
223226
}
224227

225228
public String renderConfigurationProperties(List<ModuleProperty> properties) {
@@ -268,9 +271,7 @@ public String typesToBulletPoints(List<JavaClass> types) {
268271
}
269272

270273
private String toBulletPoints(Stream<String> types) {
271-
272-
return types//
273-
.collect(Collectors.joining("\n* ", "* ", ""));
274+
return types.collect(joining(System.lineSeparator() + "* ", "* ", ""));
274275
}
275276

276277
public String toBulletPoint(String source) {
@@ -319,15 +320,16 @@ private String toInlineCode(ArchitecturallyEvidentType type) {
319320

320321
var referenceTypes = type.getReferenceTypes();
321322

322-
return String.format("%s listening to %s", //
323+
return "%s listening to %s".formatted( //
323324
toInlineCode(javaType), //
324325
toInlineCode(referenceTypes));
325326
}
326327

327-
String header = "%s listening to:\n".formatted(withDocumentation(code, javaType));
328+
String header = "%s listening to:".formatted(withDocumentation(code, javaType) + System.lineSeparator());
328329

329-
return header + type.getReferenceMethods().map(it -> renderReferenceMethod(it, 1))
330-
.collect(Collectors.joining("\n"));
330+
return header + type.getReferenceMethods()
331+
.map(it -> renderReferenceMethod(it, 1))
332+
.collect(joining(System.lineSeparator()));
331333
}
332334

333335
return withDocumentation(toInlineCode(type.getType()), type.getType());
@@ -337,43 +339,43 @@ private String renderReferenceMethod(ReferenceMethod it, int level) {
337339

338340
var method = it.getMethod();
339341
Assert.isTrue(method.getRawParameterTypes().size() > 0,
340-
() -> String.format("Method %s must have at least one parameter!", method));
342+
() -> "Method %s must have at least one parameter!".formatted(method));
341343

342344
var parameterType = method.getRawParameterTypes().get(0);
343345
var isAsync = it.isAsync() ? "(async) " : "";
344346
var indent = "*".repeat(level + 1);
345347

346348
return docSource.flatMap(source -> source.getDocumentation(method))
347-
.map(doc -> String.format("%s %s %s-- %s", indent, toInlineCode(parameterType), isAsync, doc))
348-
.orElseGet(() -> String.format("%s %s %s", indent, toInlineCode(parameterType), isAsync));
349+
.map(doc -> "%s %s %s-- %s".formatted(indent, toInlineCode(parameterType), isAsync, doc))
350+
.orElseGet(() -> "%s %s %s".formatted(indent, toInlineCode(parameterType), isAsync));
349351
}
350352

351353
private String toInlineCode(Stream<JavaClass> types) {
352-
353-
return types.map(this::toInlineCode) //
354-
.collect(Collectors.joining(", "));
354+
return types.map(this::toInlineCode).collect(joining(", "));
355355
}
356356

357357
private static String toLink(String source, String href) {
358-
return String.format("link:%s[%s]", href, source);
358+
return "link:%s[%s]".formatted(href, source);
359359
}
360360

361361
private static String toCode(String source) {
362362
return wrap(source, "`");
363363
}
364364

365365
public static String startTable(String tableSpec) {
366-
return String.format("[%s]\n|===\n", tableSpec);
366+
367+
return new StringBuilder()
368+
.append("[").append(tableSpec).append("]")
369+
.append(System.lineSeparator()).append("|===").append(System.lineSeparator())
370+
.toString();
367371
}
368372

369373
public static String startOrEndTable() {
370-
return "|===\n";
374+
return "|===" + System.lineSeparator();
371375
}
372376

373377
public static String writeTableRow(String... columns) {
374-
375-
return Stream.of(columns) //
376-
.collect(Collectors.joining("\n|", "|", "\n"));
378+
return Stream.of(columns).collect(joining(System.lineSeparator() + "|", "|", System.lineSeparator()));
377379
}
378380

379381
public String toAsciidoctor(String source) {
@@ -406,7 +408,7 @@ public String renderBeanReferences(ApplicationModule module) {
406408
return withDocumentation(result, targetType);
407409
})
408410
.map(this::toBulletPoint)
409-
.collect(Collectors.joining("\n"));
411+
.collect(joining(System.lineSeparator()));
410412

411413
return bullets.isBlank() ? "None" : bullets;
412414
}

0 commit comments

Comments
 (0)