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 private boolean checkUnbox(Type t, Type s) { 1322 if (t == syms.numberType) 1323 return s.isNumeric(); 1324 else 1325 return isSubtype(unboxedType(t), s); 1326 } 1327 /** 1328 * Can t and s be compared for equality? 1329 * 1330 */ 1331 public boolean isEqualityComparable(Type t, Type s, Warner warn) { 1332 if (t.tag == ERROR) 1333 return true; 1334 boolean tPrimitive = t.isPrimitive(); 1335 boolean sPrimitive = s.isPrimitive(); 1336 if (tPrimitive && sPrimitive) { 1337 return isSubtypeUnchecked(t, s, warn); 1338 } else if (!tPrimitive && !sPrimitive) 1339 return isCastable(t, s, warn); 1340 else if (allowBoxing) { 1341 if (tPrimitive) { 1342 return checkUnbox(s, t); 1343 } else { 1344 return checkUnbox(t, s); 1345 } 1346 } else 1347 return false; 1348 } 1349 1350 // <editor-fold defaultstate="collapsed" desc="isCastable"> 1351 public boolean isCastable(Type t, Type s) { 1352 return isCastable(t, s, noWarnings); 1353 } 1354 1355 /** 1356 * Is t is castable to s?<br> 1357 * s is assumed to be an erased type.<br> 1358 * (not defined for Method and ForAll types). 1359 */ 1360 public boolean isCastable(Type t, Type s, Warner warn) { 1361 if (t == s) 1362 return true; 1363 1364 if (t.isPrimitive() != s.isPrimitive()) 1365 return allowBoxing && ( 1366 isConvertible(t, s, warn) 1367 || (allowObjectToPrimitiveCast && 1368 s.isPrimitive() && 1369 isSubtype(boxedClass(s).type, t))); |