@SuppressWarnings("unchecked") @Nullable public Map<Object, Object> getConstantValue() { Assert.state(this.constant != null, "No constant"); return (Map<Object, Object>) this.constant.getValue(); }
@SuppressWarnings("unchecked") @Nullable public List<Object> getConstantValue() { Assert.state(this.constant != null, "No constant"); return (List<Object>) this.constant.getValue(); }
@Override @Nullable public final Object getValue(ExpressionState expressionState) throws EvaluationException { return getValueInternal(expressionState).getValue(); }
@SuppressWarnings("unchecked") private static <T> T convertValue(TypeConverter typeConverter, TypedValue typedValue, Class<T> targetType) { Object result = typeConverter.convertValue(typedValue.getValue(), typedValue.getTypeDescriptor(), TypeDescriptor.valueOf(targetType)); if (result == null) { throw new IllegalStateException("Null conversion result for value [" + typedValue.getValue() + "]"); } return (T) result; }
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { mv.visitLdcInsn(this.value.getValue()); cf.pushDescriptor(this.exitTypeDescriptor); }
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { mv.visitLdcInsn(this.value.getValue()); cf.pushDescriptor(this.exitTypeDescriptor); }
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { mv.visitLdcInsn(this.value.getValue()); cf.pushDescriptor(this.exitTypeDescriptor); }
/** * Compute the arguments to the function, they are the children of this expression node. * @return an array of argument values for the function call */ private Object[] getArguments(ExpressionState state) throws EvaluationException { // Compute arguments to the function Object[] arguments = new Object[getChildCount()]; for (int i = 0; i < arguments.length; i++) { arguments[i] = this.children[i].getValueInternal(state).getValue(); } return arguments; }
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { mv.visitLdcInsn(this.value.getValue()); cf.pushDescriptor(this.exitTypeDescriptor); }
@Nullable public Object convertValue(TypedValue value, TypeDescriptor targetTypeDescriptor) throws EvaluationException { Object val = value.getValue(); return this.relatedContext.getTypeConverter().convertValue( val, TypeDescriptor.forObject(val), targetTypeDescriptor); }
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { TypedValue newValue = this.children[1].getValueInternal(state); getChild(0).setValue(state, newValue.getValue()); return newValue; }
public MethodValueRef(ExpressionState state, Object[] arguments) { this.evaluationContext = state.getEvaluationContext(); this.value = state.getActiveContextObject().getValue(); this.targetType = state.getActiveContextObject().getTypeDescriptor(); this.arguments = arguments; }
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { Object leftValue = getLeftOperand().getValueInternal(state).getValue(); Object rightValue = getRightOperand().getValueInternal(state).getValue(); this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(leftValue); this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(rightValue); return BooleanTypedValue.forValue(!equalityCheck(state.getEvaluationContext(), leftValue, rightValue)); }
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { Object left = getLeftOperand().getValueInternal(state).getValue(); Object right = getRightOperand().getValueInternal(state).getValue(); this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(left); this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(right); return BooleanTypedValue.forValue(equalityCheck(state.getEvaluationContext(), left, right)); }
@Override protected ValueRef getValueRef(ExpressionState state) throws EvaluationException { Object[] arguments = getArguments(state); if (state.getActiveContextObject().getValue() == null) { throwIfNotNullSafe(getArgumentTypes(arguments)); return ValueRef.NullValueRef.INSTANCE; } return new MethodValueRef(state, arguments); }
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { EvaluationContext evaluationContext = state.getEvaluationContext(); Object value = state.getActiveContextObject().getValue(); TypeDescriptor targetType = state.getActiveContextObject().getTypeDescriptor(); Object[] arguments = getArguments(state); TypedValue result = getValueInternal(evaluationContext, value, targetType, arguments); updateExitTypeDescriptor(); return result; }
@Test public void testRootObjectConstructor() { EvaluationContext ctx = getContext(); // TypedValue root = ctx.getRootObject(); // supplied should override root on context ExpressionState state = new ExpressionState(ctx,new TypedValue("i am a string")); TypedValue stateRoot = state.getRootContextObject(); assertEquals(String.class, stateRoot.getTypeDescriptor().getType()); assertEquals("i am a string", stateRoot.getValue()); }
@Test public void test_binaryPlusWithStringOperands() { ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext()); StringLiteral n1 = new StringLiteral("\"foo\"", -1, -1, "\"foo\""); StringLiteral n2 = new StringLiteral("\"bar\"", -1, -1, "\"bar\""); OpPlus o = new OpPlus(-1, -1, n1, n2); TypedValue value = o.getValueInternal(expressionState); assertEquals(String.class, value.getTypeDescriptor().getObjectType()); assertEquals(String.class, value.getTypeDescriptor().getType()); assertEquals("foobar", value.getValue()); }
@Test public void test_binaryPlusWithRightStringOperand() { ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext()); LongLiteral n1 = new LongLiteral("123", -1, -1, 123); StringLiteral n2 = new StringLiteral("\" is a number\"", -1, -1, "\" is a number\""); OpPlus o = new OpPlus(-1, -1, n1, n2); TypedValue value = o.getValueInternal(expressionState); assertEquals(String.class, value.getTypeDescriptor().getObjectType()); assertEquals(String.class, value.getTypeDescriptor().getType()); assertEquals("123 is a number", value.getValue()); }
@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); assertEquals(String.class, value.getTypeDescriptor().getObjectType()); assertEquals(String.class, value.getTypeDescriptor().getType()); assertEquals("number is 123", value.getValue()); }