use of cn.taketoday.expression.OperatorOverloader in project today-infrastructure by TAKETODAY.
the class StandardComponentsTests method testStandardOperatorOverloader.
@Test
public void testStandardOperatorOverloader() throws EvaluationException {
OperatorOverloader oo = new StandardOperatorOverloader();
assertThat(oo.overridesOperation(Operation.ADD, null, null)).isFalse();
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() -> oo.operate(Operation.ADD, 2, 3));
}
use of cn.taketoday.expression.OperatorOverloader in project today-framework by TAKETODAY.
the class StandardComponentsTests method testStandardOperatorOverloader.
@Test
public void testStandardOperatorOverloader() throws EvaluationException {
OperatorOverloader oo = new StandardOperatorOverloader();
assertThat(oo.overridesOperation(Operation.ADD, null, null)).isFalse();
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() -> oo.operate(Operation.ADD, 2, 3));
}
use of cn.taketoday.expression.OperatorOverloader in project today-framework by TAKETODAY.
the class ExpressionState method operate.
public TypedValue operate(Operation op, @Nullable Object left, @Nullable Object right) throws EvaluationException {
OperatorOverloader overloader = this.relatedContext.getOperatorOverloader();
if (overloader.overridesOperation(op, left, right)) {
Object returnValue = overloader.operate(op, left, right);
return new TypedValue(returnValue);
} else {
String leftType = (left == null ? "null" : left.getClass().getName());
String rightType = (right == null ? "null" : right.getClass().getName());
throw new SpelEvaluationException(SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES, op, leftType, rightType);
}
}
use of cn.taketoday.expression.OperatorOverloader in project today-infrastructure by TAKETODAY.
the class ExpressionState method operate.
public TypedValue operate(Operation op, @Nullable Object left, @Nullable Object right) throws EvaluationException {
OperatorOverloader overloader = this.relatedContext.getOperatorOverloader();
if (overloader.overridesOperation(op, left, right)) {
Object returnValue = overloader.operate(op, left, right);
return new TypedValue(returnValue);
} else {
String leftType = (left == null ? "null" : left.getClass().getName());
String rightType = (right == null ? "null" : right.getClass().getName());
throw new SpelEvaluationException(SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES, op, leftType, rightType);
}
}
Aggregations