26
26
import org .springframework .lang .Nullable ;
27
27
28
28
/**
29
- * Implementation of {@link RouterFunctions.Visitor} that creates a formatted string representation
30
- * of router functions.
29
+ * Implementation of {@link RouterFunctions.Visitor} that creates a formatted
30
+ * string representation of router functions.
31
31
*
32
32
* @author Arjen Poutsma
33
33
* @since 5.0
34
34
*/
35
35
class ToStringVisitor implements RouterFunctions .Visitor , RequestPredicates .Visitor {
36
36
37
- private static final String NEW_LINE = System .getProperty ("line.separator" , "\\ n" );
38
-
39
37
private final StringBuilder builder = new StringBuilder ();
40
38
41
39
private int indent = 0 ;
42
40
43
41
@ Nullable
44
42
private String infix ;
45
43
44
+
46
45
// RouterFunctions.Visitor
47
46
48
47
@ Override
49
48
public void startNested (RequestPredicate predicate ) {
50
49
indent ();
51
50
predicate .accept (this );
52
- this .builder .append (" => {" );
53
- this .builder .append (NEW_LINE );
51
+ this .builder .append (" => {\n " );
54
52
this .indent ++;
55
53
}
56
54
57
55
@ Override
58
56
public void endNested (RequestPredicate predicate ) {
59
57
this .indent --;
60
58
indent ();
61
- this .builder .append ('}' );
62
- this .builder .append (NEW_LINE );
59
+ this .builder .append ("}\n " );
63
60
}
64
61
65
62
@ Override
66
63
public void route (RequestPredicate predicate , HandlerFunction <?> handlerFunction ) {
67
64
indent ();
68
65
predicate .accept (this );
69
66
this .builder .append (" -> " );
70
- this .builder .append (handlerFunction );
71
- this .builder .append (NEW_LINE );
67
+ this .builder .append (handlerFunction ).append ('\n' );
72
68
}
73
69
74
70
@ Override
75
71
public void resources (Function <ServerRequest , Mono <Resource >> lookupFunction ) {
76
72
indent ();
77
- this .builder .append (lookupFunction );
78
- this .builder .append (NEW_LINE );
73
+ this .builder .append (lookupFunction ).append ('\n' );
79
74
}
80
75
81
76
@ Override
@@ -90,6 +85,7 @@ private void indent() {
90
85
}
91
86
}
92
87
88
+
93
89
// RequestPredicates.Visitor
94
90
95
91
@ Override
@@ -178,9 +174,10 @@ private void infix() {
178
174
@ Override
179
175
public String toString () {
180
176
String result = this .builder .toString ();
181
- if (result .endsWith (NEW_LINE )) {
182
- result = result .substring (0 , result .length () - NEW_LINE . length () );
177
+ if (result .endsWith (" \n " )) {
178
+ result = result .substring (0 , result .length () - 1 );
183
179
}
184
180
return result ;
185
181
}
182
+
186
183
}
0 commit comments