1300 return isSameWildcard(t, ((CapturedType)s.unannotatedType()).wildcard); 1301 } 1302 1303 public boolean isSameWildcard(WildcardType t, Type s) { 1304 if (s.tag != WILDCARD) 1305 return false; 1306 WildcardType w = (WildcardType)s.unannotatedType(); 1307 return w.kind == t.kind && w.type == t.type; 1308 } 1309 1310 public boolean containsTypeEquivalent(List<Type> ts, List<Type> ss) { 1311 while (ts.nonEmpty() && ss.nonEmpty() 1312 && containsTypeEquivalent(ts.head, ss.head)) { 1313 ts = ts.tail; 1314 ss = ss.tail; 1315 } 1316 return ts.isEmpty() && ss.isEmpty(); 1317 } 1318 // </editor-fold> 1319 1320 // <editor-fold defaultstate="collapsed" desc="isCastable"> 1321 public boolean isCastable(Type t, Type s) { 1322 return isCastable(t, s, noWarnings); 1323 } 1324 1325 /** 1326 * Is t is castable to s?<br> 1327 * s is assumed to be an erased type.<br> 1328 * (not defined for Method and ForAll types). 1329 */ 1330 public boolean isCastable(Type t, Type s, Warner warn) { 1331 if (t == s) 1332 return true; 1333 1334 if (t.isPrimitive() != s.isPrimitive()) 1335 return allowBoxing && ( 1336 isConvertible(t, s, warn) 1337 || (allowObjectToPrimitiveCast && 1338 s.isPrimitive() && 1339 isSubtype(boxedClass(s).type, t))); | 1300 return isSameWildcard(t, ((CapturedType)s.unannotatedType()).wildcard); 1301 } 1302 1303 public boolean isSameWildcard(WildcardType t, Type s) { 1304 if (s.tag != WILDCARD) 1305 return false; 1306 WildcardType w = (WildcardType)s.unannotatedType(); 1307 return w.kind == t.kind && w.type == t.type; 1308 } 1309 1310 public boolean containsTypeEquivalent(List<Type> ts, List<Type> ss) { 1311 while (ts.nonEmpty() && ss.nonEmpty() 1312 && containsTypeEquivalent(ts.head, ss.head)) { 1313 ts = ts.tail; 1314 ss = ss.tail; 1315 } 1316 return ts.isEmpty() && ss.isEmpty(); 1317 } 1318 // </editor-fold> 1319 1320 /** 1321 * Can t and s be compared for equality? 1322 * 1323 */ 1324 public boolean isEqualityComparable(Type s, Type t, Warner warn) { 1325 boolean tPrimitive = t.isPrimitive(); 1326 boolean sPrimitive = s.isPrimitive(); 1327 if (tPrimitive && sPrimitive) { 1328 if (allowBoxing) { 1329 s = unboxedTypeOrType(s); 1330 t = unboxedTypeOrType(t); 1331 } 1332 return isSubtype(s, t) || isSubtype(t, s); 1333 } else if (!tPrimitive && !sPrimitive) { 1334 return isCastable(s, t, warn) || isCastable(t, s, warn); 1335 } else 1336 return false; 1337 } 1338 1339 // <editor-fold defaultstate="collapsed" desc="isCastable"> 1340 public boolean isCastable(Type t, Type s) { 1341 return isCastable(t, s, noWarnings); 1342 } 1343 1344 /** 1345 * Is t is castable to s?<br> 1346 * s is assumed to be an erased type.<br> 1347 * (not defined for Method and ForAll types). 1348 */ 1349 public boolean isCastable(Type t, Type s, Warner warn) { 1350 if (t == s) 1351 return true; 1352 1353 if (t.isPrimitive() != s.isPrimitive()) 1354 return allowBoxing && ( 1355 isConvertible(t, s, warn) 1356 || (allowObjectToPrimitiveCast && 1357 s.isPrimitive() && 1358 isSubtype(boxedClass(s).type, t))); |