Skip to content

Commit c5aa0d1

Browse files
committed
Polishing
Issue: SPR-9495 (cherry picked from commit baa698e)
1 parent 6de67cc commit c5aa0d1

File tree

4 files changed

+57
-54
lines changed

4 files changed

+57
-54
lines changed

spring-expression/src/main/java/org/springframework/expression/EvaluationContext.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,12 +19,12 @@
1919
import java.util.List;
2020

2121
/**
22-
* Expressions are executed in an evaluation context. It is in this context that references
23-
* are resolved when encountered during expression evaluation.
22+
* Expressions are executed in an evaluation context. It is in this context that
23+
* references are resolved when encountered during expression evaluation.
2424
*
2525
* <p>There is a default implementation of the EvaluationContext,
26-
* {@link org.springframework.expression.spel.support.StandardEvaluationContext}
27-
* that can be extended, rather than having to implement everything.
26+
* {@link org.springframework.expression.spel.support.StandardEvaluationContext} that can
27+
* be extended, rather than having to implement everything.
2828
*
2929
* @author Andy Clement
3030
* @author Juergen Hoeller
@@ -33,49 +33,51 @@
3333
public interface EvaluationContext {
3434

3535
/**
36-
* @return the default root context object against which unqualified properties/methods/etc
37-
* should be resolved. This can be overridden when evaluating an expression.
36+
* Return the default root context object against which unqualified
37+
* properties/methods/etc should be resolved. This can be overridden
38+
* when evaluating an expression.
3839
*/
3940
TypedValue getRootObject();
4041

4142
/**
42-
* @return a list of resolvers that will be asked in turn to locate a constructor
43+
* Return a list of resolvers that will be asked in turn to locate a constructor.
4344
*/
4445
List<ConstructorResolver> getConstructorResolvers();
4546

4647
/**
47-
* @return a list of resolvers that will be asked in turn to locate a method
48+
* Return a list of resolvers that will be asked in turn to locate a method.
4849
*/
4950
List<MethodResolver> getMethodResolvers();
5051

5152
/**
52-
* @return a list of accessors that will be asked in turn to read/write a property
53+
* Return a list of accessors that will be asked in turn to read/write a property.
5354
*/
5455
List<PropertyAccessor> getPropertyAccessors();
5556

5657
/**
57-
* @return a type locator that can be used to find types, either by short or fully qualified name.
58+
* Return a type locator that can be used to find types, either by short or
59+
* fully qualified name.
5860
*/
5961
TypeLocator getTypeLocator();
6062

6163
/**
62-
* @return a type converter that can convert (or coerce) a value from one type to another.
64+
* Return a type converter that can convert (or coerce) a value from one type to another.
6365
*/
6466
TypeConverter getTypeConverter();
6567

6668
/**
67-
* @return a type comparator for comparing pairs of objects for equality.
69+
* Return a type comparator for comparing pairs of objects for equality.
6870
*/
6971
TypeComparator getTypeComparator();
7072

7173
/**
72-
* @return an operator overloader that may support mathematical operations
73-
* between more than the standard set of types
74+
* Return an operator overloader that may support mathematical operations
75+
* between more than the standard set of types.
7476
*/
7577
OperatorOverloader getOperatorOverloader();
7678

7779
/**
78-
* @return a bean resolver that can look up beans by name
80+
* Return a bean resolver that can look up beans by name.
7981
*/
8082
BeanResolver getBeanResolver();
8183

spring-expression/src/main/java/org/springframework/expression/MethodExecutor.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,13 +17,15 @@
1717
package org.springframework.expression;
1818

1919
/**
20-
* MethodExecutors are built by the resolvers and can be cached by the infrastructure to repeat an operation quickly
21-
* without going back to the resolvers. For example, the particular method to run on an object may be discovered by the
22-
* reflection method resolver - it will then build a MethodExecutor that executes that method and the MethodExecutor can
23-
* be reused without needing to go back to the resolver to discover the method again.
20+
* MethodExecutors are built by the resolvers and can be cached by the infrastructure to
21+
* repeat an operation quickly without going back to the resolvers. For example, the
22+
* particular method to run on an object may be discovered by the reflection method
23+
* resolver - it will then build a MethodExecutor that executes that method and the
24+
* MethodExecutor can be reused without needing to go back to the resolver to discover
25+
* the method again.
2426
*
25-
* <p>They can become stale, and in that case should throw an AccessException - this will cause the infrastructure to go
26-
* back to the resolvers to ask for a new one.
27+
* <p>They can become stale, and in that case should throw an AccessException:
28+
* This will cause the infrastructure to go back to the resolvers to ask for a new one.
2729
*
2830
* @author Andy Clement
2931
* @since 3.0
@@ -34,10 +36,11 @@ public interface MethodExecutor {
3436
* Execute a command using the specified arguments, and using the specified expression state.
3537
* @param context the evaluation context in which the command is being executed
3638
* @param target the target object of the call - null for static methods
37-
* @param arguments the arguments to the executor, should match (in terms of number and type) whatever the
38-
* command will need to run
39+
* @param arguments the arguments to the executor, should match (in terms of number
40+
* and type) whatever the command will need to run
3941
* @return the value returned from execution
40-
* @throws AccessException if there is a problem executing the command or the MethodExecutor is no longer valid
42+
* @throws AccessException if there is a problem executing the command or the
43+
* MethodExecutor is no longer valid
4144
*/
4245
TypedValue execute(EvaluationContext context, Object target, Object... arguments) throws AccessException;
4346

spring-expression/src/main/java/org/springframework/expression/MethodResolver.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,18 +21,19 @@
2121
import org.springframework.core.convert.TypeDescriptor;
2222

