< prev index next >

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

Print this page

 214         return lb.toList();
 215     }
 216 
 217     /**For ErrorType, returns the original type, otherwise returns the type itself.
 218      */
 219     public Type getOriginalType() {
 220         return this;
 221     }
 222 
 223     public <R,S> R accept(Type.Visitor<R,S> v, S s) { return v.visitType(this, s); }
 224 
 225     /** Define a type given its tag, type symbol, and type annotations
 226      */
 227 
 228     public Type(TypeSymbol tsym, List<TypeMetadata> metadata) {
 229         Assert.checkNonNull(metadata);
 230         this.tsym = tsym;
 231         this.metadata = metadata;
 232     }
 233 















 234     /**
 235      * A subclass of {@link Types.TypeMapping} which applies a mapping recursively to the subterms
 236      * of a given type expression. This mapping returns the original type is no changes occurred
 237      * when recursively mapping the original type's subterms.
 238      */
 239     public abstract static class StructuralTypeMapping<S> extends Types.TypeMapping<S> {
 240 
 241         @Override
 242         public Type visitClassType(ClassType t, S s) {
 243             Type outer = t.getEnclosingType();
 244             Type outer1 = visit(outer, s);
 245             List<Type> typarams = t.getTypeArguments();
 246             List<Type> typarams1 = visit(typarams, s);
 247             if (outer1 == outer && typarams1 == typarams) return t;
 248             else return new ClassType(outer1, typarams1, t.tsym, t.metadata) {
 249                 @Override
 250                 protected boolean needsStripping() {
 251                     return true;
 252                 }
 253             };

1016 
1017         public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) {
1018             this(outer, typarams, tsym, List.nil());
1019         }
1020 
1021         public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym,
1022                          List<TypeMetadata> metadata) {
1023             super(tsym, metadata);
1024             this.outer_field = outer;
1025             this.typarams_field = typarams;
1026             this.allparams_field = null;
1027             this.supertype_field = null;
1028             this.interfaces_field = null;
1029         }
1030 
1031         public int poolTag() {
1032             return ClassFile.CONSTANT_Class;
1033         }
1034 
1035         @Override
1036         protected ClassType cloneWithMetadata(List<TypeMetadata> md) {
1037             return new ClassType(outer_field, typarams_field, tsym, md) {
1038                 @Override
1039                 public Type baseType() { return ClassType.this.baseType(); }
1040             };
1041         }
1042 
1043         @Override
1044         public TypeTag getTag() {
1045             return CLASS;
1046         }
1047 
1048         @Override
1049         public <R,S> R accept(Type.Visitor<R,S> v, S s) {
1050             return v.visitClassType(this, s);
1051         }
1052 
1053         public Type constType(Object constValue) {
1054             return addMetadata(new ConstantValue(constValue));
1055         }
1056 

1153             return allparams_field;
1154         }
1155 
1156         public boolean isErroneous() {
1157             return
1158                 getEnclosingType().isErroneous() ||
1159                 isErroneous(getTypeArguments()) ||
1160                 this != tsym.type && tsym.type.isErroneous();
1161         }
1162 
1163         public boolean isParameterized() {
1164             return allparams().tail != null;
1165             // optimization, was: allparams().nonEmpty();
1166         }
1167 
1168         @Override
1169         public boolean isReference() {
1170             return true;
1171         }
1172 










1173         @Override
1174         public boolean isNullOrReference() {
1175             return true;
1176         }
1177 
1178         /** A cache for the rank. */
1179         int rank_field = -1;
1180 
1181         /** A class type is raw if it misses some
1182          *  of its type parameter sections.
1183          *  After validation, this is equivalent to:
1184          *  {@code allparams.isEmpty() && tsym.type.allparams.nonEmpty(); }
1185          */
1186         public boolean isRaw() {
1187             return
1188                 this != tsym.type && // necessary, but not sufficient condition
1189                 tsym.type.allparams().nonEmpty() &&
1190                 allparams().isEmpty();
1191         }
1192 

