author | jjh |
Wed, 15 Aug 2012 13:48:46 -0700 | |
changeset 13631 | dc1212c348f9 |
parent 12915 | 28cf1e0dafdc |
child 13844 | 56339cf983a3 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
13631
dc1212c348f9
7191449: update copyright year to match last edit in jdk8 langtools repository
jjh
parents:
12915
diff
changeset
|
2 |
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 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. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.code; |
|
27 |
||
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
28 |
import java.util.Collections; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
29 |
|
10 | 30 |
import com.sun.tools.javac.util.*; |
31 |
import com.sun.tools.javac.code.Symbol.*; |
|
32 |
||
33 |
import javax.lang.model.type.*; |
|
34 |
||
35 |
import static com.sun.tools.javac.code.Flags.*; |
|
36 |
import static com.sun.tools.javac.code.Kinds.*; |
|
37 |
import static com.sun.tools.javac.code.BoundKind.*; |
|
38 |
import static com.sun.tools.javac.code.TypeTags.*; |
|
39 |
||
40 |
/** This class represents Java types. The class itself defines the behavior of |
|
41 |
* the following types: |
|
42 |
* <pre> |
|
43 |
* base types (tags: BYTE, CHAR, SHORT, INT, LONG, FLOAT, DOUBLE, BOOLEAN), |
|
44 |
* type `void' (tag: VOID), |
|
45 |
* the bottom type (tag: BOT), |
|
46 |
* the missing type (tag: NONE). |
|
47 |
* </pre> |
|
48 |
* <p>The behavior of the following types is defined in subclasses, which are |
|
49 |
* all static inner classes of this class: |
|
50 |
* <pre> |
|
51 |
* class types (tag: CLASS, class: ClassType), |
|
52 |
* array types (tag: ARRAY, class: ArrayType), |
|
53 |
* method types (tag: METHOD, class: MethodType), |
|
54 |
* package types (tag: PACKAGE, class: PackageType), |
|
55 |
* type variables (tag: TYPEVAR, class: TypeVar), |
|
56 |
* type arguments (tag: WILDCARD, class: WildcardType), |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
57 |
* generic method types (tag: FORALL, class: ForAll), |
10 | 58 |
* the error type (tag: ERROR, class: ErrorType). |
59 |
* </pre> |
|
60 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
61 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
62 |
* If you write code that depends on this, you do so at your own risk. |
10 | 63 |
* This code and its internal interfaces are subject to change or |
64 |
* deletion without notice.</b> |
|
65 |
* |
|
66 |
* @see TypeTags |
|
67 |
*/ |
|
68 |
public class Type implements PrimitiveType { |
|
69 |
||
70 |
/** Constant type: no type at all. */ |
|
71 |
public static final JCNoType noType = new JCNoType(NONE); |
|
72 |
||
73 |
/** If this switch is turned on, the names of type variables |
|
74 |
* and anonymous classes are printed with hashcodes appended. |
|
75 |
*/ |
|
76 |
public static boolean moreInfo = false; |
|
77 |
||
78 |
/** The tag of this type. |
|
79 |
* |
|
80 |
* @see TypeTags |
|
81 |
*/ |
|
82 |
public int tag; |
|
83 |
||
84 |
/** The defining class / interface / package / type variable |
|
85 |
*/ |
|
86 |
public TypeSymbol tsym; |
|
87 |
||
88 |
/** |
|
89 |
* The constant value of this type, null if this type does not |
|
90 |
* have a constant value attribute. Only primitive types and |
|
91 |
* strings (ClassType) can have a constant value attribute. |
|
92 |
* @return the constant value attribute of this type |
|
93 |
*/ |
|
94 |
public Object constValue() { |
|
95 |
return null; |
|
96 |
} |
|
97 |
||
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
98 |
/** |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
99 |
* Get the representation of this type used for modelling purposes. |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
100 |
* By default, this is itself. For ErrorType, a different value |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
101 |
* may be provided, |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
102 |
*/ |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
103 |
public Type getModelType() { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
104 |
return this; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
105 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
106 |
|
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
107 |
public static List<Type> getModelTypes(List<Type> ts) { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
108 |
ListBuffer<Type> lb = new ListBuffer<Type>(); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
109 |
for (Type t: ts) |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
110 |
lb.append(t.getModelType()); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
111 |
return lb.toList(); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
112 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
113 |
|
10 | 114 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { return v.visitType(this, s); } |
115 |
||
116 |
/** Define a type given its tag and type symbol |
|
117 |
*/ |
|
118 |
public Type(int tag, TypeSymbol tsym) { |
|
119 |
this.tag = tag; |
|
120 |
this.tsym = tsym; |
|
121 |
} |
|
122 |
||
123 |
/** An abstract class for mappings from types to types |
|
124 |
*/ |
|
125 |
public static abstract class Mapping { |
|
126 |
private String name; |
|
127 |
public Mapping(String name) { |
|
128 |
this.name = name; |
|
129 |
} |
|
130 |
public abstract Type apply(Type t); |
|
131 |
public String toString() { |
|
132 |
return name; |
|
133 |
} |
|
134 |
} |
|
135 |
||
136 |
/** map a type function over all immediate descendants of this type |
|
137 |
*/ |
|
138 |
public Type map(Mapping f) { |
|
139 |
return this; |
|
140 |
} |
|
141 |
||
142 |
/** map a type function over a list of types |
|
143 |
*/ |
|
144 |
public static List<Type> map(List<Type> ts, Mapping f) { |
|
145 |
if (ts.nonEmpty()) { |
|
146 |
List<Type> tail1 = map(ts.tail, f); |
|
147 |
Type t = f.apply(ts.head); |
|
148 |
if (tail1 != ts.tail || t != ts.head) |
|
149 |
return tail1.prepend(t); |
|
150 |
} |
|
151 |
return ts; |
|
152 |
} |
|
153 |
||
154 |
/** Define a constant type, of the same kind as this type |
|
155 |
* and with given constant value |
|
156 |
*/ |
|
157 |
public Type constType(Object constValue) { |
|
158 |
final Object value = constValue; |
|
8032 | 159 |
Assert.check(tag <= BOOLEAN); |
10 | 160 |
return new Type(tag, tsym) { |
161 |
@Override |
|
162 |
public Object constValue() { |
|
163 |
return value; |
|
164 |
} |
|
165 |
@Override |
|
166 |
public Type baseType() { |
|
167 |
return tsym.type; |
|
168 |
} |
|
169 |
}; |
|
170 |
} |
|
171 |
||
172 |
/** |
|
173 |
* If this is a constant type, return its underlying type. |
|
174 |
* Otherwise, return the type itself. |
|
175 |
*/ |
|
176 |
public Type baseType() { |
|
177 |
return this; |
|
178 |
} |
|
179 |
||
180 |
/** Return the base types of a list of types. |
|
181 |
*/ |
|
182 |
public static List<Type> baseTypes(List<Type> ts) { |
|
183 |
if (ts.nonEmpty()) { |
|
184 |
Type t = ts.head.baseType(); |
|
185 |
List<Type> baseTypes = baseTypes(ts.tail); |
|
186 |
if (t != ts.head || baseTypes != ts.tail) |
|
187 |
return baseTypes.prepend(t); |
|
188 |
} |
|
189 |
return ts; |
|
190 |
} |
|
191 |
||
192 |
/** The Java source which this type represents. |
|
193 |
*/ |
|
194 |
public String toString() { |
|
195 |
String s = (tsym == null || tsym.name == null) |
|
196 |
? "<none>" |
|
197 |
: tsym.name.toString(); |
|
198 |
if (moreInfo && tag == TYPEVAR) s = s + hashCode(); |
|
199 |
return s; |
|
200 |
} |
|
201 |
||
202 |
/** |
|
203 |
* The Java source which this type list represents. A List is |
|
204 |
* represented as a comma-spearated listing of the elements in |
|
205 |
* that list. |
|
206 |
*/ |
|
207 |
public static String toString(List<Type> ts) { |
|
208 |
if (ts.isEmpty()) { |
|
209 |
return ""; |
|
210 |
} else { |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
211 |
StringBuilder buf = new StringBuilder(); |
10 | 212 |
buf.append(ts.head.toString()); |
213 |
for (List<Type> l = ts.tail; l.nonEmpty(); l = l.tail) |
|
214 |
buf.append(",").append(l.head.toString()); |
|
215 |
return buf.toString(); |
|
216 |
} |
|
217 |
} |
|
218 |
||
219 |
/** |
|
220 |
* The constant value of this type, converted to String |
|
221 |
*/ |
|
222 |
public String stringValue() { |
|
8032 | 223 |
Object cv = Assert.checkNonNull(constValue()); |
10 | 224 |
if (tag == BOOLEAN) |
8032 | 225 |
return ((Integer) cv).intValue() == 0 ? "false" : "true"; |
10 | 226 |
else if (tag == CHAR) |
8032 | 227 |
return String.valueOf((char) ((Integer) cv).intValue()); |
10 | 228 |
else |
8032 | 229 |
return cv.toString(); |
10 | 230 |
} |
231 |
||
232 |
/** |
|
233 |
* This method is analogous to isSameType, but weaker, since we |
|
234 |
* never complete classes. Where isSameType would complete a |
|
235 |
* class, equals assumes that the two types are different. |
|
236 |
*/ |
|
237 |
public boolean equals(Object t) { |
|
238 |
return super.equals(t); |
|
239 |
} |
|
240 |
||
241 |
public int hashCode() { |
|
242 |
return super.hashCode(); |
|
243 |
} |
|
244 |
||
245 |
/** Is this a constant type whose value is false? |
|
246 |
*/ |
|
247 |
public boolean isFalse() { |
|
248 |
return |
|
249 |
tag == BOOLEAN && |
|
250 |
constValue() != null && |
|
251 |
((Integer)constValue()).intValue() == 0; |
|
252 |
} |
|
253 |
||
254 |
/** Is this a constant type whose value is true? |
|
255 |
*/ |
|
256 |
public boolean isTrue() { |
|
257 |
return |
|
258 |
tag == BOOLEAN && |
|
259 |
constValue() != null && |
|
260 |
((Integer)constValue()).intValue() != 0; |
|
261 |
} |
|
262 |
||
263 |
public String argtypes(boolean varargs) { |
|
264 |
List<Type> args = getParameterTypes(); |
|
265 |
if (!varargs) return args.toString(); |
|
7637 | 266 |
StringBuilder buf = new StringBuilder(); |
10 | 267 |
while (args.tail.nonEmpty()) { |
268 |
buf.append(args.head); |
|
269 |
args = args.tail; |
|
270 |
buf.append(','); |
|
271 |
} |
|
272 |
if (args.head.tag == ARRAY) { |
|
273 |
buf.append(((ArrayType)args.head).elemtype); |
|
274 |
buf.append("..."); |
|
275 |
} else { |
|
276 |
buf.append(args.head); |
|
277 |
} |
|
278 |
return buf.toString(); |
|
279 |
} |
|
280 |
||
281 |
/** Access methods. |
|
282 |
*/ |
|
283 |
public List<Type> getTypeArguments() { return List.nil(); } |
|
284 |
public Type getEnclosingType() { return null; } |
|
285 |
public List<Type> getParameterTypes() { return List.nil(); } |
|
286 |
public Type getReturnType() { return null; } |
|
287 |
public List<Type> getThrownTypes() { return List.nil(); } |
|
288 |
public Type getUpperBound() { return null; } |
|
289 |
public Type getLowerBound() { return null; } |
|
290 |
||
291 |
/** Navigation methods, these will work for classes, type variables, |
|
292 |
* foralls, but will return null for arrays and methods. |
|
293 |
*/ |
|
294 |
||
295 |
/** Return all parameters of this type and all its outer types in order |
|
296 |
* outer (first) to inner (last). |
|
297 |
*/ |
|
298 |
public List<Type> allparams() { return List.nil(); } |
|
299 |
||
300 |
/** Does this type contain "error" elements? |
|
301 |
*/ |
|
302 |
public boolean isErroneous() { |
|
303 |
return false; |
|
304 |
} |
|
305 |
||
306 |
public static boolean isErroneous(List<Type> ts) { |
|
307 |
for (List<Type> l = ts; l.nonEmpty(); l = l.tail) |
|
308 |
if (l.head.isErroneous()) return true; |
|
309 |
return false; |
|
310 |
} |
|
311 |
||
312 |
/** Is this type parameterized? |
|
313 |
* A class type is parameterized if it has some parameters. |
|
314 |
* An array type is parameterized if its element type is parameterized. |
|
315 |
* All other types are not parameterized. |
|
316 |
*/ |
|
317 |
public boolean isParameterized() { |
|
318 |
return false; |
|
319 |
} |
|
320 |
||
321 |
/** Is this type a raw type? |
|
322 |
* A class type is a raw type if it misses some of its parameters. |
|
323 |
* An array type is a raw type if its element type is raw. |
|
324 |
* All other types are not raw. |
|
325 |
* Type validation will ensure that the only raw types |
|
326 |
* in a program are types that miss all their type variables. |
|
327 |
*/ |
|
328 |
public boolean isRaw() { |
|
329 |
return false; |
|
330 |
} |
|
331 |
||
332 |
public boolean isCompound() { |
|
333 |
return tsym.completer == null |
|
334 |
// Compound types can't have a completer. Calling |
|
335 |
// flags() will complete the symbol causing the |
|
336 |
// compiler to load classes unnecessarily. This led |
|
337 |
// to regression 6180021. |
|
338 |
&& (tsym.flags() & COMPOUND) != 0; |
|
339 |
} |
|
340 |
||
341 |
public boolean isInterface() { |
|
342 |
return (tsym.flags() & INTERFACE) != 0; |
|
343 |
} |
|
344 |
||
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6348
diff
changeset
|
345 |
public boolean isFinal() { |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6348
diff
changeset
|
346 |
return (tsym.flags() & FINAL) != 0; |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6348
diff
changeset
|
347 |
} |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6348
diff
changeset
|
348 |
|
10 | 349 |
public boolean isPrimitive() { |
350 |
return tag < VOID; |
|
351 |
} |
|
352 |
||
353 |
/** |
|
354 |
* Does this type contain occurrences of type t? |
|
355 |
*/ |
|
356 |
public boolean contains(Type t) { |
|
357 |
return t == this; |
|
358 |
} |
|
359 |
||
360 |
public static boolean contains(List<Type> ts, Type t) { |
|
361 |
for (List<Type> l = ts; |
|
362 |
l.tail != null /*inlined: l.nonEmpty()*/; |
|
363 |
l = l.tail) |
|
364 |
if (l.head.contains(t)) return true; |
|
365 |
return false; |
|
366 |
} |
|
367 |
||
6348
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
368 |
/** Does this type contain an occurrence of some type in 'ts'? |
10 | 369 |
*/ |
6348
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
370 |
public boolean containsAny(List<Type> ts) { |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
371 |
for (Type t : ts) |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
372 |
if (this.contains(t)) return true; |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
373 |
return false; |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
374 |
} |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
375 |
|
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
376 |
public static boolean containsAny(List<Type> ts1, List<Type> ts2) { |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
377 |
for (Type t : ts1) |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
378 |
if (t.containsAny(ts2)) return true; |
10 | 379 |
return false; |
380 |
} |
|
381 |
||
8044
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
382 |
public static List<Type> filter(List<Type> ts, Filter<Type> tf) { |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
383 |
ListBuffer<Type> buf = ListBuffer.lb(); |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
384 |
for (Type t : ts) { |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
385 |
if (tf.accepts(t)) { |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
386 |
buf.append(t); |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
387 |
} |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
388 |
} |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
389 |
return buf.toList(); |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
390 |
} |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
391 |
|
10 | 392 |
public boolean isSuperBound() { return false; } |
393 |
public boolean isExtendsBound() { return false; } |
|
394 |
public boolean isUnbound() { return false; } |
|
395 |
public Type withTypeVar(Type t) { return this; } |
|
396 |
||
397 |
/** The underlying method type of this type. |
|
398 |
*/ |
|
399 |
public MethodType asMethodType() { throw new AssertionError(); } |
|
400 |
||
401 |
/** Complete loading all classes in this type. |
|
402 |
*/ |
|
403 |
public void complete() {} |
|
404 |
||
405 |
public TypeSymbol asElement() { |
|
406 |
return tsym; |
|
407 |
} |
|
408 |
||
409 |
public TypeKind getKind() { |
|
410 |
switch (tag) { |
|
411 |
case BYTE: return TypeKind.BYTE; |
|
412 |
case CHAR: return TypeKind.CHAR; |
|
413 |
case SHORT: return TypeKind.SHORT; |
|
414 |
case INT: return TypeKind.INT; |
|
415 |
case LONG: return TypeKind.LONG; |
|
416 |
case FLOAT: return TypeKind.FLOAT; |
|
417 |
case DOUBLE: return TypeKind.DOUBLE; |
|
418 |
case BOOLEAN: return TypeKind.BOOLEAN; |
|
419 |
case VOID: return TypeKind.VOID; |
|
420 |
case BOT: return TypeKind.NULL; |
|
421 |
case NONE: return TypeKind.NONE; |
|
422 |
default: return TypeKind.OTHER; |
|
423 |
} |
|
424 |
} |
|
425 |
||
426 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
|
427 |
if (isPrimitive()) |
|
428 |
return v.visitPrimitive(this, p); |
|
429 |
else |
|
430 |
throw new AssertionError(); |
|
431 |
} |
|
432 |
||
433 |
public static class WildcardType extends Type |
|
434 |
implements javax.lang.model.type.WildcardType { |
|
435 |
||
436 |
public Type type; |
|
437 |
public BoundKind kind; |
|
438 |
public TypeVar bound; |
|
439 |
||
440 |
@Override |
|
441 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
442 |
return v.visitWildcardType(this, s); |
|
443 |
} |
|
444 |
||
445 |
public WildcardType(Type type, BoundKind kind, TypeSymbol tsym) { |
|
446 |
super(WILDCARD, tsym); |
|
8032 | 447 |
this.type = Assert.checkNonNull(type); |
10 | 448 |
this.kind = kind; |
449 |
} |
|
450 |
public WildcardType(WildcardType t, TypeVar bound) { |
|
451 |
this(t.type, t.kind, t.tsym, bound); |
|
452 |
} |
|
453 |
||
454 |
public WildcardType(Type type, BoundKind kind, TypeSymbol tsym, TypeVar bound) { |
|
455 |
this(type, kind, tsym); |
|
456 |
this.bound = bound; |
|
457 |
} |
|
458 |
||
6348
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
459 |
public boolean contains(Type t) { |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
460 |
return kind != UNBOUND && type.contains(t); |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
461 |
} |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
462 |
|
10 | 463 |
public boolean isSuperBound() { |
464 |
return kind == SUPER || |
|
465 |
kind == UNBOUND; |
|
466 |
} |
|
467 |
public boolean isExtendsBound() { |
|
468 |
return kind == EXTENDS || |
|
469 |
kind == UNBOUND; |
|
470 |
} |
|
471 |
public boolean isUnbound() { |
|
472 |
return kind == UNBOUND; |
|
473 |
} |
|
474 |
||
475 |
public Type withTypeVar(Type t) { |
|
476 |
//-System.err.println(this+".withTypeVar("+t+");");//DEBUG |
|
477 |
if (bound == t) |
|
478 |
return this; |
|
479 |
bound = (TypeVar)t; |
|
480 |
return this; |
|
481 |
} |
|
482 |
||
483 |
boolean isPrintingBound = false; |
|
484 |
public String toString() { |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
485 |
StringBuilder s = new StringBuilder(); |
10 | 486 |
s.append(kind.toString()); |
487 |
if (kind != UNBOUND) |
|
488 |
s.append(type); |
|
489 |
if (moreInfo && bound != null && !isPrintingBound) |
|
490 |
try { |
|
491 |
isPrintingBound = true; |
|
492 |
s.append("{:").append(bound.bound).append(":}"); |
|
493 |
} finally { |
|
494 |
isPrintingBound = false; |
|
495 |
} |
|
496 |
return s.toString(); |
|
497 |
} |
|
498 |
||
499 |
public Type map(Mapping f) { |
|
500 |
//- System.err.println(" (" + this + ").map(" + f + ")");//DEBUG |
|
501 |
Type t = type; |
|
502 |
if (t != null) |
|
503 |
t = f.apply(t); |
|
504 |
if (t == type) |
|
505 |
return this; |
|
506 |
else |
|
507 |
return new WildcardType(t, kind, tsym, bound); |
|
508 |
} |
|
509 |
||
510 |
public Type getExtendsBound() { |
|
511 |
if (kind == EXTENDS) |
|
512 |
return type; |
|
513 |
else |
|
514 |
return null; |
|
515 |
} |
|
516 |
||
517 |
public Type getSuperBound() { |
|
518 |
if (kind == SUPER) |
|
519 |
return type; |
|
520 |
else |
|
521 |
return null; |
|
522 |
} |
|
523 |
||
524 |
public TypeKind getKind() { |
|
525 |
return TypeKind.WILDCARD; |
|
526 |
} |
|
527 |
||
528 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
|
529 |
return v.visitWildcard(this, p); |
|
530 |
} |
|
531 |
} |
|
532 |
||
533 |
public static class ClassType extends Type implements DeclaredType { |
|
534 |
||
535 |
/** The enclosing type of this type. If this is the type of an inner |
|
536 |
* class, outer_field refers to the type of its enclosing |
|
537 |
* instance class, in all other cases it referes to noType. |
|
538 |
*/ |
|
539 |
private Type outer_field; |
|
540 |
||
541 |
/** The type parameters of this type (to be set once class is loaded). |
|
542 |
*/ |
|
543 |
public List<Type> typarams_field; |
|
544 |
||
545 |
/** A cache variable for the type parameters of this type, |
|
546 |
* appended to all parameters of its enclosing class. |
|
547 |
* @see #allparams |
|
548 |
*/ |
|
549 |
public List<Type> allparams_field; |
|
550 |
||
551 |
/** The supertype of this class (to be set once class is loaded). |
|
552 |
*/ |
|
553 |
public Type supertype_field; |
|
554 |
||
555 |
/** The interfaces of this class (to be set once class is loaded). |
|
556 |
*/ |
|
557 |
public List<Type> interfaces_field; |
|
558 |
||
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
559 |
/** All the interfaces of this class, including missing ones. |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
560 |
*/ |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
561 |
public List<Type> all_interfaces_field; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
562 |
|
10 | 563 |
public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) { |
564 |
super(CLASS, tsym); |
|
565 |
this.outer_field = outer; |
|
566 |
this.typarams_field = typarams; |
|
567 |
this.allparams_field = null; |
|
568 |
this.supertype_field = null; |
|
569 |
this.interfaces_field = null; |
|
570 |
/* |
|
571 |
// this can happen during error recovery |
|
572 |
assert |
|
573 |
outer.isParameterized() ? |
|
574 |
typarams.length() == tsym.type.typarams().length() : |
|
575 |
outer.isRaw() ? |
|
576 |
typarams.length() == 0 : |
|
577 |
true; |
|
578 |
*/ |
|
579 |
} |
|
580 |
||
581 |
@Override |
|
582 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
583 |
return v.visitClassType(this, s); |
|
584 |
} |
|
585 |
||
586 |
public Type constType(Object constValue) { |
|
587 |
final Object value = constValue; |
|
588 |
return new ClassType(getEnclosingType(), typarams_field, tsym) { |
|
589 |
@Override |
|
590 |
public Object constValue() { |
|
591 |
return value; |
|
592 |
} |
|
593 |
@Override |
|
594 |
public Type baseType() { |
|
595 |
return tsym.type; |
|
596 |
} |
|
597 |
}; |
|
598 |
} |
|
599 |
||
600 |
/** The Java source which this type represents. |
|
601 |
*/ |
|
602 |
public String toString() { |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
603 |
StringBuilder buf = new StringBuilder(); |
10 | 604 |
if (getEnclosingType().tag == CLASS && tsym.owner.kind == TYP) { |
605 |
buf.append(getEnclosingType().toString()); |
|
606 |
buf.append("."); |
|
607 |
buf.append(className(tsym, false)); |
|
608 |
} else { |
|
609 |
buf.append(className(tsym, true)); |
|
610 |
} |
|
611 |
if (getTypeArguments().nonEmpty()) { |
|
612 |
buf.append('<'); |
|
613 |
buf.append(getTypeArguments().toString()); |
|
614 |
buf.append(">"); |
|
615 |
} |
|
616 |
return buf.toString(); |
|
617 |
} |
|
618 |
//where |
|
619 |
private String className(Symbol sym, boolean longform) { |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
620 |
if (sym.name.isEmpty() && (sym.flags() & COMPOUND) != 0) { |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
621 |
StringBuilder s = new StringBuilder(supertype_field.toString()); |
10 | 622 |
for (List<Type> is=interfaces_field; is.nonEmpty(); is = is.tail) { |
623 |
s.append("&"); |
|
624 |
s.append(is.head.toString()); |
|
625 |
} |
|
626 |
return s.toString(); |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
627 |
} else if (sym.name.isEmpty()) { |
10 | 628 |
String s; |
629 |
ClassType norm = (ClassType) tsym.type; |
|
630 |
if (norm == null) { |
|
631 |
s = Log.getLocalizedString("anonymous.class", (Object)null); |
|
632 |
} else if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) { |
|
633 |
s = Log.getLocalizedString("anonymous.class", |
|
634 |
norm.interfaces_field.head); |
|
635 |
} else { |
|
636 |
s = Log.getLocalizedString("anonymous.class", |
|
637 |
norm.supertype_field); |
|
638 |
} |
|
639 |
if (moreInfo) |
|
640 |
s += String.valueOf(sym.hashCode()); |
|
641 |
return s; |
|
642 |
} else if (longform) { |
|
643 |
return sym.getQualifiedName().toString(); |
|
644 |
} else { |
|
645 |
return sym.name.toString(); |
|
646 |
} |
|
647 |
} |
|
648 |
||
649 |
public List<Type> getTypeArguments() { |
|
650 |
if (typarams_field == null) { |
|
651 |
complete(); |
|
652 |
if (typarams_field == null) |
|
653 |
typarams_field = List.nil(); |
|
654 |
} |
|
655 |
return typarams_field; |
|
656 |
} |
|
657 |
||
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
658 |
public boolean hasErasedSupertypes() { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
659 |
return isRaw(); |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
660 |
} |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
661 |
|
10 | 662 |
public Type getEnclosingType() { |
663 |
return outer_field; |
|
664 |
} |
|
665 |
||
666 |
public void setEnclosingType(Type outer) { |
|
667 |
outer_field = outer; |
|
668 |
} |
|
669 |
||
670 |
public List<Type> allparams() { |
|
671 |
if (allparams_field == null) { |
|
672 |
allparams_field = getTypeArguments().prependList(getEnclosingType().allparams()); |
|
673 |
} |
|
674 |
return allparams_field; |
|
675 |
} |
|
676 |
||
677 |
public boolean isErroneous() { |
|
678 |
return |
|
679 |
getEnclosingType().isErroneous() || |
|
680 |
isErroneous(getTypeArguments()) || |
|
681 |
this != tsym.type && tsym.type.isErroneous(); |
|
682 |
} |
|
683 |
||
684 |
public boolean isParameterized() { |
|
685 |
return allparams().tail != null; |
|
686 |
// optimization, was: allparams().nonEmpty(); |
|
687 |
} |
|
688 |
||
689 |
/** A cache for the rank. */ |
|
690 |
int rank_field = -1; |
|
691 |
||
692 |
/** A class type is raw if it misses some |
|
693 |
* of its type parameter sections. |
|
694 |
* After validation, this is equivalent to: |
|
695 |
* allparams.isEmpty() && tsym.type.allparams.nonEmpty(); |
|
696 |
*/ |
|
697 |
public boolean isRaw() { |
|
698 |
return |
|
699 |
this != tsym.type && // necessary, but not sufficient condition |
|
700 |
tsym.type.allparams().nonEmpty() && |
|
701 |
allparams().isEmpty(); |
|
702 |
} |
|
703 |
||
704 |
public Type map(Mapping f) { |
|
705 |
Type outer = getEnclosingType(); |
|
706 |
Type outer1 = f.apply(outer); |
|
707 |
List<Type> typarams = getTypeArguments(); |
|
708 |
List<Type> typarams1 = map(typarams, f); |
|
709 |
if (outer1 == outer && typarams1 == typarams) return this; |
|
710 |
else return new ClassType(outer1, typarams1, tsym); |
|
711 |
} |
|
712 |
||
713 |
public boolean contains(Type elem) { |
|
714 |
return |
|
715 |
elem == this |
|
716 |
|| (isParameterized() |
|
6348
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
717 |
&& (getEnclosingType().contains(elem) || contains(getTypeArguments(), elem))) |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
718 |
|| (isCompound() |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
719 |
&& (supertype_field.contains(elem) || contains(interfaces_field, elem))); |
10 | 720 |
} |
721 |
||
722 |
public void complete() { |
|
723 |
if (tsym.completer != null) tsym.complete(); |
|
724 |
} |
|
725 |
||
726 |
public TypeKind getKind() { |
|
727 |
return TypeKind.DECLARED; |
|
728 |
} |
|
729 |
||
730 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
|
731 |
return v.visitDeclared(this, p); |
|
732 |
} |
|
733 |
} |
|
734 |
||
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
735 |
public static class ErasedClassType extends ClassType { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
736 |
public ErasedClassType(Type outer, TypeSymbol tsym) { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
737 |
super(outer, List.<Type>nil(), tsym); |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
738 |
} |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
739 |
|
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
740 |
@Override |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
741 |
public boolean hasErasedSupertypes() { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
742 |
return true; |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
743 |
} |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
744 |
} |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
745 |
|
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
746 |
// a clone of a ClassType that knows about the alternatives of a union type. |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
747 |
public static class UnionClassType extends ClassType implements UnionType { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
748 |
final List<? extends Type> alternatives_field; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
749 |
|
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
750 |
public UnionClassType(ClassType ct, List<? extends Type> alternatives) { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
751 |
super(ct.outer_field, ct.typarams_field, ct.tsym); |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
752 |
allparams_field = ct.allparams_field; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
753 |
supertype_field = ct.supertype_field; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
754 |
interfaces_field = ct.interfaces_field; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
755 |
all_interfaces_field = ct.interfaces_field; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
756 |
alternatives_field = alternatives; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
757 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
758 |
|
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
759 |
public Type getLub() { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
760 |
return tsym.type; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
761 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
762 |
|
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
763 |
public java.util.List<? extends TypeMirror> getAlternatives() { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
764 |
return Collections.unmodifiableList(alternatives_field); |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
765 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
766 |
|
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
767 |
@Override |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
768 |
public TypeKind getKind() { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
769 |
return TypeKind.UNION; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
770 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
771 |
|
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
772 |
@Override |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
773 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
774 |
return v.visitUnion(this, p); |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
775 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
776 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
777 |
|
10 | 778 |
public static class ArrayType extends Type |
779 |
implements javax.lang.model.type.ArrayType { |
|
780 |
||
781 |
public Type elemtype; |
|
782 |
||
783 |
public ArrayType(Type elemtype, TypeSymbol arrayClass) { |
|
784 |
super(ARRAY, arrayClass); |
|
785 |
this.elemtype = elemtype; |
|
786 |
} |
|
787 |
||
788 |
@Override |
|
789 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
790 |
return v.visitArrayType(this, s); |
|
791 |
} |
|
792 |
||
793 |
public String toString() { |
|
794 |
return elemtype + "[]"; |
|
795 |
} |
|
796 |
||
797 |
public boolean equals(Object obj) { |
|
798 |
return |
|
799 |
this == obj || |
|
800 |
(obj instanceof ArrayType && |
|
801 |
this.elemtype.equals(((ArrayType)obj).elemtype)); |
|
802 |
} |
|
803 |
||
804 |
public int hashCode() { |
|
805 |
return (ARRAY << 5) + elemtype.hashCode(); |
|
806 |
} |
|
807 |
||
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
808 |
public boolean isVarargs() { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
809 |
return false; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
810 |
} |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
811 |
|
10 | 812 |
public List<Type> allparams() { return elemtype.allparams(); } |
813 |
||
814 |
public boolean isErroneous() { |
|
815 |
return elemtype.isErroneous(); |
|
816 |
} |
|
817 |
||
818 |
public boolean isParameterized() { |
|
819 |
return elemtype.isParameterized(); |
|
820 |
} |
|
821 |
||
822 |
public boolean isRaw() { |
|
823 |
return elemtype.isRaw(); |
|
824 |
} |
|
825 |
||
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
826 |
public ArrayType makeVarargs() { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
827 |
return new ArrayType(elemtype, tsym) { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
828 |
@Override |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
829 |
public boolean isVarargs() { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
830 |
return true; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
831 |
} |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
832 |
}; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
833 |
} |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
834 |
|
10 | 835 |
public Type map(Mapping f) { |
836 |
Type elemtype1 = f.apply(elemtype); |
|
837 |
if (elemtype1 == elemtype) return this; |
|
838 |
else return new ArrayType(elemtype1, tsym); |
|
839 |
} |
|
840 |
||
841 |
public boolean contains(Type elem) { |
|
842 |
return elem == this || elemtype.contains(elem); |
|
843 |
} |
|
844 |
||
845 |
public void complete() { |
|
846 |
elemtype.complete(); |
|
847 |
} |
|
848 |
||
849 |
public Type getComponentType() { |
|
850 |
return elemtype; |
|
851 |
} |
|
852 |
||
853 |
public TypeKind getKind() { |
|
854 |
return TypeKind.ARRAY; |
|
855 |
} |
|
856 |
||
857 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
|
858 |
return v.visitArray(this, p); |
|
859 |
} |
|
860 |
} |
|
861 |
||
8430 | 862 |
public static class MethodType extends Type implements ExecutableType { |
10 | 863 |
|
864 |
public List<Type> argtypes; |
|
865 |
public Type restype; |
|
866 |
public List<Type> thrown; |
|
867 |
||
868 |
public MethodType(List<Type> argtypes, |
|
869 |
Type restype, |
|
870 |
List<Type> thrown, |
|
871 |
TypeSymbol methodClass) { |
|
872 |
super(METHOD, methodClass); |
|
873 |
this.argtypes = argtypes; |
|
874 |
this.restype = restype; |
|
875 |
this.thrown = thrown; |
|
876 |
} |
|
877 |
||
878 |
@Override |
|
879 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
880 |
return v.visitMethodType(this, s); |
|
881 |
} |
|
882 |
||
883 |
/** The Java source which this type represents. |
|
884 |
* |
|
885 |
* XXX 06/09/99 iris This isn't correct Java syntax, but it probably |
|
886 |
* should be. |
|
887 |
*/ |
|
888 |
public String toString() { |
|
889 |
return "(" + argtypes + ")" + restype; |
|
890 |
} |
|
891 |
||
892 |
public boolean equals(Object obj) { |
|
893 |
if (this == obj) |
|
894 |
return true; |
|
895 |
if (!(obj instanceof MethodType)) |
|
896 |
return false; |
|
897 |
MethodType m = (MethodType)obj; |
|
898 |
List<Type> args1 = argtypes; |
|
899 |
List<Type> args2 = m.argtypes; |
|
900 |
while (!args1.isEmpty() && !args2.isEmpty()) { |
|
901 |
if (!args1.head.equals(args2.head)) |
|
902 |
return false; |
|
903 |
args1 = args1.tail; |
|
904 |
args2 = args2.tail; |
|
905 |
} |
|
906 |
if (!args1.isEmpty() || !args2.isEmpty()) |
|
907 |
return false; |
|
908 |
return restype.equals(m.restype); |
|
909 |
} |
|
910 |
||
911 |
public int hashCode() { |
|
912 |
int h = METHOD; |
|
913 |
for (List<Type> thisargs = this.argtypes; |
|
914 |
thisargs.tail != null; /*inlined: thisargs.nonEmpty()*/ |
|
915 |
thisargs = thisargs.tail) |
|
916 |
h = (h << 5) + thisargs.head.hashCode(); |
|
917 |
return (h << 5) + this.restype.hashCode(); |
|
918 |
} |
|
919 |
||
920 |
public List<Type> getParameterTypes() { return argtypes; } |
|
921 |
public Type getReturnType() { return restype; } |
|
922 |
public List<Type> getThrownTypes() { return thrown; } |
|
923 |
||
924 |
public boolean isErroneous() { |
|
925 |
return |
|
926 |
isErroneous(argtypes) || |
|
927 |
restype != null && restype.isErroneous(); |
|
928 |
} |
|
929 |
||
930 |
public Type map(Mapping f) { |
|
931 |
List<Type> argtypes1 = map(argtypes, f); |
|
932 |
Type restype1 = f.apply(restype); |
|
933 |
List<Type> thrown1 = map(thrown, f); |
|
934 |
if (argtypes1 == argtypes && |
|
935 |
restype1 == restype && |
|
936 |
thrown1 == thrown) return this; |
|
937 |
else return new MethodType(argtypes1, restype1, thrown1, tsym); |
|
938 |
} |
|
939 |
||
940 |
public boolean contains(Type elem) { |
|
941 |
return elem == this || contains(argtypes, elem) || restype.contains(elem); |
|
942 |
} |
|
943 |
||
944 |
public MethodType asMethodType() { return this; } |
|
945 |
||
946 |
public void complete() { |
|
947 |
for (List<Type> l = argtypes; l.nonEmpty(); l = l.tail) |
|
948 |
l.head.complete(); |
|
949 |
restype.complete(); |
|
950 |
for (List<Type> l = thrown; l.nonEmpty(); l = l.tail) |
|
951 |
l.head.complete(); |
|
952 |
} |
|
953 |
||
954 |
public List<TypeVar> getTypeVariables() { |
|
955 |
return List.nil(); |
|
956 |
} |
|
957 |
||
958 |
public TypeSymbol asElement() { |
|
959 |
return null; |
|
960 |
} |
|
961 |
||
962 |
public TypeKind getKind() { |
|
963 |
return TypeKind.EXECUTABLE; |
|
964 |
} |
|
965 |
||
966 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
|
967 |
return v.visitExecutable(this, p); |
|
968 |
} |
|
969 |
} |
|
970 |
||
971 |
public static class PackageType extends Type implements NoType { |
|
972 |
||
973 |
PackageType(TypeSymbol tsym) { |
|
974 |
super(PACKAGE, tsym); |
|
975 |
} |
|
976 |
||
977 |
@Override |
|
978 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
979 |
return v.visitPackageType(this, s); |
|
980 |
} |
|
981 |
||
982 |
public String toString() { |
|
983 |
return tsym.getQualifiedName().toString(); |
|
984 |
} |
|
985 |
||
986 |
public TypeKind getKind() { |
|
987 |
return TypeKind.PACKAGE; |
|
988 |
} |
|
989 |
||
990 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
|
991 |
return v.visitNoType(this, p); |
|
992 |
} |
|
993 |
} |
|
994 |
||
995 |
public static class TypeVar extends Type implements TypeVariable { |
|
996 |
||
7637 | 997 |
/** The upper bound of this type variable; set from outside. |
10 | 998 |
* Must be nonempty once it is set. |
999 |
* For a bound, `bound' is the bound type itself. |
|
1000 |
* Multiple bounds are expressed as a single class type which has the |
|
1001 |
* individual bounds as superclass, respectively interfaces. |
|
1002 |
* The class type then has as `tsym' a compiler generated class `c', |
|
1003 |
* which has a flag COMPOUND and whose owner is the type variable |
|
1004 |
* itself. Furthermore, the erasure_field of the class |
|
1005 |
* points to the first class or interface bound. |
|
1006 |
*/ |
|
1007 |
public Type bound = null; |
|
7637 | 1008 |
|
1009 |
/** The lower bound of this type variable. |
|
1010 |
* TypeVars don't normally have a lower bound, so it is normally set |
|
1011 |
* to syms.botType. |
|
1012 |
* Subtypes, such as CapturedType, may provide a different value. |
|
1013 |
*/ |
|
10 | 1014 |
public Type lower; |
1015 |
||
1016 |
public TypeVar(Name name, Symbol owner, Type lower) { |
|
1017 |
super(TYPEVAR, null); |
|
1018 |
tsym = new TypeSymbol(0, name, this, owner); |
|
1019 |
this.lower = lower; |
|
1020 |
} |
|
1021 |
||
1022 |
public TypeVar(TypeSymbol tsym, Type bound, Type lower) { |
|
1023 |
super(TYPEVAR, tsym); |
|
1024 |
this.bound = bound; |
|
1025 |
this.lower = lower; |
|
1026 |
} |
|
1027 |
||
1028 |
@Override |
|
1029 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
1030 |
return v.visitTypeVar(this, s); |
|
1031 |
} |
|
1032 |
||
7637 | 1033 |
@Override |
10 | 1034 |
public Type getUpperBound() { return bound; } |
1035 |
||
1036 |
int rank_field = -1; |
|
1037 |
||
7637 | 1038 |
@Override |
10 | 1039 |
public Type getLowerBound() { |
1040 |
return lower; |
|
1041 |
} |
|
1042 |
||
1043 |
public TypeKind getKind() { |
|
1044 |
return TypeKind.TYPEVAR; |
|
1045 |
} |
|
1046 |
||
938
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1047 |
public boolean isCaptured() { |
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1048 |
return false; |
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1049 |
} |
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1050 |
|
10 | 1051 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
1052 |
return v.visitTypeVariable(this, p); |
|
1053 |
} |
|
1054 |
} |
|
1055 |
||
1056 |
/** A captured type variable comes from wildcards which can have |
|
1057 |
* both upper and lower bound. CapturedType extends TypeVar with |
|
1058 |
* a lower bound. |
|
1059 |
*/ |
|
1060 |
public static class CapturedType extends TypeVar { |
|
1061 |
||
1062 |
public WildcardType wildcard; |
|
1063 |
||
1064 |
public CapturedType(Name name, |
|
1065 |
Symbol owner, |
|
1066 |
Type upper, |
|
1067 |
Type lower, |
|
1068 |
WildcardType wildcard) { |
|
1069 |
super(name, owner, lower); |
|
8032 | 1070 |
this.lower = Assert.checkNonNull(lower); |
10 | 1071 |
this.bound = upper; |
1072 |
this.wildcard = wildcard; |
|
1073 |
} |
|
1074 |
||
1075 |
@Override |
|
1076 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
1077 |
return v.visitCapturedType(this, s); |
|
1078 |
} |
|
1079 |
||
1080 |
@Override |
|
938
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1081 |
public boolean isCaptured() { |
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1082 |
return true; |
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1083 |
} |
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1084 |
|
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1085 |
@Override |
10 | 1086 |
public String toString() { |
1087 |
return "capture#" |
|
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
1527
diff
changeset
|
1088 |
+ (hashCode() & 0xFFFFFFFFL) % Printer.PRIME |
10 | 1089 |
+ " of " |
1090 |
+ wildcard; |
|
1091 |
} |
|
1092 |
} |
|
1093 |
||
1094 |
public static abstract class DelegatedType extends Type { |
|
1095 |
public Type qtype; |
|
1096 |
public DelegatedType(int tag, Type qtype) { |
|
1097 |
super(tag, qtype.tsym); |
|
1098 |
this.qtype = qtype; |
|
1099 |
} |
|
1100 |
public String toString() { return qtype.toString(); } |
|
1101 |
public List<Type> getTypeArguments() { return qtype.getTypeArguments(); } |
|
1102 |
public Type getEnclosingType() { return qtype.getEnclosingType(); } |
|
1103 |
public List<Type> getParameterTypes() { return qtype.getParameterTypes(); } |
|
1104 |
public Type getReturnType() { return qtype.getReturnType(); } |
|
1105 |
public List<Type> getThrownTypes() { return qtype.getThrownTypes(); } |
|
1106 |
public List<Type> allparams() { return qtype.allparams(); } |
|
1107 |
public Type getUpperBound() { return qtype.getUpperBound(); } |
|
1108 |
public boolean isErroneous() { return qtype.isErroneous(); } |
|
1109 |
} |
|
1110 |
||
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
1111 |
/** |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
1112 |
* The type of a generic method type. It consists of a method type and |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
1113 |
* a list of method type-parameters that are used within the method |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
1114 |
* type. |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
1115 |
*/ |
8430 | 1116 |
public static class ForAll extends DelegatedType implements ExecutableType { |
10 | 1117 |
public List<Type> tvars; |
1118 |
||
1119 |
public ForAll(List<Type> tvars, Type qtype) { |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
1120 |
super(FORALL, (MethodType)qtype); |
10 | 1121 |
this.tvars = tvars; |
1122 |
} |
|
1123 |
||
1124 |
@Override |
|
1125 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
1126 |
return v.visitForAll(this, s); |
|
1127 |
} |
|
1128 |
||
1129 |
public String toString() { |
|
1130 |
return "<" + tvars + ">" + qtype; |
|
1131 |
} |
|
1132 |
||
1133 |
public List<Type> getTypeArguments() { return tvars; } |
|
1134 |
||
1135 |
public boolean isErroneous() { |
|
1136 |
return qtype.isErroneous(); |
|
1137 |
} |
|
1138 |
||
1139 |
public Type map(Mapping f) { |
|
1140 |
return f.apply(qtype); |
|
1141 |
} |
|
1142 |
||
1143 |
public boolean contains(Type elem) { |
|
1144 |
return qtype.contains(elem); |
|
1145 |
} |
|
1146 |
||
1147 |
public MethodType asMethodType() { |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
1148 |
return (MethodType)qtype; |
10 | 1149 |
} |
1150 |
||
1151 |
public void complete() { |
|
1152 |
for (List<Type> l = tvars; l.nonEmpty(); l = l.tail) { |
|
1153 |
((TypeVar)l.head).bound.complete(); |
|
1154 |
} |
|
1155 |
qtype.complete(); |
|
1156 |
} |
|
1157 |
||
1158 |
public List<TypeVar> getTypeVariables() { |
|
1159 |
return List.convert(TypeVar.class, getTypeArguments()); |
|
1160 |
} |
|
1161 |
||
1162 |
public TypeKind getKind() { |
|
1163 |
return TypeKind.EXECUTABLE; |
|
1164 |
} |
|
1165 |
||
1166 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
|
1167 |
return v.visitExecutable(this, p); |
|
1168 |
} |
|
1169 |
} |
|
1170 |
||
1171 |
/** A class for instantiatable variables, for use during type |
|
1172 |
* inference. |
|
1173 |
*/ |
|
1174 |
public static class UndetVar extends DelegatedType { |
|
1175 |
public List<Type> lobounds = List.nil(); |
|
1176 |
public List<Type> hibounds = List.nil(); |
|
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
9599
diff
changeset
|
1177 |
public List<Type> eq = List.nil(); |
10 | 1178 |
public Type inst = null; |
1179 |
||
1180 |
@Override |
|
1181 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
1182 |
return v.visitUndetVar(this, s); |
|
1183 |
} |
|
1184 |
||
1185 |
public UndetVar(Type origin) { |
|
1186 |
super(UNDETVAR, origin); |
|
1187 |
} |
|
1188 |
||
1189 |
public String toString() { |
|
1190 |
if (inst != null) return inst.toString(); |
|
1191 |
else return qtype + "?"; |
|
1192 |
} |
|
1193 |
||
1194 |
public Type baseType() { |
|
1195 |
if (inst != null) return inst.baseType(); |
|
1196 |
else return this; |
|
1197 |
} |
|
1198 |
} |
|
1199 |
||
1200 |
/** Represents VOID or NONE. |
|
1201 |
*/ |
|
1202 |
static class JCNoType extends Type implements NoType { |
|
1203 |
public JCNoType(int tag) { |
|
1204 |
super(tag, null); |
|
1205 |
} |
|
1206 |
||
1207 |
@Override |
|
1208 |
public TypeKind getKind() { |
|
1209 |
switch (tag) { |
|
1210 |
case VOID: return TypeKind.VOID; |
|
1211 |
case NONE: return TypeKind.NONE; |
|
1212 |
default: |
|
1213 |
throw new AssertionError("Unexpected tag: " + tag); |
|
1214 |
} |
|
1215 |
} |
|
1216 |
||
1217 |
@Override |
|
1218 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
|
1219 |
return v.visitNoType(this, p); |
|
1220 |
} |
|
1221 |
} |
|
1222 |
||
1223 |
static class BottomType extends Type implements NullType { |
|
1224 |
public BottomType() { |
|
1225 |
super(TypeTags.BOT, null); |
|
1226 |
} |
|
1227 |
||
1228 |
@Override |
|
1229 |
public TypeKind getKind() { |
|
1230 |
return TypeKind.NULL; |
|
1231 |
} |
|
1232 |
||
1233 |
@Override |
|
1234 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
|
1235 |
return v.visitNull(this, p); |
|
1236 |
} |
|
1237 |
||
1238 |
@Override |
|
1239 |
public Type constType(Object value) { |
|
1240 |
return this; |
|
1241 |
} |
|
1242 |
||
1243 |
@Override |
|
1244 |
public String stringValue() { |
|
1245 |
return "null"; |
|
1246 |
} |
|
1247 |
} |
|
1248 |
||
1249 |
public static class ErrorType extends ClassType |
|
1250 |
implements javax.lang.model.type.ErrorType { |
|
1251 |
||
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
1252 |
private Type originalType = null; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
1253 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
1254 |
public ErrorType(Type originalType, TypeSymbol tsym) { |
10 | 1255 |
super(noType, List.<Type>nil(), null); |
1256 |
tag = ERROR; |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
1257 |
this.tsym = tsym; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
1258 |
this.originalType = (originalType == null ? noType : originalType); |
10 | 1259 |
} |
1260 |
||
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
1261 |
public ErrorType(ClassSymbol c, Type originalType) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
1262 |
this(originalType, c); |
10 | 1263 |
c.type = this; |
1264 |
c.kind = ERR; |
|
1265 |
c.members_field = new Scope.ErrorScope(c); |
|
1266 |
} |
|
1267 |
||
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
1268 |
public ErrorType(Name name, TypeSymbol container, Type originalType) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
1269 |
this(new ClassSymbol(PUBLIC|STATIC|ACYCLIC, name, null, container), originalType); |
10 | 1270 |
} |
1271 |
||
1272 |
@Override |
|
1273 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
1274 |
return v.visitErrorType(this, s); |
|
1275 |
} |
|
1276 |
||
1277 |
public Type constType(Object constValue) { return this; } |
|
1278 |
public Type getEnclosingType() { return this; } |
|
1279 |
public Type getReturnType() { return this; } |
|
1280 |
public Type asSub(Symbol sym) { return this; } |
|
1281 |
public Type map(Mapping f) { return this; } |
|
1282 |
||
1283 |
public boolean isGenType(Type t) { return true; } |
|
1284 |
public boolean isErroneous() { return true; } |
|
1285 |
public boolean isCompound() { return false; } |
|
1286 |
public boolean isInterface() { return false; } |
|
1287 |
||
1288 |
public List<Type> allparams() { return List.nil(); } |
|
1289 |
public List<Type> getTypeArguments() { return List.nil(); } |
|
1290 |
||
1291 |
public TypeKind getKind() { |
|
1292 |
return TypeKind.ERROR; |
|
1293 |
} |
|
1294 |
||
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
1295 |
public Type getOriginalType() { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
1296 |
return originalType; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
1297 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
1298 |
|
10 | 1299 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
1300 |
return v.visitError(this, p); |
|
1301 |
} |
|
1302 |
} |
|
1303 |
||
1304 |
/** |
|
1305 |
* A visitor for types. A visitor is used to implement operations |
|
1306 |
* (or relations) on types. Most common operations on types are |
|
1307 |
* binary relations and this interface is designed for binary |
|
1308 |
* relations, that is, operations on the form |
|
1309 |
* Type × S → R. |
|
1310 |
* <!-- In plain text: Type x S -> R --> |
|
1311 |
* |
|
1312 |
* @param <R> the return type of the operation implemented by this |
|
1313 |
* visitor; use Void if no return type is needed. |
|
1314 |
* @param <S> the type of the second argument (the first being the |
|
1315 |
* type itself) of the operation implemented by this visitor; use |
|
1316 |
* Void if a second argument is not needed. |
|
1317 |
*/ |
|
1318 |
public interface Visitor<R,S> { |
|
1319 |
R visitClassType(ClassType t, S s); |
|
1320 |
R visitWildcardType(WildcardType t, S s); |
|
1321 |
R visitArrayType(ArrayType t, S s); |
|
1322 |
R visitMethodType(MethodType t, S s); |
|
1323 |
R visitPackageType(PackageType t, S s); |
|
1324 |
R visitTypeVar(TypeVar t, S s); |
|
1325 |
R visitCapturedType(CapturedType t, S s); |
|
1326 |
R visitForAll(ForAll t, S s); |
|
1327 |
R visitUndetVar(UndetVar t, S s); |
|
1328 |
R visitErrorType(ErrorType t, S s); |
|
1329 |
R visitType(Type t, S s); |
|
1330 |
} |
|
1331 |
} |