42
42
*/
43
43
public class MethodReference extends SpelNodeImpl {
44
44
45
- private final boolean nullSafe ;
46
-
47
45
private final String name ;
48
46
47
+ private final boolean nullSafe ;
48
+
49
49
private volatile CachedMethodExecutor cachedExecutor ;
50
50
51
51
52
- public MethodReference (boolean nullSafe , String methodName , int pos ,
53
- SpelNodeImpl ... arguments ) {
52
+ public MethodReference (boolean nullSafe , String methodName , int pos , SpelNodeImpl ... arguments ) {
54
53
super (pos , arguments );
55
- this .nullSafe = nullSafe ;
56
54
this .name = methodName ;
55
+ this .nullSafe = nullSafe ;
57
56
}
58
57
59
58
@@ -82,15 +81,14 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
82
81
83
82
private TypedValue getValueInternal (EvaluationContext evaluationContext ,
84
83
Object value , Object [] arguments , TypeDescriptor targetType ) {
85
- List <TypeDescriptor > argumentTypes = getArgumentTypes (arguments );
86
84
85
+ List <TypeDescriptor > argumentTypes = getArgumentTypes (arguments );
87
86
if (value == null ) {
88
87
throwIfNotNullSafe (argumentTypes );
89
88
return TypedValue .NULL ;
90
89
}
91
90
92
91
MethodExecutor executorToUse = getCachedExecutor (targetType , argumentTypes );
93
-
94
92
if (executorToUse != null ) {
95
93
try {
96
94
return executorToUse .execute (evaluationContext , value , arguments );
@@ -118,8 +116,7 @@ private TypedValue getValueInternal(EvaluationContext evaluationContext,
118
116
119
117
// either there was no accessor or it no longer existed
120
118
executorToUse = findAccessorForMethod (this .name , argumentTypes , value , evaluationContext );
121
- this .cachedExecutor = new CachedMethodExecutor (executorToUse , targetType ,
122
- argumentTypes );
119
+ this .cachedExecutor = new CachedMethodExecutor (executorToUse , targetType , argumentTypes );
123
120
try {
124
121
return executorToUse .execute (evaluationContext ,
125
122
value , arguments );
@@ -129,8 +126,7 @@ private TypedValue getValueInternal(EvaluationContext evaluationContext,
129
126
throwSimpleExceptionIfPossible (value , ex );
130
127
throw new SpelEvaluationException (getStartPosition (), ex ,
131
128
SpelMessage .EXCEPTION_DURING_METHOD_INVOCATION , this .name ,
132
- value .getClass ().getName (),
133
- ex .getMessage ());
129
+ value .getClass ().getName (), ex .getMessage ());
134
130
}
135
131
}
136
132
@@ -166,8 +162,7 @@ private List<TypeDescriptor> getArgumentTypes(Object... arguments) {
166
162
return Collections .unmodifiableList (descriptors );
167
163
}
168
164
169
- private MethodExecutor getCachedExecutor (TypeDescriptor target ,
170
- List <TypeDescriptor > argumentTypes ) {
165
+ private MethodExecutor getCachedExecutor (TypeDescriptor target , List <TypeDescriptor > argumentTypes ) {
171
166
if (this .cachedExecutor != null && this .cachedExecutor .isSuitable (target , argumentTypes )) {
172
167
return this .cachedExecutor .get ();
173
168
}
@@ -191,17 +186,15 @@ private MethodExecutor findAccessorForMethod(String name,
191
186
}
192
187
catch (AccessException ex ) {
193
188
throw new SpelEvaluationException (getStartPosition (), ex ,
194
- SpelMessage .PROBLEM_LOCATING_METHOD , name ,
195
- contextObject .getClass ());
189
+ SpelMessage .PROBLEM_LOCATING_METHOD , name , contextObject .getClass ());
196
190
}
197
191
}
198
192
}
199
193
200
194
throw new SpelEvaluationException (getStartPosition (), SpelMessage .METHOD_NOT_FOUND ,
201
195
FormatHelper .formatMethodForMessage (name , argumentTypes ),
202
196
FormatHelper .formatClassNameForMessage (
203
- contextObject instanceof Class ? ((Class <?>) contextObject )
204
- : contextObject .getClass ()));
197
+ contextObject instanceof Class ? ((Class <?>) contextObject ) : contextObject .getClass ()));
205
198
}
206
199
207
200
/**
@@ -239,24 +232,21 @@ public String toStringAST() {
239
232
240
233
private class MethodValueRef implements ValueRef {
241
234
235
+ private final EvaluationContext evaluationContext ;
242
236
243
- private EvaluationContext evaluationContext ;
244
-
245
- private Object value ;
237
+ private final Object value ;
246
238
247
- private TypeDescriptor targetType ;
239
+ private final TypeDescriptor targetType ;
248
240
249
- private Object [] arguments ;
241
+ private final Object [] arguments ;
250
242
251
-
252
- MethodValueRef (ExpressionState state ) {
243
+ public MethodValueRef (ExpressionState state ) {
253
244
this .evaluationContext = state .getEvaluationContext ();
254
245
this .value = state .getActiveContextObject ().getValue ();
255
246
this .targetType = state .getActiveContextObject ().getTypeDescriptor ();
256
247
this .arguments = getArguments (state );
257
248
}
258
249
259
-
260
250
@ Override
261
251
public TypedValue getValue () {
262
252
return MethodReference .this .getValueInternal (this .evaluationContext ,
@@ -283,23 +273,20 @@ private static class CachedMethodExecutor {
283
273
284
274
private final List <TypeDescriptor > argumentTypes ;
285
275
286
-
287
- public CachedMethodExecutor (MethodExecutor methodExecutor , TypeDescriptor target ,
288
- List <TypeDescriptor > argumentTypes ) {
276
+ public CachedMethodExecutor (MethodExecutor methodExecutor , TypeDescriptor target , List <TypeDescriptor > argumentTypes ) {
289
277
this .methodExecutor = methodExecutor ;
290
278
this .target = target ;
291
279
this .argumentTypes = argumentTypes ;
292
280
}
293
281
294
-
295
- public boolean isSuitable (TypeDescriptor target ,
296
- List <TypeDescriptor > argumentTypes ) {
297
- return (this .methodExecutor != null && this .target != null
298
- && this .target .equals (target ) && this .argumentTypes .equals (argumentTypes ));
282
+ public boolean isSuitable (TypeDescriptor target , List <TypeDescriptor > argumentTypes ) {
283
+ return (this .methodExecutor != null && this .target != null &&
284
+ this .target .equals (target ) && this .argumentTypes .equals (argumentTypes ));
299
285
}
300
286
301
287
public MethodExecutor get () {
302
288
return this .methodExecutor ;
303
289
}
304
290
}
291
+
305
292
}
0 commit comments