SpelExpression consistently exposes EvaluationContext to compiled AST

Operator includes explicit support for Boolean comparisons now.

Issue: SPR-17229
This commit is contained in:
Juergen Hoeller
2018-08-31 12:41:22 +02:00
parent 8c6f3505c4
commit 51cee658d5
2 changed files with 13 additions and 15 deletions

View File

@@ -218,6 +218,10 @@ public abstract class Operator extends SpelNodeImpl {
return left.toString().equals(right.toString()); return left.toString().equals(right.toString());
} }
if (left instanceof Boolean && right instanceof Boolean) {
return left.equals(right);
}
if (ObjectUtils.nullSafeEquals(left, right)) { if (ObjectUtils.nullSafeEquals(left, right)) {
return true; return true;
} }

View File

@@ -118,10 +118,8 @@ public class SpelExpression implements Expression {
public Object getValue() throws EvaluationException { public Object getValue() throws EvaluationException {
if (this.compiledAst != null) { if (this.compiledAst != null) {
try { try {
TypedValue contextRoot = EvaluationContext context = getEvaluationContext();
(this.evaluationContext != null ? this.evaluationContext.getRootObject() : null); return this.compiledAst.getValue(context.getRootObject().getValue(), context);
return this.compiledAst.getValue(
(contextRoot != null ? contextRoot.getValue() : null), this.evaluationContext);
} }
catch (Throwable ex) { catch (Throwable ex) {
// If running in mixed mode, revert to interpreted // If running in mixed mode, revert to interpreted
@@ -148,10 +146,8 @@ public class SpelExpression implements Expression {
public <T> T getValue(@Nullable Class<T> expectedResultType) throws EvaluationException { public <T> T getValue(@Nullable Class<T> expectedResultType) throws EvaluationException {
if (this.compiledAst != null) { if (this.compiledAst != null) {
try { try {
TypedValue contextRoot = EvaluationContext context = getEvaluationContext();
(this.evaluationContext != null ? this.evaluationContext.getRootObject() : null); Object result = this.compiledAst.getValue(context.getRootObject().getValue(), context);
Object result = this.compiledAst.getValue(
(contextRoot != null ? contextRoot.getValue() : null), this.evaluationContext);
if (expectedResultType == null) { if (expectedResultType == null) {
return (T) result; return (T) result;
} }
@@ -185,7 +181,7 @@ public class SpelExpression implements Expression {
public Object getValue(Object rootObject) throws EvaluationException { public Object getValue(Object rootObject) throws EvaluationException {
if (this.compiledAst != null) { if (this.compiledAst != null) {
try { try {
return this.compiledAst.getValue(rootObject, this.evaluationContext); return this.compiledAst.getValue(rootObject, getEvaluationContext());
} }
catch (Throwable ex) { catch (Throwable ex) {
// If running in mixed mode, revert to interpreted // If running in mixed mode, revert to interpreted
@@ -213,7 +209,7 @@ public class SpelExpression implements Expression {
public <T> T getValue(Object rootObject, @Nullable Class<T> expectedResultType) throws EvaluationException { public <T> T getValue(Object rootObject, @Nullable Class<T> expectedResultType) throws EvaluationException {
if (this.compiledAst != null) { if (this.compiledAst != null) {
try { try {
Object result = this.compiledAst.getValue(rootObject, null); Object result = this.compiledAst.getValue(rootObject, getEvaluationContext());
if (expectedResultType == null) { if (expectedResultType == null) {
return (T)result; return (T)result;
} }
@@ -250,8 +246,7 @@ public class SpelExpression implements Expression {
if (this.compiledAst != null) { if (this.compiledAst != null) {
try { try {
TypedValue contextRoot = context.getRootObject(); return this.compiledAst.getValue(context.getRootObject().getValue(), context);
return this.compiledAst.getValue(contextRoot.getValue(), context);
} }
catch (Throwable ex) { catch (Throwable ex) {
// If running in mixed mode, revert to interpreted // If running in mixed mode, revert to interpreted
@@ -280,8 +275,7 @@ public class SpelExpression implements Expression {
if (this.compiledAst != null) { if (this.compiledAst != null) {
try { try {
TypedValue contextRoot = context.getRootObject(); Object result = this.compiledAst.getValue(context.getRootObject().getValue(), context);
Object result = this.compiledAst.getValue(contextRoot.getValue(), context);
if (expectedResultType != null) { if (expectedResultType != null) {
return ExpressionUtils.convertTypedValue(context, new TypedValue(result), expectedResultType); return ExpressionUtils.convertTypedValue(context, new TypedValue(result), expectedResultType);
} }
@@ -315,7 +309,7 @@ public class SpelExpression implements Expression {
if (this.compiledAst != null) { if (this.compiledAst != null) {
try { try {
return this.compiledAst.getValue(rootObject,context); return this.compiledAst.getValue(rootObject, context);
} }
catch (Throwable ex) { catch (Throwable ex) {
// If running in mixed mode, revert to interpreted // If running in mixed mode, revert to interpreted