Search in sources :

Example 6 with TypedValue

use of cn.taketoday.expression.TypedValue in project today-infrastructure by TAKETODAY.

the class ReflectionHelperTests method testTypedValue.

@Test
public void testTypedValue() {
    TypedValue tv1 = new TypedValue("hello");
    TypedValue tv2 = new TypedValue("hello");
    TypedValue tv3 = new TypedValue("bye");
    assertThat(tv1.getTypeDescriptor().getType()).isEqualTo(String.class);
    assertThat(tv1.toString()).isEqualTo("TypedValue: 'hello' of [java.lang.String]");
    assertThat(tv2).isEqualTo(tv1);
    assertThat(tv1).isEqualTo(tv2);
    assertThat(tv3).isNotEqualTo(tv1);
    assertThat(tv3).isNotEqualTo(tv2);
    assertThat(tv1).isNotEqualTo(tv3);
    assertThat(tv2).isNotEqualTo(tv3);
    assertThat(tv2.hashCode()).isEqualTo(tv1.hashCode());
    assertThat(tv3.hashCode()).isNotEqualTo(tv1.hashCode());
    assertThat(tv3.hashCode()).isNotEqualTo(tv2.hashCode());
}
Also used : TypedValue(cn.taketoday.expression.TypedValue) Test(org.junit.jupiter.api.Test)

Example 7 with TypedValue

use of cn.taketoday.expression.TypedValue in project today-infrastructure by TAKETODAY.

the class SpelReproTests method SPR9994_bridgeMethods.

@Test
void SPR9994_bridgeMethods() throws Exception {
    ReflectivePropertyAccessor accessor = new ReflectivePropertyAccessor();
    StandardEvaluationContext context = new StandardEvaluationContext();
    GenericImplementation target = new GenericImplementation();
    accessor.write(context, target, "property", "1");
    assertThat(target.value).isEqualTo(1);
    TypedValue value = accessor.read(context, target, "property");
    assertThat(value.getValue()).isEqualTo(1);
    assertThat(value.getTypeDescriptor().getType()).isEqualTo(Integer.class);
    assertThat(value.getTypeDescriptor().getAnnotations()).isNotEmpty();
}
Also used : StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) ReflectivePropertyAccessor(cn.taketoday.expression.spel.support.ReflectivePropertyAccessor) TypedValue(cn.taketoday.expression.TypedValue) Test(org.junit.jupiter.api.Test)

Example 8 with TypedValue

use of cn.taketoday.expression.TypedValue 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");
}
Also used : ExpressionState(cn.taketoday.expression.spel.ExpressionState) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) TypedValue(cn.taketoday.expression.TypedValue) Test(org.junit.jupiter.api.Test)

Example 9 with TypedValue

use of cn.taketoday.expression.TypedValue in project today-infrastructure by TAKETODAY.

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;
}
Also used : TypedValue(cn.taketoday.expression.TypedValue)

Example 10 with TypedValue

use of cn.taketoday.expression.TypedValue in project today-infrastructure 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;
}
Also used : TypedValue(cn.taketoday.expression.TypedValue)

Aggregations

TypedValue (cn.taketoday.expression.TypedValue)64 Test (org.junit.jupiter.api.Test)34 StandardEvaluationContext (cn.taketoday.expression.spel.support.StandardEvaluationContext)28 ExpressionState (cn.taketoday.expression.spel.ExpressionState)18 SpelEvaluationException (cn.taketoday.expression.spel.SpelEvaluationException)14 EvaluationContext (cn.taketoday.expression.EvaluationContext)12 Expression (cn.taketoday.expression.Expression)8 CompiledExpression (cn.taketoday.expression.spel.CompiledExpression)8 SpelExpressionParser (cn.taketoday.expression.spel.standard.SpelExpressionParser)8 Nullable (cn.taketoday.lang.Nullable)8 MethodParameter (cn.taketoday.core.MethodParameter)6 TypeDescriptor (cn.taketoday.core.TypeDescriptor)6 AccessException (cn.taketoday.expression.AccessException)6 EvaluationException (cn.taketoday.expression.EvaluationException)4 ReflectivePropertyAccessor (cn.taketoday.expression.spel.support.ReflectivePropertyAccessor)4 Time (java.sql.Time)4 Date (java.util.Date)4 GenericConversionService (cn.taketoday.core.conversion.support.GenericConversionService)2 ExpressionException (cn.taketoday.expression.ExpressionException)2 ExpressionParser (cn.taketoday.expression.ExpressionParser)2