< prev index next >

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

Print this page




  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.code;
  27 
  28 import java.lang.annotation.Annotation;
  29 import java.util.ArrayDeque;
  30 import java.util.Collections;
  31 import java.util.EnumMap;
  32 import java.util.Map;
  33 
  34 import javax.lang.model.type.*;
  35 
  36 import com.sun.tools.javac.code.Symbol.*;
  37 import com.sun.tools.javac.code.TypeMetadata.Entry;
  38 import com.sun.tools.javac.code.Types.TypeMapping;
  39 import com.sun.tools.javac.code.Types.UniqueType;
  40 import com.sun.tools.javac.comp.Infer.IncorporationAction;
  41 import com.sun.tools.javac.jvm.ClassFile;
  42 import com.sun.tools.javac.jvm.PoolConstant;
  43 import com.sun.tools.javac.util.*;
  44 import com.sun.tools.javac.util.DefinedBy.Api;
  45 
  46 import static com.sun.tools.javac.code.BoundKind.*;
  47 import static com.sun.tools.javac.code.Flags.*;
  48 import static com.sun.tools.javac.code.Kinds.Kind.*;
  49 import static com.sun.tools.javac.code.TypeTag.*;
  50 
  51 /** This class represents Java types. The class itself defines the behavior of
  52  *  the following types:
  53  *  <pre>
  54  *  base types (tags: BYTE, CHAR, SHORT, INT, LONG, FLOAT, DOUBLE, BOOLEAN),
  55  *  type `void' (tag: VOID),
  56  *  the bottom type (tag: BOT),
  57  *  the missing type (tag: NONE).
  58  *  </pre>
  59  *  <p>The behavior of the following types is defined in subclasses, which are
  60  *  all static inner classes of this class:
  61  *  <pre>
  62  *  class types (tag: CLASS, class: ClassType),
  63  *  array types (tag: ARRAY, class: ArrayType),
  64  *  method types (tag: METHOD, class: MethodType),
  65  *  package types (tag: PACKAGE, class: PackageType),
  66  *  type variables (tag: TYPEVAR, class: TypeVar),
  67  *  type arguments (tag: WILDCARD, class: WildcardType),
  68  *  generic method types (tag: FORALL, class: ForAll),
  69  *  the error type (tag: ERROR, class: ErrorType).
  70  *  </pre>
  71  *
  72  *  <p><b>This is NOT part of any supported API.
  73  *  If you write code that depends on this, you do so at your own risk.
  74  *  This code and its internal interfaces are subject to change or
  75  *  deletion without notice.</b>
  76  *
  77  *  @see TypeTag
  78  */
  79 public abstract class Type extends AnnoConstruct implements TypeMirror, PoolConstant {
  80 
  81     /**
  82      * Type metadata,  Should be {@code null} for the default value.
  83      *
  84      * Note: it is an invariant that for any {@code TypeMetadata}
  85      * class, a given {@code Type} may have at most one metadata array
  86      * entry of that class.
  87      */
  88     protected final TypeMetadata metadata;
  89 
  90     public TypeMetadata getMetadata() {
  91         return metadata;
  92     }
  93 
  94     public Entry getMetadataOfKind(final Entry.Kind kind) {
  95         return metadata != null ? metadata.get(kind) : null;
  96     }
  97 
  98     /** Constant type: no type at all. */
  99     public static final JCNoType noType = new JCNoType() {


 111         }
 112     };
 113 
 114     /** Constant type: special type to be used for marking stuck trees. */
 115     public static final JCNoType stuckType = new JCNoType() {
 116         @Override @DefinedBy(Api.LANGUAGE_MODEL)
 117         public String toString() {
 118             return "stuck";
 119         }
 120     };
 121 
 122     /** If this switch is turned on, the names of type variables
 123      *  and anonymous classes are printed with hashcodes appended.
 124      */
 125     public static boolean moreInfo = false;
 126 
 127     /** The defining class / interface / package / type variable.
 128      */
 129     public TypeSymbol tsym;
 130 
 131     @Override
 132     public int poolTag() {
 133         throw new AssertionError("Invalid pool entry");
 134     }
 135 
 136     @Override
 137     public Object poolKey(Types types) {
 138         return new UniqueType(this, types);
 139     }
 140 
 141     /**
 142      * Checks if the current type tag is equal to the given tag.
 143      * @return true if tag is equal to the current type tag.
 144      */
 145     public boolean hasTag(TypeTag tag) {
 146         return tag == getTag();
 147     }
 148 
 149     /**
 150      * Returns the current type tag.
 151      * @return the value of the current type tag.
 152      */
 153     public abstract TypeTag getTag();
 154 
 155     public boolean isNumeric() {
 156         return false;
 157     }
 158 
 159     public boolean isIntegral() {
 160         return false;


 173     }
 174 
 175     public boolean isNullOrReference() {
 176         return false;
 177     }
 178 
 179     public boolean isPartial() {
 180         return false;
 181     }
 182 
 183     /**
 184      * The constant value of this type, null if this type does not
 185      * have a constant value attribute. Only primitive types and
 186      * strings (ClassType) can have a constant value attribute.
 187      * @return the constant value attribute of this type
 188      */
 189     public Object constValue() {
 190         return null;
 191     }
 192 
 193     /** Is this a constant type whose value is false?
 194      */
 195     public boolean isFalse() {
 196         return false;
 197     }
 198 
 199     /** Is this a constant type whose value is true?
 200      */
 201     public boolean isTrue() {
 202         return false;
 203     }
 204 
 205     /**
 206      * Get the representation of this type used for modelling purposes.
 207      * By default, this is itself. For ErrorType, a different value
 208      * may be provided.
 209      */
 210     public Type getModelType() {
 211         return this;
 212     }
 213 
 214     public static List<Type> getModelTypes(List<Type> ts) {
 215         ListBuffer<Type> lb = new ListBuffer<>();
 216         for (Type t: ts)
 217             lb.append(t.getModelType());
 218         return lb.toList();
 219     }
 220 
 221     /**For ErrorType, returns the original type, otherwise returns the type itself.
 222      */
 223     public Type getOriginalType() {
 224         return this;


 476     }
 477 
 478     /**
 479      * The Java source which this type list represents.  A List is
 480      * represented as a comma-spearated listing of the elements in
 481      * that list.
 482      */
 483     public static String toString(List<Type> ts) {
 484         if (ts.isEmpty()) {
 485             return "";
 486         } else {
 487             StringBuilder buf = new StringBuilder();
 488             buf.append(ts.head.toString());
 489             for (List<Type> l = ts.tail; l.nonEmpty(); l = l.tail)
 490                 buf.append(",").append(l.head.toString());
 491             return buf.toString();
 492         }
 493     }
 494 
 495     /**
 496      * The constant value of this type, converted to String
 497      */
 498     public String stringValue() {
 499         Object cv = Assert.checkNonNull(constValue());
 500         return cv.toString();
 501     }
 502 
 503     /**
 504      * Override this method with care. For most Type instances this should behave as ==.
 505      */
 506     @Override @DefinedBy(Api.LANGUAGE_MODEL)
 507     public boolean equals(Object t) {
 508         return this == t;
 509     }
 510 
 511     public boolean equalsIgnoreMetadata(Type t) {
 512         return typeNoMetadata().equals(t.typeNoMetadata());
 513     }
 514 
 515     @Override @DefinedBy(Api.LANGUAGE_MODEL)
 516     public int hashCode() {
 517         return super.hashCode();
 518     }
 519 
 520     public String argtypes(boolean varargs) {
 521         List<Type> args = getParameterTypes();
 522         if (!varargs) return args.toString();
 523         StringBuilder buf = new StringBuilder();


 739         }
 740 
 741         /** Define a constant type, of the same kind as this type
 742          *  and with given constant value
 743          */
 744         @Override
 745         public Type constType(Object constValue) {
 746             final Object value = constValue;
 747             return new JCPrimitiveType(tag, tsym, metadata) {
 748                     @Override
 749                     public Object constValue() {
 750                         return value;
 751                     }
 752                     @Override
 753                     public Type baseType() {
 754                         return tsym.type;
 755                     }
 756                 };
 757         }
 758 
 759         /**
 760          * The constant value of this type, converted to String
 761          */
 762         @Override
 763         public String stringValue() {
 764             Object cv = Assert.checkNonNull(constValue());
 765             if (tag == BOOLEAN) {
 766                 return ((Integer) cv).intValue() == 0 ? "false" : "true";
 767             }
 768             else if (tag == CHAR) {
 769                 return String.valueOf((char) ((Integer) cv).intValue());
 770             }
 771             else {
 772                 return cv.toString();
 773             }
 774         }
 775 
 776         /** Is this a constant type whose value is false?
 777          */
 778         @Override
 779         public boolean isFalse() {
 780             return
 781                 tag == BOOLEAN &&
 782                 constValue() != null &&
 783                 ((Integer)constValue()).intValue() == 0;
 784         }
 785 
 786         /** Is this a constant type whose value is true?
 787          */
 788         @Override
 789         public boolean isTrue() {
 790             return
 791                 tag == BOOLEAN &&
 792                 constValue() != null &&
 793                 ((Integer)constValue()).intValue() != 0;
 794         }
 795 
 796         @Override @DefinedBy(Api.LANGUAGE_MODEL)
 797         public <R, P> R accept(TypeVisitor<R, P> v, P p) {
 798             return v.visitPrimitive(this, p);
 799         }
 800 
 801         @Override @DefinedBy(Api.LANGUAGE_MODEL)
 802         public TypeKind getKind() {
 803             switch (tag) {
 804                 case BYTE:      return TypeKind.BYTE;
 805                 case CHAR:      return TypeKind.CHAR;
 806                 case SHORT:     return TypeKind.SHORT;
 807                 case INT:       return TypeKind.INT;
 808                 case LONG:      return TypeKind.LONG;
 809                 case FLOAT:     return TypeKind.FLOAT;
 810                 case DOUBLE:    return TypeKind.DOUBLE;
 811                 case BOOLEAN:   return TypeKind.BOOLEAN;
 812             }
 813             throw new AssertionError();
 814         }
 815 


 926 
 927         @DefinedBy(Api.LANGUAGE_MODEL)
 928         public Type getSuperBound() {
 929             if (kind == SUPER)
 930                 return type;
 931             else
 932                 return null;
 933         }
 934 
 935         @DefinedBy(Api.LANGUAGE_MODEL)
 936         public TypeKind getKind() {
 937             return TypeKind.WILDCARD;
 938         }
 939 
 940         @DefinedBy(Api.LANGUAGE_MODEL)
 941         public <R, P> R accept(TypeVisitor<R, P> v, P p) {
 942             return v.visitWildcard(this, p);
 943         }
 944     }
 945 
 946     public static class ClassType extends Type implements DeclaredType, LoadableConstant,
 947                                                           javax.lang.model.type.ErrorType {
 948 
 949         /** The enclosing type of this type. If this is the type of an inner
 950          *  class, outer_field refers to the type of its enclosing
 951          *  instance class, in all other cases it refers to noType.
 952          */
 953         private Type outer_field;
 954 
 955         /** The type parameters of this type (to be set once class is loaded).
 956          */
 957         public List<Type> typarams_field;
 958 
 959         /** A cache variable for the type parameters of this type,
 960          *  appended to all parameters of its enclosing class.
 961          *  @see #allparams
 962          */
 963         public List<Type> allparams_field;
 964 
 965         /** The supertype of this class (to be set once class is loaded).
 966          */


 971         public List<Type> interfaces_field;
 972 
 973         /** All the interfaces of this class, including missing ones.
 974          */
 975         public List<Type> all_interfaces_field;
 976 
 977         public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) {
 978             this(outer, typarams, tsym, TypeMetadata.EMPTY);
 979         }
 980 
 981         public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym,
 982                          TypeMetadata metadata) {
 983             super(tsym, metadata);
 984             this.outer_field = outer;
 985             this.typarams_field = typarams;
 986             this.allparams_field = null;
 987             this.supertype_field = null;
 988             this.interfaces_field = null;
 989         }
 990 
 991         public int poolTag() {
 992             return ClassFile.CONSTANT_Class;
 993         }
 994 
 995         @Override
 996         public ClassType cloneWithMetadata(TypeMetadata md) {
 997             return new ClassType(outer_field, typarams_field, tsym, md) {
 998                 @Override
 999                 public Type baseType() { return ClassType.this.baseType(); }
1000             };
1001         }
1002 
1003         @Override
1004         public TypeTag getTag() {
1005             return CLASS;
1006         }
1007 
1008         @Override
1009         public <R,S> R accept(Type.Visitor<R,S> v, S s) {
1010             return v.visitClassType(this, s);
1011         }
1012 
1013         public Type constType(Object constValue) {
1014             final Object value = constValue;


1277         }
1278 
1279         public List<Type> getExplicitComponents() {
1280             return allInterfaces ?
1281                     interfaces_field :
1282                     getComponents();
1283         }
1284 
1285         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1286         public TypeKind getKind() {
1287             return TypeKind.INTERSECTION;
1288         }
1289 
1290         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1291         public <R, P> R accept(TypeVisitor<R, P> v, P p) {
1292             return v.visitIntersection(this, p);
1293         }
1294     }
1295 
1296     public static class ArrayType extends Type
1297             implements LoadableConstant, javax.lang.model.type.ArrayType {
1298 
1299         public Type elemtype;
1300 
1301         public ArrayType(Type elemtype, TypeSymbol arrayClass) {
1302             this(elemtype, arrayClass, TypeMetadata.EMPTY);
1303         }
1304 
1305         public ArrayType(Type elemtype, TypeSymbol arrayClass,
1306                          TypeMetadata metadata) {
1307             super(arrayClass, metadata);
1308             this.elemtype = elemtype;
1309         }
1310 
1311         public ArrayType(ArrayType that) {
1312             //note: type metadata is deliberately shared here, as we want side-effects from annotation
1313             //processing to flow from original array to the cloned array.
1314             this(that.elemtype, that.tsym, that.getMetadata());
1315         }
1316 
1317         public int poolTag() {
1318             return ClassFile.CONSTANT_Class;
1319         }
1320 
1321         @Override
1322         public ArrayType cloneWithMetadata(TypeMetadata md) {
1323             return new ArrayType(elemtype, tsym, md) {
1324                 @Override
1325                 public Type baseType() { return ArrayType.this.baseType(); }
1326             };
1327         }
1328 
1329         @Override
1330         public TypeTag getTag() {
1331             return ARRAY;
1332         }
1333 
1334         public <R,S> R accept(Type.Visitor<R,S> v, S s) {
1335             return v.visitArrayType(this, s);
1336         }
1337 
1338         @DefinedBy(Api.LANGUAGE_MODEL)
1339         public String toString() {
1340             StringBuilder sb = new StringBuilder();


1416         public void complete() {
1417             elemtype.complete();
1418         }
1419 
1420         @DefinedBy(Api.LANGUAGE_MODEL)
1421         public Type getComponentType() {
1422             return elemtype;
1423         }
1424 
1425         @DefinedBy(Api.LANGUAGE_MODEL)
1426         public TypeKind getKind() {
1427             return TypeKind.ARRAY;
1428         }
1429 
1430         @DefinedBy(Api.LANGUAGE_MODEL)
1431         public <R, P> R accept(TypeVisitor<R, P> v, P p) {
1432             return v.visitArray(this, p);
1433         }
1434     }
1435 
1436     public static class MethodType extends Type implements ExecutableType, LoadableConstant {
1437 
1438         public List<Type> argtypes;
1439         public Type restype;
1440         public List<Type> thrown;
1441 
1442         /** The type annotations on the method receiver.
1443          */
1444         public Type recvtype;
1445 
1446         public MethodType(List<Type> argtypes,
1447                           Type restype,
1448                           List<Type> thrown,
1449                           TypeSymbol methodClass) {
1450             // Presently no way to refer to a method type directly, so
1451             // we cannot put type annotations on it.
1452             super(methodClass, TypeMetadata.EMPTY);
1453             this.argtypes = argtypes;
1454             this.restype = restype;
1455             this.thrown = thrown;
1456         }


1483             sb.append(')');
1484             sb.append(restype);
1485             return sb.toString();
1486         }
1487 
1488         @DefinedBy(Api.LANGUAGE_MODEL)
1489         public List<Type>        getParameterTypes() { return argtypes; }
1490         @DefinedBy(Api.LANGUAGE_MODEL)
1491         public Type              getReturnType()     { return restype; }
1492         @DefinedBy(Api.LANGUAGE_MODEL)
1493         public Type              getReceiverType()   { return recvtype; }
1494         @DefinedBy(Api.LANGUAGE_MODEL)
1495         public List<Type>        getThrownTypes()    { return thrown; }
1496 
1497         public boolean isErroneous() {
1498             return
1499                 isErroneous(argtypes) ||
1500                 restype != null && restype.isErroneous();
1501         }
1502 
1503         @Override
1504         public int poolTag() {
1505             return ClassFile.CONSTANT_MethodType;
1506         }
1507 
1508         public boolean contains(Type elem) {
1509             return elem.equalsIgnoreMetadata(this) || contains(argtypes, elem) || restype.contains(elem) || contains(thrown, elem);
1510         }
1511 
1512         public MethodType asMethodType() { return this; }
1513 
1514         public void complete() {
1515             for (List<Type> l = argtypes; l.nonEmpty(); l = l.tail)
1516                 l.head.complete();
1517             restype.complete();
1518             recvtype.complete();
1519             for (List<Type> l = thrown; l.nonEmpty(); l = l.tail)
1520                 l.head.complete();
1521         }
1522 
1523         @DefinedBy(Api.LANGUAGE_MODEL)
1524         public List<TypeVar> getTypeVariables() {
1525             return List.nil();
1526         }
1527 


2298         public TypeTag getTag() {
2299             return BOT;
2300         }
2301 
2302         @Override @DefinedBy(Api.LANGUAGE_MODEL)
2303         public TypeKind getKind() {
2304             return TypeKind.NULL;
2305         }
2306 
2307         @Override
2308         public boolean isCompound() { return false; }
2309 
2310         @Override @DefinedBy(Api.LANGUAGE_MODEL)
2311         public <R, P> R accept(TypeVisitor<R, P> v, P p) {
2312             return v.visitNull(this, p);
2313         }
2314 
2315         @Override
2316         public Type constType(Object value) {
2317             return this;
2318         }
2319 
2320         @Override
2321         public String stringValue() {
2322             return "null";
2323         }
2324 
2325         @Override
2326         public boolean isNullOrReference() {
2327             return true;
2328         }
2329 
2330     }
2331 
2332     public static class ErrorType extends ClassType
2333             implements javax.lang.model.type.ErrorType {
2334 
2335         private Type originalType = null;
2336 
2337         public ErrorType(ClassSymbol c, Type originalType) {
2338             this(originalType, c);
2339             c.type = this;
2340             c.kind = ERR;
2341             c.members_field = new Scope.ErrorScope(c);
2342         }




  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.code;
  27 
  28 import java.lang.annotation.Annotation;
  29 import java.util.ArrayDeque;
  30 import java.util.Collections;
  31 import java.util.EnumMap;
  32 import java.util.Map;
  33 
  34 import javax.lang.model.type.*;
  35 
  36 import com.sun.tools.javac.code.Symbol.*;
  37 import com.sun.tools.javac.code.TypeMetadata.Entry;
  38 import com.sun.tools.javac.code.Types.TypeMapping;

  39 import com.sun.tools.javac.comp.Infer.IncorporationAction;


  40 import com.sun.tools.javac.util.*;
  41 import com.sun.tools.javac.util.DefinedBy.Api;
  42 
  43 import static com.sun.tools.javac.code.BoundKind.*;
  44 import static com.sun.tools.javac.code.Flags.*;
  45 import static com.sun.tools.javac.code.Kinds.Kind.*;
  46 import static com.sun.tools.javac.code.TypeTag.*;
  47 
  48 /** This class represents Java types. The class itself defines the behavior of
  49  *  the following types:
  50  *  <pre>
  51  *  base types (tags: BYTE, CHAR, SHORT, INT, LONG, FLOAT, DOUBLE, BOOLEAN),
  52  *  type `void' (tag: VOID),
  53  *  the bottom type (tag: BOT),
  54  *  the missing type (tag: NONE).
  55  *  </pre>
  56  *  <p>The behavior of the following types is defined in subclasses, which are
  57  *  all static inner classes of this class:
  58  *  <pre>
  59  *  class types (tag: CLASS, class: ClassType),
  60  *  array types (tag: ARRAY, class: ArrayType),
  61  *  method types (tag: METHOD, class: MethodType),
  62  *  package types (tag: PACKAGE, class: PackageType),
  63  *  type variables (tag: TYPEVAR, class: TypeVar),
  64  *  type arguments (tag: WILDCARD, class: WildcardType),
  65  *  generic method types (tag: FORALL, class: ForAll),
  66  *  the error type (tag: ERROR, class: ErrorType).
  67  *  </pre>
  68  *
  69  *  <p><b>This is NOT part of any supported API.
  70  *  If you write code that depends on this, you do so at your own risk.
  71  *  This code and its internal interfaces are subject to change or
  72  *  deletion without notice.</b>
  73  *
  74  *  @see TypeTag
  75  */
  76 public abstract class Type extends AnnoConstruct implements TypeMirror {
  77 
  78     /**
  79      * Type metadata,  Should be {@code null} for the default value.
  80      *
  81      * Note: it is an invariant that for any {@code TypeMetadata}
  82      * class, a given {@code Type} may have at most one metadata array
  83      * entry of that class.
  84      */
  85     protected final TypeMetadata metadata;
  86 
  87     public TypeMetadata getMetadata() {
  88         return metadata;
  89     }
  90 
  91     public Entry getMetadataOfKind(final Entry.Kind kind) {
  92         return metadata != null ? metadata.get(kind) : null;
  93     }
  94 
  95     /** Constant type: no type at all. */
  96     public static final JCNoType noType = new JCNoType() {


 108         }
 109     };
 110 
 111     /** Constant type: special type to be used for marking stuck trees. */
 112     public static final JCNoType stuckType = new JCNoType() {
 113         @Override @DefinedBy(Api.LANGUAGE_MODEL)
 114         public String toString() {
 115             return "stuck";
 116         }
 117     };
 118 
 119     /** If this switch is turned on, the names of type variables
 120      *  and anonymous classes are printed with hashcodes appended.
 121      */
 122     public static boolean moreInfo = false;
 123 
 124     /** The defining class / interface / package / type variable.
 125      */
 126     public TypeSymbol tsym;
 127 










 128     /**
 129      * Checks if the current type tag is equal to the given tag.
 130      * @return true if tag is equal to the current type tag.
 131      */
 132     public boolean hasTag(TypeTag tag) {
 133         return tag == getTag();
 134     }
 135 
 136     /**
 137      * Returns the current type tag.
 138      * @return the value of the current type tag.
 139      */
 140     public abstract TypeTag getTag();
 141 
 142     public boolean isNumeric() {
 143         return false;
 144     }
 145 
 146     public boolean isIntegral() {
 147         return false;


 160     }
 161 
 162     public boolean isNullOrReference() {
 163         return false;
 164     }
 165 
 166     public boolean isPartial() {
 167         return false;
 168     }
 169 
 170     /**
 171      * The constant value of this type, null if this type does not
 172      * have a constant value attribute. Only primitive types and
 173      * strings (ClassType) can have a constant value attribute.
 174      * @return the constant value attribute of this type
 175      */
 176     public Object constValue() {
 177         return null;
 178     }
 179 












 180     /**
 181      * Get the representation of this type used for modelling purposes.
 182      * By default, this is itself. For ErrorType, a different value
 183      * may be provided.
 184      */
 185     public Type getModelType() {
 186         return this;
 187     }
 188 
 189     public static List<Type> getModelTypes(List<Type> ts) {
 190         ListBuffer<Type> lb = new ListBuffer<>();
 191         for (Type t: ts)
 192             lb.append(t.getModelType());
 193         return lb.toList();
 194     }
 195 
 196     /**For ErrorType, returns the original type, otherwise returns the type itself.
 197      */
 198     public Type getOriginalType() {
 199         return this;


 451     }
 452 
 453     /**
 454      * The Java source which this type list represents.  A List is
 455      * represented as a comma-spearated listing of the elements in
 456      * that list.
 457      */
 458     public static String toString(List<Type> ts) {
 459         if (ts.isEmpty()) {
 460             return "";
 461         } else {
 462             StringBuilder buf = new StringBuilder();
 463             buf.append(ts.head.toString());
 464             for (List<Type> l = ts.tail; l.nonEmpty(); l = l.tail)
 465                 buf.append(",").append(l.head.toString());
 466             return buf.toString();
 467         }
 468     }
 469 
 470     /**








 471      * Override this method with care. For most Type instances this should behave as ==.
 472      */
 473     @Override @DefinedBy(Api.LANGUAGE_MODEL)
 474     public boolean equals(Object t) {
 475         return this == t;
 476     }
 477 
 478     public boolean equalsIgnoreMetadata(Type t) {
 479         return typeNoMetadata().equals(t.typeNoMetadata());
 480     }
 481 
 482     @Override @DefinedBy(Api.LANGUAGE_MODEL)
 483     public int hashCode() {
 484         return super.hashCode();
 485     }
 486 
 487     public String argtypes(boolean varargs) {
 488         List<Type> args = getParameterTypes();
 489         if (!varargs) return args.toString();
 490         StringBuilder buf = new StringBuilder();


 706         }
 707 
 708         /** Define a constant type, of the same kind as this type
 709          *  and with given constant value
 710          */
 711         @Override
 712         public Type constType(Object constValue) {
 713             final Object value = constValue;
 714             return new JCPrimitiveType(tag, tsym, metadata) {
 715                     @Override
 716                     public Object constValue() {
 717                         return value;
 718                     }
 719                     @Override
 720                     public Type baseType() {
 721                         return tsym.type;
 722                     }
 723                 };
 724         }
 725 





































 726         @Override @DefinedBy(Api.LANGUAGE_MODEL)
 727         public <R, P> R accept(TypeVisitor<R, P> v, P p) {
 728             return v.visitPrimitive(this, p);
 729         }
 730 
 731         @Override @DefinedBy(Api.LANGUAGE_MODEL)
 732         public TypeKind getKind() {
 733             switch (tag) {
 734                 case BYTE:      return TypeKind.BYTE;
 735                 case CHAR:      return TypeKind.CHAR;
 736                 case SHORT:     return TypeKind.SHORT;
 737                 case INT:       return TypeKind.INT;
 738                 case LONG:      return TypeKind.LONG;
 739                 case FLOAT:     return TypeKind.FLOAT;
 740                 case DOUBLE:    return TypeKind.DOUBLE;
 741                 case BOOLEAN:   return TypeKind.BOOLEAN;
 742             }
 743             throw new AssertionError();
 744         }
 745 


 856 
 857         @DefinedBy(Api.LANGUAGE_MODEL)
 858         public Type getSuperBound() {
 859             if (kind == SUPER)
 860                 return type;
 861             else
 862                 return null;
 863         }
 864 
 865         @DefinedBy(Api.LANGUAGE_MODEL)
 866         public TypeKind getKind() {
 867             return TypeKind.WILDCARD;
 868         }
 869 
 870         @DefinedBy(Api.LANGUAGE_MODEL)
 871         public <R, P> R accept(TypeVisitor<R, P> v, P p) {
 872             return v.visitWildcard(this, p);
 873         }
 874     }
 875 
 876     public static class ClassType extends Type implements DeclaredType,
 877                                                           javax.lang.model.type.ErrorType {
 878 
 879         /** The enclosing type of this type. If this is the type of an inner
 880          *  class, outer_field refers to the type of its enclosing
 881          *  instance class, in all other cases it refers to noType.
 882          */
 883         private Type outer_field;
 884 
 885         /** The type parameters of this type (to be set once class is loaded).
 886          */
 887         public List<Type> typarams_field;
 888 
 889         /** A cache variable for the type parameters of this type,
 890          *  appended to all parameters of its enclosing class.
 891          *  @see #allparams
 892          */
 893         public List<Type> allparams_field;
 894 
 895         /** The supertype of this class (to be set once class is loaded).
 896          */


 901         public List<Type> interfaces_field;
 902 
 903         /** All the interfaces of this class, including missing ones.
 904          */
 905         public List<Type> all_interfaces_field;
 906 
 907         public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) {
 908             this(outer, typarams, tsym, TypeMetadata.EMPTY);
 909         }
 910 
 911         public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym,
 912                          TypeMetadata metadata) {
 913             super(tsym, metadata);
 914             this.outer_field = outer;
 915             this.typarams_field = typarams;
 916             this.allparams_field = null;
 917             this.supertype_field = null;
 918             this.interfaces_field = null;
 919         }
 920 




 921         @Override
 922         public ClassType cloneWithMetadata(TypeMetadata md) {
 923             return new ClassType(outer_field, typarams_field, tsym, md) {
 924                 @Override
 925                 public Type baseType() { return ClassType.this.baseType(); }
 926             };
 927         }
 928 
 929         @Override
 930         public TypeTag getTag() {
 931             return CLASS;
 932         }
 933 
 934         @Override
 935         public <R,S> R accept(Type.Visitor<R,S> v, S s) {
 936             return v.visitClassType(this, s);
 937         }
 938 
 939         public Type constType(Object constValue) {
 940             final Object value = constValue;


1203         }
1204 
1205         public List<Type> getExplicitComponents() {
1206             return allInterfaces ?
1207                     interfaces_field :
1208                     getComponents();
1209         }
1210 
1211         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1212         public TypeKind getKind() {
1213             return TypeKind.INTERSECTION;
1214         }
1215 
1216         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1217         public <R, P> R accept(TypeVisitor<R, P> v, P p) {
1218             return v.visitIntersection(this, p);
1219         }
1220     }
1221 
1222     public static class ArrayType extends Type
1223             implements javax.lang.model.type.ArrayType {
1224 
1225         public Type elemtype;
1226 
1227         public ArrayType(Type elemtype, TypeSymbol arrayClass) {
1228             this(elemtype, arrayClass, TypeMetadata.EMPTY);
1229         }
1230 
1231         public ArrayType(Type elemtype, TypeSymbol arrayClass,
1232                          TypeMetadata metadata) {
1233             super(arrayClass, metadata);
1234             this.elemtype = elemtype;
1235         }
1236 
1237         public ArrayType(ArrayType that) {
1238             //note: type metadata is deliberately shared here, as we want side-effects from annotation
1239             //processing to flow from original array to the cloned array.
1240             this(that.elemtype, that.tsym, that.getMetadata());
1241         }
1242 




1243         @Override
1244         public ArrayType cloneWithMetadata(TypeMetadata md) {
1245             return new ArrayType(elemtype, tsym, md) {
1246                 @Override
1247                 public Type baseType() { return ArrayType.this.baseType(); }
1248             };
1249         }
1250 
1251         @Override
1252         public TypeTag getTag() {
1253             return ARRAY;
1254         }
1255 
1256         public <R,S> R accept(Type.Visitor<R,S> v, S s) {
1257             return v.visitArrayType(this, s);
1258         }
1259 
1260         @DefinedBy(Api.LANGUAGE_MODEL)
1261         public String toString() {
1262             StringBuilder sb = new StringBuilder();


1338         public void complete() {
1339             elemtype.complete();
1340         }
1341 
1342         @DefinedBy(Api.LANGUAGE_MODEL)
1343         public Type getComponentType() {
1344             return elemtype;
1345         }
1346 
1347         @DefinedBy(Api.LANGUAGE_MODEL)
1348         public TypeKind getKind() {
1349             return TypeKind.ARRAY;
1350         }
1351 
1352         @DefinedBy(Api.LANGUAGE_MODEL)
1353         public <R, P> R accept(TypeVisitor<R, P> v, P p) {
1354             return v.visitArray(this, p);
1355         }
1356     }
1357 
1358     public static class MethodType extends Type implements ExecutableType {
1359 
1360         public List<Type> argtypes;
1361         public Type restype;
1362         public List<Type> thrown;
1363 
1364         /** The type annotations on the method receiver.
1365          */
1366         public Type recvtype;
1367 
1368         public MethodType(List<Type> argtypes,
1369                           Type restype,
1370                           List<Type> thrown,
1371                           TypeSymbol methodClass) {
1372             // Presently no way to refer to a method type directly, so
1373             // we cannot put type annotations on it.
1374             super(methodClass, TypeMetadata.EMPTY);
1375             this.argtypes = argtypes;
1376             this.restype = restype;
1377             this.thrown = thrown;
1378         }


1405             sb.append(')');
1406             sb.append(restype);
1407             return sb.toString();
1408         }
1409 
1410         @DefinedBy(Api.LANGUAGE_MODEL)
1411         public List<Type>        getParameterTypes() { return argtypes; }
1412         @DefinedBy(Api.LANGUAGE_MODEL)
1413         public Type              getReturnType()     { return restype; }
1414         @DefinedBy(Api.LANGUAGE_MODEL)
1415         public Type              getReceiverType()   { return recvtype; }
1416         @DefinedBy(Api.LANGUAGE_MODEL)
1417         public List<Type>        getThrownTypes()    { return thrown; }
1418 
1419         public boolean isErroneous() {
1420             return
1421                 isErroneous(argtypes) ||
1422                 restype != null && restype.isErroneous();
1423         }
1424 





1425         public boolean contains(Type elem) {
1426             return elem.equalsIgnoreMetadata(this) || contains(argtypes, elem) || restype.contains(elem) || contains(thrown, elem);
1427         }
1428 
1429         public MethodType asMethodType() { return this; }
1430 
1431         public void complete() {
1432             for (List<Type> l = argtypes; l.nonEmpty(); l = l.tail)
1433                 l.head.complete();
1434             restype.complete();
1435             recvtype.complete();
1436             for (List<Type> l = thrown; l.nonEmpty(); l = l.tail)
1437                 l.head.complete();
1438         }
1439 
1440         @DefinedBy(Api.LANGUAGE_MODEL)
1441         public List<TypeVar> getTypeVariables() {
1442             return List.nil();
1443         }
1444 


2215         public TypeTag getTag() {
2216             return BOT;
2217         }
2218 
2219         @Override @DefinedBy(Api.LANGUAGE_MODEL)
2220         public TypeKind getKind() {
2221             return TypeKind.NULL;
2222         }
2223 
2224         @Override
2225         public boolean isCompound() { return false; }
2226 
2227         @Override @DefinedBy(Api.LANGUAGE_MODEL)
2228         public <R, P> R accept(TypeVisitor<R, P> v, P p) {
2229             return v.visitNull(this, p);
2230         }
2231 
2232         @Override
2233         public Type constType(Object value) {
2234             return this;





2235         }
2236 
2237         @Override
2238         public boolean isNullOrReference() {
2239             return true;
2240         }
2241 
2242     }
2243 
2244     public static class ErrorType extends ClassType
2245             implements javax.lang.model.type.ErrorType {
2246 
2247         private Type originalType = null;
2248 
2249         public ErrorType(ClassSymbol c, Type originalType) {
2250             this(originalType, c);
2251             c.type = this;
2252             c.kind = ERR;
2253             c.members_field = new Scope.ErrorScope(c);
2254         }


< prev index next >