2312         @Override
2313         public boolean isNullOrReference() {
2314             return true;
2315         }
2316 
2317     }
2318 
2319     public static class ErrorType extends ClassType
2320             implements javax.lang.model.type.ErrorType {
2321 
2322         private Type originalType = null;
2323 
2324         public ErrorType(ClassSymbol c, Type originalType) {
2325             this(originalType, c);
2326             c.type = this;
2327             c.kind = ERR;
2328             c.members_field = new Scope.ErrorScope(c);
2329         }
2330 
2331         public ErrorType(Type originalType, TypeSymbol tsym) {
2332             super(noType, List.nil(), null);
2333             this.tsym = tsym;
2334             this.originalType = (originalType == null ? noType : originalType);
2335         }
2336 
2337         private ErrorType(Type originalType, TypeSymbol tsym,
2338                           List<TypeMetadata> metadata) {
2339             super(noType, List.nil(), null, metadata);
2340             this.tsym = tsym;
2341             this.originalType = (originalType == null ? noType : originalType);
2342         }
2343 
2344         @Override
2345         protected ErrorType cloneWithMetadata(List<TypeMetadata> md) {
2346             return new ErrorType(originalType, tsym, md) {
2347                 @Override
2348                 public Type baseType() { return ErrorType.this.baseType(); }
2349             };
2350         }
2351 
2352         @Override
2353         public TypeTag getTag() {
2354             return ERROR;
2355         }
2356 
2357         @Override
2358         public boolean isPartial() {
2359             return true;
2360         }
2361 
2362         @Override
2363         public boolean isReference() {
2364             return true;
2365         }

 214         return lb.toList();
 215     }
 216 
 217     /**For ErrorType, returns the original type, otherwise returns the type itself.
 218      */
 219     public Type getOriginalType() {
 220         return this;
 221     }
 222 
 223     public <R,S> R accept(Type.Visitor<R,S> v, S s) { return v.visitType(this, s); }
 224 
 225     /** Define a type given its tag, type symbol, and type annotations
 226      */
 227 
 228     public Type(TypeSymbol tsym, List<TypeMetadata> metadata) {
 229         Assert.checkNonNull(metadata);
 230         this.tsym = tsym;
 231         this.metadata = metadata;
 232     }
 233 
 234     public boolean isValueClass() {
 235         return false;
 236     }
 237 
 238     public boolean isIdentityClass() {
 239         return false;
 240     }
 241 
 242     // Does this type need to be preloaded in the context of the referring class ??
 243     public boolean requiresPreload(Symbol referringClass) {
 244         if (this.tsym == referringClass)
 245             return false; // pointless
 246         return this.isValueClass();
 247     }
 248 
 249     /**
 250      * A subclass of {@link Types.TypeMapping} which applies a mapping recursively to the subterms
 251      * of a given type expression. This mapping returns the original type is no changes occurred
 252      * when recursively mapping the original type's subterms.
 253      */
 254     public abstract static class StructuralTypeMapping<S> extends Types.TypeMapping<S> {
 255 
 256         @Override
 257         public Type visitClassType(ClassType t, S s) {
 258             Type outer = t.getEnclosingType();
 259             Type outer1 = visit(outer, s);
 260             List<Type> typarams = t.getTypeArguments();
 261             List<Type> typarams1 = visit(typarams, s);
 262             if (outer1 == outer && typarams1 == typarams) return t;
 263             else return new ClassType(outer1, typarams1, t.tsym, t.metadata) {
 264                 @Override
 265                 protected boolean needsStripping() {
 266                     return true;
 267                 }
 268             };

1031 
1032         public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) {
1033             this(outer, typarams, tsym, List.nil());
1034         }
1035 
1036         public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym,
1037                          List<TypeMetadata> metadata) {
1038             super(tsym, metadata);
1039             this.outer_field = outer;
1040             this.typarams_field = typarams;
1041             this.allparams_field = null;
1042             this.supertype_field = null;
1043             this.interfaces_field = null;
1044         }
1045 
1046         public int poolTag() {
1047             return ClassFile.CONSTANT_Class;
1048         }
1049 
1050         @Override
1051         public ClassType cloneWithMetadata(List<TypeMetadata> md) {
1052             return new ClassType(outer_field, typarams_field, tsym, md) {
1053                 @Override
1054                 public Type baseType() { return ClassType.this.baseType(); }
1055             };
1056         }
1057 
1058         @Override
1059         public TypeTag getTag() {
1060             return CLASS;
1061         }
1062 
1063         @Override
1064         public <R,S> R accept(Type.Visitor<R,S> v, S s) {
1065             return v.visitClassType(this, s);
1066         }
1067 
1068         public Type constType(Object constValue) {
1069             return addMetadata(new ConstantValue(constValue));
1070         }
1071 

