author | sadayapalam |
Mon, 04 Jul 2016 14:57:33 +0530 | |
changeset 39372 | a42db8c180c3 |
parent 37848 | 3c8ff4204d2d |
child 39920 | 4923274643f2 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
36526 | 2 |
* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.code; |
|
27 |
||
21007 | 28 |
import java.lang.annotation.Annotation; |
29 |
import java.lang.annotation.Inherited; |
|
36526 | 30 |
import java.util.Collections; |
31 |
import java.util.Map; |
|
10 | 32 |
import java.util.Set; |
33 |
import java.util.concurrent.Callable; |
|
14258 | 34 |
|
36526 | 35 |
import javax.lang.model.element.Element; |
36 |
import javax.lang.model.element.ElementKind; |
|
37 |
import javax.lang.model.element.ElementVisitor; |
|
38 |
import javax.lang.model.element.ExecutableElement; |
|
39 |
import javax.lang.model.element.Modifier; |
|
40 |
import javax.lang.model.element.ModuleElement; |
|
41 |
import javax.lang.model.element.NestingKind; |
|
42 |
import javax.lang.model.element.PackageElement; |
|
43 |
import javax.lang.model.element.TypeElement; |
|
44 |
import javax.lang.model.element.TypeParameterElement; |
|
45 |
import javax.lang.model.element.VariableElement; |
|
46 |
import javax.tools.JavaFileManager; |
|
10 | 47 |
import javax.tools.JavaFileObject; |
48 |
||
37001
594b4565d8a4
8151191: javac error when running javadoc on some inner classes
vromero
parents:
36526
diff
changeset
|
49 |
import com.sun.tools.javac.code.ClassFinder.BadEnclosingMethodAttr; |
36526 | 50 |
import com.sun.tools.javac.code.Kinds.Kind; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
51 |
import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
52 |
import com.sun.tools.javac.code.Scope.WriteableScope; |
10 | 53 |
import com.sun.tools.javac.code.Type.*; |
54 |
import com.sun.tools.javac.comp.Attr; |
|
55 |
import com.sun.tools.javac.comp.AttrContext; |
|
56 |
import com.sun.tools.javac.comp.Env; |
|
57 |
import com.sun.tools.javac.jvm.*; |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
58 |
import com.sun.tools.javac.tree.JCTree.JCVariableDecl; |
14258 | 59 |
import com.sun.tools.javac.util.*; |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
60 |
import com.sun.tools.javac.util.DefinedBy.Api; |
14258 | 61 |
import com.sun.tools.javac.util.Name; |
36526 | 62 |
|
10 | 63 |
import static com.sun.tools.javac.code.Flags.*; |
64 |
import static com.sun.tools.javac.code.Kinds.*; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
65 |
import static com.sun.tools.javac.code.Kinds.Kind.*; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
66 |
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
67 |
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
|
68 |
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
|
69 |
import static com.sun.tools.javac.code.TypeTag.TYPEVAR; |
10 | 70 |
|
71 |
/** Root class for Java symbols. It contains subclasses |
|
72 |
* for specific sorts of symbols, such as variables, methods and operators, |
|
73 |
* types, packages. Each subclass is represented as a static inner class |
|
74 |
* inside Symbol. |
|
75 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
76 |
* <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
|
77 |
* If you write code that depends on this, you do so at your own risk. |
10 | 78 |
* This code and its internal interfaces are subject to change or |
79 |
* deletion without notice.</b> |
|
80 |
*/ |
|
21007 | 81 |
public abstract class Symbol extends AnnoConstruct implements Element { |
10 | 82 |
|
83 |
/** The kind of this symbol. |
|
84 |
* @see Kinds |
|
85 |
*/ |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
86 |
public Kind kind; |
10 | 87 |
|
88 |
/** The flags of this symbol. |
|
89 |
*/ |
|
90 |
public long flags_field; |
|
91 |
||
92 |
/** An accessor method for the flags of this symbol. |
|
93 |
* Flags of class symbols should be accessed through the accessor |
|
94 |
* method to make sure that the class symbol is loaded. |
|
95 |
*/ |
|
96 |
public long flags() { return flags_field; } |
|
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. |
|
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
111 |
* This should never equal null (NULL_COMPLETER should be used instead). |
10 | 112 |
*/ |
113 |
public Completer completer; |
|
114 |
||
115 |
/** A cache for the type erasure of this symbol. |
|
116 |
*/ |
|
117 |
public Type erasure_field; |
|
118 |
||
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
119 |
// <editor-fold defaultstate="collapsed" desc="annotations"> |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
120 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
121 |
/** The attributes of this symbol are contained in this |
19928
adce50c2b76c
8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents:
19666
diff
changeset
|
122 |
* SymbolMetadata. The SymbolMetadata instance is NOT immutable. |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
123 |
*/ |
21480 | 124 |
protected SymbolMetadata metadata; |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
125 |
|
21007 | 126 |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
127 |
/** An accessor method for the attributes of this symbol. |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
128 |
* Attributes of class symbols should be accessed through the accessor |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
129 |
* method to make sure that the class symbol is loaded. |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
130 |
*/ |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
131 |
public List<Attribute.Compound> getRawAttributes() { |
21480 | 132 |
return (metadata == null) |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
133 |
? List.<Attribute.Compound>nil() |
21480 | 134 |
: metadata.getDeclarationAttributes(); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
135 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
136 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
137 |
/** An accessor method for the type attributes of this symbol. |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
138 |
* Attributes of class symbols should be accessed through the accessor |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
139 |
* method to make sure that the class symbol is loaded. |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
140 |
*/ |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
141 |
public List<Attribute.TypeCompound> getRawTypeAttributes() { |
21480 | 142 |
return (metadata == null) |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
143 |
? List.<Attribute.TypeCompound>nil() |
21480 | 144 |
: metadata.getTypeAttributes(); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
145 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
146 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
147 |
/** Fetch a particular annotation from a symbol. */ |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
148 |
public Attribute.Compound attribute(Symbol anno) { |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
149 |
for (Attribute.Compound a : getRawAttributes()) { |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
150 |
if (a.type.tsym == anno) return a; |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
151 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
152 |
return null; |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
153 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
154 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
155 |
public boolean annotationsPendingCompletion() { |
21480 | 156 |
return metadata == null ? false : metadata.pendingCompletion(); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
157 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
158 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
159 |
public void appendAttributes(List<Attribute.Compound> l) { |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
160 |
if (l.nonEmpty()) { |
21480 | 161 |
initedMetadata().append(l); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
162 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
163 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
164 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
165 |
public void appendClassInitTypeAttributes(List<Attribute.TypeCompound> l) { |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
166 |
if (l.nonEmpty()) { |
21480 | 167 |
initedMetadata().appendClassInitTypeAttributes(l); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
168 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
169 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
170 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
171 |
public void appendInitTypeAttributes(List<Attribute.TypeCompound> l) { |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
172 |
if (l.nonEmpty()) { |
21480 | 173 |
initedMetadata().appendInitTypeAttributes(l); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
174 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
175 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
176 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
177 |
public void appendUniqueTypeAttributes(List<Attribute.TypeCompound> l) { |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
178 |
if (l.nonEmpty()) { |
21480 | 179 |
initedMetadata().appendUniqueTypes(l); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
180 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
181 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
182 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
183 |
public List<Attribute.TypeCompound> getClassInitTypeAttributes() { |
21480 | 184 |
return (metadata == null) |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
185 |
? List.<Attribute.TypeCompound>nil() |
21480 | 186 |
: metadata.getClassInitTypeAttributes(); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
187 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
188 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
189 |
public List<Attribute.TypeCompound> getInitTypeAttributes() { |
21480 | 190 |
return (metadata == null) |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
191 |
? List.<Attribute.TypeCompound>nil() |
21480 | 192 |
: metadata.getInitTypeAttributes(); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
193 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
194 |
|
33712
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33367
diff
changeset
|
195 |
public void setInitTypeAttributes(List<Attribute.TypeCompound> l) { |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33367
diff
changeset
|
196 |
initedMetadata().setInitTypeAttributes(l); |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33367
diff
changeset
|
197 |
} |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33367
diff
changeset
|
198 |
|
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33367
diff
changeset
|
199 |
public void setClassInitTypeAttributes(List<Attribute.TypeCompound> l) { |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33367
diff
changeset
|
200 |
initedMetadata().setClassInitTypeAttributes(l); |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33367
diff
changeset
|
201 |
} |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33367
diff
changeset
|
202 |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
203 |
public List<Attribute.Compound> getDeclarationAttributes() { |
21480 | 204 |
return (metadata == null) |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
205 |
? List.<Attribute.Compound>nil() |
21480 | 206 |
: metadata.getDeclarationAttributes(); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
207 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
208 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
209 |
public boolean hasAnnotations() { |
21480 | 210 |
return (metadata != null && !metadata.isEmpty()); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
211 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
212 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
213 |
public boolean hasTypeAnnotations() { |
21480 | 214 |
return (metadata != null && !metadata.isTypesEmpty()); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
215 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
216 |
|
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
217 |
public boolean isCompleted() { |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
218 |
return completer.isTerminal(); |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
219 |
} |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
220 |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
221 |
public void prependAttributes(List<Attribute.Compound> l) { |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
222 |
if (l.nonEmpty()) { |
21480 | 223 |
initedMetadata().prepend(l); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
224 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
225 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
226 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
227 |
public void resetAnnotations() { |
21480 | 228 |
initedMetadata().reset(); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
229 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
230 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
231 |
public void setAttributes(Symbol other) { |
21480 | 232 |
if (metadata != null || other.metadata != null) { |
233 |
initedMetadata().setAttributes(other.metadata); |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
234 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
235 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
236 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
237 |
public void setDeclarationAttributes(List<Attribute.Compound> a) { |
21480 | 238 |
if (metadata != null || a.nonEmpty()) { |
239 |
initedMetadata().setDeclarationAttributes(a); |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
240 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
241 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
242 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
243 |
public void setTypeAttributes(List<Attribute.TypeCompound> a) { |
21480 | 244 |
if (metadata != null || a.nonEmpty()) { |
245 |
if (metadata == null) |
|
246 |
metadata = new SymbolMetadata(this); |
|
247 |
metadata.setTypeAttributes(a); |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
248 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
249 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
250 |
|
21480 | 251 |
private SymbolMetadata initedMetadata() { |
252 |
if (metadata == null) |
|
253 |
metadata = new SymbolMetadata(this); |
|
254 |
return metadata; |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
255 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
256 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
257 |
/** This method is intended for debugging only. */ |
21480 | 258 |
public SymbolMetadata getMetadata() { |
259 |
return metadata; |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
260 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
261 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
262 |
// </editor-fold> |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
263 |
|
10 | 264 |
/** Construct a symbol with given kind, flags, name, type and owner. |
265 |
*/ |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
266 |
public Symbol(Kind kind, long flags, Name name, Type type, Symbol owner) { |
10 | 267 |
this.kind = kind; |
268 |
this.flags_field = flags; |
|
269 |
this.type = type; |
|
270 |
this.owner = owner; |
|
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
271 |
this.completer = Completer.NULL_COMPLETER; |
10 | 272 |
this.erasure_field = null; |
273 |
this.name = name; |
|
274 |
} |
|
275 |
||
276 |
/** Clone this symbol with new owner. |
|
277 |
* Legal only for fields and methods. |
|
278 |
*/ |
|
279 |
public Symbol clone(Symbol newOwner) { |
|
280 |
throw new AssertionError(); |
|
281 |
} |
|
282 |
||
1357 | 283 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
284 |
return v.visitSymbol(this, p); |
|
285 |
} |
|
286 |
||
10 | 287 |
/** The Java source which this symbol represents. |
288 |
* A description of this symbol; overrides Object. |
|
289 |
*/ |
|
290 |
public String toString() { |
|
291 |
return name.toString(); |
|
292 |
} |
|
293 |
||
294 |
/** 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
|
295 |
* error reporting. |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
296 |
* |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
297 |
* @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
|
298 |
* the default package; otherwise, the owner symbol is returned |
10 | 299 |
*/ |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
300 |
public Symbol location() { |
10626
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
301 |
if (owner.name == null || (owner.name.isEmpty() && |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
302 |
(owner.flags() & BLOCK) == 0 && |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
303 |
owner.kind != PCK && |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
304 |
owner.kind != TYP)) { |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
305 |
return null; |
10 | 306 |
} |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
307 |
return owner; |
10 | 308 |
} |
309 |
||
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
310 |
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
|
311 |
if (owner.name == null || owner.name.isEmpty()) { |
10 | 312 |
return location(); |
313 |
} |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
314 |
if (owner.type.hasTag(CLASS)) { |
10 | 315 |
Type ownertype = types.asOuterSuper(site, owner); |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
316 |
if (ownertype != null) return ownertype.tsym; |
10 | 317 |
} |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
318 |
return owner; |
10 | 319 |
} |
320 |
||
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14046
diff
changeset
|
321 |
public Symbol baseSymbol() { |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14046
diff
changeset
|
322 |
return this; |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14046
diff
changeset
|
323 |
} |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14046
diff
changeset
|
324 |
|
10 | 325 |
/** The symbol's erased type. |
326 |
*/ |
|
327 |
public Type erasure(Types types) { |
|
328 |
if (erasure_field == null) |
|
329 |
erasure_field = types.erasure(type); |
|
330 |
return erasure_field; |
|
331 |
} |
|
332 |
||
333 |
/** The external type of a symbol. This is the symbol's erased type |
|
334 |
* except for constructors of inner classes which get the enclosing |
|
335 |
* instance class added as first argument. |
|
336 |
*/ |
|
337 |
public Type externalType(Types types) { |
|
338 |
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
|
339 |
if (name == name.table.names.init && owner.hasOuterInstance()) { |
10 | 340 |
Type outerThisType = types.erasure(owner.type.getEnclosingType()); |
341 |
return new MethodType(t.getParameterTypes().prepend(outerThisType), |
|
342 |
t.getReturnType(), |
|
343 |
t.getThrownTypes(), |
|
344 |
t.tsym); |
|
345 |
} else { |
|
346 |
return t; |
|
347 |
} |
|
348 |
} |
|
349 |
||
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
350 |
public boolean isDeprecated() { |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
351 |
return (flags_field & DEPRECATED) != 0; |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
352 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
353 |
|
10 | 354 |
public boolean isStatic() { |
355 |
return |
|
356 |
(flags() & STATIC) != 0 || |
|
20598
aa7b86f98471
8024497: crash returning this-referencing lambda from default method
vromero
parents:
20249
diff
changeset
|
357 |
(owner.flags() & INTERFACE) != 0 && kind != MTH && |
aa7b86f98471
8024497: crash returning this-referencing lambda from default method
vromero
parents:
20249
diff
changeset
|
358 |
name != name.table.names._this; |
10 | 359 |
} |
360 |
||
361 |
public boolean isInterface() { |
|
362 |
return (flags() & INTERFACE) != 0; |
|
363 |
} |
|
364 |
||
15720
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
365 |
public boolean isPrivate() { |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
366 |
return (flags_field & Flags.AccessFlags) == PRIVATE; |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
367 |
} |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
368 |
|
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
369 |
public boolean isEnum() { |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
370 |
return (flags() & ENUM) != 0; |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
371 |
} |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
372 |
|
10 | 373 |
/** Is this symbol declared (directly or indirectly) local |
374 |
* to a method or variable initializer? |
|
375 |
* Also includes fields of inner classes which are in |
|
376 |
* turn local to a method or variable initializer. |
|
377 |
*/ |
|
378 |
public boolean isLocal() { |
|
379 |
return |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
380 |
(owner.kind.matches(KindSelector.VAL_MTH) || |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
381 |
(owner.kind == TYP && owner.isLocal())); |
10 | 382 |
} |
383 |
||
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5006
diff
changeset
|
384 |
/** Has this symbol an empty name? This includes anonymous |
16333 | 385 |
* inner classes. |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5006
diff
changeset
|
386 |
*/ |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5006
diff
changeset
|
387 |
public boolean isAnonymous() { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5006
diff
changeset
|
388 |
return name.isEmpty(); |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5006
diff
changeset
|
389 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5006
diff
changeset
|
390 |
|
10 | 391 |
/** Is this symbol a constructor? |
392 |
*/ |
|
393 |
public boolean isConstructor() { |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
394 |
return name == name.table.names.init; |
10 | 395 |
} |
396 |
||
397 |
/** The fully qualified name of this symbol. |
|
398 |
* This is the same as the symbol's name except for class symbols, |
|
399 |
* which are handled separately. |
|
400 |
*/ |
|
401 |
public Name getQualifiedName() { |
|
402 |
return name; |
|
403 |
} |
|
404 |
||
405 |
/** The fully qualified name of this symbol after converting to flat |
|
406 |
* representation. This is the same as the symbol's name except for |
|
407 |
* class symbols, which are handled separately. |
|
408 |
*/ |
|
409 |
public Name flatName() { |
|
410 |
return getQualifiedName(); |
|
411 |
} |
|
412 |
||
413 |
/** If this is a class or package, its members, otherwise null. |
|
414 |
*/ |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
415 |
public WriteableScope members() { |
10 | 416 |
return null; |
417 |
} |
|
418 |
||
419 |
/** A class is an inner class if it it has an enclosing instance class. |
|
420 |
*/ |
|
421 |
public boolean isInner() { |
|
24219 | 422 |
return kind == TYP && type.getEnclosingType().hasTag(CLASS); |
10 | 423 |
} |
424 |
||
425 |
/** An inner class has an outer instance if it is not an interface |
|
426 |
* it has an enclosing instance class which might be referenced from the class. |
|
427 |
* Nested classes can see instance members of their enclosing class. |
|
428 |
* Their constructors carry an additional this$n parameter, inserted |
|
429 |
* implicitly by the compiler. |
|
430 |
* |
|
431 |
* @see #isInner |
|
432 |
*/ |
|
433 |
public boolean hasOuterInstance() { |
|
434 |
return |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
435 |
type.getEnclosingType().hasTag(CLASS) && (flags() & (INTERFACE | NOOUTERTHIS)) == 0; |
10 | 436 |
} |
437 |
||
438 |
/** The closest enclosing class of this symbol's declaration. |
|
34561
79c436257611
8144673: Suspect message regarding suitable enclosing instance not being in scope
sadayapalam
parents:
33712
diff
changeset
|
439 |
* Warning: this (misnamed) method returns the receiver itself |
79c436257611
8144673: Suspect message regarding suitable enclosing instance not being in scope
sadayapalam
parents:
33712
diff
changeset
|
440 |
* when the receiver is a class (as opposed to its enclosing |
79c436257611
8144673: Suspect message regarding suitable enclosing instance not being in scope
sadayapalam
parents:
33712
diff
changeset
|
441 |
* class as one may be misled to believe.) |
10 | 442 |
*/ |
443 |
public ClassSymbol enclClass() { |
|
444 |
Symbol c = this; |
|
445 |
while (c != null && |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
446 |
(!c.kind.matches(KindSelector.TYP) || !c.type.hasTag(CLASS))) { |
10 | 447 |
c = c.owner; |
448 |
} |
|
449 |
return (ClassSymbol)c; |
|
450 |
} |
|
451 |
||
452 |
/** The outermost class which indirectly owns this symbol. |
|
453 |
*/ |
|
454 |
public ClassSymbol outermostClass() { |
|
455 |
Symbol sym = this; |
|
456 |
Symbol prev = null; |
|
457 |
while (sym.kind != PCK) { |
|
458 |
prev = sym; |
|
459 |
sym = sym.owner; |
|
460 |
} |
|
461 |
return (ClassSymbol) prev; |
|
462 |
} |
|
463 |
||
464 |
/** The package which indirectly owns this symbol. |
|
465 |
*/ |
|
466 |
public PackageSymbol packge() { |
|
467 |
Symbol sym = this; |
|
468 |
while (sym.kind != PCK) { |
|
469 |
sym = sym.owner; |
|
470 |
} |
|
471 |
return (PackageSymbol) sym; |
|
472 |
} |
|
473 |
||
474 |
/** Is this symbol a subclass of `base'? Only defined for ClassSymbols. |
|
475 |
*/ |
|
476 |
public boolean isSubClass(Symbol base, Types types) { |
|
477 |
throw new AssertionError("isSubClass " + this); |
|
478 |
} |
|
479 |
||
480 |
/** Fully check membership: hierarchy, protection, and hiding. |
|
481 |
* Does not exclude methods not inherited due to overriding. |
|
482 |
*/ |
|
483 |
public boolean isMemberOf(TypeSymbol clazz, Types types) { |
|
484 |
return |
|
485 |
owner == clazz || |
|
486 |
clazz.isSubClass(owner, types) && |
|
487 |
isInheritedIn(clazz, types) && |
|
488 |
!hiddenIn((ClassSymbol)clazz, types); |
|
489 |
} |
|
490 |
||
491 |
/** Is this symbol the same as or enclosed by the given class? */ |
|
492 |
public boolean isEnclosedBy(ClassSymbol clazz) { |
|
493 |
for (Symbol sym = this; sym.kind != PCK; sym = sym.owner) |
|
494 |
if (sym == clazz) return true; |
|
495 |
return false; |
|
496 |
} |
|
497 |
||
498 |
private boolean hiddenIn(ClassSymbol clazz, Types types) { |
|
19492
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
19126
diff
changeset
|
499 |
Symbol sym = hiddenInInternal(clazz, types); |
23396
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
500 |
Assert.check(sym != null, "the result of hiddenInInternal() can't be null"); |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
501 |
/* If we find the current symbol then there is no symbol hiding it |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
502 |
*/ |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
503 |
return sym != this; |
19492
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
19126
diff
changeset
|
504 |
} |
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
19126
diff
changeset
|
505 |
|
23396
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
506 |
/** This method looks in the supertypes graph that has the current class as the |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
507 |
* initial node, till it finds the current symbol or another symbol that hides it. |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
508 |
* If the current class has more than one supertype (extends one class and |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
509 |
* implements one or more interfaces) then null can be returned, meaning that |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
510 |
* a wrong path in the supertypes graph was selected. Null can only be returned |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
511 |
* as a temporary value, as a result of the recursive call. |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
512 |
*/ |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
513 |
private Symbol hiddenInInternal(ClassSymbol currentClass, Types types) { |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
514 |
if (currentClass == owner) { |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
515 |
return this; |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
516 |
} |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
517 |
for (Symbol sym : currentClass.members().getSymbolsByName(name)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
518 |
if (sym.kind == kind && |
10 | 519 |
(kind != MTH || |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
520 |
(sym.flags() & STATIC) != 0 && |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
521 |
types.isSubSignature(sym.type, type))) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
522 |
return sym; |
10 | 523 |
} |
524 |
} |
|
23396
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
525 |
Symbol hiddenSym = null; |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
526 |
for (Type st : types.interfaces(currentClass.type) |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
527 |
.prepend(types.supertype(currentClass.type))) { |
19492
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
19126
diff
changeset
|
528 |
if (st != null && (st.hasTag(CLASS))) { |
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
19126
diff
changeset
|
529 |
Symbol sym = hiddenInInternal((ClassSymbol)st.tsym, types); |
23396
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
530 |
if (sym == this) { |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
531 |
return this; |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
532 |
} else if (sym != null) { |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
533 |
hiddenSym = sym; |
19492
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
19126
diff
changeset
|
534 |
} |
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
19126
diff
changeset
|
535 |
} |
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
19126
diff
changeset
|
536 |
} |
23396
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
537 |
return hiddenSym; |
10 | 538 |
} |
539 |
||
540 |
/** Is this symbol inherited into a given class? |
|
541 |
* PRE: If symbol's owner is a interface, |
|
542 |
* it is already assumed that the interface is a superinterface |
|
543 |
* of given class. |
|
544 |
* @param clazz The class for which we want to establish membership. |
|
545 |
* This must be a subclass of the member's owner. |
|
546 |
*/ |
|
547 |
public boolean isInheritedIn(Symbol clazz, Types types) { |
|
548 |
switch ((int)(flags_field & Flags.AccessFlags)) { |
|
549 |
default: // error recovery |
|
550 |
case PUBLIC: |
|
551 |
return true; |
|
552 |
case PRIVATE: |
|
553 |
return this.owner == clazz; |
|
554 |
case PROTECTED: |
|
555 |
// we model interfaces as extending Object |
|
556 |
return (clazz.flags() & INTERFACE) == 0; |
|
557 |
case 0: |
|
558 |
PackageSymbol thisPackage = this.packge(); |
|
559 |
for (Symbol sup = clazz; |
|
560 |
sup != null && sup != this.owner; |
|
561 |
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
|
562 |
while (sup.type.hasTag(TYPEVAR)) |
1528
441d4ec466de
6711619: javac doesn't allow access to protected members in intersection types
mcimadamore
parents:
1357
diff
changeset
|
563 |
sup = sup.type.getUpperBound().tsym; |
10 | 564 |
if (sup.type.isErroneous()) |
565 |
return true; // error recovery |
|
566 |
if ((sup.flags() & COMPOUND) != 0) |
|
567 |
continue; |
|
568 |
if (sup.packge() != thisPackage) |
|
569 |
return false; |
|
570 |
} |
|
571 |
return (clazz.flags() & INTERFACE) == 0; |
|
572 |
} |
|
573 |
} |
|
574 |
||
575 |
/** The (variable or method) symbol seen as a member of given |
|
576 |
* class type`site' (this might change the symbol's type). |
|
577 |
* This is used exclusively for producing diagnostics. |
|
578 |
*/ |
|
579 |
public Symbol asMemberOf(Type site, Types types) { |
|
580 |
throw new AssertionError(); |
|
581 |
} |
|
582 |
||
583 |
/** Does this method symbol override `other' symbol, when both are seen as |
|
584 |
* members of class `origin'? It is assumed that _other is a member |
|
585 |
* of origin. |
|
586 |
* |
|
587 |
* It is assumed that both symbols have the same name. The static |
|
588 |
* modifier is ignored for this test. |
|
589 |
* |
|
590 |
* See JLS 8.4.6.1 (without transitivity) and 8.4.6.4 |
|
591 |
*/ |
|
592 |
public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) { |
|
593 |
return false; |
|
594 |
} |
|
595 |
||
596 |
/** Complete the elaboration of this symbol's definition. |
|
597 |
*/ |
|
598 |
public void complete() throws CompletionFailure { |
|
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
599 |
if (completer != Completer.NULL_COMPLETER) { |
10 | 600 |
Completer c = completer; |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
601 |
completer = Completer.NULL_COMPLETER; |
10 | 602 |
c.complete(this); |
603 |
} |
|
604 |
} |
|
605 |
||
606 |
/** True if the symbol represents an entity that exists. |
|
607 |
*/ |
|
608 |
public boolean exists() { |
|
609 |
return true; |
|
610 |
} |
|
611 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
612 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 613 |
public Type asType() { |
614 |
return type; |
|
615 |
} |
|
616 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
617 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 618 |
public Symbol getEnclosingElement() { |
619 |
return owner; |
|
620 |
} |
|
621 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
622 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 623 |
public ElementKind getKind() { |
624 |
return ElementKind.OTHER; // most unkind |
|
625 |
} |
|
626 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
627 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 628 |
public Set<Modifier> getModifiers() { |
16970
0967fa88590b
8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents:
16967
diff
changeset
|
629 |
return Flags.asModifierSet(flags()); |
10 | 630 |
} |
631 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
632 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 633 |
public Name getSimpleName() { |
634 |
return name; |
|
635 |
} |
|
636 |
||
637 |
/** |
|
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
638 |
* This is the implementation for {@code |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
639 |
* javax.lang.model.element.Element.getAnnotationMirrors()}. |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
640 |
*/ |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
641 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
17278
a48ec76f26e9
8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents:
16970
diff
changeset
|
642 |
public List<Attribute.Compound> getAnnotationMirrors() { |
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
643 |
return getRawAttributes(); |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
644 |
} |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
645 |
|
15355
a4757c33cae9
7193719: Support repeating annotations in javax.lang.model
jfranck
parents:
15031
diff
changeset
|
646 |
|
10 | 647 |
// TODO: getEnclosedElements should return a javac List, fix in FilteredMemberList |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
648 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 649 |
public java.util.List<Symbol> getEnclosedElements() { |
650 |
return List.nil(); |
|
651 |
} |
|
652 |
||
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
653 |
public List<TypeVariableSymbol> getTypeParameters() { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19942
diff
changeset
|
654 |
ListBuffer<TypeVariableSymbol> l = new ListBuffer<>(); |
10 | 655 |
for (Type t : type.getTypeArguments()) { |
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
656 |
Assert.check(t.tsym.getKind() == ElementKind.TYPE_PARAMETER); |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
657 |
l.append((TypeVariableSymbol)t.tsym); |
10 | 658 |
} |
659 |
return l.toList(); |
|
660 |
} |
|
661 |
||
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
662 |
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
|
663 |
protected T other; |
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
664 |
public DelegatedSymbol(T other) { |
10 | 665 |
super(other.kind, other.flags_field, other.name, other.type, other.owner); |
666 |
this.other = other; |
|
667 |
} |
|
668 |
public String toString() { return other.toString(); } |
|
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
669 |
public Symbol location() { return other.location(); } |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
670 |
public Symbol location(Type site, Types types) { return other.location(site, types); } |
14547 | 671 |
public Symbol baseSymbol() { return other; } |
10 | 672 |
public Type erasure(Types types) { return other.erasure(types); } |
673 |
public Type externalType(Types types) { return other.externalType(types); } |
|
674 |
public boolean isLocal() { return other.isLocal(); } |
|
675 |
public boolean isConstructor() { return other.isConstructor(); } |
|
676 |
public Name getQualifiedName() { return other.getQualifiedName(); } |
|
677 |
public Name flatName() { return other.flatName(); } |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
678 |
public WriteableScope members() { return other.members(); } |
10 | 679 |
public boolean isInner() { return other.isInner(); } |
680 |
public boolean hasOuterInstance() { return other.hasOuterInstance(); } |
|
681 |
public ClassSymbol enclClass() { return other.enclClass(); } |
|
682 |
public ClassSymbol outermostClass() { return other.outermostClass(); } |
|
683 |
public PackageSymbol packge() { return other.packge(); } |
|
684 |
public boolean isSubClass(Symbol base, Types types) { return other.isSubClass(base, types); } |
|
685 |
public boolean isMemberOf(TypeSymbol clazz, Types types) { return other.isMemberOf(clazz, types); } |
|
686 |
public boolean isEnclosedBy(ClassSymbol clazz) { return other.isEnclosedBy(clazz); } |
|
687 |
public boolean isInheritedIn(Symbol clazz, Types types) { return other.isInheritedIn(clazz, types); } |
|
688 |
public Symbol asMemberOf(Type site, Types types) { return other.asMemberOf(site, types); } |
|
689 |
public void complete() throws CompletionFailure { other.complete(); } |
|
690 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
691 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 692 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
693 |
return other.accept(v, p); |
|
694 |
} |
|
1357 | 695 |
|
696 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
|
697 |
return v.visitSymbol(other, p); |
|
698 |
} |
|
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
699 |
|
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
700 |
public T getUnderlyingSymbol() { |
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
701 |
return other; |
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
702 |
} |
10 | 703 |
} |
704 |
||
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
705 |
/** A base class for Symbols representing types. |
10 | 706 |
*/ |
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
707 |
public static abstract class TypeSymbol extends Symbol { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
708 |
public TypeSymbol(Kind kind, long flags, Name name, Type type, Symbol owner) { |
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
709 |
super(kind, flags, name, type, owner); |
10 | 710 |
} |
711 |
/** form a fully qualified name from a name and an owner |
|
712 |
*/ |
|
713 |
static public Name formFullName(Name name, Symbol owner) { |
|
714 |
if (owner == null) return name; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
715 |
if ((owner.kind != ERR) && |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
716 |
(owner.kind.matches(KindSelector.VAL_MTH) || |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
717 |
(owner.kind == TYP && owner.type.hasTag(TYPEVAR)) |
10 | 718 |
)) return name; |
719 |
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
|
720 |
if (prefix == null || prefix == prefix.table.names.empty) |
10 | 721 |
return name; |
722 |
else return prefix.append('.', name); |
|
723 |
} |
|
724 |
||
725 |
/** form a fully qualified name from a name and an owner, after |
|
726 |
* converting to flat representation |
|
727 |
*/ |
|
728 |
static public Name formFlatName(Name name, Symbol owner) { |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
729 |
if (owner == null || owner.kind.matches(KindSelector.VAL_MTH) || |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
730 |
(owner.kind == TYP && owner.type.hasTag(TYPEVAR)) |
10 | 731 |
) return name; |
732 |
char sep = owner.kind == TYP ? '$' : '.'; |
|
733 |
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
|
734 |
if (prefix == null || prefix == prefix.table.names.empty) |
10 | 735 |
return name; |
736 |
else return prefix.append(sep, name); |
|
737 |
} |
|
738 |
||
739 |
/** |
|
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24219
diff
changeset
|
740 |
* A partial ordering between type symbols that refines the |
10 | 741 |
* class inheritance graph. |
742 |
* |
|
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24219
diff
changeset
|
743 |
* Type variables always precede other kinds of symbols. |
10 | 744 |
*/ |
745 |
public final boolean precedes(TypeSymbol that, Types types) { |
|
746 |
if (this == that) |
|
747 |
return false; |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18389
diff
changeset
|
748 |
if (type.hasTag(that.type.getTag())) { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18389
diff
changeset
|
749 |
if (type.hasTag(CLASS)) { |
10 | 750 |
return |
751 |
types.rank(that.type) < types.rank(this.type) || |
|
752 |
types.rank(that.type) == types.rank(this.type) && |
|
753 |
that.getQualifiedName().compareTo(this.getQualifiedName()) < 0; |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18389
diff
changeset
|
754 |
} else if (type.hasTag(TYPEVAR)) { |
10 | 755 |
return types.isSubtype(this.type, that.type); |
756 |
} |
|
757 |
} |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18389
diff
changeset
|
758 |
return type.hasTag(TYPEVAR); |
10 | 759 |
} |
760 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
761 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
10 | 762 |
public java.util.List<Symbol> getEnclosedElements() { |
763 |
List<Symbol> list = List.nil(); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
764 |
if (kind == TYP && type.hasTag(TYPEVAR)) { |
6584
c3d25d0ad536
6458749: TypeParameterElement.getEnclosedElements throws NPE within javac.
sundar
parents:
6148
diff
changeset
|
765 |
return list; |
c3d25d0ad536
6458749: TypeParameterElement.getEnclosedElements throws NPE within javac.
sundar
parents:
6148
diff
changeset
|
766 |
} |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
767 |
for (Symbol sym : members().getSymbols(NON_RECURSIVE)) { |
37001
594b4565d8a4
8151191: javac error when running javadoc on some inner classes
vromero
parents:
36526
diff
changeset
|
768 |
try { |
594b4565d8a4
8151191: javac error when running javadoc on some inner classes
vromero
parents:
36526
diff
changeset
|
769 |
if (sym != null && (sym.flags() & SYNTHETIC) == 0 && sym.owner == this) { |
594b4565d8a4
8151191: javac error when running javadoc on some inner classes
vromero
parents:
36526
diff
changeset
|
770 |
list = list.prepend(sym); |
594b4565d8a4
8151191: javac error when running javadoc on some inner classes
vromero
parents:
36526
diff
changeset
|
771 |
} |
594b4565d8a4
8151191: javac error when running javadoc on some inner classes
vromero
parents:
36526
diff
changeset
|
772 |
} catch (BadEnclosingMethodAttr badEnclosingMethod) { |
594b4565d8a4
8151191: javac error when running javadoc on some inner classes
vromero
parents:
36526
diff
changeset
|
773 |
// ignore the exception |
594b4565d8a4
8151191: javac error when running javadoc on some inner classes
vromero
parents:
36526
diff
changeset
|
774 |
} |
10 | 775 |
} |
776 |
return list; |
|
777 |
} |
|
778 |
||
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
779 |
public AnnotationTypeMetadata getAnnotationTypeMetadata() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
780 |
Assert.error("Only on ClassSymbol"); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
781 |
return null; //unreachable |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
782 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
783 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
784 |
public boolean isAnnotationType() { return false; } |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
785 |
|
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
786 |
@Override |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
787 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
788 |
return v.visitTypeSymbol(this, p); |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
789 |
} |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
790 |
} |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
791 |
|
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
792 |
/** |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
793 |
* Type variables are represented by instances of this class. |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
794 |
*/ |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
795 |
public static class TypeVariableSymbol |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
796 |
extends TypeSymbol implements TypeParameterElement { |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
797 |
|
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
798 |
public TypeVariableSymbol(long flags, Name name, Type type, Symbol owner) { |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
799 |
super(TYP, flags, name, type, owner); |
10 | 800 |
} |
801 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
802 |
@DefinedBy(Api.LANGUAGE_MODEL) |
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
803 |
public ElementKind getKind() { |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
804 |
return ElementKind.TYPE_PARAMETER; |
10 | 805 |
} |
806 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
807 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
808 |
public Symbol getGenericElement() { |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
809 |
return owner; |
1357 | 810 |
} |
811 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
812 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 813 |
public List<Type> getBounds() { |
814 |
TypeVar t = (TypeVar)type; |
|
815 |
Type bound = t.getUpperBound(); |
|
816 |
if (!bound.isCompound()) |
|
817 |
return List.of(bound); |
|
818 |
ClassType ct = (ClassType)bound; |
|
819 |
if (!ct.tsym.erasure_field.isInterface()) { |
|
820 |
return ct.interfaces_field.prepend(ct.supertype_field); |
|
821 |
} else { |
|
822 |
// No superclass was given in bounds. |
|
823 |
// In this case, supertype is Object, erasure is first interface. |
|
824 |
return ct.interfaces_field; |
|
825 |
} |
|
826 |
} |
|
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
827 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
828 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
17278
a48ec76f26e9
8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents:
16970
diff
changeset
|
829 |
public List<Attribute.Compound> getAnnotationMirrors() { |
25009
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
830 |
// Declaration annotations on type variables are stored in type attributes |
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
831 |
// on the owner of the TypeVariableSymbol |
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
832 |
List<Attribute.TypeCompound> candidates = owner.getRawTypeAttributes(); |
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
833 |
int index = owner.getTypeParameters().indexOf(this); |
17278
a48ec76f26e9
8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents:
16970
diff
changeset
|
834 |
List<Attribute.Compound> res = List.nil(); |
a48ec76f26e9
8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents:
16970
diff
changeset
|
835 |
for (Attribute.TypeCompound a : candidates) { |
25009
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
836 |
if (isCurrentSymbolsAnnotation(a, index)) |
17278
a48ec76f26e9
8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents:
16970
diff
changeset
|
837 |
res = res.prepend(a); |
a48ec76f26e9
8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents:
16970
diff
changeset
|
838 |
} |
a48ec76f26e9
8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents:
16970
diff
changeset
|
839 |
|
25009
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
840 |
return res.reverse(); |
17278
a48ec76f26e9
8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents:
16970
diff
changeset
|
841 |
} |
a48ec76f26e9
8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents:
16970
diff
changeset
|
842 |
|
21007 | 843 |
// Helper to getAnnotation[s] |
844 |
@Override |
|
845 |
public <A extends Annotation> Attribute.Compound getAttribute(Class<A> annoType) { |
|
846 |
String name = annoType.getName(); |
|
847 |
||
848 |
// Declaration annotations on type variables are stored in type attributes |
|
849 |
// on the owner of the TypeVariableSymbol |
|
850 |
List<Attribute.TypeCompound> candidates = owner.getRawTypeAttributes(); |
|
25009
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
851 |
int index = owner.getTypeParameters().indexOf(this); |
21007 | 852 |
for (Attribute.TypeCompound anno : candidates) |
25009
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
853 |
if (isCurrentSymbolsAnnotation(anno, index) && |
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
854 |
name.contentEquals(anno.type.tsym.flatName())) |
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
855 |
return anno; |
21007 | 856 |
|
857 |
return null; |
|
858 |
} |
|
25009
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
859 |
//where: |
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
860 |
boolean isCurrentSymbolsAnnotation(Attribute.TypeCompound anno, int index) { |
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
861 |
return (anno.position.type == TargetType.CLASS_TYPE_PARAMETER || |
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
862 |
anno.position.type == TargetType.METHOD_TYPE_PARAMETER) && |
36526 | 863 |
anno.position.parameter_index == index; |
25009
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
864 |
} |
21007 | 865 |
|
866 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
867 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
868 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
869 |
return v.visitTypeParameter(this, p); |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
870 |
} |
10 | 871 |
} |
36526 | 872 |
/** A class for module symbols. |
873 |
*/ |
|
874 |
public static class ModuleSymbol extends TypeSymbol |
|
875 |
implements ModuleElement { |
|
876 |
||
877 |
public Name version; |
|
878 |
public JavaFileManager.Location sourceLocation; |
|
879 |
public JavaFileManager.Location classLocation; |
|
880 |
||
881 |
/** All directives, in natural order. */ |
|
882 |
public List<com.sun.tools.javac.code.Directive> directives; |
|
883 |
public List<com.sun.tools.javac.code.Directive.RequiresDirective> requires; |
|
884 |
public List<com.sun.tools.javac.code.Directive.ExportsDirective> exports; |
|
885 |
public List<com.sun.tools.javac.code.Directive.ProvidesDirective> provides; |
|
886 |
public List<com.sun.tools.javac.code.Directive.UsesDirective> uses; |
|
887 |
||
888 |
public ClassSymbol module_info; |
|
889 |
||
890 |
public PackageSymbol unnamedPackage; |
|
891 |
public Map<Name, PackageSymbol> visiblePackages; |
|
892 |
public List<Symbol> enclosedPackages = List.nil(); |
|
893 |
||
894 |
public Completer usesProvidesCompleter = Completer.NULL_COMPLETER; |
|
895 |
||
896 |
/** |
|
897 |
* Create a ModuleSymbol with an associated module-info ClassSymbol. |
|
898 |
* The name of the module may be null, if it is not known yet. |
|
899 |
*/ |
|
900 |
public static ModuleSymbol create(Name name, Name module_info) { |
|
901 |
ModuleSymbol msym = new ModuleSymbol(name, null); |
|
902 |
ClassSymbol info = new ClassSymbol(Flags.MODULE, module_info, msym); |
|
903 |
info.fullname = formFullName(module_info, msym); |
|
904 |
info.flatname = info.fullname; |
|
905 |
info.members_field = WriteableScope.create(info); |
|
906 |
msym.module_info = info; |
|
907 |
return msym; |
|
908 |
} |
|
909 |
||
910 |
public ModuleSymbol() { |
|
911 |
super(MDL, 0, null, null, null); |
|
912 |
this.type = new ModuleType(this); |
|
913 |
} |
|
914 |
||
915 |
public ModuleSymbol(Name name, Symbol owner) { |
|
916 |
super(MDL, 0, name, null, owner); |
|
917 |
this.type = new ModuleType(this); |
|
918 |
} |
|
919 |
||
920 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
921 |
public boolean isUnnamed() { |
|
922 |
return name.isEmpty() && owner == null; |
|
923 |
} |
|
924 |
||
925 |
public boolean isNoModule() { |
|
926 |
return false; |
|
927 |
} |
|
928 |
||
929 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
930 |
public ElementKind getKind() { |
|
931 |
return ElementKind.MODULE; |
|
932 |
} |
|
933 |
||
934 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
935 |
public java.util.List<Directive> getDirectives() { |
|
936 |
completeUsesProvides(); |
|
937 |
return Collections.unmodifiableList(directives); |
|
938 |
} |
|
939 |
||
940 |
public void completeUsesProvides() { |
|
941 |
if (usesProvidesCompleter != Completer.NULL_COMPLETER) { |
|
942 |
Completer c = usesProvidesCompleter; |
|
943 |
usesProvidesCompleter = Completer.NULL_COMPLETER; |
|
944 |
c.complete(this); |
|
945 |
} |
|
946 |
} |
|
947 |
||
948 |
@Override |
|
949 |
public ClassSymbol outermostClass() { |
|
950 |
return null; |
|
951 |
} |
|
952 |
||
953 |
@Override |
|
954 |
public String toString() { |
|
955 |
// TODO: the following strings should be localized |
|
956 |
// Do this with custom anon subtypes in Symtab |
|
957 |
String n = (name == null) ? "<unknown>" |
|
958 |
: (name.isEmpty()) ? "<unnamed>" |
|
959 |
: String.valueOf(name); |
|
960 |
return n; |
|
961 |
} |
|
962 |
||
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37001
diff
changeset
|
963 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
36526 | 964 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
965 |
return v.visitModule(this, p); |
|
966 |
} |
|
967 |
||
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37001
diff
changeset
|
968 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
36526 | 969 |
public List<Symbol> getEnclosedElements() { |
970 |
List<Symbol> list = List.nil(); |
|
971 |
for (Symbol sym : enclosedPackages) { |
|
972 |
if (sym.members().anyMatch(m -> m.kind == TYP)) |
|
973 |
list = list.prepend(sym); |
|
974 |
} |
|
975 |
return list; |
|
976 |
} |
|
977 |
||
978 |
public void reset() { |
|
979 |
this.directives = null; |
|
980 |
this.requires = null; |
|
981 |
this.exports = null; |
|
982 |
this.provides = null; |
|
983 |
this.uses = null; |
|
984 |
this.visiblePackages = null; |
|
985 |
} |
|
986 |
||
987 |
} |
|
10 | 988 |
|
989 |
/** A class for package symbols |
|
990 |
*/ |
|
991 |
public static class PackageSymbol extends TypeSymbol |
|
992 |
implements PackageElement { |
|
993 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
994 |
public WriteableScope members_field; |
10 | 995 |
public Name fullname; |
996 |
public ClassSymbol package_info; // see bug 6443073 |
|
36526 | 997 |
public ModuleSymbol modle; |
10 | 998 |
|
999 |
public PackageSymbol(Name name, Type type, Symbol owner) { |
|
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
1000 |
super(PCK, 0, name, type, owner); |
10 | 1001 |
this.members_field = null; |
1002 |
this.fullname = formFullName(name, owner); |
|
1003 |
} |
|
1004 |
||
1005 |
public PackageSymbol(Name name, Symbol owner) { |
|
1006 |
this(name, null, owner); |
|
1007 |
this.type = new PackageType(this); |
|
1008 |
} |
|
1009 |
||
1010 |
public String toString() { |
|
1011 |
return fullname.toString(); |
|
1012 |
} |
|
1013 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1014 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1015 |
public Name getQualifiedName() { |
1016 |
return fullname; |
|
1017 |
} |
|
1018 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1019 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1020 |
public boolean isUnnamed() { |
1021 |
return name.isEmpty() && owner != null; |
|
1022 |
} |
|
1023 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1024 |
public WriteableScope members() { |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1025 |
complete(); |
10 | 1026 |
return members_field; |
1027 |
} |
|
1028 |
||
1029 |
public long flags() { |
|
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1030 |
complete(); |
10 | 1031 |
return flags_field; |
1032 |
} |
|
1033 |
||
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1034 |
@Override |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1035 |
public List<Attribute.Compound> getRawAttributes() { |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1036 |
complete(); |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1037 |
if (package_info != null) { |
4871
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
4077
diff
changeset
|
1038 |
package_info.complete(); |
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1039 |
mergeAttributes(); |
4871
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
4077
diff
changeset
|
1040 |
} |
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1041 |
return super.getRawAttributes(); |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1042 |
} |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1043 |
|
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1044 |
private void mergeAttributes() { |
21480 | 1045 |
if (metadata == null && |
1046 |
package_info.metadata != null) { |
|
1047 |
metadata = new SymbolMetadata(this); |
|
1048 |
metadata.setAttributes(package_info.metadata); |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12335
diff
changeset
|
1049 |
} |
10 | 1050 |
} |
1051 |
||
1052 |
/** A package "exists" if a type or package that exists has |
|
1053 |
* been seen within it. |
|
1054 |
*/ |
|
1055 |
public boolean exists() { |
|
1056 |
return (flags_field & EXISTS) != 0; |
|
1057 |
} |
|
1058 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1059 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1060 |
public ElementKind getKind() { |
1061 |
return ElementKind.PACKAGE; |
|
1062 |
} |
|
1063 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1064 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1065 |
public Symbol getEnclosingElement() { |
36526 | 1066 |
return modle != null && !modle.isNoModule() ? modle : null; |
10 | 1067 |
} |
1068 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1069 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1070 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
1071 |
return v.visitPackage(this, p); |
|
1072 |
} |
|
1357 | 1073 |
|
1074 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
|
1075 |
return v.visitPackageSymbol(this, p); |
|
1076 |
} |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1077 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1078 |
/**Resets the Symbol into the state good for next round of annotation processing.*/ |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1079 |
public void reset() { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1080 |
metadata = null; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1081 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1082 |
|
10 | 1083 |
} |
1084 |
||
1085 |
/** A class for class symbols |
|
1086 |
*/ |
|
1087 |
public static class ClassSymbol extends TypeSymbol implements TypeElement { |
|
1088 |
||
1089 |
/** a scope for all class members; variables, methods and inner classes |
|
1090 |
* type parameters are not part of this scope |
|
1091 |
*/ |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1092 |
public WriteableScope members_field; |
10 | 1093 |
|
1094 |
/** the fully qualified name of the class, i.e. pck.outer.inner. |
|
1095 |
* null for anonymous classes |
|
1096 |
*/ |
|
1097 |
public Name fullname; |
|
1098 |
||
1099 |
/** the fully qualified name of the class after converting to flat |
|
1100 |
* representation, i.e. pck.outer$inner, |
|
1101 |
* set externally for local and anonymous classes |
|
1102 |
*/ |
|
1103 |
public Name flatname; |
|
1104 |
||
1105 |
/** the sourcefile where the class came from |
|
1106 |
*/ |
|
1107 |
public JavaFileObject sourcefile; |
|
1108 |
||
1109 |
/** the classfile from where to load this class |
|
1110 |
* this will have extension .class or .java |
|
1111 |
*/ |
|
1112 |
public JavaFileObject classfile; |
|
1113 |
||
10627
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
10626
diff
changeset
|
1114 |
/** the list of translated local classes (used for generating |
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
10626
diff
changeset
|
1115 |
* InnerClasses attribute) |
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
10626
diff
changeset
|
1116 |
*/ |
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
10626
diff
changeset
|
1117 |
public List<ClassSymbol> trans_local; |
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
10626
diff
changeset
|
1118 |
|
10 | 1119 |
/** the constant pool of the class |
1120 |
*/ |
|
1121 |
public Pool pool; |
|
1122 |
||
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1123 |
/** the annotation metadata attached to this class */ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1124 |
private AnnotationTypeMetadata annotationTypeMetadata; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1125 |
|
10 | 1126 |
public ClassSymbol(long flags, Name name, Type type, Symbol owner) { |
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
1127 |
super(TYP, flags, name, type, owner); |
10 | 1128 |
this.members_field = null; |
1129 |
this.fullname = formFullName(name, owner); |
|
1130 |
this.flatname = formFlatName(name, owner); |
|
1131 |
this.sourcefile = null; |
|
1132 |
this.classfile = null; |
|
1133 |
this.pool = null; |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1134 |
this.annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType(); |
10 | 1135 |
} |
1136 |
||
1137 |
public ClassSymbol(long flags, Name name, Symbol owner) { |
|
1138 |
this( |
|
1139 |
flags, |
|
1140 |
name, |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1141 |
new ClassType(Type.noType, null, null), |
10 | 1142 |
owner); |
1143 |
this.type.tsym = this; |
|
1144 |
} |
|
1145 |
||
1146 |
/** The Java source which this symbol represents. |
|
1147 |
*/ |
|
1148 |
public String toString() { |
|
1149 |
return className(); |
|
1150 |
} |
|
1151 |
||
1152 |
public long flags() { |
|
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1153 |
complete(); |
10 | 1154 |
return flags_field; |
1155 |
} |
|
1156 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1157 |
public WriteableScope members() { |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1158 |
complete(); |
10 | 1159 |
return members_field; |
1160 |
} |
|
1161 |
||
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1162 |
@Override |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1163 |
public List<Attribute.Compound> getRawAttributes() { |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1164 |
complete(); |
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1165 |
return super.getRawAttributes(); |
10 | 1166 |
} |
1167 |
||
15385 | 1168 |
@Override |
1169 |
public List<Attribute.TypeCompound> getRawTypeAttributes() { |
|
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1170 |
complete(); |
15385 | 1171 |
return super.getRawTypeAttributes(); |
1172 |
} |
|
1173 |
||
10 | 1174 |
public Type erasure(Types types) { |
1175 |
if (erasure_field == null) |
|
1176 |
erasure_field = new ClassType(types.erasure(type.getEnclosingType()), |
|
24396 | 1177 |
List.<Type>nil(), this, |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1178 |
type.getMetadata()); |
10 | 1179 |
return erasure_field; |
1180 |
} |
|
1181 |
||
1182 |
public String className() { |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
1183 |
if (name.isEmpty()) |
10 | 1184 |
return |
1185 |
Log.getLocalizedString("anonymous.class", flatname); |
|
1186 |
else |
|
1187 |
return fullname.toString(); |
|
1188 |
} |
|
1189 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1190 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1191 |
public Name getQualifiedName() { |
1192 |
return fullname; |
|
1193 |
} |
|
1194 |
||
1195 |
public Name flatName() { |
|
1196 |
return flatname; |
|
1197 |
} |
|
1198 |
||
1199 |
public boolean isSubClass(Symbol base, Types types) { |
|
1200 |
if (this == base) { |
|
1201 |
return true; |
|
1202 |
} 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
|
1203 |
for (Type t = type; t.hasTag(CLASS); t = types.supertype(t)) |
10 | 1204 |
for (List<Type> is = types.interfaces(t); |
1205 |
is.nonEmpty(); |
|
1206 |
is = is.tail) |
|
1207 |
if (is.head.tsym.isSubClass(base, types)) return true; |
|
1208 |
} else { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
1209 |
for (Type t = type; t.hasTag(CLASS); t = types.supertype(t)) |
10 | 1210 |
if (t.tsym == base) return true; |
1211 |
} |
|
1212 |
return false; |
|
1213 |
} |
|
1214 |
||
1215 |
/** Complete the elaboration of this symbol's definition. |
|
1216 |
*/ |
|
1217 |
public void complete() throws CompletionFailure { |
|
1218 |
try { |
|
1219 |
super.complete(); |
|
1220 |
} catch (CompletionFailure ex) { |
|
1221 |
// quiet error recovery |
|
1222 |
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
|
1223 |
this.type = new ErrorType(this, Type.noType); |
10 | 1224 |
throw ex; |
1225 |
} |
|
1226 |
} |
|
1227 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1228 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1229 |
public List<Type> getInterfaces() { |
1230 |
complete(); |
|
1231 |
if (type instanceof ClassType) { |
|
1232 |
ClassType t = (ClassType)type; |
|
1233 |
if (t.interfaces_field == null) // FIXME: shouldn't be null |
|
1234 |
t.interfaces_field = List.nil(); |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8427
diff
changeset
|
1235 |
if (t.all_interfaces_field != null) |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8427
diff
changeset
|
1236 |
return Type.getModelTypes(t.all_interfaces_field); |
10 | 1237 |
return t.interfaces_field; |
1238 |
} else { |
|
1239 |
return List.nil(); |
|
1240 |
} |
|
1241 |
} |
|
1242 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1243 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1244 |
public Type getSuperclass() { |
1245 |
complete(); |
|
1246 |
if (type instanceof ClassType) { |
|
1247 |
ClassType t = (ClassType)type; |
|
1248 |
if (t.supertype_field == null) // FIXME: shouldn't be null |
|
1249 |
t.supertype_field = Type.noType; |
|
1250 |
// An interface has no superclass; its supertype is Object. |
|
1251 |
return t.isInterface() |
|
1252 |
? Type.noType |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8427
diff
changeset
|
1253 |
: t.supertype_field.getModelType(); |
10 | 1254 |
} else { |
1255 |
return Type.noType; |
|
1256 |
} |
|
1257 |
} |
|
1258 |
||
21007 | 1259 |
/** |
1260 |
* Returns the next class to search for inherited annotations or {@code null} |
|
1261 |
* if the next class can't be found. |
|
1262 |
*/ |
|
1263 |
private ClassSymbol getSuperClassToSearchForAnnotations() { |
|
1264 |
||
1265 |
Type sup = getSuperclass(); |
|
1266 |
||
1267 |
if (!sup.hasTag(CLASS) || sup.isErroneous()) |
|
1268 |
return null; |
|
1269 |
||
1270 |
return (ClassSymbol) sup.tsym; |
|
1271 |
} |
|
1272 |
||
1273 |
||
1274 |
@Override |
|
1275 |
protected <A extends Annotation> A[] getInheritedAnnotations(Class<A> annoType) { |
|
1276 |
||
1277 |
ClassSymbol sup = getSuperClassToSearchForAnnotations(); |
|
1278 |
||
1279 |
return sup == null ? super.getInheritedAnnotations(annoType) |
|
1280 |
: sup.getAnnotationsByType(annoType); |
|
1281 |
} |
|
1282 |
||
1283 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1284 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1285 |
public ElementKind getKind() { |
1286 |
long flags = flags(); |
|
1287 |
if ((flags & ANNOTATION) != 0) |
|
1288 |
return ElementKind.ANNOTATION_TYPE; |
|
1289 |
else if ((flags & INTERFACE) != 0) |
|
1290 |
return ElementKind.INTERFACE; |
|
1291 |
else if ((flags & ENUM) != 0) |
|
1292 |
return ElementKind.ENUM; |
|
1293 |
else |
|
1294 |
return ElementKind.CLASS; |
|
1295 |
} |
|
1296 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1297 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
20610
81a202481805
8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents:
20598
diff
changeset
|
1298 |
public Set<Modifier> getModifiers() { |
81a202481805
8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents:
20598
diff
changeset
|
1299 |
long flags = flags(); |
81a202481805
8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents:
20598
diff
changeset
|
1300 |
return Flags.asModifierSet(flags & ~DEFAULT); |
81a202481805
8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents:
20598
diff
changeset
|
1301 |
} |
81a202481805
8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents:
20598
diff
changeset
|
1302 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1303 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1304 |
public NestingKind getNestingKind() { |
1305 |
complete(); |
|
1306 |
if (owner.kind == PCK) |
|
1307 |
return NestingKind.TOP_LEVEL; |
|
1308 |
else if (name.isEmpty()) |
|
1309 |
return NestingKind.ANONYMOUS; |
|
1310 |
else if (owner.kind == MTH) |
|
1311 |
return NestingKind.LOCAL; |
|
1312 |
else |
|
1313 |
return NestingKind.MEMBER; |
|
1314 |
} |
|
1315 |
||
21007 | 1316 |
|
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16333
diff
changeset
|
1317 |
@Override |
21007 | 1318 |
protected <A extends Annotation> Attribute.Compound getAttribute(final Class<A> annoType) { |
1319 |
||
1320 |
Attribute.Compound attrib = super.getAttribute(annoType); |
|
1321 |
||
1322 |
boolean inherited = annoType.isAnnotationPresent(Inherited.class); |
|
1323 |
if (attrib != null || !inherited) |
|
1324 |
return attrib; |
|
1325 |
||
1326 |
// Search supertypes |
|
1327 |
ClassSymbol superType = getSuperClassToSearchForAnnotations(); |
|
1328 |
return superType == null ? null |
|
1329 |
: superType.getAttribute(annoType); |
|
10 | 1330 |
} |
1331 |
||
21007 | 1332 |
|
1333 |
||
1334 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1335 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1336 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
1337 |
return v.visitType(this, p); |
|
1338 |
} |
|
1357 | 1339 |
|
1340 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
|
1341 |
return v.visitClassSymbol(this, p); |
|
1342 |
} |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1343 |
|
28459
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
27224
diff
changeset
|
1344 |
public void markAbstractIfNeeded(Types types) { |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
27224
diff
changeset
|
1345 |
if (types.enter.getEnv(this) != null && |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
27224
diff
changeset
|
1346 |
(flags() & ENUM) != 0 && types.supertype(type).tsym == types.syms.enumSym && |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
27224
diff
changeset
|
1347 |
(flags() & (FINAL | ABSTRACT)) == 0) { |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
27224
diff
changeset
|
1348 |
if (types.firstUnimplementedAbstract(this) != null) |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
27224
diff
changeset
|
1349 |
// add the ABSTRACT flag to an enum |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
27224
diff
changeset
|
1350 |
flags_field |= ABSTRACT; |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
27224
diff
changeset
|
1351 |
} |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
27224
diff
changeset
|
1352 |
} |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
27224
diff
changeset
|
1353 |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1354 |
/**Resets the Symbol into the state good for next round of annotation processing.*/ |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1355 |
public void reset() { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1356 |
kind = TYP; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1357 |
erasure_field = null; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1358 |
members_field = null; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1359 |
flags_field = 0; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1360 |
if (type instanceof ClassType) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1361 |
ClassType t = (ClassType)type; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1362 |
t.setEnclosingType(Type.noType); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1363 |
t.rank_field = -1; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1364 |
t.typarams_field = null; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1365 |
t.allparams_field = null; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1366 |
t.supertype_field = null; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1367 |
t.interfaces_field = null; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1368 |
t.all_interfaces_field = null; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1369 |
} |
39372
a42db8c180c3
8132446: AsssertionError in ClassSymbol.setAnnotationType
sadayapalam
parents:
37848
diff
changeset
|
1370 |
clearAnnotationMetadata(); |
a42db8c180c3
8132446: AsssertionError in ClassSymbol.setAnnotationType
sadayapalam
parents:
37848
diff
changeset
|
1371 |
} |
a42db8c180c3
8132446: AsssertionError in ClassSymbol.setAnnotationType
sadayapalam
parents:
37848
diff
changeset
|
1372 |
|
a42db8c180c3
8132446: AsssertionError in ClassSymbol.setAnnotationType
sadayapalam
parents:
37848
diff
changeset
|
1373 |
public void clearAnnotationMetadata() { |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1374 |
metadata = null; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1375 |
annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1376 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1377 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1378 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1379 |
public AnnotationTypeMetadata getAnnotationTypeMetadata() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1380 |
return annotationTypeMetadata; |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1381 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1382 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1383 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1384 |
public boolean isAnnotationType() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1385 |
return (flags_field & Flags.ANNOTATION) != 0; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1386 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1387 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1388 |
public void setAnnotationTypeMetadata(AnnotationTypeMetadata a) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1389 |
Assert.checkNonNull(a); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1390 |
Assert.check(!annotationTypeMetadata.isMetadataForAnnotationType()); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1391 |
this.annotationTypeMetadata = a; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1392 |
} |
10 | 1393 |
} |
1394 |
||
1395 |
||
1396 |
/** A class for variable symbols |
|
1397 |
*/ |
|
1398 |
public static class VarSymbol extends Symbol implements VariableElement { |
|
1399 |
||
1400 |
/** The variable's declaration position. |
|
1401 |
*/ |
|
1402 |
public int pos = Position.NOPOS; |
|
1403 |
||
1404 |
/** The variable's address. Used for different purposes during |
|
1405 |
* flow analysis, translation and code generation. |
|
1406 |
* Flow analysis: |
|
1407 |
* If this is a blank final or local variable, its sequence number. |
|
1408 |
* Translation: |
|
1409 |
* If this is a private field, its access number. |
|
1410 |
* Code generation: |
|
1411 |
* If this is a local variable, its logical slot number. |
|
1412 |
*/ |
|
1413 |
public int adr = -1; |
|
1414 |
||
1415 |
/** Construct a variable symbol, given its flags, name, type and owner. |
|
1416 |
*/ |
|
1417 |
public VarSymbol(long flags, Name name, Type type, Symbol owner) { |
|
1418 |
super(VAR, flags, name, type, owner); |
|
1419 |
} |
|
1420 |
||
1421 |
/** Clone this symbol with new owner. |
|
1422 |
*/ |
|
1423 |
public VarSymbol clone(Symbol newOwner) { |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1424 |
VarSymbol v = new VarSymbol(flags_field, name, type, newOwner) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1425 |
@Override |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1426 |
public Symbol baseSymbol() { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1427 |
return VarSymbol.this; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1428 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1429 |
}; |
10 | 1430 |
v.pos = pos; |
1431 |
v.adr = adr; |
|
1432 |
v.data = data; |
|
1433 |
// System.out.println("clone " + v + " in " + newOwner);//DEBUG |
|
1434 |
return v; |
|
1435 |
} |
|
1436 |
||
1437 |
public String toString() { |
|
1438 |
return name.toString(); |
|
1439 |
} |
|
1440 |
||
1441 |
public Symbol asMemberOf(Type site, Types types) { |
|
1442 |
return new VarSymbol(flags_field, name, types.memberType(site, this), owner); |
|
1443 |
} |
|
1444 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1445 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1446 |
public ElementKind getKind() { |
1447 |
long flags = flags(); |
|
1448 |
if ((flags & PARAMETER) != 0) { |
|
1449 |
if (isExceptionParameter()) |
|
1450 |
return ElementKind.EXCEPTION_PARAMETER; |
|
1451 |
else |
|
1452 |
return ElementKind.PARAMETER; |
|
1453 |
} else if ((flags & ENUM) != 0) { |
|
1454 |
return ElementKind.ENUM_CONSTANT; |
|
1455 |
} else if (owner.kind == TYP || owner.kind == ERR) { |
|
1456 |
return ElementKind.FIELD; |
|
6718
56ed1962d369
6967842: Element not returned from tree API for ARM resource variables.
sundar
parents:
6592
diff
changeset
|
1457 |
} else if (isResourceVariable()) { |
56ed1962d369
6967842: Element not returned from tree API for ARM resource variables.
sundar
parents:
6592
diff
changeset
|
1458 |
return ElementKind.RESOURCE_VARIABLE; |
10 | 1459 |
} else { |
1460 |
return ElementKind.LOCAL_VARIABLE; |
|
1461 |
} |
|
1462 |
} |
|
1463 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1464 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1465 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
1466 |
return v.visitVariable(this, p); |
|
1467 |
} |
|
1468 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1469 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1470 |
public Object getConstantValue() { // Mirror API |
1471 |
return Constants.decode(getConstValue(), type); |
|
1472 |
} |
|
1473 |
||
1474 |
public void setLazyConstValue(final Env<AttrContext> env, |
|
1475 |
final Attr attr, |
|
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19928
diff
changeset
|
1476 |
final JCVariableDecl variable) |
10 | 1477 |
{ |
1478 |
setData(new Callable<Object>() { |
|
1479 |
public Object call() { |
|
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19928
diff
changeset
|
1480 |
return attr.attribLazyConstantValue(env, variable, type); |
10 | 1481 |
} |
1482 |
}); |
|
1483 |
} |
|
1484 |
||
1485 |
/** |
|
1486 |
* The variable's constant value, if this is a constant. |
|
1487 |
* Before the constant value is evaluated, it points to an |
|
19666
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
19657
diff
changeset
|
1488 |
* initializer environment. If this is not a constant, it can |
10 | 1489 |
* be used for other stuff. |
1490 |
*/ |
|
1491 |
private Object data; |
|
1492 |
||
1493 |
public boolean isExceptionParameter() { |
|
1494 |
return data == ElementKind.EXCEPTION_PARAMETER; |
|
1495 |
} |
|
1496 |
||
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
1497 |
public boolean isResourceVariable() { |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
1498 |
return data == ElementKind.RESOURCE_VARIABLE; |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
1499 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
1500 |
|
10 | 1501 |
public Object getConstValue() { |
1502 |
// 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
|
1503 |
if (data == ElementKind.EXCEPTION_PARAMETER || |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
1504 |
data == ElementKind.RESOURCE_VARIABLE) { |
10 | 1505 |
return null; |
1506 |
} else if (data instanceof Callable<?>) { |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
1507 |
// In this case, this is a final variable, with an as |
10 | 1508 |
// yet unevaluated initializer. |
1509 |
Callable<?> eval = (Callable<?>)data; |
|
1510 |
data = null; // to make sure we don't evaluate this twice. |
|
1511 |
try { |
|
1512 |
data = eval.call(); |
|
1513 |
} catch (Exception ex) { |
|
1514 |
throw new AssertionError(ex); |
|
1515 |
} |
|
1516 |
} |
|
1517 |
return data; |
|
1518 |
} |
|
1519 |
||
1520 |
public void setData(Object data) { |
|
8032 | 1521 |
Assert.check(!(data instanceof Env<?>), this); |
10 | 1522 |
this.data = data; |
1523 |
} |
|
1357 | 1524 |
|
1525 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
|
1526 |
return v.visitVarSymbol(this, p); |
|
1527 |
} |
|
10 | 1528 |
} |
1529 |
||
1530 |
/** A class for method symbols. |
|
1531 |
*/ |
|
1532 |
public static class MethodSymbol extends Symbol implements ExecutableElement { |
|
1533 |
||
1534 |
/** The code of the method. */ |
|
1535 |
public Code code = null; |
|
1536 |
||
15720
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
1537 |
/** The extra (synthetic/mandated) parameters of the method. */ |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
1538 |
public List<VarSymbol> extraParams = List.nil(); |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
1539 |
|
19657
48226ff07b84
8020745: Suspicious MethodParameters attribute generated for local classes capturing local variables
emc
parents:
19492
diff
changeset
|
1540 |
/** The captured local variables in an anonymous class */ |
48226ff07b84
8020745: Suspicious MethodParameters attribute generated for local classes capturing local variables
emc
parents:
19492
diff
changeset
|
1541 |
public List<VarSymbol> capturedLocals = List.nil(); |
48226ff07b84
8020745: Suspicious MethodParameters attribute generated for local classes capturing local variables
emc
parents:
19492
diff
changeset
|
1542 |
|
10 | 1543 |
/** The parameters of the method. */ |
1544 |
public List<VarSymbol> params = null; |
|
1545 |
||
1546 |
/** The names of the parameters */ |
|
1547 |
public List<Name> savedParameterNames; |
|
1548 |
||
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1549 |
/** For an annotation type element, its default value if any. |
10 | 1550 |
* The value is null if none appeared in the method |
1551 |
* declaration. |
|
1552 |
*/ |
|
1553 |
public Attribute defaultValue = null; |
|
1554 |
||
1555 |
/** Construct a method symbol, given its flags, name, type and owner. |
|
1556 |
*/ |
|
1557 |
public MethodSymbol(long flags, Name name, Type type, Symbol owner) { |
|
1558 |
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
|
1559 |
if (owner.type.hasTag(TYPEVAR)) Assert.error(owner + "." + name); |
10 | 1560 |
} |
1561 |
||
1562 |
/** Clone this symbol with new owner. |
|
1563 |
*/ |
|
1564 |
public MethodSymbol clone(Symbol newOwner) { |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1565 |
MethodSymbol m = new MethodSymbol(flags_field, name, type, newOwner) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1566 |
@Override |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1567 |
public Symbol baseSymbol() { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1568 |
return MethodSymbol.this; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1569 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1570 |
}; |
10 | 1571 |
m.code = code; |
1572 |
return m; |
|
1573 |
} |
|
1574 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1575 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
16970
0967fa88590b
8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents:
16967
diff
changeset
|
1576 |
public Set<Modifier> getModifiers() { |
0967fa88590b
8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents:
16967
diff
changeset
|
1577 |
long flags = flags(); |
0967fa88590b
8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents:
16967
diff
changeset
|
1578 |
return Flags.asModifierSet((flags & DEFAULT) != 0 ? flags & ~ABSTRACT : flags); |
0967fa88590b
8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents:
16967
diff
changeset
|
1579 |
} |
0967fa88590b
8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents:
16967
diff
changeset
|
1580 |
|
10 | 1581 |
/** The Java source which this symbol represents. |
1582 |
*/ |
|
1583 |
public String toString() { |
|
1584 |
if ((flags() & BLOCK) != 0) { |
|
1585 |
return owner.name.toString(); |
|
1586 |
} else { |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
1587 |
String s = (name == name.table.names.init) |
10 | 1588 |
? owner.name.toString() |
1589 |
: name.toString(); |
|
1590 |
if (type != null) { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
1591 |
if (type.hasTag(FORALL)) |
10 | 1592 |
s = "<" + ((ForAll)type).getTypeArguments() + ">" + s; |
1593 |
s += "(" + type.argtypes((flags() & VARARGS) != 0) + ")"; |
|
1594 |
} |
|
1595 |
return s; |
|
1596 |
} |
|
1597 |
} |
|
1598 |
||
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1599 |
public boolean isDynamic() { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1600 |
return false; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1601 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1602 |
|
10 | 1603 |
/** find a symbol that this (proxy method) symbol implements. |
1604 |
* @param c The class whose members are searched for |
|
1605 |
* implementations |
|
1606 |
*/ |
|
1607 |
public Symbol implemented(TypeSymbol c, Types types) { |
|
1608 |
Symbol impl = null; |
|
1609 |
for (List<Type> is = types.interfaces(c.type); |
|
1610 |
impl == null && is.nonEmpty(); |
|
1611 |
is = is.tail) { |
|
1612 |
TypeSymbol i = is.head.tsym; |
|
7628
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1613 |
impl = implementedIn(i, types); |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1614 |
if (impl == null) |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1615 |
impl = implemented(i, types); |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1616 |
} |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1617 |
return impl; |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1618 |
} |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1619 |
|
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1620 |
public Symbol implementedIn(TypeSymbol c, Types types) { |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1621 |
Symbol impl = null; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1622 |
for (Symbol sym : c.members().getSymbolsByName(name)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1623 |
if (this.overrides(sym, (TypeSymbol)owner, types, true) && |
7628
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1624 |
// FIXME: I suspect the following requires a |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1625 |
// subst() for a parametric return type. |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1626 |
types.isSameType(type.getReturnType(), |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1627 |
types.memberType(owner.type, sym).getReturnType())) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1628 |
impl = sym; |
10 | 1629 |
} |
1630 |
} |
|
1631 |
return impl; |
|
1632 |
} |
|
1633 |
||
1634 |
/** Will the erasure of this method be considered by the VM to |
|
1635 |
* override the erasure of the other when seen from class `origin'? |
|
1636 |
*/ |
|
1637 |
public boolean binaryOverrides(Symbol _other, TypeSymbol origin, Types types) { |
|
1638 |
if (isConstructor() || _other.kind != MTH) return false; |
|
1639 |
||
1640 |
if (this == _other) return true; |
|
1641 |
MethodSymbol other = (MethodSymbol)_other; |
|
1642 |
||
1643 |
// check for a direct implementation |
|
1644 |
if (other.isOverridableIn((TypeSymbol)owner) && |
|
1645 |
types.asSuper(owner.type, other.owner) != null && |
|
1646 |
types.isSameType(erasure(types), other.erasure(types))) |
|
1647 |
return true; |
|
1648 |
||
1649 |
// check for an inherited implementation |
|
1650 |
return |
|
1651 |
(flags() & ABSTRACT) == 0 && |
|
1652 |
other.isOverridableIn(origin) && |
|
1653 |
this.isMemberOf(origin, types) && |
|
1654 |
types.isSameType(erasure(types), other.erasure(types)); |
|
1655 |
} |
|
1656 |
||
1657 |
/** The implementation of this (abstract) symbol in class origin, |
|
1658 |
* from the VM's point of view, null if method does not have an |
|
1659 |
* implementation in class. |
|
1660 |
* @param origin The class of which the implementation is a member. |
|
1661 |
*/ |
|
1662 |
public MethodSymbol binaryImplementation(ClassSymbol origin, Types types) { |
|
1663 |
for (TypeSymbol c = origin; c != null; c = types.supertype(c.type).tsym) { |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1664 |
for (Symbol sym : c.members().getSymbolsByName(name)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1665 |
if (sym.kind == MTH && |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1666 |
((MethodSymbol)sym).binaryOverrides(this, origin, types)) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1667 |
return (MethodSymbol)sym; |
10 | 1668 |
} |
1669 |
} |
|
1670 |
return null; |
|
1671 |
} |
|
1672 |
||
1673 |
/** Does this symbol override `other' symbol, when both are seen as |
|
1674 |
* members of class `origin'? It is assumed that _other is a member |
|
1675 |
* of origin. |
|
1676 |
* |
|
1677 |
* It is assumed that both symbols have the same name. The static |
|
1678 |
* modifier is ignored for this test. |
|
1679 |
* |
|
33367 | 1680 |
* A quirk in the works is that if the receiver is a method symbol for |
1681 |
* an inherited abstract method we answer false summarily all else being |
|
1682 |
* immaterial. Abstract "own" methods (i.e `this' is a direct member of |
|
1683 |
* origin) don't get rejected as summarily and are put to test against the |
|
1684 |
* suitable criteria. |
|
1685 |
* |
|
10 | 1686 |
* See JLS 8.4.6.1 (without transitivity) and 8.4.6.4 |
1687 |
*/ |
|
1688 |
public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) { |
|
33367 | 1689 |
return overrides(_other, origin, types, checkResult, true); |
1690 |
} |
|
1691 |
||
1692 |
/** Does this symbol override `other' symbol, when both are seen as |
|
1693 |
* members of class `origin'? It is assumed that _other is a member |
|
1694 |
* of origin. |
|
1695 |
* |
|
1696 |
* Caveat: If `this' is an abstract inherited member of origin, it is |
|
1697 |
* deemed to override `other' only when `requireConcreteIfInherited' |
|
1698 |
* is false. |
|
1699 |
* |
|
1700 |
* It is assumed that both symbols have the same name. The static |
|
1701 |
* modifier is ignored for this test. |
|
1702 |
* |
|
1703 |
* See JLS 8.4.6.1 (without transitivity) and 8.4.6.4 |
|
1704 |
*/ |
|
1705 |
public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult, |
|
1706 |
boolean requireConcreteIfInherited) { |
|
10 | 1707 |
if (isConstructor() || _other.kind != MTH) return false; |
1708 |
||
1709 |
if (this == _other) return true; |
|
1710 |
MethodSymbol other = (MethodSymbol)_other; |
|
1711 |
||
1712 |
// check for a direct implementation |
|
1713 |
if (other.isOverridableIn((TypeSymbol)owner) && |
|
1714 |
types.asSuper(owner.type, other.owner) != null) { |
|
1715 |
Type mt = types.memberType(owner.type, this); |
|
1716 |
Type ot = types.memberType(owner.type, other); |
|
1717 |
if (types.isSubSignature(mt, ot)) { |
|
1718 |
if (!checkResult) |
|
1719 |
return true; |
|
1720 |
if (types.returnTypeSubstitutable(mt, ot)) |
|
1721 |
return true; |
|
1722 |
} |
|
1723 |
} |
|
1724 |
||
1725 |
// check for an inherited implementation |
|
33367 | 1726 |
if (((flags() & ABSTRACT) != 0 && requireConcreteIfInherited) || |
14547 | 1727 |
((other.flags() & ABSTRACT) == 0 && (other.flags() & DEFAULT) == 0) || |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1728 |
!other.isOverridableIn(origin) || |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1729 |
!this.isMemberOf(origin, types)) |
10 | 1730 |
return false; |
1731 |
||
1732 |
// assert types.asSuper(origin.type, other.owner) != null; |
|
1733 |
Type mt = types.memberType(origin.type, this); |
|
1734 |
Type ot = types.memberType(origin.type, other); |
|
1735 |
return |
|
1736 |
types.isSubSignature(mt, ot) && |
|
14547 | 1737 |
(!checkResult || types.resultSubtype(mt, ot, types.noWarnings)); |
10 | 1738 |
} |
1739 |
||
1740 |
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
|
1741 |
// JLS 8.4.6.1 |
10 | 1742 |
switch ((int)(flags_field & Flags.AccessFlags)) { |
1743 |
case Flags.PRIVATE: |
|
1744 |
return false; |
|
1745 |
case Flags.PUBLIC: |
|
15377
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1746 |
return !this.owner.isInterface() || |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1747 |
(flags_field & STATIC) == 0; |
10 | 1748 |
case Flags.PROTECTED: |
1749 |
return (origin.flags() & INTERFACE) == 0; |
|
1750 |
case 0: |
|
1751 |
// for package private: can only override in the same |
|
1752 |
// package |
|
1753 |
return |
|
1754 |
this.packge() == origin.packge() && |
|
1755 |
(origin.flags() & INTERFACE) == 0; |
|
1756 |
default: |
|
1757 |
return false; |
|
1758 |
} |
|
1759 |
} |
|
1760 |
||
15377
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1761 |
@Override |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1762 |
public boolean isInheritedIn(Symbol clazz, Types types) { |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1763 |
switch ((int)(flags_field & Flags.AccessFlags)) { |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1764 |
case PUBLIC: |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1765 |
return !this.owner.isInterface() || |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1766 |
clazz == owner || |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1767 |
(flags_field & STATIC) == 0; |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1768 |
default: |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1769 |
return super.isInheritedIn(clazz, types); |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1770 |
} |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1771 |
} |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1772 |
|
33364
542040bb5990
8138729: javac -parameters should not emit parameter names for lambda expressions
sadayapalam
parents:
30066
diff
changeset
|
1773 |
public boolean isLambdaMethod() { |
542040bb5990
8138729: javac -parameters should not emit parameter names for lambda expressions
sadayapalam
parents:
30066
diff
changeset
|
1774 |
return (flags() & LAMBDA_METHOD) == LAMBDA_METHOD; |
542040bb5990
8138729: javac -parameters should not emit parameter names for lambda expressions
sadayapalam
parents:
30066
diff
changeset
|
1775 |
} |
542040bb5990
8138729: javac -parameters should not emit parameter names for lambda expressions
sadayapalam
parents:
30066
diff
changeset
|
1776 |
|
10 | 1777 |
/** The implementation of this (abstract) symbol in class origin; |
1778 |
* null if none exists. Synthetic methods are not considered |
|
1779 |
* as possible implementations. |
|
1780 |
*/ |
|
1781 |
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
|
1782 |
return implementation(origin, types, checkResult, implementation_filter); |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1783 |
} |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1784 |
// where |
16320
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
15720
diff
changeset
|
1785 |
public static final Filter<Symbol> implementation_filter = new Filter<Symbol>() { |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1786 |
public boolean accepts(Symbol s) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
1787 |
return s.kind == MTH && |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1788 |
(s.flags() & SYNTHETIC) == 0; |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1789 |
} |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1790 |
}; |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1791 |
|
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1792 |
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
|
1793 |
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
|
1794 |
if (res != null) |
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3149
diff
changeset
|
1795 |
return res; |
10 | 1796 |
// if origin is derived from a raw type, we might have missed |
1797 |
// an implementation because we do not know enough about instantiations. |
|
1798 |
// 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
|
1799 |
if (types.isDerivedRaw(origin.type) && !origin.isInterface()) |
10 | 1800 |
return implementation(types.supertype(origin.type).tsym, types, checkResult); |
1801 |
else |
|
1802 |
return null; |
|
1803 |
} |
|
1804 |
||
1805 |
public List<VarSymbol> params() { |
|
1806 |
owner.complete(); |
|
1807 |
if (params == null) { |
|
4077
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1808 |
// 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
|
1809 |
// 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
|
1810 |
// 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
|
1811 |
// 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
|
1812 |
// 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
|
1813 |
// 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
|
1814 |
// savedParameterNames will be null. |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1815 |
List<Name> paramNames = savedParameterNames; |
10 | 1816 |
savedParameterNames = null; |
4077
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1817 |
// 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
|
1818 |
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
|
1819 |
paramNames = List.nil(); |
15031
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14961
diff
changeset
|
1820 |
} |
22163 | 1821 |
ListBuffer<VarSymbol> buf = new ListBuffer<>(); |
4077
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1822 |
List<Name> remaining = paramNames; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1823 |
// 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
|
1824 |
// 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
|
1825 |
int i = 0; |
10 | 1826 |
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
|
1827 |
Name paramName; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1828 |
if (remaining.isEmpty()) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1829 |
// 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
|
1830 |
paramName = createArgName(i, paramNames); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1831 |
} else { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1832 |
paramName = remaining.head; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1833 |
remaining = remaining.tail; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1834 |
if (paramName.isEmpty()) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1835 |
// 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
|
1836 |
paramName = createArgName(i, paramNames); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1837 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1838 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1839 |
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
|
1840 |
i++; |
10 | 1841 |
} |
1842 |
params = buf.toList(); |
|
1843 |
} |
|
1844 |
return params; |
|
1845 |
} |
|
1846 |
||
4077
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1847 |
// 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
|
1848 |
// 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
|
1849 |
// 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
|
1850 |
// 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
|
1851 |
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
|
1852 |
String prefix = "arg"; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1853 |
while (true) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1854 |
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
|
1855 |
if (!exclude.contains(argName)) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1856 |
return argName; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1857 |
prefix += "$"; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1858 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1859 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
1860 |
|
10 | 1861 |
public Symbol asMemberOf(Type site, Types types) { |
1862 |
return new MethodSymbol(flags_field, name, types.memberType(site, this), owner); |
|
1863 |
} |
|
1864 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1865 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1866 |
public ElementKind getKind() { |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
1867 |
if (name == name.table.names.init) |
10 | 1868 |
return ElementKind.CONSTRUCTOR; |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
1869 |
else if (name == name.table.names.clinit) |
10 | 1870 |
return ElementKind.STATIC_INIT; |
10626
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
1871 |
else if ((flags() & BLOCK) != 0) |
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
1872 |
return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT; |
10 | 1873 |
else |
1874 |
return ElementKind.METHOD; |
|
1875 |
} |
|
1876 |
||
10626
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
1877 |
public boolean isStaticOrInstanceInit() { |
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
1878 |
return getKind() == ElementKind.STATIC_INIT || |
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
1879 |
getKind() == ElementKind.INSTANCE_INIT; |
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
1880 |
} |
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
1881 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1882 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1883 |
public Attribute getDefaultValue() { |
1884 |
return defaultValue; |
|
1885 |
} |
|
1886 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1887 |
@DefinedBy(Api.LANGUAGE_MODEL) |
15385 | 1888 |
public List<VarSymbol> getParameters() { |
10 | 1889 |
return params(); |
1890 |
} |
|
1891 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1892 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1893 |
public boolean isVarArgs() { |
1894 |
return (flags() & VARARGS) != 0; |
|
1895 |
} |
|
1896 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1897 |
@DefinedBy(Api.LANGUAGE_MODEL) |
14956
185bd7c693d8
8005046: Provide checking for a default method in javax.lang.model
darcy
parents:
14547
diff
changeset
|
1898 |
public boolean isDefault() { |
185bd7c693d8
8005046: Provide checking for a default method in javax.lang.model
darcy
parents:
14547
diff
changeset
|
1899 |
return (flags() & DEFAULT) != 0; |
185bd7c693d8
8005046: Provide checking for a default method in javax.lang.model
darcy
parents:
14547
diff
changeset
|
1900 |
} |
185bd7c693d8
8005046: Provide checking for a default method in javax.lang.model
darcy
parents:
14547
diff
changeset
|
1901 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1902 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1903 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
1904 |
return v.visitExecutable(this, p); |
|
1905 |
} |
|
1906 |
||
1357 | 1907 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
1908 |
return v.visitMethodSymbol(this, p); |
|
1909 |
} |
|
1910 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1911 |
@DefinedBy(Api.LANGUAGE_MODEL) |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16333
diff
changeset
|
1912 |
public Type getReceiverType() { |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16333
diff
changeset
|
1913 |
return asType().getReceiverType(); |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16333
diff
changeset
|
1914 |
} |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16333
diff
changeset
|
1915 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1916 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1917 |
public Type getReturnType() { |
1918 |
return asType().getReturnType(); |
|
1919 |
} |
|
1920 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1921 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1922 |
public List<Type> getThrownTypes() { |
1923 |
return asType().getThrownTypes(); |
|
1924 |
} |
|
1925 |
} |
|
1926 |
||
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1927 |
/** A class for invokedynamic method calls. |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1928 |
*/ |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1929 |
public static class DynamicMethodSymbol extends MethodSymbol { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1930 |
|
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1931 |
public Object[] staticArgs; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1932 |
public Symbol bsm; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1933 |
public int bsmKind; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1934 |
|
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1935 |
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
|
1936 |
super(0, name, type, owner); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1937 |
this.bsm = bsm; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1938 |
this.bsmKind = bsmKind; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1939 |
this.staticArgs = staticArgs; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1940 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1941 |
|
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1942 |
@Override |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1943 |
public boolean isDynamic() { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1944 |
return true; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1945 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1946 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1947 |
|
10 | 1948 |
/** A class for predefined operators. |
1949 |
*/ |
|
1950 |
public static class OperatorSymbol extends MethodSymbol { |
|
1951 |
||
1952 |
public int opcode; |
|
1953 |
||
1954 |
public OperatorSymbol(Name name, Type type, int opcode, Symbol owner) { |
|
1955 |
super(PUBLIC | STATIC, name, type, owner); |
|
1956 |
this.opcode = opcode; |
|
1957 |
} |
|
1357 | 1958 |
|
1959 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
|
1960 |
return v.visitOperatorSymbol(this, p); |
|
1961 |
} |
|
10 | 1962 |
} |
1963 |
||
1964 |
/** Symbol completer interface. |
|
1965 |
*/ |
|
1966 |
public static interface Completer { |
|
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1967 |
|
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1968 |
/** Dummy completer to be used when the symbol has been completed or |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1969 |
* does not need completion. |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1970 |
*/ |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1971 |
public final static Completer NULL_COMPLETER = new Completer() { |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1972 |
public void complete(Symbol sym) { } |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1973 |
public boolean isTerminal() { return true; } |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1974 |
}; |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1975 |
|
10 | 1976 |
void complete(Symbol sym) throws CompletionFailure; |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1977 |
|
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1978 |
/** Returns true if this completer is <em>terminal</em>. A terminal |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1979 |
* completer is used as a place holder when the symbol is completed. |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1980 |
* Calling complete on a terminal completer will not affect the symbol. |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1981 |
* |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1982 |
* The dummy NULL_COMPLETER and the GraphDependencies completer are |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1983 |
* examples of terminal completers. |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1984 |
* |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1985 |
* @return true iff this completer is terminal |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1986 |
*/ |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1987 |
default boolean isTerminal() { |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1988 |
return false; |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1989 |
} |
10 | 1990 |
} |
1991 |
||
1992 |
public static class CompletionFailure extends RuntimeException { |
|
1993 |
private static final long serialVersionUID = 0; |
|
1994 |
public Symbol sym; |
|
1995 |
||
169 | 1996 |
/** A diagnostic object describing the failure |
1997 |
*/ |
|
1998 |
public JCDiagnostic diag; |
|
1999 |
||
10 | 2000 |
/** A localized string describing the failure. |
169 | 2001 |
* @deprecated Use {@code getDetail()} or {@code getMessage()} |
10 | 2002 |
*/ |
169 | 2003 |
@Deprecated |
10 | 2004 |
public String errmsg; |
2005 |
||
2006 |
public CompletionFailure(Symbol sym, String errmsg) { |
|
2007 |
this.sym = sym; |
|
2008 |
this.errmsg = errmsg; |
|
2009 |
// this.printStackTrace();//DEBUG |
|
2010 |
} |
|
2011 |
||
169 | 2012 |
public CompletionFailure(Symbol sym, JCDiagnostic diag) { |
2013 |
this.sym = sym; |
|
2014 |
this.diag = diag; |
|
2015 |
// this.printStackTrace();//DEBUG |
|
2016 |
} |
|
2017 |
||
2018 |
public JCDiagnostic getDiagnostic() { |
|
2019 |
return diag; |
|
2020 |
} |
|
2021 |
||
2022 |
@Override |
|
10 | 2023 |
public String getMessage() { |
169 | 2024 |
if (diag != null) |
2025 |
return diag.getMessage(null); |
|
2026 |
else |
|
2027 |
return errmsg; |
|
2028 |
} |
|
2029 |
||
2030 |
public Object getDetailValue() { |
|
2031 |
return (diag != null ? diag : errmsg); |
|
10 | 2032 |
} |
2033 |
||
2034 |
@Override |
|
2035 |
public CompletionFailure initCause(Throwable cause) { |
|
2036 |
super.initCause(cause); |
|
2037 |
return this; |
|
2038 |
} |
|
2039 |
||
2040 |
} |
|
1357 | 2041 |
|
2042 |
/** |
|
2043 |
* A visitor for symbols. A visitor is used to implement operations |
|
2044 |
* (or relations) on symbols. Most common operations on types are |
|
2045 |
* binary relations and this interface is designed for binary |
|
2046 |
* relations, that is, operations on the form |
|
2047 |
* Symbol × P → R. |
|
2048 |
* <!-- In plain text: Type x P -> R --> |
|
2049 |
* |
|
2050 |
* @param <R> the return type of the operation implemented by this |
|
2051 |
* visitor; use Void if no return type is needed. |
|
2052 |
* @param <P> the type of the second argument (the first being the |
|
2053 |
* symbol itself) of the operation implemented by this visitor; use |
|
2054 |
* Void if a second argument is not needed. |
|
2055 |
*/ |
|
2056 |
public interface Visitor<R,P> { |
|
2057 |
R visitClassSymbol(ClassSymbol s, P arg); |
|
2058 |
R visitMethodSymbol(MethodSymbol s, P arg); |
|
2059 |
R visitPackageSymbol(PackageSymbol s, P arg); |
|
2060 |
R visitOperatorSymbol(OperatorSymbol s, P arg); |
|
2061 |
R visitVarSymbol(VarSymbol s, P arg); |
|
2062 |
R visitTypeSymbol(TypeSymbol s, P arg); |
|
2063 |
R visitSymbol(Symbol s, P arg); |
|
2064 |
} |
|
10 | 2065 |
} |