68 * This code and its internal interfaces are subject to change or |
68 * This code and its internal interfaces are subject to change or |
69 * deletion without notice.</b> |
69 * deletion without notice.</b> |
70 * |
70 * |
71 * @see TypeTag |
71 * @see TypeTag |
72 */ |
72 */ |
73 public class Type implements PrimitiveType { |
73 public abstract class Type implements TypeMirror { |
74 |
74 |
75 /** Constant type: no type at all. */ |
75 /** Constant type: no type at all. */ |
76 public static final JCNoType noType = new JCNoType(NONE); |
76 public static final JCNoType noType = new JCNoType(); |
77 |
77 |
78 /** Constant type: special type to be used during recovery of deferred expressions. */ |
78 /** Constant type: special type to be used during recovery of deferred expressions. */ |
79 public static final JCNoType recoveryType = new JCNoType(NONE); |
79 public static final JCNoType recoveryType = new JCNoType(); |
80 |
80 |
81 /** If this switch is turned on, the names of type variables |
81 /** If this switch is turned on, the names of type variables |
82 * and anonymous classes are printed with hashcodes appended. |
82 * and anonymous classes are printed with hashcodes appended. |
83 */ |
83 */ |
84 public static boolean moreInfo = false; |
84 public static boolean moreInfo = false; |
85 |
|
86 /** The tag of this type. |
|
87 * |
|
88 * @see TypeTag |
|
89 */ |
|
90 protected TypeTag tag; |
|
91 |
85 |
92 /** The defining class / interface / package / type variable. |
86 /** The defining class / interface / package / type variable. |
93 */ |
87 */ |
94 public TypeSymbol tsym; |
88 public TypeSymbol tsym; |
95 |
89 |
96 /** |
90 /** |
97 * Checks if the current type tag is equal to the given tag. |
91 * Checks if the current type tag is equal to the given tag. |
98 * @return true if tag is equal to the current type tag. |
92 * @return true if tag is equal to the current type tag. |
99 */ |
93 */ |
100 public boolean hasTag(TypeTag tag) { |
94 public boolean hasTag(TypeTag tag) { |
101 return this.tag == tag; |
95 return tag == getTag(); |
102 } |
96 } |
103 |
97 |
104 /** |
98 /** |
105 * Returns the current type tag. |
99 * Returns the current type tag. |
106 * @return the value of the current type tag. |
100 * @return the value of the current type tag. |
107 */ |
101 */ |
108 public TypeTag getTag() { |
102 public abstract TypeTag getTag(); |
109 return tag; |
|
110 } |
|
111 |
103 |
112 public boolean isNumeric() { |
104 public boolean isNumeric() { |
113 return tag.isNumeric; |
105 return false; |
114 } |
106 } |
115 |
107 |
116 public boolean isPrimitive() { |
108 public boolean isPrimitive() { |
117 return tag.isPrimitive; |
109 return false; |
118 } |
110 } |
119 |
111 |
120 public boolean isPrimitiveOrVoid() { |
112 public boolean isPrimitiveOrVoid() { |
121 return tag.isPrimitiveOrVoid; |
113 return false; |
122 } |
114 } |
123 |
115 |
124 public boolean isReference() { |
116 public boolean isReference() { |
125 return tag.isReference; |
117 return false; |
126 } |
118 } |
127 |
119 |
128 public boolean isNullOrReference() { |
120 public boolean isNullOrReference() { |
129 return (tag.isReference || tag == BOT); |
121 return false; |
130 } |
122 } |
131 |
123 |
132 public boolean isPartial() { |
124 public boolean isPartial() { |
133 return tag.isPartial; |
125 return false; |
134 } |
126 } |
135 |
127 |
136 /** |
128 /** |
137 * The constant value of this type, null if this type does not |
129 * The constant value of this type, null if this type does not |
138 * have a constant value attribute. Only primitive types and |
130 * have a constant value attribute. Only primitive types and |
141 */ |
133 */ |
142 public Object constValue() { |
134 public Object constValue() { |
143 return null; |
135 return null; |
144 } |
136 } |
145 |
137 |
|
138 /** Is this a constant type whose value is false? |
|
139 */ |
|
140 public boolean isFalse() { |
|
141 return false; |
|
142 } |
|
143 |
|
144 /** Is this a constant type whose value is true? |
|
145 */ |
|
146 public boolean isTrue() { |
|
147 return false; |
|
148 } |
|
149 |
146 /** |
150 /** |
147 * Get the representation of this type used for modelling purposes. |
151 * Get the representation of this type used for modelling purposes. |
148 * By default, this is itself. For ErrorType, a different value |
152 * By default, this is itself. For ErrorType, a different value |
149 * may be provided. |
153 * may be provided. |
150 */ |
154 */ |
151 public Type getModelType() { |
155 public Type getModelType() { |
152 return this; |
156 return this; |
153 } |
157 } |
154 |
158 |
155 public static List<Type> getModelTypes(List<Type> ts) { |
159 public static List<Type> getModelTypes(List<Type> ts) { |
156 ListBuffer<Type> lb = new ListBuffer<Type>(); |
160 ListBuffer<Type> lb = new ListBuffer<>(); |
157 for (Type t: ts) |
161 for (Type t: ts) |
158 lb.append(t.getModelType()); |
162 lb.append(t.getModelType()); |
159 return lb.toList(); |
163 return lb.toList(); |
160 } |
164 } |
161 |
165 |
162 public <R,S> R accept(Type.Visitor<R,S> v, S s) { return v.visitType(this, s); } |
166 public <R,S> R accept(Type.Visitor<R,S> v, S s) { return v.visitType(this, s); } |
163 |
167 |
164 /** Define a type given its tag and type symbol |
168 /** Define a type given its tag and type symbol |
165 */ |
169 */ |
166 public Type(TypeTag tag, TypeSymbol tsym) { |
170 public Type(TypeSymbol tsym) { |
167 this.tag = tag; |
|
168 this.tsym = tsym; |
171 this.tsym = tsym; |
169 } |
172 } |
170 |
173 |
171 /** An abstract class for mappings from types to types |
174 /** An abstract class for mappings from types to types |
172 */ |
175 */ |
201 |
204 |
202 /** Define a constant type, of the same kind as this type |
205 /** Define a constant type, of the same kind as this type |
203 * and with given constant value |
206 * and with given constant value |
204 */ |
207 */ |
205 public Type constType(Object constValue) { |
208 public Type constType(Object constValue) { |
206 final Object value = constValue; |
209 throw new AssertionError(); |
207 Assert.check(isPrimitive()); |
|
208 return new Type(tag, tsym) { |
|
209 @Override |
|
210 public Object constValue() { |
|
211 return value; |
|
212 } |
|
213 @Override |
|
214 public Type baseType() { |
|
215 return tsym.type; |
|
216 } |
|
217 }; |
|
218 } |
210 } |
219 |
211 |
220 /** |
212 /** |
221 * If this is a constant type, return its underlying type. |
213 * If this is a constant type, return its underlying type. |
222 * Otherwise, return the type itself. |
214 * Otherwise, return the type itself. |
296 /** |
290 /** |
297 * The constant value of this type, converted to String |
291 * The constant value of this type, converted to String |
298 */ |
292 */ |
299 public String stringValue() { |
293 public String stringValue() { |
300 Object cv = Assert.checkNonNull(constValue()); |
294 Object cv = Assert.checkNonNull(constValue()); |
301 if (tag == BOOLEAN) |
295 return cv.toString(); |
302 return ((Integer) cv).intValue() == 0 ? "false" : "true"; |
|
303 else if (tag == CHAR) |
|
304 return String.valueOf((char) ((Integer) cv).intValue()); |
|
305 else |
|
306 return cv.toString(); |
|
307 } |
296 } |
308 |
297 |
309 /** |
298 /** |
310 * This method is analogous to isSameType, but weaker, since we |
299 * This method is analogous to isSameType, but weaker, since we |
311 * never complete classes. Where isSameType would complete a |
300 * never complete classes. Where isSameType would complete a |
317 } |
306 } |
318 |
307 |
319 @Override |
308 @Override |
320 public int hashCode() { |
309 public int hashCode() { |
321 return super.hashCode(); |
310 return super.hashCode(); |
322 } |
|
323 |
|
324 /** Is this a constant type whose value is false? |
|
325 */ |
|
326 public boolean isFalse() { |
|
327 return |
|
328 tag == BOOLEAN && |
|
329 constValue() != null && |
|
330 ((Integer)constValue()).intValue() == 0; |
|
331 } |
|
332 |
|
333 /** Is this a constant type whose value is true? |
|
334 */ |
|
335 public boolean isTrue() { |
|
336 return |
|
337 tag == BOOLEAN && |
|
338 constValue() != null && |
|
339 ((Integer)constValue()).intValue() != 0; |
|
340 } |
311 } |
341 |
312 |
342 public String argtypes(boolean varargs) { |
313 public String argtypes(boolean varargs) { |
343 List<Type> args = getParameterTypes(); |
314 List<Type> args = getParameterTypes(); |
344 if (!varargs) return args.toString(); |
315 if (!varargs) return args.toString(); |
483 |
454 |
484 public TypeSymbol asElement() { |
455 public TypeSymbol asElement() { |
485 return tsym; |
456 return tsym; |
486 } |
457 } |
487 |
458 |
|
459 @Override |
488 public TypeKind getKind() { |
460 public TypeKind getKind() { |
489 switch (tag) { |
461 return TypeKind.OTHER; |
490 case BYTE: return TypeKind.BYTE; |
462 } |
491 case CHAR: return TypeKind.CHAR; |
463 |
492 case SHORT: return TypeKind.SHORT; |
464 @Override |
493 case INT: return TypeKind.INT; |
|
494 case LONG: return TypeKind.LONG; |
|
495 case FLOAT: return TypeKind.FLOAT; |
|
496 case DOUBLE: return TypeKind.DOUBLE; |
|
497 case BOOLEAN: return TypeKind.BOOLEAN; |
|
498 case VOID: return TypeKind.VOID; |
|
499 case BOT: return TypeKind.NULL; |
|
500 case NONE: return TypeKind.NONE; |
|
501 default: return TypeKind.OTHER; |
|
502 } |
|
503 } |
|
504 |
|
505 public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
465 public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
506 if (isPrimitive()) |
466 throw new AssertionError(); |
|
467 } |
|
468 |
|
469 public static class JCPrimitiveType extends Type |
|
470 implements javax.lang.model.type.PrimitiveType { |
|
471 |
|
472 TypeTag tag; |
|
473 |
|
474 public JCPrimitiveType(TypeTag tag, TypeSymbol tsym) { |
|
475 super(tsym); |
|
476 this.tag = tag; |
|
477 Assert.check(tag.isPrimitive); |
|
478 } |
|
479 |
|
480 @Override |
|
481 public boolean isNumeric() { |
|
482 return tag != BOOLEAN; |
|
483 } |
|
484 |
|
485 @Override |
|
486 public boolean isPrimitive() { |
|
487 return true; |
|
488 } |
|
489 |
|
490 @Override |
|
491 public TypeTag getTag() { |
|
492 return tag; |
|
493 } |
|
494 |
|
495 @Override |
|
496 public boolean isPrimitiveOrVoid() { |
|
497 return true; |
|
498 } |
|
499 |
|
500 /** Define a constant type, of the same kind as this type |
|
501 * and with given constant value |
|
502 */ |
|
503 @Override |
|
504 public Type constType(Object constValue) { |
|
505 final Object value = constValue; |
|
506 return new JCPrimitiveType(tag, tsym) { |
|
507 @Override |
|
508 public Object constValue() { |
|
509 return value; |
|
510 } |
|
511 @Override |
|
512 public Type baseType() { |
|
513 return tsym.type; |
|
514 } |
|
515 }; |
|
516 } |
|
517 |
|
518 /** |
|
519 * The constant value of this type, converted to String |
|
520 */ |
|
521 @Override |
|
522 public String stringValue() { |
|
523 Object cv = Assert.checkNonNull(constValue()); |
|
524 if (tag == BOOLEAN) { |
|
525 return ((Integer) cv).intValue() == 0 ? "false" : "true"; |
|
526 } |
|
527 else if (tag == CHAR) { |
|
528 return String.valueOf((char) ((Integer) cv).intValue()); |
|
529 } |
|
530 else { |
|
531 return cv.toString(); |
|
532 } |
|
533 } |
|
534 |
|
535 /** Is this a constant type whose value is false? |
|
536 */ |
|
537 @Override |
|
538 public boolean isFalse() { |
|
539 return |
|
540 tag == BOOLEAN && |
|
541 constValue() != null && |
|
542 ((Integer)constValue()).intValue() == 0; |
|
543 } |
|
544 |
|
545 /** Is this a constant type whose value is true? |
|
546 */ |
|
547 @Override |
|
548 public boolean isTrue() { |
|
549 return |
|
550 tag == BOOLEAN && |
|
551 constValue() != null && |
|
552 ((Integer)constValue()).intValue() != 0; |
|
553 } |
|
554 |
|
555 @Override |
|
556 public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
507 return v.visitPrimitive(this, p); |
557 return v.visitPrimitive(this, p); |
508 else |
558 } |
|
559 |
|
560 @Override |
|
561 public TypeKind getKind() { |
|
562 switch (tag) { |
|
563 case BYTE: return TypeKind.BYTE; |
|
564 case CHAR: return TypeKind.CHAR; |
|
565 case SHORT: return TypeKind.SHORT; |
|
566 case INT: return TypeKind.INT; |
|
567 case LONG: return TypeKind.LONG; |
|
568 case FLOAT: return TypeKind.FLOAT; |
|
569 case DOUBLE: return TypeKind.DOUBLE; |
|
570 case BOOLEAN: return TypeKind.BOOLEAN; |
|
571 } |
509 throw new AssertionError(); |
572 throw new AssertionError(); |
|
573 } |
|
574 |
510 } |
575 } |
511 |
576 |
512 public static class WildcardType extends Type |
577 public static class WildcardType extends Type |
513 implements javax.lang.model.type.WildcardType { |
578 implements javax.lang.model.type.WildcardType { |
514 |
579 |
520 public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
585 public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
521 return v.visitWildcardType(this, s); |
586 return v.visitWildcardType(this, s); |
522 } |
587 } |
523 |
588 |
524 public WildcardType(Type type, BoundKind kind, TypeSymbol tsym) { |
589 public WildcardType(Type type, BoundKind kind, TypeSymbol tsym) { |
525 super(WILDCARD, tsym); |
590 super(tsym); |
526 this.type = Assert.checkNonNull(type); |
591 this.type = Assert.checkNonNull(type); |
527 this.kind = kind; |
592 this.kind = kind; |
528 } |
593 } |
529 public WildcardType(WildcardType t, TypeVar bound) { |
594 public WildcardType(WildcardType t, TypeVar bound) { |
530 this(t.type, t.kind, t.tsym, bound); |
595 this(t.type, t.kind, t.tsym, bound); |
533 public WildcardType(Type type, BoundKind kind, TypeSymbol tsym, TypeVar bound) { |
598 public WildcardType(Type type, BoundKind kind, TypeSymbol tsym, TypeVar bound) { |
534 this(type, kind, tsym); |
599 this(type, kind, tsym); |
535 this.bound = bound; |
600 this.bound = bound; |
536 } |
601 } |
537 |
602 |
|
603 @Override |
|
604 public TypeTag getTag() { |
|
605 return WILDCARD; |
|
606 } |
|
607 |
|
608 @Override |
538 public boolean contains(Type t) { |
609 public boolean contains(Type t) { |
539 return kind != UNBOUND && type.contains(t); |
610 return kind != UNBOUND && type.contains(t); |
540 } |
611 } |
541 |
612 |
542 public boolean isSuperBound() { |
613 public boolean isSuperBound() { |
638 /** All the interfaces of this class, including missing ones. |
720 /** All the interfaces of this class, including missing ones. |
639 */ |
721 */ |
640 public List<Type> all_interfaces_field; |
722 public List<Type> all_interfaces_field; |
641 |
723 |
642 public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) { |
724 public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) { |
643 super(CLASS, tsym); |
725 super(tsym); |
644 this.outer_field = outer; |
726 this.outer_field = outer; |
645 this.typarams_field = typarams; |
727 this.typarams_field = typarams; |
646 this.allparams_field = null; |
728 this.allparams_field = null; |
647 this.supertype_field = null; |
729 this.supertype_field = null; |
648 this.interfaces_field = null; |
730 this.interfaces_field = null; |
678 |
765 |
679 /** The Java source which this type represents. |
766 /** The Java source which this type represents. |
680 */ |
767 */ |
681 public String toString() { |
768 public String toString() { |
682 StringBuilder buf = new StringBuilder(); |
769 StringBuilder buf = new StringBuilder(); |
683 if (getEnclosingType().tag == CLASS && tsym.owner.kind == TYP) { |
770 if (getEnclosingType().hasTag(CLASS) && tsym.owner.kind == TYP) { |
684 buf.append(getEnclosingType().toString()); |
771 buf.append(getEnclosingType().toString()); |
685 buf.append("."); |
772 buf.append("."); |
686 buf.append(className(tsym, false)); |
773 buf.append(className(tsym, false)); |
687 } else { |
774 } else { |
688 buf.append(className(tsym, true)); |
775 buf.append(className(tsym, true)); |
907 implements javax.lang.model.type.ArrayType { |
1004 implements javax.lang.model.type.ArrayType { |
908 |
1005 |
909 public Type elemtype; |
1006 public Type elemtype; |
910 |
1007 |
911 public ArrayType(Type elemtype, TypeSymbol arrayClass) { |
1008 public ArrayType(Type elemtype, TypeSymbol arrayClass) { |
912 super(ARRAY, arrayClass); |
1009 super(arrayClass); |
913 this.elemtype = elemtype; |
1010 this.elemtype = elemtype; |
914 } |
1011 } |
915 |
1012 |
916 @Override |
1013 @Override |
|
1014 public TypeTag getTag() { |
|
1015 return ARRAY; |
|
1016 } |
|
1017 |
917 public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
1018 public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
918 return v.visitArrayType(this, s); |
1019 return v.visitArrayType(this, s); |
919 } |
1020 } |
920 |
1021 |
921 public String toString() { |
1022 public String toString() { |
999 |
1110 |
1000 public MethodType(List<Type> argtypes, |
1111 public MethodType(List<Type> argtypes, |
1001 Type restype, |
1112 Type restype, |
1002 List<Type> thrown, |
1113 List<Type> thrown, |
1003 TypeSymbol methodClass) { |
1114 TypeSymbol methodClass) { |
1004 super(METHOD, methodClass); |
1115 super(methodClass); |
1005 this.argtypes = argtypes; |
1116 this.argtypes = argtypes; |
1006 this.restype = restype; |
1117 this.restype = restype; |
1007 this.thrown = thrown; |
1118 this.thrown = thrown; |
1008 } |
1119 } |
1009 |
1120 |
1010 @Override |
1121 @Override |
|
1122 public TypeTag getTag() { |
|
1123 return METHOD; |
|
1124 } |
|
1125 |
1011 public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
1126 public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
1012 return v.visitMethodType(this, s); |
1127 return v.visitMethodType(this, s); |
1013 } |
1128 } |
1014 |
1129 |
1015 /** The Java source which this type represents. |
1130 /** The Java source which this type represents. |
1118 * Subtypes, such as CapturedType, may provide a different value. |
1238 * Subtypes, such as CapturedType, may provide a different value. |
1119 */ |
1239 */ |
1120 public Type lower; |
1240 public Type lower; |
1121 |
1241 |
1122 public TypeVar(Name name, Symbol owner, Type lower) { |
1242 public TypeVar(Name name, Symbol owner, Type lower) { |
1123 super(TYPEVAR, null); |
1243 super(null); |
1124 tsym = new TypeVariableSymbol(0, name, this, owner); |
1244 tsym = new TypeVariableSymbol(0, name, this, owner); |
1125 this.lower = lower; |
1245 this.lower = lower; |
1126 } |
1246 } |
1127 |
1247 |
1128 public TypeVar(TypeSymbol tsym, Type bound, Type lower) { |
1248 public TypeVar(TypeSymbol tsym, Type bound, Type lower) { |
1129 super(TYPEVAR, tsym); |
1249 super(tsym); |
1130 this.bound = bound; |
1250 this.bound = bound; |
1131 this.lower = lower; |
1251 this.lower = lower; |
1132 } |
1252 } |
1133 |
1253 |
1134 @Override |
1254 @Override |
|
1255 public TypeTag getTag() { |
|
1256 return TYPEVAR; |
|
1257 } |
|
1258 |
|
1259 @Override |
1135 public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
1260 public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
1136 return v.visitTypeVar(this, s); |
1261 return v.visitTypeVar(this, s); |
1137 } |
1262 } |
1138 |
1263 |
1139 @Override |
1264 @Override |
1140 public Type getUpperBound() { |
1265 public Type getUpperBound() { |
1141 if ((bound == null || bound.tag == NONE) && this != tsym.type) |
1266 if ((bound == null || bound.hasTag(NONE)) && this != tsym.type) { |
1142 bound = tsym.type.getUpperBound(); |
1267 bound = tsym.type.getUpperBound(); |
|
1268 } |
1143 return bound; |
1269 return bound; |
1144 } |
1270 } |
1145 |
1271 |
1146 int rank_field = -1; |
1272 int rank_field = -1; |
1147 |
1273 |
1201 } |
1338 } |
1202 } |
1339 } |
1203 |
1340 |
1204 public static abstract class DelegatedType extends Type { |
1341 public static abstract class DelegatedType extends Type { |
1205 public Type qtype; |
1342 public Type qtype; |
|
1343 public TypeTag tag; |
1206 public DelegatedType(TypeTag tag, Type qtype) { |
1344 public DelegatedType(TypeTag tag, Type qtype) { |
1207 super(tag, qtype.tsym); |
1345 super(qtype.tsym); |
|
1346 this.tag = tag; |
1208 this.qtype = qtype; |
1347 this.qtype = qtype; |
1209 } |
1348 } |
|
1349 public TypeTag getTag() { return tag; } |
1210 public String toString() { return qtype.toString(); } |
1350 public String toString() { return qtype.toString(); } |
1211 public List<Type> getTypeArguments() { return qtype.getTypeArguments(); } |
1351 public List<Type> getTypeArguments() { return qtype.getTypeArguments(); } |
1212 public Type getEnclosingType() { return qtype.getEnclosingType(); } |
1352 public Type getEnclosingType() { return qtype.getEnclosingType(); } |
1213 public List<Type> getParameterTypes() { return qtype.getParameterTypes(); } |
1353 public List<Type> getParameterTypes() { return qtype.getParameterTypes(); } |
1214 public Type getReturnType() { return qtype.getReturnType(); } |
1354 public Type getReturnType() { return qtype.getReturnType(); } |
1437 listener.varChanged(this, ibs); |
1583 listener.varChanged(this, ibs); |
1438 } |
1584 } |
1439 } |
1585 } |
1440 } |
1586 } |
1441 |
1587 |
1442 /** Represents VOID or NONE. |
1588 /** Represents NONE. |
1443 */ |
1589 */ |
1444 static class JCNoType extends Type implements NoType { |
1590 public static class JCNoType extends Type implements NoType { |
1445 public JCNoType(TypeTag tag) { |
1591 public JCNoType() { |
1446 super(tag, null); |
1592 super(null); |
|
1593 } |
|
1594 |
|
1595 @Override |
|
1596 public TypeTag getTag() { |
|
1597 return NONE; |
1447 } |
1598 } |
1448 |
1599 |
1449 @Override |
1600 @Override |
1450 public TypeKind getKind() { |
1601 public TypeKind getKind() { |
1451 switch (tag) { |
1602 return TypeKind.NONE; |
1452 case VOID: return TypeKind.VOID; |
|
1453 case NONE: return TypeKind.NONE; |
|
1454 default: |
|
1455 throw new AssertionError("Unexpected tag: " + tag); |
|
1456 } |
|
1457 } |
1603 } |
1458 |
1604 |
1459 @Override |
1605 @Override |
1460 public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
1606 public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
1461 return v.visitNoType(this, p); |
1607 return v.visitNoType(this, p); |
1462 } |
1608 } |
1463 } |
1609 } |
1464 |
1610 |
|
1611 /** Represents VOID. |
|
1612 */ |
|
1613 public static class JCVoidType extends Type implements NoType { |
|
1614 |
|
1615 public JCVoidType() { |
|
1616 super(null); |
|
1617 } |
|
1618 |
|
1619 @Override |
|
1620 public TypeTag getTag() { |
|
1621 return VOID; |
|
1622 } |
|
1623 |
|
1624 @Override |
|
1625 public TypeKind getKind() { |
|
1626 return TypeKind.VOID; |
|
1627 } |
|
1628 |
|
1629 @Override |
|
1630 public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
|
1631 return v.visitNoType(this, p); |
|
1632 } |
|
1633 |
|
1634 @Override |
|
1635 public boolean isPrimitiveOrVoid() { |
|
1636 return true; |
|
1637 } |
|
1638 } |
|
1639 |
1465 static class BottomType extends Type implements NullType { |
1640 static class BottomType extends Type implements NullType { |
1466 public BottomType() { |
1641 public BottomType() { |
1467 super(BOT, null); |
1642 super(null); |
|
1643 } |
|
1644 |
|
1645 @Override |
|
1646 public TypeTag getTag() { |
|
1647 return BOT; |
1468 } |
1648 } |
1469 |
1649 |
1470 @Override |
1650 @Override |
1471 public TypeKind getKind() { |
1651 public TypeKind getKind() { |
1472 return TypeKind.NULL; |
1652 return TypeKind.NULL; |
1484 |
1664 |
1485 @Override |
1665 @Override |
1486 public String stringValue() { |
1666 public String stringValue() { |
1487 return "null"; |
1667 return "null"; |
1488 } |
1668 } |
|
1669 |
|
1670 @Override |
|
1671 public boolean isNullOrReference() { |
|
1672 return true; |
|
1673 } |
|
1674 |
1489 } |
1675 } |
1490 |
1676 |
1491 public static class ErrorType extends ClassType |
1677 public static class ErrorType extends ClassType |
1492 implements javax.lang.model.type.ErrorType { |
1678 implements javax.lang.model.type.ErrorType { |
1493 |
1679 |
1494 private Type originalType = null; |
1680 private Type originalType = null; |
1495 |
1681 |
1496 public ErrorType(Type originalType, TypeSymbol tsym) { |
1682 public ErrorType(Type originalType, TypeSymbol tsym) { |
1497 super(noType, List.<Type>nil(), null); |
1683 super(noType, List.<Type>nil(), null); |
1498 tag = ERROR; |
|
1499 this.tsym = tsym; |
1684 this.tsym = tsym; |
1500 this.originalType = (originalType == null ? noType : originalType); |
1685 this.originalType = (originalType == null ? noType : originalType); |
1501 } |
1686 } |
1502 |
1687 |
1503 public ErrorType(ClassSymbol c, Type originalType) { |
1688 public ErrorType(ClassSymbol c, Type originalType) { |
1504 this(originalType, c); |
1689 this(originalType, c); |
1505 c.type = this; |
1690 c.type = this; |
1506 c.kind = ERR; |
1691 c.kind = ERR; |
1507 c.members_field = new Scope.ErrorScope(c); |
1692 c.members_field = new Scope.ErrorScope(c); |
|
1693 } |
|
1694 |
|
1695 @Override |
|
1696 public TypeTag getTag() { |
|
1697 return ERROR; |
|
1698 } |
|
1699 |
|
1700 @Override |
|
1701 public boolean isPartial() { |
|
1702 return true; |
|
1703 } |
|
1704 |
|
1705 @Override |
|
1706 public boolean isReference() { |
|
1707 return true; |
|
1708 } |
|
1709 |
|
1710 @Override |
|
1711 public boolean isNullOrReference() { |
|
1712 return true; |
1508 } |
1713 } |
1509 |
1714 |
1510 public ErrorType(Name name, TypeSymbol container, Type originalType) { |
1715 public ErrorType(Name name, TypeSymbol container, Type originalType) { |
1511 this(new ClassSymbol(PUBLIC|STATIC|ACYCLIC, name, null, container), originalType); |
1716 this(new ClassSymbol(PUBLIC|STATIC|ACYCLIC, name, null, container), originalType); |
1512 } |
1717 } |
1557 /** The underlying type that is annotated. |
1762 /** The underlying type that is annotated. |
1558 */ |
1763 */ |
1559 public Type underlyingType; |
1764 public Type underlyingType; |
1560 |
1765 |
1561 public AnnotatedType(Type underlyingType) { |
1766 public AnnotatedType(Type underlyingType) { |
1562 super(underlyingType.tag, underlyingType.tsym); |
1767 super(underlyingType.tsym); |
1563 this.typeAnnotations = List.nil(); |
1768 this.typeAnnotations = List.nil(); |
1564 this.underlyingType = underlyingType; |
1769 this.underlyingType = underlyingType; |
1565 Assert.check(!underlyingType.isAnnotated(), |
1770 Assert.check(!underlyingType.isAnnotated(), |
1566 "Can't annotate already annotated type: " + underlyingType); |
1771 "Can't annotate already annotated type: " + underlyingType); |
1567 } |
1772 } |
1568 |
1773 |
1569 public AnnotatedType(List<Attribute.TypeCompound> typeAnnotations, |
1774 public AnnotatedType(List<Attribute.TypeCompound> typeAnnotations, |
1570 Type underlyingType) { |
1775 Type underlyingType) { |
1571 super(underlyingType.tag, underlyingType.tsym); |
1776 super(underlyingType.tsym); |
1572 this.typeAnnotations = typeAnnotations; |
1777 this.typeAnnotations = typeAnnotations; |
1573 this.underlyingType = underlyingType; |
1778 this.underlyingType = underlyingType; |
1574 Assert.check(!underlyingType.isAnnotated(), |
1779 Assert.check(!underlyingType.isAnnotated(), |
1575 "Can't annotate already annotated type: " + underlyingType + |
1780 "Can't annotate already annotated type: " + underlyingType + |
1576 "; adding: " + typeAnnotations); |
1781 "; adding: " + typeAnnotations); |
1577 } |
1782 } |
1578 |
1783 |
1579 @Override |
1784 @Override |
|
1785 public TypeTag getTag() { |
|
1786 return underlyingType.getTag(); |
|
1787 } |
|
1788 |
|
1789 @Override |
1580 public boolean isAnnotated() { |
1790 public boolean isAnnotated() { |
1581 return true; |
1791 return true; |
1582 } |
1792 } |
1583 |
1793 |
1584 @Override |
1794 @Override |
1649 @Override |
1859 @Override |
1650 public boolean isInterface() { return underlyingType.isInterface(); } |
1860 public boolean isInterface() { return underlyingType.isInterface(); } |
1651 @Override |
1861 @Override |
1652 public List<Type> allparams() { return underlyingType.allparams(); } |
1862 public List<Type> allparams() { return underlyingType.allparams(); } |
1653 @Override |
1863 @Override |
|
1864 public boolean isPrimitive() { return underlyingType.isPrimitive(); } |
|
1865 @Override |
|
1866 public boolean isPrimitiveOrVoid() { return underlyingType.isPrimitiveOrVoid(); } |
|
1867 @Override |
1654 public boolean isNumeric() { return underlyingType.isNumeric(); } |
1868 public boolean isNumeric() { return underlyingType.isNumeric(); } |
1655 @Override |
1869 @Override |
1656 public boolean isReference() { return underlyingType.isReference(); } |
1870 public boolean isReference() { return underlyingType.isReference(); } |
|
1871 @Override |
|
1872 public boolean isNullOrReference() { return underlyingType.isNullOrReference(); } |
|
1873 @Override |
|
1874 public boolean isPartial() { return underlyingType.isPartial(); } |
1657 @Override |
1875 @Override |
1658 public boolean isParameterized() { return underlyingType.isParameterized(); } |
1876 public boolean isParameterized() { return underlyingType.isParameterized(); } |
1659 @Override |
1877 @Override |
1660 public boolean isRaw() { return underlyingType.isRaw(); } |
1878 public boolean isRaw() { return underlyingType.isRaw(); } |
1661 @Override |
1879 @Override |
1715 |
1933 |
1716 @Override |
1934 @Override |
1717 public TypeMirror getExtendsBound() { return ((WildcardType)underlyingType).getExtendsBound(); } |
1935 public TypeMirror getExtendsBound() { return ((WildcardType)underlyingType).getExtendsBound(); } |
1718 @Override |
1936 @Override |
1719 public TypeMirror getSuperBound() { return ((WildcardType)underlyingType).getSuperBound(); } |
1937 public TypeMirror getSuperBound() { return ((WildcardType)underlyingType).getSuperBound(); } |
|
1938 } |
|
1939 |
|
1940 public static class UnknownType extends Type { |
|
1941 |
|
1942 public UnknownType() { |
|
1943 super(null); |
|
1944 } |
|
1945 |
|
1946 @Override |
|
1947 public TypeTag getTag() { |
|
1948 return UNKNOWN; |
|
1949 } |
|
1950 |
|
1951 @Override |
|
1952 public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
|
1953 return v.visitUnknown(this, p); |
|
1954 } |
|
1955 |
|
1956 @Override |
|
1957 public boolean isPartial() { |
|
1958 return true; |
|
1959 } |
1720 } |
1960 } |
1721 |
1961 |
1722 /** |
1962 /** |
1723 * A visitor for types. A visitor is used to implement operations |
1963 * A visitor for types. A visitor is used to implement operations |
1724 * (or relations) on types. Most common operations on types are |
1964 * (or relations) on types. Most common operations on types are |