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