21
21
import pl .wavesoftware .utils .stringify .impl .inspector .InspectionContext ;
22
22
import pl .wavesoftware .utils .stringify .impl .inspector .InspectorModule ;
23
23
import pl .wavesoftware .utils .stringify .impl .inspector .ObjectInspector ;
24
+ import pl .wavesoftware .utils .stringify .spi .theme .ComplexObjectStyle ;
24
25
25
26
import java .lang .reflect .Field ;
26
27
import java .util .LinkedHashMap ;
27
28
import java .util .Map ;
28
- import java .util .function .Function ;
29
29
30
30
import static pl .wavesoftware .eid .utils .EidExecutions .tryToExecute ;
31
31
@@ -40,56 +40,56 @@ final class InspectorBasedToStringResolver implements ToStringResolver {
40
40
private final DefaultConfiguration configuration ;
41
41
private final Object target ;
42
42
private final InspectionContext inspectionContext ;
43
- private final Function <Object , CharSequence > alternative ;
44
43
private final BeanFactoryCache beanFactoryCache ;
45
44
private final InspectingFieldFactory inspectingFieldFactory ;
46
45
47
46
InspectorBasedToStringResolver (
48
47
DefaultConfiguration configuration ,
49
48
Object target ,
50
49
InspectionContext inspectionContext ,
51
- Function <Object , CharSequence > alternative ,
52
50
BeanFactoryCache beanFactoryCache ,
53
51
InspectingFieldFactory inspectingFieldFactory
54
52
) {
55
53
this .configuration = configuration ;
56
54
this .target = target ;
57
55
this .inspectionContext = inspectionContext ;
58
- this .alternative = alternative ;
59
56
this .beanFactoryCache = beanFactoryCache ;
60
57
this .inspectingFieldFactory = inspectingFieldFactory ;
61
58
}
62
59
63
60
@ Override
64
61
public CharSequence resolve () {
65
- inspectionContext .markIsInspected (target );
62
+ inspectionContext .markAsInspected (target );
63
+ ComplexObjectStyle style = inspectionContext .theme ().complexObject ();
66
64
StringBuilder sb = new StringBuilder ();
67
- sb .append ('<' );
68
- sb .append (target . getClass (). getSimpleName ( ));
65
+ sb .append (style . begin () );
66
+ sb .append (style . name ( target :: getClass , target :: hashCode ));
69
67
CharSequence props = propertiesForToString ();
70
68
if (props .length () != 0 ) {
71
- sb .append (' ' );
69
+ sb .append (style . nameSeparator () );
72
70
sb .append (props );
73
71
}
74
- sb .append ('>' );
72
+ sb .append (style . end () );
75
73
return sb ;
76
74
}
77
75
78
76
private CharSequence propertiesForToString () {
79
77
Map <String , CharSequence > props ;
80
78
props = inspectTargetAsClass (target .getClass ());
79
+ ComplexObjectStyle style = inspectionContext .theme ().complexObject ();
81
80
StringBuilder sb = new StringBuilder ();
82
81
for (Map .Entry <String , CharSequence > entry : props .entrySet ()) {
83
82
String fieldName = entry .getKey ();
84
83
CharSequence fieldStringValue = entry .getValue ();
85
84
sb .append (fieldName );
86
- sb .append ("=" );
85
+ sb .append (style . propertyEquals () );
87
86
sb .append (fieldStringValue );
88
- sb .append (", " );
87
+ sb .append (style . propertySeparator () );
89
88
}
90
- if (sb .length () > 0 ) {
91
- sb .deleteCharAt (sb .length () - 1 );
92
- sb .deleteCharAt (sb .length () - 1 );
89
+ if (!props .isEmpty ()) {
90
+ for (int i = 0 ; i < style .propertySeparator ().length (); i ++) {
91
+ sb .deleteCharAt (sb .length () - 1 );
92
+ }
93
93
}
94
94
return sb ;
95
95
}
@@ -106,11 +106,13 @@ private Map<String, CharSequence> inspectTargetAsClass(Class<?> type) {
106
106
return props ;
107
107
}
108
108
109
- private void inspectFields (Field [] fields ,
110
- Map <String , CharSequence > properties ) {
109
+ private void inspectFields (
110
+ Field [] fields , Map <String , CharSequence > properties
111
+ ) {
111
112
for (Field field : fields ) {
112
113
InspectionPoint inspectionPoint = createInspectionPoint (field );
113
- InspectingField inspectingField = inspectingFieldFactory .create (inspectionPoint , beanFactoryCache );
114
+ InspectingField inspectingField = inspectingFieldFactory
115
+ .create (inspectionPoint , beanFactoryCache );
114
116
if (inspectingField .shouldInspect ()) {
115
117
inspectAnnotatedField (properties , field , inspectingField );
116
118
}
@@ -121,9 +123,11 @@ private InspectionPoint createInspectionPoint(Field field) {
121
123
return new InspectionPointImpl (field , target );
122
124
}
123
125
124
- private void inspectAnnotatedField (final Map <String , CharSequence > properties ,
125
- final Field field ,
126
- final InspectingField inspectingField ) {
126
+ private void inspectAnnotatedField (
127
+ final Map <String , CharSequence > properties ,
128
+ final Field field ,
129
+ final InspectingField inspectingField
130
+ ) {
127
131
tryToExecute (() -> {
128
132
ensureAccessible (field );
129
133
Object value = field .get (target );
@@ -146,7 +150,7 @@ private static void ensureAccessible(Field field) {
146
150
CharSequence inspectObject (Object object ) {
147
151
for (ObjectInspector inspector : OBJECT_INSPECTORS ) {
148
152
if (inspector .consentTo (object , inspectionContext )) {
149
- return inspector .inspect (object , alternative );
153
+ return inspector .inspect (object , inspectionContext );
150
154
}
151
155
}
152
156
ToStringResolverImpl sub = new ToStringResolverImpl (
0 commit comments