SpelExpression consistently exposes EvaluationContext to compiled AST
Operator includes explicit support for Boolean comparisons now. Issue: SPR-17229
This commit is contained in:
@@ -218,6 +218,10 @@ public abstract class Operator extends SpelNodeImpl {
|
||||
return left.toString().equals(right.toString());
|
||||
}
|
||||
|
||||
if (left instanceof Boolean && right instanceof Boolean) {
|
||||
return left.equals(right);
|
||||
}
|
||||
|
||||
if (ObjectUtils.nullSafeEquals(left, right)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -118,10 +118,8 @@ public class SpelExpression implements Expression {
|
||||
public Object getValue() throws EvaluationException {
|
||||
if (this.compiledAst != null) {
|
||||
try {
|
||||
TypedValue contextRoot =
|
||||
(this.evaluationContext != null ? this.evaluationContext.getRootObject() : null);
|
||||
return this.compiledAst.getValue(
|
||||
(contextRoot != null ? contextRoot.getValue() : null), this.evaluationContext);
|
||||
EvaluationContext context = getEvaluationContext();
|
||||
return this.compiledAst.getValue(context.getRootObject().getValue(), context);
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
// 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 {
|
||||
if (this.compiledAst != null) {
|
||||
try {
|
||||
TypedValue contextRoot =
|
||||
(this.evaluationContext != null ? this.evaluationContext.getRootObject() : null);
|
||||
Object result = this.compiledAst.getValue(
|
||||
(contextRoot != null ? contextRoot.getValue() : null), this.evaluationContext);
|
||||
EvaluationContext context = getEvaluationContext();
|
||||
Object result = this.compiledAst.getValue(context.getRootObject().getValue(), context);
|
||||
if (expectedResultType == null) {
|
||||
return (T) result;
|
||||
}
|
||||
@@ -185,7 +181,7 @@ public class SpelExpression implements Expression {
|
||||
public Object getValue(Object rootObject) throws EvaluationException {
|
||||
if (this.compiledAst != null) {
|
||||
try {
|
||||
return this.compiledAst.getValue(rootObject, this.evaluationContext);
|
||||
return this.compiledAst.getValue(rootObject, getEvaluationContext());
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
// 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 {
|
||||
if (this.compiledAst != null) {
|
||||
try {
|
||||
Object result = this.compiledAst.getValue(rootObject, null);
|
||||
Object result = this.compiledAst.getValue(rootObject, getEvaluationContext());
|
||||
if (expectedResultType == null) {
|
||||
return (T)result;
|
||||
}
|
||||
@@ -250,8 +246,7 @@ public class SpelExpression implements Expression {
|
||||
|
||||
if (this.compiledAst != null) {
|
||||
try {
|
||||
TypedValue contextRoot = context.getRootObject();
|
||||
return this.compiledAst.getValue(contextRoot.getValue(), context);
|
||||
return this.compiledAst.getValue(context.getRootObject().getValue(), context);
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
// If running in mixed mode, revert to interpreted
|
||||
@@ -280,8 +275,7 @@ public class SpelExpression implements Expression {
|
||||
|
||||
if (this.compiledAst != null) {
|
||||
try {
|
||||
TypedValue contextRoot = context.getRootObject();
|
||||
Object result = this.compiledAst.getValue(contextRoot.getValue(), context);
|
||||
Object result = this.compiledAst.getValue(context.getRootObject().getValue(), context);
|
||||
if (expectedResultType != null) {
|
||||
return ExpressionUtils.convertTypedValue(context, new TypedValue(result), expectedResultType);
|
||||
}
|
||||
@@ -315,7 +309,7 @@ public class SpelExpression implements Expression {
|
||||
|
||||
if (this.compiledAst != null) {
|
||||
try {
|
||||
return this.compiledAst.getValue(rootObject,context);
|
||||
return this.compiledAst.getValue(rootObject, context);
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
// If running in mixed mode, revert to interpreted
|
||||
|
||||
Reference in New Issue
Block a user