@@ -59,15 +59,16 @@ public class NodeImpl
59
59
private final NodeImpl parent ;
60
60
private final NodeImpl root ;
61
61
private final int size ;
62
- private final boolean isIterable ;
63
- private final Integer index ;
64
- private final Object key ;
62
+ private boolean isIterable ;
63
+ private Integer index ;
64
+ private Object key ;
65
65
private final ElementKind kind ;
66
66
67
67
//type-specific attributes
68
68
private final Class <?>[] parameterTypes ;
69
69
private final Integer parameterIndex ;
70
- private final Object value ;
70
+ private Object value ;
71
+ private boolean valueSet ;
71
72
private final Class <?> containerClass ;
72
73
private final Integer typeArgumentIndex ;
73
74
@@ -76,7 +77,7 @@ public class NodeImpl
76
77
77
78
private NodeImpl (
78
79
String name , NodeImpl parent , boolean isIterable , Integer index , Object key , ElementKind kind , Class <?>[] parameterTypes ,
79
- Integer parameterIndex , Object value , Class <?> containerClass , Integer typeArgumentIndex
80
+ Integer parameterIndex , Object value , boolean valueSet , Class <?> containerClass , Integer typeArgumentIndex
80
81
) {
81
82
this .name = name ;
82
83
this .parent = parent ;
@@ -85,6 +86,7 @@ private NodeImpl(
85
86
this .index = index ;
86
87
this .key = key ;
87
88
this .value = value ;
89
+ this .valueSet = valueSet ;
88
90
this .isIterable = isIterable ;
89
91
this .kind = kind ;
90
92
this .parameterTypes = parameterTypes ;
@@ -105,6 +107,7 @@ public static NodeImpl createPropertyNode(String name, NodeImpl parent) {
105
107
EMPTY_CLASS_ARRAY ,
106
108
null ,
107
109
null ,
110
+ false ,
108
111
null ,
109
112
null
110
113
);
@@ -121,6 +124,7 @@ public static NodeImpl createContainerElementNode(String name, NodeImpl parent)
121
124
EMPTY_CLASS_ARRAY ,
122
125
null ,
123
126
null ,
127
+ false ,
124
128
null ,
125
129
null
126
130
);
@@ -137,6 +141,7 @@ public static NodeImpl createParameterNode(String name, NodeImpl parent, int par
137
141
EMPTY_CLASS_ARRAY ,
138
142
parameterIndex ,
139
143
null ,
144
+ false ,
140
145
null ,
141
146
null
142
147
);
@@ -153,17 +158,18 @@ public static NodeImpl createCrossParameterNode(NodeImpl parent) {
153
158
EMPTY_CLASS_ARRAY ,
154
159
null ,
155
160
null ,
161
+ false ,
156
162
null ,
157
163
null
158
164
);
159
165
}
160
166
161
167
public static NodeImpl createMethodNode (String name , NodeImpl parent , Class <?>[] parameterTypes ) {
162
- return new NodeImpl ( name , parent , false , null , null , ElementKind .METHOD , parameterTypes , null , null , null , null );
168
+ return new NodeImpl ( name , parent , false , null , null , ElementKind .METHOD , parameterTypes , null , null , false , null , null );
163
169
}
164
170
165
171
public static NodeImpl createConstructorNode (String name , NodeImpl parent , Class <?>[] parameterTypes ) {
166
- return new NodeImpl ( name , parent , false , null , null , ElementKind .CONSTRUCTOR , parameterTypes , null , null , null , null );
172
+ return new NodeImpl ( name , parent , false , null , null , ElementKind .CONSTRUCTOR , parameterTypes , null , null , false , null , null );
167
173
}
168
174
169
175
public static NodeImpl createBeanNode (NodeImpl parent ) {
@@ -177,6 +183,7 @@ public static NodeImpl createBeanNode(NodeImpl parent) {
177
183
EMPTY_CLASS_ARRAY ,
178
184
null ,
179
185
null ,
186
+ false ,
180
187
null ,
181
188
null
182
189
);
@@ -193,6 +200,7 @@ public static NodeImpl createReturnValue(NodeImpl parent) {
193
200
EMPTY_CLASS_ARRAY ,
194
201
null ,
195
202
null ,
203
+ false ,
196
204
null ,
197
205
null
198
206
);
@@ -209,6 +217,7 @@ public static NodeImpl makeIterable(NodeImpl node) {
209
217
node .parameterTypes ,
210
218
node .parameterIndex ,
211
219
node .value ,
220
+ node .valueSet ,
212
221
node .containerClass ,
213
222
node .typeArgumentIndex
214
223
);
@@ -225,6 +234,7 @@ public static NodeImpl makeIterableAndSetIndex(NodeImpl node, Integer index) {
225
234
node .parameterTypes ,
226
235
node .parameterIndex ,
227
236
node .value ,
237
+ node .valueSet ,
228
238
node .containerClass ,
229
239
node .typeArgumentIndex
230
240
);
@@ -241,25 +251,32 @@ public static NodeImpl makeIterableAndSetMapKey(NodeImpl node, Object key) {
241
251
node .parameterTypes ,
242
252
node .parameterIndex ,
243
253
node .value ,
254
+ node .valueSet ,
244
255
node .containerClass ,
245
256
node .typeArgumentIndex
246
257
);
247
258
}
248
259
249
260
public static NodeImpl setPropertyValue (NodeImpl node , Object value ) {
250
- return new NodeImpl (
251
- node .name ,
252
- node .parent ,
253
- node .isIterable ,
254
- node .index ,
255
- node .key ,
256
- node .kind ,
257
- node .parameterTypes ,
258
- node .parameterIndex ,
259
- value ,
260
- node .containerClass ,
261
- node .typeArgumentIndex
262
- );
261
+ if ( node .valueSet && node .value != value ) {
262
+ return new NodeImpl (
263
+ node .name ,
264
+ node .parent ,
265
+ node .isIterable ,
266
+ node .index ,
267
+ node .key ,
268
+ node .kind ,
269
+ node .parameterTypes ,
270
+ node .parameterIndex ,
271
+ value ,
272
+ true ,
273
+ node .containerClass ,
274
+ node .typeArgumentIndex
275
+ );
276
+ }
277
+ node .value = value ;
278
+ node .valueSet = true ;
279
+ return node ;
263
280
}
264
281
265
282
public static NodeImpl setTypeParameter (NodeImpl node , Class <?> containerClass , Integer typeArgumentIndex ) {
@@ -273,6 +290,7 @@ public static NodeImpl setTypeParameter(NodeImpl node, Class<?> containerClass,
273
290
node .parameterTypes ,
274
291
node .parameterIndex ,
275
292
node .value ,
293
+ node .valueSet ,
276
294
containerClass ,
277
295
typeArgumentIndex
278
296
);
@@ -370,7 +388,7 @@ public int getParameterIndex() {
370
388
kind == ElementKind .PARAMETER ,
371
389
"getParameterIndex() may only be invoked for nodes of type ElementKind.PARAMETER."
372
390
);
373
- return parameterIndex . intValue () ;
391
+ return parameterIndex ;
374
392
}
375
393
376
394
@ Override
@@ -541,6 +559,7 @@ boolean isRootPath() {
541
559
542
560
@ Override
543
561
public Iterator <Path .Node > iterator () {
562
+ // TODO: keep the initialized list so next iterator calls can reuse it?
544
563
if ( parent == null ) {
545
564
return List .of ( (Path .Node ) this ).iterator ();
546
565
}
0 commit comments