author | vromero |
Tue, 17 Oct 2017 07:11:05 -0700 | |
changeset 47356 | c30033467073 |
parent 47268 | 48ec75306997 |
child 48661 | 19173eb3358b |
permissions | -rw-r--r-- |
10 | 1 |
/* |
47356 | 2 |
* Copyright (c) 1999, 2017, 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; |
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
29 |
import java.util.ArrayDeque; |
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
30 |
import java.util.Collections; |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
31 |
import java.util.EnumMap; |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
32 |
import java.util.Map; |
14052 | 33 |
|
10 | 34 |
import javax.lang.model.type.*; |
35 |
||
14258 | 36 |
import com.sun.tools.javac.code.Symbol.*; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
37 |
import com.sun.tools.javac.code.TypeMetadata.Entry; |
44186
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
42828
diff
changeset
|
38 |
import com.sun.tools.javac.code.Types.TypeMapping; |
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
39 |
import com.sun.tools.javac.comp.Infer.IncorporationAction; |
14258 | 40 |
import com.sun.tools.javac.util.*; |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
41 |
import com.sun.tools.javac.util.DefinedBy.Api; |
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
42 |
|
14052 | 43 |
import static com.sun.tools.javac.code.BoundKind.*; |
10 | 44 |
import static com.sun.tools.javac.code.Flags.*; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
45 |
import static com.sun.tools.javac.code.Kinds.Kind.*; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
46 |
import static com.sun.tools.javac.code.TypeTag.*; |
10 | 47 |
|
48 |
/** This class represents Java types. The class itself defines the behavior of |
|
49 |
* the following types: |
|
50 |
* <pre> |
|
51 |
* base types (tags: BYTE, CHAR, SHORT, INT, LONG, FLOAT, DOUBLE, BOOLEAN), |
|
52 |
* type `void' (tag: VOID), |
|
53 |
* the bottom type (tag: BOT), |
|
54 |
* the missing type (tag: NONE). |
|
55 |
* </pre> |
|
56 |
* <p>The behavior of the following types is defined in subclasses, which are |
|
57 |
* all static inner classes of this class: |
|
58 |
* <pre> |
|
59 |
* class types (tag: CLASS, class: ClassType), |
|
60 |
* array types (tag: ARRAY, class: ArrayType), |
|
61 |
* method types (tag: METHOD, class: MethodType), |
|
62 |
* package types (tag: PACKAGE, class: PackageType), |
|
63 |
* type variables (tag: TYPEVAR, class: TypeVar), |
|
64 |
* type arguments (tag: WILDCARD, class: WildcardType), |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
65 |
* generic method types (tag: FORALL, class: ForAll), |
10 | 66 |
* the error type (tag: ERROR, class: ErrorType). |
67 |
* </pre> |
|
68 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
69 |
* <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
|
70 |
* If you write code that depends on this, you do so at your own risk. |
10 | 71 |
* This code and its internal interfaces are subject to change or |
72 |
* deletion without notice.</b> |
|
73 |
* |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
74 |
* @see TypeTag |
10 | 75 |
*/ |
21007 | 76 |
public abstract class Type extends AnnoConstruct implements TypeMirror { |
10 | 77 |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
78 |
/** |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
79 |
* Type metadata, Should be {@code null} for the default value. |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
80 |
* |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
81 |
* Note: it is an invariant that for any {@code TypeMetadata} |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
82 |
* class, a given {@code Type} may have at most one metadata array |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
83 |
* entry of that class. |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
84 |
*/ |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
85 |
protected final TypeMetadata metadata; |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
86 |
|
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
87 |
public TypeMetadata getMetadata() { |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
88 |
return metadata; |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
89 |
} |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
90 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
91 |
public Entry getMetadataOfKind(final Entry.Kind kind) { |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
92 |
return metadata != null ? metadata.get(kind) : null; |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
93 |
} |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
94 |
|
10 | 95 |
/** Constant type: no type at all. */ |
24794
22946bb4c27d
8041713: Type inference of non-existent method references crashes the compiler
vromero
parents:
24396
diff
changeset
|
96 |
public static final JCNoType noType = new JCNoType() { |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
97 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
24794
22946bb4c27d
8041713: Type inference of non-existent method references crashes the compiler
vromero
parents:
24396
diff
changeset
|
98 |
public String toString() { |
22946bb4c27d
8041713: Type inference of non-existent method references crashes the compiler
vromero
parents:
24396
diff
changeset
|
99 |
return "none"; |
22946bb4c27d
8041713: Type inference of non-existent method references crashes the compiler
vromero
parents:
24396
diff
changeset
|
100 |
} |
22946bb4c27d
8041713: Type inference of non-existent method references crashes the compiler
vromero
parents:
24396
diff
changeset
|
101 |
}; |
10 | 102 |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14052
diff
changeset
|
103 |
/** Constant type: special type to be used during recovery of deferred expressions. */ |
24794
22946bb4c27d
8041713: Type inference of non-existent method references crashes the compiler
vromero
parents:
24396
diff
changeset
|
104 |
public static final JCNoType recoveryType = new JCNoType(){ |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
105 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
24794
22946bb4c27d
8041713: Type inference of non-existent method references crashes the compiler
vromero
parents:
24396
diff
changeset
|
106 |
public String toString() { |
22946bb4c27d
8041713: Type inference of non-existent method references crashes the compiler
vromero
parents:
24396
diff
changeset
|
107 |
return "recovery"; |
22946bb4c27d
8041713: Type inference of non-existent method references crashes the compiler
vromero
parents:
24396
diff
changeset
|
108 |
} |
22946bb4c27d
8041713: Type inference of non-existent method references crashes the compiler
vromero
parents:
24396
diff
changeset
|
109 |
}; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14052
diff
changeset
|
110 |
|
18902 | 111 |
/** Constant type: special type to be used for marking stuck trees. */ |
24794
22946bb4c27d
8041713: Type inference of non-existent method references crashes the compiler
vromero
parents:
24396
diff
changeset
|
112 |
public static final JCNoType stuckType = new JCNoType() { |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
113 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
24794
22946bb4c27d
8041713: Type inference of non-existent method references crashes the compiler
vromero
parents:
24396
diff
changeset
|
114 |
public String toString() { |
22946bb4c27d
8041713: Type inference of non-existent method references crashes the compiler
vromero
parents:
24396
diff
changeset
|
115 |
return "stuck"; |
22946bb4c27d
8041713: Type inference of non-existent method references crashes the compiler
vromero
parents:
24396
diff
changeset
|
116 |
} |
22946bb4c27d
8041713: Type inference of non-existent method references crashes the compiler
vromero
parents:
24396
diff
changeset
|
117 |
}; |
18902 | 118 |
|
10 | 119 |
/** If this switch is turned on, the names of type variables |
120 |
* and anonymous classes are printed with hashcodes appended. |
|
121 |
*/ |
|
122 |
public static boolean moreInfo = false; |
|
123 |
||
15385 | 124 |
/** The defining class / interface / package / type variable. |
10 | 125 |
*/ |
126 |
public TypeSymbol tsym; |
|
127 |
||
128 |
/** |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
129 |
* 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
|
130 |
* @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
|
131 |
*/ |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
132 |
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
|
133 |
return tag == getTag(); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
134 |
} |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
135 |
|
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
136 |
/** |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
137 |
* Returns the current type tag. |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
138 |
* @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
|
139 |
*/ |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
140 |
public abstract TypeTag getTag(); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
141 |
|
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
142 |
public boolean isNumeric() { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
143 |
return false; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
144 |
} |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
145 |
|
33018
9790ed482dd0
8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents:
30066
diff
changeset
|
146 |
public boolean isIntegral() { |
9790ed482dd0
8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents:
30066
diff
changeset
|
147 |
return false; |
9790ed482dd0
8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents:
30066
diff
changeset
|
148 |
} |
9790ed482dd0
8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents:
30066
diff
changeset
|
149 |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
150 |
public boolean isPrimitive() { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
151 |
return false; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
152 |
} |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
153 |
|
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
154 |
public boolean isPrimitiveOrVoid() { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
155 |
return false; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
156 |
} |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
157 |
|
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
158 |
public boolean isReference() { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
159 |
return false; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
160 |
} |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
161 |
|
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
162 |
public boolean isNullOrReference() { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
163 |
return false; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
164 |
} |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
165 |
|
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
166 |
public boolean isPartial() { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
167 |
return false; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
168 |
} |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
169 |
|
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
170 |
/** |
10 | 171 |
* The constant value of this type, null if this type does not |
172 |
* have a constant value attribute. Only primitive types and |
|
173 |
* strings (ClassType) can have a constant value attribute. |
|
174 |
* @return the constant value attribute of this type |
|
175 |
*/ |
|
176 |
public Object constValue() { |
|
177 |
return null; |
|
178 |
} |
|
179 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
180 |
/** 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
|
181 |
*/ |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
182 |
public boolean isFalse() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
183 |
return false; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
184 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
185 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
186 |
/** 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
|
187 |
*/ |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
188 |
public boolean isTrue() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
189 |
return false; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
190 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
191 |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
192 |
/** |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
193 |
* Get the representation of this type used for modelling purposes. |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
194 |
* By default, this is itself. For ErrorType, a different value |
15385 | 195 |
* may be provided. |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
196 |
*/ |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
197 |
public Type getModelType() { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
198 |
return this; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
199 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
200 |
|
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
201 |
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
|
202 |
ListBuffer<Type> lb = new ListBuffer<>(); |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
203 |
for (Type t: ts) |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
204 |
lb.append(t.getModelType()); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
205 |
return lb.toList(); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
206 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
207 |
|
21015
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
21007
diff
changeset
|
208 |
/**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
|
209 |
*/ |
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
21007
diff
changeset
|
210 |
public Type getOriginalType() { |
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
21007
diff
changeset
|
211 |
return this; |
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
21007
diff
changeset
|
212 |
} |
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
21007
diff
changeset
|
213 |
|
10 | 214 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { return v.visitType(this, s); } |
215 |
||
24396 | 216 |
/** Define a type given its tag, type symbol, and type annotations |
10 | 217 |
*/ |
24396 | 218 |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
219 |
public Type(TypeSymbol tsym, TypeMetadata metadata) { |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
220 |
Assert.checkNonNull(metadata); |
10 | 221 |
this.tsym = tsym; |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
222 |
this.metadata = metadata; |
10 | 223 |
} |
224 |
||
44186
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
42828
diff
changeset
|
225 |
/** |
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
42828
diff
changeset
|
226 |
* A subclass of {@link Types.TypeMapping} which applies a mapping recursively to the subterms |
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
42828
diff
changeset
|
227 |
* of a given type expression. This mapping returns the original type is no changes occurred |
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
42828
diff
changeset
|
228 |
* when recursively mapping the original type's subterms. |
10 | 229 |
*/ |
44186
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
42828
diff
changeset
|
230 |
public static abstract class StructuralTypeMapping<S> extends Types.TypeMapping<S> { |
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
231 |
|
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
232 |
@Override |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
233 |
public Type visitClassType(ClassType t, S s) { |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
234 |
Type outer = t.getEnclosingType(); |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
235 |
Type outer1 = visit(outer, s); |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
236 |
List<Type> typarams = t.getTypeArguments(); |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
237 |
List<Type> typarams1 = visit(typarams, s); |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
238 |
if (outer1 == outer && typarams1 == typarams) return t; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
239 |
else return new ClassType(outer1, typarams1, t.tsym, t.metadata) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
240 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
241 |
protected boolean needsStripping() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
242 |
return true; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
243 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
244 |
}; |
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
245 |
} |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
246 |
|
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
247 |
@Override |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
248 |
public Type visitWildcardType(WildcardType wt, S s) { |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
249 |
Type t = wt.type; |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
250 |
if (t != null) |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
251 |
t = visit(t, s); |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
252 |
if (t == wt.type) |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
253 |
return wt; |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
254 |
else |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
255 |
return new WildcardType(t, wt.kind, wt.tsym, wt.bound, wt.metadata) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
256 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
257 |
protected boolean needsStripping() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
258 |
return true; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
259 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
260 |
}; |
10 | 261 |
} |
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
262 |
|
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
263 |
@Override |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
264 |
public Type visitArrayType(ArrayType t, S s) { |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
265 |
Type elemtype = t.elemtype; |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
266 |
Type elemtype1 = visit(elemtype, s); |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
267 |
if (elemtype1 == elemtype) return t; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
268 |
else return new ArrayType(elemtype1, t.tsym, t.metadata) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
269 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
270 |
protected boolean needsStripping() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
271 |
return true; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
272 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
273 |
}; |
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
274 |
} |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
275 |
|
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
276 |
@Override |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
277 |
public Type visitMethodType(MethodType t, S s) { |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
278 |
List<Type> argtypes = t.argtypes; |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
279 |
Type restype = t.restype; |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
280 |
List<Type> thrown = t.thrown; |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
281 |
List<Type> argtypes1 = visit(argtypes, s); |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
282 |
Type restype1 = visit(restype, s); |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
283 |
List<Type> thrown1 = visit(thrown, s); |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
284 |
if (argtypes1 == argtypes && |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
285 |
restype1 == restype && |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
286 |
thrown1 == thrown) return t; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
287 |
else return new MethodType(argtypes1, restype1, thrown1, t.tsym) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
288 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
289 |
protected boolean needsStripping() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
290 |
return true; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
291 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
292 |
}; |
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
293 |
} |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
294 |
|
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
295 |
@Override |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
296 |
public Type visitForAll(ForAll t, S s) { |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
297 |
return visit(t.qtype, s); |
10 | 298 |
} |
299 |
} |
|
300 |
||
301 |
/** map a type function over all immediate descendants of this type |
|
302 |
*/ |
|
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
303 |
public <Z> Type map(TypeMapping<Z> mapping, Z arg) { |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
304 |
return mapping.visit(this, arg); |
10 | 305 |
} |
306 |
||
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
307 |
/** map a type function over all immediate descendants of this type (no arg version) |
10 | 308 |
*/ |
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
309 |
public <Z> Type map(TypeMapping<Z> mapping) { |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
310 |
return mapping.visit(this, null); |
10 | 311 |
} |
312 |
||
313 |
/** Define a constant type, of the same kind as this type |
|
314 |
* and with given constant value |
|
315 |
*/ |
|
316 |
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
|
317 |
throw new AssertionError(); |
10 | 318 |
} |
319 |
||
320 |
/** |
|
321 |
* If this is a constant type, return its underlying type. |
|
322 |
* Otherwise, return the type itself. |
|
323 |
*/ |
|
324 |
public Type baseType() { |
|
325 |
return this; |
|
326 |
} |
|
327 |
||
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
328 |
/** |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
329 |
* Returns the original version of this type, before metadata were added. This routine is meant |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
330 |
* for internal use only (i.e. {@link Type#equalsIgnoreMetadata(Type)}, {@link Type#stripMetadata}); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
331 |
* it should not be used outside this class. |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
332 |
*/ |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
333 |
protected Type typeNoMetadata() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
334 |
return metadata == TypeMetadata.EMPTY ? this : baseType(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
335 |
} |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
336 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
337 |
/** |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
338 |
* Create a new copy of this type but with the specified TypeMetadata. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
339 |
*/ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
340 |
public abstract Type cloneWithMetadata(TypeMetadata metadata); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
341 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
342 |
/** |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
343 |
* Does this type require annotation stripping for API clients? |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
344 |
*/ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
345 |
protected boolean needsStripping() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
346 |
return false; |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
347 |
} |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
348 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
349 |
/** |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
350 |
* Strip all metadata associated with this type - this could return a new clone of the type. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
351 |
* This routine is only used to present the correct annotated types back to the users when types |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
352 |
* are accessed through compiler APIs; it should not be used anywhere in the compiler internals |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
353 |
* as doing so might result in performance penalties. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
354 |
*/ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
355 |
public Type stripMetadataIfNeeded() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
356 |
return needsStripping() ? |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
357 |
accept(stripMetadata, null) : |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
358 |
this; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
359 |
} |
35348
95a9b9409b50
8144580: java.lang.AssertionError: Missing type variable in where clause: T
sadayapalam
parents:
33917
diff
changeset
|
360 |
|
95a9b9409b50
8144580: java.lang.AssertionError: Missing type variable in where clause: T
sadayapalam
parents:
33917
diff
changeset
|
361 |
public Type stripMetadata() { |
95a9b9409b50
8144580: java.lang.AssertionError: Missing type variable in where clause: T
sadayapalam
parents:
33917
diff
changeset
|
362 |
return accept(stripMetadata, null); |
95a9b9409b50
8144580: java.lang.AssertionError: Missing type variable in where clause: T
sadayapalam
parents:
33917
diff
changeset
|
363 |
} |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
364 |
//where |
44186
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
42828
diff
changeset
|
365 |
private final static TypeMapping<Void> stripMetadata = new StructuralTypeMapping<Void>() { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
366 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
367 |
public Type visitClassType(ClassType t, Void aVoid) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
368 |
return super.visitClassType((ClassType)t.typeNoMetadata(), aVoid); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
369 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
370 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
371 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
372 |
public Type visitArrayType(ArrayType t, Void aVoid) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
373 |
return super.visitArrayType((ArrayType)t.typeNoMetadata(), aVoid); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
374 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
375 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
376 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
377 |
public Type visitTypeVar(TypeVar t, Void aVoid) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
378 |
return super.visitTypeVar((TypeVar)t.typeNoMetadata(), aVoid); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
379 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
380 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
381 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
382 |
public Type visitWildcardType(WildcardType wt, Void aVoid) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
383 |
return super.visitWildcardType((WildcardType)wt.typeNoMetadata(), aVoid); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
384 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
385 |
}; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
386 |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
387 |
public Type annotatedType(final List<Attribute.TypeCompound> annos) { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
388 |
final Entry annoMetadata = new TypeMetadata.Annotations(annos); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
389 |
return cloneWithMetadata(metadata.combine(annoMetadata)); |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
390 |
} |
21041 | 391 |
|
16556
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
16341
diff
changeset
|
392 |
public boolean isAnnotated() { |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
393 |
final TypeMetadata.Annotations metadata = |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
394 |
(TypeMetadata.Annotations)getMetadataOfKind(Entry.Kind.ANNOTATIONS); |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
395 |
|
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
396 |
return null != metadata && !metadata.getAnnotations().isEmpty(); |
15385 | 397 |
} |
398 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
399 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
21007 | 400 |
public List<Attribute.TypeCompound> getAnnotationMirrors() { |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
401 |
final TypeMetadata.Annotations metadata = |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
402 |
(TypeMetadata.Annotations)getMetadataOfKind(Entry.Kind.ANNOTATIONS); |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
403 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
404 |
return metadata == null ? List.nil() : metadata.getAnnotations(); |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
405 |
} |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
406 |
|
21007 | 407 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
408 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
409 |
public <A extends Annotation> A getAnnotation(Class<A> annotationType) { |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
410 |
return null; |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
411 |
} |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
412 |
|
21007 | 413 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
414 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
415 |
public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType) { |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
416 |
@SuppressWarnings("unchecked") |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
417 |
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
|
418 |
return tmp; |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
419 |
} |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
420 |
|
10 | 421 |
/** Return the base types of a list of types. |
422 |
*/ |
|
423 |
public static List<Type> baseTypes(List<Type> ts) { |
|
424 |
if (ts.nonEmpty()) { |
|
425 |
Type t = ts.head.baseType(); |
|
426 |
List<Type> baseTypes = baseTypes(ts.tail); |
|
427 |
if (t != ts.head || baseTypes != ts.tail) |
|
428 |
return baseTypes.prepend(t); |
|
429 |
} |
|
430 |
return ts; |
|
431 |
} |
|
432 |
||
24396 | 433 |
protected void appendAnnotationsString(StringBuilder sb, |
434 |
boolean prefix) { |
|
435 |
if (isAnnotated()) { |
|
436 |
if (prefix) { |
|
437 |
sb.append(" "); |
|
438 |
} |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
439 |
sb.append(getAnnotationMirrors()); |
24396 | 440 |
sb.append(" "); |
441 |
} |
|
442 |
} |
|
443 |
||
444 |
protected void appendAnnotationsString(StringBuilder sb) { |
|
445 |
appendAnnotationsString(sb, false); |
|
446 |
} |
|
447 |
||
10 | 448 |
/** The Java source which this type represents. |
449 |
*/ |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
450 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 451 |
public String toString() { |
24396 | 452 |
StringBuilder sb = new StringBuilder(); |
453 |
appendAnnotationsString(sb); |
|
454 |
if (tsym == null || tsym.name == null) { |
|
455 |
sb.append("<none>"); |
|
456 |
} else { |
|
457 |
sb.append(tsym.name); |
|
458 |
} |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
459 |
if (moreInfo && hasTag(TYPEVAR)) { |
24396 | 460 |
sb.append(hashCode()); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
461 |
} |
24396 | 462 |
return sb.toString(); |
10 | 463 |
} |
464 |
||
465 |
/** |
|
466 |
* The Java source which this type list represents. A List is |
|
467 |
* represented as a comma-spearated listing of the elements in |
|
468 |
* that list. |
|
469 |
*/ |
|
470 |
public static String toString(List<Type> ts) { |
|
471 |
if (ts.isEmpty()) { |
|
472 |
return ""; |
|
473 |
} else { |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
474 |
StringBuilder buf = new StringBuilder(); |
10 | 475 |
buf.append(ts.head.toString()); |
476 |
for (List<Type> l = ts.tail; l.nonEmpty(); l = l.tail) |
|
477 |
buf.append(",").append(l.head.toString()); |
|
478 |
return buf.toString(); |
|
479 |
} |
|
480 |
} |
|
481 |
||
482 |
/** |
|
483 |
* The constant value of this type, converted to String |
|
484 |
*/ |
|
485 |
public String stringValue() { |
|
8032 | 486 |
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
|
487 |
return cv.toString(); |
10 | 488 |
} |
489 |
||
490 |
/** |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
491 |
* Override this method with care. For most Type instances this should behave as ==. |
10 | 492 |
*/ |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
493 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
10 | 494 |
public boolean equals(Object t) { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
495 |
return this == t; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
496 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
497 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
498 |
public boolean equalsIgnoreMetadata(Type t) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
499 |
return typeNoMetadata().equals(t.typeNoMetadata()); |
10 | 500 |
} |
501 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
502 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
10 | 503 |
public int hashCode() { |
504 |
return super.hashCode(); |
|
505 |
} |
|
506 |
||
507 |
public String argtypes(boolean varargs) { |
|
508 |
List<Type> args = getParameterTypes(); |
|
509 |
if (!varargs) return args.toString(); |
|
7637 | 510 |
StringBuilder buf = new StringBuilder(); |
10 | 511 |
while (args.tail.nonEmpty()) { |
512 |
buf.append(args.head); |
|
513 |
args = args.tail; |
|
514 |
buf.append(','); |
|
515 |
} |
|
24396 | 516 |
if (args.head.hasTag(ARRAY)) { |
517 |
buf.append(((ArrayType)args.head).elemtype); |
|
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
518 |
if (args.head.getAnnotationMirrors().nonEmpty()) { |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16556
diff
changeset
|
519 |
buf.append(args.head.getAnnotationMirrors()); |
15385 | 520 |
} |
10 | 521 |
buf.append("..."); |
522 |
} else { |
|
523 |
buf.append(args.head); |
|
524 |
} |
|
525 |
return buf.toString(); |
|
526 |
} |
|
527 |
||
528 |
/** Access methods. |
|
529 |
*/ |
|
530 |
public List<Type> getTypeArguments() { return List.nil(); } |
|
15385 | 531 |
public Type getEnclosingType() { return null; } |
10 | 532 |
public List<Type> getParameterTypes() { return List.nil(); } |
533 |
public Type getReturnType() { return null; } |
|
15385 | 534 |
public Type getReceiverType() { return null; } |
10 | 535 |
public List<Type> getThrownTypes() { return List.nil(); } |
536 |
public Type getUpperBound() { return null; } |
|
537 |
public Type getLowerBound() { return null; } |
|
538 |
||
539 |
/** Navigation methods, these will work for classes, type variables, |
|
540 |
* foralls, but will return null for arrays and methods. |
|
541 |
*/ |
|
542 |
||
543 |
/** Return all parameters of this type and all its outer types in order |
|
544 |
* outer (first) to inner (last). |
|
545 |
*/ |
|
546 |
public List<Type> allparams() { return List.nil(); } |
|
547 |
||
548 |
/** Does this type contain "error" elements? |
|
549 |
*/ |
|
550 |
public boolean isErroneous() { |
|
551 |
return false; |
|
552 |
} |
|
553 |
||
554 |
public static boolean isErroneous(List<Type> ts) { |
|
555 |
for (List<Type> l = ts; l.nonEmpty(); l = l.tail) |
|
556 |
if (l.head.isErroneous()) return true; |
|
557 |
return false; |
|
558 |
} |
|
559 |
||
560 |
/** Is this type parameterized? |
|
561 |
* A class type is parameterized if it has some parameters. |
|
562 |
* An array type is parameterized if its element type is parameterized. |
|
563 |
* All other types are not parameterized. |
|
564 |
*/ |
|
565 |
public boolean isParameterized() { |
|
566 |
return false; |
|
567 |
} |
|
568 |
||
569 |
/** Is this type a raw type? |
|
570 |
* A class type is a raw type if it misses some of its parameters. |
|
571 |
* An array type is a raw type if its element type is raw. |
|
572 |
* All other types are not raw. |
|
573 |
* Type validation will ensure that the only raw types |
|
574 |
* in a program are types that miss all their type variables. |
|
575 |
*/ |
|
576 |
public boolean isRaw() { |
|
577 |
return false; |
|
578 |
} |
|
579 |
||
33556
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
33018
diff
changeset
|
580 |
/** |
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
33018
diff
changeset
|
581 |
* A compound type is a special class type whose supertypes are used to store a list |
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
33018
diff
changeset
|
582 |
* of component types. There are two kinds of compound types: (i) intersection types |
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
33018
diff
changeset
|
583 |
* {@see IntersectionClassType} and (ii) union types {@see UnionClassType}. |
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
33018
diff
changeset
|
584 |
*/ |
10 | 585 |
public boolean isCompound() { |
33556
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
33018
diff
changeset
|
586 |
return false; |
10 | 587 |
} |
588 |
||
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
27224
diff
changeset
|
589 |
public boolean isIntersection() { |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
27224
diff
changeset
|
590 |
return false; |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
27224
diff
changeset
|
591 |
} |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
27224
diff
changeset
|
592 |
|
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
27224
diff
changeset
|
593 |
public boolean isUnion() { |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
27224
diff
changeset
|
594 |
return false; |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
27224
diff
changeset
|
595 |
} |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
27224
diff
changeset
|
596 |
|
10 | 597 |
public boolean isInterface() { |
598 |
return (tsym.flags() & INTERFACE) != 0; |
|
599 |
} |
|
600 |
||
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6348
diff
changeset
|
601 |
public boolean isFinal() { |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6348
diff
changeset
|
602 |
return (tsym.flags() & FINAL) != 0; |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6348
diff
changeset
|
603 |
} |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6348
diff
changeset
|
604 |
|
10 | 605 |
/** |
606 |
* Does this type contain occurrences of type t? |
|
607 |
*/ |
|
608 |
public boolean contains(Type t) { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
609 |
return t.equalsIgnoreMetadata(this); |
10 | 610 |
} |
611 |
||
612 |
public static boolean contains(List<Type> ts, Type t) { |
|
613 |
for (List<Type> l = ts; |
|
614 |
l.tail != null /*inlined: l.nonEmpty()*/; |
|
615 |
l = l.tail) |
|
616 |
if (l.head.contains(t)) return true; |
|
617 |
return false; |
|
618 |
} |
|
619 |
||
6348
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
620 |
/** Does this type contain an occurrence of some type in 'ts'? |
10 | 621 |
*/ |
6348
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
622 |
public boolean containsAny(List<Type> ts) { |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
623 |
for (Type t : ts) |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
624 |
if (this.contains(t)) return true; |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
625 |
return false; |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
626 |
} |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
627 |
|
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
628 |
public static boolean containsAny(List<Type> ts1, List<Type> ts2) { |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
629 |
for (Type t : ts1) |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
630 |
if (t.containsAny(ts2)) return true; |
10 | 631 |
return false; |
632 |
} |
|
633 |
||
8044
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
634 |
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
|
635 |
ListBuffer<Type> buf = new ListBuffer<>(); |
8044
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
636 |
for (Type t : ts) { |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
637 |
if (tf.accepts(t)) { |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
638 |
buf.append(t); |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
639 |
} |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
640 |
} |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
641 |
return buf.toList(); |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
642 |
} |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8032
diff
changeset
|
643 |
|
10 | 644 |
public boolean isSuperBound() { return false; } |
645 |
public boolean isExtendsBound() { return false; } |
|
646 |
public boolean isUnbound() { return false; } |
|
647 |
public Type withTypeVar(Type t) { return this; } |
|
648 |
||
649 |
/** The underlying method type of this type. |
|
650 |
*/ |
|
651 |
public MethodType asMethodType() { throw new AssertionError(); } |
|
652 |
||
653 |
/** Complete loading all classes in this type. |
|
654 |
*/ |
|
655 |
public void complete() {} |
|
656 |
||
657 |
public TypeSymbol asElement() { |
|
658 |
return tsym; |
|
659 |
} |
|
660 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
661 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
10 | 662 |
public TypeKind getKind() { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
663 |
return TypeKind.OTHER; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
664 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
665 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
666 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
667 |
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
|
668 |
throw new AssertionError(); |
10 | 669 |
} |
670 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
671 |
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
|
672 |
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
|
673 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
674 |
TypeTag tag; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
675 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
676 |
public JCPrimitiveType(TypeTag tag, TypeSymbol tsym) { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
677 |
this(tag, tsym, TypeMetadata.EMPTY); |
24396 | 678 |
} |
679 |
||
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
680 |
private JCPrimitiveType(TypeTag tag, TypeSymbol tsym, TypeMetadata metadata) { |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
681 |
super(tsym, metadata); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
682 |
this.tag = tag; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
683 |
Assert.check(tag.isPrimitive); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
684 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
685 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
686 |
@Override |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
687 |
public JCPrimitiveType cloneWithMetadata(TypeMetadata md) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
688 |
return new JCPrimitiveType(tag, tsym, md) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
689 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
690 |
public Type baseType() { return JCPrimitiveType.this.baseType(); } |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
691 |
}; |
24396 | 692 |
} |
693 |
||
694 |
@Override |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
695 |
public boolean isNumeric() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
696 |
return tag != BOOLEAN; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
697 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
698 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
699 |
@Override |
33018
9790ed482dd0
8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents:
30066
diff
changeset
|
700 |
public boolean isIntegral() { |
9790ed482dd0
8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents:
30066
diff
changeset
|
701 |
switch (tag) { |
9790ed482dd0
8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents:
30066
diff
changeset
|
702 |
case CHAR: |
9790ed482dd0
8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents:
30066
diff
changeset
|
703 |
case BYTE: |
9790ed482dd0
8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents:
30066
diff
changeset
|
704 |
case SHORT: |
9790ed482dd0
8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents:
30066
diff
changeset
|
705 |
case INT: |
9790ed482dd0
8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents:
30066
diff
changeset
|
706 |
case LONG: |
9790ed482dd0
8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents:
30066
diff
changeset
|
707 |
return true; |
9790ed482dd0
8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents:
30066
diff
changeset
|
708 |
default: |
9790ed482dd0
8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents:
30066
diff
changeset
|
709 |
return false; |
9790ed482dd0
8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents:
30066
diff
changeset
|
710 |
} |
9790ed482dd0
8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents:
30066
diff
changeset
|
711 |
} |
9790ed482dd0
8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents:
30066
diff
changeset
|
712 |
|
9790ed482dd0
8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents:
30066
diff
changeset
|
713 |
@Override |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
714 |
public boolean isPrimitive() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
715 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
716 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
717 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
718 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
719 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
720 |
return tag; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
721 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
722 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
723 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
724 |
public boolean isPrimitiveOrVoid() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
725 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
726 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
727 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
728 |
/** 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
|
729 |
* and with given constant value |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
730 |
*/ |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
731 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
732 |
public Type constType(Object constValue) { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
733 |
final Object value = constValue; |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
734 |
return new JCPrimitiveType(tag, tsym, metadata) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
735 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
736 |
public Object constValue() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
737 |
return value; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
738 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
739 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
740 |
public Type baseType() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
741 |
return tsym.type; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
742 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
743 |
}; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
744 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
745 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
746 |
/** |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
747 |
* 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
|
748 |
*/ |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
749 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
750 |
public String stringValue() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
751 |
Object cv = Assert.checkNonNull(constValue()); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
752 |
if (tag == BOOLEAN) { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
753 |
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
|
754 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
755 |
else if (tag == CHAR) { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
756 |
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
|
757 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
758 |
else { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
759 |
return cv.toString(); |
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 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
762 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
763 |
/** 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
|
764 |
*/ |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
765 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
766 |
public boolean isFalse() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
767 |
return |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
768 |
tag == BOOLEAN && |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
769 |
constValue() != null && |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
770 |
((Integer)constValue()).intValue() == 0; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
771 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
772 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
773 |
/** 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
|
774 |
*/ |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
775 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
776 |
public boolean isTrue() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
777 |
return |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
778 |
tag == BOOLEAN && |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
779 |
constValue() != null && |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
780 |
((Integer)constValue()).intValue() != 0; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
781 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
782 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
783 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
784 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
10 | 785 |
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
|
786 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
787 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
788 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
789 |
public TypeKind getKind() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
790 |
switch (tag) { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
791 |
case BYTE: return TypeKind.BYTE; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
792 |
case CHAR: return TypeKind.CHAR; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
793 |
case SHORT: return TypeKind.SHORT; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
794 |
case INT: return TypeKind.INT; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
795 |
case LONG: return TypeKind.LONG; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
796 |
case FLOAT: return TypeKind.FLOAT; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
797 |
case DOUBLE: return TypeKind.DOUBLE; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
798 |
case BOOLEAN: return TypeKind.BOOLEAN; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
799 |
} |
10 | 800 |
throw new AssertionError(); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
801 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
802 |
|
10 | 803 |
} |
804 |
||
805 |
public static class WildcardType extends Type |
|
806 |
implements javax.lang.model.type.WildcardType { |
|
807 |
||
808 |
public Type type; |
|
809 |
public BoundKind kind; |
|
810 |
public TypeVar bound; |
|
811 |
||
812 |
@Override |
|
813 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
814 |
return v.visitWildcardType(this, s); |
|
815 |
} |
|
816 |
||
817 |
public WildcardType(Type type, BoundKind kind, TypeSymbol tsym) { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
818 |
this(type, kind, tsym, null, TypeMetadata.EMPTY); |
24396 | 819 |
} |
820 |
||
821 |
public WildcardType(Type type, BoundKind kind, TypeSymbol tsym, |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
822 |
TypeMetadata metadata) { |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
823 |
this(type, kind, tsym, null, metadata); |
24396 | 824 |
} |
825 |
||
826 |
public WildcardType(Type type, BoundKind kind, TypeSymbol tsym, |
|
827 |
TypeVar bound) { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
828 |
this(type, kind, tsym, bound, TypeMetadata.EMPTY); |
24396 | 829 |
} |
830 |
||
831 |
public WildcardType(Type type, BoundKind kind, TypeSymbol tsym, |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
832 |
TypeVar bound, TypeMetadata metadata) { |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
833 |
super(tsym, metadata); |
8032 | 834 |
this.type = Assert.checkNonNull(type); |
10 | 835 |
this.kind = kind; |
24396 | 836 |
this.bound = bound; |
10 | 837 |
} |
838 |
||
24396 | 839 |
@Override |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
840 |
public WildcardType cloneWithMetadata(TypeMetadata md) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
841 |
return new WildcardType(type, kind, tsym, bound, md) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
842 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
843 |
public Type baseType() { return WildcardType.this.baseType(); } |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
844 |
}; |
10 | 845 |
} |
846 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
847 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
848 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
849 |
return WILDCARD; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
850 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
851 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
852 |
@Override |
6348
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
853 |
public boolean contains(Type t) { |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
854 |
return kind != UNBOUND && type.contains(t); |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
855 |
} |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
856 |
|
10 | 857 |
public boolean isSuperBound() { |
858 |
return kind == SUPER || |
|
859 |
kind == UNBOUND; |
|
860 |
} |
|
861 |
public boolean isExtendsBound() { |
|
862 |
return kind == EXTENDS || |
|
863 |
kind == UNBOUND; |
|
864 |
} |
|
865 |
public boolean isUnbound() { |
|
866 |
return kind == UNBOUND; |
|
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 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
879 |
@Override |
10 | 880 |
public Type withTypeVar(Type t) { |
881 |
//-System.err.println(this+".withTypeVar("+t+");");//DEBUG |
|
882 |
if (bound == t) |
|
883 |
return this; |
|
884 |
bound = (TypeVar)t; |
|
885 |
return this; |
|
886 |
} |
|
887 |
||
888 |
boolean isPrintingBound = false; |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
889 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 890 |
public String toString() { |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
891 |
StringBuilder s = new StringBuilder(); |
24396 | 892 |
appendAnnotationsString(s); |
10 | 893 |
s.append(kind.toString()); |
894 |
if (kind != UNBOUND) |
|
895 |
s.append(type); |
|
896 |
if (moreInfo && bound != null && !isPrintingBound) |
|
897 |
try { |
|
898 |
isPrintingBound = true; |
|
899 |
s.append("{:").append(bound.bound).append(":}"); |
|
900 |
} finally { |
|
901 |
isPrintingBound = false; |
|
902 |
} |
|
903 |
return s.toString(); |
|
904 |
} |
|
905 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
906 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 907 |
public Type getExtendsBound() { |
908 |
if (kind == EXTENDS) |
|
909 |
return type; |
|
910 |
else |
|
911 |
return null; |
|
912 |
} |
|
913 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
914 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 915 |
public Type getSuperBound() { |
916 |
if (kind == SUPER) |
|
917 |
return type; |
|
918 |
else |
|
919 |
return null; |
|
920 |
} |
|
921 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
922 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 923 |
public TypeKind getKind() { |
924 |
return TypeKind.WILDCARD; |
|
925 |
} |
|
926 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
927 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 928 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
929 |
return v.visitWildcard(this, p); |
|
930 |
} |
|
931 |
} |
|
932 |
||
933 |
public static class ClassType extends Type implements DeclaredType { |
|
934 |
||
935 |
/** The enclosing type of this type. If this is the type of an inner |
|
936 |
* class, outer_field refers to the type of its enclosing |
|
15385 | 937 |
* instance class, in all other cases it refers to noType. |
10 | 938 |
*/ |
939 |
private Type outer_field; |
|
940 |
||
941 |
/** The type parameters of this type (to be set once class is loaded). |
|
942 |
*/ |
|
943 |
public List<Type> typarams_field; |
|
944 |
||
945 |
/** A cache variable for the type parameters of this type, |
|
946 |
* appended to all parameters of its enclosing class. |
|
947 |
* @see #allparams |
|
948 |
*/ |
|
949 |
public List<Type> allparams_field; |
|
950 |
||
951 |
/** The supertype of this class (to be set once class is loaded). |
|
952 |
*/ |
|
953 |
public Type supertype_field; |
|
954 |
||
955 |
/** The interfaces of this class (to be set once class is loaded). |
|
956 |
*/ |
|
957 |
public List<Type> interfaces_field; |
|
958 |
||
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
959 |
/** All the interfaces of this class, including missing ones. |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
960 |
*/ |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
961 |
public List<Type> all_interfaces_field; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
962 |
|
10 | 963 |
public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
964 |
this(outer, typarams, tsym, TypeMetadata.EMPTY); |
24396 | 965 |
} |
966 |
||
967 |
public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym, |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
968 |
TypeMetadata metadata) { |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
969 |
super(tsym, metadata); |
10 | 970 |
this.outer_field = outer; |
971 |
this.typarams_field = typarams; |
|
972 |
this.allparams_field = null; |
|
973 |
this.supertype_field = null; |
|
974 |
this.interfaces_field = null; |
|
975 |
} |
|
976 |
||
977 |
@Override |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
978 |
public ClassType cloneWithMetadata(TypeMetadata md) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
979 |
return new ClassType(outer_field, typarams_field, tsym, md) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
980 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
981 |
public Type baseType() { return ClassType.this.baseType(); } |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
982 |
}; |
24396 | 983 |
} |
984 |
||
985 |
@Override |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
986 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
987 |
return CLASS; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
988 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
989 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
990 |
@Override |
10 | 991 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
992 |
return v.visitClassType(this, s); |
|
993 |
} |
|
994 |
||
995 |
public Type constType(Object constValue) { |
|
996 |
final Object value = constValue; |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
997 |
return new ClassType(getEnclosingType(), typarams_field, tsym, metadata) { |
10 | 998 |
@Override |
999 |
public Object constValue() { |
|
1000 |
return value; |
|
1001 |
} |
|
1002 |
@Override |
|
1003 |
public Type baseType() { |
|
1004 |
return tsym.type; |
|
1005 |
} |
|
1006 |
}; |
|
1007 |
} |
|
1008 |
||
1009 |
/** The Java source which this type represents. |
|
1010 |
*/ |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1011 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1012 |
public String toString() { |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
1013 |
StringBuilder buf = new StringBuilder(); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1014 |
if (getEnclosingType().hasTag(CLASS) && tsym.owner.kind == TYP) { |
10 | 1015 |
buf.append(getEnclosingType().toString()); |
1016 |
buf.append("."); |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1017 |
appendAnnotationsString(buf); |
10 | 1018 |
buf.append(className(tsym, false)); |
1019 |
} else { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1020 |
appendAnnotationsString(buf); |
10 | 1021 |
buf.append(className(tsym, true)); |
1022 |
} |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1023 |
|
10 | 1024 |
if (getTypeArguments().nonEmpty()) { |
1025 |
buf.append('<'); |
|
1026 |
buf.append(getTypeArguments().toString()); |
|
1027 |
buf.append(">"); |
|
1028 |
} |
|
1029 |
return buf.toString(); |
|
1030 |
} |
|
1031 |
//where |
|
1032 |
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
|
1033 |
if (sym.name.isEmpty() && (sym.flags() & COMPOUND) != 0) { |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8430
diff
changeset
|
1034 |
StringBuilder s = new StringBuilder(supertype_field.toString()); |
10 | 1035 |
for (List<Type> is=interfaces_field; is.nonEmpty(); is = is.tail) { |
1036 |
s.append("&"); |
|
1037 |
s.append(is.head.toString()); |
|
1038 |
} |
|
1039 |
return s.toString(); |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
1040 |
} else if (sym.name.isEmpty()) { |
10 | 1041 |
String s; |
24396 | 1042 |
ClassType norm = (ClassType) tsym.type; |
10 | 1043 |
if (norm == null) { |
1044 |
s = Log.getLocalizedString("anonymous.class", (Object)null); |
|
1045 |
} else if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) { |
|
1046 |
s = Log.getLocalizedString("anonymous.class", |
|
1047 |
norm.interfaces_field.head); |
|
1048 |
} else { |
|
1049 |
s = Log.getLocalizedString("anonymous.class", |
|
1050 |
norm.supertype_field); |
|
1051 |
} |
|
1052 |
if (moreInfo) |
|
1053 |
s += String.valueOf(sym.hashCode()); |
|
1054 |
return s; |
|
1055 |
} else if (longform) { |
|
1056 |
return sym.getQualifiedName().toString(); |
|
1057 |
} else { |
|
1058 |
return sym.name.toString(); |
|
1059 |
} |
|
1060 |
} |
|
1061 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1062 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1063 |
public List<Type> getTypeArguments() { |
1064 |
if (typarams_field == null) { |
|
1065 |
complete(); |
|
1066 |
if (typarams_field == null) |
|
1067 |
typarams_field = List.nil(); |
|
1068 |
} |
|
1069 |
return typarams_field; |
|
1070 |
} |
|
1071 |
||
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
1072 |
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
|
1073 |
return isRaw(); |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
1074 |
} |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
1075 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1076 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1077 |
public Type getEnclosingType() { |
1078 |
return outer_field; |
|
1079 |
} |
|
1080 |
||
1081 |
public void setEnclosingType(Type outer) { |
|
1082 |
outer_field = outer; |
|
1083 |
} |
|
1084 |
||
1085 |
public List<Type> allparams() { |
|
1086 |
if (allparams_field == null) { |
|
1087 |
allparams_field = getTypeArguments().prependList(getEnclosingType().allparams()); |
|
1088 |
} |
|
1089 |
return allparams_field; |
|
1090 |
} |
|
1091 |
||
1092 |
public boolean isErroneous() { |
|
1093 |
return |
|
1094 |
getEnclosingType().isErroneous() || |
|
1095 |
isErroneous(getTypeArguments()) || |
|
24396 | 1096 |
this != tsym.type && tsym.type.isErroneous(); |
10 | 1097 |
} |
1098 |
||
1099 |
public boolean isParameterized() { |
|
1100 |
return allparams().tail != null; |
|
1101 |
// optimization, was: allparams().nonEmpty(); |
|
1102 |
} |
|
1103 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1104 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1105 |
public boolean isReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1106 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1107 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1108 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1109 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1110 |
public boolean isNullOrReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1111 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1112 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1113 |
|
10 | 1114 |
/** A cache for the rank. */ |
1115 |
int rank_field = -1; |
|
1116 |
||
1117 |
/** A class type is raw if it misses some |
|
1118 |
* of its type parameter sections. |
|
1119 |
* After validation, this is equivalent to: |
|
13844 | 1120 |
* {@code allparams.isEmpty() && tsym.type.allparams.nonEmpty(); } |
10 | 1121 |
*/ |
1122 |
public boolean isRaw() { |
|
1123 |
return |
|
1124 |
this != tsym.type && // necessary, but not sufficient condition |
|
1125 |
tsym.type.allparams().nonEmpty() && |
|
1126 |
allparams().isEmpty(); |
|
1127 |
} |
|
1128 |
||
1129 |
public boolean contains(Type elem) { |
|
1130 |
return |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1131 |
elem.equalsIgnoreMetadata(this) |
10 | 1132 |
|| (isParameterized() |
6348
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
1133 |
&& (getEnclosingType().contains(elem) || contains(getTypeArguments(), elem))) |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
1134 |
|| (isCompound() |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
5847
diff
changeset
|
1135 |
&& (supertype_field.contains(elem) || contains(interfaces_field, elem))); |
10 | 1136 |
} |
1137 |
||
1138 |
public void complete() { |
|
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
30011
diff
changeset
|
1139 |
tsym.complete(); |
10 | 1140 |
} |
1141 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1142 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1143 |
public TypeKind getKind() { |
1144 |
return TypeKind.DECLARED; |
|
1145 |
} |
|
1146 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1147 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1148 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
1149 |
return v.visitDeclared(this, p); |
|
1150 |
} |
|
1151 |
} |
|
1152 |
||
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
1153 |
public static class ErasedClassType extends ClassType { |
24396 | 1154 |
public ErasedClassType(Type outer, TypeSymbol tsym, |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1155 |
TypeMetadata metadata) { |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
1156 |
super(outer, List.nil(), tsym, metadata); |
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
1157 |
} |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
1158 |
|
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
1159 |
@Override |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
1160 |
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
|
1161 |
return true; |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
1162 |
} |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
1163 |
} |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
10
diff
changeset
|
1164 |
|
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
1165 |
// 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
|
1166 |
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
|
1167 |
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
|
1168 |
|
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
1169 |
public UnionClassType(ClassType ct, List<? extends Type> alternatives) { |
24396 | 1170 |
// Presently no way to refer to this type directly, so we |
1171 |
// cannot put annotations directly on it. |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1172 |
super(ct.outer_field, ct.typarams_field, ct.tsym); |
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
1173 |
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
|
1174 |
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
|
1175 |
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
|
1176 |
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
|
1177 |
alternatives_field = alternatives; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
1178 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
1179 |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1180 |
@Override |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1181 |
public UnionClassType cloneWithMetadata(TypeMetadata md) { |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1182 |
throw new AssertionError("Cannot add metadata to a union type"); |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1183 |
} |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1184 |
|
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
1185 |
public Type getLub() { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
1186 |
return tsym.type; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
1187 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
1188 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1189 |
@DefinedBy(Api.LANGUAGE_MODEL) |
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
1190 |
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
|
1191 |
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
|
1192 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
1193 |
|
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
27224
diff
changeset
|
1194 |
@Override |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
27224
diff
changeset
|
1195 |
public boolean isUnion() { |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
27224
diff
changeset
|
1196 |
return true; |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
27224
diff
changeset
|
1197 |
} |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
27224
diff
changeset
|
1198 |
|
33556
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
33018
diff
changeset
|
1199 |
@Override |
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
33018
diff
changeset
|
1200 |
public boolean isCompound() { |
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
33018
diff
changeset
|
1201 |
return getLub().isCompound(); |
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
33018
diff
changeset
|
1202 |
} |
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
33018
diff
changeset
|
1203 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1204 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
1205 |
public TypeKind getKind() { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
1206 |
return TypeKind.UNION; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
1207 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
1208 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1209 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
1210 |
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
|
1211 |
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
|
1212 |
} |
25440
7f9cedf2e88d
8042239: javac: TreeMaker.Type(Type t) does not handle UnionClassType
jlahoda
parents:
24794
diff
changeset
|
1213 |
|
7f9cedf2e88d
8042239: javac: TreeMaker.Type(Type t) does not handle UnionClassType
jlahoda
parents:
24794
diff
changeset
|
1214 |
public Iterable<? extends Type> getAlternativeTypes() { |
7f9cedf2e88d
8042239: javac: TreeMaker.Type(Type t) does not handle UnionClassType
jlahoda
parents:
24794
diff
changeset
|
1215 |
return alternatives_field; |
7f9cedf2e88d
8042239: javac: TreeMaker.Type(Type t) does not handle UnionClassType
jlahoda
parents:
24794
diff
changeset
|
1216 |
} |
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
1217 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
8625
diff
changeset
|
1218 |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1219 |
// 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
|
1220 |
public static class IntersectionClassType extends ClassType implements IntersectionType { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1221 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1222 |
public boolean allInterfaces; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1223 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1224 |
public IntersectionClassType(List<Type> bounds, ClassSymbol csym, boolean allInterfaces) { |
24396 | 1225 |
// Presently no way to refer to this type directly, so we |
1226 |
// cannot put annotations directly on it. |
|
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
1227 |
super(Type.noType, List.nil(), csym); |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1228 |
this.allInterfaces = allInterfaces; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1229 |
Assert.check((csym.flags() & COMPOUND) != 0); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1230 |
supertype_field = bounds.head; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1231 |
interfaces_field = bounds.tail; |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
30011
diff
changeset
|
1232 |
Assert.check(!supertype_field.tsym.isCompleted() || |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1233 |
!supertype_field.isInterface(), supertype_field); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1234 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1235 |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1236 |
@Override |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1237 |
public IntersectionClassType cloneWithMetadata(TypeMetadata md) { |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1238 |
throw new AssertionError("Cannot add metadata to an intersection type"); |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1239 |
} |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1240 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1241 |
@DefinedBy(Api.LANGUAGE_MODEL) |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1242 |
public java.util.List<? extends TypeMirror> getBounds() { |
20252
fae5c47ba7a4
6499673: Assertion check for TypeVariable.getUpperBound() fails.
emc
parents:
20249
diff
changeset
|
1243 |
return Collections.unmodifiableList(getExplicitComponents()); |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1244 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1245 |
|
33556
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
33018
diff
changeset
|
1246 |
@Override |
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
33018
diff
changeset
|
1247 |
public boolean isCompound() { |
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
33018
diff
changeset
|
1248 |
return true; |
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
33018
diff
changeset
|
1249 |
} |
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
33018
diff
changeset
|
1250 |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1251 |
public List<Type> getComponents() { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1252 |
return interfaces_field.prepend(supertype_field); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1253 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1254 |
|
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
27224
diff
changeset
|
1255 |
@Override |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
27224
diff
changeset
|
1256 |
public boolean isIntersection() { |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
27224
diff
changeset
|
1257 |
return true; |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
27224
diff
changeset
|
1258 |
} |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
27224
diff
changeset
|
1259 |
|
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16557
diff
changeset
|
1260 |
public List<Type> getExplicitComponents() { |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16557
diff
changeset
|
1261 |
return allInterfaces ? |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16557
diff
changeset
|
1262 |
interfaces_field : |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16557
diff
changeset
|
1263 |
getComponents(); |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16557
diff
changeset
|
1264 |
} |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16557
diff
changeset
|
1265 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1266 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1267 |
public TypeKind getKind() { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1268 |
return TypeKind.INTERSECTION; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1269 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1270 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1271 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1272 |
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
|
1273 |
return v.visitIntersection(this, p); |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1274 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1275 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
1276 |
|
10 | 1277 |
public static class ArrayType extends Type |
1278 |
implements javax.lang.model.type.ArrayType { |
|
1279 |
||
1280 |
public Type elemtype; |
|
1281 |
||
1282 |
public ArrayType(Type elemtype, TypeSymbol arrayClass) { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1283 |
this(elemtype, arrayClass, TypeMetadata.EMPTY); |
24396 | 1284 |
} |
1285 |
||
1286 |
public ArrayType(Type elemtype, TypeSymbol arrayClass, |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1287 |
TypeMetadata metadata) { |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1288 |
super(arrayClass, metadata); |
10 | 1289 |
this.elemtype = elemtype; |
1290 |
} |
|
1291 |
||
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1292 |
public ArrayType(ArrayType that) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1293 |
//note: type metadata is deliberately shared here, as we want side-effects from annotation |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1294 |
//processing to flow from original array to the cloned array. |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1295 |
this(that.elemtype, that.tsym, that.getMetadata()); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1296 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1297 |
|
10 | 1298 |
@Override |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1299 |
public ArrayType cloneWithMetadata(TypeMetadata md) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1300 |
return new ArrayType(elemtype, tsym, md) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1301 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1302 |
public Type baseType() { return ArrayType.this.baseType(); } |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1303 |
}; |
24396 | 1304 |
} |
1305 |
||
1306 |
@Override |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1307 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1308 |
return ARRAY; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1309 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1310 |
|
10 | 1311 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
1312 |
return v.visitArrayType(this, s); |
|
1313 |
} |
|
1314 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1315 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1316 |
public String toString() { |
24396 | 1317 |
StringBuilder sb = new StringBuilder(); |
30011
34df75eba76b
8068737: ArrayType prints element type post order
alundblad
parents:
29842
diff
changeset
|
1318 |
|
34df75eba76b
8068737: ArrayType prints element type post order
alundblad
parents:
29842
diff
changeset
|
1319 |
// First append root component type |
34df75eba76b
8068737: ArrayType prints element type post order
alundblad
parents:
29842
diff
changeset
|
1320 |
Type t = elemtype; |
34df75eba76b
8068737: ArrayType prints element type post order
alundblad
parents:
29842
diff
changeset
|
1321 |
while (t.getKind() == TypeKind.ARRAY) |
34df75eba76b
8068737: ArrayType prints element type post order
alundblad
parents:
29842
diff
changeset
|
1322 |
t = ((ArrayType) t).getComponentType(); |
34df75eba76b
8068737: ArrayType prints element type post order
alundblad
parents:
29842
diff
changeset
|
1323 |
sb.append(t); |
34df75eba76b
8068737: ArrayType prints element type post order
alundblad
parents:
29842
diff
changeset
|
1324 |
|
34df75eba76b
8068737: ArrayType prints element type post order
alundblad
parents:
29842
diff
changeset
|
1325 |
// then append @Anno[] @Anno[] ... @Anno[] |
34df75eba76b
8068737: ArrayType prints element type post order
alundblad
parents:
29842
diff
changeset
|
1326 |
t = this; |
34df75eba76b
8068737: ArrayType prints element type post order
alundblad
parents:
29842
diff
changeset
|
1327 |
do { |
34df75eba76b
8068737: ArrayType prints element type post order
alundblad
parents:
29842
diff
changeset
|
1328 |
t.appendAnnotationsString(sb, true); |
34df75eba76b
8068737: ArrayType prints element type post order
alundblad
parents:
29842
diff
changeset
|
1329 |
sb.append("[]"); |
34df75eba76b
8068737: ArrayType prints element type post order
alundblad
parents:
29842
diff
changeset
|
1330 |
t = ((ArrayType) t).getComponentType(); |
34df75eba76b
8068737: ArrayType prints element type post order
alundblad
parents:
29842
diff
changeset
|
1331 |
} while (t.getKind() == TypeKind.ARRAY); |
34df75eba76b
8068737: ArrayType prints element type post order
alundblad
parents:
29842
diff
changeset
|
1332 |
|
24396 | 1333 |
return sb.toString(); |
10 | 1334 |
} |
1335 |
||
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1336 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1337 |
public boolean equals(Object obj) { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1338 |
if (obj instanceof ArrayType) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1339 |
ArrayType that = (ArrayType)obj; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1340 |
return this == that || |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1341 |
elemtype.equals(that.elemtype); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1342 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1343 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1344 |
return false; |
10 | 1345 |
} |
1346 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1347 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1348 |
public int hashCode() { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
1349 |
return (ARRAY.ordinal() << 5) + elemtype.hashCode(); |
10 | 1350 |
} |
1351 |
||
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1352 |
public boolean isVarargs() { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1353 |
return false; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1354 |
} |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1355 |
|
10 | 1356 |
public List<Type> allparams() { return elemtype.allparams(); } |
1357 |
||
1358 |
public boolean isErroneous() { |
|
1359 |
return elemtype.isErroneous(); |
|
1360 |
} |
|
1361 |
||
1362 |
public boolean isParameterized() { |
|
1363 |
return elemtype.isParameterized(); |
|
1364 |
} |
|
1365 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1366 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1367 |
public boolean isReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1368 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1369 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1370 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1371 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1372 |
public boolean isNullOrReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1373 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1374 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1375 |
|
10 | 1376 |
public boolean isRaw() { |
1377 |
return elemtype.isRaw(); |
|
1378 |
} |
|
1379 |
||
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1380 |
public ArrayType makeVarargs() { |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1381 |
return new ArrayType(elemtype, tsym, metadata) { |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1382 |
@Override |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1383 |
public boolean isVarargs() { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1384 |
return true; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1385 |
} |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1386 |
}; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1387 |
} |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1388 |
|
10 | 1389 |
public boolean contains(Type elem) { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1390 |
return elem.equalsIgnoreMetadata(this) || elemtype.contains(elem); |
10 | 1391 |
} |
1392 |
||
1393 |
public void complete() { |
|
1394 |
elemtype.complete(); |
|
1395 |
} |
|
1396 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1397 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1398 |
public Type getComponentType() { |
1399 |
return elemtype; |
|
1400 |
} |
|
1401 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1402 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1403 |
public TypeKind getKind() { |
1404 |
return TypeKind.ARRAY; |
|
1405 |
} |
|
1406 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1407 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1408 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
1409 |
return v.visitArray(this, p); |
|
1410 |
} |
|
1411 |
} |
|
1412 |
||
8430 | 1413 |
public static class MethodType extends Type implements ExecutableType { |
10 | 1414 |
|
1415 |
public List<Type> argtypes; |
|
1416 |
public Type restype; |
|
1417 |
public List<Type> thrown; |
|
1418 |
||
15385 | 1419 |
/** The type annotations on the method receiver. |
1420 |
*/ |
|
1421 |
public Type recvtype; |
|
1422 |
||
10 | 1423 |
public MethodType(List<Type> argtypes, |
1424 |
Type restype, |
|
1425 |
List<Type> thrown, |
|
1426 |
TypeSymbol methodClass) { |
|
24396 | 1427 |
// Presently no way to refer to a method type directly, so |
1428 |
// we cannot put type annotations on it. |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1429 |
super(methodClass, TypeMetadata.EMPTY); |
10 | 1430 |
this.argtypes = argtypes; |
1431 |
this.restype = restype; |
|
1432 |
this.thrown = thrown; |
|
1433 |
} |
|
1434 |
||
1435 |
@Override |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1436 |
public MethodType cloneWithMetadata(TypeMetadata md) { |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1437 |
throw new AssertionError("Cannot add metadata to a method type"); |
24396 | 1438 |
} |
1439 |
||
1440 |
@Override |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1441 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1442 |
return METHOD; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1443 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1444 |
|
10 | 1445 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
1446 |
return v.visitMethodType(this, s); |
|
1447 |
} |
|
1448 |
||
1449 |
/** The Java source which this type represents. |
|
1450 |
* |
|
1451 |
* XXX 06/09/99 iris This isn't correct Java syntax, but it probably |
|
1452 |
* should be. |
|
1453 |
*/ |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1454 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1455 |
public String toString() { |
24396 | 1456 |
StringBuilder sb = new StringBuilder(); |
1457 |
appendAnnotationsString(sb); |
|
1458 |
sb.append('('); |
|
1459 |
sb.append(argtypes); |
|
1460 |
sb.append(')'); |
|
1461 |
sb.append(restype); |
|
1462 |
return sb.toString(); |
|
10 | 1463 |
} |
1464 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1465 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1466 |
public List<Type> getParameterTypes() { return argtypes; } |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1467 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1468 |
public Type getReturnType() { return restype; } |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1469 |
@DefinedBy(Api.LANGUAGE_MODEL) |
15385 | 1470 |
public Type getReceiverType() { return recvtype; } |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1471 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1472 |
public List<Type> getThrownTypes() { return thrown; } |
1473 |
||
1474 |
public boolean isErroneous() { |
|
1475 |
return |
|
1476 |
isErroneous(argtypes) || |
|
1477 |
restype != null && restype.isErroneous(); |
|
1478 |
} |
|
1479 |
||
1480 |
public boolean contains(Type elem) { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1481 |
return elem.equalsIgnoreMetadata(this) || contains(argtypes, elem) || restype.contains(elem) || contains(thrown, elem); |
10 | 1482 |
} |
1483 |
||
1484 |
public MethodType asMethodType() { return this; } |
|
1485 |
||
1486 |
public void complete() { |
|
1487 |
for (List<Type> l = argtypes; l.nonEmpty(); l = l.tail) |
|
1488 |
l.head.complete(); |
|
1489 |
restype.complete(); |
|
15385 | 1490 |
recvtype.complete(); |
10 | 1491 |
for (List<Type> l = thrown; l.nonEmpty(); l = l.tail) |
1492 |
l.head.complete(); |
|
1493 |
} |
|
1494 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1495 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1496 |
public List<TypeVar> getTypeVariables() { |
1497 |
return List.nil(); |
|
1498 |
} |
|
1499 |
||
1500 |
public TypeSymbol asElement() { |
|
1501 |
return null; |
|
1502 |
} |
|
1503 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1504 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1505 |
public TypeKind getKind() { |
1506 |
return TypeKind.EXECUTABLE; |
|
1507 |
} |
|
1508 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1509 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1510 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
1511 |
return v.visitExecutable(this, p); |
|
1512 |
} |
|
1513 |
} |
|
1514 |
||
1515 |
public static class PackageType extends Type implements NoType { |
|
1516 |
||
36526 | 1517 |
PackageType(PackageSymbol tsym) { |
24396 | 1518 |
// Package types cannot be annotated |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1519 |
super(tsym, TypeMetadata.EMPTY); |
24396 | 1520 |
} |
1521 |
||
1522 |
@Override |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1523 |
public PackageType cloneWithMetadata(TypeMetadata md) { |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1524 |
throw new AssertionError("Cannot add metadata to a package type"); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1525 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1526 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1527 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1528 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1529 |
return PACKAGE; |
10 | 1530 |
} |
1531 |
||
1532 |
@Override |
|
1533 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
1534 |
return v.visitPackageType(this, s); |
|
1535 |
} |
|
1536 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1537 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1538 |
public String toString() { |
1539 |
return tsym.getQualifiedName().toString(); |
|
1540 |
} |
|
1541 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1542 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1543 |
public TypeKind getKind() { |
1544 |
return TypeKind.PACKAGE; |
|
1545 |
} |
|
1546 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1547 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1548 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
1549 |
return v.visitNoType(this, p); |
|
1550 |
} |
|
1551 |
} |
|
1552 |
||
36526 | 1553 |
public static class ModuleType extends Type implements NoType { |
1554 |
||
1555 |
ModuleType(ModuleSymbol tsym) { |
|
1556 |
// Module types cannot be annotated |
|
1557 |
super(tsym, TypeMetadata.EMPTY); |
|
1558 |
} |
|
1559 |
||
1560 |
@Override |
|
1561 |
public ModuleType cloneWithMetadata(TypeMetadata md) { |
|
1562 |
throw new AssertionError("Cannot add metadata to a module type"); |
|
1563 |
} |
|
1564 |
||
1565 |
@Override |
|
1566 |
public ModuleType annotatedType(List<Attribute.TypeCompound> annos) { |
|
1567 |
throw new AssertionError("Cannot annotate a module type"); |
|
1568 |
} |
|
1569 |
||
1570 |
@Override |
|
1571 |
public TypeTag getTag() { |
|
1572 |
return TypeTag.MODULE; |
|
1573 |
} |
|
1574 |
||
1575 |
@Override |
|
1576 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
1577 |
return v.visitModuleType(this, s); |
|
1578 |
} |
|
1579 |
||
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37003
diff
changeset
|
1580 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
36526 | 1581 |
public String toString() { |
1582 |
return tsym.getQualifiedName().toString(); |
|
1583 |
} |
|
1584 |
||
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37003
diff
changeset
|
1585 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
36526 | 1586 |
public TypeKind getKind() { |
1587 |
return TypeKind.MODULE; |
|
1588 |
} |
|
1589 |
||
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37003
diff
changeset
|
1590 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
36526 | 1591 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
1592 |
return v.visitNoType(this, p); |
|
1593 |
} |
|
1594 |
} |
|
1595 |
||
10 | 1596 |
public static class TypeVar extends Type implements TypeVariable { |
1597 |
||
7637 | 1598 |
/** The upper bound of this type variable; set from outside. |
10 | 1599 |
* Must be nonempty once it is set. |
1600 |
* For a bound, `bound' is the bound type itself. |
|
1601 |
* Multiple bounds are expressed as a single class type which has the |
|
1602 |
* individual bounds as superclass, respectively interfaces. |
|
1603 |
* The class type then has as `tsym' a compiler generated class `c', |
|
1604 |
* which has a flag COMPOUND and whose owner is the type variable |
|
1605 |
* itself. Furthermore, the erasure_field of the class |
|
1606 |
* points to the first class or interface bound. |
|
1607 |
*/ |
|
1608 |
public Type bound = null; |
|
7637 | 1609 |
|
1610 |
/** The lower bound of this type variable. |
|
1611 |
* TypeVars don't normally have a lower bound, so it is normally set |
|
1612 |
* to syms.botType. |
|
1613 |
* Subtypes, such as CapturedType, may provide a different value. |
|
1614 |
*/ |
|
10 | 1615 |
public Type lower; |
1616 |
||
1617 |
public TypeVar(Name name, Symbol owner, Type lower) { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1618 |
super(null, TypeMetadata.EMPTY); |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
1619 |
Assert.checkNonNull(lower); |
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16809
diff
changeset
|
1620 |
tsym = new TypeVariableSymbol(0, name, this, owner); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1621 |
this.bound = null; |
10 | 1622 |
this.lower = lower; |
1623 |
} |
|
1624 |
||
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1625 |
public TypeVar(TypeSymbol tsym, Type bound, Type lower) { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1626 |
this(tsym, bound, lower, TypeMetadata.EMPTY); |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1627 |
} |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1628 |
|
24396 | 1629 |
public TypeVar(TypeSymbol tsym, Type bound, Type lower, |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1630 |
TypeMetadata metadata) { |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1631 |
super(tsym, metadata); |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
1632 |
Assert.checkNonNull(lower); |
10 | 1633 |
this.bound = bound; |
1634 |
this.lower = lower; |
|
1635 |
} |
|
1636 |
||
1637 |
@Override |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1638 |
public TypeVar cloneWithMetadata(TypeMetadata md) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1639 |
return new TypeVar(tsym, bound, lower, md) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1640 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1641 |
public Type baseType() { return TypeVar.this.baseType(); } |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1642 |
}; |
24396 | 1643 |
} |
1644 |
||
1645 |
@Override |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1646 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1647 |
return TYPEVAR; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1648 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1649 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1650 |
@Override |
10 | 1651 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
1652 |
return v.visitTypeVar(this, s); |
|
1653 |
} |
|
1654 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1655 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
15385 | 1656 |
public Type getUpperBound() { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1657 |
if ((bound == null || bound.hasTag(NONE)) && this != tsym.type) { |
15385 | 1658 |
bound = tsym.type.getUpperBound(); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1659 |
} |
15385 | 1660 |
return bound; |
1661 |
} |
|
10 | 1662 |
|
1663 |
int rank_field = -1; |
|
1664 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1665 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1666 |
public Type getLowerBound() { |
1667 |
return lower; |
|
1668 |
} |
|
1669 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1670 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1671 |
public TypeKind getKind() { |
1672 |
return TypeKind.TYPEVAR; |
|
1673 |
} |
|
1674 |
||
938
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1675 |
public boolean isCaptured() { |
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1676 |
return false; |
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1677 |
} |
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1678 |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1679 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1680 |
public boolean isReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1681 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1682 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1683 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1684 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1685 |
public boolean isNullOrReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1686 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1687 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1688 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1689 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1690 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
1691 |
return v.visitTypeVariable(this, p); |
|
1692 |
} |
|
1693 |
} |
|
1694 |
||
1695 |
/** A captured type variable comes from wildcards which can have |
|
1696 |
* both upper and lower bound. CapturedType extends TypeVar with |
|
1697 |
* a lower bound. |
|
1698 |
*/ |
|
1699 |
public static class CapturedType extends TypeVar { |
|
1700 |
||
1701 |
public WildcardType wildcard; |
|
1702 |
||
1703 |
public CapturedType(Name name, |
|
1704 |
Symbol owner, |
|
1705 |
Type upper, |
|
1706 |
Type lower, |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1707 |
WildcardType wildcard) { |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1708 |
super(name, owner, lower); |
8032 | 1709 |
this.lower = Assert.checkNonNull(lower); |
10 | 1710 |
this.bound = upper; |
1711 |
this.wildcard = wildcard; |
|
1712 |
} |
|
1713 |
||
24396 | 1714 |
public CapturedType(TypeSymbol tsym, |
1715 |
Type bound, |
|
1716 |
Type upper, |
|
1717 |
Type lower, |
|
1718 |
WildcardType wildcard, |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1719 |
TypeMetadata metadata) { |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1720 |
super(tsym, bound, lower, metadata); |
24396 | 1721 |
this.wildcard = wildcard; |
1722 |
} |
|
1723 |
||
1724 |
@Override |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1725 |
public CapturedType cloneWithMetadata(TypeMetadata md) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1726 |
return new CapturedType(tsym, bound, bound, lower, wildcard, md) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1727 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1728 |
public Type baseType() { return CapturedType.this.baseType(); } |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1729 |
}; |
24396 | 1730 |
} |
1731 |
||
10 | 1732 |
@Override |
1733 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
1734 |
return v.visitCapturedType(this, s); |
|
1735 |
} |
|
1736 |
||
1737 |
@Override |
|
938
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1738 |
public boolean isCaptured() { |
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1739 |
return true; |
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1740 |
} |
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
1741 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1742 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1743 |
public String toString() { |
24396 | 1744 |
StringBuilder sb = new StringBuilder(); |
1745 |
appendAnnotationsString(sb); |
|
1746 |
sb.append("capture#"); |
|
1747 |
sb.append((hashCode() & 0xFFFFFFFFL) % Printer.PRIME); |
|
1748 |
sb.append(" of "); |
|
1749 |
sb.append(wildcard); |
|
1750 |
return sb.toString(); |
|
10 | 1751 |
} |
1752 |
} |
|
1753 |
||
1754 |
public static abstract class DelegatedType extends Type { |
|
1755 |
public Type qtype; |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1756 |
public TypeTag tag; |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1757 |
|
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1758 |
public DelegatedType(TypeTag tag, Type qtype) { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1759 |
this(tag, qtype, TypeMetadata.EMPTY); |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1760 |
} |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1761 |
|
24396 | 1762 |
public DelegatedType(TypeTag tag, Type qtype, |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1763 |
TypeMetadata metadata) { |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1764 |
super(qtype.tsym, metadata); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1765 |
this.tag = tag; |
10 | 1766 |
this.qtype = qtype; |
1767 |
} |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1768 |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
1769 |
public TypeTag getTag() { return tag; } |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1770 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1771 |
public String toString() { return qtype.toString(); } |
1772 |
public List<Type> getTypeArguments() { return qtype.getTypeArguments(); } |
|
1773 |
public Type getEnclosingType() { return qtype.getEnclosingType(); } |
|
1774 |
public List<Type> getParameterTypes() { return qtype.getParameterTypes(); } |
|
1775 |
public Type getReturnType() { return qtype.getReturnType(); } |
|
15385 | 1776 |
public Type getReceiverType() { return qtype.getReceiverType(); } |
10 | 1777 |
public List<Type> getThrownTypes() { return qtype.getThrownTypes(); } |
1778 |
public List<Type> allparams() { return qtype.allparams(); } |
|
1779 |
public Type getUpperBound() { return qtype.getUpperBound(); } |
|
1780 |
public boolean isErroneous() { return qtype.isErroneous(); } |
|
1781 |
} |
|
1782 |
||
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
1783 |
/** |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
1784 |
* 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
|
1785 |
* 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
|
1786 |
* type. |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
1787 |
*/ |
8430 | 1788 |
public static class ForAll extends DelegatedType implements ExecutableType { |
10 | 1789 |
public List<Type> tvars; |
1790 |
||
1791 |
public ForAll(List<Type> tvars, Type qtype) { |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1792 |
super(FORALL, (MethodType)qtype); |
10 | 1793 |
this.tvars = tvars; |
1794 |
} |
|
1795 |
||
1796 |
@Override |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
1797 |
public ForAll cloneWithMetadata(TypeMetadata md) { |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1798 |
throw new AssertionError("Cannot add metadata to a forall type"); |
24396 | 1799 |
} |
1800 |
||
1801 |
@Override |
|
10 | 1802 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
1803 |
return v.visitForAll(this, s); |
|
1804 |
} |
|
1805 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1806 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1807 |
public String toString() { |
24396 | 1808 |
StringBuilder sb = new StringBuilder(); |
1809 |
appendAnnotationsString(sb); |
|
1810 |
sb.append('<'); |
|
1811 |
sb.append(tvars); |
|
1812 |
sb.append('>'); |
|
1813 |
sb.append(qtype); |
|
1814 |
return sb.toString(); |
|
10 | 1815 |
} |
1816 |
||
1817 |
public List<Type> getTypeArguments() { return tvars; } |
|
1818 |
||
1819 |
public boolean isErroneous() { |
|
1820 |
return qtype.isErroneous(); |
|
1821 |
} |
|
1822 |
||
1823 |
public boolean contains(Type elem) { |
|
1824 |
return qtype.contains(elem); |
|
1825 |
} |
|
1826 |
||
1827 |
public MethodType asMethodType() { |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
1828 |
return (MethodType)qtype; |
10 | 1829 |
} |
1830 |
||
1831 |
public void complete() { |
|
1832 |
for (List<Type> l = tvars; l.nonEmpty(); l = l.tail) { |
|
1833 |
((TypeVar)l.head).bound.complete(); |
|
1834 |
} |
|
1835 |
qtype.complete(); |
|
1836 |
} |
|
1837 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1838 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1839 |
public List<TypeVar> getTypeVariables() { |
1840 |
return List.convert(TypeVar.class, getTypeArguments()); |
|
1841 |
} |
|
1842 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1843 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1844 |
public TypeKind getKind() { |
1845 |
return TypeKind.EXECUTABLE; |
|
1846 |
} |
|
1847 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1848 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1849 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
1850 |
return v.visitExecutable(this, p); |
|
1851 |
} |
|
1852 |
} |
|
1853 |
||
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1854 |
/** 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
|
1855 |
* 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
|
1856 |
* 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
|
1857 |
* 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
|
1858 |
* 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
|
1859 |
* whenever the bounds of an inference variable change. |
10 | 1860 |
*/ |
1861 |
public static class UndetVar extends DelegatedType { |
|
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1862 |
|
42416
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1863 |
enum Kind { |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1864 |
NORMAL, |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1865 |
CAPTURED, |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1866 |
THROWS; |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1867 |
} |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1868 |
|
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1869 |
/** 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
|
1870 |
* 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
|
1871 |
*/ |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1872 |
public interface UndetVarListener { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1873 |
/** called when some inference variable bounds (of given kinds ibs) change */ |
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1874 |
void varBoundChanged(UndetVar uv, InferenceBound ib, Type bound, boolean update); |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1875 |
/** called when the inferred type is set on some inference variable */ |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1876 |
default void varInstantiated(UndetVar uv) { Assert.error(); } |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1877 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1878 |
|
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1879 |
/** |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1880 |
* Inference variable bound kinds |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1881 |
*/ |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1882 |
public enum InferenceBound { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1883 |
/** lower bounds */ |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
23395
diff
changeset
|
1884 |
LOWER { |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
23395
diff
changeset
|
1885 |
public InferenceBound complement() { return UPPER; } |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
23395
diff
changeset
|
1886 |
}, |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1887 |
/** equality constraints */ |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
23395
diff
changeset
|
1888 |
EQ { |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
23395
diff
changeset
|
1889 |
public InferenceBound complement() { return EQ; } |
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1890 |
}, |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1891 |
/** upper bounds */ |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1892 |
UPPER { |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1893 |
public InferenceBound complement() { return LOWER; } |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
23395
diff
changeset
|
1894 |
}; |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
23395
diff
changeset
|
1895 |
|
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
23395
diff
changeset
|
1896 |
public abstract InferenceBound complement(); |
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1897 |
|
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1898 |
public boolean lessThan(InferenceBound that) { |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1899 |
if (that == this) { |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1900 |
return false; |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1901 |
} else { |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1902 |
switch (that) { |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1903 |
case UPPER: return true; |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1904 |
case LOWER: return false; |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1905 |
case EQ: return (this != UPPER); |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1906 |
default: |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1907 |
Assert.error("Cannot get here!"); |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1908 |
return false; |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1909 |
} |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1910 |
} |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1911 |
} |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1912 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1913 |
|
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1914 |
/** list of incorporation actions (used by the incorporation engine). */ |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1915 |
public ArrayDeque<IncorporationAction> incorporationActions = new ArrayDeque<>(); |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1916 |
|
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1917 |
/** inference variable bounds */ |
18911 | 1918 |
protected Map<InferenceBound, List<Type>> bounds; |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1919 |
|
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1920 |
/** inference variable's inferred type (set from Infer.java) */ |
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1921 |
private Type inst = null; |
10 | 1922 |
|
15705 | 1923 |
/** number of declared (upper) bounds */ |
1924 |
public int declaredCount; |
|
1925 |
||
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1926 |
/** inference variable's change listener */ |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1927 |
public UndetVarListener listener = null; |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
1928 |
|
42416
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1929 |
Kind kind; |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1930 |
|
10 | 1931 |
@Override |
1932 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
1933 |
return v.visitUndetVar(this, s); |
|
1934 |
} |
|
1935 |
||
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1936 |
public UndetVar(TypeVar origin, UndetVarListener listener, Types types) { |
24396 | 1937 |
// This is a synthesized internal type, so we cannot annotate it. |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1938 |
super(UNDETVAR, origin); |
42416
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1939 |
this.kind = origin.isCaptured() ? |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1940 |
Kind.CAPTURED : |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1941 |
Kind.NORMAL; |
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1942 |
this.listener = listener; |
22163 | 1943 |
bounds = new EnumMap<>(InferenceBound.class); |
15705 | 1944 |
List<Type> declaredBounds = types.getBounds(origin); |
1945 |
declaredCount = declaredBounds.length(); |
|
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1946 |
bounds.put(InferenceBound.UPPER, List.nil()); |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1947 |
bounds.put(InferenceBound.LOWER, List.nil()); |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1948 |
bounds.put(InferenceBound.EQ, List.nil()); |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1949 |
for (Type t : declaredBounds.reverse()) { |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1950 |
//add bound works in reverse order |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1951 |
addBound(InferenceBound.UPPER, t, types, true); |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1952 |
} |
42416
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1953 |
if (origin.isCaptured() && !origin.lower.hasTag(BOT)) { |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1954 |
//add lower bound if needed |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1955 |
addBound(InferenceBound.LOWER, origin.lower, types, true); |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1956 |
} |
10 | 1957 |
} |
1958 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1959 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1960 |
public String toString() { |
24396 | 1961 |
StringBuilder sb = new StringBuilder(); |
1962 |
appendAnnotationsString(sb); |
|
1963 |
if (inst == null) { |
|
1964 |
sb.append(qtype); |
|
1965 |
sb.append('?'); |
|
1966 |
} else { |
|
1967 |
sb.append(inst); |
|
1968 |
} |
|
1969 |
return sb.toString(); |
|
23395
e7e0973e6d2e
8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents:
22163
diff
changeset
|
1970 |
} |
e7e0973e6d2e
8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents:
22163
diff
changeset
|
1971 |
|
e7e0973e6d2e
8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents:
22163
diff
changeset
|
1972 |
public String debugString() { |
e7e0973e6d2e
8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents:
22163
diff
changeset
|
1973 |
String result = "inference var = " + qtype + "\n"; |
e7e0973e6d2e
8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents:
22163
diff
changeset
|
1974 |
if (inst != null) { |
e7e0973e6d2e
8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents:
22163
diff
changeset
|
1975 |
result += "inst = " + inst + '\n'; |
e7e0973e6d2e
8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents:
22163
diff
changeset
|
1976 |
} |
e7e0973e6d2e
8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents:
22163
diff
changeset
|
1977 |
for (InferenceBound bound: InferenceBound.values()) { |
e7e0973e6d2e
8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents:
22163
diff
changeset
|
1978 |
List<Type> aboundList = bounds.get(bound); |
47356 | 1979 |
if (aboundList != null && aboundList.size() > 0) { |
23395
e7e0973e6d2e
8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents:
22163
diff
changeset
|
1980 |
result += bound + " = " + aboundList + '\n'; |
e7e0973e6d2e
8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents:
22163
diff
changeset
|
1981 |
} |
e7e0973e6d2e
8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents:
22163
diff
changeset
|
1982 |
} |
e7e0973e6d2e
8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents:
22163
diff
changeset
|
1983 |
return result; |
10 | 1984 |
} |
1985 |
||
42416
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1986 |
public void setThrow() { |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1987 |
if (this.kind == Kind.CAPTURED) { |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1988 |
//invalid state transition |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1989 |
throw new IllegalStateException(); |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1990 |
} |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1991 |
this.kind = Kind.THROWS; |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1992 |
} |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
1993 |
|
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1994 |
/** |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1995 |
* Returns a new copy of this undet var. |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1996 |
*/ |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1997 |
public UndetVar dup(Types types) { |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1998 |
UndetVar uv2 = new UndetVar((TypeVar)qtype, listener, types); |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
1999 |
dupTo(uv2, types); |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2000 |
return uv2; |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2001 |
} |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2002 |
|
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2003 |
/** |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2004 |
* Dumps the contents of this undet var on another undet var. |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2005 |
*/ |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2006 |
public void dupTo(UndetVar uv2, Types types) { |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2007 |
uv2.listener = null; |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2008 |
uv2.bounds.clear(); |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2009 |
for (InferenceBound ib : InferenceBound.values()) { |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2010 |
uv2.bounds.put(ib, List.nil()); |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2011 |
for (Type t : getBounds(ib)) { |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2012 |
uv2.addBound(ib, t, types, true); |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2013 |
} |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2014 |
} |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2015 |
uv2.inst = inst; |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2016 |
uv2.listener = listener; |
37003 | 2017 |
uv2.incorporationActions = new ArrayDeque<>(); |
2018 |
for (IncorporationAction action : incorporationActions) { |
|
2019 |
uv2.incorporationActions.add(action.dup(uv2)); |
|
2020 |
} |
|
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2021 |
} |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2022 |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2023 |
@Override |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
2024 |
public UndetVar cloneWithMetadata(TypeMetadata md) { |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
2025 |
throw new AssertionError("Cannot add metadata to an UndetVar type"); |
24396 | 2026 |
} |
2027 |
||
2028 |
@Override |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2029 |
public boolean isPartial() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2030 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2031 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2032 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2033 |
@Override |
10 | 2034 |
public Type baseType() { |
23395
e7e0973e6d2e
8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents:
22163
diff
changeset
|
2035 |
return (inst == null) ? this : inst.baseType(); |
10 | 2036 |
} |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
2037 |
|
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2038 |
public Type getInst() { |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2039 |
return inst; |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2040 |
} |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2041 |
|
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2042 |
public void setInst(Type inst) { |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2043 |
this.inst = inst; |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2044 |
if (listener != null) { |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2045 |
listener.varInstantiated(this); |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2046 |
} |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2047 |
} |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2048 |
|
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
2049 |
/** get all bounds of a given kind */ |
15705 | 2050 |
public List<Type> getBounds(InferenceBound... ibs) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19502
diff
changeset
|
2051 |
ListBuffer<Type> buf = new ListBuffer<>(); |
15705 | 2052 |
for (InferenceBound ib : ibs) { |
2053 |
buf.appendList(bounds.get(ib)); |
|
2054 |
} |
|
2055 |
return buf.toList(); |
|
2056 |
} |
|
2057 |
||
2058 |
/** get the list of declared (upper) bounds */ |
|
2059 |
public List<Type> getDeclaredBounds() { |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19502
diff
changeset
|
2060 |
ListBuffer<Type> buf = new ListBuffer<>(); |
15705 | 2061 |
int count = 0; |
2062 |
for (Type b : getBounds(InferenceBound.UPPER)) { |
|
2063 |
if (count++ == declaredCount) break; |
|
2064 |
buf.append(b); |
|
2065 |
} |
|
2066 |
return buf.toList(); |
|
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
2067 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
2068 |
|
18904
3c4c6457ec5b
8019824: very long error messages on inference error
mcimadamore
parents:
18902
diff
changeset
|
2069 |
/** internal method used to override an undetvar bounds */ |
3c4c6457ec5b
8019824: very long error messages on inference error
mcimadamore
parents:
18902
diff
changeset
|
2070 |
public void setBounds(InferenceBound ib, List<Type> newBounds) { |
3c4c6457ec5b
8019824: very long error messages on inference error
mcimadamore
parents:
18902
diff
changeset
|
2071 |
bounds.put(ib, newBounds); |
3c4c6457ec5b
8019824: very long error messages on inference error
mcimadamore
parents:
18902
diff
changeset
|
2072 |
} |
3c4c6457ec5b
8019824: very long error messages on inference error
mcimadamore
parents:
18902
diff
changeset
|
2073 |
|
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
2074 |
/** add a bound of a given kind - this might trigger listener notification */ |
18911 | 2075 |
public final void addBound(InferenceBound ib, Type bound, Types types) { |
42819
4ce83e629dc1
8075793: Source incompatibility for inference using -source 7
dlsmith
parents:
42416
diff
changeset
|
2076 |
// Per JDK-8075793: in pre-8 sources, follow legacy javac behavior |
4ce83e629dc1
8075793: Source incompatibility for inference using -source 7
dlsmith
parents:
42416
diff
changeset
|
2077 |
// when capture variables are inferred as bounds: for lower bounds, |
4ce83e629dc1
8075793: Source incompatibility for inference using -source 7
dlsmith
parents:
42416
diff
changeset
|
2078 |
// map to the capture variable's upper bound; for upper bounds, |
4ce83e629dc1
8075793: Source incompatibility for inference using -source 7
dlsmith
parents:
42416
diff
changeset
|
2079 |
// if the capture variable has a lower bound, map to that type |
4ce83e629dc1
8075793: Source incompatibility for inference using -source 7
dlsmith
parents:
42416
diff
changeset
|
2080 |
if (types.mapCapturesToBounds) { |
4ce83e629dc1
8075793: Source incompatibility for inference using -source 7
dlsmith
parents:
42416
diff
changeset
|
2081 |
switch (ib) { |
4ce83e629dc1
8075793: Source incompatibility for inference using -source 7
dlsmith
parents:
42416
diff
changeset
|
2082 |
case LOWER: |
4ce83e629dc1
8075793: Source incompatibility for inference using -source 7
dlsmith
parents:
42416
diff
changeset
|
2083 |
bound = types.cvarUpperBound(bound); |
4ce83e629dc1
8075793: Source incompatibility for inference using -source 7
dlsmith
parents:
42416
diff
changeset
|
2084 |
break; |
4ce83e629dc1
8075793: Source incompatibility for inference using -source 7
dlsmith
parents:
42416
diff
changeset
|
2085 |
case UPPER: |
4ce83e629dc1
8075793: Source incompatibility for inference using -source 7
dlsmith
parents:
42416
diff
changeset
|
2086 |
Type altBound = types.cvarLowerBound(bound); |
4ce83e629dc1
8075793: Source incompatibility for inference using -source 7
dlsmith
parents:
42416
diff
changeset
|
2087 |
if (!altBound.hasTag(TypeTag.BOT)) bound = altBound; |
4ce83e629dc1
8075793: Source incompatibility for inference using -source 7
dlsmith
parents:
42416
diff
changeset
|
2088 |
break; |
4ce83e629dc1
8075793: Source incompatibility for inference using -source 7
dlsmith
parents:
42416
diff
changeset
|
2089 |
} |
4ce83e629dc1
8075793: Source incompatibility for inference using -source 7
dlsmith
parents:
42416
diff
changeset
|
2090 |
} |
18911 | 2091 |
addBound(ib, bound, types, false); |
2092 |
} |
|
2093 |
||
42416
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2094 |
@SuppressWarnings("fallthrough") |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2095 |
private void addBound(InferenceBound ib, Type bound, Types types, boolean update) { |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2096 |
if (kind == Kind.CAPTURED && !update) { |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2097 |
//Captured inference variables bounds must not be updated during incorporation, |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2098 |
//except when some inference variable (beta) has been instantiated in the |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2099 |
//right-hand-side of a 'C<alpha> = capture(C<? extends/super beta>) constraint. |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2100 |
if (bound.hasTag(UNDETVAR) && !((UndetVar)bound).isCaptured()) { |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2101 |
//If the new incoming bound is itself a (regular) inference variable, |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2102 |
//then we are allowed to propagate this inference variable bounds to it. |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2103 |
((UndetVar)bound).addBound(ib.complement(), this, types, false); |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2104 |
} |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2105 |
} else { |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2106 |
Type bound2 = bound.map(toTypeVarMap).baseType(); |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2107 |
List<Type> prevBounds = bounds.get(ib); |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2108 |
if (bound == qtype) return; |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2109 |
for (Type b : prevBounds) { |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2110 |
//check for redundancy - use strict version of isSameType on tvars |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2111 |
//(as the standard version will lead to false positives w.r.t. clones ivars) |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2112 |
if (types.isSameType(b, bound2, true)) return; |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2113 |
} |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2114 |
bounds.put(ib, prevBounds.prepend(bound2)); |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2115 |
notifyBoundChange(ib, bound2, false); |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
2116 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
2117 |
} |
15705 | 2118 |
//where |
44186
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
42828
diff
changeset
|
2119 |
TypeMapping<Void> toTypeVarMap = new StructuralTypeMapping<Void>() { |
15705 | 2120 |
@Override |
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
2121 |
public Type visitUndetVar(UndetVar uv, Void _unused) { |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29147
diff
changeset
|
2122 |
return uv.inst != null ? uv.inst : uv.qtype; |
15705 | 2123 |
} |
2124 |
}; |
|
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
2125 |
|
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
2126 |
/** 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
|
2127 |
public void substBounds(List<Type> from, List<Type> to, Types types) { |
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2128 |
final ListBuffer<Pair<InferenceBound, Type>> boundsChanged = new ListBuffer<>(); |
15705 | 2129 |
UndetVarListener prevListener = listener; |
2130 |
try { |
|
2131 |
//setup new listener for keeping track of changed bounds |
|
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42819
diff
changeset
|
2132 |
listener = (uv, ib, t, _ignored) -> { |
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42819
diff
changeset
|
2133 |
Assert.check(uv == UndetVar.this); |
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42819
diff
changeset
|
2134 |
boundsChanged.add(new Pair<>(ib, t)); |
15705 | 2135 |
}; |
2136 |
for (Map.Entry<InferenceBound, List<Type>> _entry : bounds.entrySet()) { |
|
2137 |
InferenceBound ib = _entry.getKey(); |
|
2138 |
List<Type> prevBounds = _entry.getValue(); |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19502
diff
changeset
|
2139 |
ListBuffer<Type> newBounds = new ListBuffer<>(); |
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19502
diff
changeset
|
2140 |
ListBuffer<Type> deps = new ListBuffer<>(); |
15705 | 2141 |
//step 1 - re-add bounds that are not dependent on ivars |
2142 |
for (Type t : prevBounds) { |
|
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2143 |
if (!t.containsAny(from)) { |
15705 | 2144 |
newBounds.append(t); |
2145 |
} else { |
|
2146 |
deps.append(t); |
|
2147 |
} |
|
2148 |
} |
|
2149 |
//step 2 - replace bounds |
|
2150 |
bounds.put(ib, newBounds.toList()); |
|
2151 |
//step 3 - for each dependency, add new replaced bound |
|
2152 |
for (Type dep : deps) { |
|
18911 | 2153 |
addBound(ib, types.subst(dep, from, to), types, true); |
15705 | 2154 |
} |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
2155 |
} |
15705 | 2156 |
} finally { |
2157 |
listener = prevListener; |
|
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2158 |
for (Pair<InferenceBound, Type> boundUpdate : boundsChanged) { |
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2159 |
notifyBoundChange(boundUpdate.fst, boundUpdate.snd, true); |
15705 | 2160 |
} |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
2161 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
2162 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
2163 |
|
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2164 |
private void notifyBoundChange(InferenceBound ib, Type bound, boolean update) { |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
2165 |
if (listener != null) { |
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2166 |
listener.varBoundChanged(this, ib, bound, update); |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
2167 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13844
diff
changeset
|
2168 |
} |
18911 | 2169 |
|
42416
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2170 |
public final boolean isCaptured() { |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2171 |
return kind == Kind.CAPTURED; |
18911 | 2172 |
} |
2173 |
||
42416
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2174 |
public final boolean isThrows() { |
1cfad0990b99
8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents:
37848
diff
changeset
|
2175 |
return kind == Kind.THROWS; |
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33556
diff
changeset
|
2176 |
} |
10 | 2177 |
} |
2178 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2179 |
/** Represents NONE. |
10 | 2180 |
*/ |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2181 |
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
|
2182 |
public JCNoType() { |
24396 | 2183 |
// Need to use List.nil(), because JCNoType constructor |
2184 |
// gets called in static initializers in Type, where |
|
2185 |
// noAnnotations is also defined. |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
2186 |
super(null, TypeMetadata.EMPTY); |
24396 | 2187 |
} |
2188 |
||
2189 |
@Override |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
2190 |
public JCNoType cloneWithMetadata(TypeMetadata md) { |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
2191 |
throw new AssertionError("Cannot add metadata to a JCNoType"); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2192 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2193 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2194 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2195 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2196 |
return NONE; |
10 | 2197 |
} |
2198 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2199 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
10 | 2200 |
public TypeKind getKind() { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2201 |
return TypeKind.NONE; |
10 | 2202 |
} |
2203 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2204 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
10 | 2205 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
2206 |
return v.visitNoType(this, p); |
|
2207 |
} |
|
20606 | 2208 |
|
2209 |
@Override |
|
2210 |
public boolean isCompound() { return false; } |
|
10 | 2211 |
} |
2212 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2213 |
/** Represents VOID. |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2214 |
*/ |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2215 |
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
|
2216 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2217 |
public JCVoidType() { |
24396 | 2218 |
// Void cannot be annotated |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
2219 |
super(null, TypeMetadata.EMPTY); |
24396 | 2220 |
} |
2221 |
||
2222 |
@Override |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
2223 |
public JCVoidType cloneWithMetadata(TypeMetadata md) { |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
2224 |
throw new AssertionError("Cannot add metadata to a void type"); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2225 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2226 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2227 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2228 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2229 |
return VOID; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2230 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2231 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2232 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2233 |
public TypeKind getKind() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2234 |
return TypeKind.VOID; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2235 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2236 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2237 |
@Override |
20606 | 2238 |
public boolean isCompound() { return false; } |
2239 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2240 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2241 |
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
|
2242 |
return v.visitNoType(this, p); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2243 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2244 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2245 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2246 |
public boolean isPrimitiveOrVoid() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2247 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2248 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2249 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2250 |
|
10 | 2251 |
static class BottomType extends Type implements NullType { |
2252 |
public BottomType() { |
|
24396 | 2253 |
// Bottom is a synthesized internal type, so it cannot be annotated |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
2254 |
super(null, TypeMetadata.EMPTY); |
24396 | 2255 |
} |
2256 |
||
2257 |
@Override |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
2258 |
public BottomType cloneWithMetadata(TypeMetadata md) { |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
2259 |
throw new AssertionError("Cannot add metadata to a bottom type"); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2260 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2261 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2262 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2263 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2264 |
return BOT; |
10 | 2265 |
} |
2266 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2267 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
10 | 2268 |
public TypeKind getKind() { |
2269 |
return TypeKind.NULL; |
|
2270 |
} |
|
2271 |
||
2272 |
@Override |
|
20606 | 2273 |
public boolean isCompound() { return false; } |
2274 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2275 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
10 | 2276 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
2277 |
return v.visitNull(this, p); |
|
2278 |
} |
|
2279 |
||
2280 |
@Override |
|
2281 |
public Type constType(Object value) { |
|
2282 |
return this; |
|
2283 |
} |
|
2284 |
||
2285 |
@Override |
|
2286 |
public String stringValue() { |
|
2287 |
return "null"; |
|
2288 |
} |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2289 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2290 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2291 |
public boolean isNullOrReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2292 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2293 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2294 |
|
10 | 2295 |
} |
2296 |
||
2297 |
public static class ErrorType extends ClassType |
|
2298 |
implements javax.lang.model.type.ErrorType { |
|
2299 |
||
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
|
2300 |
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
|
2301 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
2302 |
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
|
2303 |
this(originalType, c); |
10 | 2304 |
c.type = this; |
2305 |
c.kind = ERR; |
|
2306 |
c.members_field = new Scope.ErrorScope(c); |
|
2307 |
} |
|
2308 |
||
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
2309 |
public ErrorType(Type originalType, TypeSymbol tsym) { |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
2310 |
super(noType, List.nil(), null); |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
2311 |
this.tsym = tsym; |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
2312 |
this.originalType = (originalType == null ? noType : originalType); |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
2313 |
} |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
2314 |
|
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
2315 |
private ErrorType(Type originalType, TypeSymbol tsym, |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
2316 |
TypeMetadata metadata) { |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
2317 |
super(noType, List.nil(), null, metadata); |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
2318 |
this.tsym = tsym; |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
2319 |
this.originalType = (originalType == null ? noType : originalType); |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
2320 |
} |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
2321 |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2322 |
@Override |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
2323 |
public ErrorType cloneWithMetadata(TypeMetadata md) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
2324 |
return new ErrorType(originalType, tsym, md) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
2325 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
2326 |
public Type baseType() { return ErrorType.this.baseType(); } |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
2327 |
}; |
24396 | 2328 |
} |
2329 |
||
2330 |
@Override |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2331 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2332 |
return ERROR; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2333 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2334 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2335 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2336 |
public boolean isPartial() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2337 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2338 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2339 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2340 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2341 |
public boolean isReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2342 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2343 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2344 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2345 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2346 |
public boolean isNullOrReference() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2347 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2348 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2349 |
|
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
|
2350 |
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
|
2351 |
this(new ClassSymbol(PUBLIC|STATIC|ACYCLIC, name, null, container), originalType); |
10 | 2352 |
} |
2353 |
||
2354 |
@Override |
|
2355 |
public <R,S> R accept(Type.Visitor<R,S> v, S s) { |
|
2356 |
return v.visitErrorType(this, s); |
|
2357 |
} |
|
2358 |
||
2359 |
public Type constType(Object constValue) { return this; } |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2360 |
@DefinedBy(Api.LANGUAGE_MODEL) |
15385 | 2361 |
public Type getEnclosingType() { return this; } |
10 | 2362 |
public Type getReturnType() { return this; } |
2363 |
public Type asSub(Symbol sym) { return this; } |
|
2364 |
||
2365 |
public boolean isGenType(Type t) { return true; } |
|
2366 |
public boolean isErroneous() { return true; } |
|
2367 |
public boolean isCompound() { return false; } |
|
2368 |
public boolean isInterface() { return false; } |
|
2369 |
||
2370 |
public List<Type> allparams() { return List.nil(); } |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2371 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 2372 |
public List<Type> getTypeArguments() { return List.nil(); } |
2373 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2374 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 2375 |
public TypeKind getKind() { |
2376 |
return TypeKind.ERROR; |
|
2377 |
} |
|
2378 |
||
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
|
2379 |
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
|
2380 |
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
|
2381 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
2382 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2383 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 2384 |
public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
2385 |
return v.visitError(this, p); |
|
2386 |
} |
|
2387 |
} |
|
2388 |
||
24396 | 2389 |
public static class UnknownType extends Type { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2390 |
|
24396 | 2391 |
public UnknownType() { |
2392 |
// Unknown is a synthesized internal type, so it cannot be |
|
2393 |
// annotated. |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
2394 |
super(null, TypeMetadata.EMPTY); |
15385 | 2395 |
} |
2396 |
||
2397 |
@Override |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29554
diff
changeset
|
2398 |
public UnknownType cloneWithMetadata(TypeMetadata md) { |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
2399 |
throw new AssertionError("Cannot add metadata to an unknown type"); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2400 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2401 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2402 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2403 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2404 |
return UNKNOWN; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2405 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2406 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2407 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2408 |
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
|
2409 |
return v.visitUnknown(this, p); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2410 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2411 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2412 |
@Override |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2413 |
public boolean isPartial() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2414 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2415 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2416 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18395
diff
changeset
|
2417 |
|
10 | 2418 |
/** |
2419 |
* A visitor for types. A visitor is used to implement operations |
|
2420 |
* (or relations) on types. Most common operations on types are |
|
2421 |
* binary relations and this interface is designed for binary |
|
15385 | 2422 |
* relations, that is, operations of the form |
10 | 2423 |
* Type × S → R. |
2424 |
* <!-- In plain text: Type x S -> R --> |
|
2425 |
* |
|
2426 |
* @param <R> the return type of the operation implemented by this |
|
2427 |
* visitor; use Void if no return type is needed. |
|
2428 |
* @param <S> the type of the second argument (the first being the |
|
2429 |
* type itself) of the operation implemented by this visitor; use |
|
2430 |
* Void if a second argument is not needed. |
|
2431 |
*/ |
|
2432 |
public interface Visitor<R,S> { |
|
2433 |
R visitClassType(ClassType t, S s); |
|
2434 |
R visitWildcardType(WildcardType t, S s); |
|
2435 |
R visitArrayType(ArrayType t, S s); |
|
2436 |
R visitMethodType(MethodType t, S s); |
|
2437 |
R visitPackageType(PackageType t, S s); |
|
36526 | 2438 |
R visitModuleType(ModuleType t, S s); |
10 | 2439 |
R visitTypeVar(TypeVar t, S s); |
2440 |
R visitCapturedType(CapturedType t, S s); |
|
2441 |
R visitForAll(ForAll t, S s); |
|
2442 |
R visitUndetVar(UndetVar t, S s); |
|
2443 |
R visitErrorType(ErrorType t, S s); |
|
2444 |
R visitType(Type t, S s); |
|
2445 |
} |
|
2446 |
} |