@Test public void testCanBeAssignedTo() { for (PrimitiveTypeUsage ptu : PrimitiveTypeUsage.ALL) { for (UnsignedPrimitiveTypeUsage btu : UnsignedPrimitiveTypeUsage.ALL) { assertFalse(ptu.describe() + " can be assigned to " + btu.describe(), ptu.canBeAssignedTo(btu)); } } assertEquals(true, PrimitiveTypeUsage.BYTE.canBeAssignedTo(object)); assertEquals(false, PrimitiveTypeUsage.BYTE.canBeAssignedTo(string)); assertEquals(false, PrimitiveTypeUsage.BYTE.canBeAssignedTo(PrimitiveTypeUsage.CHAR)); assertEquals(false, PrimitiveTypeUsage.BYTE.canBeAssignedTo(PrimitiveTypeUsage.BOOLEAN)); assertEquals(true, PrimitiveTypeUsage.BYTE.canBeAssignedTo(PrimitiveTypeUsage.BYTE)); assertEquals(true, PrimitiveTypeUsage.BYTE.canBeAssignedTo(PrimitiveTypeUsage.SHORT)); assertEquals(true, PrimitiveTypeUsage.BYTE.canBeAssignedTo(PrimitiveTypeUsage.INT)); assertEquals(true, PrimitiveTypeUsage.BYTE.canBeAssignedTo(PrimitiveTypeUsage.LONG)); assertEquals(false, PrimitiveTypeUsage.BYTE.canBeAssignedTo(PrimitiveTypeUsage.FLOAT)); assertEquals(false, PrimitiveTypeUsage.BYTE.canBeAssignedTo(PrimitiveTypeUsage.DOUBLE)); assertEquals(true, PrimitiveTypeUsage.BYTE.canBeAssignedTo(byteBoxType)); assertEquals(true, PrimitiveTypeUsage.BYTE.canBeAssignedTo(shortBoxType)); assertEquals(true, PrimitiveTypeUsage.BYTE.canBeAssignedTo(integerBoxType)); assertEquals(true, PrimitiveTypeUsage.BYTE.canBeAssignedTo(longBoxType)); assertEquals(true, PrimitiveTypeUsage.SHORT.canBeAssignedTo(object)); assertEquals(false, PrimitiveTypeUsage.SHORT.canBeAssignedTo(string)); assertEquals(false, PrimitiveTypeUsage.SHORT.canBeAssignedTo(PrimitiveTypeUsage.CHAR)); assertEquals(false, PrimitiveTypeUsage.SHORT.canBeAssignedTo(PrimitiveTypeUsage.BOOLEAN)); assertEquals(false, PrimitiveTypeUsage.SHORT.canBeAssignedTo(PrimitiveTypeUsage.BYTE)); assertEquals(true, PrimitiveTypeUsage.SHORT.canBeAssignedTo(PrimitiveTypeUsage.SHORT)); assertEquals(true, PrimitiveTypeUsage.SHORT.canBeAssignedTo(PrimitiveTypeUsage.INT)); assertEquals(true, PrimitiveTypeUsage.SHORT.canBeAssignedTo(PrimitiveTypeUsage.LONG)); assertEquals(false, PrimitiveTypeUsage.SHORT.canBeAssignedTo(PrimitiveTypeUsage.FLOAT)); assertEquals(false, PrimitiveTypeUsage.SHORT.canBeAssignedTo(PrimitiveTypeUsage.DOUBLE)); assertEquals(false, PrimitiveTypeUsage.SHORT.canBeAssignedTo(byteBoxType)); assertEquals(true, PrimitiveTypeUsage.SHORT.canBeAssignedTo(shortBoxType)); assertEquals(true, PrimitiveTypeUsage.SHORT.canBeAssignedTo(integerBoxType)); assertEquals(true, PrimitiveTypeUsage.SHORT.canBeAssignedTo(longBoxType)); assertEquals(true, PrimitiveTypeUsage.INT.canBeAssignedTo(object)); assertEquals(false, PrimitiveTypeUsage.INT.canBeAssignedTo(string)); assertEquals(false, PrimitiveTypeUsage.INT.canBeAssignedTo(PrimitiveTypeUsage.CHAR)); assertEquals(false, PrimitiveTypeUsage.INT.canBeAssignedTo(PrimitiveTypeUsage.BOOLEAN)); assertEquals(false, PrimitiveTypeUsage.INT.canBeAssignedTo(PrimitiveTypeUsage.BYTE)); assertEquals(false, PrimitiveTypeUsage.INT.canBeAssignedTo(PrimitiveTypeUsage.SHORT)); assertEquals(true, PrimitiveTypeUsage.INT.canBeAssignedTo(PrimitiveTypeUsage.INT)); assertEquals(true, PrimitiveTypeUsage.INT.canBeAssignedTo(PrimitiveTypeUsage.LONG)); assertEquals(false, PrimitiveTypeUsage.INT.canBeAssignedTo(PrimitiveTypeUsage.FLOAT)); assertEquals(false, PrimitiveTypeUsage.INT.canBeAssignedTo(PrimitiveTypeUsage.DOUBLE)); assertEquals(false, PrimitiveTypeUsage.INT.canBeAssignedTo(byteBoxType)); assertEquals(false, PrimitiveTypeUsage.INT.canBeAssignedTo(shortBoxType)); assertEquals(true, PrimitiveTypeUsage.INT.canBeAssignedTo(integerBoxType)); assertEquals(true, PrimitiveTypeUsage.INT.canBeAssignedTo(longBoxType)); assertEquals(true, PrimitiveTypeUsage.LONG.canBeAssignedTo(object)); assertEquals(false, PrimitiveTypeUsage.LONG.canBeAssignedTo(string)); assertEquals(false, PrimitiveTypeUsage.LONG.canBeAssignedTo(PrimitiveTypeUsage.CHAR)); assertEquals(false, PrimitiveTypeUsage.LONG.canBeAssignedTo(PrimitiveTypeUsage.BOOLEAN)); assertEquals(false, PrimitiveTypeUsage.LONG.canBeAssignedTo(PrimitiveTypeUsage.BYTE)); assertEquals(false, PrimitiveTypeUsage.LONG.canBeAssignedTo(PrimitiveTypeUsage.SHORT)); assertEquals(false, PrimitiveTypeUsage.LONG.canBeAssignedTo(PrimitiveTypeUsage.INT)); assertEquals(true, PrimitiveTypeUsage.LONG.canBeAssignedTo(PrimitiveTypeUsage.LONG)); assertEquals(false, PrimitiveTypeUsage.LONG.canBeAssignedTo(PrimitiveTypeUsage.FLOAT)); assertEquals(false, PrimitiveTypeUsage.LONG.canBeAssignedTo(PrimitiveTypeUsage.DOUBLE)); assertEquals(false, PrimitiveTypeUsage.LONG.canBeAssignedTo(byteBoxType)); assertEquals(false, PrimitiveTypeUsage.LONG.canBeAssignedTo(shortBoxType)); assertEquals(false, PrimitiveTypeUsage.LONG.canBeAssignedTo(integerBoxType)); assertEquals(true, PrimitiveTypeUsage.LONG.canBeAssignedTo(longBoxType)); assertEquals(true, PrimitiveTypeUsage.FLOAT.canBeAssignedTo(object)); assertEquals(false, PrimitiveTypeUsage.FLOAT.canBeAssignedTo(string)); assertEquals(false, PrimitiveTypeUsage.FLOAT.canBeAssignedTo(PrimitiveTypeUsage.CHAR)); assertEquals(false, PrimitiveTypeUsage.FLOAT.canBeAssignedTo(PrimitiveTypeUsage.BOOLEAN)); assertEquals(false, PrimitiveTypeUsage.FLOAT.canBeAssignedTo(PrimitiveTypeUsage.BYTE)); assertEquals(false, PrimitiveTypeUsage.FLOAT.canBeAssignedTo(PrimitiveTypeUsage.SHORT)); assertEquals(false, PrimitiveTypeUsage.FLOAT.canBeAssignedTo(PrimitiveTypeUsage.INT)); assertEquals(false, PrimitiveTypeUsage.FLOAT.canBeAssignedTo(PrimitiveTypeUsage.LONG)); assertEquals(true, PrimitiveTypeUsage.FLOAT.canBeAssignedTo(PrimitiveTypeUsage.FLOAT)); assertEquals(true, PrimitiveTypeUsage.FLOAT.canBeAssignedTo(PrimitiveTypeUsage.DOUBLE)); assertEquals(true, PrimitiveTypeUsage.FLOAT.canBeAssignedTo(floatBoxType)); assertEquals(true, PrimitiveTypeUsage.FLOAT.canBeAssignedTo(doubleBoxType)); assertEquals(true, PrimitiveTypeUsage.DOUBLE.canBeAssignedTo(object)); assertEquals(false, PrimitiveTypeUsage.DOUBLE.canBeAssignedTo(string)); assertEquals(false, PrimitiveTypeUsage.DOUBLE.canBeAssignedTo(PrimitiveTypeUsage.CHAR)); assertEquals(false, PrimitiveTypeUsage.DOUBLE.canBeAssignedTo(PrimitiveTypeUsage.BOOLEAN)); assertEquals(false, PrimitiveTypeUsage.DOUBLE.canBeAssignedTo(PrimitiveTypeUsage.BYTE)); assertEquals(false, PrimitiveTypeUsage.DOUBLE.canBeAssignedTo(PrimitiveTypeUsage.SHORT)); assertEquals(false, PrimitiveTypeUsage.DOUBLE.canBeAssignedTo(PrimitiveTypeUsage.INT)); assertEquals(false, PrimitiveTypeUsage.DOUBLE.canBeAssignedTo(PrimitiveTypeUsage.LONG)); assertEquals(false, PrimitiveTypeUsage.DOUBLE.canBeAssignedTo(PrimitiveTypeUsage.FLOAT)); assertEquals(true, PrimitiveTypeUsage.DOUBLE.canBeAssignedTo(PrimitiveTypeUsage.DOUBLE)); assertEquals(false, PrimitiveTypeUsage.DOUBLE.canBeAssignedTo(floatBoxType)); assertEquals(true, PrimitiveTypeUsage.DOUBLE.canBeAssignedTo(doubleBoxType)); }
@Override public boolean canBeAssignedTo(TypeUsage other) { if (isBoxType(other) || isObject(other)) { return true; } if (!other.isPrimitive()) { return false; } if (other instanceof UnsignedPrimitiveTypeUsage) { return false; } if (promotionsTypes.contains(other)) { return true; } return jvmType().equals(other.jvmType()); }
PrimitiveTypeUsage implements TypeUsage { @Override public boolean canBeAssignedTo(TypeUsage other) { if (isBoxType(other) || isObject(other)) { return true; } if (!other.isPrimitive()) { return false; } if (other instanceof UnsignedPrimitiveTypeUsage) { return false; } if (promotionsTypes.contains(other)) { return true; } return jvmType().equals(other.jvmType()); } }
PrimitiveTypeUsage implements TypeUsage { @Override public boolean canBeAssignedTo(TypeUsage other) { if (isBoxType(other) || isObject(other)) { return true; } if (!other.isPrimitive()) { return false; } if (other instanceof UnsignedPrimitiveTypeUsage) { return false; } if (promotionsTypes.contains(other)) { return true; } return jvmType().equals(other.jvmType()); } private  PrimitiveTypeUsage(String name, JvmType jvmType, Class<?> boxTypeClazz, List<PrimitiveTypeUsage> promotionsTypes); private  PrimitiveTypeUsage(String name, JvmType jvmType, Class<?> boxTypeClazz); }
PrimitiveTypeUsage implements TypeUsage { @Override public boolean canBeAssignedTo(TypeUsage other) { if (isBoxType(other) || isObject(other)) { return true; } if (!other.isPrimitive()) { return false; } if (other instanceof UnsignedPrimitiveTypeUsage) { return false; } if (promotionsTypes.contains(other)) { return true; } return jvmType().equals(other.jvmType()); } private  PrimitiveTypeUsage(String name, JvmType jvmType, Class<?> boxTypeClazz, List<PrimitiveTypeUsage> promotionsTypes); private  PrimitiveTypeUsage(String name, JvmType jvmType, Class<?> boxTypeClazz); @Override boolean isPrimitive(); @Override TypeUsage replaceTypeVariables(Map<String, T> typeParams); @Override boolean canBeAssignedTo(TypeUsage other); static Optional<PrimitiveTypeUsage> findByJvmType(JvmType jvmType); TypeUsage getBoxType(SymbolResolver resolver); @Override JvmType jvmType(); String turinName(); static PrimitiveTypeUsage getByName(String name); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); static boolean isPrimitiveTypeName(String typeName); @Override PrimitiveTypeUsage asPrimitiveTypeUsage(); boolean isLong(); boolean isFloat(); boolean isDouble(); boolean isStoredInInt(); boolean isInt(); boolean isShort(); boolean isChar(); boolean isByte(); boolean isBoolean(); String getName(); @Override String describe(); @Override boolean sameType(TypeUsage other); @Override boolean hasInstanceField(String fieldName, Symbol instance); @Override Symbol getInstanceField(String fieldName, Symbol instance); @Override Optional<Invokable> getMethod(String method, boolean staticContext); }
PrimitiveTypeUsage implements TypeUsage { @Override public boolean canBeAssignedTo(TypeUsage other) { if (isBoxType(other) || isObject(other)) { return true; } if (!other.isPrimitive()) { return false; } if (other instanceof UnsignedPrimitiveTypeUsage) { return false; } if (promotionsTypes.contains(other)) { return true; } return jvmType().equals(other.jvmType()); } private  PrimitiveTypeUsage(String name, JvmType jvmType, Class<?> boxTypeClazz, List<PrimitiveTypeUsage> promotionsTypes); private  PrimitiveTypeUsage(String name, JvmType jvmType, Class<?> boxTypeClazz); @Override boolean isPrimitive(); @Override TypeUsage replaceTypeVariables(Map<String, T> typeParams); @Override boolean canBeAssignedTo(TypeUsage other); static Optional<PrimitiveTypeUsage> findByJvmType(JvmType jvmType); TypeUsage getBoxType(SymbolResolver resolver); @Override JvmType jvmType(); String turinName(); static PrimitiveTypeUsage getByName(String name); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); static boolean isPrimitiveTypeName(String typeName); @Override PrimitiveTypeUsage asPrimitiveTypeUsage(); boolean isLong(); boolean isFloat(); boolean isDouble(); boolean isStoredInInt(); boolean isInt(); boolean isShort(); boolean isChar(); boolean isByte(); boolean isBoolean(); String getName(); @Override String describe(); @Override boolean sameType(TypeUsage other); @Override boolean hasInstanceField(String fieldName, Symbol instance); @Override Symbol getInstanceField(String fieldName, Symbol instance); @Override Optional<Invokable> getMethod(String method, boolean staticContext); static PrimitiveTypeUsage BOOLEAN; static PrimitiveTypeUsage CHAR; static PrimitiveTypeUsage LONG; static PrimitiveTypeUsage INT; static PrimitiveTypeUsage SHORT; static PrimitiveTypeUsage BYTE; static PrimitiveTypeUsage DOUBLE; static PrimitiveTypeUsage FLOAT; static List<PrimitiveTypeUsage> ALL; }