Skip to content

Commit faf54f3

Browse files
jhoellerunknown
authored and
unknown
committed
Polishing
Issue: SPR-10657
1 parent ed996ab commit faf54f3

File tree

1 file changed

+20
-33
lines changed

1 file changed

+20
-33
lines changed

spring-expression/src/main/java/org/springframework/expression/spel/ast/MethodReference.java

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,17 @@
4242
*/
4343
public class MethodReference extends SpelNodeImpl {
4444

45-
private final boolean nullSafe;
46-
4745
private final String name;
4846

47+
private final boolean nullSafe;
48+
4949
private volatile CachedMethodExecutor cachedExecutor;
5050

5151

52-
public MethodReference(boolean nullSafe, String methodName, int pos,
53-
SpelNodeImpl... arguments) {
52+
public MethodReference(boolean nullSafe, String methodName, int pos, SpelNodeImpl... arguments) {
5453
super(pos, arguments);
55-
this.nullSafe = nullSafe;
5654
this.name = methodName;
55+
this.nullSafe = nullSafe;
5756
}
5857

5958

@@ -82,15 +81,14 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
8281

8382
private TypedValue getValueInternal(EvaluationContext evaluationContext,
8483
Object value, Object[] arguments, TypeDescriptor targetType) {
85-
List<TypeDescriptor> argumentTypes = getArgumentTypes(arguments);
8684

85+
List<TypeDescriptor> argumentTypes = getArgumentTypes(arguments);
8786
if (value == null) {
8887
throwIfNotNullSafe(argumentTypes);
8988
return TypedValue.NULL;
9089
}
9190

9291
MethodExecutor executorToUse = getCachedExecutor(targetType, argumentTypes);
93-
9492
if (executorToUse != null) {
9593
try {
9694
return executorToUse.execute(evaluationContext, value, arguments);
@@ -118,8 +116,7 @@ private TypedValue getValueInternal(EvaluationContext evaluationContext,
118116

119117
// either there was no accessor or it no longer existed
120118
executorToUse = findAccessorForMethod(this.name, argumentTypes, value, evaluationContext);
121-
this.cachedExecutor = new CachedMethodExecutor(executorToUse, targetType,
122-
argumentTypes);
119+
this.cachedExecutor = new CachedMethodExecutor(executorToUse, targetType, argumentTypes);
123120
try {
124121
return executorToUse.execute(evaluationContext,
125122
value, arguments);
@@ -129,8 +126,7 @@ private TypedValue getValueInternal(EvaluationContext evaluationContext,
129126
throwSimpleExceptionIfPossible(value, ex);
130127
throw new SpelEvaluationException(getStartPosition(), ex,
131128
SpelMessage.EXCEPTION_DURING_METHOD_INVOCATION, this.name,
132-
value.getClass().getName(),
133-
ex.getMessage());
129+
value.getClass().getName(), ex.getMessage());
134130
}
135131
}
136132

@@ -166,8 +162,7 @@ private List<TypeDescriptor> getArgumentTypes(Object... arguments) {
166162
return Collections.unmodifiableList(descriptors);
167163
}
168164

169-
private MethodExecutor getCachedExecutor(TypeDescriptor target,
170-
List<TypeDescriptor> argumentTypes) {
165+
private MethodExecutor getCachedExecutor(TypeDescriptor target, List<TypeDescriptor> argumentTypes) {
171166
if (this.cachedExecutor != null && this.cachedExecutor.isSuitable(target, argumentTypes)) {
172167
return this.cachedExecutor.get();
173168
}
@@ -191,17 +186,15 @@ private MethodExecutor findAccessorForMethod(String name,
191186
}
192187
catch (AccessException ex) {
193188
throw new SpelEvaluationException(getStartPosition(), ex,
194-
SpelMessage.PROBLEM_LOCATING_METHOD, name,
195-
contextObject.getClass());
189+
SpelMessage.PROBLEM_LOCATING_METHOD, name, contextObject.getClass());
196190
}
197191
}
198192
}
199193

200194
throw new SpelEvaluationException(getStartPosition(), SpelMessage.METHOD_NOT_FOUND,
201195
FormatHelper.formatMethodForMessage(name, argumentTypes),
202196
FormatHelper.formatClassNameForMessage(
203-
contextObject instanceof Class ? ((Class<?>) contextObject)
204-
: contextObject.getClass()));
197+
contextObject instanceof Class ? ((Class<?>) contextObject) : contextObject.getClass()));
205198
}
206199

207200
/**
@@ -239,24 +232,21 @@ public String toStringAST() {
239232

240233
private class MethodValueRef implements ValueRef {
241234

235+
private final EvaluationContext evaluationContext;
242236

243-
private EvaluationContext evaluationContext;
244-
245-
private Object value;
237+
private final Object value;
246238

247-
private TypeDescriptor targetType;
239+
private final TypeDescriptor targetType;
248240

249-
private Object[] arguments;
241+
private final Object[] arguments;
250242

251-
252-
MethodValueRef(ExpressionState state) {
243+
public MethodValueRef(ExpressionState state) {
253244
this.evaluationContext = state.getEvaluationContext();
254245
this.value = state.getActiveContextObject().getValue();
255246
this.targetType = state.getActiveContextObject().getTypeDescriptor();
256247
this.arguments = getArguments(state);
257248
}
258249

259-
260250
@Override
261251
public TypedValue getValue() {
262252
return MethodReference.this.getValueInternal(this.evaluationContext,
@@ -283,23 +273,20 @@ private static class CachedMethodExecutor {
283273

284274
private final List<TypeDescriptor> argumentTypes;
285275

286-
287-
public CachedMethodExecutor(MethodExecutor methodExecutor, TypeDescriptor target,
288-
List<TypeDescriptor> argumentTypes) {
276+
public CachedMethodExecutor(MethodExecutor methodExecutor, TypeDescriptor target, List<TypeDescriptor> argumentTypes) {
289277
this.methodExecutor = methodExecutor;
290278
this.target = target;
291279
this.argumentTypes = argumentTypes;
292280
}
293281

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));
299285
}
300286

301287
public MethodExecutor get() {
302288
return this.methodExecutor;
303289
}
304290
}
291+
305292
}

0 commit comments

Comments
 (0)