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