From 40d84c297bd88a2c4b7979b14eb7925e5fce0170 Mon Sep 17 00:00:00 2001 From: Xjzon <1070809335@qq.com> Date: Thu, 28 Oct 2021 00:11:59 +0800 Subject: [PATCH 1/2] Add support for custom expression parsing See gh-27604 --- .../context/expression/CachedExpressionEvaluator.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 7b868fc987..13a04440d5 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 @@ -86,7 +86,7 @@ public abstract class CachedExpressionEvaluator { ExpressionKey expressionKey = createKey(elementKey, expression); Expression expr = cache.get(expressionKey); if (expr == null) { - expr = getParser().parseExpression(expression); + expr = parseExpression(expression); cache.put(expressionKey, expr); } return expr; @@ -96,6 +96,13 @@ public abstract class CachedExpressionEvaluator { return new ExpressionKey(elementKey, expression); } + /** + * Parse the expression + * @param expression the expression to parse + */ + protected Expression parseExpression(String expression) { + return getParser().parseExpression(expression); + } /** * An expression key. From f295c8b2fbb8ac61f570c9b35abb45f0837fdd66 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 28 Oct 2021 14:10:21 +0200 Subject: [PATCH 2/2] Polish "Add support for custom expression parsing" See gh-27604 --- .../expression/CachedExpressionEvaluator.java | 14 ++++++++------ .../expression/CachedExpressionEvaluatorTests.java | 2 +- 2 files changed, 9 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 13a04440d5..c2d197a122 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 @@ -75,7 +75,7 @@ public abstract class CachedExpressionEvaluator { /** * Return the {@link Expression} for the specified SpEL value - *

Parse the expression if it hasn't been already. + *

{@link #parseExpression(String) 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 @@ -92,18 +92,20 @@ public abstract class CachedExpressionEvaluator { return expr; } - private ExpressionKey createKey(AnnotatedElementKey elementKey, String expression) { - return new ExpressionKey(elementKey, expression); - } - /** - * Parse the expression + * Parse the specified {@code expression}. * @param expression the expression to parse + * @since 5.3.13 */ protected Expression parseExpression(String expression) { return getParser().parseExpression(expression); } + private ExpressionKey createKey(AnnotatedElementKey elementKey, String expression) { + return new ExpressionKey(elementKey, expression); + } + + /** * An expression key. */ diff --git a/spring-context/src/test/java/org/springframework/context/expression/CachedExpressionEvaluatorTests.java b/spring-context/src/test/java/org/springframework/context/expression/CachedExpressionEvaluatorTests.java index f81a7945d7..1594137c04 100644 --- a/spring-context/src/test/java/org/springframework/context/expression/CachedExpressionEvaluatorTests.java +++ b/spring-context/src/test/java/org/springframework/context/expression/CachedExpressionEvaluatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.