use of cn.taketoday.expression.TypedValue in project today-framework by TAKETODAY.
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 cn.taketoday.expression.TypedValue in project today-framework by TAKETODAY.
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 cn.taketoday.expression.TypedValue in project today-framework by TAKETODAY.
the class ReflectiveConstructorExecutor method execute.
@Override
public TypedValue execute(EvaluationContext context, Object... arguments) throws AccessException {
try {
ReflectionHelper.convertArguments(context.getTypeConverter(), arguments, this.ctor, this.varargsPosition);
if (this.ctor.isVarArgs()) {
arguments = ReflectionHelper.setupArgumentsForVarargsInvocation(this.ctor.getParameterTypes(), arguments);
}
ReflectionUtils.makeAccessible(this.ctor);
return new TypedValue(this.ctor.newInstance(arguments));
} catch (Exception ex) {
throw new AccessException("Problem invoking constructor: " + this.ctor, ex);
}
}
use of cn.taketoday.expression.TypedValue in project today-framework by TAKETODAY.
the class SpelExpression method getValue.
@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> T getValue(EvaluationContext context, @Nullable Class<T> expectedResultType) throws EvaluationException {
Assert.notNull(context, "EvaluationContext is required");
CompiledExpression compiledAst = this.compiledAst;
if (compiledAst != null) {
try {
Object result = compiledAst.getValue(context.getRootObject().getValue(), context);
if (expectedResultType != null) {
return ExpressionUtils.convertTypedValue(context, new TypedValue(result), expectedResultType);
} else {
return (T) result;
}
} 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(context, this.configuration);
TypedValue typedResultValue = this.ast.getTypedValue(expressionState);
checkCompile(expressionState);
return ExpressionUtils.convertTypedValue(context, typedResultValue, expectedResultType);
}
use of cn.taketoday.expression.TypedValue in project today-framework by TAKETODAY.
the class QualifiedIdentifier method getValueInternal.
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
// Cache the concatenation of child identifiers
if (this.value == null) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < getChildCount(); i++) {
Object value = this.children[i].getValueInternal(state).getValue();
if (i > 0 && (value == null || !value.toString().startsWith("$"))) {
sb.append('.');
}
sb.append(value);
}
this.value = new TypedValue(sb.toString());
}
return this.value;
}
Aggregations