1168             return allparams_field;
1169         }
1170 
1171         public boolean isErroneous() {
1172             return
1173                 getEnclosingType().isErroneous() ||
1174                 isErroneous(getTypeArguments()) ||
1175                 this != tsym.type && tsym.type.isErroneous();
1176         }
1177 
1178         public boolean isParameterized() {
1179             return allparams().tail != null;
1180             // optimization, was: allparams().nonEmpty();
1181         }
1182 
1183         @Override
1184         public boolean isReference() {
1185             return true;
1186         }
1187 
1188         @Override
1189         public boolean isValueClass() {
1190             return tsym != null && tsym.isValueClass();
1191         }
1192 
1193         @Override
1194         public boolean isIdentityClass() {
1195             return tsym != null && tsym.isIdentityClass();
1196         }
1197 
1198         @Override
1199         public boolean isNullOrReference() {
1200             return true;
1201         }
1202 
1203         /** A cache for the rank. */
1204         int rank_field = -1;
1205 
1206         /** A class type is raw if it misses some
1207          *  of its type parameter sections.
1208          *  After validation, this is equivalent to:
1209          *  {@code allparams.isEmpty() && tsym.type.allparams.nonEmpty(); }
1210          */
1211         public boolean isRaw() {
1212             return
1213                 this != tsym.type && // necessary, but not sufficient condition
1214                 tsym.type.allparams().nonEmpty() &&
1215                 allparams().isEmpty();
1216         }
1217 

2337         @Override
2338         public boolean isNullOrReference() {
2339             return true;
2340         }
2341 
2342     }
2343 
2344     public static class ErrorType extends ClassType
2345             implements javax.lang.model.type.ErrorType {
2346 
2347         private Type originalType = null;
2348 
2349         public ErrorType(ClassSymbol c, Type originalType) {
2350             this(originalType, c);
2351             c.type = this;
2352             c.kind = ERR;
2353             c.members_field = new Scope.ErrorScope(c);
2354         }
2355 
2356         public ErrorType(Type originalType, TypeSymbol tsym) {
2357             super(noType, List.nil(), tsym, List.nil());

2358             this.originalType = (originalType == null ? noType : originalType);
2359         }
2360 
2361         private ErrorType(Type originalType, TypeSymbol tsym,
2362                           List<TypeMetadata> metadata) {
2363             super(noType, List.nil(), null, metadata);
2364             this.tsym = tsym;
2365             this.originalType = (originalType == null ? noType : originalType);
2366         }
2367 
2368         @Override
2369         public ErrorType cloneWithMetadata(List<TypeMetadata> md) {
2370             return new ErrorType(originalType, tsym, md) {
2371                 @Override
2372                 public Type baseType() { return ErrorType.this.baseType(); }
2373             };
2374         }
2375 
2376         @Override
2377         public TypeTag getTag() {
2378             return ERROR;
2379         }
2380 
2381         @Override
2382         public boolean isPartial() {
2383             return true;
2384         }
2385 
2386         @Override
2387         public boolean isReference() {
2388             return true;
2389         }
< prev index next >