use of org.springframework.expression.TypedValue in project spring-framework by spring-projects.
the class CompoundExpression method getValueInternal.
/**
* Evaluates a compound expression. This involves evaluating each piece in turn and the
* return value from each piece is the active context object for the subsequent piece.
* @param state the state in which the expression is being evaluated
* @return the final value from the last piece of the compound expression
*/
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
ValueRef ref = getValueRef(state);
TypedValue result = ref.getValue();
this.exitTypeDescriptor = this.children[this.children.length - 1].exitTypeDescriptor;
return result;
}
use of org.springframework.expression.TypedValue in project spring-framework by spring-projects.
the class Elvis method getValueInternal.
/**
* Evaluate the condition and if not null, return it.
* If it is null, return the other value.
* @param state the expression state
* @throws EvaluationException if the condition does not evaluate correctly
* to a boolean or there is a problem executing the chosen alternative
*/
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
TypedValue value = this.children[0].getValueInternal(state);
// If this check is changed, the generateCode method will need changing too
if (value.getValue() != null && !"".equals(value.getValue())) {
return value;
} else {
TypedValue result = this.children[1].getValueInternal(state);
computeExitTypeDescriptor();
return result;
}
}
use of org.springframework.expression.TypedValue in project spring-framework by spring-projects.
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 org.springframework.expression.TypedValue in project spring-framework by spring-projects.
the class Assign method getValueInternal.
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
TypedValue newValue = this.children[1].getValueInternal(state);
getChild(0).setValue(state, newValue.getValue());
return newValue;
}
use of org.springframework.expression.TypedValue in project spring-framework by spring-projects.
the class ExpressionStateTests method testTypeConversion.
@Test
public void testTypeConversion() throws EvaluationException {
ExpressionState state = getState();
String s = (String) state.convertValue(34, TypeDescriptor.valueOf(String.class));
assertThat(s).isEqualTo("34");
s = (String) state.convertValue(new TypedValue(34), TypeDescriptor.valueOf(String.class));
assertThat(s).isEqualTo("34");
}
Aggregations