From baa698eddfa5d5cb842a52b9fe183bbde8eb3f29 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 4 Sep 2013 16:44:07 +0200 Subject: [PATCH] Polishing Issue: SPR-9495 --- .../expression/EvaluationContext.java | 26 +++++++------- .../expression/MethodExecutor.java | 15 ++++---- .../expression/MethodResolver.java | 7 ++-- .../support/StandardEvaluationContext.java | 35 +++++++++---------- 4 files changed, 39 insertions(+), 44 deletions(-) diff --git a/spring-expression/src/main/java/org/springframework/expression/EvaluationContext.java b/spring-expression/src/main/java/org/springframework/expression/EvaluationContext.java index a4953fe06d2..9d509c6121b 100644 --- a/spring-expression/src/main/java/org/springframework/expression/EvaluationContext.java +++ b/spring-expression/src/main/java/org/springframework/expression/EvaluationContext.java @@ -33,51 +33,51 @@ import java.util.List; public interface EvaluationContext { /** - * @return the default root context object against which unqualified - * properties/methods/etc should be resolved. This can be overridden when - * evaluating an expression. + * Return the default root context object against which unqualified + * properties/methods/etc should be resolved. This can be overridden + * when evaluating an expression. */ TypedValue getRootObject(); /** - * @return a list of resolvers that will be asked in turn to locate a constructor + * Return a list of resolvers that will be asked in turn to locate a constructor. */ List getConstructorResolvers(); /** - * @return a list of resolvers that will be asked in turn to locate a method + * Return a list of resolvers that will be asked in turn to locate a method. */ List getMethodResolvers(); /** - * @return a list of accessors that will be asked in turn to read/write a property + * Return a list of accessors that will be asked in turn to read/write a property. */ List getPropertyAccessors(); /** - * @return a type locator that can be used to find types, either by short or fully - * qualified name. + * Return a type locator that can be used to find types, either by short or + * fully qualified name. */ TypeLocator getTypeLocator(); /** - * @return a type converter that can convert (or coerce) a value from one type to another. + * Return a type converter that can convert (or coerce) a value from one type to another. */ TypeConverter getTypeConverter(); /** - * @return a type comparator for comparing pairs of objects for equality. + * Return a type comparator for comparing pairs of objects for equality. */ TypeComparator getTypeComparator(); /** - * @return an operator overloader that may support mathematical operations - * between more than the standard set of types + * Return an operator overloader that may support mathematical operations + * between more than the standard set of types. */ OperatorOverloader getOperatorOverloader(); /** - * @return a bean resolver that can look up beans by name + * Return a bean resolver that can look up beans by name. */ BeanResolver getBeanResolver(); diff --git a/spring-expression/src/main/java/org/springframework/expression/MethodExecutor.java b/spring-expression/src/main/java/org/springframework/expression/MethodExecutor.java index 1506f986303..6b94e4fbac8 100644 --- a/spring-expression/src/main/java/org/springframework/expression/MethodExecutor.java +++ b/spring-expression/src/main/java/org/springframework/expression/MethodExecutor.java @@ -21,11 +21,11 @@ package org.springframework.expression; * repeat an operation quickly without going back to the resolvers. For example, the * particular method to run on an object may be discovered by the reflection method * resolver - it will then build a MethodExecutor that executes that method and the - * MethodExecutor can be reused without needing to go back to the resolver to discover the - * method again. + * MethodExecutor can be reused without needing to go back to the resolver to discover + * the method again. * - *

They can become stale, and in that case should throw an AccessException - this will - * cause the infrastructure to go back to the resolvers to ask for a new one. + *

They can become stale, and in that case should throw an AccessException: + * This will cause the infrastructure to go back to the resolvers to ask for a new one. * * @author Andy Clement * @since 3.0 @@ -33,15 +33,14 @@ package org.springframework.expression; public interface MethodExecutor { /** - * Execute a command using the specified arguments, and using the specified expression - * state. + * Execute a command using the specified arguments, and using the specified expression state. * @param context the evaluation context in which the command is being executed * @param target the target object of the call - null for static methods * @param arguments the arguments to the executor, should match (in terms of number - * and type) whatever the command will need to run + * and type) whatever the command will need to run * @return the value returned from execution * @throws AccessException if there is a problem executing the command or the - * MethodExecutor is no longer valid + * MethodExecutor is no longer valid */ TypedValue execute(EvaluationContext context, Object target, Object... arguments) throws AccessException; diff --git a/spring-expression/src/main/java/org/springframework/expression/MethodResolver.java b/spring-expression/src/main/java/org/springframework/expression/MethodResolver.java index d3bdb78c962..e33dc8423fe 100644 --- a/spring-expression/src/main/java/org/springframework/expression/MethodResolver.java +++ b/spring-expression/src/main/java/org/springframework/expression/MethodResolver.java @@ -32,13 +32,12 @@ public interface MethodResolver { /** * Within the supplied context determine a suitable method on the supplied object that - * can handle the specified arguments. Return a MethodExecutor that can be used to - * invoke that method (or {@code null} if no method could be found). + * can handle the specified arguments. Return a {@link MethodExecutor} that can be used + * to invoke that method, or {@code null} if no method could be found. * @param context the current evaluation context * @param targetObject the object upon which the method is being called * @param argumentTypes the arguments that the constructor must be able to handle - * @return a MethodExecutor that can invoke the method, or null if the method cannot - * be found + * @return a MethodExecutor that can invoke the method, or null if the method cannot be found */ MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List argumentTypes) throws AccessException; diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java index 7f11c0d7b38..7f02343b396 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java @@ -104,17 +104,16 @@ public class StandardEvaluationContext implements EvaluationContext { return this.constructorResolvers.remove(resolver); } + public void setConstructorResolvers(List constructorResolvers) { + this.constructorResolvers = constructorResolvers; + } + @Override public List getConstructorResolvers() { ensureConstructorResolversInitialized(); return this.constructorResolvers; } - public void setConstructorResolvers(List constructorResolvers) { - this.constructorResolvers = constructorResolvers; - } - - public void addMethodResolver(MethodResolver resolver) { ensureMethodResolversInitialized(); this.methodResolvers.add(this.methodResolvers.size() - 1, resolver); @@ -125,6 +124,10 @@ public class StandardEvaluationContext implements EvaluationContext { return this.methodResolvers.remove(methodResolver); } + public void setMethodResolvers(List methodResolvers) { + this.methodResolvers = methodResolvers; + } + @Override public List getMethodResolvers() { ensureMethodResolversInitialized(); @@ -140,11 +143,6 @@ public class StandardEvaluationContext implements EvaluationContext { return this.beanResolver; } - public void setMethodResolvers(List methodResolvers) { - this.methodResolvers = methodResolvers; - } - - public void addPropertyAccessor(PropertyAccessor accessor) { ensurePropertyAccessorsInitialized(); this.propertyAccessors.add(this.propertyAccessors.size() - 1, accessor); @@ -154,17 +152,16 @@ public class StandardEvaluationContext implements EvaluationContext { return this.propertyAccessors.remove(accessor); } + public void setPropertyAccessors(List propertyAccessors) { + this.propertyAccessors = propertyAccessors; + } + @Override public List getPropertyAccessors() { ensurePropertyAccessorsInitialized(); return this.propertyAccessors; } - public void setPropertyAccessors(List propertyAccessors) { - this.propertyAccessors = propertyAccessors; - } - - public void setTypeLocator(TypeLocator typeLocator) { Assert.notNull(typeLocator, "TypeLocator must not be null"); this.typeLocator = typeLocator; @@ -232,10 +229,8 @@ public class StandardEvaluationContext implements EvaluationContext { /** * Register a {@code MethodFilter} which will be called during method resolution * for the specified type. - * *

The {@code MethodFilter} may remove methods and/or sort the methods which * will then be used by SpEL as the candidates to look through for a match. - * * @param type the type for which the filter should be called * @param filter a {@code MethodFilter}, or {@code null} to unregister a filter for the type * @throws IllegalStateException if the {@link ReflectiveMethodResolver} is not in use @@ -244,7 +239,8 @@ public class StandardEvaluationContext implements EvaluationContext { ensureMethodResolversInitialized(); if (this.reflectiveMethodResolver != null) { this.reflectiveMethodResolver.registerMethodFilter(type, filter); - } else { + } + else { throw new IllegalStateException("Method filter cannot be set as the reflective method resolver is not in use"); } } @@ -272,7 +268,8 @@ public class StandardEvaluationContext implements EvaluationContext { private synchronized void initializeMethodResolvers() { if (this.methodResolvers == null) { List defaultResolvers = new ArrayList(); - defaultResolvers.add(this.reflectiveMethodResolver = new ReflectiveMethodResolver()); + this.reflectiveMethodResolver = new ReflectiveMethodResolver(); + defaultResolvers.add(this.reflectiveMethodResolver); this.methodResolvers = defaultResolvers; } }