author | jlahoda |
Mon, 21 Oct 2019 15:38:26 +0200 | |
changeset 58713 | ad69fd32778e |
parent 58350 | e23e560afbcb |
permissions | -rw-r--r-- |
10 | 1 |
/* |
54514
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
2 |
* Copyright (c) 1999, 2019, 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; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
31 |
import java.util.EnumSet; |
36526 | 32 |
import java.util.Map; |
10 | 33 |
import java.util.Set; |
34 |
import java.util.concurrent.Callable; |
|
54339
f69a2f675f19
8221118: Avoid eagerly creating JCDiagnostic for CompletionFailures
ronsh
parents:
49197
diff
changeset
|
35 |
import java.util.function.Supplier; |
14258 | 36 |
|
36526 | 37 |
import javax.lang.model.element.Element; |
38 |
import javax.lang.model.element.ElementKind; |
|
39 |
import javax.lang.model.element.ElementVisitor; |
|
40 |
import javax.lang.model.element.ExecutableElement; |
|
41 |
import javax.lang.model.element.Modifier; |
|
42 |
import javax.lang.model.element.ModuleElement; |
|
43 |
import javax.lang.model.element.NestingKind; |
|
44 |
import javax.lang.model.element.PackageElement; |
|
45 |
import javax.lang.model.element.TypeElement; |
|
46 |
import javax.lang.model.element.TypeParameterElement; |
|
47 |
import javax.lang.model.element.VariableElement; |
|
48 |
import javax.tools.JavaFileManager; |
|
10 | 49 |
import javax.tools.JavaFileObject; |
50 |
||
36526 | 51 |
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
|
52 |
import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata; |
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.*; |
|
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
58 |
import com.sun.tools.javac.jvm.PoolConstant; |
39920
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
59 |
import com.sun.tools.javac.tree.JCTree.JCFieldAccess; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
60 |
import com.sun.tools.javac.tree.JCTree.JCVariableDecl; |
39920
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
61 |
import com.sun.tools.javac.tree.JCTree.Tag; |
14258 | 62 |
import com.sun.tools.javac.util.*; |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
63 |
import com.sun.tools.javac.util.DefinedBy.Api; |
14258 | 64 |
import com.sun.tools.javac.util.Name; |
36526 | 65 |
|
10 | 66 |
import static com.sun.tools.javac.code.Flags.*; |
67 |
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
|
68 |
import static com.sun.tools.javac.code.Kinds.Kind.*; |
54514
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
69 |
import com.sun.tools.javac.code.MissingInfoHandler; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
70 |
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; |
49197
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
71 |
import com.sun.tools.javac.code.Scope.WriteableScope; |
54514
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
72 |
import com.sun.tools.javac.code.Symbol; |
39920
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
73 |
import static com.sun.tools.javac.code.Symbol.OperatorSymbol.AccessCode.FIRSTASGOP; |
54514
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
74 |
import com.sun.tools.javac.code.Type; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
75 |
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
|
76 |
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
|
77 |
import static com.sun.tools.javac.code.TypeTag.TYPEVAR; |
39920
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
78 |
import static com.sun.tools.javac.jvm.ByteCodes.iadd; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
79 |
import static com.sun.tools.javac.jvm.ByteCodes.ishll; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
80 |
import static com.sun.tools.javac.jvm.ByteCodes.lushrl; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
81 |
import static com.sun.tools.javac.jvm.ByteCodes.lxor; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
82 |
import static com.sun.tools.javac.jvm.ByteCodes.string_add; |
54514
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
83 |
import com.sun.tools.javac.util.Name; |
10 | 84 |
|
85 |
/** Root class for Java symbols. It contains subclasses |
|
86 |
* for specific sorts of symbols, such as variables, methods and operators, |
|
87 |
* types, packages. Each subclass is represented as a static inner class |
|
88 |
* inside Symbol. |
|
89 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
90 |
* <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
|
91 |
* If you write code that depends on this, you do so at your own risk. |
10 | 92 |
* This code and its internal interfaces are subject to change or |
93 |
* deletion without notice.</b> |
|
94 |
*/ |
|
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
95 |
public abstract class Symbol extends AnnoConstruct implements PoolConstant, Element { |
10 | 96 |
|
97 |
/** The kind of this symbol. |
|
98 |
* @see Kinds |
|
99 |
*/ |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
100 |
public Kind kind; |
10 | 101 |
|
102 |
/** The flags of this symbol. |
|
103 |
*/ |
|
104 |
public long flags_field; |
|
105 |
||
106 |
/** An accessor method for the flags of this symbol. |
|
107 |
* Flags of class symbols should be accessed through the accessor |
|
108 |
* method to make sure that the class symbol is loaded. |
|
109 |
*/ |
|
110 |
public long flags() { return flags_field; } |
|
111 |
||
112 |
/** The name of this symbol in Utf8 representation. |
|
113 |
*/ |
|
114 |
public Name name; |
|
115 |
||
116 |
/** The type of this symbol. |
|
117 |
*/ |
|
118 |
public Type type; |
|
119 |
||
120 |
/** The owner of this symbol. |
|
121 |
*/ |
|
122 |
public Symbol owner; |
|
123 |
||
124 |
/** The completer of this symbol. |
|
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
125 |
* This should never equal null (NULL_COMPLETER should be used instead). |
10 | 126 |
*/ |
127 |
public Completer completer; |
|
128 |
||
129 |
/** A cache for the type erasure of this symbol. |
|
130 |
*/ |
|
131 |
public Type erasure_field; |
|
132 |
||
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
133 |
// <editor-fold defaultstate="collapsed" desc="annotations"> |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
134 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
135 |
/** 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
|
136 |
* 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
|
137 |
*/ |
21480 | 138 |
protected SymbolMetadata metadata; |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
139 |
|
21007 | 140 |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
141 |
/** 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
|
142 |
* 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
|
143 |
* 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
|
144 |
*/ |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
145 |
public List<Attribute.Compound> getRawAttributes() { |
21480 | 146 |
return (metadata == null) |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
147 |
? List.nil() |
21480 | 148 |
: metadata.getDeclarationAttributes(); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
149 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
150 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
151 |
/** 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
|
152 |
* 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
|
153 |
* 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
|
154 |
*/ |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
155 |
public List<Attribute.TypeCompound> getRawTypeAttributes() { |
21480 | 156 |
return (metadata == null) |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
157 |
? List.nil() |
21480 | 158 |
: metadata.getTypeAttributes(); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
159 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
160 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
161 |
/** 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
|
162 |
public Attribute.Compound attribute(Symbol anno) { |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
163 |
for (Attribute.Compound a : getRawAttributes()) { |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
164 |
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
|
165 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
166 |
return null; |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
167 |
} |
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 |
public boolean annotationsPendingCompletion() { |
21480 | 170 |
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
|
171 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
172 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
173 |
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
|
174 |
if (l.nonEmpty()) { |
21480 | 175 |
initedMetadata().append(l); |
18010
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 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
178 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
179 |
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
|
180 |
if (l.nonEmpty()) { |
21480 | 181 |
initedMetadata().appendClassInitTypeAttributes(l); |
18010
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 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
184 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
185 |
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
|
186 |
if (l.nonEmpty()) { |
21480 | 187 |
initedMetadata().appendInitTypeAttributes(l); |
18010
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 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
190 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
191 |
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
|
192 |
if (l.nonEmpty()) { |
21480 | 193 |
initedMetadata().appendUniqueTypes(l); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
194 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
195 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
196 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
197 |
public List<Attribute.TypeCompound> getClassInitTypeAttributes() { |
21480 | 198 |
return (metadata == null) |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
199 |
? List.nil() |
21480 | 200 |
: metadata.getClassInitTypeAttributes(); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
201 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
202 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
203 |
public List<Attribute.TypeCompound> getInitTypeAttributes() { |
21480 | 204 |
return (metadata == null) |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
205 |
? List.nil() |
21480 | 206 |
: metadata.getInitTypeAttributes(); |
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 |
|
33712
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33367
diff
changeset
|
209 |
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
|
210 |
initedMetadata().setInitTypeAttributes(l); |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33367
diff
changeset
|
211 |
} |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33367
diff
changeset
|
212 |
|
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33367
diff
changeset
|
213 |
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
|
214 |
initedMetadata().setClassInitTypeAttributes(l); |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33367
diff
changeset
|
215 |
} |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33367
diff
changeset
|
216 |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
217 |
public List<Attribute.Compound> getDeclarationAttributes() { |
21480 | 218 |
return (metadata == null) |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
219 |
? List.nil() |
21480 | 220 |
: metadata.getDeclarationAttributes(); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
221 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
222 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
223 |
public boolean hasAnnotations() { |
21480 | 224 |
return (metadata != null && !metadata.isEmpty()); |
18010
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 boolean hasTypeAnnotations() { |
21480 | 228 |
return (metadata != null && !metadata.isTypesEmpty()); |
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 |
|
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
231 |
public boolean isCompleted() { |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
232 |
return completer.isTerminal(); |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
233 |
} |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
234 |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
235 |
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
|
236 |
if (l.nonEmpty()) { |
21480 | 237 |
initedMetadata().prepend(l); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
238 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
239 |
} |
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 |
public void resetAnnotations() { |
21480 | 242 |
initedMetadata().reset(); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
243 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
244 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
245 |
public void setAttributes(Symbol other) { |
21480 | 246 |
if (metadata != null || other.metadata != null) { |
247 |
initedMetadata().setAttributes(other.metadata); |
|
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 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
251 |
public void setDeclarationAttributes(List<Attribute.Compound> a) { |
21480 | 252 |
if (metadata != null || a.nonEmpty()) { |
253 |
initedMetadata().setDeclarationAttributes(a); |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
254 |
} |
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 |
public void setTypeAttributes(List<Attribute.TypeCompound> a) { |
21480 | 258 |
if (metadata != null || a.nonEmpty()) { |
259 |
if (metadata == null) |
|
260 |
metadata = new SymbolMetadata(this); |
|
261 |
metadata.setTypeAttributes(a); |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
262 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
263 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
264 |
|
21480 | 265 |
private SymbolMetadata initedMetadata() { |
266 |
if (metadata == null) |
|
267 |
metadata = new SymbolMetadata(this); |
|
268 |
return metadata; |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
269 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
270 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
271 |
/** This method is intended for debugging only. */ |
21480 | 272 |
public SymbolMetadata getMetadata() { |
273 |
return metadata; |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
274 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
275 |
|
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
276 |
// </editor-fold> |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
277 |
|
10 | 278 |
/** Construct a symbol with given kind, flags, name, type and owner. |
279 |
*/ |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
280 |
public Symbol(Kind kind, long flags, Name name, Type type, Symbol owner) { |
10 | 281 |
this.kind = kind; |
282 |
this.flags_field = flags; |
|
283 |
this.type = type; |
|
284 |
this.owner = owner; |
|
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
285 |
this.completer = Completer.NULL_COMPLETER; |
10 | 286 |
this.erasure_field = null; |
287 |
this.name = name; |
|
288 |
} |
|
289 |
||
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
290 |
@Override |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
291 |
public int poolTag() { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
292 |
throw new AssertionError("Invalid pool entry"); |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
293 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
294 |
|
10 | 295 |
/** Clone this symbol with new owner. |
296 |
* Legal only for fields and methods. |
|
297 |
*/ |
|
298 |
public Symbol clone(Symbol newOwner) { |
|
299 |
throw new AssertionError(); |
|
300 |
} |
|
301 |
||
1357 | 302 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
303 |
return v.visitSymbol(this, p); |
|
304 |
} |
|
305 |
||
10 | 306 |
/** The Java source which this symbol represents. |
307 |
* A description of this symbol; overrides Object. |
|
308 |
*/ |
|
309 |
public String toString() { |
|
310 |
return name.toString(); |
|
311 |
} |
|
312 |
||
313 |
/** 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
|
314 |
* error reporting. |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
315 |
* |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
316 |
* @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
|
317 |
* the default package; otherwise, the owner symbol is returned |
10 | 318 |
*/ |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
319 |
public Symbol location() { |
10626
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
320 |
if (owner.name == null || (owner.name.isEmpty() && |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
321 |
(owner.flags() & BLOCK) == 0 && |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
322 |
owner.kind != PCK && |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
323 |
owner.kind != TYP)) { |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
324 |
return null; |
10 | 325 |
} |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
326 |
return owner; |
10 | 327 |
} |
328 |
||
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
329 |
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
|
330 |
if (owner.name == null || owner.name.isEmpty()) { |
10 | 331 |
return location(); |
332 |
} |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
333 |
if (owner.type.hasTag(CLASS)) { |
10 | 334 |
Type ownertype = types.asOuterSuper(site, owner); |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
335 |
if (ownertype != null) return ownertype.tsym; |
10 | 336 |
} |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
337 |
return owner; |
10 | 338 |
} |
339 |
||
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14046
diff
changeset
|
340 |
public Symbol baseSymbol() { |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14046
diff
changeset
|
341 |
return this; |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14046
diff
changeset
|
342 |
} |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14046
diff
changeset
|
343 |
|
10 | 344 |
/** The symbol's erased type. |
345 |
*/ |
|
346 |
public Type erasure(Types types) { |
|
347 |
if (erasure_field == null) |
|
348 |
erasure_field = types.erasure(type); |
|
349 |
return erasure_field; |
|
350 |
} |
|
351 |
||
352 |
/** The external type of a symbol. This is the symbol's erased type |
|
353 |
* except for constructors of inner classes which get the enclosing |
|
354 |
* instance class added as first argument. |
|
355 |
*/ |
|
356 |
public Type externalType(Types types) { |
|
357 |
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
|
358 |
if (name == name.table.names.init && owner.hasOuterInstance()) { |
10 | 359 |
Type outerThisType = types.erasure(owner.type.getEnclosingType()); |
360 |
return new MethodType(t.getParameterTypes().prepend(outerThisType), |
|
361 |
t.getReturnType(), |
|
362 |
t.getThrownTypes(), |
|
363 |
t.tsym); |
|
364 |
} else { |
|
365 |
return t; |
|
366 |
} |
|
367 |
} |
|
368 |
||
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
369 |
public boolean isDeprecated() { |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
370 |
return (flags_field & DEPRECATED) != 0; |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
371 |
} |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17278
diff
changeset
|
372 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
373 |
public boolean hasDeprecatedAnnotation() { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
374 |
return (flags_field & DEPRECATED_ANNOTATION) != 0; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
375 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
376 |
|
41637 | 377 |
public boolean isDeprecatedForRemoval() { |
378 |
return (flags_field & DEPRECATED_REMOVAL) != 0; |
|
379 |
} |
|
380 |
||
58713
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
58350
diff
changeset
|
381 |
public boolean isPreviewApi() { |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
58350
diff
changeset
|
382 |
return (flags_field & PREVIEW_API) != 0; |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
58350
diff
changeset
|
383 |
} |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
58350
diff
changeset
|
384 |
|
40772
de87954b8f20
8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents:
39920
diff
changeset
|
385 |
public boolean isDeprecatableViaAnnotation() { |
de87954b8f20
8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents:
39920
diff
changeset
|
386 |
switch (getKind()) { |
de87954b8f20
8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents:
39920
diff
changeset
|
387 |
case LOCAL_VARIABLE: |
de87954b8f20
8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents:
39920
diff
changeset
|
388 |
case PACKAGE: |
de87954b8f20
8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents:
39920
diff
changeset
|
389 |
case PARAMETER: |
de87954b8f20
8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents:
39920
diff
changeset
|
390 |
case RESOURCE_VARIABLE: |
de87954b8f20
8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents:
39920
diff
changeset
|
391 |
case EXCEPTION_PARAMETER: |
de87954b8f20
8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents:
39920
diff
changeset
|
392 |
return false; |
de87954b8f20
8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents:
39920
diff
changeset
|
393 |
default: |
de87954b8f20
8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents:
39920
diff
changeset
|
394 |
return true; |
de87954b8f20
8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents:
39920
diff
changeset
|
395 |
} |
de87954b8f20
8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents:
39920
diff
changeset
|
396 |
} |
de87954b8f20
8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents:
39920
diff
changeset
|
397 |
|
10 | 398 |
public boolean isStatic() { |
399 |
return |
|
400 |
(flags() & STATIC) != 0 || |
|
20598
aa7b86f98471
8024497: crash returning this-referencing lambda from default method
vromero
parents:
20249
diff
changeset
|
401 |
(owner.flags() & INTERFACE) != 0 && kind != MTH && |
aa7b86f98471
8024497: crash returning this-referencing lambda from default method
vromero
parents:
20249
diff
changeset
|
402 |
name != name.table.names._this; |
10 | 403 |
} |
404 |
||
405 |
public boolean isInterface() { |
|
406 |
return (flags() & INTERFACE) != 0; |
|
407 |
} |
|
408 |
||
15720
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
409 |
public boolean isPrivate() { |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
410 |
return (flags_field & Flags.AccessFlags) == PRIVATE; |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
411 |
} |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
412 |
|
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
413 |
public boolean isEnum() { |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
414 |
return (flags() & ENUM) != 0; |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
415 |
} |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
416 |
|
10 | 417 |
/** Is this symbol declared (directly or indirectly) local |
418 |
* to a method or variable initializer? |
|
419 |
* Also includes fields of inner classes which are in |
|
420 |
* turn local to a method or variable initializer. |
|
421 |
*/ |
|
422 |
public boolean isLocal() { |
|
423 |
return |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
424 |
(owner.kind.matches(KindSelector.VAL_MTH) || |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
425 |
(owner.kind == TYP && owner.isLocal())); |
10 | 426 |
} |
427 |
||
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5006
diff
changeset
|
428 |
/** Has this symbol an empty name? This includes anonymous |
16333 | 429 |
* inner classes. |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5006
diff
changeset
|
430 |
*/ |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5006
diff
changeset
|
431 |
public boolean isAnonymous() { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5006
diff
changeset
|
432 |
return name.isEmpty(); |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5006
diff
changeset
|
433 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5006
diff
changeset
|
434 |
|
10 | 435 |
/** Is this symbol a constructor? |
436 |
*/ |
|
437 |
public boolean isConstructor() { |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
438 |
return name == name.table.names.init; |
10 | 439 |
} |
440 |
||
54762 | 441 |
public boolean isDynamic() { |
442 |
return false; |
|
443 |
} |
|
444 |
||
10 | 445 |
/** The fully qualified name of this symbol. |
446 |
* This is the same as the symbol's name except for class symbols, |
|
447 |
* which are handled separately. |
|
448 |
*/ |
|
449 |
public Name getQualifiedName() { |
|
450 |
return name; |
|
451 |
} |
|
452 |
||
453 |
/** The fully qualified name of this symbol after converting to flat |
|
454 |
* representation. This is the same as the symbol's name except for |
|
455 |
* class symbols, which are handled separately. |
|
456 |
*/ |
|
457 |
public Name flatName() { |
|
458 |
return getQualifiedName(); |
|
459 |
} |
|
460 |
||
461 |
/** If this is a class or package, its members, otherwise null. |
|
462 |
*/ |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
463 |
public WriteableScope members() { |
10 | 464 |
return null; |
465 |
} |
|
466 |
||
467 |
/** A class is an inner class if it it has an enclosing instance class. |
|
468 |
*/ |
|
469 |
public boolean isInner() { |
|
24219 | 470 |
return kind == TYP && type.getEnclosingType().hasTag(CLASS); |
10 | 471 |
} |
472 |
||
473 |
/** An inner class has an outer instance if it is not an interface |
|
474 |
* it has an enclosing instance class which might be referenced from the class. |
|
475 |
* Nested classes can see instance members of their enclosing class. |
|
476 |
* Their constructors carry an additional this$n parameter, inserted |
|
477 |
* implicitly by the compiler. |
|
478 |
* |
|
479 |
* @see #isInner |
|
480 |
*/ |
|
481 |
public boolean hasOuterInstance() { |
|
482 |
return |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
483 |
type.getEnclosingType().hasTag(CLASS) && (flags() & (INTERFACE | NOOUTERTHIS)) == 0; |
10 | 484 |
} |
485 |
||
486 |
/** 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
|
487 |
* 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
|
488 |
* 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
|
489 |
* class as one may be misled to believe.) |
10 | 490 |
*/ |
491 |
public ClassSymbol enclClass() { |
|
492 |
Symbol c = this; |
|
493 |
while (c != null && |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
494 |
(!c.kind.matches(KindSelector.TYP) || !c.type.hasTag(CLASS))) { |
10 | 495 |
c = c.owner; |
496 |
} |
|
497 |
return (ClassSymbol)c; |
|
498 |
} |
|
499 |
||
500 |
/** The outermost class which indirectly owns this symbol. |
|
501 |
*/ |
|
502 |
public ClassSymbol outermostClass() { |
|
503 |
Symbol sym = this; |
|
504 |
Symbol prev = null; |
|
505 |
while (sym.kind != PCK) { |
|
506 |
prev = sym; |
|
507 |
sym = sym.owner; |
|
508 |
} |
|
509 |
return (ClassSymbol) prev; |
|
510 |
} |
|
511 |
||
512 |
/** The package which indirectly owns this symbol. |
|
513 |
*/ |
|
514 |
public PackageSymbol packge() { |
|
515 |
Symbol sym = this; |
|
516 |
while (sym.kind != PCK) { |
|
517 |
sym = sym.owner; |
|
518 |
} |
|
519 |
return (PackageSymbol) sym; |
|
520 |
} |
|
521 |
||
522 |
/** Is this symbol a subclass of `base'? Only defined for ClassSymbols. |
|
523 |
*/ |
|
524 |
public boolean isSubClass(Symbol base, Types types) { |
|
525 |
throw new AssertionError("isSubClass " + this); |
|
526 |
} |
|
527 |
||
528 |
/** Fully check membership: hierarchy, protection, and hiding. |
|
529 |
* Does not exclude methods not inherited due to overriding. |
|
530 |
*/ |
|
531 |
public boolean isMemberOf(TypeSymbol clazz, Types types) { |
|
532 |
return |
|
533 |
owner == clazz || |
|
534 |
clazz.isSubClass(owner, types) && |
|
535 |
isInheritedIn(clazz, types) && |
|
536 |
!hiddenIn((ClassSymbol)clazz, types); |
|
537 |
} |
|
538 |
||
539 |
/** Is this symbol the same as or enclosed by the given class? */ |
|
540 |
public boolean isEnclosedBy(ClassSymbol clazz) { |
|
541 |
for (Symbol sym = this; sym.kind != PCK; sym = sym.owner) |
|
542 |
if (sym == clazz) return true; |
|
543 |
return false; |
|
544 |
} |
|
545 |
||
546 |
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
|
547 |
Symbol sym = hiddenInInternal(clazz, types); |
23396
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
548 |
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
|
549 |
/* 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
|
550 |
*/ |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
551 |
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
|
552 |
} |
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
19126
diff
changeset
|
553 |
|
23396
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
554 |
/** 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
|
555 |
* 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
|
556 |
* 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
|
557 |
* 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
|
558 |
* 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
|
559 |
* as a temporary value, as a result of the recursive call. |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
560 |
*/ |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
561 |
private Symbol hiddenInInternal(ClassSymbol currentClass, Types types) { |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
562 |
if (currentClass == owner) { |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
563 |
return this; |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
564 |
} |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
565 |
for (Symbol sym : currentClass.members().getSymbolsByName(name)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
566 |
if (sym.kind == kind && |
10 | 567 |
(kind != MTH || |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
568 |
(sym.flags() & STATIC) != 0 && |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
569 |
types.isSubSignature(sym.type, type))) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
570 |
return sym; |
10 | 571 |
} |
572 |
} |
|
23396
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
573 |
Symbol hiddenSym = null; |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
574 |
for (Type st : types.interfaces(currentClass.type) |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
575 |
.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
|
576 |
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
|
577 |
Symbol sym = hiddenInInternal((ClassSymbol)st.tsym, types); |
23396
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
578 |
if (sym == this) { |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
579 |
return this; |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
580 |
} else if (sym != null) { |
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
581 |
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
|
582 |
} |
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
19126
diff
changeset
|
583 |
} |
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
19126
diff
changeset
|
584 |
} |
23396
06e3726c6b3f
8034924: Incorrect inheritance of inaccessible static method
vromero
parents:
22163
diff
changeset
|
585 |
return hiddenSym; |
10 | 586 |
} |
587 |
||
48945
6e6c777a37a2
8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents:
48683
diff
changeset
|
588 |
/** Is this symbol accessible in a given class? |
10 | 589 |
* PRE: If symbol's owner is a interface, |
590 |
* it is already assumed that the interface is a superinterface |
|
48945
6e6c777a37a2
8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents:
48683
diff
changeset
|
591 |
* the given class. |
10 | 592 |
* @param clazz The class for which we want to establish membership. |
593 |
* This must be a subclass of the member's owner. |
|
594 |
*/ |
|
48945
6e6c777a37a2
8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents:
48683
diff
changeset
|
595 |
public final boolean isAccessibleIn(Symbol clazz, Types types) { |
10 | 596 |
switch ((int)(flags_field & Flags.AccessFlags)) { |
597 |
default: // error recovery |
|
598 |
case PUBLIC: |
|
599 |
return true; |
|
600 |
case PRIVATE: |
|
601 |
return this.owner == clazz; |
|
602 |
case PROTECTED: |
|
603 |
// we model interfaces as extending Object |
|
604 |
return (clazz.flags() & INTERFACE) == 0; |
|
605 |
case 0: |
|
606 |
PackageSymbol thisPackage = this.packge(); |
|
607 |
for (Symbol sup = clazz; |
|
608 |
sup != null && sup != this.owner; |
|
609 |
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
|
610 |
while (sup.type.hasTag(TYPEVAR)) |
1528
441d4ec466de
6711619: javac doesn't allow access to protected members in intersection types
mcimadamore
parents:
1357
diff
changeset
|
611 |
sup = sup.type.getUpperBound().tsym; |
10 | 612 |
if (sup.type.isErroneous()) |
613 |
return true; // error recovery |
|
614 |
if ((sup.flags() & COMPOUND) != 0) |
|
615 |
continue; |
|
616 |
if (sup.packge() != thisPackage) |
|
617 |
return false; |
|
618 |
} |
|
619 |
return (clazz.flags() & INTERFACE) == 0; |
|
620 |
} |
|
621 |
} |
|
622 |
||
48945
6e6c777a37a2
8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents:
48683
diff
changeset
|
623 |
/** Is this symbol inherited into a given class? |
6e6c777a37a2
8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents:
48683
diff
changeset
|
624 |
* PRE: If symbol's owner is a interface, |
6e6c777a37a2
8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents:
48683
diff
changeset
|
625 |
* it is already assumed that the interface is a superinterface |
6e6c777a37a2
8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents:
48683
diff
changeset
|
626 |
* of the given class. |
6e6c777a37a2
8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents:
48683
diff
changeset
|
627 |
* @param clazz The class for which we want to establish membership. |
6e6c777a37a2
8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents:
48683
diff
changeset
|
628 |
* This must be a subclass of the member's owner. |
6e6c777a37a2
8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents:
48683
diff
changeset
|
629 |
*/ |
6e6c777a37a2
8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents:
48683
diff
changeset
|
630 |
public boolean isInheritedIn(Symbol clazz, Types types) { |
6e6c777a37a2
8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents:
48683
diff
changeset
|
631 |
return isAccessibleIn(clazz, types); |
6e6c777a37a2
8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents:
48683
diff
changeset
|
632 |
} |
6e6c777a37a2
8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents:
48683
diff
changeset
|
633 |
|
10 | 634 |
/** The (variable or method) symbol seen as a member of given |
635 |
* class type`site' (this might change the symbol's type). |
|
636 |
* This is used exclusively for producing diagnostics. |
|
637 |
*/ |
|
638 |
public Symbol asMemberOf(Type site, Types types) { |
|
639 |
throw new AssertionError(); |
|
640 |
} |
|
641 |
||
642 |
/** Does this method symbol override `other' symbol, when both are seen as |
|
643 |
* members of class `origin'? It is assumed that _other is a member |
|
644 |
* of origin. |
|
645 |
* |
|
646 |
* It is assumed that both symbols have the same name. The static |
|
647 |
* modifier is ignored for this test. |
|
648 |
* |
|
649 |
* See JLS 8.4.6.1 (without transitivity) and 8.4.6.4 |
|
650 |
*/ |
|
651 |
public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) { |
|
652 |
return false; |
|
653 |
} |
|
654 |
||
655 |
/** Complete the elaboration of this symbol's definition. |
|
656 |
*/ |
|
657 |
public void complete() throws CompletionFailure { |
|
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
658 |
if (completer != Completer.NULL_COMPLETER) { |
10 | 659 |
Completer c = completer; |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
660 |
completer = Completer.NULL_COMPLETER; |
10 | 661 |
c.complete(this); |
662 |
} |
|
663 |
} |
|
664 |
||
49197
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
665 |
public void apiComplete() throws CompletionFailure { |
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
666 |
try { |
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
667 |
complete(); |
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
668 |
} catch (CompletionFailure cf) { |
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
669 |
cf.dcfh.handleAPICompletionFailure(cf); |
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
670 |
} |
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
671 |
} |
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
672 |
|
10 | 673 |
/** True if the symbol represents an entity that exists. |
674 |
*/ |
|
675 |
public boolean exists() { |
|
676 |
return true; |
|
677 |
} |
|
678 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
679 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 680 |
public Type asType() { |
681 |
return type; |
|
682 |
} |
|
683 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
684 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 685 |
public Symbol getEnclosingElement() { |
686 |
return owner; |
|
687 |
} |
|
688 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
689 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 690 |
public ElementKind getKind() { |
691 |
return ElementKind.OTHER; // most unkind |
|
692 |
} |
|
693 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
694 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 695 |
public Set<Modifier> getModifiers() { |
49197
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
696 |
apiComplete(); |
16970
0967fa88590b
8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents:
16967
diff
changeset
|
697 |
return Flags.asModifierSet(flags()); |
10 | 698 |
} |
699 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
700 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 701 |
public Name getSimpleName() { |
702 |
return name; |
|
703 |
} |
|
704 |
||
705 |
/** |
|
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
706 |
* This is the implementation for {@code |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
707 |
* javax.lang.model.element.Element.getAnnotationMirrors()}. |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
708 |
*/ |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
709 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
17278
a48ec76f26e9
8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents:
16970
diff
changeset
|
710 |
public List<Attribute.Compound> getAnnotationMirrors() { |
49197
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
711 |
apiComplete(); |
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
712 |
return getRawAttributes(); |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
713 |
} |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
714 |
|
15355
a4757c33cae9
7193719: Support repeating annotations in javax.lang.model
jfranck
parents:
15031
diff
changeset
|
715 |
|
10 | 716 |
// 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
|
717 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 718 |
public java.util.List<Symbol> getEnclosedElements() { |
719 |
return List.nil(); |
|
720 |
} |
|
721 |
||
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
722 |
public List<TypeVariableSymbol> getTypeParameters() { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19942
diff
changeset
|
723 |
ListBuffer<TypeVariableSymbol> l = new ListBuffer<>(); |
10 | 724 |
for (Type t : type.getTypeArguments()) { |
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
725 |
Assert.check(t.tsym.getKind() == ElementKind.TYPE_PARAMETER); |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
726 |
l.append((TypeVariableSymbol)t.tsym); |
10 | 727 |
} |
728 |
return l.toList(); |
|
729 |
} |
|
730 |
||
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
731 |
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
|
732 |
protected T other; |
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
733 |
public DelegatedSymbol(T other) { |
10 | 734 |
super(other.kind, other.flags_field, other.name, other.type, other.owner); |
735 |
this.other = other; |
|
736 |
} |
|
737 |
public String toString() { return other.toString(); } |
|
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
738 |
public Symbol location() { return other.location(); } |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
739 |
public Symbol location(Type site, Types types) { return other.location(site, types); } |
14547 | 740 |
public Symbol baseSymbol() { return other; } |
10 | 741 |
public Type erasure(Types types) { return other.erasure(types); } |
742 |
public Type externalType(Types types) { return other.externalType(types); } |
|
743 |
public boolean isLocal() { return other.isLocal(); } |
|
744 |
public boolean isConstructor() { return other.isConstructor(); } |
|
745 |
public Name getQualifiedName() { return other.getQualifiedName(); } |
|
746 |
public Name flatName() { return other.flatName(); } |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
747 |
public WriteableScope members() { return other.members(); } |
10 | 748 |
public boolean isInner() { return other.isInner(); } |
749 |
public boolean hasOuterInstance() { return other.hasOuterInstance(); } |
|
750 |
public ClassSymbol enclClass() { return other.enclClass(); } |
|
751 |
public ClassSymbol outermostClass() { return other.outermostClass(); } |
|
752 |
public PackageSymbol packge() { return other.packge(); } |
|
753 |
public boolean isSubClass(Symbol base, Types types) { return other.isSubClass(base, types); } |
|
754 |
public boolean isMemberOf(TypeSymbol clazz, Types types) { return other.isMemberOf(clazz, types); } |
|
755 |
public boolean isEnclosedBy(ClassSymbol clazz) { return other.isEnclosedBy(clazz); } |
|
756 |
public boolean isInheritedIn(Symbol clazz, Types types) { return other.isInheritedIn(clazz, types); } |
|
757 |
public Symbol asMemberOf(Type site, Types types) { return other.asMemberOf(site, types); } |
|
758 |
public void complete() throws CompletionFailure { other.complete(); } |
|
759 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
760 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 761 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
762 |
return other.accept(v, p); |
|
763 |
} |
|
1357 | 764 |
|
765 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
|
766 |
return v.visitSymbol(other, p); |
|
767 |
} |
|
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
768 |
|
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
769 |
public T getUnderlyingSymbol() { |
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
770 |
return other; |
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
771 |
} |
10 | 772 |
} |
773 |
||
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
774 |
/** A base class for Symbols representing types. |
10 | 775 |
*/ |
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
776 |
public static abstract class TypeSymbol extends Symbol { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
777 |
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
|
778 |
super(kind, flags, name, type, owner); |
10 | 779 |
} |
780 |
/** form a fully qualified name from a name and an owner |
|
781 |
*/ |
|
782 |
static public Name formFullName(Name name, Symbol owner) { |
|
783 |
if (owner == null) return name; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
784 |
if ((owner.kind != ERR) && |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
785 |
(owner.kind.matches(KindSelector.VAL_MTH) || |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
786 |
(owner.kind == TYP && owner.type.hasTag(TYPEVAR)) |
10 | 787 |
)) return name; |
788 |
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
|
789 |
if (prefix == null || prefix == prefix.table.names.empty) |
10 | 790 |
return name; |
791 |
else return prefix.append('.', name); |
|
792 |
} |
|
793 |
||
794 |
/** form a fully qualified name from a name and an owner, after |
|
795 |
* converting to flat representation |
|
796 |
*/ |
|
797 |
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
|
798 |
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
|
799 |
(owner.kind == TYP && owner.type.hasTag(TYPEVAR)) |
10 | 800 |
) return name; |
801 |
char sep = owner.kind == TYP ? '$' : '.'; |
|
802 |
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
|
803 |
if (prefix == null || prefix == prefix.table.names.empty) |
10 | 804 |
return name; |
805 |
else return prefix.append(sep, name); |
|
806 |
} |
|
807 |
||
808 |
/** |
|
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24219
diff
changeset
|
809 |
* A partial ordering between type symbols that refines the |
10 | 810 |
* class inheritance graph. |
811 |
* |
|
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24219
diff
changeset
|
812 |
* Type variables always precede other kinds of symbols. |
10 | 813 |
*/ |
814 |
public final boolean precedes(TypeSymbol that, Types types) { |
|
815 |
if (this == that) |
|
816 |
return false; |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18389
diff
changeset
|
817 |
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
|
818 |
if (type.hasTag(CLASS)) { |
10 | 819 |
return |
820 |
types.rank(that.type) < types.rank(this.type) || |
|
821 |
types.rank(that.type) == types.rank(this.type) && |
|
822 |
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
|
823 |
} else if (type.hasTag(TYPEVAR)) { |
10 | 824 |
return types.isSubtype(this.type, that.type); |
825 |
} |
|
826 |
} |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18389
diff
changeset
|
827 |
return type.hasTag(TYPEVAR); |
10 | 828 |
} |
829 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
830 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
10 | 831 |
public java.util.List<Symbol> getEnclosedElements() { |
832 |
List<Symbol> list = List.nil(); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
833 |
if (kind == TYP && type.hasTag(TYPEVAR)) { |
6584
c3d25d0ad536
6458749: TypeParameterElement.getEnclosedElements throws NPE within javac.
sundar
parents:
6148
diff
changeset
|
834 |
return list; |
c3d25d0ad536
6458749: TypeParameterElement.getEnclosedElements throws NPE within javac.
sundar
parents:
6148
diff
changeset
|
835 |
} |
49197
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
836 |
apiComplete(); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
837 |
for (Symbol sym : members().getSymbols(NON_RECURSIVE)) { |
49197
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
838 |
sym.apiComplete(); |
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
839 |
if ((sym.flags() & SYNTHETIC) == 0 && sym.owner == this && sym.kind != ERR) { |
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
840 |
list = list.prepend(sym); |
37001
594b4565d8a4
8151191: javac error when running javadoc on some inner classes
vromero
parents:
36526
diff
changeset
|
841 |
} |
10 | 842 |
} |
843 |
return list; |
|
844 |
} |
|
845 |
||
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
846 |
public AnnotationTypeMetadata getAnnotationTypeMetadata() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
847 |
Assert.error("Only on ClassSymbol"); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
848 |
return null; //unreachable |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
849 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
850 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
851 |
public boolean isAnnotationType() { return false; } |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
852 |
|
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
853 |
@Override |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
854 |
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
|
855 |
return v.visitTypeSymbol(this, p); |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
856 |
} |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
857 |
} |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
858 |
|
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
859 |
/** |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
860 |
* Type variables are represented by instances of this class. |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
861 |
*/ |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
862 |
public static class TypeVariableSymbol |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
863 |
extends TypeSymbol implements TypeParameterElement { |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
864 |
|
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
865 |
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
|
866 |
super(TYP, flags, name, type, owner); |
10 | 867 |
} |
868 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
869 |
@DefinedBy(Api.LANGUAGE_MODEL) |
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
870 |
public ElementKind getKind() { |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
871 |
return ElementKind.TYPE_PARAMETER; |
10 | 872 |
} |
873 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
874 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
875 |
public Symbol getGenericElement() { |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
876 |
return owner; |
1357 | 877 |
} |
878 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
879 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 880 |
public List<Type> getBounds() { |
881 |
TypeVar t = (TypeVar)type; |
|
882 |
Type bound = t.getUpperBound(); |
|
883 |
if (!bound.isCompound()) |
|
884 |
return List.of(bound); |
|
885 |
ClassType ct = (ClassType)bound; |
|
886 |
if (!ct.tsym.erasure_field.isInterface()) { |
|
887 |
return ct.interfaces_field.prepend(ct.supertype_field); |
|
888 |
} else { |
|
889 |
// No superclass was given in bounds. |
|
890 |
// In this case, supertype is Object, erasure is first interface. |
|
891 |
return ct.interfaces_field; |
|
892 |
} |
|
893 |
} |
|
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
894 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
895 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
17278
a48ec76f26e9
8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents:
16970
diff
changeset
|
896 |
public List<Attribute.Compound> getAnnotationMirrors() { |
25009
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
897 |
// 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
|
898 |
// on the owner of the TypeVariableSymbol |
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
899 |
List<Attribute.TypeCompound> candidates = owner.getRawTypeAttributes(); |
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
900 |
int index = owner.getTypeParameters().indexOf(this); |
17278
a48ec76f26e9
8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents:
16970
diff
changeset
|
901 |
List<Attribute.Compound> res = List.nil(); |
a48ec76f26e9
8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents:
16970
diff
changeset
|
902 |
for (Attribute.TypeCompound a : candidates) { |
25009
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
903 |
if (isCurrentSymbolsAnnotation(a, index)) |
17278
a48ec76f26e9
8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents:
16970
diff
changeset
|
904 |
res = res.prepend(a); |
a48ec76f26e9
8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents:
16970
diff
changeset
|
905 |
} |
a48ec76f26e9
8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents:
16970
diff
changeset
|
906 |
|
25009
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
907 |
return res.reverse(); |
17278
a48ec76f26e9
8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents:
16970
diff
changeset
|
908 |
} |
a48ec76f26e9
8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents:
16970
diff
changeset
|
909 |
|
21007 | 910 |
// Helper to getAnnotation[s] |
911 |
@Override |
|
912 |
public <A extends Annotation> Attribute.Compound getAttribute(Class<A> annoType) { |
|
913 |
String name = annoType.getName(); |
|
914 |
||
915 |
// Declaration annotations on type variables are stored in type attributes |
|
916 |
// on the owner of the TypeVariableSymbol |
|
917 |
List<Attribute.TypeCompound> candidates = owner.getRawTypeAttributes(); |
|
25009
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
918 |
int index = owner.getTypeParameters().indexOf(this); |
21007 | 919 |
for (Attribute.TypeCompound anno : candidates) |
25009
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
920 |
if (isCurrentSymbolsAnnotation(anno, index) && |
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
921 |
name.contentEquals(anno.type.tsym.flatName())) |
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
922 |
return anno; |
21007 | 923 |
|
924 |
return null; |
|
925 |
} |
|
25009
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
926 |
//where: |
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
927 |
boolean isCurrentSymbolsAnnotation(Attribute.TypeCompound anno, int index) { |
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
928 |
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
|
929 |
anno.position.type == TargetType.METHOD_TYPE_PARAMETER) && |
36526 | 930 |
anno.position.parameter_index == index; |
25009
55c823e853f2
8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents:
24396
diff
changeset
|
931 |
} |
21007 | 932 |
|
933 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
934 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
935 |
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
|
936 |
return v.visitTypeParameter(this, p); |
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
937 |
} |
10 | 938 |
} |
36526 | 939 |
/** A class for module symbols. |
940 |
*/ |
|
941 |
public static class ModuleSymbol extends TypeSymbol |
|
942 |
implements ModuleElement { |
|
943 |
||
944 |
public Name version; |
|
945 |
public JavaFileManager.Location sourceLocation; |
|
946 |
public JavaFileManager.Location classLocation; |
|
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43376
diff
changeset
|
947 |
public JavaFileManager.Location patchLocation; |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43376
diff
changeset
|
948 |
public JavaFileManager.Location patchOutputLocation; |
36526 | 949 |
|
950 |
/** All directives, in natural order. */ |
|
951 |
public List<com.sun.tools.javac.code.Directive> directives; |
|
952 |
public List<com.sun.tools.javac.code.Directive.RequiresDirective> requires; |
|
953 |
public List<com.sun.tools.javac.code.Directive.ExportsDirective> exports; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
954 |
public List<com.sun.tools.javac.code.Directive.OpensDirective> opens; |
36526 | 955 |
public List<com.sun.tools.javac.code.Directive.ProvidesDirective> provides; |
956 |
public List<com.sun.tools.javac.code.Directive.UsesDirective> uses; |
|
957 |
||
958 |
public ClassSymbol module_info; |
|
959 |
||
960 |
public PackageSymbol unnamedPackage; |
|
961 |
public Map<Name, PackageSymbol> visiblePackages; |
|
43138
680d378b9d64
8169197: Improve error reporting for compiling against unexported package
jlahoda
parents:
42828
diff
changeset
|
962 |
public Set<ModuleSymbol> readModules; |
36526 | 963 |
public List<Symbol> enclosedPackages = List.nil(); |
964 |
||
965 |
public Completer usesProvidesCompleter = Completer.NULL_COMPLETER; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
966 |
public final Set<ModuleFlags> flags = EnumSet.noneOf(ModuleFlags.class); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
967 |
public final Set<ModuleResolutionFlags> resolutionFlags = EnumSet.noneOf(ModuleResolutionFlags.class); |
36526 | 968 |
|
969 |
/** |
|
970 |
* Create a ModuleSymbol with an associated module-info ClassSymbol. |
|
971 |
*/ |
|
972 |
public static ModuleSymbol create(Name name, Name module_info) { |
|
973 |
ModuleSymbol msym = new ModuleSymbol(name, null); |
|
974 |
ClassSymbol info = new ClassSymbol(Flags.MODULE, module_info, msym); |
|
975 |
info.fullname = formFullName(module_info, msym); |
|
976 |
info.flatname = info.fullname; |
|
977 |
info.members_field = WriteableScope.create(info); |
|
978 |
msym.module_info = info; |
|
979 |
return msym; |
|
980 |
} |
|
981 |
||
982 |
public ModuleSymbol(Name name, Symbol owner) { |
|
983 |
super(MDL, 0, name, null, owner); |
|
41254
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40774
diff
changeset
|
984 |
Assert.checkNonNull(name); |
36526 | 985 |
this.type = new ModuleType(this); |
986 |
} |
|
987 |
||
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
988 |
@Override |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
989 |
public int poolTag() { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
990 |
return ClassFile.CONSTANT_Module; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
991 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
992 |
|
36526 | 993 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
45687 | 994 |
public Name getSimpleName() { |
45752 | 995 |
return Convert.shortName(name); |
45687 | 996 |
} |
997 |
||
998 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
43376
f165c71d9e03
8172810: ModuleElement should declare and provide appropriate modifiers
jjg
parents:
43270
diff
changeset
|
999 |
public boolean isOpen() { |
f165c71d9e03
8172810: ModuleElement should declare and provide appropriate modifiers
jjg
parents:
43270
diff
changeset
|
1000 |
return flags.contains(ModuleFlags.OPEN); |
f165c71d9e03
8172810: ModuleElement should declare and provide appropriate modifiers
jjg
parents:
43270
diff
changeset
|
1001 |
} |
f165c71d9e03
8172810: ModuleElement should declare and provide appropriate modifiers
jjg
parents:
43270
diff
changeset
|
1002 |
|
f165c71d9e03
8172810: ModuleElement should declare and provide appropriate modifiers
jjg
parents:
43270
diff
changeset
|
1003 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
36526 | 1004 |
public boolean isUnnamed() { |
1005 |
return name.isEmpty() && owner == null; |
|
1006 |
} |
|
1007 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1008 |
@Override |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1009 |
public boolean isDeprecated() { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1010 |
return hasDeprecatedAnnotation(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1011 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1012 |
|
36526 | 1013 |
public boolean isNoModule() { |
1014 |
return false; |
|
1015 |
} |
|
1016 |
||
1017 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
1018 |
public ElementKind getKind() { |
|
1019 |
return ElementKind.MODULE; |
|
1020 |
} |
|
1021 |
||
1022 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
1023 |
public java.util.List<Directive> getDirectives() { |
|
49197
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
1024 |
apiComplete(); |
36526 | 1025 |
completeUsesProvides(); |
1026 |
return Collections.unmodifiableList(directives); |
|
1027 |
} |
|
1028 |
||
1029 |
public void completeUsesProvides() { |
|
1030 |
if (usesProvidesCompleter != Completer.NULL_COMPLETER) { |
|
1031 |
Completer c = usesProvidesCompleter; |
|
1032 |
usesProvidesCompleter = Completer.NULL_COMPLETER; |
|
1033 |
c.complete(this); |
|
1034 |
} |
|
1035 |
} |
|
1036 |
||
1037 |
@Override |
|
1038 |
public ClassSymbol outermostClass() { |
|
1039 |
return null; |
|
1040 |
} |
|
1041 |
||
1042 |
@Override |
|
1043 |
public String toString() { |
|
1044 |
// TODO: the following strings should be localized |
|
1045 |
// Do this with custom anon subtypes in Symtab |
|
1046 |
String n = (name == null) ? "<unknown>" |
|
1047 |
: (name.isEmpty()) ? "<unnamed>" |
|
1048 |
: String.valueOf(name); |
|
1049 |
return n; |
|
1050 |
} |
|
1051 |
||
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37001
diff
changeset
|
1052 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
36526 | 1053 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
1054 |
return v.visitModule(this, p); |
|
1055 |
} |
|
1056 |
||
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37001
diff
changeset
|
1057 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
36526 | 1058 |
public List<Symbol> getEnclosedElements() { |
1059 |
List<Symbol> list = List.nil(); |
|
1060 |
for (Symbol sym : enclosedPackages) { |
|
1061 |
if (sym.members().anyMatch(m -> m.kind == TYP)) |
|
1062 |
list = list.prepend(sym); |
|
1063 |
} |
|
1064 |
return list; |
|
1065 |
} |
|
1066 |
||
1067 |
public void reset() { |
|
1068 |
this.directives = null; |
|
1069 |
this.requires = null; |
|
1070 |
this.exports = null; |
|
1071 |
this.provides = null; |
|
1072 |
this.uses = null; |
|
1073 |
this.visiblePackages = null; |
|
1074 |
} |
|
1075 |
||
1076 |
} |
|
10 | 1077 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1078 |
public enum ModuleFlags { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1079 |
OPEN(0x0020), |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1080 |
SYNTHETIC(0x1000), |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1081 |
MANDATED(0x8000); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1082 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1083 |
public static int value(Set<ModuleFlags> s) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1084 |
int v = 0; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1085 |
for (ModuleFlags f: s) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1086 |
v |= f.value; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1087 |
return v; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1088 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1089 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1090 |
private ModuleFlags(int value) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1091 |
this.value = value; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1092 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1093 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1094 |
public final int value; |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
1095 |
} |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1096 |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
1097 |
public enum ModuleResolutionFlags { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
1098 |
DO_NOT_RESOLVE_BY_DEFAULT(0x0001), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
1099 |
WARN_DEPRECATED(0x0002), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
1100 |
WARN_DEPRECATED_REMOVAL(0x0004), |
43270
de9a02e20567
8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
43265
diff
changeset
|
1101 |
WARN_INCUBATING(0x0008); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
1102 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
1103 |
public static int value(Set<ModuleResolutionFlags> s) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
1104 |
int v = 0; |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
1105 |
for (ModuleResolutionFlags f: s) |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
1106 |
v |= f.value; |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
1107 |
return v; |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
1108 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
1109 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
1110 |
private ModuleResolutionFlags(int value) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
1111 |
this.value = value; |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
1112 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
1113 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
1114 |
public final int value; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1115 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1116 |
|
10 | 1117 |
/** A class for package symbols |
1118 |
*/ |
|
1119 |
public static class PackageSymbol extends TypeSymbol |
|
1120 |
implements PackageElement { |
|
1121 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1122 |
public WriteableScope members_field; |
10 | 1123 |
public Name fullname; |
1124 |
public ClassSymbol package_info; // see bug 6443073 |
|
36526 | 1125 |
public ModuleSymbol modle; |
43265
4ec472ee5135
8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents:
43138
diff
changeset
|
1126 |
// the file containing the documentation comments for the package |
4ec472ee5135
8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents:
43138
diff
changeset
|
1127 |
public JavaFileObject sourcefile; |
10 | 1128 |
|
1129 |
public PackageSymbol(Name name, Type type, Symbol owner) { |
|
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16557
diff
changeset
|
1130 |
super(PCK, 0, name, type, owner); |
10 | 1131 |
this.members_field = null; |
1132 |
this.fullname = formFullName(name, owner); |
|
1133 |
} |
|
1134 |
||
1135 |
public PackageSymbol(Name name, Symbol owner) { |
|
1136 |
this(name, null, owner); |
|
1137 |
this.type = new PackageType(this); |
|
1138 |
} |
|
1139 |
||
1140 |
public String toString() { |
|
1141 |
return fullname.toString(); |
|
1142 |
} |
|
1143 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1144 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1145 |
public Name getQualifiedName() { |
1146 |
return fullname; |
|
1147 |
} |
|
1148 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1149 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1150 |
public boolean isUnnamed() { |
1151 |
return name.isEmpty() && owner != null; |
|
1152 |
} |
|
1153 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1154 |
public WriteableScope members() { |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1155 |
complete(); |
10 | 1156 |
return members_field; |
1157 |
} |
|
1158 |
||
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1159 |
@Override |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1160 |
public int poolTag() { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1161 |
return ClassFile.CONSTANT_Package; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1162 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1163 |
|
10 | 1164 |
public long flags() { |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1165 |
complete(); |
10 | 1166 |
return flags_field; |
1167 |
} |
|
1168 |
||
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1169 |
@Override |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1170 |
public List<Attribute.Compound> getRawAttributes() { |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1171 |
complete(); |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1172 |
if (package_info != null) { |
4871
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
4077
diff
changeset
|
1173 |
package_info.complete(); |
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1174 |
mergeAttributes(); |
4871
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
4077
diff
changeset
|
1175 |
} |
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1176 |
return super.getRawAttributes(); |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1177 |
} |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1178 |
|
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1179 |
private void mergeAttributes() { |
21480 | 1180 |
if (metadata == null && |
1181 |
package_info.metadata != null) { |
|
1182 |
metadata = new SymbolMetadata(this); |
|
1183 |
metadata.setAttributes(package_info.metadata); |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12335
diff
changeset
|
1184 |
} |
10 | 1185 |
} |
1186 |
||
1187 |
/** A package "exists" if a type or package that exists has |
|
1188 |
* been seen within it. |
|
1189 |
*/ |
|
1190 |
public boolean exists() { |
|
1191 |
return (flags_field & EXISTS) != 0; |
|
1192 |
} |
|
1193 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1194 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1195 |
public ElementKind getKind() { |
1196 |
return ElementKind.PACKAGE; |
|
1197 |
} |
|
1198 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1199 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1200 |
public Symbol getEnclosingElement() { |
36526 | 1201 |
return modle != null && !modle.isNoModule() ? modle : null; |
10 | 1202 |
} |
1203 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1204 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1205 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
1206 |
return v.visitPackage(this, p); |
|
1207 |
} |
|
1357 | 1208 |
|
1209 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
|
1210 |
return v.visitPackageSymbol(this, p); |
|
1211 |
} |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1212 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1213 |
/**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
|
1214 |
public void reset() { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1215 |
metadata = null; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1216 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1217 |
|
10 | 1218 |
} |
1219 |
||
54514
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1220 |
public static class RootPackageSymbol extends PackageSymbol { |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1221 |
public final MissingInfoHandler missingInfoHandler; |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1222 |
|
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1223 |
public RootPackageSymbol(Name name, Symbol owner, MissingInfoHandler missingInfoHandler) { |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1224 |
super(name, owner); |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1225 |
this.missingInfoHandler = missingInfoHandler; |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1226 |
} |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1227 |
|
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1228 |
} |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1229 |
|
10 | 1230 |
/** A class for class symbols |
1231 |
*/ |
|
1232 |
public static class ClassSymbol extends TypeSymbol implements TypeElement { |
|
1233 |
||
1234 |
/** a scope for all class members; variables, methods and inner classes |
|
1235 |
* type parameters are not part of this scope |
|
1236 |
*/ |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1237 |
public WriteableScope members_field; |
10 | 1238 |
|
1239 |
/** the fully qualified name of the class, i.e. pck.outer.inner. |
|
1240 |
* null for anonymous classes |
|
1241 |
*/ |
|
1242 |
public Name fullname; |
|
1243 |
||
1244 |
/** the fully qualified name of the class after converting to flat |
|
1245 |
* representation, i.e. pck.outer$inner, |
|
1246 |
* set externally for local and anonymous classes |
|
1247 |
*/ |
|
1248 |
public Name flatname; |
|
1249 |
||
1250 |
/** the sourcefile where the class came from |
|
1251 |
*/ |
|
1252 |
public JavaFileObject sourcefile; |
|
1253 |
||
1254 |
/** the classfile from where to load this class |
|
1255 |
* this will have extension .class or .java |
|
1256 |
*/ |
|
1257 |
public JavaFileObject classfile; |
|
1258 |
||
10627
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
10626
diff
changeset
|
1259 |
/** the list of translated local classes (used for generating |
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
10626
diff
changeset
|
1260 |
* InnerClasses attribute) |
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
10626
diff
changeset
|
1261 |
*/ |
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
10626
diff
changeset
|
1262 |
public List<ClassSymbol> trans_local; |
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
10626
diff
changeset
|
1263 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1264 |
/** the annotation metadata attached to this class */ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1265 |
private AnnotationTypeMetadata annotationTypeMetadata; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1266 |
|
10 | 1267 |
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
|
1268 |
super(TYP, flags, name, type, owner); |
10 | 1269 |
this.members_field = null; |
1270 |
this.fullname = formFullName(name, owner); |
|
1271 |
this.flatname = formFlatName(name, owner); |
|
1272 |
this.sourcefile = null; |
|
1273 |
this.classfile = null; |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1274 |
this.annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType(); |
10 | 1275 |
} |
1276 |
||
1277 |
public ClassSymbol(long flags, Name name, Symbol owner) { |
|
1278 |
this( |
|
1279 |
flags, |
|
1280 |
name, |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1281 |
new ClassType(Type.noType, null, null), |
10 | 1282 |
owner); |
1283 |
this.type.tsym = this; |
|
1284 |
} |
|
1285 |
||
1286 |
/** The Java source which this symbol represents. |
|
1287 |
*/ |
|
1288 |
public String toString() { |
|
1289 |
return className(); |
|
1290 |
} |
|
1291 |
||
1292 |
public long flags() { |
|
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1293 |
complete(); |
10 | 1294 |
return flags_field; |
1295 |
} |
|
1296 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1297 |
public WriteableScope members() { |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1298 |
complete(); |
10 | 1299 |
return members_field; |
1300 |
} |
|
1301 |
||
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1302 |
@Override |
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1303 |
public List<Attribute.Compound> getRawAttributes() { |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1304 |
complete(); |
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14956
diff
changeset
|
1305 |
return super.getRawAttributes(); |
10 | 1306 |
} |
1307 |
||
15385 | 1308 |
@Override |
1309 |
public List<Attribute.TypeCompound> getRawTypeAttributes() { |
|
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
1310 |
complete(); |
15385 | 1311 |
return super.getRawTypeAttributes(); |
1312 |
} |
|
1313 |
||
10 | 1314 |
public Type erasure(Types types) { |
1315 |
if (erasure_field == null) |
|
1316 |
erasure_field = new ClassType(types.erasure(type.getEnclosingType()), |
|
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
1317 |
List.nil(), this, |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1318 |
type.getMetadata()); |
10 | 1319 |
return erasure_field; |
1320 |
} |
|
1321 |
||
1322 |
public String className() { |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
1323 |
if (name.isEmpty()) |
10 | 1324 |
return |
1325 |
Log.getLocalizedString("anonymous.class", flatname); |
|
1326 |
else |
|
1327 |
return fullname.toString(); |
|
1328 |
} |
|
1329 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1330 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1331 |
public Name getQualifiedName() { |
1332 |
return fullname; |
|
1333 |
} |
|
1334 |
||
1335 |
public Name flatName() { |
|
1336 |
return flatname; |
|
1337 |
} |
|
1338 |
||
1339 |
public boolean isSubClass(Symbol base, Types types) { |
|
1340 |
if (this == base) { |
|
1341 |
return true; |
|
1342 |
} 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
|
1343 |
for (Type t = type; t.hasTag(CLASS); t = types.supertype(t)) |
10 | 1344 |
for (List<Type> is = types.interfaces(t); |
1345 |
is.nonEmpty(); |
|
1346 |
is = is.tail) |
|
1347 |
if (is.head.tsym.isSubClass(base, types)) return true; |
|
1348 |
} else { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
1349 |
for (Type t = type; t.hasTag(CLASS); t = types.supertype(t)) |
10 | 1350 |
if (t.tsym == base) return true; |
1351 |
} |
|
1352 |
return false; |
|
1353 |
} |
|
1354 |
||
1355 |
/** Complete the elaboration of this symbol's definition. |
|
1356 |
*/ |
|
1357 |
public void complete() throws CompletionFailure { |
|
49197
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
1358 |
Completer origCompleter = completer; |
10 | 1359 |
try { |
1360 |
super.complete(); |
|
1361 |
} catch (CompletionFailure ex) { |
|
49197
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
1362 |
ex.dcfh.classSymbolCompleteFailed(this, origCompleter); |
10 | 1363 |
// quiet error recovery |
1364 |
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
|
1365 |
this.type = new ErrorType(this, Type.noType); |
10 | 1366 |
throw ex; |
1367 |
} |
|
1368 |
} |
|
1369 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1370 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1371 |
public List<Type> getInterfaces() { |
49197
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
1372 |
apiComplete(); |
10 | 1373 |
if (type instanceof ClassType) { |
1374 |
ClassType t = (ClassType)type; |
|
1375 |
if (t.interfaces_field == null) // FIXME: shouldn't be null |
|
1376 |
t.interfaces_field = List.nil(); |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8427
diff
changeset
|
1377 |
if (t.all_interfaces_field != null) |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8427
diff
changeset
|
1378 |
return Type.getModelTypes(t.all_interfaces_field); |
10 | 1379 |
return t.interfaces_field; |
1380 |
} else { |
|
1381 |
return List.nil(); |
|
1382 |
} |
|
1383 |
} |
|
1384 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1385 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1386 |
public Type getSuperclass() { |
49197
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
1387 |
apiComplete(); |
10 | 1388 |
if (type instanceof ClassType) { |
1389 |
ClassType t = (ClassType)type; |
|
1390 |
if (t.supertype_field == null) // FIXME: shouldn't be null |
|
1391 |
t.supertype_field = Type.noType; |
|
1392 |
// An interface has no superclass; its supertype is Object. |
|
1393 |
return t.isInterface() |
|
1394 |
? Type.noType |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8427
diff
changeset
|
1395 |
: t.supertype_field.getModelType(); |
10 | 1396 |
} else { |
1397 |
return Type.noType; |
|
1398 |
} |
|
1399 |
} |
|
1400 |
||
21007 | 1401 |
/** |
1402 |
* Returns the next class to search for inherited annotations or {@code null} |
|
1403 |
* if the next class can't be found. |
|
1404 |
*/ |
|
1405 |
private ClassSymbol getSuperClassToSearchForAnnotations() { |
|
1406 |
||
1407 |
Type sup = getSuperclass(); |
|
1408 |
||
1409 |
if (!sup.hasTag(CLASS) || sup.isErroneous()) |
|
1410 |
return null; |
|
1411 |
||
1412 |
return (ClassSymbol) sup.tsym; |
|
1413 |
} |
|
1414 |
||
1415 |
||
1416 |
@Override |
|
1417 |
protected <A extends Annotation> A[] getInheritedAnnotations(Class<A> annoType) { |
|
1418 |
||
1419 |
ClassSymbol sup = getSuperClassToSearchForAnnotations(); |
|
1420 |
||
1421 |
return sup == null ? super.getInheritedAnnotations(annoType) |
|
1422 |
: sup.getAnnotationsByType(annoType); |
|
1423 |
} |
|
1424 |
||
1425 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1426 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1427 |
public ElementKind getKind() { |
49197
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
1428 |
apiComplete(); |
10 | 1429 |
long flags = flags(); |
1430 |
if ((flags & ANNOTATION) != 0) |
|
1431 |
return ElementKind.ANNOTATION_TYPE; |
|
1432 |
else if ((flags & INTERFACE) != 0) |
|
1433 |
return ElementKind.INTERFACE; |
|
1434 |
else if ((flags & ENUM) != 0) |
|
1435 |
return ElementKind.ENUM; |
|
1436 |
else |
|
1437 |
return ElementKind.CLASS; |
|
1438 |
} |
|
1439 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1440 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
20610
81a202481805
8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents:
20598
diff
changeset
|
1441 |
public Set<Modifier> getModifiers() { |
49197
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
1442 |
apiComplete(); |
20610
81a202481805
8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents:
20598
diff
changeset
|
1443 |
long flags = flags(); |
81a202481805
8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents:
20598
diff
changeset
|
1444 |
return Flags.asModifierSet(flags & ~DEFAULT); |
81a202481805
8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents:
20598
diff
changeset
|
1445 |
} |
81a202481805
8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents:
20598
diff
changeset
|
1446 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1447 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1448 |
public NestingKind getNestingKind() { |
49197
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
1449 |
apiComplete(); |
10 | 1450 |
if (owner.kind == PCK) |
1451 |
return NestingKind.TOP_LEVEL; |
|
1452 |
else if (name.isEmpty()) |
|
1453 |
return NestingKind.ANONYMOUS; |
|
1454 |
else if (owner.kind == MTH) |
|
1455 |
return NestingKind.LOCAL; |
|
1456 |
else |
|
1457 |
return NestingKind.MEMBER; |
|
1458 |
} |
|
1459 |
||
21007 | 1460 |
|
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16333
diff
changeset
|
1461 |
@Override |
21007 | 1462 |
protected <A extends Annotation> Attribute.Compound getAttribute(final Class<A> annoType) { |
1463 |
||
1464 |
Attribute.Compound attrib = super.getAttribute(annoType); |
|
1465 |
||
1466 |
boolean inherited = annoType.isAnnotationPresent(Inherited.class); |
|
1467 |
if (attrib != null || !inherited) |
|
1468 |
return attrib; |
|
1469 |
||
1470 |
// Search supertypes |
|
1471 |
ClassSymbol superType = getSuperClassToSearchForAnnotations(); |
|
1472 |
return superType == null ? null |
|
1473 |
: superType.getAttribute(annoType); |
|
10 | 1474 |
} |
1475 |
||
21007 | 1476 |
|
1477 |
||
1478 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1479 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1480 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
1481 |
return v.visitType(this, p); |
|
1482 |
} |
|
1357 | 1483 |
|
1484 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
|
1485 |
return v.visitClassSymbol(this, p); |
|
1486 |
} |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1487 |
|
28459
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
27224
diff
changeset
|
1488 |
public void markAbstractIfNeeded(Types types) { |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
27224
diff
changeset
|
1489 |
if (types.enter.getEnv(this) != null && |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
27224
diff
changeset
|
1490 |
(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
|
1491 |
(flags() & (FINAL | ABSTRACT)) == 0) { |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
27224
diff
changeset
|
1492 |
if (types.firstUnimplementedAbstract(this) != null) |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
27224
diff
changeset
|
1493 |
// add the ABSTRACT flag to an enum |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
27224
diff
changeset
|
1494 |
flags_field |= ABSTRACT; |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
27224
diff
changeset
|
1495 |
} |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
27224
diff
changeset
|
1496 |
} |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
27224
diff
changeset
|
1497 |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1498 |
/**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
|
1499 |
public void reset() { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1500 |
kind = TYP; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1501 |
erasure_field = null; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1502 |
members_field = null; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1503 |
flags_field = 0; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1504 |
if (type instanceof ClassType) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1505 |
ClassType t = (ClassType)type; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1506 |
t.setEnclosingType(Type.noType); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1507 |
t.rank_field = -1; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1508 |
t.typarams_field = null; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1509 |
t.allparams_field = null; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1510 |
t.supertype_field = null; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1511 |
t.interfaces_field = null; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1512 |
t.all_interfaces_field = null; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1513 |
} |
39372
a42db8c180c3
8132446: AsssertionError in ClassSymbol.setAnnotationType
sadayapalam
parents:
37848
diff
changeset
|
1514 |
clearAnnotationMetadata(); |
a42db8c180c3
8132446: AsssertionError in ClassSymbol.setAnnotationType
sadayapalam
parents:
37848
diff
changeset
|
1515 |
} |
a42db8c180c3
8132446: AsssertionError in ClassSymbol.setAnnotationType
sadayapalam
parents:
37848
diff
changeset
|
1516 |
|
a42db8c180c3
8132446: AsssertionError in ClassSymbol.setAnnotationType
sadayapalam
parents:
37848
diff
changeset
|
1517 |
public void clearAnnotationMetadata() { |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1518 |
metadata = null; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1519 |
annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1520 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1521 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1522 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1523 |
public AnnotationTypeMetadata getAnnotationTypeMetadata() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1524 |
return annotationTypeMetadata; |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1525 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23396
diff
changeset
|
1526 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1527 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1528 |
public boolean isAnnotationType() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1529 |
return (flags_field & Flags.ANNOTATION) != 0; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1530 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1531 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1532 |
public void setAnnotationTypeMetadata(AnnotationTypeMetadata a) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1533 |
Assert.checkNonNull(a); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1534 |
Assert.check(!annotationTypeMetadata.isMetadataForAnnotationType()); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1535 |
this.annotationTypeMetadata = a; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1536 |
} |
10 | 1537 |
} |
1538 |
||
1539 |
||
1540 |
/** A class for variable symbols |
|
1541 |
*/ |
|
1542 |
public static class VarSymbol extends Symbol implements VariableElement { |
|
1543 |
||
1544 |
/** The variable's declaration position. |
|
1545 |
*/ |
|
1546 |
public int pos = Position.NOPOS; |
|
1547 |
||
1548 |
/** The variable's address. Used for different purposes during |
|
1549 |
* flow analysis, translation and code generation. |
|
1550 |
* Flow analysis: |
|
1551 |
* If this is a blank final or local variable, its sequence number. |
|
1552 |
* Translation: |
|
1553 |
* If this is a private field, its access number. |
|
1554 |
* Code generation: |
|
1555 |
* If this is a local variable, its logical slot number. |
|
1556 |
*/ |
|
1557 |
public int adr = -1; |
|
1558 |
||
1559 |
/** Construct a variable symbol, given its flags, name, type and owner. |
|
1560 |
*/ |
|
1561 |
public VarSymbol(long flags, Name name, Type type, Symbol owner) { |
|
1562 |
super(VAR, flags, name, type, owner); |
|
1563 |
} |
|
1564 |
||
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1565 |
@Override |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1566 |
public int poolTag() { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1567 |
return ClassFile.CONSTANT_Fieldref; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1568 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1569 |
|
54668
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
1570 |
public MethodHandleSymbol asMethodHandle(boolean getter) { |
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
1571 |
return new MethodHandleSymbol(this, getter); |
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
1572 |
} |
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
1573 |
|
10 | 1574 |
/** Clone this symbol with new owner. |
1575 |
*/ |
|
1576 |
public VarSymbol clone(Symbol newOwner) { |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1577 |
VarSymbol v = new VarSymbol(flags_field, name, type, newOwner) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1578 |
@Override |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1579 |
public Symbol baseSymbol() { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1580 |
return VarSymbol.this; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1581 |
} |
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1582 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1583 |
@Override |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1584 |
public Object poolKey(Types types) { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1585 |
return new Pair<>(newOwner, baseSymbol()); |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1586 |
} |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1587 |
}; |
10 | 1588 |
v.pos = pos; |
1589 |
v.adr = adr; |
|
1590 |
v.data = data; |
|
1591 |
// System.out.println("clone " + v + " in " + newOwner);//DEBUG |
|
1592 |
return v; |
|
1593 |
} |
|
1594 |
||
1595 |
public String toString() { |
|
1596 |
return name.toString(); |
|
1597 |
} |
|
1598 |
||
1599 |
public Symbol asMemberOf(Type site, Types types) { |
|
1600 |
return new VarSymbol(flags_field, name, types.memberType(site, this), owner); |
|
1601 |
} |
|
1602 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1603 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1604 |
public ElementKind getKind() { |
1605 |
long flags = flags(); |
|
1606 |
if ((flags & PARAMETER) != 0) { |
|
1607 |
if (isExceptionParameter()) |
|
1608 |
return ElementKind.EXCEPTION_PARAMETER; |
|
1609 |
else |
|
1610 |
return ElementKind.PARAMETER; |
|
1611 |
} else if ((flags & ENUM) != 0) { |
|
1612 |
return ElementKind.ENUM_CONSTANT; |
|
1613 |
} else if (owner.kind == TYP || owner.kind == ERR) { |
|
1614 |
return ElementKind.FIELD; |
|
6718
56ed1962d369
6967842: Element not returned from tree API for ARM resource variables.
sundar
parents:
6592
diff
changeset
|
1615 |
} else if (isResourceVariable()) { |
56ed1962d369
6967842: Element not returned from tree API for ARM resource variables.
sundar
parents:
6592
diff
changeset
|
1616 |
return ElementKind.RESOURCE_VARIABLE; |
10 | 1617 |
} else { |
1618 |
return ElementKind.LOCAL_VARIABLE; |
|
1619 |
} |
|
1620 |
} |
|
1621 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1622 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1623 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
1624 |
return v.visitVariable(this, p); |
|
1625 |
} |
|
1626 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1627 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 1628 |
public Object getConstantValue() { // Mirror API |
1629 |
return Constants.decode(getConstValue(), type); |
|
1630 |
} |
|
1631 |
||
1632 |
public void setLazyConstValue(final Env<AttrContext> env, |
|
1633 |
final Attr attr, |
|
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19928
diff
changeset
|
1634 |
final JCVariableDecl variable) |
10 | 1635 |
{ |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42822
diff
changeset
|
1636 |
setData((Callable<Object>)() -> attr.attribLazyConstantValue(env, variable, type)); |
10 | 1637 |
} |
1638 |
||
1639 |
/** |
|
1640 |
* The variable's constant value, if this is a constant. |
|
1641 |
* Before the constant value is evaluated, it points to an |
|
19666
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
19657
diff
changeset
|
1642 |
* initializer environment. If this is not a constant, it can |
10 | 1643 |
* be used for other stuff. |
1644 |
*/ |
|
1645 |
private Object data; |
|
1646 |
||
1647 |
public boolean isExceptionParameter() { |
|
1648 |
return data == ElementKind.EXCEPTION_PARAMETER; |
|
1649 |
} |
|
1650 |
||
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
1651 |
public boolean isResourceVariable() { |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
1652 |
return data == ElementKind.RESOURCE_VARIABLE; |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
1653 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
1654 |
|
10 | 1655 |
public Object getConstValue() { |
1656 |
// 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
|
1657 |
if (data == ElementKind.EXCEPTION_PARAMETER || |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
1658 |
data == ElementKind.RESOURCE_VARIABLE) { |
10 | 1659 |
return null; |
1660 |
} else if (data instanceof Callable<?>) { |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
1661 |
// In this case, this is a final variable, with an as |
10 | 1662 |
// yet unevaluated initializer. |
1663 |
Callable<?> eval = (Callable<?>)data; |
|
1664 |
data = null; // to make sure we don't evaluate this twice. |
|
1665 |
try { |
|
1666 |
data = eval.call(); |
|
1667 |
} catch (Exception ex) { |
|
1668 |
throw new AssertionError(ex); |
|
1669 |
} |
|
1670 |
} |
|
1671 |
return data; |
|
1672 |
} |
|
1673 |
||
1674 |
public void setData(Object data) { |
|
8032 | 1675 |
Assert.check(!(data instanceof Env<?>), this); |
10 | 1676 |
this.data = data; |
1677 |
} |
|
1357 | 1678 |
|
1679 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
|
1680 |
return v.visitVarSymbol(this, p); |
|
1681 |
} |
|
10 | 1682 |
} |
1683 |
||
54514
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1684 |
public static class ParamSymbol extends VarSymbol { |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1685 |
public ParamSymbol(long flags, Name name, Type type, Symbol owner) { |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1686 |
super(flags, name, type, owner); |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1687 |
} |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1688 |
|
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1689 |
@Override |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1690 |
public Name getSimpleName() { |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1691 |
if ((flags_field & NAME_FILLED) == 0) { |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1692 |
flags_field |= NAME_FILLED; |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1693 |
Symbol rootPack = this; |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1694 |
while (rootPack != null && !(rootPack instanceof RootPackageSymbol)) { |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1695 |
rootPack = rootPack.owner; |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1696 |
} |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1697 |
if (rootPack != null) { |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1698 |
Name inferredName = |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1699 |
((RootPackageSymbol) rootPack).missingInfoHandler.getParameterName(this); |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1700 |
if (inferredName != null) { |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1701 |
this.name = inferredName; |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1702 |
} |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1703 |
} |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1704 |
} |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1705 |
return super.getSimpleName(); |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1706 |
} |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1707 |
|
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1708 |
} |
b0651dcc8d98
8217047: Provide a way to inject missing parameter names
jlahoda
parents:
54339
diff
changeset
|
1709 |
|
10 | 1710 |
/** A class for method symbols. |
1711 |
*/ |
|
1712 |
public static class MethodSymbol extends Symbol implements ExecutableElement { |
|
1713 |
||
1714 |
/** The code of the method. */ |
|
1715 |
public Code code = null; |
|
1716 |
||
15720
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
1717 |
/** The extra (synthetic/mandated) parameters of the method. */ |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
1718 |
public List<VarSymbol> extraParams = List.nil(); |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15719
diff
changeset
|
1719 |
|
19657
48226ff07b84
8020745: Suspicious MethodParameters attribute generated for local classes capturing local variables
emc
parents:
19492
diff
changeset
|
1720 |
/** 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
|
1721 |
public List<VarSymbol> capturedLocals = List.nil(); |
48226ff07b84
8020745: Suspicious MethodParameters attribute generated for local classes capturing local variables
emc
parents:
19492
diff
changeset
|
1722 |
|
10 | 1723 |
/** The parameters of the method. */ |
1724 |
public List<VarSymbol> params = null; |
|
1725 |
||
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
28459
diff
changeset
|
1726 |
/** For an annotation type element, its default value if any. |
10 | 1727 |
* The value is null if none appeared in the method |
1728 |
* declaration. |
|
1729 |
*/ |
|
1730 |
public Attribute defaultValue = null; |
|
1731 |
||
1732 |
/** Construct a method symbol, given its flags, name, type and owner. |
|
1733 |
*/ |
|
1734 |
public MethodSymbol(long flags, Name name, Type type, Symbol owner) { |
|
1735 |
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
|
1736 |
if (owner.type.hasTag(TYPEVAR)) Assert.error(owner + "." + name); |
10 | 1737 |
} |
1738 |
||
1739 |
/** Clone this symbol with new owner. |
|
1740 |
*/ |
|
1741 |
public MethodSymbol clone(Symbol newOwner) { |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1742 |
MethodSymbol m = new MethodSymbol(flags_field, name, type, newOwner) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1743 |
@Override |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1744 |
public Symbol baseSymbol() { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1745 |
return MethodSymbol.this; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1746 |
} |
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1747 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1748 |
@Override |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1749 |
public Object poolKey(Types types) { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1750 |
return new Pair<>(newOwner, baseSymbol()); |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1751 |
} |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14051
diff
changeset
|
1752 |
}; |
10 | 1753 |
m.code = code; |
1754 |
return m; |
|
1755 |
} |
|
1756 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1757 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
16970
0967fa88590b
8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents:
16967
diff
changeset
|
1758 |
public Set<Modifier> getModifiers() { |
0967fa88590b
8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents:
16967
diff
changeset
|
1759 |
long flags = flags(); |
0967fa88590b
8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents:
16967
diff
changeset
|
1760 |
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
|
1761 |
} |
0967fa88590b
8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents:
16967
diff
changeset
|
1762 |
|
10 | 1763 |
/** The Java source which this symbol represents. |
1764 |
*/ |
|
1765 |
public String toString() { |
|
1766 |
if ((flags() & BLOCK) != 0) { |
|
1767 |
return owner.name.toString(); |
|
1768 |
} else { |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
1769 |
String s = (name == name.table.names.init) |
10 | 1770 |
? owner.name.toString() |
1771 |
: name.toString(); |
|
1772 |
if (type != null) { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
1773 |
if (type.hasTag(FORALL)) |
10 | 1774 |
s = "<" + ((ForAll)type).getTypeArguments() + ">" + s; |
1775 |
s += "(" + type.argtypes((flags() & VARARGS) != 0) + ")"; |
|
1776 |
} |
|
1777 |
return s; |
|
1778 |
} |
|
1779 |
} |
|
1780 |
||
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1781 |
@Override |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1782 |
public int poolTag() { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1783 |
return owner.isInterface() ? |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1784 |
ClassFile.CONSTANT_InterfaceMethodref : ClassFile.CONSTANT_Methodref; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1785 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1786 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1787 |
public boolean isHandle() { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1788 |
return false; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1789 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1790 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1791 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1792 |
public MethodHandleSymbol asHandle() { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1793 |
return new MethodHandleSymbol(this); |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1794 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
1795 |
|
10 | 1796 |
/** find a symbol that this (proxy method) symbol implements. |
1797 |
* @param c The class whose members are searched for |
|
1798 |
* implementations |
|
1799 |
*/ |
|
1800 |
public Symbol implemented(TypeSymbol c, Types types) { |
|
1801 |
Symbol impl = null; |
|
1802 |
for (List<Type> is = types.interfaces(c.type); |
|
1803 |
impl == null && is.nonEmpty(); |
|
1804 |
is = is.tail) { |
|
1805 |
TypeSymbol i = is.head.tsym; |
|
7628
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1806 |
impl = implementedIn(i, types); |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1807 |
if (impl == null) |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1808 |
impl = implemented(i, types); |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1809 |
} |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1810 |
return impl; |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1811 |
} |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1812 |
|
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1813 |
public Symbol implementedIn(TypeSymbol c, Types types) { |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1814 |
Symbol impl = null; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1815 |
for (Symbol sym : c.members().getSymbolsByName(name)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1816 |
if (this.overrides(sym, (TypeSymbol)owner, types, true) && |
7628
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1817 |
// FIXME: I suspect the following requires a |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1818 |
// subst() for a parametric return type. |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
6718
diff
changeset
|
1819 |
types.isSameType(type.getReturnType(), |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1820 |
types.memberType(owner.type, sym).getReturnType())) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1821 |
impl = sym; |
10 | 1822 |
} |
1823 |
} |
|
1824 |
return impl; |
|
1825 |
} |
|
1826 |
||
1827 |
/** Will the erasure of this method be considered by the VM to |
|
1828 |
* override the erasure of the other when seen from class `origin'? |
|
1829 |
*/ |
|
1830 |
public boolean binaryOverrides(Symbol _other, TypeSymbol origin, Types types) { |
|
1831 |
if (isConstructor() || _other.kind != MTH) return false; |
|
1832 |
||
1833 |
if (this == _other) return true; |
|
1834 |
MethodSymbol other = (MethodSymbol)_other; |
|
1835 |
||
1836 |
// check for a direct implementation |
|
1837 |
if (other.isOverridableIn((TypeSymbol)owner) && |
|
1838 |
types.asSuper(owner.type, other.owner) != null && |
|
1839 |
types.isSameType(erasure(types), other.erasure(types))) |
|
1840 |
return true; |
|
1841 |
||
1842 |
// check for an inherited implementation |
|
1843 |
return |
|
1844 |
(flags() & ABSTRACT) == 0 && |
|
1845 |
other.isOverridableIn(origin) && |
|
1846 |
this.isMemberOf(origin, types) && |
|
1847 |
types.isSameType(erasure(types), other.erasure(types)); |
|
1848 |
} |
|
1849 |
||
1850 |
/** The implementation of this (abstract) symbol in class origin, |
|
1851 |
* from the VM's point of view, null if method does not have an |
|
1852 |
* implementation in class. |
|
1853 |
* @param origin The class of which the implementation is a member. |
|
1854 |
*/ |
|
1855 |
public MethodSymbol binaryImplementation(ClassSymbol origin, Types types) { |
|
1856 |
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
|
1857 |
for (Symbol sym : c.members().getSymbolsByName(name)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1858 |
if (sym.kind == MTH && |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1859 |
((MethodSymbol)sym).binaryOverrides(this, origin, types)) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25009
diff
changeset
|
1860 |
return (MethodSymbol)sym; |
10 | 1861 |
} |
1862 |
} |
|
1863 |
return null; |
|
1864 |
} |
|
1865 |
||
1866 |
/** Does this symbol override `other' symbol, when both are seen as |
|
1867 |
* members of class `origin'? It is assumed that _other is a member |
|
1868 |
* of origin. |
|
1869 |
* |
|
1870 |
* It is assumed that both symbols have the same name. The static |
|
1871 |
* modifier is ignored for this test. |
|
1872 |
* |
|
33367 | 1873 |
* A quirk in the works is that if the receiver is a method symbol for |
1874 |
* an inherited abstract method we answer false summarily all else being |
|
1875 |
* immaterial. Abstract "own" methods (i.e `this' is a direct member of |
|
1876 |
* origin) don't get rejected as summarily and are put to test against the |
|
1877 |
* suitable criteria. |
|
1878 |
* |
|
10 | 1879 |
* See JLS 8.4.6.1 (without transitivity) and 8.4.6.4 |
1880 |
*/ |
|
1881 |
public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) { |
|
33367 | 1882 |
return overrides(_other, origin, types, checkResult, true); |
1883 |
} |
|
1884 |
||
1885 |
/** Does this symbol override `other' symbol, when both are seen as |
|
1886 |
* members of class `origin'? It is assumed that _other is a member |
|
1887 |
* of origin. |
|
1888 |
* |
|
1889 |
* Caveat: If `this' is an abstract inherited member of origin, it is |
|
1890 |
* deemed to override `other' only when `requireConcreteIfInherited' |
|
1891 |
* is false. |
|
1892 |
* |
|
1893 |
* It is assumed that both symbols have the same name. The static |
|
1894 |
* modifier is ignored for this test. |
|
1895 |
* |
|
1896 |
* See JLS 8.4.6.1 (without transitivity) and 8.4.6.4 |
|
1897 |
*/ |
|
1898 |
public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult, |
|
1899 |
boolean requireConcreteIfInherited) { |
|
10 | 1900 |
if (isConstructor() || _other.kind != MTH) return false; |
1901 |
||
1902 |
if (this == _other) return true; |
|
1903 |
MethodSymbol other = (MethodSymbol)_other; |
|
1904 |
||
1905 |
// check for a direct implementation |
|
1906 |
if (other.isOverridableIn((TypeSymbol)owner) && |
|
1907 |
types.asSuper(owner.type, other.owner) != null) { |
|
1908 |
Type mt = types.memberType(owner.type, this); |
|
1909 |
Type ot = types.memberType(owner.type, other); |
|
1910 |
if (types.isSubSignature(mt, ot)) { |
|
1911 |
if (!checkResult) |
|
1912 |
return true; |
|
1913 |
if (types.returnTypeSubstitutable(mt, ot)) |
|
1914 |
return true; |
|
1915 |
} |
|
1916 |
} |
|
1917 |
||
1918 |
// check for an inherited implementation |
|
33367 | 1919 |
if (((flags() & ABSTRACT) != 0 && requireConcreteIfInherited) || |
14547 | 1920 |
((other.flags() & ABSTRACT) == 0 && (other.flags() & DEFAULT) == 0) || |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1921 |
!other.isOverridableIn(origin) || |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1922 |
!this.isMemberOf(origin, types)) |
10 | 1923 |
return false; |
1924 |
||
1925 |
// assert types.asSuper(origin.type, other.owner) != null; |
|
1926 |
Type mt = types.memberType(origin.type, this); |
|
1927 |
Type ot = types.memberType(origin.type, other); |
|
1928 |
return |
|
1929 |
types.isSubSignature(mt, ot) && |
|
14547 | 1930 |
(!checkResult || types.resultSubtype(mt, ot, types.noWarnings)); |
10 | 1931 |
} |
1932 |
||
1933 |
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
|
1934 |
// JLS 8.4.6.1 |
10 | 1935 |
switch ((int)(flags_field & Flags.AccessFlags)) { |
1936 |
case Flags.PRIVATE: |
|
1937 |
return false; |
|
1938 |
case Flags.PUBLIC: |
|
15377
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1939 |
return !this.owner.isInterface() || |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1940 |
(flags_field & STATIC) == 0; |
10 | 1941 |
case Flags.PROTECTED: |
1942 |
return (origin.flags() & INTERFACE) == 0; |
|
1943 |
case 0: |
|
1944 |
// for package private: can only override in the same |
|
1945 |
// package |
|
1946 |
return |
|
1947 |
this.packge() == origin.packge() && |
|
1948 |
(origin.flags() & INTERFACE) == 0; |
|
1949 |
default: |
|
1950 |
return false; |
|
1951 |
} |
|
1952 |
} |
|
1953 |
||
15377
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1954 |
@Override |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1955 |
public boolean isInheritedIn(Symbol clazz, Types types) { |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1956 |
switch ((int)(flags_field & Flags.AccessFlags)) { |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1957 |
case PUBLIC: |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1958 |
return !this.owner.isInterface() || |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1959 |
clazz == owner || |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1960 |
(flags_field & STATIC) == 0; |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1961 |
default: |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1962 |
return super.isInheritedIn(clazz, types); |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1963 |
} |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1964 |
} |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15355
diff
changeset
|
1965 |
|
33364
542040bb5990
8138729: javac -parameters should not emit parameter names for lambda expressions
sadayapalam
parents:
30066
diff
changeset
|
1966 |
public boolean isLambdaMethod() { |
542040bb5990
8138729: javac -parameters should not emit parameter names for lambda expressions
sadayapalam
parents:
30066
diff
changeset
|
1967 |
return (flags() & LAMBDA_METHOD) == LAMBDA_METHOD; |
542040bb5990
8138729: javac -parameters should not emit parameter names for lambda expressions
sadayapalam
parents:
30066
diff
changeset
|
1968 |
} |
542040bb5990
8138729: javac -parameters should not emit parameter names for lambda expressions
sadayapalam
parents:
30066
diff
changeset
|
1969 |
|
54846
e4049522b074
8215470: Bad EnclosingMethod attribute on classes declared in lambdas
vromero
parents:
54762
diff
changeset
|
1970 |
/** override this method to point to the original enclosing method if this method symbol represents a synthetic |
e4049522b074
8215470: Bad EnclosingMethod attribute on classes declared in lambdas
vromero
parents:
54762
diff
changeset
|
1971 |
* lambda method |
e4049522b074
8215470: Bad EnclosingMethod attribute on classes declared in lambdas
vromero
parents:
54762
diff
changeset
|
1972 |
*/ |
e4049522b074
8215470: Bad EnclosingMethod attribute on classes declared in lambdas
vromero
parents:
54762
diff
changeset
|
1973 |
public MethodSymbol originalEnclosingMethod() { |
e4049522b074
8215470: Bad EnclosingMethod attribute on classes declared in lambdas
vromero
parents:
54762
diff
changeset
|
1974 |
return this; |
e4049522b074
8215470: Bad EnclosingMethod attribute on classes declared in lambdas
vromero
parents:
54762
diff
changeset
|
1975 |
} |
e4049522b074
8215470: Bad EnclosingMethod attribute on classes declared in lambdas
vromero
parents:
54762
diff
changeset
|
1976 |
|
10 | 1977 |
/** The implementation of this (abstract) symbol in class origin; |
1978 |
* null if none exists. Synthetic methods are not considered |
|
1979 |
* as possible implementations. |
|
1980 |
*/ |
|
1981 |
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
|
1982 |
return implementation(origin, types, checkResult, implementation_filter); |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1983 |
} |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1984 |
// where |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42822
diff
changeset
|
1985 |
public static final Filter<Symbol> implementation_filter = s -> |
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42822
diff
changeset
|
1986 |
s.kind == MTH && (s.flags() & SYNTHETIC) == 0; |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1987 |
|
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6584
diff
changeset
|
1988 |
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
|
1989 |
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
|
1990 |
if (res != null) |
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3149
diff
changeset
|
1991 |
return res; |
10 | 1992 |
// if origin is derived from a raw type, we might have missed |
1993 |
// an implementation because we do not know enough about instantiations. |
|
1994 |
// 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
|
1995 |
if (types.isDerivedRaw(origin.type) && !origin.isInterface()) |
10 | 1996 |
return implementation(types.supertype(origin.type).tsym, types, checkResult); |
1997 |
else |
|
1998 |
return null; |
|
1999 |
} |
|
2000 |
||
2001 |
public List<VarSymbol> params() { |
|
2002 |
owner.complete(); |
|
2003 |
if (params == null) { |
|
48344
89f6aa26fd6c
8007720: Names are not loaded correctly for method parameters if the parameters have annotations
cushon
parents:
47216
diff
changeset
|
2004 |
ListBuffer<VarSymbol> newParams = new ListBuffer<>(); |
4077
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
3539
diff
changeset
|
2005 |
int i = 0; |
10 | 2006 |
for (Type t : type.getParameterTypes()) { |
48344
89f6aa26fd6c
8007720: Names are not loaded correctly for method parameters if the parameters have annotations
cushon
parents:
47216
diff
changeset
|
2007 |
Name paramName = name.table.fromString("arg" + i); |
89f6aa26fd6c
8007720: Names are not loaded correctly for method parameters if the parameters have annotations
cushon
parents:
47216
diff
changeset
|
2008 |
VarSymbol param = new VarSymbol(PARAMETER, paramName, t, this); |
89f6aa26fd6c
8007720: Names are not loaded correctly for method parameters if the parameters have annotations
cushon
parents:
47216
diff
changeset
|
2009 |
newParams.append(param); |
48683
b2f2bdba0472
8194268: Incorrect parameter names for synthetic methods
cushon
parents:
48344
diff
changeset
|
2010 |
i++; |
10 | 2011 |
} |
48344
89f6aa26fd6c
8007720: Names are not loaded correctly for method parameters if the parameters have annotations
cushon
parents:
47216
diff
changeset
|
2012 |
params = newParams.toList(); |
10 | 2013 |
} |
48344
89f6aa26fd6c
8007720: Names are not loaded correctly for method parameters if the parameters have annotations
cushon
parents:
47216
diff
changeset
|
2014 |
Assert.checkNonNull(params); |
10 | 2015 |
return params; |
2016 |
} |
|
2017 |
||
2018 |
public Symbol asMemberOf(Type site, Types types) { |
|
2019 |
return new MethodSymbol(flags_field, name, types.memberType(site, this), owner); |
|
2020 |
} |
|
2021 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2022 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 2023 |
public ElementKind getKind() { |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
2024 |
if (name == name.table.names.init) |
10 | 2025 |
return ElementKind.CONSTRUCTOR; |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
2026 |
else if (name == name.table.names.clinit) |
10 | 2027 |
return ElementKind.STATIC_INIT; |
10626
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
2028 |
else if ((flags() & BLOCK) != 0) |
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
2029 |
return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT; |
10 | 2030 |
else |
2031 |
return ElementKind.METHOD; |
|
2032 |
} |
|
2033 |
||
10626
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
2034 |
public boolean isStaticOrInstanceInit() { |
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
2035 |
return getKind() == ElementKind.STATIC_INIT || |
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
2036 |
getKind() == ElementKind.INSTANCE_INIT; |
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
2037 |
} |
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
9812
diff
changeset
|
2038 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2039 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 2040 |
public Attribute getDefaultValue() { |
2041 |
return defaultValue; |
|
2042 |
} |
|
2043 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2044 |
@DefinedBy(Api.LANGUAGE_MODEL) |
15385 | 2045 |
public List<VarSymbol> getParameters() { |
10 | 2046 |
return params(); |
2047 |
} |
|
2048 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2049 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 2050 |
public boolean isVarArgs() { |
2051 |
return (flags() & VARARGS) != 0; |
|
2052 |
} |
|
2053 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2054 |
@DefinedBy(Api.LANGUAGE_MODEL) |
14956
185bd7c693d8
8005046: Provide checking for a default method in javax.lang.model
darcy
parents:
14547
diff
changeset
|
2055 |
public boolean isDefault() { |
185bd7c693d8
8005046: Provide checking for a default method in javax.lang.model
darcy
parents:
14547
diff
changeset
|
2056 |
return (flags() & DEFAULT) != 0; |
185bd7c693d8
8005046: Provide checking for a default method in javax.lang.model
darcy
parents:
14547
diff
changeset
|
2057 |
} |
185bd7c693d8
8005046: Provide checking for a default method in javax.lang.model
darcy
parents:
14547
diff
changeset
|
2058 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2059 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 2060 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
2061 |
return v.visitExecutable(this, p); |
|
2062 |
} |
|
2063 |
||
1357 | 2064 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
2065 |
return v.visitMethodSymbol(this, p); |
|
2066 |
} |
|
2067 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2068 |
@DefinedBy(Api.LANGUAGE_MODEL) |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16333
diff
changeset
|
2069 |
public Type getReceiverType() { |
55390
4a3c13548b9e
8222369: ExecutableElement.getReceiverType returns null instead of NOTYPE
darcy
parents:
54846
diff
changeset
|
2070 |
Type result = asType().getReceiverType(); |
4a3c13548b9e
8222369: ExecutableElement.getReceiverType returns null instead of NOTYPE
darcy
parents:
54846
diff
changeset
|
2071 |
return (result == null) ? Type.noType : result; |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16333
diff
changeset
|
2072 |
} |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
16333
diff
changeset
|
2073 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2074 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 2075 |
public Type getReturnType() { |
2076 |
return asType().getReturnType(); |
|
2077 |
} |
|
2078 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
2079 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 2080 |
public List<Type> getThrownTypes() { |
2081 |
return asType().getThrownTypes(); |
|
2082 |
} |
|
2083 |
} |
|
2084 |
||
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
2085 |
/** A class for invokedynamic method calls. |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
2086 |
*/ |
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2087 |
public static class DynamicMethodSymbol extends MethodSymbol implements Dynamic { |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
2088 |
|
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2089 |
public LoadableConstant[] staticArgs; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2090 |
public MethodHandleSymbol bsm; |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
2091 |
|
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2092 |
public DynamicMethodSymbol(Name name, Symbol owner, MethodHandleSymbol bsm, Type type, LoadableConstant[] staticArgs) { |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
2093 |
super(0, name, type, owner); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
2094 |
this.bsm = bsm; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
2095 |
this.staticArgs = staticArgs; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
2096 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
2097 |
|
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
2098 |
@Override |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
2099 |
public boolean isDynamic() { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
2100 |
return true; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
2101 |
} |
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2102 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2103 |
@Override |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2104 |
public LoadableConstant[] staticArgs() { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2105 |
return staticArgs; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2106 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2107 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2108 |
@Override |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2109 |
public MethodHandleSymbol bootstrapMethod() { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2110 |
return bsm; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2111 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2112 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2113 |
@Override |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2114 |
public int poolTag() { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2115 |
return ClassFile.CONSTANT_InvokeDynamic; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2116 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2117 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2118 |
@Override |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2119 |
public Type dynamicType() { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2120 |
return type; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2121 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2122 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2123 |
|
54762 | 2124 |
/** A class for condy. |
2125 |
*/ |
|
2126 |
public static class DynamicVarSymbol extends VarSymbol implements Dynamic, LoadableConstant { |
|
2127 |
public LoadableConstant[] staticArgs; |
|
2128 |
public MethodHandleSymbol bsm; |
|
2129 |
||
2130 |
public DynamicVarSymbol(Name name, Symbol owner, MethodHandleSymbol bsm, Type type, LoadableConstant[] staticArgs) { |
|
2131 |
super(0, name, type, owner); |
|
2132 |
this.bsm = bsm; |
|
2133 |
this.staticArgs = staticArgs; |
|
2134 |
} |
|
2135 |
||
2136 |
@Override |
|
2137 |
public boolean isDynamic() { |
|
2138 |
return true; |
|
2139 |
} |
|
2140 |
||
2141 |
@Override |
|
2142 |
public PoolConstant dynamicType() { |
|
2143 |
return type; |
|
2144 |
} |
|
2145 |
||
2146 |
@Override |
|
2147 |
public LoadableConstant[] staticArgs() { |
|
2148 |
return staticArgs; |
|
2149 |
} |
|
2150 |
||
2151 |
@Override |
|
2152 |
public LoadableConstant bootstrapMethod() { |
|
2153 |
return bsm; |
|
2154 |
} |
|
2155 |
||
2156 |
@Override |
|
2157 |
public int poolTag() { |
|
2158 |
return ClassFile.CONSTANT_Dynamic; |
|
2159 |
} |
|
2160 |
} |
|
2161 |
||
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2162 |
/** A class for method handles. |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2163 |
*/ |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2164 |
public static class MethodHandleSymbol extends MethodSymbol implements LoadableConstant { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2165 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2166 |
private Symbol refSym; |
54668
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2167 |
private boolean getter; |
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2168 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2169 |
public MethodHandleSymbol(Symbol msym) { |
54668
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2170 |
this(msym, false); |
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2171 |
} |
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2172 |
|
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2173 |
public MethodHandleSymbol(Symbol msym, boolean getter) { |
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2174 |
super(msym.flags_field, msym.name, msym.type, msym.owner); |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2175 |
this.refSym = msym; |
54668
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2176 |
this.getter = getter; |
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2177 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2178 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2179 |
/** |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2180 |
* Returns the kind associated with this method handle. |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2181 |
*/ |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2182 |
public int referenceKind() { |
54668
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2183 |
if (refSym.kind == VAR) { |
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2184 |
return getter ? |
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2185 |
refSym.isStatic() ? ClassFile.REF_getStatic : ClassFile.REF_getField : |
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2186 |
refSym.isStatic() ? ClassFile.REF_putStatic : ClassFile.REF_putField; |
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2187 |
} else { |
54668
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2188 |
if (refSym.isConstructor()) { |
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2189 |
return ClassFile.REF_newInvokeSpecial; |
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2190 |
} else { |
54668
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2191 |
if (refSym.isStatic()) { |
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2192 |
return ClassFile.REF_invokeStatic; |
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2193 |
} else if ((refSym.flags() & PRIVATE) != 0) { |
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2194 |
return ClassFile.REF_invokeSpecial; |
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2195 |
} else if (refSym.enclClass().isInterface()) { |
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2196 |
return ClassFile.REF_invokeInterface; |
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2197 |
} else { |
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2198 |
return ClassFile.REF_invokeVirtual; |
0bda2308eded
8222744: add support for generating method handles from a variable symbol
vromero
parents:
54568
diff
changeset
|
2199 |
} |
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2200 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2201 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2202 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2203 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2204 |
@Override |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2205 |
public int poolTag() { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2206 |
return ClassFile.CONSTANT_MethodHandle; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2207 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2208 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2209 |
@Override |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2210 |
public Object poolKey(Types types) { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2211 |
return new Pair<>(baseSymbol(), referenceKind()); |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2212 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2213 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2214 |
@Override |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2215 |
public MethodHandleSymbol asHandle() { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2216 |
return this; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2217 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2218 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2219 |
@Override |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2220 |
public Symbol baseSymbol() { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2221 |
return refSym; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2222 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2223 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2224 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2225 |
@Override |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2226 |
public boolean isHandle() { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2227 |
return true; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
54514
diff
changeset
|
2228 |
} |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
2229 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
2230 |
|
10 | 2231 |
/** A class for predefined operators. |
2232 |
*/ |
|
2233 |
public static class OperatorSymbol extends MethodSymbol { |
|
2234 |
||
2235 |
public int opcode; |
|
39920
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2236 |
private int accessCode = Integer.MIN_VALUE; |
10 | 2237 |
|
2238 |
public OperatorSymbol(Name name, Type type, int opcode, Symbol owner) { |
|
2239 |
super(PUBLIC | STATIC, name, type, owner); |
|
2240 |
this.opcode = opcode; |
|
2241 |
} |
|
1357 | 2242 |
|
39920
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2243 |
@Override |
1357 | 2244 |
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
2245 |
return v.visitOperatorSymbol(this, p); |
|
2246 |
} |
|
39920
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2247 |
|
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2248 |
public int getAccessCode(Tag tag) { |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2249 |
if (accessCode != Integer.MIN_VALUE && !tag.isIncOrDecUnaryOp()) { |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2250 |
return accessCode; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2251 |
} |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2252 |
accessCode = AccessCode.from(tag, opcode); |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2253 |
return accessCode; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2254 |
} |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2255 |
|
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2256 |
/** Access codes for dereferencing, assignment, |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2257 |
* and pre/post increment/decrement. |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2258 |
|
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2259 |
* All access codes for accesses to the current class are even. |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2260 |
* If a member of the superclass should be accessed instead (because |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2261 |
* access was via a qualified super), add one to the corresponding code |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2262 |
* for the current class, making the number odd. |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2263 |
* This numbering scheme is used by the backend to decide whether |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2264 |
* to issue an invokevirtual or invokespecial call. |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2265 |
* |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2266 |
* @see Gen#visitSelect(JCFieldAccess tree) |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2267 |
*/ |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2268 |
public enum AccessCode { |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2269 |
UNKNOWN(-1, Tag.NO_TAG), |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2270 |
DEREF(0, Tag.NO_TAG), |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2271 |
ASSIGN(2, Tag.ASSIGN), |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2272 |
PREINC(4, Tag.PREINC), |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2273 |
PREDEC(6, Tag.PREDEC), |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2274 |
POSTINC(8, Tag.POSTINC), |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2275 |
POSTDEC(10, Tag.POSTDEC), |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2276 |
FIRSTASGOP(12, Tag.NO_TAG); |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2277 |
|
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2278 |
public final int code; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2279 |
public final Tag tag; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2280 |
public static final int numberOfAccessCodes = (lushrl - ishll + lxor + 2 - iadd) * 2 + FIRSTASGOP.code + 2; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2281 |
|
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2282 |
AccessCode(int code, Tag tag) { |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2283 |
this.code = code; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2284 |
this.tag = tag; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2285 |
} |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2286 |
|
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2287 |
static public AccessCode getFromCode(int code) { |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2288 |
for (AccessCode aCodes : AccessCode.values()) { |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2289 |
if (aCodes.code == code) { |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2290 |
return aCodes; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2291 |
} |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2292 |
} |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2293 |
return UNKNOWN; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2294 |
} |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2295 |
|
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2296 |
static int from(Tag tag, int opcode) { |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2297 |
/** Map bytecode of binary operation to access code of corresponding |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2298 |
* assignment operation. This is always an even number. |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2299 |
*/ |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2300 |
switch (tag) { |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2301 |
case PREINC: |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2302 |
return AccessCode.PREINC.code; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2303 |
case PREDEC: |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2304 |
return AccessCode.PREDEC.code; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2305 |
case POSTINC: |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2306 |
return AccessCode.POSTINC.code; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2307 |
case POSTDEC: |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2308 |
return AccessCode.POSTDEC.code; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2309 |
} |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2310 |
if (iadd <= opcode && opcode <= lxor) { |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2311 |
return (opcode - iadd) * 2 + FIRSTASGOP.code; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2312 |
} else if (opcode == string_add) { |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2313 |
return (lxor + 1 - iadd) * 2 + FIRSTASGOP.code; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2314 |
} else if (ishll <= opcode && opcode <= lushrl) { |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2315 |
return (opcode - ishll + lxor + 2 - iadd) * 2 + FIRSTASGOP.code; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2316 |
} |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2317 |
return -1; |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2318 |
} |
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39372
diff
changeset
|
2319 |
} |
10 | 2320 |
} |
2321 |
||
2322 |
/** Symbol completer interface. |
|
2323 |
*/ |
|
2324 |
public static interface Completer { |
|
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
2325 |
|
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
2326 |
/** 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
|
2327 |
* does not need completion. |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
2328 |
*/ |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
2329 |
public final static Completer NULL_COMPLETER = new Completer() { |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
2330 |
public void complete(Symbol sym) { } |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
2331 |
public boolean isTerminal() { return true; } |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
2332 |
}; |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
2333 |
|
10 | 2334 |
void complete(Symbol sym) throws CompletionFailure; |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
2335 |
|
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
2336 |
/** 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
|
2337 |
* 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
|
2338 |
* 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
|
2339 |
* |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
2340 |
* The dummy NULL_COMPLETER and the GraphDependencies completer are |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
2341 |
* examples of terminal completers. |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
2342 |
* |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
2343 |
* @return true iff this completer is terminal |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
2344 |
*/ |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
2345 |
default boolean isTerminal() { |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
2346 |
return false; |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
2347 |
} |
10 | 2348 |
} |
2349 |
||
2350 |
public static class CompletionFailure extends RuntimeException { |
|
2351 |
private static final long serialVersionUID = 0; |
|
58350
e23e560afbcb
8231414: Mark various instance fields of javac internal types as transient
darcy
parents:
55390
diff
changeset
|
2352 |
public final transient DeferredCompletionFailureHandler dcfh; |
e23e560afbcb
8231414: Mark various instance fields of javac internal types as transient
darcy
parents:
55390
diff
changeset
|
2353 |
public transient Symbol sym; |
10 | 2354 |
|
169 | 2355 |
/** A diagnostic object describing the failure |
2356 |
*/ |
|
58350
e23e560afbcb
8231414: Mark various instance fields of javac internal types as transient
darcy
parents:
55390
diff
changeset
|
2357 |
private transient JCDiagnostic diag; |
169 | 2358 |
|
58350
e23e560afbcb
8231414: Mark various instance fields of javac internal types as transient
darcy
parents:
55390
diff
changeset
|
2359 |
private transient Supplier<JCDiagnostic> diagSupplier; |
54339
f69a2f675f19
8221118: Avoid eagerly creating JCDiagnostic for CompletionFailures
ronsh
parents:
49197
diff
changeset
|
2360 |
|
f69a2f675f19
8221118: Avoid eagerly creating JCDiagnostic for CompletionFailures
ronsh
parents:
49197
diff
changeset
|
2361 |
public CompletionFailure(Symbol sym, Supplier<JCDiagnostic> diagSupplier, DeferredCompletionFailureHandler dcfh) { |
49197
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
48945
diff
changeset
|
2362 |
this.dcfh = dcfh; |
169 | 2363 |
this.sym = sym; |
54339
f69a2f675f19
8221118: Avoid eagerly creating JCDiagnostic for CompletionFailures
ronsh
parents:
49197
diff
changeset
|
2364 |
this.diagSupplier = diagSupplier; |
169 | 2365 |
// this.printStackTrace();//DEBUG |
2366 |
} |
|
2367 |
||
2368 |
public JCDiagnostic getDiagnostic() { |
|
54339
f69a2f675f19
8221118: Avoid eagerly creating JCDiagnostic for CompletionFailures
ronsh
parents:
49197
diff
changeset
|
2369 |
if (diag == null && diagSupplier != null) { |
f69a2f675f19
8221118: Avoid eagerly creating JCDiagnostic for CompletionFailures
ronsh
parents:
49197
diff
changeset
|
2370 |
diag = diagSupplier.get(); |
f69a2f675f19
8221118: Avoid eagerly creating JCDiagnostic for CompletionFailures
ronsh
parents:
49197
diff
changeset
|
2371 |
} |
169 | 2372 |
return diag; |
2373 |
} |
|
2374 |
||
2375 |
@Override |
|
10 | 2376 |
public String getMessage() { |
54339
f69a2f675f19
8221118: Avoid eagerly creating JCDiagnostic for CompletionFailures
ronsh
parents:
49197
diff
changeset
|
2377 |
return getDiagnostic().getMessage(null); |
169 | 2378 |
} |
2379 |
||
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
43772
diff
changeset
|
2380 |
public JCDiagnostic getDetailValue() { |
54339
f69a2f675f19
8221118: Avoid eagerly creating JCDiagnostic for CompletionFailures
ronsh
parents:
49197
diff
changeset
|
2381 |
return getDiagnostic(); |
10 | 2382 |
} |
2383 |
||
2384 |
@Override |
|
2385 |
public CompletionFailure initCause(Throwable cause) { |
|
2386 |
super.initCause(cause); |
|
2387 |
return this; |
|
2388 |
} |
|
2389 |
||
54339
f69a2f675f19
8221118: Avoid eagerly creating JCDiagnostic for CompletionFailures
ronsh
parents:
49197
diff
changeset
|
2390 |
public void resetDiagnostic(Supplier<JCDiagnostic> diagSupplier) { |
f69a2f675f19
8221118: Avoid eagerly creating JCDiagnostic for CompletionFailures
ronsh
parents:
49197
diff
changeset
|
2391 |
this.diagSupplier = diagSupplier; |
f69a2f675f19
8221118: Avoid eagerly creating JCDiagnostic for CompletionFailures
ronsh
parents:
49197
diff
changeset
|
2392 |
this.diag = null; |
f69a2f675f19
8221118: Avoid eagerly creating JCDiagnostic for CompletionFailures
ronsh
parents:
49197
diff
changeset
|
2393 |
} |
f69a2f675f19
8221118: Avoid eagerly creating JCDiagnostic for CompletionFailures
ronsh
parents:
49197
diff
changeset
|
2394 |
|
10 | 2395 |
} |
1357 | 2396 |
|
2397 |
/** |
|
2398 |
* A visitor for symbols. A visitor is used to implement operations |
|
2399 |
* (or relations) on symbols. Most common operations on types are |
|
2400 |
* binary relations and this interface is designed for binary |
|
2401 |
* relations, that is, operations on the form |
|
2402 |
* Symbol × P → R. |
|
2403 |
* <!-- In plain text: Type x P -> R --> |
|
2404 |
* |
|
2405 |
* @param <R> the return type of the operation implemented by this |
|
2406 |
* visitor; use Void if no return type is needed. |
|
2407 |
* @param <P> the type of the second argument (the first being the |
|
2408 |
* symbol itself) of the operation implemented by this visitor; use |
|
2409 |
* Void if a second argument is not needed. |
|
2410 |
*/ |
|
2411 |
public interface Visitor<R,P> { |
|
2412 |
R visitClassSymbol(ClassSymbol s, P arg); |
|
2413 |
R visitMethodSymbol(MethodSymbol s, P arg); |
|
2414 |
R visitPackageSymbol(PackageSymbol s, P arg); |
|
2415 |
R visitOperatorSymbol(OperatorSymbol s, P arg); |
|
2416 |
R visitVarSymbol(VarSymbol s, P arg); |
|
2417 |
R visitTypeSymbol(TypeSymbol s, P arg); |
|
2418 |
R visitSymbol(Symbol s, P arg); |
|
2419 |
} |
|
10 | 2420 |
} |