|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2023 the original author or authors. |
|
|
|
* Copyright 2002-2024 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -24,11 +24,10 @@ import org.springframework.expression.Expression; |
|
|
|
import org.springframework.expression.spel.standard.SpelExpressionParser; |
|
|
|
import org.springframework.expression.spel.standard.SpelExpressionParser; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Shared utility class used to evaluate and cache SpEL expressions that |
|
|
|
* Shared utility class used to evaluate and cache SpEL expressions that |
|
|
|
* are defined on {@link java.lang.reflect.AnnotatedElement}. |
|
|
|
* are defined on an {@link java.lang.reflect.AnnotatedElement AnnotatedElement}. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Stephane Nicoll |
|
|
|
* @author Stephane Nicoll |
|
|
|
* @since 4.2 |
|
|
|
* @since 4.2 |
|
|
|
@ -42,18 +41,18 @@ public abstract class CachedExpressionEvaluator { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new instance with the specified {@link SpelExpressionParser}. |
|
|
|
* Create a new instance with the default {@link SpelExpressionParser}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected CachedExpressionEvaluator(SpelExpressionParser parser) { |
|
|
|
protected CachedExpressionEvaluator() { |
|
|
|
Assert.notNull(parser, "SpelExpressionParser must not be null"); |
|
|
|
this(new SpelExpressionParser()); |
|
|
|
this.parser = parser; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new instance with a default {@link SpelExpressionParser}. |
|
|
|
* Create a new instance with the specified {@link SpelExpressionParser}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected CachedExpressionEvaluator() { |
|
|
|
protected CachedExpressionEvaluator(SpelExpressionParser parser) { |
|
|
|
this(new SpelExpressionParser()); |
|
|
|
Assert.notNull(parser, "SpelExpressionParser must not be null"); |
|
|
|
|
|
|
|
this.parser = parser; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -72,12 +71,13 @@ public abstract class CachedExpressionEvaluator { |
|
|
|
return this.parameterNameDiscoverer; |
|
|
|
return this.parameterNameDiscoverer; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return the {@link Expression} for the specified SpEL value |
|
|
|
* Return the parsed {@link Expression} for the specified SpEL expression. |
|
|
|
* <p>{@link #parseExpression(String) Parse the expression} if it hasn't been already. |
|
|
|
* <p>{@linkplain #parseExpression(String) Parses} the expression if it hasn't |
|
|
|
|
|
|
|
* already been parsed and cached. |
|
|
|
* @param cache the cache to use |
|
|
|
* @param cache the cache to use |
|
|
|
* @param elementKey the element on which the expression is defined |
|
|
|
* @param elementKey the {@code AnnotatedElementKey} containing the element |
|
|
|
|
|
|
|
* on which the expression is defined |
|
|
|
* @param expression the expression to parse |
|
|
|
* @param expression the expression to parse |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected Expression getExpression(Map<ExpressionKey, Expression> cache, |
|
|
|
protected Expression getExpression(Map<ExpressionKey, Expression> cache, |
|
|
|
@ -125,8 +125,7 @@ public abstract class CachedExpressionEvaluator { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean equals(@Nullable Object other) { |
|
|
|
public boolean equals(@Nullable Object other) { |
|
|
|
return (this == other || (other instanceof ExpressionKey that && |
|
|
|
return (this == other || (other instanceof ExpressionKey that && |
|
|
|
this.element.equals(that.element) && |
|
|
|
this.element.equals(that.element) && this.expression.equals(that.expression))); |
|
|
|
ObjectUtils.nullSafeEquals(this.expression, that.expression))); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
|