public override ITypedValue GetValueInternal(ExpressionState state) { var rightOperand = RightOperand; var left = LeftOperand.GetValueInternal(state); var right = rightOperand.GetValueInternal(state); var leftValue = left.Value; var rightValue = right.Value; BooleanTypedValue result; if (!(rightValue is Type)) { throw new SpelEvaluationException(RightOperand.StartPosition, SpelMessage.INSTANCEOF_OPERATOR_NEEDS_CLASS_OPERAND, rightValue == null ? "null" : rightValue.GetType().FullName); } var rightClass = (Type)rightValue; if (leftValue == null) { result = BooleanTypedValue.FALSE; // null is not an instanceof anything } else { result = BooleanTypedValue.ForValue(rightClass.IsAssignableFrom(leftValue.GetType())); } _type = rightClass; if (rightOperand is TypeReference) { // Can only generate bytecode where the right operand is a direct type reference, // not if it is indirect (for example when right operand is a variable reference) _exitTypeDescriptor = "Z"; } return(result); }
public override ITypedValue GetValueInternal(ExpressionState state) { var left = LeftOperand.GetValueInternal(state).Value; var right = RightOperand.GetValueInternal(state).Value; if (!(right is IList) || ((IList)right).Count != 2) { throw new SpelEvaluationException(RightOperand.StartPosition, SpelMessage.BETWEEN_RIGHT_OPERAND_MUST_BE_TWO_ELEMENT_LIST); } var list = (IList)right; var low = list[0]; var high = list[1]; var comp = state.TypeComparator; try { return(BooleanTypedValue.ForValue(comp.Compare(left, low) >= 0 && comp.Compare(left, high) <= 0)); } catch (SpelEvaluationException ex) { ex.Position = StartPosition; throw; } }
public override ITypedValue GetValueInternal(ExpressionState state) { var leftOperand = LeftOperand.GetValueInternal(state).Value; var rightOperand = RightOperand.GetValueInternal(state).Value; if (IsNumber(leftOperand) && IsNumber(rightOperand)) { var leftConv = (IConvertible)leftOperand; var rightConv = (IConvertible)rightOperand; if (leftOperand is decimal || rightOperand is decimal) { var leftVal = leftConv.ToDecimal(CultureInfo.InvariantCulture); var rightVal = rightConv.ToDecimal(CultureInfo.InvariantCulture); return(new TypedValue(leftVal / rightVal)); } else if (leftOperand is double || rightOperand is double) { var leftVal = leftConv.ToDouble(CultureInfo.InvariantCulture); var rightVal = rightConv.ToDouble(CultureInfo.InvariantCulture); _exitTypeDescriptor = TypeDescriptor.D; return(new TypedValue(leftVal / rightVal)); } else if (leftOperand is float || rightOperand is float) { var leftVal = leftConv.ToSingle(CultureInfo.InvariantCulture); var rightVal = rightConv.ToSingle(CultureInfo.InvariantCulture); _exitTypeDescriptor = TypeDescriptor.F; return(new TypedValue(leftVal / rightVal)); } // Look at need to add support for .NET types not present in Java, e.g. ulong, ushort, byte, uint else if (leftOperand is long || rightOperand is long) { var leftVal = leftConv.ToInt64(CultureInfo.InvariantCulture); var rightVal = rightConv.ToInt64(CultureInfo.InvariantCulture); _exitTypeDescriptor = TypeDescriptor.J; return(new TypedValue(leftVal / rightVal)); } else if (CodeFlow.IsIntegerForNumericOp(leftOperand) || CodeFlow.IsIntegerForNumericOp(rightOperand)) { var leftVal = leftConv.ToInt32(CultureInfo.InvariantCulture); var rightVal = rightConv.ToInt32(CultureInfo.InvariantCulture); _exitTypeDescriptor = TypeDescriptor.I; return(new TypedValue(leftVal / rightVal)); } else { var leftVal = leftConv.ToDouble(CultureInfo.InvariantCulture); var rightVal = rightConv.ToDouble(CultureInfo.InvariantCulture); // Unknown Number subtypes -> best guess is double division // Look at need to add support for .NET types not present in Java, e.g. ulong, ushort, byte, uint return(new TypedValue(leftVal / rightVal)); } } return(state.Operate(Operation.DIVIDE, leftOperand, rightOperand)); }
public override ITypedValue GetValueInternal(ExpressionState state) { var leftValue = LeftOperand.GetValueInternal(state).Value; var rightValue = RightOperand.GetValueInternal(state).Value; _leftActualDescriptor = CodeFlow.ToDescriptorFromObject(leftValue); _rightActualDescriptor = CodeFlow.ToDescriptorFromObject(rightValue); return(BooleanTypedValue.ForValue(!EqualityCheck(state.EvaluationContext, leftValue, rightValue))); }
public override ITypedValue GetValueInternal(ExpressionState state) { var leftOperand = LeftOperand.GetValueInternal(state).Value; var rightOperand = RightOperand.GetValueInternal(state).Value; if (IsNumber(leftOperand) && IsNumber(rightOperand)) { var leftNumber = (IConvertible)leftOperand; var rightNumber = (IConvertible)rightOperand; if (leftNumber is decimal || rightNumber is decimal) { var leftVal = leftNumber.ToDecimal(CultureInfo.InvariantCulture); var rightVal = rightNumber.ToDecimal(CultureInfo.InvariantCulture); return(new TypedValue(leftVal % rightVal)); } else if (leftNumber is double || rightNumber is double) { _exitTypeDescriptor = "D"; var leftVal = leftNumber.ToDouble(CultureInfo.InvariantCulture); var rightVal = rightNumber.ToDouble(CultureInfo.InvariantCulture); return(new TypedValue(leftVal % rightVal)); } else if (leftNumber is float || rightNumber is float) { _exitTypeDescriptor = "F"; var leftVal = leftNumber.ToSingle(CultureInfo.InvariantCulture); var rightVal = rightNumber.ToSingle(CultureInfo.InvariantCulture); return(new TypedValue(leftVal % rightVal)); } else if (leftNumber is long || rightNumber is long) { _exitTypeDescriptor = "J"; var leftVal = leftNumber.ToInt64(CultureInfo.InvariantCulture); var rightVal = rightNumber.ToInt64(CultureInfo.InvariantCulture); return(new TypedValue(leftVal % rightVal)); } else if (CodeFlow.IsIntegerForNumericOp(leftNumber) || CodeFlow.IsIntegerForNumericOp(rightNumber)) { _exitTypeDescriptor = "I"; var leftVal = leftNumber.ToInt32(CultureInfo.InvariantCulture); var rightVal = rightNumber.ToInt32(CultureInfo.InvariantCulture); return(new TypedValue(leftVal % rightVal)); } else { // Unknown Number subtypes -> best guess is double division var leftVal = leftNumber.ToDouble(CultureInfo.InvariantCulture); var rightVal = rightNumber.ToDouble(CultureInfo.InvariantCulture); return(new TypedValue(leftVal % rightVal)); } } return(state.Operate(Operation.MODULUS, leftOperand, rightOperand)); }
public override ITypedValue GetValueInternal(ExpressionState state) { var left = LeftOperand.GetValueInternal(state).Value; var right = RightOperand.GetValueInternal(state).Value; _leftActualDescriptor = CodeFlow.ToDescriptorFromObject(left); _rightActualDescriptor = CodeFlow.ToDescriptorFromObject(right); if (IsNumber(left) && IsNumber(right)) { var leftConv = (IConvertible)left; var rightConv = (IConvertible)right; if (left is decimal || right is decimal) { var leftVal = leftConv.ToDecimal(CultureInfo.InvariantCulture); var rightVal = rightConv.ToDecimal(CultureInfo.InvariantCulture); return(BooleanTypedValue.ForValue(leftVal.CompareTo(rightVal) <= 0)); } else if (left is double || right is double) { var leftVal = leftConv.ToDouble(CultureInfo.InvariantCulture); var rightVal = rightConv.ToDouble(CultureInfo.InvariantCulture); return(BooleanTypedValue.ForValue(leftVal <= rightVal)); } else if (left is float || right is float) { var leftVal = leftConv.ToSingle(CultureInfo.InvariantCulture); var rightVal = rightConv.ToSingle(CultureInfo.InvariantCulture); return(BooleanTypedValue.ForValue(leftVal <= rightVal)); } else if (left is long || right is long) { var leftVal = leftConv.ToInt64(CultureInfo.InvariantCulture); var rightVal = rightConv.ToInt64(CultureInfo.InvariantCulture); return(BooleanTypedValue.ForValue(leftVal <= rightVal)); } else if (left is int || right is int) { var leftVal = leftConv.ToInt32(CultureInfo.InvariantCulture); var rightVal = rightConv.ToInt32(CultureInfo.InvariantCulture); return(BooleanTypedValue.ForValue(leftVal <= rightVal)); } else if (left is short || right is short) { var leftVal = leftConv.ToInt16(CultureInfo.InvariantCulture); var rightVal = rightConv.ToInt16(CultureInfo.InvariantCulture); return(BooleanTypedValue.ForValue(leftVal <= rightVal)); } else if (left is byte || right is byte) { var leftVal = leftConv.ToByte(CultureInfo.InvariantCulture); var rightVal = rightConv.ToByte(CultureInfo.InvariantCulture); return(BooleanTypedValue.ForValue(leftVal <= rightVal)); } else if (left is ulong || right is ulong) { var leftVal = leftConv.ToUInt64(CultureInfo.InvariantCulture); var rightVal = rightConv.ToUInt64(CultureInfo.InvariantCulture); return(BooleanTypedValue.ForValue(leftVal <= rightVal)); } else if (left is uint || right is uint) { var leftVal = leftConv.ToUInt32(CultureInfo.InvariantCulture); var rightVal = rightConv.ToUInt32(CultureInfo.InvariantCulture); return(BooleanTypedValue.ForValue(leftVal <= rightVal)); } else if (left is ushort || right is ushort) { var leftVal = leftConv.ToUInt16(CultureInfo.InvariantCulture); var rightVal = rightConv.ToUInt16(CultureInfo.InvariantCulture); return(BooleanTypedValue.ForValue(leftVal <= rightVal)); } else if (left is sbyte || right is sbyte) { var leftVal = leftConv.ToSByte(CultureInfo.InvariantCulture); var rightVal = rightConv.ToSByte(CultureInfo.InvariantCulture); return(BooleanTypedValue.ForValue(leftVal <= rightVal)); } } return(BooleanTypedValue.ForValue(state.TypeComparator.Compare(left, right) <= 0)); }
public override ITypedValue GetValueInternal(ExpressionState state) { var leftOperand = LeftOperand.GetValueInternal(state).Value; var rightOperand = RightOperand.GetValueInternal(state).Value; if (IsNumber(leftOperand) && IsNumber(rightOperand)) { var leftConv = (IConvertible)leftOperand; var rightConv = (IConvertible)rightOperand; if (leftOperand is decimal || rightOperand is decimal) { var leftVal = leftConv.ToDecimal(CultureInfo.InvariantCulture); var rightVal = rightConv.ToDecimal(CultureInfo.InvariantCulture); return(new TypedValue(leftVal / rightVal)); } else if (leftOperand is double || rightOperand is double) { var leftVal = leftConv.ToDouble(CultureInfo.InvariantCulture); var rightVal = rightConv.ToDouble(CultureInfo.InvariantCulture); _exitTypeDescriptor = "D"; return(new TypedValue(leftVal / rightVal)); } else if (leftOperand is float || rightOperand is float) { var leftVal = leftConv.ToSingle(CultureInfo.InvariantCulture); var rightVal = rightConv.ToSingle(CultureInfo.InvariantCulture); _exitTypeDescriptor = "F"; return(new TypedValue(leftVal / rightVal)); } // else if (leftNumber instanceof BigInteger || rightNumber instanceof BigInteger) { // BigInteger leftBigInteger = NumberUtils.convertNumberToTargetClass(leftNumber, BigInteger.class); // BigInteger rightBigInteger = NumberUtils.convertNumberToTargetClass(rightNumber, BigInteger.class); // return new TypedValue(leftBigInteger.divide(rightBigInteger)); // } // TODO: Look at need to add support for .NET types not present in Java, e.g. ulong, ushort, byte, uint else if (leftOperand is long || rightOperand is long) { var leftVal = leftConv.ToInt64(CultureInfo.InvariantCulture); var rightVal = rightConv.ToInt64(CultureInfo.InvariantCulture); _exitTypeDescriptor = "J"; return(new TypedValue(leftVal / rightVal)); } else if (CodeFlow.IsIntegerForNumericOp(leftOperand) || CodeFlow.IsIntegerForNumericOp(rightOperand)) { var leftVal = leftConv.ToInt32(CultureInfo.InvariantCulture); var rightVal = rightConv.ToInt32(CultureInfo.InvariantCulture); _exitTypeDescriptor = "I"; return(new TypedValue(leftVal / rightVal)); } else { var leftVal = leftConv.ToDouble(CultureInfo.InvariantCulture); var rightVal = rightConv.ToDouble(CultureInfo.InvariantCulture); // Unknown Number subtypes -> best guess is double division // TODO: Look at need to add support for .NET types not present in Java, e.g. ulong, ushort, byte, uint return(new TypedValue(leftVal / rightVal)); } } return(state.Operate(Operation.DIVIDE, leftOperand, rightOperand)); }
public override ITypedValue GetValueInternal(ExpressionState state) { var leftOperand = LeftOperand.GetValueInternal(state).Value; var rightOperand = RightOperand.GetValueInternal(state).Value; if (IsNumber(leftOperand) && IsNumber(rightOperand)) { var leftNumber = (IConvertible)leftOperand; var rightNumber = (IConvertible)rightOperand; if (leftNumber is decimal || rightNumber is decimal) { var leftVal = leftNumber.ToDecimal(CultureInfo.InvariantCulture); var rightVal = rightNumber.ToDecimal(CultureInfo.InvariantCulture); return(new TypedValue(leftVal * rightVal)); } else if (leftNumber is double || rightNumber is double) { _exitTypeDescriptor = TypeDescriptor.D; var leftVal = leftNumber.ToDouble(CultureInfo.InvariantCulture); var rightVal = rightNumber.ToDouble(CultureInfo.InvariantCulture); return(new TypedValue(leftVal * rightVal)); } else if (leftNumber is float || rightNumber is float) { _exitTypeDescriptor = TypeDescriptor.F; var leftVal = leftNumber.ToSingle(CultureInfo.InvariantCulture); var rightVal = rightNumber.ToSingle(CultureInfo.InvariantCulture); return(new TypedValue(leftVal * rightVal)); } else if (leftNumber is long || rightNumber is long) { _exitTypeDescriptor = TypeDescriptor.J; var leftVal = leftNumber.ToInt64(CultureInfo.InvariantCulture); var rightVal = rightNumber.ToInt64(CultureInfo.InvariantCulture); return(new TypedValue(leftVal * rightVal)); } else if (CodeFlow.IsIntegerForNumericOp(leftNumber) || CodeFlow.IsIntegerForNumericOp(rightNumber)) { _exitTypeDescriptor = TypeDescriptor.I; var leftVal = leftNumber.ToInt32(CultureInfo.InvariantCulture); var rightVal = rightNumber.ToInt32(CultureInfo.InvariantCulture); return(new TypedValue(leftVal * rightVal)); } else { // Unknown Number subtypes -> best guess is double multiplication var leftVal = leftNumber.ToDouble(CultureInfo.InvariantCulture); var rightVal = rightNumber.ToDouble(CultureInfo.InvariantCulture); return(new TypedValue(leftVal * rightVal)); } } if (leftOperand is string && rightOperand is int integer) { var repeats = integer; var result = new StringBuilder(); for (var i = 0; i < repeats; i++) { result.Append(leftOperand); } return(new TypedValue(result.ToString())); } return(state.Operate(Operation.MULTIPLY, leftOperand, rightOperand)); }