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