author | briangoetz |
Wed, 18 Dec 2013 16:05:18 -0500 | |
changeset 22163 | 3651128c74eb |
parent 21890 | a627c91c71db |
child 23395 | e7e0973e6d2e |
permissions | -rw-r--r-- |
10 | 1 |
/* |
15385 | 2 |
* Copyright (c) 1999, 2013, 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 |
||
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
28 |
import java.lang.annotation.Annotation; |
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
29 |
import java.util.Collections; |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
30 |
import java.util.EnumMap; |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
31 |
import java.util.EnumSet; |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
32 |
import java.util.Map; |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
33 |
import java.util.Set; |
14052 | 34 |
|
10 | 35 |
import javax.lang.model.type.*; |
36 |
||
14258 | 37 |
import com.sun.tools.javac.code.Symbol.*; |
38 |
import com.sun.tools.javac.util.*; |
|
14052 | 39 |
import static com.sun.tools.javac.code.BoundKind.*; |
10 | 40 |
import static com.sun.tools.javac.code.Flags.*; |
41 |
import static com.sun.tools.javac.code.Kinds.*; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
42 |
import static com.sun.tools.javac.code.TypeTag.*; |
10 | 43 |
|
44 |
/** This class represents Java types. The class itself defines the behavior of |
|
45 |
* the following types: |
|
46 |
* <pre> |
|
47 |
* base types (tags: BYTE, CHAR, SHORT, INT, LONG, FLOAT, DOUBLE, BOOLEAN), |
|
48 |
* type `void' (tag: VOID), |
|
49 |
* the bottom type (tag: BOT), |
|
50 |
* the missing type (tag: NONE). |
|
51 |
* </pre> |
|
52 |
* <p>The behavior of the following types is defined in subclasses, which are |
|
53 |
* all static inner classes of this class: |
|
54 |
* <pre> |
|
55 |
* class types (tag: CLASS, class: ClassType), |
|
56 |
* array types (tag: ARRAY, class: ArrayType), |
|
57 |
* method types (tag: METHOD, class: MethodType), |
|
58 |
* package types (tag: PACKAGE, class: PackageType), |
|
59 |
* type variables (tag: TYPEVAR, class: TypeVar), |
|
60 |
* type arguments (tag: WILDCARD, class: WildcardType), |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
61 |
* generic method types (tag: FORALL, class: ForAll), |
10 | 62 |
* the error type (tag: ERROR, class: ErrorType). |
63 |
* </pre> |
|
64 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
65 |
* <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
|
66 |
* If you write code that depends on this, you do so at your own risk. |
10 | 67 |
* This code and its internal interfaces are subject to change or |
68 |
* deletion without notice.</b> |
|
69 |
* |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
70 |
* @see TypeTag |
10 | 71 |
*/ |
21007 | 72 |
public abstract class Type extends AnnoConstruct implements TypeMirror { |
10 | 73 |
|
74 |
/** Constant type: no type at all. */ |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
75 |
public static final JCNoType noType = new JCNoType(); |
10 | 76 |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14052
diff
changeset
|
77 |
/** Constant type: special type to be used during recovery of deferred expressions. */ |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
78 |
public static final JCNoType recoveryType = new JCNoType(); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14052
diff
changeset
|
79 |
|
18902 | 80 |
/** Constant type: special type to be used for marking stuck trees. */ |
81 |
public static final JCNoType stuckType = new JCNoType(); |
|
82 |
||
10 | 83 |
/** If this switch is turned on, the names of type variables |
84 |
* and anonymous classes are printed with hashcodes appended. |
|
85 |
*/ |
|
86 |
public static boolean moreInfo = false; |
|
87 |
||
15385 | 88 |
/** The defining class / interface / package / type variable. |
10 | 89 |
*/ |
90 |
public TypeSymbol tsym; |
|
91 |
||
92 |
/** |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
93 |
* Checks if the current type tag is equal to the given tag. |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
94 |
* @return true if tag is equal to the current type tag. |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
95 |
*/ |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
96 |
public boolean hasTag(TypeTag tag) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
97 |
return tag == getTag(); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
98 |
} |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
99 |
|
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
100 |
/** |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
101 |
* Returns the current type tag. |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
102 |
* @return the value of the current type tag. |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
103 |
*/ |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
104 |
public abstract TypeTag getTag(); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
105 |
|
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
106 |
public boolean isNumeric() { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
107 |
return false; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
108 |
} |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
109 |
|
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
110 |
public boolean isPrimitive() { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
111 |
return false; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
112 |
} |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
113 |
|
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
114 |
public boolean isPrimitiveOrVoid() { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
115 |
return false; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
116 |
} |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
117 |
|
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
118 |
public boolean isReference() { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
119 |
return false; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
120 |
} |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
121 |
|
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
122 |
public boolean isNullOrReference() { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
123 |
return false; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
124 |
} |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
125 |
|
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
126 |
public boolean isPartial() { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
127 |
return false; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
128 |
} |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
129 |
|
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
130 |
/** |
10 | 131 |
* The constant value of this type, null if this type does not |
132 |
* have a constant value attribute. Only primitive types and |
|
133 |
* strings (ClassType) can have a constant value attribute. |
|
134 |
* @return the constant value attribute of this type |
|
135 |
*/ |
|
136 |
public Object constValue() { |
|
137 |
return null; |
|
138 |
} |
|
139 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
140 |
/** Is this a constant type whose value is false? |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
141 |
*/ |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
142 |
public boolean isFalse() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
143 |
return false; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
144 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
145 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
146 |
/** Is this a constant type whose value is true? |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
147 |
*/ |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
148 |
public boolean isTrue() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
149 |
return false; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
150 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
151 |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
152 |
/** |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
153 |
* Get the representation of this type used for modelling purposes. |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
154 |
* By default, this is itself. For ErrorType, a different value |
15385 | 155 |
* may be provided. |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
156 |
*/ |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
157 |
public Type getModelType() { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
158 |
return this; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
159 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
160 |
|
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
161 |
public static List<Type> getModelTypes(List<Type> ts) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
162 |
ListBuffer<Type> lb = new ListBuffer<>(); |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
163 |
for (Type t: ts) |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
164 |
lb.append(t.getModelType()); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
165 |
return lb.toList(); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
166 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
167 |
|
21015
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
21007
diff
changeset
|
168 |
/**For ErrorType, returns the original type, otherwise returns the type itself. |
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
21007
diff
changeset
|
169 |
*/ |
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
21007
diff
changeset
|
170 |
public Type getOriginalType() { |
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
21007
diff
changeset
|
171 |
return this; |
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
21007
diff
changeset
|
172 |
} |
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
21007
diff
changeset
|
173 |
|
10 | 174 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { return v.visitType(this, s); } |
175 |
||
176 |
/** Define a type given its tag and type symbol |
|
177 |
*/ |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
178 |
public Type(TypeSymbol tsym) { |
10 | 179 |
this.tsym = tsym; |
180 |
} |
|
181 |
||
182 |
/** An abstract class for mappings from types to types |
|
183 |
*/ |
|
184 |
public static abstract class Mapping { |
|
185 |
private String name; |
|
186 |
public Mapping(String name) { |
|
187 |
this.name = name; |
|
188 |
} |
|
189 |
public abstract Type apply(Type t); |
|
190 |
public String toString() { |
|
191 |
return name; |
|
192 |
} |
|
193 |
} |
|
194 |
||
195 |
/** map a type function over all immediate descendants of this type |
|
196 |
*/ |
|
197 |
public Type map(Mapping f) { |
|
198 |
return this; |
|
199 |
} |
|
200 |
||
201 |
/** map a type function over a list of types |
|
202 |
*/ |
|
203 |
public static List<Type> map(List<Type> ts, Mapping f) { |
|
204 |
if (ts.nonEmpty()) { |
|
205 |
List<Type> tail1 = map(ts.tail, f); |
|
206 |
Type t = f.apply(ts.head); |
|
207 |
if (tail1 != ts.tail || t != ts.head) |
|
208 |
return tail1.prepend(t); |
|
209 |
} |
|
210 |
return ts; |
|
211 |
} |
|
212 |
||
213 |
/** Define a constant type, of the same kind as this type |
|
214 |
* and with given constant value |
|
215 |
*/ |
|
216 |
public Type constType(Object constValue) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
217 |
throw new AssertionError(); |
10 | 218 |
} |
219 |
||
220 |
/** |
|
221 |
* If this is a constant type, return its underlying type. |
|
222 |
* Otherwise, return the type itself. |
|
223 |
*/ |
|
224 |
public Type baseType() { |
|
225 |
return this; |
|
226 |
} |
|
227 |
||
21041 | 228 |
public Type annotatedType(List<Attribute.TypeCompound> annos) { |
229 |
return new AnnotatedType(annos, this); |
|
230 |
} |
|
231 |
||
16556
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
16341
diff
changeset
|
232 |
public boolean isAnnotated() { |
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
16341
diff
changeset
|
233 |
return false; |
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
16341
diff
changeset
|
234 |
} |
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
16341
diff
changeset
|
235 |
|
15385 | 236 |
/** |
237 |
* If this is an annotated type, return the underlying type. |
|
238 |
* Otherwise, return the type itself. |
|
239 |
*/ |
|
240 |
public Type unannotatedType() { |
|
241 |
return this; |
|
242 |
} |
|
243 |
||
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
244 |
@Override |
21007 | 245 |
public List<Attribute.TypeCompound> getAnnotationMirrors() { |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
246 |
return List.nil(); |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
247 |
} |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
248 |
|
21007 | 249 |
|
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
250 |
@Override |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
251 |
public <A extends Annotation> A getAnnotation(Class<A> annotationType) { |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
252 |
return null; |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
253 |
} |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
254 |
|
21007 | 255 |
|
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
256 |
@Override |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
257 |
public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType) { |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
258 |
@SuppressWarnings("unchecked") |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
259 |
A[] tmp = (A[]) java.lang.reflect.Array.newInstance(annotationType, 0); |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
260 |
return tmp; |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
261 |
} |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
262 |
|
10 | 263 |
/** Return the base types of a list of types. |
264 |
*/ |
|
265 |
public static List<Type> baseTypes(List<Type> ts) { |
|
266 |
if (ts.nonEmpty()) { |
|
267 |
Type t = ts.head.baseType(); |
|
268 |
List<Type> baseTypes = baseTypes(ts.tail); |
|
269 |
if (t != ts.head || baseTypes != ts.tail) |
|
270 |
return baseTypes.prepend(t); |
|
271 |
} |
|
272 |
return ts; |
|
273 |
} |
|
274 |
||
275 |
/** The Java source which this type represents. |
|
276 |
*/ |
|
277 |
public String toString() { |
|
278 |
String s = (tsym == null || tsym.name == null) |
|
279 |
? "<none>" |
|
280 |
: tsym.name.toString(); |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
281 |
if (moreInfo && hasTag(TYPEVAR)) { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
282 |
s = s + hashCode(); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
283 |
} |
10 | 284 |
return s; |
285 |
} |
|
286 |
||
287 |
/** |
|
288 |
* The Java source which this type list represents. A List is |
|
289 |
* represented as a comma-spearated listing of the elements in |
|
290 |
* that list. |
|
291 |
*/ |
|
292 |
public static String toString(List<Type> ts) { |
|
293 |
if (ts.isEmpty()) { |
|
294 |
return ""; |
|
295 |
} else { |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
296 |
StringBuilder buf = new StringBuilder(); |
10 | 297 |
buf.append(ts.head.toString()); |
298 |
for (List<Type> l = ts.tail; l.nonEmpty(); l = l.tail) |
|
299 |
buf.append(",").append(l.head.toString()); |
|
300 |
return buf.toString(); |
|
301 |
} |
|
302 |
} |
|
303 |
||
304 |
/** |
|
305 |
* The constant value of this type, converted to String |
|
306 |
*/ |
|
307 |
public String stringValue() { |
|
8032 | 308 |
Object cv = Assert.checkNonNull(constValue()); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
309 |
return cv.toString(); |
10 | 310 |
} |
311 |
||
312 |
/** |
|
313 |
* This method is analogous to isSameType, but weaker, since we |
|
314 |
* never complete classes. Where isSameType would complete a |
|
315 |
* class, equals assumes that the two types are different. |
|
316 |
*/ |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14725
diff
changeset
|
317 |
@Override |
10 | 318 |
public boolean equals(Object t) { |
319 |
return super.equals(t); |
|
320 |
} |
|
321 |
||
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14725
diff
changeset
|
322 |
@Override |
10 | 323 |
public int hashCode() { |
324 |
return super.hashCode(); |
|
325 |
} |
|
326 |
||
327 |
public String argtypes(boolean varargs) { |
|
328 |
List<Type> args = getParameterTypes(); |
|
329 |
if (!varargs) return args.toString(); |
|
7637 | 330 |
StringBuilder buf = new StringBuilder(); |
10 | 331 |
while (args.tail.nonEmpty()) { |
332 |
buf.append(args.head); |
|
333 |
args = args.tail; |
|
334 |
buf.append(','); |
|
335 |
} |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
336 |
if (args.head.unannotatedType().hasTag(ARRAY)) { |
15385 | 337 |
buf.append(((ArrayType)args.head.unannotatedType()).elemtype); |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
338 |
if (args.head.getAnnotationMirrors().nonEmpty()) { |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
339 |
buf.append(args.head.getAnnotationMirrors()); |
15385 | 340 |
} |
10 | 341 |
buf.append("..."); |
342 |
} else { |
|
343 |
buf.append(args.head); |
|
344 |
} |
|
345 |
return buf.toString(); |
|
346 |
} |
|
347 |
||
348 |
/** Access methods. |
|
349 |
*/ |
|
350 |
public List<Type> getTypeArguments() { return List.nil(); } |
|
15385 | 351 |
public Type getEnclosingType() { return null; } |
10 | 352 |
public List<Type> getParameterTypes() { return List.nil(); } |
353 |
public Type getReturnType() { return null; } |
|
15385 | 354 |
public Type getReceiverType() { return null; } |
10 | 355 |
public List<Type> getThrownTypes() { return List.nil(); } |
356 |
public Type getUpperBound() { return null; } |
|
357 |
public Type getLowerBound() { return null; } |
|
358 |
||
359 |
/** Navigation methods, these will work for classes, type variables, |
|
360 |
* foralls, but will return null for arrays and methods. |
|
361 |
*/ |
|
362 |
||
363 |
/** Return all parameters of this type and all its outer types in order |
|
364 |
* outer (first) to inner (last). |
|
365 |
*/ |
|
366 |
public List<Type> allparams() { return List.nil(); } |
|
367 |
||
368 |
/** Does this type contain "error" elements? |
|
369 |
*/ |
|
370 |
public boolean isErroneous() { |
|
371 |
return false; |
|
372 |
} |
|
373 |
||
374 |
public static boolean isErroneous(List<Type> ts) { |
|
375 |
for (List<Type> l = ts; l.nonEmpty(); l = l.tail) |
|
376 |
if (l.head.isErroneous()) return true; |
|
377 |
return false; |
|
378 |
} |
|
379 |
||
380 |
/** Is this type parameterized? |
|
381 |
* A class type is parameterized if it has some parameters. |
|
382 |
* An array type is parameterized if its element type is parameterized. |
|
383 |
* All other types are not parameterized. |
|
384 |
*/ |
|
385 |
public boolean isParameterized() { |
|
386 |
return false; |
|
387 |
} |
|
388 |
||
389 |
/** Is this type a raw type? |
|
390 |
* A class type is a raw type if it misses some of its parameters. |
|
391 |
* An array type is a raw type if its element type is raw. |
|
392 |
* All other types are not raw. |
|
393 |
* Type validation will ensure that the only raw types |
|
394 |
* in a program are types that miss all their type variables. |
|
395 |
*/ |
|
396 |
public boolean isRaw() { |
|
397 |
return false; |
|
398 |
} |
|
399 |
||
400 |
public boolean isCompound() { |
|
401 |
return tsym.completer == null |
|
402 |
// Compound types can't have a completer. Calling |
|
403 |
// flags() will complete the symbol causing the |
|
404 |
// compiler to load classes unnecessarily. This led |
|
405 |
// to regression 6180021. |
|
406 |
&& (tsym.flags() & COMPOUND) != 0; |
|
407 |
} |
|
408 |
||
409 |
public boolean isInterface() { |
|
410 |
return (tsym.flags() & INTERFACE) != 0; |
|
411 |
} |
|
412 |
||
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6348
diff
changeset
|
413 |
public boolean isFinal() { |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6348
diff
changeset
|
414 |
return (tsym.flags() & FINAL) != 0; |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6348
diff
changeset
|
415 |
} |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6348
diff
changeset
|
416 |
|
10 | 417 |
/** |
418 |
* Does this type contain occurrences of type t? |
|
419 |
*/ |
|
420 |
public boolean contains(Type t) { |
|
421 |
return t == this; |
|
422 |
} |
|
423 |
||
424 |
public static boolean contains(List<Type> ts, Type t) { |
|
425 |
for (List<Type> l = ts; |
|
426 |
l.tail != null /*inlined: l.nonEmpty()*/; |
|
427 |
l = l.tail) |
|
428 |
if (l.head.contains(t)) return true; |
|
429 |
return false; |
|
430 |
} |
|
431 |
||
6348
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
432 |
/** Does this type contain an occurrence of some type in 'ts'? |
10 | 433 |
*/ |
6348
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
434 |
public boolean containsAny(List<Type> ts) { |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
435 |
for (Type t : ts) |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
436 |
if (this.contains(t)) return true; |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
437 |
return false; |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
438 |
} |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
439 |
|
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
440 |
public static boolean containsAny(List<Type> ts1, List<Type> ts2) { |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
441 |
for (Type t : ts1) |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
442 |
if (t.containsAny(ts2)) return true; |
10 | 443 |
return false; |
444 |
} |
|
445 |
||
8044
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
446 |
public static List<Type> filter(List<Type> ts, Filter<Type> tf) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19502
diff
changeset
|
447 |
ListBuffer<Type> buf = new ListBuffer<>(); |
8044
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
448 |
for (Type t : ts) { |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
449 |
if (tf.accepts(t)) { |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
450 |
buf.append(t); |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
451 |
} |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
452 |
} |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
453 |
return buf.toList(); |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
454 |
} |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
455 |
|
10 | 456 |
public boolean isSuperBound() { return false; } |
457 |
public boolean isExtendsBound() { return false; } |
|
458 |
public boolean isUnbound() { return false; } |
|
459 |
public Type withTypeVar(Type t) { return this; } |
|
460 |
||
461 |
/** The underlying method type of this type. |
|
462 |
*/ |
|
463 |
public MethodType asMethodType() { throw new AssertionError(); } |
|
464 |
||
465 |
/** Complete loading all classes in this type. |
|
466 |
*/ |
|
467 |
public void complete() {} |
|
468 |
||
469 |
public TypeSymbol asElement() { |
|
470 |
return tsym; |
|
471 |
} |
|
472 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
473 |
@Override |
10 | 474 |
public TypeKind getKind() { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
475 |
return TypeKind.OTHER; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
476 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
477 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
478 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
479 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
480 |
throw new AssertionError(); |
10 | 481 |
} |
482 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
483 |
public static class JCPrimitiveType extends Type |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
484 |
implements javax.lang.model.type.PrimitiveType { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
485 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
486 |
TypeTag tag; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
487 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
488 |
public JCPrimitiveType(TypeTag tag, TypeSymbol tsym) { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
489 |
super(tsym); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
490 |
this.tag = tag; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
491 |
Assert.check(tag.isPrimitive); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
492 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
493 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
494 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
495 |
public boolean isNumeric() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
496 |
return tag != BOOLEAN; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
497 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
498 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
499 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
500 |
public boolean isPrimitive() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
501 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
502 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
503 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
504 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
505 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
506 |
return tag; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
507 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
508 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
509 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
510 |
public boolean isPrimitiveOrVoid() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
511 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
512 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
513 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
514 |
/** Define a constant type, of the same kind as this type |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
515 |
* and with given constant value |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
516 |
*/ |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
517 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
518 |
public Type constType(Object constValue) { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
519 |
final Object value = constValue; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
520 |
return new JCPrimitiveType(tag, tsym) { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
521 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
522 |
public Object constValue() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
523 |
return value; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
524 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
525 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
526 |
public Type baseType() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
527 |
return tsym.type; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
528 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
529 |
}; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
530 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
531 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
532 |
/** |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
533 |
* The constant value of this type, converted to String |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
534 |
*/ |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
535 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
536 |
public String stringValue() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
537 |
Object cv = Assert.checkNonNull(constValue()); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
538 |
if (tag == BOOLEAN) { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
539 |
return ((Integer) cv).intValue() == 0 ? "false" : "true"; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
540 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
541 |
else if (tag == CHAR) { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
542 |
return String.valueOf((char) ((Integer) cv).intValue()); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
543 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
544 |
else { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
545 |
return cv.toString(); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
546 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
547 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
548 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
549 |
/** Is this a constant type whose value is false? |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
550 |
*/ |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
551 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
552 |
public boolean isFalse() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
553 |
return |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
554 |
tag == BOOLEAN && |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
555 |
constValue() != null && |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
556 |
((Integer)constValue()).intValue() == 0; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
557 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
558 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
559 |
/** Is this a constant type whose value is true? |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
560 |
*/ |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
561 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
562 |
public boolean isTrue() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
563 |
return |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
564 |
tag == BOOLEAN && |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
565 |
constValue() != null && |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
566 |
((Integer)constValue()).intValue() != 0; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
567 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
568 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
569 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
570 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
10 | 571 |
return v.visitPrimitive(this, p); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
572 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
573 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
574 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
575 |
public TypeKind getKind() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
576 |
switch (tag) { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
577 |
case BYTE: return TypeKind.BYTE; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
578 |
case CHAR: return TypeKind.CHAR; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
579 |
case SHORT: return TypeKind.SHORT; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
580 |
case INT: return TypeKind.INT; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
581 |
case LONG: return TypeKind.LONG; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
582 |
case FLOAT: return TypeKind.FLOAT; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
583 |
case DOUBLE: return TypeKind.DOUBLE; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
584 |
case BOOLEAN: return TypeKind.BOOLEAN; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
585 |
} |
10 | 586 |
throw new AssertionError(); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
587 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
588 |
|
10 | 589 |
} |
590 |
||
591 |
public static class WildcardType extends Type |
|
592 |
implements javax.lang.model.type.WildcardType { |
|
593 |
||
594 |
public Type type; |
|
595 |
public BoundKind kind; |
|
596 |
public TypeVar bound; |
|
597 |
||
598 |
@Override |
|
599 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
600 |
return v.visitWildcardType(this, s); |
|
601 |
} |
|
602 |
||
603 |
public WildcardType(Type type, BoundKind kind, TypeSymbol tsym) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
604 |
super(tsym); |
8032 | 605 |
this.type = Assert.checkNonNull(type); |
10 | 606 |
this.kind = kind; |
607 |
} |
|
608 |
public WildcardType(WildcardType t, TypeVar bound) { |
|
609 |
this(t.type, t.kind, t.tsym, bound); |
|
610 |
} |
|
611 |
||
612 |
public WildcardType(Type type, BoundKind kind, TypeSymbol tsym, TypeVar bound) { |
|
613 |
this(type, kind, tsym); |
|
614 |
this.bound = bound; |
|
615 |
} |
|
616 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
617 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
618 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
619 |
return WILDCARD; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
620 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
621 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
622 |
@Override |
6348
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
623 |
public boolean contains(Type t) { |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
624 |
return kind != UNBOUND && type.contains(t); |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
625 |
} |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
626 |
|
10 | 627 |
public boolean isSuperBound() { |
628 |
return kind == SUPER || |
|
629 |
kind == UNBOUND; |
|
630 |
} |
|
631 |
public boolean isExtendsBound() { |
|
632 |
return kind == EXTENDS || |
|
633 |
kind == UNBOUND; |
|
634 |
} |
|
635 |
public boolean isUnbound() { |
|
636 |
return kind == UNBOUND; |
|
637 |
} |
|
638 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
639 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
640 |
public boolean isReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
641 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
642 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
643 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
644 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
645 |
public boolean isNullOrReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
646 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
647 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
648 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
649 |
@Override |
10 | 650 |
public Type withTypeVar(Type t) { |
651 |
//-System.err.println(this+".withTypeVar("+t+");");//DEBUG |
|
652 |
if (bound == t) |
|
653 |
return this; |
|
654 |
bound = (TypeVar)t; |
|
655 |
return this; |
|
656 |
} |
|
657 |
||
658 |
boolean isPrintingBound = false; |
|
659 |
public String toString() { |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
660 |
StringBuilder s = new StringBuilder(); |
10 | 661 |
s.append(kind.toString()); |
662 |
if (kind != UNBOUND) |
|
663 |
s.append(type); |
|
664 |
if (moreInfo && bound != null && !isPrintingBound) |
|
665 |
try { |
|
666 |
isPrintingBound = true; |
|
667 |
s.append("{:").append(bound.bound).append(":}"); |
|
668 |
} finally { |
|
669 |
isPrintingBound = false; |
|
670 |
} |
|
671 |
return s.toString(); |
|
672 |
} |
|
673 |
||
674 |
public Type map(Mapping f) { |
|
675 |
//- System.err.println(" (" + this + ").map(" + f + ")");//DEBUG |
|
676 |
Type t = type; |
|
677 |
if (t != null) |
|
678 |
t = f.apply(t); |
|
679 |
if (t == type) |
|
680 |
return this; |
|
681 |
else |
|
682 |
return new WildcardType(t, kind, tsym, bound); |
|
683 |
} |
|
684 |
||
685 |
public Type getExtendsBound() { |
|
686 |
if (kind == EXTENDS) |
|
687 |
return type; |
|
688 |
else |
|
689 |
return null; |
|
690 |
} |
|
691 |
||
692 |
public Type getSuperBound() { |
|
693 |
if (kind == SUPER) |
|
694 |
return type; |
|
695 |
else |
|
696 |
return null; |
|
697 |
} |
|
698 |
||
699 |
public TypeKind getKind() { |
|
700 |
return TypeKind.WILDCARD; |
|
701 |
} |
|
702 |
||
703 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
|
704 |
return v.visitWildcard(this, p); |
|
705 |
} |
|
706 |
} |
|
707 |
||
708 |
public static class ClassType extends Type implements DeclaredType { |
|
709 |
||
710 |
/** The enclosing type of this type. If this is the type of an inner |
|
711 |
* class, outer_field refers to the type of its enclosing |
|
15385 | 712 |
* instance class, in all other cases it refers to noType. |
10 | 713 |
*/ |
714 |
private Type outer_field; |
|
715 |
||
716 |
/** The type parameters of this type (to be set once class is loaded). |
|
717 |
*/ |
|
718 |
public List<Type> typarams_field; |
|
719 |
||
720 |
/** A cache variable for the type parameters of this type, |
|
721 |
* appended to all parameters of its enclosing class. |
|
722 |
* @see #allparams |
|
723 |
*/ |
|
724 |
public List<Type> allparams_field; |
|
725 |
||
726 |
/** The supertype of this class (to be set once class is loaded). |
|
727 |
*/ |
|
728 |
public Type supertype_field; |
|
729 |
||
730 |
/** The interfaces of this class (to be set once class is loaded). |
|
731 |
*/ |
|
732 |
public List<Type> interfaces_field; |
|
733 |
||
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
734 |
/** All the interfaces of this class, including missing ones. |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
735 |
*/ |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
736 |
public List<Type> all_interfaces_field; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
737 |
|
10 | 738 |
public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
739 |
super(tsym); |
10 | 740 |
this.outer_field = outer; |
741 |
this.typarams_field = typarams; |
|
742 |
this.allparams_field = null; |
|
743 |
this.supertype_field = null; |
|
744 |
this.interfaces_field = null; |
|
745 |
/* |
|
746 |
// this can happen during error recovery |
|
747 |
assert |
|
748 |
outer.isParameterized() ? |
|
749 |
typarams.length() == tsym.type.typarams().length() : |
|
750 |
outer.isRaw() ? |
|
751 |
typarams.length() == 0 : |
|
752 |
true; |
|
753 |
*/ |
|
754 |
} |
|
755 |
||
756 |
@Override |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
757 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
758 |
return CLASS; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
759 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
760 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
761 |
@Override |
10 | 762 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
763 |
return v.visitClassType(this, s); |
|
764 |
} |
|
765 |
||
766 |
public Type constType(Object constValue) { |
|
767 |
final Object value = constValue; |
|
768 |
return new ClassType(getEnclosingType(), typarams_field, tsym) { |
|
769 |
@Override |
|
770 |
public Object constValue() { |
|
771 |
return value; |
|
772 |
} |
|
773 |
@Override |
|
774 |
public Type baseType() { |
|
775 |
return tsym.type; |
|
776 |
} |
|
777 |
}; |
|
778 |
} |
|
779 |
||
780 |
/** The Java source which this type represents. |
|
781 |
*/ |
|
782 |
public String toString() { |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
783 |
StringBuilder buf = new StringBuilder(); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
784 |
if (getEnclosingType().hasTag(CLASS) && tsym.owner.kind == TYP) { |
10 | 785 |
buf.append(getEnclosingType().toString()); |
786 |
buf.append("."); |
|
787 |
buf.append(className(tsym, false)); |
|
788 |
} else { |
|
789 |
buf.append(className(tsym, true)); |
|
790 |
} |
|
791 |
if (getTypeArguments().nonEmpty()) { |
|
792 |
buf.append('<'); |
|
793 |
buf.append(getTypeArguments().toString()); |
|
794 |
buf.append(">"); |
|
795 |
} |
|
796 |
return buf.toString(); |
|
797 |
} |
|
798 |
//where |
|
799 |
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
|
800 |
if (sym.name.isEmpty() && (sym.flags() & COMPOUND) != 0) { |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
801 |
StringBuilder s = new StringBuilder(supertype_field.toString()); |
10 | 802 |
for (List<Type> is=interfaces_field; is.nonEmpty(); is = is.tail) { |
803 |
s.append("&"); |
|
804 |
s.append(is.head.toString()); |
|
805 |
} |
|
806 |
return s.toString(); |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
807 |
} else if (sym.name.isEmpty()) { |
10 | 808 |
String s; |
17578 | 809 |
ClassType norm = (ClassType) tsym.type.unannotatedType(); |
10 | 810 |
if (norm == null) { |
811 |
s = Log.getLocalizedString("anonymous.class", (Object)null); |
|
812 |
} else if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) { |
|
813 |
s = Log.getLocalizedString("anonymous.class", |
|
814 |
norm.interfaces_field.head); |
|
815 |
} else { |
|
816 |
s = Log.getLocalizedString("anonymous.class", |
|
817 |
norm.supertype_field); |
|
818 |
} |
|
819 |
if (moreInfo) |
|
820 |
s += String.valueOf(sym.hashCode()); |
|
821 |
return s; |
|
822 |
} else if (longform) { |
|
823 |
return sym.getQualifiedName().toString(); |
|
824 |
} else { |
|
825 |
return sym.name.toString(); |
|
826 |
} |
|
827 |
} |
|
828 |
||
829 |
public List<Type> getTypeArguments() { |
|
830 |
if (typarams_field == null) { |
|
831 |
complete(); |
|
832 |
if (typarams_field == null) |
|
833 |
typarams_field = List.nil(); |
|
834 |
} |
|
835 |
return typarams_field; |
|
836 |
} |
|
837 |
||
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
838 |
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
|
839 |
return isRaw(); |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
840 |
} |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
841 |
|
10 | 842 |
public Type getEnclosingType() { |
843 |
return outer_field; |
|
844 |
} |
|
845 |
||
846 |
public void setEnclosingType(Type outer) { |
|
847 |
outer_field = outer; |
|
848 |
} |
|
849 |
||
850 |
public List<Type> allparams() { |
|
851 |
if (allparams_field == null) { |
|
852 |
allparams_field = getTypeArguments().prependList(getEnclosingType().allparams()); |
|
853 |
} |
|
854 |
return allparams_field; |
|
855 |
} |
|
856 |
||
857 |
public boolean isErroneous() { |
|
858 |
return |
|
859 |
getEnclosingType().isErroneous() || |
|
860 |
isErroneous(getTypeArguments()) || |
|
17578 | 861 |
this != tsym.type.unannotatedType() && tsym.type.isErroneous(); |
10 | 862 |
} |
863 |
||
864 |
public boolean isParameterized() { |
|
865 |
return allparams().tail != null; |
|
866 |
// optimization, was: allparams().nonEmpty(); |
|
867 |
} |
|
868 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
869 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
870 |
public boolean isReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
871 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
872 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
873 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
874 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
875 |
public boolean isNullOrReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
876 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
877 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
878 |
|
10 | 879 |
/** A cache for the rank. */ |
880 |
int rank_field = -1; |
|
881 |
||
882 |
/** A class type is raw if it misses some |
|
883 |
* of its type parameter sections. |
|
884 |
* After validation, this is equivalent to: |
|
13844 | 885 |
* {@code allparams.isEmpty() && tsym.type.allparams.nonEmpty(); } |
10 | 886 |
*/ |
887 |
public boolean isRaw() { |
|
888 |
return |
|
889 |
this != tsym.type && // necessary, but not sufficient condition |
|
890 |
tsym.type.allparams().nonEmpty() && |
|
891 |
allparams().isEmpty(); |
|
892 |
} |
|
893 |
||
894 |
public Type map(Mapping f) { |
|
895 |
Type outer = getEnclosingType(); |
|
896 |
Type outer1 = f.apply(outer); |
|
897 |
List<Type> typarams = getTypeArguments(); |
|
898 |
List<Type> typarams1 = map(typarams, f); |
|
899 |
if (outer1 == outer && typarams1 == typarams) return this; |
|
900 |
else return new ClassType(outer1, typarams1, tsym); |
|
901 |
} |
|
902 |
||
903 |
public boolean contains(Type elem) { |
|
904 |
return |
|
905 |
elem == this |
|
906 |
|| (isParameterized() |
|
6348
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
907 |
&& (getEnclosingType().contains(elem) || contains(getTypeArguments(), elem))) |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
908 |
|| (isCompound() |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
909 |
&& (supertype_field.contains(elem) || contains(interfaces_field, elem))); |
10 | 910 |
} |
911 |
||
912 |
public void complete() { |
|
913 |
if (tsym.completer != null) tsym.complete(); |
|
914 |
} |
|
915 |
||
916 |
public TypeKind getKind() { |
|
917 |
return TypeKind.DECLARED; |
|
918 |
} |
|
919 |
||
920 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
|
921 |
return v.visitDeclared(this, p); |
|
922 |
} |
|
923 |
} |
|
924 |
||
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
925 |
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
|
926 |
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
|
927 |
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
|
928 |
} |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
929 |
|
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
930 |
@Override |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
931 |
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
|
932 |
return true; |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
933 |
} |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
934 |
} |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
935 |
|
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
936 |
// 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
|
937 |
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
|
938 |
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
|
939 |
|
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
940 |
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
|
941 |
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
|
942 |
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
|
943 |
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
|
944 |
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
|
945 |
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
|
946 |
alternatives_field = alternatives; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
947 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
948 |
|
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
949 |
public Type getLub() { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
950 |
return tsym.type; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
951 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
952 |
|
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
953 |
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
|
954 |
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
|
955 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
956 |
|
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
957 |
@Override |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
958 |
public TypeKind getKind() { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
959 |
return TypeKind.UNION; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
960 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
961 |
|
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
962 |
@Override |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
963 |
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
|
964 |
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
|
965 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
966 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
967 |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
968 |
// a clone of a ClassType that knows about the bounds of an intersection type. |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
969 |
public static class IntersectionClassType extends ClassType implements IntersectionType { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
970 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
971 |
public boolean allInterfaces; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
972 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
973 |
public IntersectionClassType(List<Type> bounds, ClassSymbol csym, boolean allInterfaces) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
974 |
super(Type.noType, List.<Type>nil(), csym); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
975 |
this.allInterfaces = allInterfaces; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
976 |
Assert.check((csym.flags() & COMPOUND) != 0); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
977 |
supertype_field = bounds.head; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
978 |
interfaces_field = bounds.tail; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
979 |
Assert.check(supertype_field.tsym.completer != null || |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
980 |
!supertype_field.isInterface(), supertype_field); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
981 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
982 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
983 |
public java.util.List<? extends TypeMirror> getBounds() { |
20252
fae5c47ba7a4
6499673: Assertion check for TypeVariable.getUpperBound() fails.
emc
parents:
20249
diff
changeset
|
984 |
return Collections.unmodifiableList(getExplicitComponents()); |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
985 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
986 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
987 |
public List<Type> getComponents() { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
988 |
return interfaces_field.prepend(supertype_field); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
989 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
990 |
|
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16557
diff
changeset
|
991 |
public List<Type> getExplicitComponents() { |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16557
diff
changeset
|
992 |
return allInterfaces ? |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16557
diff
changeset
|
993 |
interfaces_field : |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16557
diff
changeset
|
994 |
getComponents(); |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16557
diff
changeset
|
995 |
} |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16557
diff
changeset
|
996 |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
997 |
@Override |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
998 |
public TypeKind getKind() { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
999 |
return TypeKind.INTERSECTION; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1000 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1001 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1002 |
@Override |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1003 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
21890
a627c91c71db
6557966: Multiple upper bounds of the TypeVariable
jlahoda
parents:
21041
diff
changeset
|
1004 |
return v.visitIntersection(this, p); |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1005 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1006 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1007 |
|
10 | 1008 |
public static class ArrayType extends Type |
1009 |
implements javax.lang.model.type.ArrayType { |
|
1010 |
||
1011 |
public Type elemtype; |
|
1012 |
||
1013 |
public ArrayType(Type elemtype, TypeSymbol arrayClass) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1014 |
super(arrayClass); |
10 | 1015 |
this.elemtype = elemtype; |
1016 |
} |
|
1017 |
||
1018 |
@Override |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1019 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1020 |
return ARRAY; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1021 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1022 |
|
10 | 1023 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
1024 |
return v.visitArrayType(this, s); |
|
1025 |
} |
|
1026 |
||
1027 |
public String toString() { |
|
1028 |
return elemtype + "[]"; |
|
1029 |
} |
|
1030 |
||
1031 |
public boolean equals(Object obj) { |
|
1032 |
return |
|
1033 |
this == obj || |
|
1034 |
(obj instanceof ArrayType && |
|
1035 |
this.elemtype.equals(((ArrayType)obj).elemtype)); |
|
1036 |
} |
|
1037 |
||
1038 |
public int hashCode() { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
1039 |
return (ARRAY.ordinal() << 5) + elemtype.hashCode(); |
10 | 1040 |
} |
1041 |
||
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1042 |
public boolean isVarargs() { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1043 |
return false; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1044 |
} |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1045 |
|
10 | 1046 |
public List<Type> allparams() { return elemtype.allparams(); } |
1047 |
||
1048 |
public boolean isErroneous() { |
|
1049 |
return elemtype.isErroneous(); |
|
1050 |
} |
|
1051 |
||
1052 |
public boolean isParameterized() { |
|
1053 |
return elemtype.isParameterized(); |
|
1054 |
} |
|
1055 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1056 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1057 |
public boolean isReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1058 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1059 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1060 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1061 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1062 |
public boolean isNullOrReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1063 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1064 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1065 |
|
10 | 1066 |
public boolean isRaw() { |
1067 |
return elemtype.isRaw(); |
|
1068 |
} |
|
1069 |
||
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1070 |
public ArrayType makeVarargs() { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1071 |
return new ArrayType(elemtype, tsym) { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1072 |
@Override |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1073 |
public boolean isVarargs() { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1074 |
return true; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1075 |
} |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1076 |
}; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1077 |
} |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1078 |
|
10 | 1079 |
public Type map(Mapping f) { |
1080 |
Type elemtype1 = f.apply(elemtype); |
|
1081 |
if (elemtype1 == elemtype) return this; |
|
1082 |
else return new ArrayType(elemtype1, tsym); |
|
1083 |
} |
|
1084 |
||
1085 |
public boolean contains(Type elem) { |
|
1086 |
return elem == this || elemtype.contains(elem); |
|
1087 |
} |
|
1088 |
||
1089 |
public void complete() { |
|
1090 |
elemtype.complete(); |
|
1091 |
} |
|
1092 |
||
1093 |
public Type getComponentType() { |
|
1094 |
return elemtype; |
|
1095 |
} |
|
1096 |
||
1097 |
public TypeKind getKind() { |
|
1098 |
return TypeKind.ARRAY; |
|
1099 |
} |
|
1100 |
||
1101 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
|
1102 |
return v.visitArray(this, p); |
|
1103 |
} |
|
1104 |
} |
|
1105 |
||
8430 | 1106 |
public static class MethodType extends Type implements ExecutableType { |
10 | 1107 |
|
1108 |
public List<Type> argtypes; |
|
1109 |
public Type restype; |
|
1110 |
public List<Type> thrown; |
|
1111 |
||
15385 | 1112 |
/** The type annotations on the method receiver. |
1113 |
*/ |
|
1114 |
public Type recvtype; |
|
1115 |
||
10 | 1116 |
public MethodType(List<Type> argtypes, |
1117 |
Type restype, |
|
1118 |
List<Type> thrown, |
|
1119 |
TypeSymbol methodClass) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1120 |
super(methodClass); |
10 | 1121 |
this.argtypes = argtypes; |
1122 |
this.restype = restype; |
|
1123 |
this.thrown = thrown; |
|
1124 |
} |
|
1125 |
||
1126 |
@Override |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1127 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1128 |
return METHOD; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1129 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1130 |
|
10 | 1131 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
1132 |
return v.visitMethodType(this, s); |
|
1133 |
} |
|
1134 |
||
1135 |
/** The Java source which this type represents. |
|
1136 |
* |
|
1137 |
* XXX 06/09/99 iris This isn't correct Java syntax, but it probably |
|
1138 |
* should be. |
|
1139 |
*/ |
|
1140 |
public String toString() { |
|
1141 |
return "(" + argtypes + ")" + restype; |
|
1142 |
} |
|
1143 |
||
1144 |
public List<Type> getParameterTypes() { return argtypes; } |
|
1145 |
public Type getReturnType() { return restype; } |
|
15385 | 1146 |
public Type getReceiverType() { return recvtype; } |
10 | 1147 |
public List<Type> getThrownTypes() { return thrown; } |
1148 |
||
1149 |
public boolean isErroneous() { |
|
1150 |
return |
|
1151 |
isErroneous(argtypes) || |
|
1152 |
restype != null && restype.isErroneous(); |
|
1153 |
} |
|
1154 |
||
1155 |
public Type map(Mapping f) { |
|
1156 |
List<Type> argtypes1 = map(argtypes, f); |
|
1157 |
Type restype1 = f.apply(restype); |
|
1158 |
List<Type> thrown1 = map(thrown, f); |
|
1159 |
if (argtypes1 == argtypes && |
|
1160 |
restype1 == restype && |
|
1161 |
thrown1 == thrown) return this; |
|
1162 |
else return new MethodType(argtypes1, restype1, thrown1, tsym); |
|
1163 |
} |
|
1164 |
||
1165 |
public boolean contains(Type elem) { |
|
19502
f30b3ef165ea
8015809: More user friendly compile-time errors for uncaught exceptions in lambda expression
jlahoda
parents:
19493
diff
changeset
|
1166 |
return elem == this || contains(argtypes, elem) || restype.contains(elem) || contains(thrown, elem); |
10 | 1167 |
} |
1168 |
||
1169 |
public MethodType asMethodType() { return this; } |
|
1170 |
||
1171 |
public void complete() { |
|
1172 |
for (List<Type> l = argtypes; l.nonEmpty(); l = l.tail) |
|
1173 |
l.head.complete(); |
|
1174 |
restype.complete(); |
|
15385 | 1175 |
recvtype.complete(); |
10 | 1176 |
for (List<Type> l = thrown; l.nonEmpty(); l = l.tail) |
1177 |
l.head.complete(); |
|
1178 |
} |
|
1179 |
||
1180 |
public List<TypeVar> getTypeVariables() { |
|
1181 |
return List.nil(); |
|
1182 |
} |
|
1183 |
||
1184 |
public TypeSymbol asElement() { |
|
1185 |
return null; |
|
1186 |
} |
|
1187 |
||
1188 |
public TypeKind getKind() { |
|
1189 |
return TypeKind.EXECUTABLE; |
|
1190 |
} |
|
1191 |
||
1192 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
|
1193 |
return v.visitExecutable(this, p); |
|
1194 |
} |
|
1195 |
} |
|
1196 |
||
1197 |
public static class PackageType extends Type implements NoType { |
|
1198 |
||
1199 |
PackageType(TypeSymbol tsym) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1200 |
super(tsym); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1201 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1202 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1203 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1204 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1205 |
return PACKAGE; |
10 | 1206 |
} |
1207 |
||
1208 |
@Override |
|
1209 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
1210 |
return v.visitPackageType(this, s); |
|
1211 |
} |
|
1212 |
||
1213 |
public String toString() { |
|
1214 |
return tsym.getQualifiedName().toString(); |
|
1215 |
} |
|
1216 |
||
1217 |
public TypeKind getKind() { |
|
1218 |
return TypeKind.PACKAGE; |
|
1219 |
} |
|
1220 |
||
1221 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
|
1222 |
return v.visitNoType(this, p); |
|
1223 |
} |
|
1224 |
} |
|
1225 |
||
1226 |
public static class TypeVar extends Type implements TypeVariable { |
|
1227 |
||
7637 | 1228 |
/** The upper bound of this type variable; set from outside. |
10 | 1229 |
* Must be nonempty once it is set. |
1230 |
* For a bound, `bound' is the bound type itself. |
|
1231 |
* Multiple bounds are expressed as a single class type which has the |
|
1232 |
* individual bounds as superclass, respectively interfaces. |
|
1233 |
* The class type then has as `tsym' a compiler generated class `c', |
|
1234 |
* which has a flag COMPOUND and whose owner is the type variable |
|
1235 |
* itself. Furthermore, the erasure_field of the class |
|
1236 |
* points to the first class or interface bound. |
|
1237 |
*/ |
|
1238 |
public Type bound = null; |
|
7637 | 1239 |
|
1240 |
/** The lower bound of this type variable. |
|
1241 |
* TypeVars don't normally have a lower bound, so it is normally set |
|
1242 |
* to syms.botType. |
|
1243 |
* Subtypes, such as CapturedType, may provide a different value. |
|
1244 |
*/ |
|
10 | 1245 |
public Type lower; |
1246 |
||
1247 |
public TypeVar(Name name, Symbol owner, Type lower) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1248 |
super(null); |
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16809
diff
changeset
|
1249 |
tsym = new TypeVariableSymbol(0, name, this, owner); |
10 | 1250 |
this.lower = lower; |
1251 |
} |
|
1252 |
||
1253 |
public TypeVar(TypeSymbol tsym, Type bound, Type lower) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1254 |
super(tsym); |
10 | 1255 |
this.bound = bound; |
1256 |
this.lower = lower; |
|
1257 |
} |
|
1258 |
||
1259 |
@Override |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1260 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1261 |
return TYPEVAR; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1262 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1263 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1264 |
@Override |
10 | 1265 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
1266 |
return v.visitTypeVar(this, s); |
|
1267 |
} |
|
1268 |
||
7637 | 1269 |
@Override |
15385 | 1270 |
public Type getUpperBound() { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1271 |
if ((bound == null || bound.hasTag(NONE)) && this != tsym.type) { |
15385 | 1272 |
bound = tsym.type.getUpperBound(); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1273 |
} |
15385 | 1274 |
return bound; |
1275 |
} |
|
10 | 1276 |
|
1277 |
int rank_field = -1; |
|
1278 |
||
7637 | 1279 |
@Override |
10 | 1280 |
public Type getLowerBound() { |
1281 |
return lower; |
|
1282 |
} |
|
1283 |
||
1284 |
public TypeKind getKind() { |
|
1285 |
return TypeKind.TYPEVAR; |
|
1286 |
} |
|
1287 |
||
938
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1288 |
public boolean isCaptured() { |
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1289 |
return false; |
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1290 |
} |
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1291 |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1292 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1293 |
public boolean isReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1294 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1295 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1296 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1297 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1298 |
public boolean isNullOrReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1299 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1300 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1301 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1302 |
@Override |
10 | 1303 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
1304 |
return v.visitTypeVariable(this, p); |
|
1305 |
} |
|
1306 |
} |
|
1307 |
||
1308 |
/** A captured type variable comes from wildcards which can have |
|
1309 |
* both upper and lower bound. CapturedType extends TypeVar with |
|
1310 |
* a lower bound. |
|
1311 |
*/ |
|
1312 |
public static class CapturedType extends TypeVar { |
|
1313 |
||
1314 |
public WildcardType wildcard; |
|
1315 |
||
1316 |
public CapturedType(Name name, |
|
1317 |
Symbol owner, |
|
1318 |
Type upper, |
|
1319 |
Type lower, |
|
1320 |
WildcardType wildcard) { |
|
1321 |
super(name, owner, lower); |
|
8032 | 1322 |
this.lower = Assert.checkNonNull(lower); |
10 | 1323 |
this.bound = upper; |
1324 |
this.wildcard = wildcard; |
|
1325 |
} |
|
1326 |
||
1327 |
@Override |
|
1328 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
1329 |
return v.visitCapturedType(this, s); |
|
1330 |
} |
|
1331 |
||
1332 |
@Override |
|
938
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1333 |
public boolean isCaptured() { |
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1334 |
return true; |
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1335 |
} |
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1336 |
|
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1337 |
@Override |
10 | 1338 |
public String toString() { |
1339 |
return "capture#" |
|
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
1527
diff
changeset
|
1340 |
+ (hashCode() & 0xFFFFFFFFL) % Printer.PRIME |
10 | 1341 |
+ " of " |
1342 |
+ wildcard; |
|
1343 |
} |
|
1344 |
} |
|
1345 |
||
1346 |
public static abstract class DelegatedType extends Type { |
|
1347 |
public Type qtype; |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1348 |
public TypeTag tag; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
1349 |
public DelegatedType(TypeTag tag, Type qtype) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1350 |
super(qtype.tsym); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1351 |
this.tag = tag; |
10 | 1352 |
this.qtype = qtype; |
1353 |
} |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1354 |
public TypeTag getTag() { return tag; } |
10 | 1355 |
public String toString() { return qtype.toString(); } |
1356 |
public List<Type> getTypeArguments() { return qtype.getTypeArguments(); } |
|
1357 |
public Type getEnclosingType() { return qtype.getEnclosingType(); } |
|
1358 |
public List<Type> getParameterTypes() { return qtype.getParameterTypes(); } |
|
1359 |
public Type getReturnType() { return qtype.getReturnType(); } |
|
15385 | 1360 |
public Type getReceiverType() { return qtype.getReceiverType(); } |
10 | 1361 |
public List<Type> getThrownTypes() { return qtype.getThrownTypes(); } |
1362 |
public List<Type> allparams() { return qtype.allparams(); } |
|
1363 |
public Type getUpperBound() { return qtype.getUpperBound(); } |
|
1364 |
public boolean isErroneous() { return qtype.isErroneous(); } |
|
1365 |
} |
|
1366 |
||
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
1367 |
/** |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
1368 |
* 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
|
1369 |
* 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
|
1370 |
* type. |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
1371 |
*/ |
8430 | 1372 |
public static class ForAll extends DelegatedType implements ExecutableType { |
10 | 1373 |
public List<Type> tvars; |
1374 |
||
1375 |
public ForAll(List<Type> tvars, Type qtype) { |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
1376 |
super(FORALL, (MethodType)qtype); |
10 | 1377 |
this.tvars = tvars; |
1378 |
} |
|
1379 |
||
1380 |
@Override |
|
1381 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
1382 |
return v.visitForAll(this, s); |
|
1383 |
} |
|
1384 |
||
1385 |
public String toString() { |
|
1386 |
return "<" + tvars + ">" + qtype; |
|
1387 |
} |
|
1388 |
||
1389 |
public List<Type> getTypeArguments() { return tvars; } |
|
1390 |
||
1391 |
public boolean isErroneous() { |
|
1392 |
return qtype.isErroneous(); |
|
1393 |
} |
|
1394 |
||
1395 |
public Type map(Mapping f) { |
|
1396 |
return f.apply(qtype); |
|
1397 |
} |
|
1398 |
||
1399 |
public boolean contains(Type elem) { |
|
1400 |
return qtype.contains(elem); |
|
1401 |
} |
|
1402 |
||
1403 |
public MethodType asMethodType() { |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
1404 |
return (MethodType)qtype; |
10 | 1405 |
} |
1406 |
||
1407 |
public void complete() { |
|
1408 |
for (List<Type> l = tvars; l.nonEmpty(); l = l.tail) { |
|
1409 |
((TypeVar)l.head).bound.complete(); |
|
1410 |
} |
|
1411 |
qtype.complete(); |
|
1412 |
} |
|
1413 |
||
1414 |
public List<TypeVar> getTypeVariables() { |
|
1415 |
return List.convert(TypeVar.class, getTypeArguments()); |
|
1416 |
} |
|
1417 |
||
1418 |
public TypeKind getKind() { |
|
1419 |
return TypeKind.EXECUTABLE; |
|
1420 |
} |
|
1421 |
||
1422 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
|
1423 |
return v.visitExecutable(this, p); |
|
1424 |
} |
|
1425 |
} |
|
1426 |
||
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1427 |
/** A class for inference variables, for use during method/diamond type |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1428 |
* inference. An inference variable has upper/lower bounds and a set |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1429 |
* of equality constraints. Such bounds are set during subtyping, type-containment, |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1430 |
* type-equality checks, when the types being tested contain inference variables. |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1431 |
* A change listener can be attached to an inference variable, to receive notifications |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1432 |
* whenever the bounds of an inference variable change. |
10 | 1433 |
*/ |
1434 |
public static class UndetVar extends DelegatedType { |
|
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1435 |
|
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1436 |
/** Inference variable change listener. The listener method is called |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1437 |
* whenever a change to the inference variable's bounds occurs |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1438 |
*/ |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1439 |
public interface UndetVarListener { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1440 |
/** called when some inference variable bounds (of given kinds ibs) change */ |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1441 |
void varChanged(UndetVar uv, Set<InferenceBound> ibs); |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1442 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1443 |
|
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1444 |
/** |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1445 |
* Inference variable bound kinds |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1446 |
*/ |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1447 |
public enum InferenceBound { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1448 |
/** upper bounds */ |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1449 |
UPPER, |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1450 |
/** lower bounds */ |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1451 |
LOWER, |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1452 |
/** equality constraints */ |
22163 | 1453 |
EQ |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1454 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1455 |
|
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1456 |
/** inference variable bounds */ |
18911 | 1457 |
protected Map<InferenceBound, List<Type>> bounds; |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1458 |
|
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1459 |
/** inference variable's inferred type (set from Infer.java) */ |
10 | 1460 |
public Type inst = null; |
1461 |
||
15705 | 1462 |
/** number of declared (upper) bounds */ |
1463 |
public int declaredCount; |
|
1464 |
||
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1465 |
/** inference variable's change listener */ |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1466 |
public UndetVarListener listener = null; |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1467 |
|
10 | 1468 |
@Override |
1469 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
1470 |
return v.visitUndetVar(this, s); |
|
1471 |
} |
|
1472 |
||
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1473 |
public UndetVar(TypeVar origin, Types types) { |
10 | 1474 |
super(UNDETVAR, origin); |
22163 | 1475 |
bounds = new EnumMap<>(InferenceBound.class); |
15705 | 1476 |
List<Type> declaredBounds = types.getBounds(origin); |
1477 |
declaredCount = declaredBounds.length(); |
|
1478 |
bounds.put(InferenceBound.UPPER, declaredBounds); |
|
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1479 |
bounds.put(InferenceBound.LOWER, List.<Type>nil()); |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1480 |
bounds.put(InferenceBound.EQ, List.<Type>nil()); |
10 | 1481 |
} |
1482 |
||
1483 |
public String toString() { |
|
1484 |
if (inst != null) return inst.toString(); |
|
1485 |
else return qtype + "?"; |
|
1486 |
} |
|
1487 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1488 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1489 |
public boolean isPartial() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1490 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1491 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1492 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1493 |
@Override |
10 | 1494 |
public Type baseType() { |
1495 |
if (inst != null) return inst.baseType(); |
|
1496 |
else return this; |
|
1497 |
} |
|
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1498 |
|
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1499 |
/** get all bounds of a given kind */ |
15705 | 1500 |
public List<Type> getBounds(InferenceBound... ibs) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19502
diff
changeset
|
1501 |
ListBuffer<Type> buf = new ListBuffer<>(); |
15705 | 1502 |
for (InferenceBound ib : ibs) { |
1503 |
buf.appendList(bounds.get(ib)); |
|
1504 |
} |
|
1505 |
return buf.toList(); |
|
1506 |
} |
|
1507 |
||
1508 |
/** get the list of declared (upper) bounds */ |
|
1509 |
public List<Type> getDeclaredBounds() { |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19502
diff
changeset
|
1510 |
ListBuffer<Type> buf = new ListBuffer<>(); |
15705 | 1511 |
int count = 0; |
1512 |
for (Type b : getBounds(InferenceBound.UPPER)) { |
|
1513 |
if (count++ == declaredCount) break; |
|
1514 |
buf.append(b); |
|
1515 |
} |
|
1516 |
return buf.toList(); |
|
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1517 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1518 |
|
18904
3c4c6457ec5b
8019824: very long error messages on inference error
mcimadamore
parents:
18902
diff
changeset
|
1519 |
/** internal method used to override an undetvar bounds */ |
3c4c6457ec5b
8019824: very long error messages on inference error
mcimadamore
parents:
18902
diff
changeset
|
1520 |
public void setBounds(InferenceBound ib, List<Type> newBounds) { |
3c4c6457ec5b
8019824: very long error messages on inference error
mcimadamore
parents:
18902
diff
changeset
|
1521 |
bounds.put(ib, newBounds); |
3c4c6457ec5b
8019824: very long error messages on inference error
mcimadamore
parents:
18902
diff
changeset
|
1522 |
} |
3c4c6457ec5b
8019824: very long error messages on inference error
mcimadamore
parents:
18902
diff
changeset
|
1523 |
|
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1524 |
/** add a bound of a given kind - this might trigger listener notification */ |
18911 | 1525 |
public final void addBound(InferenceBound ib, Type bound, Types types) { |
1526 |
addBound(ib, bound, types, false); |
|
1527 |
} |
|
1528 |
||
1529 |
protected void addBound(InferenceBound ib, Type bound, Types types, boolean update) { |
|
19493
f2028bc02f0c
8021567: Javac doesn't report \"java: reference to method is ambiguous\" any more
mcimadamore
parents:
18918
diff
changeset
|
1530 |
Type bound2 = toTypeVarMap.apply(bound).baseType(); |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1531 |
List<Type> prevBounds = bounds.get(ib); |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1532 |
for (Type b : prevBounds) { |
15705 | 1533 |
//check for redundancy - use strict version of isSameType on tvars |
1534 |
//(as the standard version will lead to false positives w.r.t. clones ivars) |
|
16341
cc4b4e3c0f12
8009545: Graph inference: dependencies between inference variables should be set during incorporation
mcimadamore
parents:
15705
diff
changeset
|
1535 |
if (types.isSameType(b, bound2, true) || bound == qtype) return; |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1536 |
} |
15705 | 1537 |
bounds.put(ib, prevBounds.prepend(bound2)); |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1538 |
notifyChange(EnumSet.of(ib)); |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1539 |
} |
15705 | 1540 |
//where |
18918
4e8769f15a95
8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents:
18911
diff
changeset
|
1541 |
Type.Mapping toTypeVarMap = new Mapping("toTypeVarMap") { |
15705 | 1542 |
@Override |
1543 |
public Type apply(Type t) { |
|
1544 |
if (t.hasTag(UNDETVAR)) { |
|
1545 |
UndetVar uv = (UndetVar)t; |
|
18904
3c4c6457ec5b
8019824: very long error messages on inference error
mcimadamore
parents:
18902
diff
changeset
|
1546 |
return uv.inst != null ? uv.inst : uv.qtype; |
15705 | 1547 |
} else { |
1548 |
return t.map(this); |
|
1549 |
} |
|
1550 |
} |
|
1551 |
}; |
|
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1552 |
|
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1553 |
/** replace types in all bounds - this might trigger listener notification */ |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1554 |
public void substBounds(List<Type> from, List<Type> to, Types types) { |
15705 | 1555 |
List<Type> instVars = from.diff(to); |
1556 |
//if set of instantiated ivars is empty, there's nothing to do! |
|
1557 |
if (instVars.isEmpty()) return; |
|
1558 |
final EnumSet<InferenceBound> boundsChanged = EnumSet.noneOf(InferenceBound.class); |
|
1559 |
UndetVarListener prevListener = listener; |
|
1560 |
try { |
|
1561 |
//setup new listener for keeping track of changed bounds |
|
1562 |
listener = new UndetVarListener() { |
|
1563 |
public void varChanged(UndetVar uv, Set<InferenceBound> ibs) { |
|
1564 |
boundsChanged.addAll(ibs); |
|
1565 |
} |
|
1566 |
}; |
|
1567 |
for (Map.Entry<InferenceBound, List<Type>> _entry : bounds.entrySet()) { |
|
1568 |
InferenceBound ib = _entry.getKey(); |
|
1569 |
List<Type> prevBounds = _entry.getValue(); |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19502
diff
changeset
|
1570 |
ListBuffer<Type> newBounds = new ListBuffer<>(); |
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19502
diff
changeset
|
1571 |
ListBuffer<Type> deps = new ListBuffer<>(); |
15705 | 1572 |
//step 1 - re-add bounds that are not dependent on ivars |
1573 |
for (Type t : prevBounds) { |
|
1574 |
if (!t.containsAny(instVars)) { |
|
1575 |
newBounds.append(t); |
|
1576 |
} else { |
|
1577 |
deps.append(t); |
|
1578 |
} |
|
1579 |
} |
|
1580 |
//step 2 - replace bounds |
|
1581 |
bounds.put(ib, newBounds.toList()); |
|
1582 |
//step 3 - for each dependency, add new replaced bound |
|
1583 |
for (Type dep : deps) { |
|
18911 | 1584 |
addBound(ib, types.subst(dep, from, to), types, true); |
15705 | 1585 |
} |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1586 |
} |
15705 | 1587 |
} finally { |
1588 |
listener = prevListener; |
|
1589 |
if (!boundsChanged.isEmpty()) { |
|
1590 |
notifyChange(boundsChanged); |
|
1591 |
} |
|
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1592 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1593 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1594 |
|
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1595 |
private void notifyChange(EnumSet<InferenceBound> ibs) { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1596 |
if (listener != null) { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1597 |
listener.varChanged(this, ibs); |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1598 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1599 |
} |
18911 | 1600 |
|
1601 |
public boolean isCaptured() { |
|
1602 |
return false; |
|
1603 |
} |
|
1604 |
} |
|
1605 |
||
1606 |
/** |
|
1607 |
* This class is used to represent synthetic captured inference variables |
|
1608 |
* that can be generated during nested generic method calls. The only difference |
|
1609 |
* between these inference variables and ordinary ones is that captured inference |
|
1610 |
* variables cannot get new bounds through incorporation. |
|
1611 |
*/ |
|
1612 |
public static class CapturedUndetVar extends UndetVar { |
|
1613 |
||
1614 |
public CapturedUndetVar(CapturedType origin, Types types) { |
|
1615 |
super(origin, types); |
|
1616 |
if (!origin.lower.hasTag(BOT)) { |
|
1617 |
bounds.put(InferenceBound.LOWER, List.of(origin.lower)); |
|
1618 |
} |
|
1619 |
} |
|
1620 |
||
1621 |
@Override |
|
1622 |
public void addBound(InferenceBound ib, Type bound, Types types, boolean update) { |
|
1623 |
if (update) { |
|
1624 |
//only change bounds if request comes from substBounds |
|
1625 |
super.addBound(ib, bound, types, update); |
|
1626 |
} |
|
1627 |
} |
|
1628 |
||
1629 |
@Override |
|
1630 |
public boolean isCaptured() { |
|
1631 |
return true; |
|
1632 |
} |
|
10 | 1633 |
} |
1634 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1635 |
/** Represents NONE. |
10 | 1636 |
*/ |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1637 |
public static class JCNoType extends Type implements NoType { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1638 |
public JCNoType() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1639 |
super(null); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1640 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1641 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1642 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1643 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1644 |
return NONE; |
10 | 1645 |
} |
1646 |
||
1647 |
@Override |
|
1648 |
public TypeKind getKind() { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1649 |
return TypeKind.NONE; |
10 | 1650 |
} |
1651 |
||
1652 |
@Override |
|
1653 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
|
1654 |
return v.visitNoType(this, p); |
|
1655 |
} |
|
20606 | 1656 |
|
1657 |
@Override |
|
1658 |
public boolean isCompound() { return false; } |
|
10 | 1659 |
} |
1660 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1661 |
/** Represents VOID. |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1662 |
*/ |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1663 |
public static class JCVoidType extends Type implements NoType { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1664 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1665 |
public JCVoidType() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1666 |
super(null); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1667 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1668 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1669 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1670 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1671 |
return VOID; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1672 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1673 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1674 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1675 |
public TypeKind getKind() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1676 |
return TypeKind.VOID; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1677 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1678 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1679 |
@Override |
20606 | 1680 |
public boolean isCompound() { return false; } |
1681 |
||
1682 |
@Override |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1683 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1684 |
return v.visitNoType(this, p); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1685 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1686 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1687 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1688 |
public boolean isPrimitiveOrVoid() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1689 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1690 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1691 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1692 |
|
10 | 1693 |
static class BottomType extends Type implements NullType { |
1694 |
public BottomType() { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1695 |
super(null); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1696 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1697 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1698 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1699 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1700 |
return BOT; |
10 | 1701 |
} |
1702 |
||
1703 |
@Override |
|
1704 |
public TypeKind getKind() { |
|
1705 |
return TypeKind.NULL; |
|
1706 |
} |
|
1707 |
||
1708 |
@Override |
|
20606 | 1709 |
public boolean isCompound() { return false; } |
1710 |
||
1711 |
@Override |
|
10 | 1712 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
1713 |
return v.visitNull(this, p); |
|
1714 |
} |
|
1715 |
||
1716 |
@Override |
|
1717 |
public Type constType(Object value) { |
|
1718 |
return this; |
|
1719 |
} |
|
1720 |
||
1721 |
@Override |
|
1722 |
public String stringValue() { |
|
1723 |
return "null"; |
|
1724 |
} |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1725 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1726 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1727 |
public boolean isNullOrReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1728 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1729 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1730 |
|
10 | 1731 |
} |
1732 |
||
1733 |
public static class ErrorType extends ClassType |
|
1734 |
implements javax.lang.model.type.ErrorType { |
|
1735 |
||
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
|
1736 |
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
|
1737 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
1738 |
public ErrorType(Type originalType, TypeSymbol tsym) { |
10 | 1739 |
super(noType, List.<Type>nil(), null); |
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
|
1740 |
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
|
1741 |
this.originalType = (originalType == null ? noType : originalType); |
10 | 1742 |
} |
1743 |
||
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
|
1744 |
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
|
1745 |
this(originalType, c); |
10 | 1746 |
c.type = this; |
1747 |
c.kind = ERR; |
|
1748 |
c.members_field = new Scope.ErrorScope(c); |
|
1749 |
} |
|
1750 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1751 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1752 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1753 |
return ERROR; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1754 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1755 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1756 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1757 |
public boolean isPartial() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1758 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1759 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1760 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1761 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1762 |
public boolean isReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1763 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1764 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1765 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1766 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1767 |
public boolean isNullOrReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1768 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1769 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1770 |
|
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
|
1771 |
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
|
1772 |
this(new ClassSymbol(PUBLIC|STATIC|ACYCLIC, name, null, container), originalType); |
10 | 1773 |
} |
1774 |
||
1775 |
@Override |
|
1776 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
1777 |
return v.visitErrorType(this, s); |
|
1778 |
} |
|
1779 |
||
1780 |
public Type constType(Object constValue) { return this; } |
|
15385 | 1781 |
public Type getEnclosingType() { return this; } |
10 | 1782 |
public Type getReturnType() { return this; } |
1783 |
public Type asSub(Symbol sym) { return this; } |
|
1784 |
public Type map(Mapping f) { return this; } |
|
1785 |
||
1786 |
public boolean isGenType(Type t) { return true; } |
|
1787 |
public boolean isErroneous() { return true; } |
|
1788 |
public boolean isCompound() { return false; } |
|
1789 |
public boolean isInterface() { return false; } |
|
1790 |
||
1791 |
public List<Type> allparams() { return List.nil(); } |
|
1792 |
public List<Type> getTypeArguments() { return List.nil(); } |
|
1793 |
||
1794 |
public TypeKind getKind() { |
|
1795 |
return TypeKind.ERROR; |
|
1796 |
} |
|
1797 |
||
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
|
1798 |
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
|
1799 |
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
|
1800 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
1801 |
|
10 | 1802 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
1803 |
return v.visitError(this, p); |
|
1804 |
} |
|
1805 |
} |
|
1806 |
||
15385 | 1807 |
public static class AnnotatedType extends Type |
16556
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
16341
diff
changeset
|
1808 |
implements |
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
16341
diff
changeset
|
1809 |
javax.lang.model.type.ArrayType, |
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
16341
diff
changeset
|
1810 |
javax.lang.model.type.DeclaredType, |
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
16341
diff
changeset
|
1811 |
javax.lang.model.type.PrimitiveType, |
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
16341
diff
changeset
|
1812 |
javax.lang.model.type.TypeVariable, |
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
16341
diff
changeset
|
1813 |
javax.lang.model.type.WildcardType { |
15385 | 1814 |
/** The type annotations on this type. |
1815 |
*/ |
|
21041 | 1816 |
private List<Attribute.TypeCompound> typeAnnotations; |
15385 | 1817 |
|
1818 |
/** The underlying type that is annotated. |
|
1819 |
*/ |
|
21041 | 1820 |
private Type underlyingType; |
15385 | 1821 |
|
21041 | 1822 |
protected AnnotatedType(List<Attribute.TypeCompound> typeAnnotations, |
15385 | 1823 |
Type underlyingType) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1824 |
super(underlyingType.tsym); |
15385 | 1825 |
this.typeAnnotations = typeAnnotations; |
1826 |
this.underlyingType = underlyingType; |
|
21041 | 1827 |
Assert.check(typeAnnotations != null && typeAnnotations.nonEmpty(), |
1828 |
"Can't create AnnotatedType without annotations: " + underlyingType); |
|
16556
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
16341
diff
changeset
|
1829 |
Assert.check(!underlyingType.isAnnotated(), |
15385 | 1830 |
"Can't annotate already annotated type: " + underlyingType + |
1831 |
"; adding: " + typeAnnotations); |
|
1832 |
} |
|
1833 |
||
1834 |
@Override |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1835 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1836 |
return underlyingType.getTag(); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1837 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1838 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1839 |
@Override |
16556
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
16341
diff
changeset
|
1840 |
public boolean isAnnotated() { |
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
16341
diff
changeset
|
1841 |
return true; |
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
16341
diff
changeset
|
1842 |
} |
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
16341
diff
changeset
|
1843 |
|
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
16341
diff
changeset
|
1844 |
@Override |
21007 | 1845 |
public List<Attribute.TypeCompound> getAnnotationMirrors() { |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
1846 |
return typeAnnotations; |
15385 | 1847 |
} |
1848 |
||
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
1849 |
|
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
1850 |
@Override |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
1851 |
public TypeKind getKind() { |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
1852 |
return underlyingType.getKind(); |
15385 | 1853 |
} |
1854 |
||
1855 |
@Override |
|
1856 |
public Type unannotatedType() { |
|
1857 |
return underlyingType; |
|
1858 |
} |
|
1859 |
||
1860 |
@Override |
|
1861 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
1862 |
return v.visitAnnotatedType(this, s); |
|
1863 |
} |
|
1864 |
||
1865 |
@Override |
|
1866 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
|
16556
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
16341
diff
changeset
|
1867 |
return underlyingType.accept(v, p); |
15385 | 1868 |
} |
1869 |
||
1870 |
@Override |
|
1871 |
public Type map(Mapping f) { |
|
1872 |
underlyingType.map(f); |
|
1873 |
return this; |
|
1874 |
} |
|
1875 |
||
1876 |
@Override |
|
1877 |
public Type constType(Object constValue) { return underlyingType.constType(constValue); } |
|
1878 |
@Override |
|
1879 |
public Type getEnclosingType() { return underlyingType.getEnclosingType(); } |
|
1880 |
||
1881 |
@Override |
|
1882 |
public Type getReturnType() { return underlyingType.getReturnType(); } |
|
1883 |
@Override |
|
1884 |
public List<Type> getTypeArguments() { return underlyingType.getTypeArguments(); } |
|
1885 |
@Override |
|
1886 |
public List<Type> getParameterTypes() { return underlyingType.getParameterTypes(); } |
|
1887 |
@Override |
|
1888 |
public Type getReceiverType() { return underlyingType.getReceiverType(); } |
|
1889 |
@Override |
|
1890 |
public List<Type> getThrownTypes() { return underlyingType.getThrownTypes(); } |
|
1891 |
@Override |
|
1892 |
public Type getUpperBound() { return underlyingType.getUpperBound(); } |
|
1893 |
@Override |
|
1894 |
public Type getLowerBound() { return underlyingType.getLowerBound(); } |
|
1895 |
||
1896 |
@Override |
|
1897 |
public boolean isErroneous() { return underlyingType.isErroneous(); } |
|
1898 |
@Override |
|
1899 |
public boolean isCompound() { return underlyingType.isCompound(); } |
|
1900 |
@Override |
|
1901 |
public boolean isInterface() { return underlyingType.isInterface(); } |
|
1902 |
@Override |
|
1903 |
public List<Type> allparams() { return underlyingType.allparams(); } |
|
1904 |
@Override |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1905 |
public boolean isPrimitive() { return underlyingType.isPrimitive(); } |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1906 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1907 |
public boolean isPrimitiveOrVoid() { return underlyingType.isPrimitiveOrVoid(); } |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1908 |
@Override |
15385 | 1909 |
public boolean isNumeric() { return underlyingType.isNumeric(); } |
1910 |
@Override |
|
1911 |
public boolean isReference() { return underlyingType.isReference(); } |
|
1912 |
@Override |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1913 |
public boolean isNullOrReference() { return underlyingType.isNullOrReference(); } |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1914 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1915 |
public boolean isPartial() { return underlyingType.isPartial(); } |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1916 |
@Override |
15385 | 1917 |
public boolean isParameterized() { return underlyingType.isParameterized(); } |
1918 |
@Override |
|
1919 |
public boolean isRaw() { return underlyingType.isRaw(); } |
|
1920 |
@Override |
|
1921 |
public boolean isFinal() { return underlyingType.isFinal(); } |
|
1922 |
@Override |
|
1923 |
public boolean isSuperBound() { return underlyingType.isSuperBound(); } |
|
1924 |
@Override |
|
1925 |
public boolean isExtendsBound() { return underlyingType.isExtendsBound(); } |
|
1926 |
@Override |
|
1927 |
public boolean isUnbound() { return underlyingType.isUnbound(); } |
|
1928 |
||
1929 |
@Override |
|
1930 |
public String toString() { |
|
17578 | 1931 |
// This method is only used for internal debugging output. |
1932 |
// See |
|
1933 |
// com.sun.tools.javac.code.Printer.visitAnnotatedType(AnnotatedType, Locale) |
|
1934 |
// for the user-visible logic. |
|
15385 | 1935 |
if (typeAnnotations != null && |
1936 |
!typeAnnotations.isEmpty()) { |
|
1937 |
return "(" + typeAnnotations.toString() + " :: " + underlyingType.toString() + ")"; |
|
1938 |
} else { |
|
1939 |
return "({} :: " + underlyingType.toString() +")"; |
|
1940 |
} |
|
1941 |
} |
|
1942 |
||
1943 |
@Override |
|
1944 |
public boolean contains(Type t) { return underlyingType.contains(t); } |
|
1945 |
||
1946 |
@Override |
|
17578 | 1947 |
public Type withTypeVar(Type t) { |
1948 |
// Don't create a new AnnotatedType, as 'this' will |
|
1949 |
// get its annotations set later. |
|
1950 |
underlyingType = underlyingType.withTypeVar(t); |
|
1951 |
return this; |
|
1952 |
} |
|
15385 | 1953 |
|
1954 |
// TODO: attach annotations? |
|
1955 |
@Override |
|
1956 |
public TypeSymbol asElement() { return underlyingType.asElement(); } |
|
1957 |
||
1958 |
// TODO: attach annotations? |
|
1959 |
@Override |
|
1960 |
public MethodType asMethodType() { return underlyingType.asMethodType(); } |
|
1961 |
||
1962 |
@Override |
|
1963 |
public void complete() { underlyingType.complete(); } |
|
1964 |
||
1965 |
@Override |
|
1966 |
public TypeMirror getComponentType() { return ((ArrayType)underlyingType).getComponentType(); } |
|
1967 |
||
1968 |
// The result is an ArrayType, but only in the model sense, not the Type sense. |
|
21041 | 1969 |
public Type makeVarargs() { |
1970 |
return ((ArrayType) underlyingType).makeVarargs().annotatedType(typeAnnotations); |
|
15385 | 1971 |
} |
1972 |
||
1973 |
@Override |
|
1974 |
public TypeMirror getExtendsBound() { return ((WildcardType)underlyingType).getExtendsBound(); } |
|
1975 |
@Override |
|
1976 |
public TypeMirror getSuperBound() { return ((WildcardType)underlyingType).getSuperBound(); } |
|
1977 |
} |
|
1978 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1979 |
public static class UnknownType extends Type { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1980 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1981 |
public UnknownType() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1982 |
super(null); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1983 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1984 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1985 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1986 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1987 |
return UNKNOWN; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1988 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1989 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1990 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1991 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1992 |
return v.visitUnknown(this, p); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1993 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1994 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1995 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1996 |
public boolean isPartial() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1997 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1998 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1999 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2000 |
|
10 | 2001 |
/** |
2002 |
* A visitor for types. A visitor is used to implement operations |
|
2003 |
* (or relations) on types. Most common operations on types are |
|
2004 |
* binary relations and this interface is designed for binary |
|
15385 | 2005 |
* relations, that is, operations of the form |
10 | 2006 |
* Type × S → R. |
2007 |
* <!-- In plain text: Type x S -> R --> |
|
2008 |
* |
|
2009 |
* @param <R> the return type of the operation implemented by this |
|
2010 |
* visitor; use Void if no return type is needed. |
|
2011 |
* @param <S> the type of the second argument (the first being the |
|
2012 |
* type itself) of the operation implemented by this visitor; use |
|
2013 |
* Void if a second argument is not needed. |
|
2014 |
*/ |
|
2015 |
public interface Visitor<R,S> { |
|
2016 |
R visitClassType(ClassType t, S s); |
|
2017 |
R visitWildcardType(WildcardType t, S s); |
|
2018 |
R visitArrayType(ArrayType t, S s); |
|
2019 |
R visitMethodType(MethodType t, S s); |
|
2020 |
R visitPackageType(PackageType t, S s); |
|
2021 |
R visitTypeVar(TypeVar t, S s); |
|
2022 |
R visitCapturedType(CapturedType t, S s); |
|
2023 |
R visitForAll(ForAll t, S s); |
|
2024 |
R visitUndetVar(UndetVar t, S s); |
|
2025 |
R visitErrorType(ErrorType t, S s); |
|
15385 | 2026 |
R visitAnnotatedType(AnnotatedType t, S s); |
10 | 2027 |
R visitType(Type t, S s); |
2028 |
} |
|
2029 |
} |