Skip to content

Commit

Permalink
add parseConext param for CachedExpressionEvaluator#getExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
Xjzon committed Oct 24, 2021
1 parent e4e667a commit 756aaa2
Showing 1 changed file with 22 additions and 8 deletions.
Expand Up @@ -21,6 +21,7 @@
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.expression.Expression;
import org.springframework.expression.ParserContext;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
Expand Down Expand Up @@ -82,15 +83,28 @@ protected ParameterNameDiscoverer getParameterNameDiscoverer() {
*/
protected Expression getExpression(Map<ExpressionKey, Expression> cache,
AnnotatedElementKey elementKey, String expression) {

ExpressionKey expressionKey = createKey(elementKey, expression);
Expression expr = cache.get(expressionKey);
if (expr == null) {
expr = getParser().parseExpression(expression);
cache.put(expressionKey, expr);
}
return expr;
return getExpression(cache, elementKey, expression, null);
}

/**
* Return the {@link Expression} for the specified SpEL value
* <p>Parse the expression if it hasn't been already.
* @param cache the cache to use
* @param elementKey the element on which the expression is defined
* @param expression the expression to parse
* @param parserContext Input provided to an expression parser that can influence an expression
*/
protected Expression getExpression(Map<ExpressionKey, Expression> cache,
AnnotatedElementKey elementKey, String expression, ParserContext parserContext) {

ExpressionKey expressionKey = createKey(elementKey, expression);
Expression expr = cache.get(expressionKey);
if (expr == null) {
expr = getParser().parseExpression(expression, parserContext);
cache.put(expressionKey, expr);
}
return expr;
}

private ExpressionKey createKey(AnnotatedElementKey elementKey, String expression) {
return new ExpressionKey(elementKey, expression);
Expand Down

0 comments on commit 756aaa2

Please sign in to comment.