use of cn.taketoday.expression.spel.ExpressionState in project today-infrastructure by TAKETODAY.
the class OpPlusTests method test_unaryPlusWithStringLiteral.
@Test
public void test_unaryPlusWithStringLiteral() {
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
StringLiteral str = new StringLiteral("word", -1, -1, "word");
OpPlus o = new OpPlus(-1, -1, str);
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() -> o.getValueInternal(expressionState));
}
use of cn.taketoday.expression.spel.ExpressionState in project today-infrastructure by TAKETODAY.
the class OpPlusTests method test_binaryPlusWithLeftStringOperand.
@Test
public void test_binaryPlusWithLeftStringOperand() {
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
StringLiteral n1 = new StringLiteral("\"number is \"", -1, -1, "\"number is \"");
LongLiteral n2 = new LongLiteral("123", -1, -1, 123);
OpPlus o = new OpPlus(-1, -1, n1, n2);
TypedValue value = o.getValueInternal(expressionState);
assertThat(value.getTypeDescriptor().getObjectType()).isEqualTo(String.class);
assertThat(value.getTypeDescriptor().getType()).isEqualTo(String.class);
assertThat(value.getValue()).isEqualTo("number is 123");
}
use of cn.taketoday.expression.spel.ExpressionState in project today-infrastructure by TAKETODAY.
the class SpelExpression method getValueTypeDescriptor.
@Override
@Nullable
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException {
Assert.notNull(context, "EvaluationContext is required");
ExpressionState expressionState = new ExpressionState(context, toTypedValue(rootObject), this.configuration);
return this.ast.getValueInternal(expressionState).getTypeDescriptor();
}
use of cn.taketoday.expression.spel.ExpressionState in project today-infrastructure by TAKETODAY.
the class SpelExpression method getValueTypeDescriptor.
@Override
@Nullable
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context) throws EvaluationException {
Assert.notNull(context, "EvaluationContext is required");
ExpressionState expressionState = new ExpressionState(context, this.configuration);
return this.ast.getValueInternal(expressionState).getTypeDescriptor();
}
use of cn.taketoday.expression.spel.ExpressionState in project today-infrastructure by TAKETODAY.
the class SpelExpression method getValue.
@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> T getValue(@Nullable Class<T> expectedResultType) throws EvaluationException {
CompiledExpression compiledAst = this.compiledAst;
if (compiledAst != null) {
try {
EvaluationContext context = getEvaluationContext();
Object result = compiledAst.getValue(context.getRootObject().getValue(), context);
if (expectedResultType == null) {
return (T) result;
} else {
return ExpressionUtils.convertTypedValue(getEvaluationContext(), new TypedValue(result), expectedResultType);
}
} catch (Throwable ex) {
// If running in mixed mode, revert to interpreted
if (this.configuration.getCompilerMode() == SpelCompilerMode.MIXED) {
this.compiledAst = null;
this.interpretedCount.set(0);
} else {
// Running in SpelCompilerMode.immediate mode - propagate exception to caller
throw new SpelEvaluationException(ex, SpelMessage.EXCEPTION_RUNNING_COMPILED_EXPRESSION);
}
}
}
ExpressionState expressionState = new ExpressionState(getEvaluationContext(), this.configuration);
TypedValue typedResultValue = this.ast.getTypedValue(expressionState);
checkCompile(expressionState);
return ExpressionUtils.convertTypedValue(expressionState.getEvaluationContext(), typedResultValue, expectedResultType);
}
Aggregations