< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java

Print this page

1676             }
1677             // if both are classes or both are interfaces, shortcut
1678             if (ts.isInterface() == ss.isInterface() && isSubtype(erasure(ss.type), erasure(ts.type))) {
1679                 return false;
1680             }
1681             if (ts.isInterface() && !ss.isInterface()) {
1682                 /* so ts is interface but ss is a class
1683                  * an interface is disjoint from a class if the class is disjoint form the interface
1684                  */
1685                 return areDisjoint(ss, ts);
1686             }
1687             // a final class that is not subtype of ss is disjoint
1688             if (!ts.isInterface() && ts.isFinal()) {
1689                 return true;
1690             }
1691             // if at least one is sealed
1692             if (ts.isSealed() || ss.isSealed()) {
1693                 // permitted subtypes have to be disjoint with the other symbol
1694                 ClassSymbol sealedOne = ts.isSealed() ? ts : ss;
1695                 ClassSymbol other = sealedOne == ts ? ss : ts;
1696                 return sealedOne.permitted.stream().allMatch(sym -> areDisjoint((ClassSymbol)sym, other));
1697             }
1698             return false;
1699         }
1700 
1701         private TypeRelation isCastable = new TypeRelation() {
1702 
1703             public Boolean visitType(Type t, Type s) {
1704                 if (s.hasTag(ERROR) || t.hasTag(NONE))
1705                     return true;
1706 
1707                 switch (t.getTag()) {
1708                 case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT:
1709                 case DOUBLE:
1710                     return s.isNumeric();
1711                 case BOOLEAN:
1712                     return s.hasTag(BOOLEAN);
1713                 case VOID:
1714                     return false;
1715                 case BOT:
1716                     return isSubtype(t, s);

1676             }
1677             // if both are classes or both are interfaces, shortcut
1678             if (ts.isInterface() == ss.isInterface() && isSubtype(erasure(ss.type), erasure(ts.type))) {
1679                 return false;
1680             }
1681             if (ts.isInterface() && !ss.isInterface()) {
1682                 /* so ts is interface but ss is a class
1683                  * an interface is disjoint from a class if the class is disjoint form the interface
1684                  */
1685                 return areDisjoint(ss, ts);
1686             }
1687             // a final class that is not subtype of ss is disjoint
1688             if (!ts.isInterface() && ts.isFinal()) {
1689                 return true;
1690             }
1691             // if at least one is sealed
1692             if (ts.isSealed() || ss.isSealed()) {
1693                 // permitted subtypes have to be disjoint with the other symbol
1694                 ClassSymbol sealedOne = ts.isSealed() ? ts : ss;
1695                 ClassSymbol other = sealedOne == ts ? ss : ts;
1696                 return sealedOne.getPermittedSubclasses().stream().allMatch(type -> areDisjoint((ClassSymbol)type.tsym, other));
1697             }
1698             return false;
1699         }
1700 
1701         private TypeRelation isCastable = new TypeRelation() {
1702 
1703             public Boolean visitType(Type t, Type s) {
1704                 if (s.hasTag(ERROR) || t.hasTag(NONE))
1705                     return true;
1706 
1707                 switch (t.getTag()) {
1708                 case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT:
1709                 case DOUBLE:
1710                     return s.isNumeric();
1711                 case BOOLEAN:
1712                     return s.hasTag(BOOLEAN);
1713                 case VOID:
1714                     return false;
1715                 case BOT:
1716                     return isSubtype(t, s);
< prev index next >