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? Any primitive == 1322 * primitive or primitive == object comparisons here are an error. 1323 * Unboxing and correct primitive == primitive comparisons are 1324 * already dealt with in Attr.visitBinary. 1325 * 1326 */ 1327 public boolean isEqualityComparable(Type s, Type t, Warner warn) { 1328 if (t.isNumeric() && s.isNumeric()) 1329 return true; 1330 1331 boolean tPrimitive = t.isPrimitive(); 1332 boolean sPrimitive = s.isPrimitive(); 1333 if (!tPrimitive && !sPrimitive) { 1334 return isCastable(s, t, warn) || isCastable(t, s, warn); 1335 } else { 1336 return false; 1337 } 1338 } 1339 1340 // <editor-fold defaultstate="collapsed" desc="isCastable"> 1341 public boolean isCastable(Type t, Type s) { 1342 return isCastable(t, s, noWarnings); 1343 } 1344 1345 /** 1346 * Is t is castable to s?<br> 1347 * s is assumed to be an erased type.<br> 1348 * (not defined for Method and ForAll types). 1349 */ 1350 public boolean isCastable(Type t, Type s, Warner warn) { 1351 if (t == s) 1352 return true; 1353 1354 if (t.isPrimitive() != s.isPrimitive()) 1355 return allowBoxing && ( 1356 isConvertible(t, s, warn) 1357 || (allowObjectToPrimitiveCast && 1358 s.isPrimitive() && 1359 isSubtype(boxedClass(s).type, t))); |