1281 return isSameWildcard(t, ((CapturedType)s).wildcard); 1282 } 1283 1284 public boolean isSameWildcard(WildcardType t, Type s) { 1285 if (s.tag != WILDCARD) 1286 return false; 1287 WildcardType w = (WildcardType)s; 1288 return w.kind == t.kind && w.type == t.type; 1289 } 1290 1291 public boolean containsTypeEquivalent(List<Type> ts, List<Type> ss) { 1292 while (ts.nonEmpty() && ss.nonEmpty() 1293 && containsTypeEquivalent(ts.head, ss.head)) { 1294 ts = ts.tail; 1295 ss = ss.tail; 1296 } 1297 return ts.isEmpty() && ss.isEmpty(); 1298 } 1299 // </editor-fold> 1300 1301 // <editor-fold defaultstate="collapsed" desc="isCastable"> 1302 public boolean isCastable(Type t, Type s) { 1303 return isCastable(t, s, noWarnings); 1304 } 1305 1306 /** 1307 * Is t is castable to s?<br> 1308 * s is assumed to be an erased type.<br> 1309 * (not defined for Method and ForAll types). 1310 */ 1311 public boolean isCastable(Type t, Type s, Warner warn) { 1312 if (t == s) 1313 return true; 1314 1315 if (t.isPrimitive() != s.isPrimitive()) 1316 return allowBoxing && ( 1317 isConvertible(t, s, warn) 1318 || (allowObjectToPrimitiveCast && 1319 s.isPrimitive() && 1320 isSubtype(boxedClass(s).type, t))); | 1281 return isSameWildcard(t, ((CapturedType)s).wildcard); 1282 } 1283 1284 public boolean isSameWildcard(WildcardType t, Type s) { 1285 if (s.tag != WILDCARD) 1286 return false; 1287 WildcardType w = (WildcardType)s; 1288 return w.kind == t.kind && w.type == t.type; 1289 } 1290 1291 public boolean containsTypeEquivalent(List<Type> ts, List<Type> ss) { 1292 while (ts.nonEmpty() && ss.nonEmpty() 1293 && containsTypeEquivalent(ts.head, ss.head)) { 1294 ts = ts.tail; 1295 ss = ss.tail; 1296 } 1297 return ts.isEmpty() && ss.isEmpty(); 1298 } 1299 // </editor-fold> 1300 1301 /** 1302 * Can t and s be compared for equality? 1303 * 1304 */ 1305 public boolean isEqualityComparable(Type t, Type s, Warner warn) { 1306 if (t.tag == ERROR) 1307 return true; 1308 boolean tPrimitive = t.isPrimitive(); 1309 boolean sPrimitive = s.isPrimitive(); 1310 if (tPrimitive && sPrimitive) { 1311 return isSubtypeUnchecked(t, s, warn); 1312 } else if (!tPrimitive && !sPrimitive) 1313 return isCastable(t, s, warn); 1314 else if (allowBoxing) { 1315 return tPrimitive 1316 ? isSubtype(unboxedType(s), t) 1317 : isSubtype(unboxedType(t), s); 1318 } else 1319 return false; 1320 } 1321 1322 // <editor-fold defaultstate="collapsed" desc="isCastable"> 1323 public boolean isCastable(Type t, Type s) { 1324 return isCastable(t, s, noWarnings); 1325 } 1326 1327 /** 1328 * Is t is castable to s?<br> 1329 * s is assumed to be an erased type.<br> 1330 * (not defined for Method and ForAll types). 1331 */ 1332 public boolean isCastable(Type t, Type s, Warner warn) { 1333 if (t == s) 1334 return true; 1335 1336 if (t.isPrimitive() != s.isPrimitive()) 1337 return allowBoxing && ( 1338 isConvertible(t, s, warn) 1339 || (allowObjectToPrimitiveCast && 1340 s.isPrimitive() && 1341 isSubtype(boxedClass(s).type, t))); |