Skip to content

Commit

Permalink
GH-967 - Polishing.
Browse files Browse the repository at this point in the history
  • Loading branch information
odrotbohm committed Nov 25, 2024
1 parent d7efd19 commit cadcb31
Showing 1 changed file with 30 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
package org.springframework.modulith.docs;

import static java.util.stream.Collectors.*;
import static org.springframework.util.ClassUtils.*;

import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

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

var interfacesAsString = interfaces.stream() //
.map(this::toInlineCode) //
.collect(Collectors.joining(", "));
.collect(joining(", "));

return "%s (via %s)".formatted(interfacesAsString, base);
}
Expand Down Expand Up @@ -159,7 +159,8 @@ public String renderSpringBeans(ApplicationModule module, CanvasOptions options)
}

if (builder.length() != 0) {
builder.append("\n\n");
builder.append(System.lineSeparator());
builder.append(System.lineSeparator());
}

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

builder.append("\n\n");
builder.append(System.lineSeparator());
builder.append(System.lineSeparator());
builder.append(toBulletPoints(beans));

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

if (!eventType.hasSources()) {
builder.append("\n");
builder.append(System.lineSeparator());
} else {
builder.append((documentation.isPresent() ? " C" : " c") + "reated by:\n");
builder.append((documentation.isPresent() ? " C" : " c") + "reated by:");
builder.append(System.lineSeparator());
}

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

builder.append("** ")
.append(toInlineCode(source.toString(module)))
.append("\n");
.append(System.lineSeparator());
}
}

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

public String renderConfigurationProperties(List<ModuleProperty> properties) {
Expand Down Expand Up @@ -268,9 +271,7 @@ public String typesToBulletPoints(List<JavaClass> types) {
}

private String toBulletPoints(Stream<String> types) {

return types//
.collect(Collectors.joining("\n* ", "* ", ""));
return types.collect(joining(System.lineSeparator() + "* ", "* ", ""));
}

public String toBulletPoint(String source) {
Expand Down Expand Up @@ -319,15 +320,16 @@ private String toInlineCode(ArchitecturallyEvidentType type) {

var referenceTypes = type.getReferenceTypes();

return String.format("%s listening to %s", //
return "%s listening to %s".formatted( //
toInlineCode(javaType), //
toInlineCode(referenceTypes));
}

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

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

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

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

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

return docSource.flatMap(source -> source.getDocumentation(method))
.map(doc -> String.format("%s %s %s-- %s", indent, toInlineCode(parameterType), isAsync, doc))
.orElseGet(() -> String.format("%s %s %s", indent, toInlineCode(parameterType), isAsync));
.map(doc -> "%s %s %s-- %s".formatted(indent, toInlineCode(parameterType), isAsync, doc))
.orElseGet(() -> "%s %s %s".formatted(indent, toInlineCode(parameterType), isAsync));
}

private String toInlineCode(Stream<JavaClass> types) {

return types.map(this::toInlineCode) //
.collect(Collectors.joining(", "));
return types.map(this::toInlineCode).collect(joining(", "));
}

private static String toLink(String source, String href) {
return String.format("link:%s[%s]", href, source);
return "link:%s[%s]".formatted(href, source);
}

private static String toCode(String source) {
return wrap(source, "`");
}

public static String startTable(String tableSpec) {
return String.format("[%s]\n|===\n", tableSpec);

return new StringBuilder()
.append("[").append(tableSpec).append("]")
.append(System.lineSeparator()).append("|===").append(System.lineSeparator())
.toString();
}

public static String startOrEndTable() {
return "|===\n";
return "|===" + System.lineSeparator();
}

public static String writeTableRow(String... columns) {

return Stream.of(columns) //
.collect(Collectors.joining("\n|", "|", "\n"));
return Stream.of(columns).collect(joining(System.lineSeparator() + "|", "|", System.lineSeparator()));
}

public String toAsciidoctor(String source) {
Expand Down Expand Up @@ -406,7 +408,7 @@ public String renderBeanReferences(ApplicationModule module) {
return withDocumentation(result, targetType);
})
.map(this::toBulletPoint)
.collect(Collectors.joining("\n"));
.collect(joining(System.lineSeparator()));

return bullets.isBlank() ? "None" : bullets;
}
Expand Down

0 comments on commit cadcb31

Please sign in to comment.