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

changeset 1268
af6a4c24f4e3
parent 1251
6f0ed5a89c25
child 1305
9d47f4850714
equal deleted inserted replaced
1267:f43aded513e7 1268:af6a4c24f4e3
52 * array types (tag: ARRAY, class: ArrayType), 52 * array types (tag: ARRAY, class: ArrayType),
53 * method types (tag: METHOD, class: MethodType), 53 * method types (tag: METHOD, class: MethodType),
54 * package types (tag: PACKAGE, class: PackageType), 54 * package types (tag: PACKAGE, class: PackageType),
55 * type variables (tag: TYPEVAR, class: TypeVar), 55 * type variables (tag: TYPEVAR, class: TypeVar),
56 * type arguments (tag: WILDCARD, class: WildcardType), 56 * type arguments (tag: WILDCARD, class: WildcardType),
57 * polymorphic types (tag: FORALL, class: ForAll), 57 * generic method types (tag: FORALL, class: ForAll),
58 * the error type (tag: ERROR, class: ErrorType). 58 * the error type (tag: ERROR, class: ErrorType).
59 * </pre> 59 * </pre>
60 * 60 *
61 * <p><b>This is NOT part of any supported API. 61 * <p><b>This is NOT part of any supported API.
62 * If you write code that depends on this, you do so at your own risk. 62 * If you write code that depends on this, you do so at your own risk.
1106 public List<Type> allparams() { return qtype.allparams(); } 1106 public List<Type> allparams() { return qtype.allparams(); }
1107 public Type getUpperBound() { return qtype.getUpperBound(); } 1107 public Type getUpperBound() { return qtype.getUpperBound(); }
1108 public boolean isErroneous() { return qtype.isErroneous(); } 1108 public boolean isErroneous() { return qtype.isErroneous(); }
1109 } 1109 }
1110 1110
1111 /**
1112 * The type of a generic method type. It consists of a method type and
1113 * a list of method type-parameters that are used within the method
1114 * type.
1115 */
1111 public static class ForAll extends DelegatedType implements ExecutableType { 1116 public static class ForAll extends DelegatedType implements ExecutableType {
1112 public List<Type> tvars; 1117 public List<Type> tvars;
1113 1118
1114 public ForAll(List<Type> tvars, Type qtype) { 1119 public ForAll(List<Type> tvars, Type qtype) {
1115 super(FORALL, qtype); 1120 super(FORALL, (MethodType)qtype);
1116 this.tvars = tvars; 1121 this.tvars = tvars;
1117 } 1122 }
1118 1123
1119 @Override 1124 @Override
1120 public <R,S> R accept(Type.Visitor<R,S> v, S s) { 1125 public <R,S> R accept(Type.Visitor<R,S> v, S s) {
1129 1134
1130 public boolean isErroneous() { 1135 public boolean isErroneous() {
1131 return qtype.isErroneous(); 1136 return qtype.isErroneous();
1132 } 1137 }
1133 1138
1134 /**
1135 * Replaces this ForAll's typevars with a set of concrete Java types
1136 * and returns the instantiated generic type. Subclasses should override
1137 * in order to check that the list of types is a valid instantiation
1138 * of the ForAll's typevars.
1139 *
1140 * @param actuals list of actual types
1141 * @param types types instance
1142 * @return qtype where all occurrences of tvars are replaced
1143 * by types in actuals
1144 */
1145 public Type inst(List<Type> actuals, Types types) {
1146 return types.subst(qtype, tvars, actuals);
1147 }
1148
1149 /**
1150 * Get the type-constraints of a given kind for a given type-variable of
1151 * this ForAll type. Subclasses should override in order to return more
1152 * accurate sets of constraints.
1153 *
1154 * @param tv the type-variable for which the constraint is to be retrieved
1155 * @param ck the constraint kind to be retrieved
1156 * @return the list of types specified by the selected constraint
1157 */
1158 public List<Type> undetvars() {
1159 return List.nil();
1160 }
1161
1162 public Type map(Mapping f) { 1139 public Type map(Mapping f) {
1163 return f.apply(qtype); 1140 return f.apply(qtype);
1164 } 1141 }
1165 1142
1166 public boolean contains(Type elem) { 1143 public boolean contains(Type elem) {
1167 return qtype.contains(elem); 1144 return qtype.contains(elem);
1168 } 1145 }
1169 1146
1170 public MethodType asMethodType() { 1147 public MethodType asMethodType() {
1171 return qtype.asMethodType(); 1148 return (MethodType)qtype;
1172 } 1149 }
1173 1150
1174 public void complete() { 1151 public void complete() {
1175 for (List<Type> l = tvars; l.nonEmpty(); l = l.tail) { 1152 for (List<Type> l = tvars; l.nonEmpty(); l = l.tail) {
1176 ((TypeVar)l.head).bound.complete(); 1153 ((TypeVar)l.head).bound.complete();

mercurial