diff options
Diffstat (limited to 'spring-context/src/main/java/org/springframework/context/expression/CachedExpressionEvaluator.java')
-rw-r--r-- | spring-context/src/main/java/org/springframework/context/expression/CachedExpressionEvaluator.java | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/spring-context/src/main/java/org/springframework/context/expression/CachedExpressionEvaluator.java b/spring-context/src/main/java/org/springframework/context/expression/CachedExpressionEvaluator.java index 4bb20b28..d530db80 100644 --- a/spring-context/src/main/java/org/springframework/context/expression/CachedExpressionEvaluator.java +++ b/spring-context/src/main/java/org/springframework/context/expression/CachedExpressionEvaluator.java @@ -18,6 +18,8 @@ package org.springframework.context.expression; import java.util.Map; +import org.springframework.core.DefaultParameterNameDiscoverer; +import org.springframework.core.ParameterNameDiscoverer; import org.springframework.expression.Expression; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.util.Assert; @@ -35,12 +37,14 @@ public abstract class CachedExpressionEvaluator { private final SpelExpressionParser parser; + private final ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer(); + /** * Create a new instance with the specified {@link SpelExpressionParser}. */ protected CachedExpressionEvaluator(SpelExpressionParser parser) { - Assert.notNull(parser, "Parser must not be null"); + Assert.notNull(parser, "SpelExpressionParser must not be null"); this.parser = parser; } @@ -59,6 +63,14 @@ public abstract class CachedExpressionEvaluator { return this.parser; } + /** + * Return a shared parameter name discoverer which caches data internally. + * @since 4.3 + */ + protected ParameterNameDiscoverer getParameterNameDiscoverer() { + return this.parameterNameDiscoverer; + } + /** * Return the {@link Expression} for the specified SpEL value @@ -84,14 +96,14 @@ public abstract class CachedExpressionEvaluator { } - protected static class ExpressionKey { + protected static class ExpressionKey implements Comparable<ExpressionKey> { - private final AnnotatedElementKey key; + private final AnnotatedElementKey element; private final String expression; - protected ExpressionKey(AnnotatedElementKey key, String expression) { - this.key = key; + protected ExpressionKey(AnnotatedElementKey element, String expression) { + this.element = element; this.expression = expression; } @@ -104,13 +116,27 @@ public abstract class CachedExpressionEvaluator { return false; } ExpressionKey otherKey = (ExpressionKey) other; - return (this.key.equals(otherKey.key) && + return (this.element.equals(otherKey.element) && ObjectUtils.nullSafeEquals(this.expression, otherKey.expression)); } @Override public int hashCode() { - return this.key.hashCode() + (this.expression != null ? this.expression.hashCode() * 29 : 0); + return this.element.hashCode() + (this.expression != null ? this.expression.hashCode() * 29 : 0); + } + + @Override + public String toString() { + return this.element + (this.expression != null ? " with expression \"" + this.expression : "\""); + } + + @Override + public int compareTo(ExpressionKey other) { + int result = this.element.toString().compareTo(other.element.toString()); + if (result == 0 && this.expression != null) { + result = this.expression.compareTo(other.expression); + } + return result; } } |