15
15
*/
16
16
package org .springframework .modulith .docs ;
17
17
18
+ import static java .util .stream .Collectors .*;
18
19
import static org .springframework .util .ClassUtils .*;
19
20
20
21
import java .util .List ;
21
22
import java .util .Optional ;
22
23
import java .util .regex .Matcher ;
23
24
import java .util .regex .Pattern ;
24
- import java .util .stream .Collectors ;
25
25
import java .util .stream .Stream ;
26
26
27
27
import org .slf4j .Logger ;
@@ -131,7 +131,7 @@ public String toInlineCode(SpringBean bean) {
131
131
132
132
var interfacesAsString = interfaces .stream () //
133
133
.map (this ::toInlineCode ) //
134
- .collect (Collectors . joining (", " ));
134
+ .collect (joining (", " ));
135
135
136
136
return "%s (via %s)" .formatted (interfacesAsString , base );
137
137
}
@@ -159,7 +159,8 @@ public String renderSpringBeans(ApplicationModule module, CanvasOptions options)
159
159
}
160
160
161
161
if (builder .length () != 0 ) {
162
- builder .append ("\n \n " );
162
+ builder .append (System .lineSeparator ());
163
+ builder .append (System .lineSeparator ());
163
164
}
164
165
165
166
builder .append ("_" ).append (grouping .getName ()).append ("_" );
@@ -168,7 +169,8 @@ public String renderSpringBeans(ApplicationModule module, CanvasOptions options)
168
169
builder .append (" -- " ).append (grouping .getDescription ());
169
170
}
170
171
171
- builder .append ("\n \n " );
172
+ builder .append (System .lineSeparator ());
173
+ builder .append (System .lineSeparator ());
172
174
builder .append (toBulletPoints (beans ));
173
175
174
176
});
@@ -196,16 +198,17 @@ public String renderPublishedEvents(ApplicationModule module) {
196
198
documentation .ifPresent (builder ::append );
197
199
198
200
if (!eventType .hasSources ()) {
199
- builder .append (" \n " );
201
+ builder .append (System . lineSeparator () );
200
202
} 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 ());
202
205
}
203
206
204
207
for (Source source : eventType .getSources ()) {
205
208
206
209
builder .append ("** " )
207
210
.append (toInlineCode (source .toString (module )))
208
- .append (" \n " );
211
+ .append (System . lineSeparator () );
209
212
}
210
213
}
211
214
@@ -219,7 +222,7 @@ public String renderEventsListenedTo(ApplicationModule module) {
219
222
.filter (ArchitecturallyEvidentType ::isEventListener )
220
223
.flatMap (ArchitecturallyEvidentType ::getReferenceMethods )
221
224
.map (it -> renderReferenceMethod (it , 0 ))
222
- .collect (Collectors . joining (System .lineSeparator ()));
225
+ .collect (joining (System .lineSeparator ()));
223
226
}
224
227
225
228
public String renderConfigurationProperties (List <ModuleProperty > properties ) {
@@ -268,9 +271,7 @@ public String typesToBulletPoints(List<JavaClass> types) {
268
271
}
269
272
270
273
private String toBulletPoints (Stream <String > types ) {
271
-
272
- return types //
273
- .collect (Collectors .joining ("\n * " , "* " , "" ));
274
+ return types .collect (joining (System .lineSeparator () + "* " , "* " , "" ));
274
275
}
275
276
276
277
public String toBulletPoint (String source ) {
@@ -319,15 +320,16 @@ private String toInlineCode(ArchitecturallyEvidentType type) {
319
320
320
321
var referenceTypes = type .getReferenceTypes ();
321
322
322
- return String . format ( "%s listening to %s" , //
323
+ return "%s listening to %s" . formatted ( //
323
324
toInlineCode (javaType ), //
324
325
toInlineCode (referenceTypes ));
325
326
}
326
327
327
- String header = "%s listening to:\n " .formatted (withDocumentation (code , javaType ));
328
+ String header = "%s listening to:" .formatted (withDocumentation (code , javaType ) + System . lineSeparator ( ));
328
329
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 ()));
331
333
}
332
334
333
335
return withDocumentation (toInlineCode (type .getType ()), type .getType ());
@@ -337,43 +339,43 @@ private String renderReferenceMethod(ReferenceMethod it, int level) {
337
339
338
340
var method = it .getMethod ();
339
341
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 ));
341
343
342
344
var parameterType = method .getRawParameterTypes ().get (0 );
343
345
var isAsync = it .isAsync () ? "(async) " : "" ;
344
346
var indent = "*" .repeat (level + 1 );
345
347
346
348
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 ));
349
351
}
350
352
351
353
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 (", " ));
355
355
}
356
356
357
357
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 );
359
359
}
360
360
361
361
private static String toCode (String source ) {
362
362
return wrap (source , "`" );
363
363
}
364
364
365
365
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 ();
367
371
}
368
372
369
373
public static String startOrEndTable () {
370
- return "|===\n " ;
374
+ return "|===" + System . lineSeparator () ;
371
375
}
372
376
373
377
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 ()));
377
379
}
378
380
379
381
public String toAsciidoctor (String source ) {
@@ -406,7 +408,7 @@ public String renderBeanReferences(ApplicationModule module) {
406
408
return withDocumentation (result , targetType );
407
409
})
408
410
.map (this ::toBulletPoint )
409
- .collect (Collectors . joining (" \n " ));
411
+ .collect (joining (System . lineSeparator () ));
410
412
411
413
return bullets .isBlank () ? "None" : bullets ;
412
414
}
0 commit comments