/** * Test if the {@code sourceType} is convertible to the {@code destType}. * Convertible follows the rules in Java Language Specification, 3rd Ed, s5.3 and means that: * <ul> * <li>{@code sourceType} and {@code destType} are the same type (identity conversion)</li> * <li>For primitive types: that {@code sourceType} can be widened into {@code destType} * or that {@code sourceType} can be boxed into a class assignable to {@code destType}.</li> * <li>For non-primitive types: that the {@code sourceType} can be unboxed into a primitive * that is the same as, or can be widened into, * {@code destType} or {@code sourceType} can be assigned to {@code destType}.</li> * * @return True iff the conditions above are true. */ private boolean isConvertibleToByMethodInvocationConversion(Class<?> sourceType, Class<?> destType) { // Note that class.isAssignableFrom is a widening reference conversion test if (sourceType.isPrimitive()) { return isConvertibleToByIdentityPrimitiveConversion(sourceType, destType) || isConvertibleToByWideningPrimitive(sourceType, destType) || destType.isAssignableFrom(box(sourceType)); } else { // Note that unbox will return null if the sourceType is not a wrapper. // The identity primitive conversion and widening primitive handle this. return isConvertibleToByIdentityPrimitiveConversion(unbox(sourceType), destType) || isConvertibleToByWideningPrimitive(unbox(sourceType), destType) || destType.isAssignableFrom(sourceType); } }
/** * Test if the {@code sourceType} is convertible to the {@code destType}. * Convertible follows the rules in Java Language Specification, 3rd Ed, s5.3 and means that: * <ul> * <li>{@code sourceType} and {@code destType} are the same type (identity conversion)</li> * <li>For primitive types: that {@code sourceType} can be widened into {@code destType} * or that {@code sourceType} can be boxed into a class assignable to {@code destType}.</li> * <li>For non-primitive types: that the {@code sourceType} can be unboxed into a primitive * that is the same as, or can be widened into, * {@code destType} or {@code sourceType} can be assigned to {@code destType}.</li> * * @return True iff the conditions above are true. */ private boolean isConvertibleToByMethodInvocationConversion(Class<?> sourceType, Class<?> destType) { // Note that class.isAssignableFrom is a widening reference conversion test if (sourceType.isPrimitive()) { return isConvertibleToByIdentityPrimitiveConversion(sourceType, destType) || isConvertibleToByWideningPrimitive(sourceType, destType) || destType.isAssignableFrom(box(sourceType)); } else { // Note that unbox will return null if the sourceType is not a wrapper. // The identity primitive conversion and widening primitive handle this. return isConvertibleToByIdentityPrimitiveConversion(unbox(sourceType), destType) || isConvertibleToByWideningPrimitive(unbox(sourceType), destType) || destType.isAssignableFrom(sourceType); } }
/** * Test if the {@code sourceType} is convertible to the {@code destType}. * Convertible follows the rules in Java Language Specification, 3rd Ed, s5.3 and means that: * <ul> * <li>{@code sourceType} and {@code destType} are the same type (identity conversion)</li> * <li>For primitive types: that {@code sourceType} can be widened into {@code destType} * or that {@code sourceType} can be boxed into a class assignable to {@code destType}.</li> * <li>For non-primitive types: that the {@code sourceType} can be unboxed into a primitive * that is the same as, or can be widened into, * {@code destType} or {@code sourceType} can be assigned to {@code destType}.</li> * * @return True iff the conditions above are true. */ private boolean isConvertibleToByMethodInvocationConversion(Class<?> sourceType, Class<?> destType) { // Note that class.isAssignableFrom is a widening reference conversion test if (sourceType.isPrimitive()) { return isConvertibleToByIdentityPrimitiveConversion(sourceType, destType) || isConvertibleToByWideningPrimitive(sourceType, destType) || destType.isAssignableFrom(box(sourceType)); } else { // Note that unbox will return null if the sourceType is not a wrapper. // The identity primitive conversion and widening primitive handle this. return isConvertibleToByIdentityPrimitiveConversion(unbox(sourceType), destType) || isConvertibleToByWideningPrimitive(unbox(sourceType), destType) || destType.isAssignableFrom(sourceType); } }
/** * Test if the {@code sourceType} is convertible to the {@code destType}. * Convertible follows the rules in Java Language Specification, 3rd Ed, s5.3 and means that: * <ul> * <li>{@code sourceType} and {@code destType} are the same type (identity conversion)</li> * <li>For primitive types: that {@code sourceType} can be widened into {@code destType} * or that {@code sourceType} can be boxed into a class assignable to {@code destType}.</li> * <li>For non-primitive types: that the {@code sourceType} can be unboxed into a primitive * that is the same as, or can be widened into, * {@code destType} or {@code sourceType} can be assigned to {@code destType}.</li> * * @return True iff the conditions above are true. */ private boolean isConvertibleToByMethodInvocationConversion(Class<?> sourceType, Class<?> destType) { // Note that class.isAssignableFrom is a widening reference conversion test if (sourceType.isPrimitive()) { return isConvertibleToByIdentityPrimitiveConversion(sourceType, destType) || isConvertibleToByWideningPrimitive(sourceType, destType) || destType.isAssignableFrom(box(sourceType)); } else { // Note that unbox will return null if the sourceType is not a wrapper. // The identity primitive conversion and widening primitive handle this. return isConvertibleToByIdentityPrimitiveConversion(unbox(sourceType), destType) || isConvertibleToByWideningPrimitive(unbox(sourceType), destType) || destType.isAssignableFrom(sourceType); } }