protected final void cast(Class<?> from, Class<?> to) { if (to.isAssignableFrom(from)) { return; } if (from.isPrimitive()) { if (to.isPrimitive()) { castPrimitiveToPrimitive(from, to); } else { Class toPrimitive = convertToPrimitiveType(to); castPrimitiveToPrimitive(convertToPrimitiveType(from), toPrimitive); castFromPrimitive(toPrimitive); } } else { if (to.isPrimitive()) { Class<?> primitiveFrom = convertToPrimitiveType(from); castToPrimitive(primitiveFrom); castPrimitiveToPrimitive(primitiveFrom, to); } else { cast(to); } } }
private void castOrCoercePrimitive(int regNr, Class<?> fromType, Class<?> toType) { if (fromType == toType) { return; } load(regNr); if (toType.isPrimitive()) { castPrimitiveToPrimitive(fromType, toType); } else { Class<?> toTypeAsPrimitive = convertToPrimitiveType(toType); castPrimitiveToPrimitive(fromType, toTypeAsPrimitive); invokeStatic(toType, "valueOf", toType, toTypeAsPrimitive); } store(regNr, toType); }
private Class<?> inferType() { if (isStringConcat()) { return String.class; } if (operator.isBitwiseOperation()) { Class<?> type = left.getType(); return type == long.class || type == Long.class ? long.class : int.class; } if (left.getType().isPrimitive() && left.getType() == right.getType()) { return left.getType(); } if (left.getType() == BigDecimal.class || right.getType() == BigDecimal.class) { return BigDecimal.class; } if (left.getType() == BigInteger.class || right.getType() == BigInteger.class) { return BigInteger.class; } Class<?> primitiveLeft = convertToPrimitiveType(left.getType()); Class<?> primitiveRight = convertToPrimitiveType(right.getType()); return primitiveLeft == primitiveRight ? primitiveLeft : double.class; } }