author | rfield |
Fri, 15 Feb 2013 18:40:38 -0800 | |
changeset 16300 | 7cf27559c8df |
parent 15720 | e61b2f7a5148 |
child 16320 | 92ba27b7aaf3 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
15355
a4757c33cae9
7193719: Support repeating annotations in javax.lang.model
jfranck
parents:
15031
diff
changeset
|
2 |
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.code; |
|
27 |
||
28 |
import java.util.Set; |
|
29 |
import java.util.concurrent.Callable; |
|
14258 | 30 |
|
10 | 31 |
import javax.lang.model.element.*; |
32 |
import javax.tools.JavaFileObject; |
|
33 |
||
34 |
import com.sun.tools.javac.code.Type.*; |
|
35 |
import com.sun.tools.javac.comp.Attr; |
|
36 |
import com.sun.tools.javac.comp.AttrContext; |
|
37 |
import com.sun.tools.javac.comp.Env; |
|
38 |
import com.sun.tools.javac.jvm.*; |
|
39 |
import com.sun.tools.javac.model.*; |
|
40 |
import com.sun.tools.javac.tree.JCTree; |
|
14258 | 41 |
import com.sun.tools.javac.util.*; |
42 |
import com.sun.tools.javac.util.Name; |
|
10 | 43 |
import static com.sun.tools.javac.code.Flags.*; |
44 |
import static com.sun.tools.javac.code.Kinds.*; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
45 |
import static com.sun.tools.javac.code.TypeTag.CLASS; |
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.FORALL; |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
47 |
import static com.sun.tools.javac.code.TypeTag.TYPEVAR; |
10 | 48 |
|
49 |
/** Root class for Java symbols. It contains subclasses |
|
50 |
* for specific sorts of symbols, such as variables, methods and operators, |
|
51 |
* types, packages. Each subclass is represented as a static inner class |
|
52 |
* inside Symbol. |
|
53 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
54 |
* <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
|
55 |
* If you write code that depends on this, you do so at your own risk. |
10 | 56 |
* This code and its internal interfaces are subject to change or |
57 |
* deletion without notice.</b> |
|
58 |
*/ |
|
59 |
public abstract class Symbol implements Element { |
|
60 |
// public Throwable debug = new Throwable(); |
|
61 |
||
62 |
/** The kind of this symbol. |
|
63 |
* @see Kinds |
|
64 |
*/ |
|
65 |
public int kind; |
|
66 |
||
67 |
/** The flags of this symbol. |
|
68 |
*/ |
|
69 |
public long flags_field; |
|
70 |
||
71 |
/** An accessor method for the flags of this symbol. |
|
72 |
* Flags of class symbols should be accessed through the accessor |
|
73 |
* method to make sure that the class symbol is loaded. |
|
74 |
*/ |
|
75 |
public long flags() { return flags_field; } |
|
76 |
||
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12335
diff
changeset
|
77 |
/** The attributes of this symbol are contained in this |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12335
diff
changeset
|
78 |
* Annotations. The Annotations instance is NOT immutable. |
10 | 79 |
*/ |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12335
diff
changeset
|
80 |
public final Annotations annotations = new Annotations(this); |
10 | 81 |
|
82 |
/** An accessor method for the attributes of this symbol. |
|
83 |
* Attributes of class symbols should be accessed through the accessor |
|
84 |
* method to make sure that the class symbol is loaded. |
|
85 |
*/ |
|
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
86 |
public List<Attribute.Compound> getRawAttributes() { |
15385 | 87 |
return annotations.getDeclarationAttributes(); |
88 |
} |
|
89 |
||
90 |
/** An accessor method for the type attributes of this symbol. |
|
91 |
* Attributes of class symbols should be accessed through the accessor |
|
92 |
* method to make sure that the class symbol is loaded. |
|
93 |
*/ |
|
94 |
public List<Attribute.TypeCompound> getRawTypeAttributes() { |
|
95 |
return annotations.getTypeAttributes(); |
|
10 | 96 |
} |
97 |
||
98 |
/** Fetch a particular annotation from a symbol. */ |
|
99 |
public Attribute.Compound attribute(Symbol anno) { |
|
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
100 |
for (Attribute.Compound a : getRawAttributes()) { |
10 | 101 |
if (a.type.tsym == anno) return a; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12335
diff
changeset
|
102 |
} |
10 | 103 |
return null; |
104 |
} |
|
105 |
||
106 |
/** The name of this symbol in Utf8 representation. |
|
107 |
*/ |
|
108 |
public Name name; |
|
109 |
||
110 |
/** The type of this symbol. |
|
111 |
*/ |
|
112 |
public Type type; |
|
113 |
||
114 |
/** The owner of this symbol. |
|
115 |
*/ |
|
116 |
public Symbol owner; |
|
117 |
||
118 |
/** The completer of this symbol. |
|
119 |
*/ |
|
120 |
public Completer completer; |
|
121 |
||
122 |
/** A cache for the type erasure of this symbol. |
|
123 |
*/ |
|
124 |
public Type erasure_field; |
|
125 |
||
126 |
/** Construct a symbol with given kind, flags, name, type and owner. |
|
127 |
*/ |
|
128 |
public Symbol(int kind, long flags, Name name, Type type, Symbol owner) { |
|
129 |
this.kind = kind; |
|
130 |
this.flags_field = flags; |
|
131 |
this.type = type; |
|
132 |
this.owner = owner; |
|
133 |
this.completer = null; |
|
134 |
this.erasure_field = null; |
|
135 |
this.name = name; |
|
136 |
} |
|
137 |
||
138 |
/** Clone this symbol with new owner. |
|
139 |
* Legal only for fields and methods. |
|
140 |
*/ |
|
141 |
public Symbol clone(Symbol newOwner) { |
|
142 |
throw new AssertionError(); |
|
143 |
} |
|
144 |
||
1357 | 145 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
146 |
return v.visitSymbol(this, p); |
|
147 |
} |
|
148 |
||
10 | 149 |
/** The Java source which this symbol represents. |
150 |
* A description of this symbol; overrides Object. |
|
151 |
*/ |
|
152 |
public String toString() { |
|
153 |
return name.toString(); |
|
154 |
} |
|
155 |
||
156 |
/** A Java source description of the location of this symbol; used for |
|
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
157 |
* error reporting. |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
158 |
* |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
159 |
* @return null if the symbol is a package or a toplevel class defined in |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
160 |
* the default package; otherwise, the owner symbol is returned |
10 | 161 |
*/ |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
162 |
public Symbol location() { |
10626
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
163 |
if (owner.name == null || (owner.name.isEmpty() && |
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
164 |
(owner.flags() & BLOCK) == 0 && owner.kind != PCK && owner.kind != TYP)) { |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
165 |
return null; |
10 | 166 |
} |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
167 |
return owner; |
10 | 168 |
} |
169 |
||
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
170 |
public Symbol location(Type site, Types types) { |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
171 |
if (owner.name == null || owner.name.isEmpty()) { |
10 | 172 |
return location(); |
173 |
} |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
174 |
if (owner.type.hasTag(CLASS)) { |
10 | 175 |
Type ownertype = types.asOuterSuper(site, owner); |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
176 |
if (ownertype != null) return ownertype.tsym; |
10 | 177 |
} |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
178 |
return owner; |
10 | 179 |
} |
180 |
||
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14046
diff
changeset
|
181 |
public Symbol baseSymbol() { |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14046
diff
changeset
|
182 |
return this; |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14046
diff
changeset
|
183 |
} |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14046
diff
changeset
|
184 |
|
10 | 185 |
/** The symbol's erased type. |
186 |
*/ |
|
187 |
public Type erasure(Types types) { |
|
188 |
if (erasure_field == null) |
|
189 |
erasure_field = types.erasure(type); |
|
190 |
return erasure_field; |
|
191 |
} |
|
192 |
||
193 |
/** The external type of a symbol. This is the symbol's erased type |
|
194 |
* except for constructors of inner classes which get the enclosing |
|
195 |
* instance class added as first argument. |
|
196 |
*/ |
|
197 |
public Type externalType(Types types) { |
|
198 |
Type t = erasure(types); |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
199 |
if (name == name.table.names.init && owner.hasOuterInstance()) { |
10 | 200 |
Type outerThisType = types.erasure(owner.type.getEnclosingType()); |
201 |
return new MethodType(t.getParameterTypes().prepend(outerThisType), |
|
202 |
t.getReturnType(), |
|
203 |
t.getThrownTypes(), |
|
204 |
t.tsym); |
|
205 |
} else { |
|
206 |
return t; |
|
207 |
} |
|
208 |
} |
|
209 |
||
210 |
public boolean isStatic() { |
|
211 |
return |
|
212 |
(flags() & STATIC) != 0 || |
|
213 |
(owner.flags() & INTERFACE) != 0 && kind != MTH; |
|
214 |
} |
|
215 |
||
216 |
public boolean isInterface() { |
|
217 |
return (flags() & INTERFACE) != 0; |
|
218 |
} |
|
219 |
||
15720
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
220 |
public boolean isPrivate() { |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
221 |
return (flags_field & Flags.AccessFlags) == PRIVATE; |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
222 |
} |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
223 |
|
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
224 |
public boolean isEnum() { |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
225 |
return (flags() & ENUM) != 0; |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
226 |
} |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
227 |
|
10 | 228 |
/** Is this symbol declared (directly or indirectly) local |
229 |
* to a method or variable initializer? |
|
230 |
* Also includes fields of inner classes which are in |
|
231 |
* turn local to a method or variable initializer. |
|
232 |
*/ |
|
233 |
public boolean isLocal() { |
|
234 |
return |
|
235 |
(owner.kind & (VAR | MTH)) != 0 || |
|
236 |
(owner.kind == TYP && owner.isLocal()); |
|
237 |
} |
|
238 |
||
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5006
diff
changeset
|
239 |
/** Has this symbol an empty name? This includes anonymous |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5006
diff
changeset
|
240 |
* inner classses. |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5006
diff
changeset
|
241 |
*/ |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5006
diff
changeset
|
242 |
public boolean isAnonymous() { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5006
diff
changeset
|
243 |
return name.isEmpty(); |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5006
diff
changeset
|
244 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5006
diff
changeset
|
245 |
|
10 | 246 |
/** Is this symbol a constructor? |
247 |
*/ |
|
248 |
public boolean isConstructor() { |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
249 |
return name == name.table.names.init; |
10 | 250 |
} |
251 |
||
252 |
/** The fully qualified name of this symbol. |
|
253 |
* This is the same as the symbol's name except for class symbols, |
|
254 |
* which are handled separately. |
|
255 |
*/ |
|
256 |
public Name getQualifiedName() { |
|
257 |
return name; |
|
258 |
} |
|
259 |
||
260 |
/** The fully qualified name of this symbol after converting to flat |
|
261 |
* representation. This is the same as the symbol's name except for |
|
262 |
* class symbols, which are handled separately. |
|
263 |
*/ |
|
264 |
public Name flatName() { |
|
265 |
return getQualifiedName(); |
|
266 |
} |
|
267 |
||
268 |
/** If this is a class or package, its members, otherwise null. |
|
269 |
*/ |
|
270 |
public Scope members() { |
|
271 |
return null; |
|
272 |
} |
|
273 |
||
274 |
/** A class is an inner class if it it has an enclosing instance class. |
|
275 |
*/ |
|
276 |
public boolean isInner() { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
277 |
return type.getEnclosingType().hasTag(CLASS); |
10 | 278 |
} |
279 |
||
280 |
/** An inner class has an outer instance if it is not an interface |
|
281 |
* it has an enclosing instance class which might be referenced from the class. |
|
282 |
* Nested classes can see instance members of their enclosing class. |
|
283 |
* Their constructors carry an additional this$n parameter, inserted |
|
284 |
* implicitly by the compiler. |
|
285 |
* |
|
286 |
* @see #isInner |
|
287 |
*/ |
|
288 |
public boolean hasOuterInstance() { |
|
289 |
return |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
290 |
type.getEnclosingType().hasTag(CLASS) && (flags() & (INTERFACE | NOOUTERTHIS)) == 0; |
10 | 291 |
} |
292 |
||
293 |
/** The closest enclosing class of this symbol's declaration. |
|
294 |
*/ |
|
295 |
public ClassSymbol enclClass() { |
|
296 |
Symbol c = this; |
|
297 |
while (c != null && |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
298 |
((c.kind & TYP) == 0 || !c.type.hasTag(CLASS))) { |
10 | 299 |
c = c.owner; |
300 |
} |
|
301 |
return (ClassSymbol)c; |
|
302 |
} |
|
303 |
||
304 |
/** The outermost class which indirectly owns this symbol. |
|
305 |
*/ |
|
306 |
public ClassSymbol outermostClass() { |
|
307 |
Symbol sym = this; |
|
308 |
Symbol prev = null; |
|
309 |
while (sym.kind != PCK) { |
|
310 |
prev = sym; |
|
311 |
sym = sym.owner; |
|
312 |
} |
|
313 |
return (ClassSymbol) prev; |
|
314 |
} |
|
315 |
||
316 |
/** The package which indirectly owns this symbol. |
|
317 |
*/ |
|
318 |
public PackageSymbol packge() { |
|
319 |
Symbol sym = this; |
|
320 |
while (sym.kind != PCK) { |
|
321 |
sym = sym.owner; |
|
322 |
} |
|
323 |
return (PackageSymbol) sym; |
|
324 |
} |
|
325 |
||
326 |
/** Is this symbol a subclass of `base'? Only defined for ClassSymbols. |
|
327 |
*/ |
|
328 |
public boolean isSubClass(Symbol base, Types types) { |
|
329 |
throw new AssertionError("isSubClass " + this); |
|
330 |
} |
|
331 |
||
332 |
/** Fully check membership: hierarchy, protection, and hiding. |
|
333 |
* Does not exclude methods not inherited due to overriding. |
|
334 |
*/ |
|
335 |
public boolean isMemberOf(TypeSymbol clazz, Types types) { |
|
336 |
return |
|
337 |
owner == clazz || |
|
338 |
clazz.isSubClass(owner, types) && |
|
339 |
isInheritedIn(clazz, types) && |
|
340 |
!hiddenIn((ClassSymbol)clazz, types); |
|
341 |
} |
|
342 |
||
343 |
/** Is this symbol the same as or enclosed by the given class? */ |
|
344 |
public boolean isEnclosedBy(ClassSymbol clazz) { |
|
345 |
for (Symbol sym = this; sym.kind != PCK; sym = sym.owner) |
|
346 |
if (sym == clazz) return true; |
|
347 |
return false; |
|
348 |
} |
|
349 |
||
350 |
/** Check for hiding. Note that this doesn't handle multiple |
|
351 |
* (interface) inheritance. */ |
|
352 |
private boolean hiddenIn(ClassSymbol clazz, Types types) { |
|
353 |
if (kind == MTH && (flags() & STATIC) == 0) return false; |
|
354 |
while (true) { |
|
355 |
if (owner == clazz) return false; |
|
356 |
Scope.Entry e = clazz.members().lookup(name); |
|
357 |
while (e.scope != null) { |
|
358 |
if (e.sym == this) return false; |
|
359 |
if (e.sym.kind == kind && |
|
360 |
(kind != MTH || |
|
361 |
(e.sym.flags() & STATIC) != 0 && |
|
362 |
types.isSubSignature(e.sym.type, type))) |
|
363 |
return true; |
|
364 |
e = e.next(); |
|
365 |
} |
|
366 |
Type superType = types.supertype(clazz.type); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
367 |
if (!superType.hasTag(CLASS)) return false; |
10 | 368 |
clazz = (ClassSymbol)superType.tsym; |
369 |
} |
|
370 |
} |
|
371 |
||
372 |
/** Is this symbol inherited into a given class? |
|
373 |
* PRE: If symbol's owner is a interface, |
|
374 |
* it is already assumed that the interface is a superinterface |
|
375 |
* of given class. |
|
376 |
* @param clazz The class for which we want to establish membership. |
|
377 |
* This must be a subclass of the member's owner. |
|
378 |
*/ |
|
379 |
public boolean isInheritedIn(Symbol clazz, Types types) { |
|
380 |
switch ((int)(flags_field & Flags.AccessFlags)) { |
|
381 |
default: // error recovery |
|
382 |
case PUBLIC: |
|
383 |
return true; |
|
384 |
case PRIVATE: |
|
385 |
return this.owner == clazz; |
|
386 |
case PROTECTED: |
|
387 |
// we model interfaces as extending Object |
|
388 |
return (clazz.flags() & INTERFACE) == 0; |
|
389 |
case 0: |
|
390 |
PackageSymbol thisPackage = this.packge(); |
|
391 |
for (Symbol sup = clazz; |
|
392 |
sup != null && sup != this.owner; |
|
393 |
sup = types.supertype(sup.type).tsym) { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
394 |
while (sup.type.hasTag(TYPEVAR)) |
1528
441d4ec466de
6711619: javac doesn't allow access to protected members in intersection types
mcimadamore
parents:
1357
diff
changeset
|
395 |
sup = sup.type.getUpperBound().tsym; |
10 | 396 |
if (sup.type.isErroneous()) |
397 |
return true; // error recovery |
|
398 |
if ((sup.flags() & COMPOUND) != 0) |
|
399 |
continue; |
|
400 |
if (sup.packge() != thisPackage) |
|
401 |
return false; |
|
402 |
} |
|
403 |
return (clazz.flags() & INTERFACE) == 0; |
|
404 |
} |
|
405 |
} |
|
406 |
||
407 |
/** The (variable or method) symbol seen as a member of given |
|
408 |
* class type`site' (this might change the symbol's type). |
|
409 |
* This is used exclusively for producing diagnostics. |
|
410 |
*/ |
|
411 |
public Symbol asMemberOf(Type site, Types types) { |
|
412 |
throw new AssertionError(); |
|
413 |
} |
|
414 |
||
415 |
/** Does this method symbol override `other' symbol, when both are seen as |
|
416 |
* members of class `origin'? It is assumed that _other is a member |
|
417 |
* of origin. |
|
418 |
* |
|
419 |
* It is assumed that both symbols have the same name. The static |
|
420 |
* modifier is ignored for this test. |
|
421 |
* |
|
422 |
* See JLS 8.4.6.1 (without transitivity) and 8.4.6.4 |
|
423 |
*/ |
|
424 |
public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) { |
|
425 |
return false; |
|
426 |
} |
|
427 |
||
428 |
/** Complete the elaboration of this symbol's definition. |
|
429 |
*/ |
|
430 |
public void complete() throws CompletionFailure { |
|
431 |
if (completer != null) { |
|
432 |
Completer c = completer; |
|
433 |
completer = null; |
|
434 |
c.complete(this); |
|
435 |
} |
|
436 |
} |
|
437 |
||
438 |
/** True if the symbol represents an entity that exists. |
|
439 |
*/ |
|
440 |
public boolean exists() { |
|
441 |
return true; |
|
442 |
} |
|
443 |
||
444 |
public Type asType() { |
|
445 |
return type; |
|
446 |
} |
|
447 |
||
448 |
public Symbol getEnclosingElement() { |
|
449 |
return owner; |
|
450 |
} |
|
451 |
||
452 |
public ElementKind getKind() { |
|
453 |
return ElementKind.OTHER; // most unkind |
|
454 |
} |
|
455 |
||
456 |
public Set<Modifier> getModifiers() { |
|
14547 | 457 |
long flags = flags(); |
458 |
return Flags.asModifierSet((flags & DEFAULT) != 0 ? flags & ~ABSTRACT : flags); |
|
10 | 459 |
} |
460 |
||
461 |
public Name getSimpleName() { |
|
462 |
return name; |
|
463 |
} |
|
464 |
||
465 |
/** |
|
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
466 |
* This is the implementation for {@code |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
467 |
* javax.lang.model.element.Element.getAnnotationMirrors()}. |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
468 |
*/ |
15355
a4757c33cae9
7193719: Support repeating annotations in javax.lang.model
jfranck
parents:
15031
diff
changeset
|
469 |
public final List<? extends AnnotationMirror> getAnnotationMirrors() { |
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
470 |
return getRawAttributes(); |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
471 |
} |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
472 |
|
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
473 |
/** |
15385 | 474 |
* TODO: Should there be a {@code |
475 |
* javax.lang.model.element.Element.getTypeAnnotationMirrors()}. |
|
476 |
*/ |
|
477 |
public final List<Attribute.TypeCompound> getTypeAnnotationMirrors() { |
|
478 |
return getRawTypeAttributes(); |
|
479 |
} |
|
480 |
||
481 |
/** |
|
10 | 482 |
* @deprecated this method should never be used by javac internally. |
483 |
*/ |
|
484 |
@Deprecated |
|
485 |
public <A extends java.lang.annotation.Annotation> A getAnnotation(Class<A> annoType) { |
|
486 |
return JavacElements.getAnnotation(this, annoType); |
|
487 |
} |
|
488 |
||
15355
a4757c33cae9
7193719: Support repeating annotations in javax.lang.model
jfranck
parents:
15031
diff
changeset
|
489 |
// This method is part of the javax.lang.model API, do not use this in javac code. |
15719
6b64cf96346b
8007279: Rename javax.l.model.element.Element.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents:
15564
diff
changeset
|
490 |
public <A extends java.lang.annotation.Annotation> A[] getAnnotationsByType(Class<A> annoType) { |
15355
a4757c33cae9
7193719: Support repeating annotations in javax.lang.model
jfranck
parents:
15031
diff
changeset
|
491 |
return JavacElements.getAnnotations(this, annoType); |
a4757c33cae9
7193719: Support repeating annotations in javax.lang.model
jfranck
parents:
15031
diff
changeset
|
492 |
} |
a4757c33cae9
7193719: Support repeating annotations in javax.lang.model
jfranck
parents:
15031
diff
changeset
|
493 |
|
10 | 494 |
// TODO: getEnclosedElements should return a javac List, fix in FilteredMemberList |
495 |
public java.util.List<Symbol> getEnclosedElements() { |
|
496 |
return List.nil(); |
|
497 |
} |
|
498 |
||
499 |
public List<TypeSymbol> getTypeParameters() { |
|
500 |
ListBuffer<TypeSymbol> l = ListBuffer.lb(); |
|
501 |
for (Type t : type.getTypeArguments()) { |
|
502 |
l.append(t.tsym); |
|
503 |
} |
|
504 |
return l.toList(); |
|
505 |
} |
|
506 |
||
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
507 |
public static class DelegatedSymbol<T extends Symbol> extends Symbol { |
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
508 |
protected T other; |
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
509 |
public DelegatedSymbol(T other) { |
10 | 510 |
super(other.kind, other.flags_field, other.name, other.type, other.owner); |
511 |
this.other = other; |
|
512 |
} |
|
513 |
public String toString() { return other.toString(); } |
|
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
514 |
public Symbol location() { return other.location(); } |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
515 |
public Symbol location(Type site, Types types) { return other.location(site, types); } |
14547 | 516 |
public Symbol baseSymbol() { return other; } |
10 | 517 |
public Type erasure(Types types) { return other.erasure(types); } |
518 |
public Type externalType(Types types) { return other.externalType(types); } |
|
519 |
public boolean isLocal() { return other.isLocal(); } |
|
520 |
public boolean isConstructor() { return other.isConstructor(); } |
|
521 |
public Name getQualifiedName() { return other.getQualifiedName(); } |
|
522 |
public Name flatName() { return other.flatName(); } |
|
523 |
public Scope members() { return other.members(); } |
|
524 |
public boolean isInner() { return other.isInner(); } |
|
525 |
public boolean hasOuterInstance() { return other.hasOuterInstance(); } |
|
526 |
public ClassSymbol enclClass() { return other.enclClass(); } |
|
527 |
public ClassSymbol outermostClass() { return other.outermostClass(); } |
|
528 |
public PackageSymbol packge() { return other.packge(); } |
|
529 |
public boolean isSubClass(Symbol base, Types types) { return other.isSubClass(base, types); } |
|
530 |
public boolean isMemberOf(TypeSymbol clazz, Types types) { return other.isMemberOf(clazz, types); } |
|
531 |
public boolean isEnclosedBy(ClassSymbol clazz) { return other.isEnclosedBy(clazz); } |
|
532 |
public boolean isInheritedIn(Symbol clazz, Types types) { return other.isInheritedIn(clazz, types); } |
|
533 |
public Symbol asMemberOf(Type site, Types types) { return other.asMemberOf(site, types); } |
|
534 |
public void complete() throws CompletionFailure { other.complete(); } |
|
535 |
||
536 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
|
537 |
return other.accept(v, p); |
|
538 |
} |
|
1357 | 539 |
|
540 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
|
541 |
return v.visitSymbol(other, p); |
|
542 |
} |
|
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
543 |
|
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
544 |
public T getUnderlyingSymbol() { |
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
545 |
return other; |
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
546 |
} |
10 | 547 |
} |
548 |
||
549 |
/** A class for type symbols. Type variables are represented by instances |
|
550 |
* of this class, classes and packages by instances of subclasses. |
|
551 |
*/ |
|
552 |
public static class TypeSymbol |
|
553 |
extends Symbol implements TypeParameterElement { |
|
554 |
// Implements TypeParameterElement because type parameters don't |
|
555 |
// have their own TypeSymbol subclass. |
|
556 |
// TODO: type parameters should have their own TypeSymbol subclass |
|
557 |
||
558 |
public TypeSymbol(long flags, Name name, Type type, Symbol owner) { |
|
559 |
super(TYP, flags, name, type, owner); |
|
560 |
} |
|
561 |
||
562 |
/** form a fully qualified name from a name and an owner |
|
563 |
*/ |
|
564 |
static public Name formFullName(Name name, Symbol owner) { |
|
565 |
if (owner == null) return name; |
|
566 |
if (((owner.kind != ERR)) && |
|
567 |
((owner.kind & (VAR | MTH)) != 0 |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
568 |
|| (owner.kind == TYP && owner.type.hasTag(TYPEVAR)) |
10 | 569 |
)) return name; |
570 |
Name prefix = owner.getQualifiedName(); |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
571 |
if (prefix == null || prefix == prefix.table.names.empty) |
10 | 572 |
return name; |
573 |
else return prefix.append('.', name); |
|
574 |
} |
|
575 |
||
576 |
/** form a fully qualified name from a name and an owner, after |
|
577 |
* converting to flat representation |
|
578 |
*/ |
|
579 |
static public Name formFlatName(Name name, Symbol owner) { |
|
580 |
if (owner == null || |
|
581 |
(owner.kind & (VAR | MTH)) != 0 |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
582 |
|| (owner.kind == TYP && owner.type.hasTag(TYPEVAR)) |
10 | 583 |
) return name; |
584 |
char sep = owner.kind == TYP ? '$' : '.'; |
|
585 |
Name prefix = owner.flatName(); |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
586 |
if (prefix == null || prefix == prefix.table.names.empty) |
10 | 587 |
return name; |
588 |
else return prefix.append(sep, name); |
|
589 |
} |
|
590 |
||
591 |
/** |
|
592 |
* A total ordering between type symbols that refines the |
|
593 |
* class inheritance graph. |
|
594 |
* |
|
595 |
* Typevariables always precede other kinds of symbols. |
|
596 |
*/ |
|
597 |
public final boolean precedes(TypeSymbol that, Types types) { |
|
598 |
if (this == that) |
|
599 |
return false; |
|
600 |
if (this.type.tag == that.type.tag) { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
601 |
if (this.type.hasTag(CLASS)) { |
10 | 602 |
return |
603 |
types.rank(that.type) < types.rank(this.type) || |
|
604 |
types.rank(that.type) == types.rank(this.type) && |
|
605 |
that.getQualifiedName().compareTo(this.getQualifiedName()) < 0; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
606 |
} else if (this.type.hasTag(TYPEVAR)) { |
10 | 607 |
return types.isSubtype(this.type, that.type); |
608 |
} |
|
609 |
} |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
610 |
return this.type.hasTag(TYPEVAR); |
10 | 611 |
} |
612 |
||
613 |
// For type params; overridden in subclasses. |
|
614 |
public ElementKind getKind() { |
|
615 |
return ElementKind.TYPE_PARAMETER; |
|
616 |
} |
|
617 |
||
618 |
public java.util.List<Symbol> getEnclosedElements() { |
|
619 |
List<Symbol> list = List.nil(); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
620 |
if (kind == TYP && type.hasTag(TYPEVAR)) { |
6584
c3d25d0ad536
6458749: TypeParameterElement.getEnclosedElements throws NPE within javac.
sundar
parents:
6148
diff
changeset
|
621 |
return list; |
c3d25d0ad536
6458749: TypeParameterElement.getEnclosedElements throws NPE within javac.
sundar
parents:
6148
diff
changeset
|
622 |
} |
10 | 623 |
for (Scope.Entry e = members().elems; e != null; e = e.sibling) { |
624 |
if (e.sym != null && (e.sym.flags() & SYNTHETIC) == 0 && e.sym.owner == this) |
|
625 |
list = list.prepend(e.sym); |
|
626 |
} |
|
627 |
return list; |
|
628 |
} |
|
629 |
||
630 |
// For type params. |
|
631 |
// Perhaps not needed if getEnclosingElement can be spec'ed |
|
632 |
// to do the same thing. |
|
633 |
// TODO: getGenericElement() might not be needed |
|
634 |
public Symbol getGenericElement() { |
|
635 |
return owner; |
|
636 |
} |
|
637 |
||
638 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
639 |
Assert.check(type.hasTag(TYPEVAR)); // else override will be invoked |
10 | 640 |
return v.visitTypeParameter(this, p); |
641 |
} |
|
642 |
||
1357 | 643 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
644 |
return v.visitTypeSymbol(this, p); |
|
645 |
} |
|
646 |
||
10 | 647 |
public List<Type> getBounds() { |
648 |
TypeVar t = (TypeVar)type; |
|
649 |
Type bound = t.getUpperBound(); |
|
650 |
if (!bound.isCompound()) |
|
651 |
return List.of(bound); |
|
652 |
ClassType ct = (ClassType)bound; |
|
653 |
if (!ct.tsym.erasure_field.isInterface()) { |
|
654 |
return ct.interfaces_field.prepend(ct.supertype_field); |
|
655 |
} else { |
|
656 |
// No superclass was given in bounds. |
|
657 |
// In this case, supertype is Object, erasure is first interface. |
|
658 |
return ct.interfaces_field; |
|
659 |
} |
|
660 |
} |
|
661 |
} |
|
662 |
||
663 |
/** A class for package symbols |
|
664 |
*/ |
|
665 |
public static class PackageSymbol extends TypeSymbol |
|
666 |
implements PackageElement { |
|
667 |
||
668 |
public Scope members_field; |
|
669 |
public Name fullname; |
|
670 |
public ClassSymbol package_info; // see bug 6443073 |
|
671 |
||
672 |
public PackageSymbol(Name name, Type type, Symbol owner) { |
|
673 |
super(0, name, type, owner); |
|
674 |
this.kind = PCK; |
|
675 |
this.members_field = null; |
|
676 |
this.fullname = formFullName(name, owner); |
|
677 |
} |
|
678 |
||
679 |
public PackageSymbol(Name name, Symbol owner) { |
|
680 |
this(name, null, owner); |
|
681 |
this.type = new PackageType(this); |
|
682 |
} |
|
683 |
||
684 |
public String toString() { |
|
685 |
return fullname.toString(); |
|
686 |
} |
|
687 |
||
688 |
public Name getQualifiedName() { |
|
689 |
return fullname; |
|
690 |
} |
|
691 |
||
692 |
public boolean isUnnamed() { |
|
693 |
return name.isEmpty() && owner != null; |
|
694 |
} |
|
695 |
||
696 |
public Scope members() { |
|
697 |
if (completer != null) complete(); |
|
698 |
return members_field; |
|
699 |
} |
|
700 |
||
701 |
public long flags() { |
|
702 |
if (completer != null) complete(); |
|
703 |
return flags_field; |
|
704 |
} |
|
705 |
||
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
706 |
@Override |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
707 |
public List<Attribute.Compound> getRawAttributes() { |
10 | 708 |
if (completer != null) complete(); |
4871
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
4077
diff
changeset
|
709 |
if (package_info != null && package_info.completer != null) { |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
4077
diff
changeset
|
710 |
package_info.complete(); |
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
711 |
mergeAttributes(); |
4871
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
4077
diff
changeset
|
712 |
} |
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
713 |
return super.getRawAttributes(); |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
714 |
} |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
715 |
|
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
716 |
private void mergeAttributes() { |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
717 |
if (annotations.isEmpty() && |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
718 |
!package_info.annotations.isEmpty()) { |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
719 |
annotations.setAttributes(package_info.annotations); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12335
diff
changeset
|
720 |
} |
10 | 721 |
} |
722 |
||
723 |
/** A package "exists" if a type or package that exists has |
|
724 |
* been seen within it. |
|
725 |
*/ |
|
726 |
public boolean exists() { |
|
727 |
return (flags_field & EXISTS) != 0; |
|
728 |
} |
|
729 |
||
730 |
public ElementKind getKind() { |
|
731 |
return ElementKind.PACKAGE; |
|
732 |
} |
|
733 |
||
734 |
public Symbol getEnclosingElement() { |
|
735 |
return null; |
|
736 |
} |
|
737 |
||
738 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
|
739 |
return v.visitPackage(this, p); |
|
740 |
} |
|
1357 | 741 |
|
742 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
|
743 |
return v.visitPackageSymbol(this, p); |
|
744 |
} |
|
10 | 745 |
} |
746 |
||
747 |
/** A class for class symbols |
|
748 |
*/ |
|
749 |
public static class ClassSymbol extends TypeSymbol implements TypeElement { |
|
750 |
||
751 |
/** a scope for all class members; variables, methods and inner classes |
|
752 |
* type parameters are not part of this scope |
|
753 |
*/ |
|
754 |
public Scope members_field; |
|
755 |
||
756 |
/** the fully qualified name of the class, i.e. pck.outer.inner. |
|
757 |
* null for anonymous classes |
|
758 |
*/ |
|
759 |
public Name fullname; |
|
760 |
||
761 |
/** the fully qualified name of the class after converting to flat |
|
762 |
* representation, i.e. pck.outer$inner, |
|
763 |
* set externally for local and anonymous classes |
|
764 |
*/ |
|
765 |
public Name flatname; |
|
766 |
||
767 |
/** the sourcefile where the class came from |
|
768 |
*/ |
|
769 |
public JavaFileObject sourcefile; |
|
770 |
||
771 |
/** the classfile from where to load this class |
|
772 |
* this will have extension .class or .java |
|
773 |
*/ |
|
774 |
public JavaFileObject classfile; |
|
775 |
||
10627
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
10626
diff
changeset
|
776 |
/** the list of translated local classes (used for generating |
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
10626
diff
changeset
|
777 |
* InnerClasses attribute) |
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
10626
diff
changeset
|
778 |
*/ |
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
10626
diff
changeset
|
779 |
public List<ClassSymbol> trans_local; |
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
10626
diff
changeset
|
780 |
|
10 | 781 |
/** the constant pool of the class |
782 |
*/ |
|
783 |
public Pool pool; |
|
784 |
||
785 |
public ClassSymbol(long flags, Name name, Type type, Symbol owner) { |
|
786 |
super(flags, name, type, owner); |
|
787 |
this.members_field = null; |
|
788 |
this.fullname = formFullName(name, owner); |
|
789 |
this.flatname = formFlatName(name, owner); |
|
790 |
this.sourcefile = null; |
|
791 |
this.classfile = null; |
|
792 |
this.pool = null; |
|
793 |
} |
|
794 |
||
795 |
public ClassSymbol(long flags, Name name, Symbol owner) { |
|
796 |
this( |
|
797 |
flags, |
|
798 |
name, |
|
799 |
new ClassType(Type.noType, null, null), |
|
800 |
owner); |
|
801 |
this.type.tsym = this; |
|
802 |
} |
|
803 |
||
804 |
/** The Java source which this symbol represents. |
|
805 |
*/ |
|
806 |
public String toString() { |
|
807 |
return className(); |
|
808 |
} |
|
809 |
||
810 |
public long flags() { |
|
811 |
if (completer != null) complete(); |
|
812 |
return flags_field; |
|
813 |
} |
|
814 |
||
815 |
public Scope members() { |
|
816 |
if (completer != null) complete(); |
|
817 |
return members_field; |
|
818 |
} |
|
819 |
||
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
820 |
@Override |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
821 |
public List<Attribute.Compound> getRawAttributes() { |
10 | 822 |
if (completer != null) complete(); |
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
823 |
return super.getRawAttributes(); |
10 | 824 |
} |
825 |
||
15385 | 826 |
@Override |
827 |
public List<Attribute.TypeCompound> getRawTypeAttributes() { |
|
828 |
if (completer != null) complete(); |
|
829 |
return super.getRawTypeAttributes(); |
|
830 |
} |
|
831 |
||
10 | 832 |
public Type erasure(Types types) { |
833 |
if (erasure_field == null) |
|
834 |
erasure_field = new ClassType(types.erasure(type.getEnclosingType()), |
|
835 |
List.<Type>nil(), this); |
|
836 |
return erasure_field; |
|
837 |
} |
|
838 |
||
839 |
public String className() { |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
840 |
if (name.isEmpty()) |
10 | 841 |
return |
842 |
Log.getLocalizedString("anonymous.class", flatname); |
|
843 |
else |
|
844 |
return fullname.toString(); |
|
845 |
} |
|
846 |
||
847 |
public Name getQualifiedName() { |
|
848 |
return fullname; |
|
849 |
} |
|
850 |
||
851 |
public Name flatName() { |
|
852 |
return flatname; |
|
853 |
} |
|
854 |
||
855 |
public boolean isSubClass(Symbol base, Types types) { |
|
856 |
if (this == base) { |
|
857 |
return true; |
|
858 |
} else if ((base.flags() & INTERFACE) != 0) { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
859 |
for (Type t = type; t.hasTag(CLASS); t = types.supertype(t)) |
10 | 860 |
for (List<Type> is = types.interfaces(t); |
861 |
is.nonEmpty(); |
|
862 |
is = is.tail) |
|
863 |
if (is.head.tsym.isSubClass(base, types)) return true; |
|
864 |
} else { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
865 |
for (Type t = type; t.hasTag(CLASS); t = types.supertype(t)) |
10 | 866 |
if (t.tsym == base) return true; |
867 |
} |
|
868 |
return false; |
|
869 |
} |
|
870 |
||
871 |
/** Complete the elaboration of this symbol's definition. |
|
872 |
*/ |
|
873 |
public void complete() throws CompletionFailure { |
|
874 |
try { |
|
875 |
super.complete(); |
|
876 |
} catch (CompletionFailure ex) { |
|
877 |
// quiet error recovery |
|
878 |
flags_field |= (PUBLIC|STATIC); |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
879 |
this.type = new ErrorType(this, Type.noType); |
10 | 880 |
throw ex; |
881 |
} |
|
882 |
} |
|
883 |
||
884 |
public List<Type> getInterfaces() { |
|
885 |
complete(); |
|
886 |
if (type instanceof ClassType) { |
|
887 |
ClassType t = (ClassType)type; |
|
888 |
if (t.interfaces_field == null) // FIXME: shouldn't be null |
|
889 |
t.interfaces_field = List.nil(); |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8427
diff
changeset
|
890 |
if (t.all_interfaces_field != null) |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8427
diff
changeset
|
891 |
return Type.getModelTypes(t.all_interfaces_field); |
10 | 892 |
return t.interfaces_field; |
893 |
} else { |
|
894 |
return List.nil(); |
|
895 |
} |
|
896 |
} |
|
897 |
||
898 |
public Type getSuperclass() { |
|
899 |
complete(); |
|
900 |
if (type instanceof ClassType) { |
|
901 |
ClassType t = (ClassType)type; |
|
902 |
if (t.supertype_field == null) // FIXME: shouldn't be null |
|
903 |
t.supertype_field = Type.noType; |
|
904 |
// An interface has no superclass; its supertype is Object. |
|
905 |
return t.isInterface() |
|
906 |
? Type.noType |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8427
diff
changeset
|
907 |
: t.supertype_field.getModelType(); |
10 | 908 |
} else { |
909 |
return Type.noType; |
|
910 |
} |
|
911 |
} |
|
912 |
||
913 |
public ElementKind getKind() { |
|
914 |
long flags = flags(); |
|
915 |
if ((flags & ANNOTATION) != 0) |
|
916 |
return ElementKind.ANNOTATION_TYPE; |
|
917 |
else if ((flags & INTERFACE) != 0) |
|
918 |
return ElementKind.INTERFACE; |
|
919 |
else if ((flags & ENUM) != 0) |
|
920 |
return ElementKind.ENUM; |
|
921 |
else |
|
922 |
return ElementKind.CLASS; |
|
923 |
} |
|
924 |
||
925 |
public NestingKind getNestingKind() { |
|
926 |
complete(); |
|
927 |
if (owner.kind == PCK) |
|
928 |
return NestingKind.TOP_LEVEL; |
|
929 |
else if (name.isEmpty()) |
|
930 |
return NestingKind.ANONYMOUS; |
|
931 |
else if (owner.kind == MTH) |
|
932 |
return NestingKind.LOCAL; |
|
933 |
else |
|
934 |
return NestingKind.MEMBER; |
|
935 |
} |
|
936 |
||
937 |
/** |
|
938 |
* @deprecated this method should never be used by javac internally. |
|
939 |
*/ |
|
940 |
@Override @Deprecated |
|
941 |
public <A extends java.lang.annotation.Annotation> A getAnnotation(Class<A> annoType) { |
|
942 |
return JavacElements.getAnnotation(this, annoType); |
|
943 |
} |
|
944 |
||
945 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
|
946 |
return v.visitType(this, p); |
|
947 |
} |
|
1357 | 948 |
|
949 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
|
950 |
return v.visitClassSymbol(this, p); |
|
951 |
} |
|
10 | 952 |
} |
953 |
||
954 |
||
955 |
/** A class for variable symbols |
|
956 |
*/ |
|
957 |
public static class VarSymbol extends Symbol implements VariableElement { |
|
958 |
||
959 |
/** The variable's declaration position. |
|
960 |
*/ |
|
961 |
public int pos = Position.NOPOS; |
|
962 |
||
963 |
/** The variable's address. Used for different purposes during |
|
964 |
* flow analysis, translation and code generation. |
|
965 |
* Flow analysis: |
|
966 |
* If this is a blank final or local variable, its sequence number. |
|
967 |
* Translation: |
|
968 |
* If this is a private field, its access number. |
|
969 |
* Code generation: |
|
970 |
* If this is a local variable, its logical slot number. |
|
971 |
*/ |
|
972 |
public int adr = -1; |
|
973 |
||
974 |
/** Construct a variable symbol, given its flags, name, type and owner. |
|
975 |
*/ |
|
976 |
public VarSymbol(long flags, Name name, Type type, Symbol owner) { |
|
977 |
super(VAR, flags, name, type, owner); |
|
978 |
} |
|
979 |
||
980 |
/** Clone this symbol with new owner. |
|
981 |
*/ |
|
982 |
public VarSymbol clone(Symbol newOwner) { |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
983 |
VarSymbol v = new VarSymbol(flags_field, name, type, newOwner) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
984 |
@Override |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
985 |
public Symbol baseSymbol() { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
986 |
return VarSymbol.this; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
987 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
988 |
}; |
10 | 989 |
v.pos = pos; |
990 |
v.adr = adr; |
|
991 |
v.data = data; |
|
992 |
// System.out.println("clone " + v + " in " + newOwner);//DEBUG |
|
993 |
return v; |
|
994 |
} |
|
995 |
||
996 |
public String toString() { |
|
997 |
return name.toString(); |
|
998 |
} |
|
999 |
||
1000 |
public Symbol asMemberOf(Type site, Types types) { |
|
1001 |
return new VarSymbol(flags_field, name, types.memberType(site, this), owner); |
|
1002 |
} |
|
1003 |
||
1004 |
public ElementKind getKind() { |
|
1005 |
long flags = flags(); |
|
1006 |
if ((flags & PARAMETER) != 0) { |
|
1007 |
if (isExceptionParameter()) |
|
1008 |
return ElementKind.EXCEPTION_PARAMETER; |
|
1009 |
else |
|
1010 |
return ElementKind.PARAMETER; |
|
1011 |
} else if ((flags & ENUM) != 0) { |
|
1012 |
return ElementKind.ENUM_CONSTANT; |
|
1013 |
} else if (owner.kind == TYP || owner.kind == ERR) { |
|
1014 |
return ElementKind.FIELD; |
|
6718
56ed1962d369
6967842: Element not returned from tree API for ARM resource variables.
sundar
parents:
6592
diff
changeset
|
1015 |
} else if (isResourceVariable()) { |
56ed1962d369
6967842: Element not returned from tree API for ARM resource variables.
sundar
parents:
6592
diff
changeset
|
1016 |
return ElementKind.RESOURCE_VARIABLE; |
10 | 1017 |
} else { |
1018 |
return ElementKind.LOCAL_VARIABLE; |
|
1019 |
} |
|
1020 |
} |
|
1021 |
||
1022 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
|
1023 |
return v.visitVariable(this, p); |
|
1024 |
} |
|
1025 |
||
1026 |
public Object getConstantValue() { // Mirror API |
|
1027 |
return Constants.decode(getConstValue(), type); |
|
1028 |
} |
|
1029 |
||
1030 |
public void setLazyConstValue(final Env<AttrContext> env, |
|
1031 |
final Attr attr, |
|
1032 |
final JCTree.JCExpression initializer) |
|
1033 |
{ |
|
1034 |
setData(new Callable<Object>() { |
|
1035 |
public Object call() { |
|
8225 | 1036 |
return attr.attribLazyConstantValue(env, initializer, type); |
10 | 1037 |
} |
1038 |
}); |
|
1039 |
} |
|
1040 |
||
1041 |
/** |
|
1042 |
* The variable's constant value, if this is a constant. |
|
1043 |
* Before the constant value is evaluated, it points to an |
|
1044 |
* initalizer environment. If this is not a constant, it can |
|
1045 |
* be used for other stuff. |
|
1046 |
*/ |
|
1047 |
private Object data; |
|
1048 |
||
1049 |
public boolean isExceptionParameter() { |
|
1050 |
return data == ElementKind.EXCEPTION_PARAMETER; |
|
1051 |
} |
|
1052 |
||
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
1053 |
public boolean isResourceVariable() { |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
1054 |
return data == ElementKind.RESOURCE_VARIABLE; |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
1055 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
1056 |
|
10 | 1057 |
public Object getConstValue() { |
1058 |
// TODO: Consider if getConstValue and getConstantValue can be collapsed |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
1059 |
if (data == ElementKind.EXCEPTION_PARAMETER || |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
1060 |
data == ElementKind.RESOURCE_VARIABLE) { |
10 | 1061 |
return null; |
1062 |
} else if (data instanceof Callable<?>) { |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
1063 |
// In this case, this is a final variable, with an as |
10 | 1064 |
// yet unevaluated initializer. |
1065 |
Callable<?> eval = (Callable<?>)data; |
|
1066 |
data = null; // to make sure we don't evaluate this twice. |
|
1067 |
try { |
|
1068 |
data = eval.call(); |
|
1069 |
} catch (Exception ex) { |
|
1070 |
throw new AssertionError(ex); |
|
1071 |
} |
|
1072 |
} |
|
1073 |
return data; |
|
1074 |
} |
|
1075 |
||
1076 |
public void setData(Object data) { |
|
8032 | 1077 |
Assert.check(!(data instanceof Env<?>), this); |
10 | 1078 |
this.data = data; |
1079 |
} |
|
1357 | 1080 |
|
1081 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
|
1082 |
return v.visitVarSymbol(this, p); |
|
1083 |
} |
|
10 | 1084 |
} |
1085 |
||
1086 |
/** A class for method symbols. |
|
1087 |
*/ |
|
1088 |
public static class MethodSymbol extends Symbol implements ExecutableElement { |
|
1089 |
||
1090 |
/** The code of the method. */ |
|
1091 |
public Code code = null; |
|
1092 |
||
15720
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
1093 |
/** The extra (synthetic/mandated) parameters of the method. */ |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
1094 |
public List<VarSymbol> extraParams = List.nil(); |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
1095 |
|
10 | 1096 |
/** The parameters of the method. */ |
1097 |
public List<VarSymbol> params = null; |
|
1098 |
||
1099 |
/** The names of the parameters */ |
|
1100 |
public List<Name> savedParameterNames; |
|
1101 |
||
1102 |
/** For an attribute field accessor, its default value if any. |
|
1103 |
* The value is null if none appeared in the method |
|
1104 |
* declaration. |
|
1105 |
*/ |
|
1106 |
public Attribute defaultValue = null; |
|
1107 |
||
1108 |
/** Construct a method symbol, given its flags, name, type and owner. |
|
1109 |
*/ |
|
1110 |
public MethodSymbol(long flags, Name name, Type type, Symbol owner) { |
|
1111 |
super(MTH, flags, name, type, owner); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
1112 |
if (owner.type.hasTag(TYPEVAR)) Assert.error(owner + "." + name); |
10 | 1113 |
} |
1114 |
||
1115 |
/** Clone this symbol with new owner. |
|
1116 |
*/ |
|
1117 |
public MethodSymbol clone(Symbol newOwner) { |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1118 |
MethodSymbol m = new MethodSymbol(flags_field, name, type, newOwner) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1119 |
@Override |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1120 |
public Symbol baseSymbol() { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1121 |
return MethodSymbol.this; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1122 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1123 |
}; |
10 | 1124 |
m.code = code; |
1125 |
return m; |
|
1126 |
} |
|
1127 |
||
1128 |
/** The Java source which this symbol represents. |
|
1129 |
*/ |
|
1130 |
public String toString() { |
|
1131 |
if ((flags() & BLOCK) != 0) { |
|
1132 |
return owner.name.toString(); |
|
1133 |
} else { |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
1134 |
String s = (name == name.table.names.init) |
10 | 1135 |
? owner.name.toString() |
1136 |
: name.toString(); |
|
1137 |
if (type != null) { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
1138 |
if (type.hasTag(FORALL)) |
10 | 1139 |
s = "<" + ((ForAll)type).getTypeArguments() + ">" + s; |
1140 |
s += "(" + type.argtypes((flags() & VARARGS) != 0) + ")"; |
|
1141 |
} |
|
1142 |
return s; |
|
1143 |
} |
|
1144 |
} |
|
1145 |
||
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1146 |
public boolean isDynamic() { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1147 |
return false; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1148 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1149 |
|
10 | 1150 |
/** find a symbol that this (proxy method) symbol implements. |
1151 |
* @param c The class whose members are searched for |
|
1152 |
* implementations |
|
1153 |
*/ |
|
1154 |
public Symbol implemented(TypeSymbol c, Types types) { |
|
1155 |
Symbol impl = null; |
|
1156 |
for (List<Type> is = types.interfaces(c.type); |
|
1157 |
impl == null && is.nonEmpty(); |
|
1158 |
is = is.tail) { |
|
1159 |
TypeSymbol i = is.head.tsym; |
|
7628
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1160 |
impl = implementedIn(i, types); |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1161 |
if (impl == null) |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1162 |
impl = implemented(i, types); |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1163 |
} |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1164 |
return impl; |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1165 |
} |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1166 |
|
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1167 |
public Symbol implementedIn(TypeSymbol c, Types types) { |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1168 |
Symbol impl = null; |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1169 |
for (Scope.Entry e = c.members().lookup(name); |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1170 |
impl == null && e.scope != null; |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1171 |
e = e.next()) { |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1172 |
if (this.overrides(e.sym, (TypeSymbol)owner, types, true) && |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1173 |
// FIXME: I suspect the following requires a |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1174 |
// subst() for a parametric return type. |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1175 |
types.isSameType(type.getReturnType(), |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1176 |
types.memberType(owner.type, e.sym).getReturnType())) { |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1177 |
impl = e.sym; |
10 | 1178 |
} |
1179 |
} |
|
1180 |
return impl; |
|
1181 |
} |
|
1182 |
||
1183 |
/** Will the erasure of this method be considered by the VM to |
|
1184 |
* override the erasure of the other when seen from class `origin'? |
|
1185 |
*/ |
|
1186 |
public boolean binaryOverrides(Symbol _other, TypeSymbol origin, Types types) { |
|
1187 |
if (isConstructor() || _other.kind != MTH) return false; |
|
1188 |
||
1189 |
if (this == _other) return true; |
|
1190 |
MethodSymbol other = (MethodSymbol)_other; |
|
1191 |
||
1192 |
// check for a direct implementation |
|
1193 |
if (other.isOverridableIn((TypeSymbol)owner) && |
|
1194 |
types.asSuper(owner.type, other.owner) != null && |
|
1195 |
types.isSameType(erasure(types), other.erasure(types))) |
|
1196 |
return true; |
|
1197 |
||
1198 |
// check for an inherited implementation |
|
1199 |
return |
|
1200 |
(flags() & ABSTRACT) == 0 && |
|
1201 |
other.isOverridableIn(origin) && |
|
1202 |
this.isMemberOf(origin, types) && |
|
1203 |
types.isSameType(erasure(types), other.erasure(types)); |
|
1204 |
} |
|
1205 |
||
1206 |
/** The implementation of this (abstract) symbol in class origin, |
|
1207 |
* from the VM's point of view, null if method does not have an |
|
1208 |
* implementation in class. |
|
1209 |
* @param origin The class of which the implementation is a member. |
|
1210 |
*/ |
|
1211 |
public MethodSymbol binaryImplementation(ClassSymbol origin, Types types) { |
|
1212 |
for (TypeSymbol c = origin; c != null; c = types.supertype(c.type).tsym) { |
|
1213 |
for (Scope.Entry e = c.members().lookup(name); |
|
1214 |
e.scope != null; |
|
1215 |
e = e.next()) { |
|
1216 |
if (e.sym.kind == MTH && |
|
1217 |
((MethodSymbol)e.sym).binaryOverrides(this, origin, types)) |
|
1218 |
return (MethodSymbol)e.sym; |
|
1219 |
} |
|
1220 |
} |
|
1221 |
return null; |
|
1222 |
} |
|
1223 |
||
1224 |
/** Does this symbol override `other' symbol, when both are seen as |
|
1225 |
* members of class `origin'? It is assumed that _other is a member |
|
1226 |
* of origin. |
|
1227 |
* |
|
1228 |
* It is assumed that both symbols have the same name. The static |
|
1229 |
* modifier is ignored for this test. |
|
1230 |
* |
|
1231 |
* See JLS 8.4.6.1 (without transitivity) and 8.4.6.4 |
|
1232 |
*/ |
|
1233 |
public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) { |
|
1234 |
if (isConstructor() || _other.kind != MTH) return false; |
|
1235 |
||
1236 |
if (this == _other) return true; |
|
1237 |
MethodSymbol other = (MethodSymbol)_other; |
|
1238 |
||
1239 |
// check for a direct implementation |
|
1240 |
if (other.isOverridableIn((TypeSymbol)owner) && |
|
1241 |
types.asSuper(owner.type, other.owner) != null) { |
|
1242 |
Type mt = types.memberType(owner.type, this); |
|
1243 |
Type ot = types.memberType(owner.type, other); |
|
1244 |
if (types.isSubSignature(mt, ot)) { |
|
1245 |
if (!checkResult) |
|
1246 |
return true; |
|
1247 |
if (types.returnTypeSubstitutable(mt, ot)) |
|
1248 |
return true; |
|
1249 |
} |
|
1250 |
} |
|
1251 |
||
1252 |
// check for an inherited implementation |
|
1253 |
if ((flags() & ABSTRACT) != 0 || |
|
14547 | 1254 |
((other.flags() & ABSTRACT) == 0 && (other.flags() & DEFAULT) == 0) || |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1255 |
!other.isOverridableIn(origin) || |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1256 |
!this.isMemberOf(origin, types)) |
10 | 1257 |
return false; |
1258 |
||
1259 |
// assert types.asSuper(origin.type, other.owner) != null; |
|
1260 |
Type mt = types.memberType(origin.type, this); |
|
1261 |
Type ot = types.memberType(origin.type, other); |
|
1262 |
return |
|
1263 |
types.isSubSignature(mt, ot) && |
|
14547 | 1264 |
(!checkResult || types.resultSubtype(mt, ot, types.noWarnings)); |
10 | 1265 |
} |
1266 |
||
1267 |
private boolean isOverridableIn(TypeSymbol origin) { |
|
9303
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
8625
diff
changeset
|
1268 |
// JLS 8.4.6.1 |
10 | 1269 |
switch ((int)(flags_field & Flags.AccessFlags)) { |
1270 |
case Flags.PRIVATE: |
|
1271 |
return false; |
|
1272 |
case Flags.PUBLIC: |
|
15377
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1273 |
return !this.owner.isInterface() || |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1274 |
(flags_field & STATIC) == 0; |
10 | 1275 |
case Flags.PROTECTED: |
1276 |
return (origin.flags() & INTERFACE) == 0; |
|
1277 |
case 0: |
|
1278 |
// for package private: can only override in the same |
|
1279 |
// package |
|
1280 |
return |
|
1281 |
this.packge() == origin.packge() && |
|
1282 |
(origin.flags() & INTERFACE) == 0; |
|
1283 |
default: |
|
1284 |
return false; |
|
1285 |
} |
|
1286 |
} |
|
1287 |
||
15377
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1288 |
@Override |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1289 |
public boolean isInheritedIn(Symbol clazz, Types types) { |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1290 |
switch ((int)(flags_field & Flags.AccessFlags)) { |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1291 |
case PUBLIC: |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1292 |
return !this.owner.isInterface() || |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1293 |
clazz == owner || |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1294 |
(flags_field & STATIC) == 0; |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1295 |
default: |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1296 |
return super.isInheritedIn(clazz, types); |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1297 |
} |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1298 |
} |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1299 |
|
10 | 1300 |
/** The implementation of this (abstract) symbol in class origin; |
1301 |
* null if none exists. Synthetic methods are not considered |
|
1302 |
* as possible implementations. |
|
1303 |
*/ |
|
1304 |
public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) { |
|
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1305 |
return implementation(origin, types, checkResult, implementation_filter); |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1306 |
} |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1307 |
// where |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1308 |
private static final Filter<Symbol> implementation_filter = new Filter<Symbol>() { |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1309 |
public boolean accepts(Symbol s) { |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1310 |
return s.kind == Kinds.MTH && |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1311 |
(s.flags() & SYNTHETIC) == 0; |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1312 |
} |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1313 |
}; |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1314 |
|
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1315 |
public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult, Filter<Symbol> implFilter) { |
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8225
diff
changeset
|
1316 |
MethodSymbol res = types.implementation(this, origin, checkResult, implFilter); |
3539
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3149
diff
changeset
|
1317 |
if (res != null) |
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3149
diff
changeset
|
1318 |
return res; |
10 | 1319 |
// if origin is derived from a raw type, we might have missed |
1320 |
// an implementation because we do not know enough about instantiations. |
|
1321 |
// in this case continue with the supertype as origin. |
|
12083
c9d98f7e59e8
7148556: Implementing a generic interface causes a public clone() to become inaccessible
mcimadamore
parents:
10627
diff
changeset
|
1322 |
if (types.isDerivedRaw(origin.type) && !origin.isInterface()) |
10 | 1323 |
return implementation(types.supertype(origin.type).tsym, types, checkResult); |
1324 |
else |
|
1325 |
return null; |
|
1326 |
} |
|
1327 |
||
1328 |
public List<VarSymbol> params() { |
|
1329 |
owner.complete(); |
|
1330 |
if (params == null) { |
|
4077
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1331 |
// If ClassReader.saveParameterNames has been set true, then |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1332 |
// savedParameterNames will be set to a list of names that |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1333 |
// matches the types in type.getParameterTypes(). If any names |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1334 |
// were not found in the class file, those names in the list will |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1335 |
// be set to the empty name. |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1336 |
// If ClassReader.saveParameterNames has been set false, then |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1337 |
// savedParameterNames will be null. |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1338 |
List<Name> paramNames = savedParameterNames; |
10 | 1339 |
savedParameterNames = null; |
4077
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1340 |
// discard the provided names if the list of names is the wrong size. |
15031
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14961
diff
changeset
|
1341 |
if (paramNames == null || paramNames.size() != type.getParameterTypes().size()) { |
4077
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1342 |
paramNames = List.nil(); |
15031
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14961
diff
changeset
|
1343 |
} |
10 | 1344 |
ListBuffer<VarSymbol> buf = new ListBuffer<VarSymbol>(); |
4077
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1345 |
List<Name> remaining = paramNames; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1346 |
// assert: remaining and paramNames are both empty or both |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1347 |
// have same cardinality as type.getParameterTypes() |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1348 |
int i = 0; |
10 | 1349 |
for (Type t : type.getParameterTypes()) { |
4077
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1350 |
Name paramName; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1351 |
if (remaining.isEmpty()) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1352 |
// no names for any parameters available |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1353 |
paramName = createArgName(i, paramNames); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1354 |
} else { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1355 |
paramName = remaining.head; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1356 |
remaining = remaining.tail; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1357 |
if (paramName.isEmpty()) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1358 |
// no name for this specific parameter |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1359 |
paramName = createArgName(i, paramNames); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1360 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1361 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1362 |
buf.append(new VarSymbol(PARAMETER, paramName, t, this)); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1363 |
i++; |
10 | 1364 |
} |
1365 |
params = buf.toList(); |
|
1366 |
} |
|
1367 |
return params; |
|
1368 |
} |
|
1369 |
||
4077
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1370 |
// Create a name for the argument at position 'index' that is not in |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1371 |
// the exclude list. In normal use, either no names will have been |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1372 |
// provided, in which case the exclude list is empty, or all the names |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1373 |
// will have been provided, in which case this method will not be called. |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1374 |
private Name createArgName(int index, List<Name> exclude) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1375 |
String prefix = "arg"; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1376 |
while (true) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1377 |
Name argName = name.table.fromString(prefix + index); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1378 |
if (!exclude.contains(argName)) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1379 |
return argName; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1380 |
prefix += "$"; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1381 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1382 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1383 |
|
10 | 1384 |
public Symbol asMemberOf(Type site, Types types) { |
1385 |
return new MethodSymbol(flags_field, name, types.memberType(site, this), owner); |
|
1386 |
} |
|
1387 |
||
1388 |
public ElementKind getKind() { |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
1389 |
if (name == name.table.names.init) |
10 | 1390 |
return ElementKind.CONSTRUCTOR; |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
1391 |
else if (name == name.table.names.clinit) |
10 | 1392 |
return ElementKind.STATIC_INIT; |
10626
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
1393 |
else if ((flags() & BLOCK) != 0) |
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
1394 |
return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT; |
10 | 1395 |
else |
1396 |
return ElementKind.METHOD; |
|
1397 |
} |
|
1398 |
||
10626
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
1399 |
public boolean isStaticOrInstanceInit() { |
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
1400 |
return getKind() == ElementKind.STATIC_INIT || |
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
1401 |
getKind() == ElementKind.INSTANCE_INIT; |
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
1402 |
} |
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
1403 |
|
12335
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12083
diff
changeset
|
1404 |
/** |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12083
diff
changeset
|
1405 |
* A polymorphic signature method (JLS SE 7, 8.4.1) is a method that |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12083
diff
changeset
|
1406 |
* (i) is declared in the java.lang.invoke.MethodHandle class, (ii) takes |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12083
diff
changeset
|
1407 |
* a single variable arity parameter (iii) whose declared type is Object[], |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12083
diff
changeset
|
1408 |
* (iv) has a return type of Object and (v) is native. |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12083
diff
changeset
|
1409 |
*/ |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12083
diff
changeset
|
1410 |
public boolean isSignaturePolymorphic(Types types) { |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12083
diff
changeset
|
1411 |
List<Type> argtypes = type.getParameterTypes(); |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12083
diff
changeset
|
1412 |
Type firstElemType = argtypes.nonEmpty() ? |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12083
diff
changeset
|
1413 |
types.elemtype(argtypes.head) : |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12083
diff
changeset
|
1414 |
null; |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12083
diff
changeset
|
1415 |
return owner == types.syms.methodHandleType.tsym && |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12083
diff
changeset
|
1416 |
argtypes.length() == 1 && |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12083
diff
changeset
|
1417 |
firstElemType != null && |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12083
diff
changeset
|
1418 |
types.isSameType(firstElemType, types.syms.objectType) && |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12083
diff
changeset
|
1419 |
types.isSameType(type.getReturnType(), types.syms.objectType) && |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12083
diff
changeset
|
1420 |
(flags() & NATIVE) != 0; |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12083
diff
changeset
|
1421 |
} |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12083
diff
changeset
|
1422 |
|
10 | 1423 |
public Attribute getDefaultValue() { |
1424 |
return defaultValue; |
|
1425 |
} |
|
1426 |
||
15385 | 1427 |
public List<VarSymbol> getParameters() { |
10 | 1428 |
return params(); |
1429 |
} |
|
1430 |
||
1431 |
public boolean isVarArgs() { |
|
1432 |
return (flags() & VARARGS) != 0; |
|
1433 |
} |
|
1434 |
||
14956
185bd7c693d8
8005046: Provide checking for a default method in javax.lang.model
darcy
parents:
14547
diff
changeset
|
1435 |
public boolean isDefault() { |
185bd7c693d8
8005046: Provide checking for a default method in javax.lang.model
darcy
parents:
14547
diff
changeset
|
1436 |
return (flags() & DEFAULT) != 0; |
185bd7c693d8
8005046: Provide checking for a default method in javax.lang.model
darcy
parents:
14547
diff
changeset
|
1437 |
} |
185bd7c693d8
8005046: Provide checking for a default method in javax.lang.model
darcy
parents:
14547
diff
changeset
|
1438 |
|
10 | 1439 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
1440 |
return v.visitExecutable(this, p); |
|
1441 |
} |
|
1442 |
||
1357 | 1443 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
1444 |
return v.visitMethodSymbol(this, p); |
|
1445 |
} |
|
1446 |
||
10 | 1447 |
public Type getReturnType() { |
1448 |
return asType().getReturnType(); |
|
1449 |
} |
|
1450 |
||
1451 |
public List<Type> getThrownTypes() { |
|
1452 |
return asType().getThrownTypes(); |
|
1453 |
} |
|
1454 |
} |
|
1455 |
||
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1456 |
/** A class for invokedynamic method calls. |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1457 |
*/ |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1458 |
public static class DynamicMethodSymbol extends MethodSymbol { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1459 |
|
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1460 |
public Object[] staticArgs; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1461 |
public Symbol bsm; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1462 |
public int bsmKind; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1463 |
|
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1464 |
public DynamicMethodSymbol(Name name, Symbol owner, int bsmKind, MethodSymbol bsm, Type type, Object[] staticArgs) { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1465 |
super(0, name, type, owner); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1466 |
this.bsm = bsm; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1467 |
this.bsmKind = bsmKind; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1468 |
this.staticArgs = staticArgs; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1469 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1470 |
|
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1471 |
@Override |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1472 |
public boolean isDynamic() { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1473 |
return true; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1474 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1475 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1476 |
|
10 | 1477 |
/** A class for predefined operators. |
1478 |
*/ |
|
1479 |
public static class OperatorSymbol extends MethodSymbol { |
|
1480 |
||
1481 |
public int opcode; |
|
1482 |
||
1483 |
public OperatorSymbol(Name name, Type type, int opcode, Symbol owner) { |
|
1484 |
super(PUBLIC | STATIC, name, type, owner); |
|
1485 |
this.opcode = opcode; |
|
1486 |
} |
|
1357 | 1487 |
|
1488 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
|
1489 |
return v.visitOperatorSymbol(this, p); |
|
1490 |
} |
|
10 | 1491 |
} |
1492 |
||
1493 |
/** Symbol completer interface. |
|
1494 |
*/ |
|
1495 |
public static interface Completer { |
|
1496 |
void complete(Symbol sym) throws CompletionFailure; |
|
1497 |
} |
|
1498 |
||
1499 |
public static class CompletionFailure extends RuntimeException { |
|
1500 |
private static final long serialVersionUID = 0; |
|
1501 |
public Symbol sym; |
|
1502 |
||
169 | 1503 |
/** A diagnostic object describing the failure |
1504 |
*/ |
|
1505 |
public JCDiagnostic diag; |
|
1506 |
||
10 | 1507 |
/** A localized string describing the failure. |
169 | 1508 |
* @deprecated Use {@code getDetail()} or {@code getMessage()} |
10 | 1509 |
*/ |
169 | 1510 |
@Deprecated |
10 | 1511 |
public String errmsg; |
1512 |
||
1513 |
public CompletionFailure(Symbol sym, String errmsg) { |
|
1514 |
this.sym = sym; |
|
1515 |
this.errmsg = errmsg; |
|
1516 |
// this.printStackTrace();//DEBUG |
|
1517 |
} |
|
1518 |
||
169 | 1519 |
public CompletionFailure(Symbol sym, JCDiagnostic diag) { |
1520 |
this.sym = sym; |
|
1521 |
this.diag = diag; |
|
1522 |
// this.printStackTrace();//DEBUG |
|
1523 |
} |
|
1524 |
||
1525 |
public JCDiagnostic getDiagnostic() { |
|
1526 |
return diag; |
|
1527 |
} |
|
1528 |
||
1529 |
@Override |
|
10 | 1530 |
public String getMessage() { |
169 | 1531 |
if (diag != null) |
1532 |
return diag.getMessage(null); |
|
1533 |
else |
|
1534 |
return errmsg; |
|
1535 |
} |
|
1536 |
||
1537 |
public Object getDetailValue() { |
|
1538 |
return (diag != null ? diag : errmsg); |
|
10 | 1539 |
} |
1540 |
||
1541 |
@Override |
|
1542 |
public CompletionFailure initCause(Throwable cause) { |
|
1543 |
super.initCause(cause); |
|
1544 |
return this; |
|
1545 |
} |
|
1546 |
||
1547 |
} |
|
1357 | 1548 |
|
1549 |
/** |
|
1550 |
* A visitor for symbols. A visitor is used to implement operations |
|
1551 |
* (or relations) on symbols. Most common operations on types are |
|
1552 |
* binary relations and this interface is designed for binary |
|
1553 |
* relations, that is, operations on the form |
|
1554 |
* Symbol × P → R. |
|
1555 |
* <!-- In plain text: Type x P -> R --> |
|
1556 |
* |
|
1557 |
* @param <R> the return type of the operation implemented by this |
|
1558 |
* visitor; use Void if no return type is needed. |
|
1559 |
* @param <P> the type of the second argument (the first being the |
|
1560 |
* symbol itself) of the operation implemented by this visitor; use |
|
1561 |
* Void if a second argument is not needed. |
|
1562 |
*/ |
|
1563 |
public interface Visitor<R,P> { |
|
1564 |
R visitClassSymbol(ClassSymbol s, P arg); |
|
1565 |
R visitMethodSymbol(MethodSymbol s, P arg); |
|
1566 |
R visitPackageSymbol(PackageSymbol s, P arg); |
|
1567 |
R visitOperatorSymbol(OperatorSymbol s, P arg); |
|
1568 |
R visitVarSymbol(VarSymbol s, P arg); |
|
1569 |
R visitTypeSymbol(TypeSymbol s, P arg); |
|
1570 |
R visitSymbol(Symbol s, P arg); |
|
1571 |
} |
|
10 | 1572 |
} |