< prev index next >

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

Print this page




1462                     return false;
1463                 }
1464 
1465                 if (t == s || t.qtype == s || s.hasTag(ERROR) || s.hasTag(UNKNOWN)) {
1466                     return true;
1467                 }
1468 
1469                 t.addBound(InferenceBound.EQ, s, Types.this);
1470 
1471                 return true;
1472             }
1473 
1474             @Override
1475             public Boolean visitErrorType(ErrorType t, Type s) {
1476                 return true;
1477             }
1478         };
1479 
1480     // </editor-fold>
1481 













1482     // <editor-fold defaultstate="collapsed" desc="Contains Type">
1483     public boolean containedBy(Type t, Type s) {
1484         switch (t.getTag()) {
1485         case UNDETVAR:
1486             if (s.hasTag(WILDCARD)) {
1487                 UndetVar undetvar = (UndetVar)t;
1488                 WildcardType wt = (WildcardType)s;
1489                 switch(wt.kind) {
1490                     case UNBOUND:
1491                         break;
1492                     case EXTENDS: {
1493                         Type bound = wildUpperBound(s);
1494                         undetvar.addBound(InferenceBound.UPPER, bound, this);
1495                         break;
1496                     }
1497                     case SUPER: {
1498                         Type bound = wildLowerBound(s);
1499                         undetvar.addBound(InferenceBound.LOWER, bound, this);
1500                         break;
1501                     }


5160             }
5161         }
5162 
5163         public void assembleParamsSig(List<Type> typarams) {
5164             append('<');
5165             for (List<Type> ts = typarams; ts.nonEmpty(); ts = ts.tail) {
5166                 Type.TypeVar tvar = (Type.TypeVar) ts.head;
5167                 append(tvar.tsym.name);
5168                 List<Type> bounds = types.getBounds(tvar);
5169                 if ((bounds.head.tsym.flags() & INTERFACE) != 0) {
5170                     append(':');
5171                 }
5172                 for (List<Type> l = bounds; l.nonEmpty(); l = l.tail) {
5173                     append(':');
5174                     assembleSig(l.head);
5175                 }
5176             }
5177             append('>');
5178         }
5179 
5180         private void assembleSig(List<Type> types) {
5181             for (List<Type> ts = types; ts.nonEmpty(); ts = ts.tail) {
5182                 assembleSig(ts.head);
5183             }
5184         }
5185     }
5186 
5187     public Type constantType(LoadableConstant c) {
5188         switch (c.poolTag()) {
5189             case ClassFile.CONSTANT_Class:
5190                 return syms.classType;
5191             case ClassFile.CONSTANT_String:
5192                 return syms.stringType;
5193             case ClassFile.CONSTANT_Integer:
5194                 return syms.intType;
5195             case ClassFile.CONSTANT_Float:
5196                 return syms.floatType;
5197             case ClassFile.CONSTANT_Long:
5198                 return syms.longType;
5199             case ClassFile.CONSTANT_Double:
5200                 return syms.doubleType;


1462                     return false;
1463                 }
1464 
1465                 if (t == s || t.qtype == s || s.hasTag(ERROR) || s.hasTag(UNKNOWN)) {
1466                     return true;
1467                 }
1468 
1469                 t.addBound(InferenceBound.EQ, s, Types.this);
1470 
1471                 return true;
1472             }
1473 
1474             @Override
1475             public Boolean visitErrorType(ErrorType t, Type s) {
1476                 return true;
1477             }
1478         };
1479 
1480     // </editor-fold>
1481 
1482     public List<VarSymbol> recordVars(Type t) {
1483         List<VarSymbol> vars = List.nil();
1484         while (!t.hasTag(NONE)) {
1485             if (t.hasTag(CLASS)) {
1486                 for (Symbol s : t.tsym.members().getSymbols(s -> s.kind == VAR && (s.flags() & RECORD) != 0)) {
1487                     vars = vars.prepend((VarSymbol)s);
1488                 }
1489             }
1490             t = supertype(t);
1491         }
1492         return vars;
1493     }
1494 
1495     // <editor-fold defaultstate="collapsed" desc="Contains Type">
1496     public boolean containedBy(Type t, Type s) {
1497         switch (t.getTag()) {
1498         case UNDETVAR:
1499             if (s.hasTag(WILDCARD)) {
1500                 UndetVar undetvar = (UndetVar)t;
1501                 WildcardType wt = (WildcardType)s;
1502                 switch(wt.kind) {
1503                     case UNBOUND:
1504                         break;
1505                     case EXTENDS: {
1506                         Type bound = wildUpperBound(s);
1507                         undetvar.addBound(InferenceBound.UPPER, bound, this);
1508                         break;
1509                     }
1510                     case SUPER: {
1511                         Type bound = wildLowerBound(s);
1512                         undetvar.addBound(InferenceBound.LOWER, bound, this);
1513                         break;
1514                     }


5173             }
5174         }
5175 
5176         public void assembleParamsSig(List<Type> typarams) {
5177             append('<');
5178             for (List<Type> ts = typarams; ts.nonEmpty(); ts = ts.tail) {
5179                 Type.TypeVar tvar = (Type.TypeVar) ts.head;
5180                 append(tvar.tsym.name);
5181                 List<Type> bounds = types.getBounds(tvar);
5182                 if ((bounds.head.tsym.flags() & INTERFACE) != 0) {
5183                     append(':');
5184                 }
5185                 for (List<Type> l = bounds; l.nonEmpty(); l = l.tail) {
5186                     append(':');
5187                     assembleSig(l.head);
5188                 }
5189             }
5190             append('>');
5191         }
5192 
5193         public void assembleSig(List<Type> types) {
5194             for (List<Type> ts = types; ts.nonEmpty(); ts = ts.tail) {
5195                 assembleSig(ts.head);
5196             }
5197         }
5198     }
5199 
5200     public Type constantType(LoadableConstant c) {
5201         switch (c.poolTag()) {
5202             case ClassFile.CONSTANT_Class:
5203                 return syms.classType;
5204             case ClassFile.CONSTANT_String:
5205                 return syms.stringType;
5206             case ClassFile.CONSTANT_Integer:
5207                 return syms.intType;
5208             case ClassFile.CONSTANT_Float:
5209                 return syms.floatType;
5210             case ClassFile.CONSTANT_Long:
5211                 return syms.longType;
5212             case ClassFile.CONSTANT_Double:
5213                 return syms.doubleType;
< prev index next >