2323
/**
24-
* A method resolver attempts locate a method and returns a command executor that can be used to invoke that method.
25-
* The command executor will be cached but if it 'goes stale' the resolvers will be called again.
24+
* A method resolver attempts locate a method and returns a command executor that can be
25+
* used to invoke that method. The command executor will be cached but if it 'goes stale'
26+
* the resolvers will be called again.
2627
*
2728
* @author Andy Clement
2829
* @since 3.0
2930
*/
3031
public interface MethodResolver {
3132

3233
/**
33-
* Within the supplied context determine a suitable method on the supplied object that can handle the
34-
* specified arguments. Return a MethodExecutor that can be used to invoke that method
35-
* (or {@code null} if no method could be found).
34+
* Within the supplied context determine a suitable method on the supplied object that
35+
* can handle the specified arguments. Return a {@link MethodExecutor} that can be used
36+
* to invoke that method, or {@code null} if no method could be found.
3637
* @param context the current evaluation context
3738
* @param targetObject the object upon which the method is being called
3839
* @param argumentTypes the arguments that the constructor must be able to handle

spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -103,15 +103,14 @@ public boolean removeConstructorResolver(ConstructorResolver resolver) {
103103
return this.constructorResolvers.remove(resolver);
104104
}
105105

106-
public List<ConstructorResolver> getConstructorResolvers() {
107-
ensureConstructorResolversInitialized();
108-
return this.constructorResolvers;
109-
}
110-
111106
public void setConstructorResolvers(List<ConstructorResolver> constructorResolvers) {
112107
this.constructorResolvers = constructorResolvers;
113108
}
114109

110+
public List<ConstructorResolver> getConstructorResolvers() {
111+
ensureConstructorResolversInitialized();
112+
return this.constructorResolvers;
113+
}
115114

116115
public void addMethodResolver(MethodResolver resolver) {
117116
ensureMethodResolversInitialized();
@@ -123,6 +122,10 @@ public boolean removeMethodResolver(MethodResolver methodResolver) {
123122
return this.methodResolvers.remove(methodResolver);
124123
}
125124

125+
public void setMethodResolvers(List<MethodResolver> methodResolvers) {
126+
this.methodResolvers = methodResolvers;
127+
}
128+
126129
public List<MethodResolver> getMethodResolvers() {
127130
ensureMethodResolversInitialized();
128131
return this.methodResolvers;
@@ -136,11 +139,6 @@ public BeanResolver getBeanResolver() {
136139
return this.beanResolver;
137140
}
138141

139-
public void setMethodResolvers(List<MethodResolver> methodResolvers) {
140-
this.methodResolvers = methodResolvers;
141-
}
142-
143-
144142
public void addPropertyAccessor(PropertyAccessor accessor) {
145143
ensurePropertyAccessorsInitialized();
146144
this.propertyAccessors.add(this.propertyAccessors.size() - 1, accessor);
@@ -150,15 +148,14 @@ public boolean removePropertyAccessor(PropertyAccessor accessor) {
150148
return this.propertyAccessors.remove(accessor);
151149
}
152150

153-
public List<PropertyAccessor> getPropertyAccessors() {
154-
ensurePropertyAccessorsInitialized();
155-
return this.propertyAccessors;
156-
}
157-
158151
public void setPropertyAccessors(List<PropertyAccessor> propertyAccessors) {
159152
this.propertyAccessors = propertyAccessors;
160153
}
161154

155+
public List<PropertyAccessor> getPropertyAccessors() {
156+
ensurePropertyAccessorsInitialized();
157+
return this.propertyAccessors;
158+
}
162159

163160
public void setTypeLocator(TypeLocator typeLocator) {
164161
Assert.notNull(typeLocator, "TypeLocator must not be null");
@@ -221,19 +218,18 @@ public Object lookupVariable(String name) {
221218
/**
222219
* Register a {@code MethodFilter} which will be called during method resolution
223220
* for the specified type.
224-
*
225221
* <p>The {@code MethodFilter} may remove methods and/or sort the methods which
226222
* will then be used by SpEL as the candidates to look through for a match.
227-
*
228223
* @param type the type for which the filter should be called
229224
* @param filter a {@code MethodFilter}, or {@code null} to unregister a filter for the type
230225
* @throws IllegalStateException if the {@link ReflectiveMethodResolver} is not in use
231226
*/
232227
public void registerMethodFilter(Class<?> type, MethodFilter filter) throws IllegalStateException {
233228
ensureMethodResolversInitialized();
234-
if (reflectiveMethodResolver != null) {
235-
reflectiveMethodResolver.registerMethodFilter(type, filter);
236-
} else {
229+
if (this.reflectiveMethodResolver != null) {
230+
this.reflectiveMethodResolver.registerMethodFilter(type, filter);
231+
}
232+
else {
237233
throw new IllegalStateException("Method filter cannot be set as the reflective method resolver is not in use");
238234
}
239235
}
@@ -261,7 +257,8 @@ private void ensureMethodResolversInitialized() {
261257
private synchronized void initializeMethodResolvers() {
262258
if (this.methodResolvers == null) {
263259
List<MethodResolver> defaultResolvers = new ArrayList<MethodResolver>();
264-
defaultResolvers.add(reflectiveMethodResolver = new ReflectiveMethodResolver());
260+
this.reflectiveMethodResolver = new ReflectiveMethodResolver();
261+
defaultResolvers.add(this.reflectiveMethodResolver);
265262
this.methodResolvers = defaultResolvers;
266263
}
267264
}

0 commit comments

Comments
 (0)