author | jlahoda |
Mon, 21 Oct 2019 15:38:26 +0200 | |
changeset 58713 | ad69fd32778e |
parent 53275 | f5e601ad26a8 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
53275
f5e601ad26a8
8215482: check for cycles in type variables can provoke NPE
vromero
parents:
50374
diff
changeset
|
2 |
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.comp; |
|
27 |
||
15385 | 28 |
import java.util.HashSet; |
10 | 29 |
import java.util.Set; |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31299
diff
changeset
|
30 |
import java.util.function.BiConsumer; |
15385 | 31 |
|
10 | 32 |
import javax.tools.JavaFileObject; |
33 |
||
34 |
import com.sun.tools.javac.code.*; |
|
27854
22b4bfc4e22f
8032211: Don't issue deprecation warnings on import statements
jlahoda
parents:
27231
diff
changeset
|
35 |
import com.sun.tools.javac.code.Lint.LintCategory; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25007
diff
changeset
|
36 |
import com.sun.tools.javac.code.Scope.ImportFilter; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25007
diff
changeset
|
37 |
import com.sun.tools.javac.code.Scope.NamedImportScope; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25007
diff
changeset
|
38 |
import com.sun.tools.javac.code.Scope.StarImportScope; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25007
diff
changeset
|
39 |
import com.sun.tools.javac.code.Scope.WriteableScope; |
48054
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47350
diff
changeset
|
40 |
import com.sun.tools.javac.code.Source.Feature; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29149
diff
changeset
|
41 |
import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata; |
10 | 42 |
import com.sun.tools.javac.tree.*; |
43 |
import com.sun.tools.javac.util.*; |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
44 |
import com.sun.tools.javac.util.DefinedBy.Api; |
10 | 45 |
|
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
46 |
import com.sun.tools.javac.code.Symbol.*; |
10 | 47 |
import com.sun.tools.javac.code.Type.*; |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
43141
diff
changeset
|
48 |
import com.sun.tools.javac.resources.CompilerProperties.Errors; |
10 | 49 |
import com.sun.tools.javac.tree.JCTree.*; |
50 |
||
51 |
import static com.sun.tools.javac.code.Flags.*; |
|
10950 | 52 |
import static com.sun.tools.javac.code.Flags.ANNOTATION; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
53 |
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
54 |
import static com.sun.tools.javac.code.Kinds.Kind.*; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
55 |
import static com.sun.tools.javac.code.TypeTag.CLASS; |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
56 |
import static com.sun.tools.javac.code.TypeTag.ERROR; |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
43141
diff
changeset
|
57 |
import com.sun.tools.javac.resources.CompilerProperties.Fragments; |
10950 | 58 |
import static com.sun.tools.javac.tree.JCTree.Tag.*; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24396
diff
changeset
|
59 |
|
27857 | 60 |
import com.sun.tools.javac.util.Dependencies.CompletionCause; |
11709
0d56d3fc22e6
7129225: javac fails to run annotation processors when star import of package of gensrc
jjh
parents:
10950
diff
changeset
|
61 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; |
10 | 62 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
63 |
||
64 |
/** This is the second phase of Enter, in which classes are completed |
|
27857 | 65 |
* by resolving their headers and entering their members in the into |
66 |
* the class scope. See Enter for an overall overview. |
|
67 |
* |
|
68 |
* This class uses internal phases to process the classes. When a phase |
|
69 |
* processes classes, the lower phases are not invoked until all classes |
|
70 |
* pass through the current phase. Note that it is possible that upper phases |
|
71 |
* are run due to recursive completion. The internal phases are: |
|
72 |
* - ImportPhase: shallow pass through imports, adds information about imports |
|
73 |
* the NamedImportScope and StarImportScope, but avoids queries |
|
74 |
* about class hierarchy. |
|
75 |
* - HierarchyPhase: resolves the supertypes of the given class. Does not handle |
|
76 |
* type parameters of the class or type argument of the supertypes. |
|
77 |
* - HeaderPhase: finishes analysis of the header of the given class by resolving |
|
78 |
* type parameters, attributing supertypes including type arguments |
|
79 |
* and scheduling full annotation attribution. This phase also adds |
|
80 |
* a synthetic default constructor if needed and synthetic "this" field. |
|
81 |
* - MembersPhase: resolves headers for fields, methods and constructors in the given class. |
|
82 |
* Also generates synthetic enum members. |
|
10 | 83 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
84 |
* <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
|
85 |
* If you write code that depends on this, you do so at your own risk. |
10 | 86 |
* This code and its internal interfaces are subject to change or |
87 |
* deletion without notice.</b> |
|
88 |
*/ |
|
27857 | 89 |
public class TypeEnter implements Completer { |
90 |
protected static final Context.Key<TypeEnter> typeEnterKey = new Context.Key<>(); |
|
10 | 91 |
|
92 |
/** A switch to determine whether we check for package/class conflicts |
|
93 |
*/ |
|
94 |
final static boolean checkClash = true; |
|
95 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1045
diff
changeset
|
96 |
private final Names names; |
10 | 97 |
private final Enter enter; |
27857 | 98 |
private final MemberEnter memberEnter; |
10 | 99 |
private final Log log; |
100 |
private final Check chk; |
|
101 |
private final Attr attr; |
|
102 |
private final Symtab syms; |
|
103 |
private final TreeMaker make; |
|
104 |
private final Todo todo; |
|
105 |
private final Annotate annotate; |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
106 |
private final TypeAnnotations typeAnnotations; |
10 | 107 |
private final Types types; |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
108 |
private final JCDiagnostic.Factory diags; |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
109 |
private final DeferredLintHandler deferredLintHandler; |
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
110 |
private final Lint lint; |
25007 | 111 |
private final TypeEnvs typeEnvs; |
25844
48eab270456c
8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents:
25443
diff
changeset
|
112 |
private final Dependencies dependencies; |
10 | 113 |
|
27857 | 114 |
public static TypeEnter instance(Context context) { |
115 |
TypeEnter instance = context.get(typeEnterKey); |
|
10 | 116 |
if (instance == null) |
27857 | 117 |
instance = new TypeEnter(context); |
10 | 118 |
return instance; |
119 |
} |
|
120 |
||
27857 | 121 |
protected TypeEnter(Context context) { |
122 |
context.put(typeEnterKey, this); |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1045
diff
changeset
|
123 |
names = Names.instance(context); |
10 | 124 |
enter = Enter.instance(context); |
27857 | 125 |
memberEnter = MemberEnter.instance(context); |
10 | 126 |
log = Log.instance(context); |
127 |
chk = Check.instance(context); |
|
128 |
attr = Attr.instance(context); |
|
129 |
syms = Symtab.instance(context); |
|
130 |
make = TreeMaker.instance(context); |
|
131 |
todo = Todo.instance(context); |
|
132 |
annotate = Annotate.instance(context); |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
133 |
typeAnnotations = TypeAnnotations.instance(context); |
10 | 134 |
types = Types.instance(context); |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
135 |
diags = JCDiagnostic.Factory.instance(context); |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
136 |
deferredLintHandler = DeferredLintHandler.instance(context); |
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
137 |
lint = Lint.instance(context); |
25007 | 138 |
typeEnvs = TypeEnvs.instance(context); |
25844
48eab270456c
8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents:
25443
diff
changeset
|
139 |
dependencies = Dependencies.instance(context); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29149
diff
changeset
|
140 |
Source source = Source.instance(context); |
48054
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47350
diff
changeset
|
141 |
allowTypeAnnos = Feature.TYPE_ANNOTATIONS.allowedInSource(source); |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47350
diff
changeset
|
142 |
allowDeprecationOnImport = Feature.DEPRECATION_ON_IMPORT.allowedInSource(source); |
10 | 143 |
} |
144 |
||
18643
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18389
diff
changeset
|
145 |
/** Switch: support type annotations. |
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18389
diff
changeset
|
146 |
*/ |
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18389
diff
changeset
|
147 |
boolean allowTypeAnnos; |
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18389
diff
changeset
|
148 |
|
27854
22b4bfc4e22f
8032211: Don't issue deprecation warnings on import statements
jlahoda
parents:
27231
diff
changeset
|
149 |
/** |
22b4bfc4e22f
8032211: Don't issue deprecation warnings on import statements
jlahoda
parents:
27231
diff
changeset
|
150 |
* Switch: should deprecation warnings be issued on import |
22b4bfc4e22f
8032211: Don't issue deprecation warnings on import statements
jlahoda
parents:
27231
diff
changeset
|
151 |
*/ |
22b4bfc4e22f
8032211: Don't issue deprecation warnings on import statements
jlahoda
parents:
27231
diff
changeset
|
152 |
boolean allowDeprecationOnImport; |
22b4bfc4e22f
8032211: Don't issue deprecation warnings on import statements
jlahoda
parents:
27231
diff
changeset
|
153 |
|
10 | 154 |
/** A flag to disable completion from time to time during member |
155 |
* enter, as we only need to look up types. This avoids |
|
156 |
* unnecessarily deep recursion. |
|
157 |
*/ |
|
158 |
boolean completionEnabled = true; |
|
159 |
||
27857 | 160 |
/* Verify Imports: |
10 | 161 |
*/ |
27857 | 162 |
protected void ensureImportsChecked(List<JCCompilationUnit> trees) { |
163 |
// if there remain any unimported toplevels (these must have |
|
164 |
// no classes at all), process their import statements as well. |
|
165 |
for (JCCompilationUnit tree : trees) { |
|
29149
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
166 |
if (!tree.starImportScope.isFilled()) { |
27857 | 167 |
Env<AttrContext> topEnv = enter.topLevelEnv(tree); |
168 |
finishImports(tree, () -> { completeClass.resolveImports(tree, topEnv); }); |
|
10 | 169 |
} |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29149
diff
changeset
|
170 |
} |
10 | 171 |
} |
172 |
||
173 |
/* ******************************************************************** |
|
174 |
* Source completer |
|
175 |
*********************************************************************/ |
|
176 |
||
177 |
/** Complete entering a class. |
|
178 |
* @param sym The symbol of the class to be completed. |
|
179 |
*/ |
|
41637 | 180 |
@Override |
10 | 181 |
public void complete(Symbol sym) throws CompletionFailure { |
182 |
// Suppress some (recursive) MemberEnter invocations |
|
183 |
if (!completionEnabled) { |
|
184 |
// Re-install same completer for next time around and return. |
|
8032 | 185 |
Assert.check((sym.flags() & Flags.COMPOUND) == 0); |
10 | 186 |
sym.completer = this; |
187 |
return; |
|
188 |
} |
|
189 |
||
27231
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
190 |
try { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29149
diff
changeset
|
191 |
annotate.blockAnnotations(); |
27857 | 192 |
sym.flags_field |= UNATTRIBUTED; |
1043
11ea4773b0af
6695838: javac does not detect cyclic inheritance involving static inner classes after import clause
mcimadamore
parents:
1040
diff
changeset
|
193 |
|
27857 | 194 |
List<Env<AttrContext>> queue; |
27231
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
195 |
|
27857 | 196 |
dependencies.push((ClassSymbol) sym, CompletionCause.MEMBER_ENTER); |
197 |
try { |
|
32913
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
198 |
queue = completeClass.completeEnvs(List.of(typeEnvs.get((ClassSymbol) sym))); |
27231
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
199 |
} finally { |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
200 |
dependencies.pop(); |
10 | 201 |
} |
202 |
||
27857 | 203 |
if (!queue.isEmpty()) { |
204 |
Set<JCCompilationUnit> seen = new HashSet<>(); |
|
205 |
||
206 |
for (Env<AttrContext> env : queue) { |
|
207 |
if (env.toplevel.defs.contains(env.enclClass) && seen.add(env.toplevel)) { |
|
208 |
finishImports(env.toplevel, () -> {}); |
|
10 | 209 |
} |
210 |
} |
|
14369
3d660d08d1f7
7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents:
14359
diff
changeset
|
211 |
} |
10 | 212 |
} finally { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29149
diff
changeset
|
213 |
annotate.unblockAnnotations(); |
15385 | 214 |
} |
215 |
} |
|
10 | 216 |
|
27857 | 217 |
void finishImports(JCCompilationUnit toplevel, Runnable resolve) { |
218 |
JavaFileObject prev = log.useSource(toplevel.sourcefile); |
|
10 | 219 |
try { |
27857 | 220 |
resolve.run(); |
221 |
chk.checkImportsUnique(toplevel); |
|
222 |
chk.checkImportsResolvable(toplevel); |
|
31299
81ce5febcae8
4869999: Error on import statement naming package containing no class files
sadayapalam
parents:
30066
diff
changeset
|
223 |
chk.checkImportedPackagesObservable(toplevel); |
27857 | 224 |
toplevel.namedImportScope.finalizeScope(); |
225 |
toplevel.starImportScope.finalizeScope(); |
|
50374
2d0647b9ac18
8198378: javac crash when checking imports and a broken class is present
jlahoda
parents:
48054
diff
changeset
|
226 |
} catch (CompletionFailure cf) { |
2d0647b9ac18
8198378: javac crash when checking imports and a broken class is present
jlahoda
parents:
48054
diff
changeset
|
227 |
chk.completionError(toplevel.pos(), cf); |
10 | 228 |
} finally { |
229 |
log.useSource(prev); |
|
230 |
} |
|
231 |
} |
|
232 |
||
27857 | 233 |
abstract class Phase { |
234 |
private final ListBuffer<Env<AttrContext>> queue = new ListBuffer<>(); |
|
235 |
private final Phase next; |
|
236 |
private final CompletionCause phaseName; |
|
237 |
||
238 |
Phase(CompletionCause phaseName, Phase next) { |
|
239 |
this.phaseName = phaseName; |
|
240 |
this.next = next; |
|
241 |
} |
|
242 |
||
32913
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
243 |
public final List<Env<AttrContext>> completeEnvs(List<Env<AttrContext>> envs) { |
27857 | 244 |
boolean firstToComplete = queue.isEmpty(); |
245 |
||
39371
ac04aefa4ba6
8148131: compilation result depends on order of sources
jlahoda
parents:
37942
diff
changeset
|
246 |
Phase prevTopLevelPhase = topLevelPhase; |
47350
d65c3b21081c
8186694: JShell: speed-up compilation by reusing compiler instances
jlahoda
parents:
47248
diff
changeset
|
247 |
boolean success = false; |
39371
ac04aefa4ba6
8148131: compilation result depends on order of sources
jlahoda
parents:
37942
diff
changeset
|
248 |
|
ac04aefa4ba6
8148131: compilation result depends on order of sources
jlahoda
parents:
37942
diff
changeset
|
249 |
try { |
ac04aefa4ba6
8148131: compilation result depends on order of sources
jlahoda
parents:
37942
diff
changeset
|
250 |
topLevelPhase = this; |
ac04aefa4ba6
8148131: compilation result depends on order of sources
jlahoda
parents:
37942
diff
changeset
|
251 |
doCompleteEnvs(envs); |
47350
d65c3b21081c
8186694: JShell: speed-up compilation by reusing compiler instances
jlahoda
parents:
47248
diff
changeset
|
252 |
success = true; |
39371
ac04aefa4ba6
8148131: compilation result depends on order of sources
jlahoda
parents:
37942
diff
changeset
|
253 |
} finally { |
ac04aefa4ba6
8148131: compilation result depends on order of sources
jlahoda
parents:
37942
diff
changeset
|
254 |
topLevelPhase = prevTopLevelPhase; |
47350
d65c3b21081c
8186694: JShell: speed-up compilation by reusing compiler instances
jlahoda
parents:
47248
diff
changeset
|
255 |
if (!success && firstToComplete) { |
d65c3b21081c
8186694: JShell: speed-up compilation by reusing compiler instances
jlahoda
parents:
47248
diff
changeset
|
256 |
//an exception was thrown, e.g. BreakAttr: |
d65c3b21081c
8186694: JShell: speed-up compilation by reusing compiler instances
jlahoda
parents:
47248
diff
changeset
|
257 |
//the queue would become stale, clear it: |
d65c3b21081c
8186694: JShell: speed-up compilation by reusing compiler instances
jlahoda
parents:
47248
diff
changeset
|
258 |
queue.clear(); |
d65c3b21081c
8186694: JShell: speed-up compilation by reusing compiler instances
jlahoda
parents:
47248
diff
changeset
|
259 |
} |
39371
ac04aefa4ba6
8148131: compilation result depends on order of sources
jlahoda
parents:
37942
diff
changeset
|
260 |
} |
32913
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
261 |
|
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
262 |
if (firstToComplete) { |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
263 |
List<Env<AttrContext>> out = queue.toList(); |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
264 |
|
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
265 |
queue.clear(); |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
266 |
return next != null ? next.completeEnvs(out) : out; |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
267 |
} else { |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
268 |
return List.nil(); |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
269 |
} |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
270 |
} |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
271 |
|
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
272 |
protected void doCompleteEnvs(List<Env<AttrContext>> envs) { |
27857 | 273 |
for (Env<AttrContext> env : envs) { |
274 |
JCClassDecl tree = (JCClassDecl)env.tree; |
|
275 |
||
276 |
queue.add(env); |
|
277 |
||
278 |
JavaFileObject prev = log.useSource(env.toplevel.sourcefile); |
|
279 |
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); |
|
280 |
try { |
|
281 |
dependencies.push(env.enclClass.sym, phaseName); |
|
32913
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
282 |
runPhase(env); |
27857 | 283 |
} catch (CompletionFailure ex) { |
284 |
chk.completionError(tree.pos(), ex); |
|
285 |
} finally { |
|
286 |
dependencies.pop(); |
|
287 |
deferredLintHandler.setPos(prevLintPos); |
|
288 |
log.useSource(prev); |
|
289 |
} |
|
290 |
} |
|
32913
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
291 |
} |
27857 | 292 |
|
32913
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
293 |
protected abstract void runPhase(Env<AttrContext> env); |
10 | 294 |
} |
295 |
||
27857 | 296 |
private final ImportsPhase completeClass = new ImportsPhase(); |
39371
ac04aefa4ba6
8148131: compilation result depends on order of sources
jlahoda
parents:
37942
diff
changeset
|
297 |
private Phase topLevelPhase; |
27857 | 298 |
|
299 |
/**Analyze import clauses. |
|
300 |
*/ |
|
301 |
private final class ImportsPhase extends Phase { |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
302 |
|
27857 | 303 |
public ImportsPhase() { |
304 |
super(CompletionCause.IMPORTS_PHASE, new HierarchyPhase()); |
|
305 |
} |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
306 |
|
27857 | 307 |
Env<AttrContext> env; |
308 |
ImportFilter staticImportFilter; |
|
29149
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
309 |
ImportFilter typeImportFilter; |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31299
diff
changeset
|
310 |
BiConsumer<JCImport, CompletionFailure> cfHandler = |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31299
diff
changeset
|
311 |
(imp, cf) -> chk.completionError(imp.pos(), cf); |
27857 | 312 |
|
313 |
@Override |
|
32913
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
314 |
protected void runPhase(Env<AttrContext> env) { |
27857 | 315 |
JCClassDecl tree = env.enclClass; |
316 |
ClassSymbol sym = tree.sym; |
|
317 |
||
318 |
// If sym is a toplevel-class, make sure any import |
|
319 |
// clauses in its source file have been seen. |
|
320 |
if (sym.owner.kind == PCK) { |
|
321 |
resolveImports(env.toplevel, env.enclosing(TOPLEVEL)); |
|
322 |
todo.append(env); |
|
323 |
} |
|
324 |
||
325 |
if (sym.owner.kind == TYP) |
|
326 |
sym.owner.complete(); |
|
327 |
} |
|
328 |
||
329 |
private void resolveImports(JCCompilationUnit tree, Env<AttrContext> env) { |
|
29149
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
330 |
if (tree.starImportScope.isFilled()) { |
27857 | 331 |
// we must have already processed this toplevel |
332 |
return; |
|
333 |
} |
|
334 |
||
335 |
ImportFilter prevStaticImportFilter = staticImportFilter; |
|
29149
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
336 |
ImportFilter prevTypeImportFilter = typeImportFilter; |
27857 | 337 |
DiagnosticPosition prevLintPos = deferredLintHandler.immediate(); |
338 |
Lint prevLint = chk.setLint(lint); |
|
339 |
Env<AttrContext> prevEnv = this.env; |
|
340 |
try { |
|
341 |
this.env = env; |
|
342 |
final PackageSymbol packge = env.toplevel.packge; |
|
29149
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
343 |
this.staticImportFilter = |
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
344 |
(origin, sym) -> sym.isStatic() && |
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
345 |
chk.importAccessible(sym, packge) && |
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
346 |
sym.isMemberOf((TypeSymbol) origin.owner, types); |
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
347 |
this.typeImportFilter = |
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
348 |
(origin, sym) -> sym.kind == TYP && |
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
349 |
chk.importAccessible(sym, packge); |
27857 | 350 |
|
351 |
// Import-on-demand java.lang. |
|
36526 | 352 |
PackageSymbol javaLang = syms.enterPackage(syms.java_base, names.java_lang); |
31299
81ce5febcae8
4869999: Error on import statement naming package containing no class files
sadayapalam
parents:
30066
diff
changeset
|
353 |
if (javaLang.members().isEmpty() && !javaLang.exists()) |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
43141
diff
changeset
|
354 |
throw new FatalError(diags.fragment(Fragments.FatalErrNoJavaLang)); |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31299
diff
changeset
|
355 |
importAll(make.at(tree.pos()).Import(make.QualIdent(javaLang), false), javaLang, env); |
27857 | 356 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
357 |
JCModuleDecl decl = tree.getModuleDecl(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
358 |
|
27857 | 359 |
// Process the package def and all import clauses. |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
360 |
if (tree.getPackage() != null && decl == null) |
27857 | 361 |
checkClassPackageClash(tree.getPackage()); |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
362 |
|
27857 | 363 |
for (JCImport imp : tree.getImports()) { |
364 |
doImport(imp); |
|
365 |
} |
|
42407
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 |
if (decl != null) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
368 |
//check @Deprecated: |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
369 |
markDeprecated(decl.sym, decl.mods.annotations, env); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
370 |
// process module annotations |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
371 |
annotate.annotateLater(decl.mods.annotations, env, env.toplevel.modle, null); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
372 |
} |
27857 | 373 |
} finally { |
374 |
this.env = prevEnv; |
|
375 |
chk.setLint(prevLint); |
|
376 |
deferredLintHandler.setPos(prevLintPos); |
|
377 |
this.staticImportFilter = prevStaticImportFilter; |
|
29149
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
378 |
this.typeImportFilter = prevTypeImportFilter; |
27857 | 379 |
} |
380 |
} |
|
381 |
||
382 |
private void checkClassPackageClash(JCPackageDecl tree) { |
|
383 |
// check that no class exists with same fully qualified name as |
|
384 |
// toplevel package |
|
385 |
if (checkClash && tree.pid != null) { |
|
386 |
Symbol p = env.toplevel.packge; |
|
387 |
while (p.owner != syms.rootPackage) { |
|
388 |
p.owner.complete(); // enter all class members of p |
|
36526 | 389 |
//need to lookup the owning module/package: |
390 |
PackageSymbol pack = syms.lookupPackage(env.toplevel.modle, p.owner.getQualifiedName()); |
|
391 |
if (syms.getClass(pack.modle, p.getQualifiedName()) != null) { |
|
27857 | 392 |
log.error(tree.pos, |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
43141
diff
changeset
|
393 |
Errors.PkgClashesWithClassOfSameName(p)); |
27857 | 394 |
} |
395 |
p = p.owner; |
|
396 |
} |
|
397 |
} |
|
398 |
// process package annotations |
|
399 |
annotate.annotateLater(tree.annotations, env, env.toplevel.packge, null); |
|
400 |
} |
|
401 |
||
402 |
private void doImport(JCImport tree) { |
|
403 |
JCFieldAccess imp = (JCFieldAccess)tree.qualid; |
|
404 |
Name name = TreeInfo.name(imp); |
|
405 |
||
406 |
// Create a local environment pointing to this tree to disable |
|
407 |
// effects of other imports in Resolve.findGlobalType |
|
408 |
Env<AttrContext> localEnv = env.dup(tree); |
|
409 |
||
410 |
TypeSymbol p = attr.attribImportQualifier(tree, localEnv).tsym; |
|
411 |
if (name == names.asterisk) { |
|
412 |
// Import on demand. |
|
413 |
chk.checkCanonical(imp.selected); |
|
414 |
if (tree.staticImport) |
|
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31299
diff
changeset
|
415 |
importStaticAll(tree, p, env); |
27857 | 416 |
else |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31299
diff
changeset
|
417 |
importAll(tree, p, env); |
27857 | 418 |
} else { |
419 |
// Named type import. |
|
420 |
if (tree.staticImport) { |
|
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31299
diff
changeset
|
421 |
importNamedStatic(tree, p, name, localEnv); |
27857 | 422 |
chk.checkCanonical(imp.selected); |
423 |
} else { |
|
43141
7ea6578a9110
8172668: NPE in jdk.compiler/com.sun.tools.javac.comp.TypeEnter$ImportsPhase.importNamed(
jlahoda
parents:
43138
diff
changeset
|
424 |
Type importedType = attribImportType(imp, localEnv); |
7ea6578a9110
8172668: NPE in jdk.compiler/com.sun.tools.javac.comp.TypeEnter$ImportsPhase.importNamed(
jlahoda
parents:
43138
diff
changeset
|
425 |
Type originalType = importedType.getOriginalType(); |
7ea6578a9110
8172668: NPE in jdk.compiler/com.sun.tools.javac.comp.TypeEnter$ImportsPhase.importNamed(
jlahoda
parents:
43138
diff
changeset
|
426 |
TypeSymbol c = originalType.hasTag(CLASS) ? originalType.tsym : importedType.tsym; |
27857 | 427 |
chk.checkCanonical(imp); |
428 |
importNamed(tree.pos(), c, env, tree); |
|
429 |
} |
|
430 |
} |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
431 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
432 |
|
27857 | 433 |
Type attribImportType(JCTree tree, Env<AttrContext> env) { |
434 |
Assert.check(completionEnabled); |
|
435 |
Lint prevLint = chk.setLint(allowDeprecationOnImport ? |
|
41637 | 436 |
lint : lint.suppress(LintCategory.DEPRECATION, LintCategory.REMOVAL)); |
27857 | 437 |
try { |
438 |
// To prevent deep recursion, suppress completion of some |
|
439 |
// types. |
|
440 |
completionEnabled = false; |
|
441 |
return attr.attribType(tree, env); |
|
442 |
} finally { |
|
443 |
completionEnabled = true; |
|
444 |
chk.setLint(prevLint); |
|
445 |
} |
|
446 |
} |
|
447 |
||
448 |
/** Import all classes of a class or package on demand. |
|
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31299
diff
changeset
|
449 |
* @param imp The import that is being handled. |
27857 | 450 |
* @param tsym The class or package the members of which are imported. |
451 |
* @param env The env in which the imported classes will be entered. |
|
452 |
*/ |
|
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31299
diff
changeset
|
453 |
private void importAll(JCImport imp, |
27857 | 454 |
final TypeSymbol tsym, |
455 |
Env<AttrContext> env) { |
|
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31299
diff
changeset
|
456 |
env.toplevel.starImportScope.importAll(types, tsym.members(), typeImportFilter, imp, cfHandler); |
27857 | 457 |
} |
458 |
||
459 |
/** Import all static members of a class or package on demand. |
|
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31299
diff
changeset
|
460 |
* @param imp The import that is being handled. |
27857 | 461 |
* @param tsym The class or package the members of which are imported. |
462 |
* @param env The env in which the imported classes will be entered. |
|
463 |
*/ |
|
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31299
diff
changeset
|
464 |
private void importStaticAll(JCImport imp, |
27857 | 465 |
final TypeSymbol tsym, |
466 |
Env<AttrContext> env) { |
|
467 |
final StarImportScope toScope = env.toplevel.starImportScope; |
|
468 |
final TypeSymbol origin = tsym; |
|
469 |
||
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31299
diff
changeset
|
470 |
toScope.importAll(types, origin.members(), staticImportFilter, imp, cfHandler); |
27857 | 471 |
} |
472 |
||
473 |
/** Import statics types of a given name. Non-types are handled in Attr. |
|
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31299
diff
changeset
|
474 |
* @param imp The import that is being handled. |
27857 | 475 |
* @param tsym The class from which the name is imported. |
476 |
* @param name The (simple) name being imported. |
|
477 |
* @param env The environment containing the named import |
|
478 |
* scope to add to. |
|
479 |
*/ |
|
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31299
diff
changeset
|
480 |
private void importNamedStatic(final JCImport imp, |
27857 | 481 |
final TypeSymbol tsym, |
482 |
final Name name, |
|
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31299
diff
changeset
|
483 |
final Env<AttrContext> env) { |
27857 | 484 |
if (tsym.kind != TYP) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
43141
diff
changeset
|
485 |
log.error(DiagnosticFlag.RECOVERABLE, imp.pos(), Errors.StaticImpOnlyClassesAndInterfaces); |
27857 | 486 |
return; |
487 |
} |
|
488 |
||
489 |
final NamedImportScope toScope = env.toplevel.namedImportScope; |
|
490 |
final Scope originMembers = tsym.members(); |
|
491 |
||
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
31299
diff
changeset
|
492 |
imp.importScope = toScope.importByName(types, originMembers, name, staticImportFilter, imp, cfHandler); |
27857 | 493 |
} |
494 |
||
495 |
/** Import given class. |
|
496 |
* @param pos Position to be used for error reporting. |
|
497 |
* @param tsym The class to be imported. |
|
498 |
* @param env The environment containing the named import |
|
499 |
* scope to add to. |
|
500 |
*/ |
|
501 |
private void importNamed(DiagnosticPosition pos, final Symbol tsym, Env<AttrContext> env, JCImport imp) { |
|
502 |
if (tsym.kind == TYP) |
|
503 |
imp.importScope = env.toplevel.namedImportScope.importType(tsym.owner.members(), tsym.owner.members(), tsym); |
|
504 |
} |
|
505 |
||
506 |
} |
|
507 |
||
508 |
/**Defines common utility methods used by the HierarchyPhase and HeaderPhase. |
|
509 |
*/ |
|
510 |
private abstract class AbstractHeaderPhase extends Phase { |
|
511 |
||
512 |
public AbstractHeaderPhase(CompletionCause phaseName, Phase next) { |
|
513 |
super(phaseName, next); |
|
514 |
} |
|
515 |
||
516 |
protected Env<AttrContext> baseEnv(JCClassDecl tree, Env<AttrContext> env) { |
|
517 |
WriteableScope baseScope = WriteableScope.create(tree.sym); |
|
518 |
//import already entered local classes into base scope |
|
519 |
for (Symbol sym : env.outer.info.scope.getSymbols(NON_RECURSIVE)) { |
|
520 |
if (sym.isLocal()) { |
|
521 |
baseScope.enter(sym); |
|
522 |
} |
|
523 |
} |
|
524 |
//import current type-parameters into base scope |
|
525 |
if (tree.typarams != null) |
|
526 |
for (List<JCTypeParameter> typarams = tree.typarams; |
|
527 |
typarams.nonEmpty(); |
|
528 |
typarams = typarams.tail) |
|
529 |
baseScope.enter(typarams.head.type.tsym); |
|
530 |
Env<AttrContext> outer = env.outer; // the base clause can't see members of this class |
|
531 |
Env<AttrContext> localEnv = outer.dup(tree, outer.info.dup(baseScope)); |
|
532 |
localEnv.baseClause = true; |
|
533 |
localEnv.outer = outer; |
|
534 |
localEnv.info.isSelfCall = false; |
|
535 |
return localEnv; |
|
536 |
} |
|
537 |
||
538 |
/** Generate a base clause for an enum type. |
|
539 |
* @param pos The position for trees and diagnostics, if any |
|
540 |
* @param c The class symbol of the enum |
|
541 |
*/ |
|
542 |
protected JCExpression enumBase(int pos, ClassSymbol c) { |
|
543 |
JCExpression result = make.at(pos). |
|
544 |
TypeApply(make.QualIdent(syms.enumSym), |
|
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42407
diff
changeset
|
545 |
List.of(make.Type(c.type))); |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
546 |
return result; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
547 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
548 |
|
36526 | 549 |
protected Type modelMissingTypes(Env<AttrContext> env, Type t, final JCExpression tree, final boolean interfaceExpected) { |
27857 | 550 |
if (!t.hasTag(ERROR)) |
551 |
return t; |
|
552 |
||
553 |
return new ErrorType(t.getOriginalType(), t.tsym) { |
|
554 |
private Type modelType; |
|
555 |
||
556 |
@Override |
|
557 |
public Type getModelType() { |
|
558 |
if (modelType == null) |
|
36526 | 559 |
modelType = new Synthesizer(env.toplevel.modle, getOriginalType(), interfaceExpected).visit(tree); |
27857 | 560 |
return modelType; |
561 |
} |
|
562 |
}; |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
563 |
} |
27857 | 564 |
// where: |
565 |
private class Synthesizer extends JCTree.Visitor { |
|
36526 | 566 |
ModuleSymbol msym; |
27857 | 567 |
Type originalType; |
568 |
boolean interfaceExpected; |
|
569 |
List<ClassSymbol> synthesizedSymbols = List.nil(); |
|
570 |
Type result; |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
571 |
|
36526 | 572 |
Synthesizer(ModuleSymbol msym, Type originalType, boolean interfaceExpected) { |
573 |
this.msym = msym; |
|
27857 | 574 |
this.originalType = originalType; |
575 |
this.interfaceExpected = interfaceExpected; |
|
576 |
} |
|
577 |
||
578 |
Type visit(JCTree tree) { |
|
579 |
tree.accept(this); |
|
580 |
return result; |
|
581 |
} |
|
582 |
||
583 |
List<Type> visit(List<? extends JCTree> trees) { |
|
584 |
ListBuffer<Type> lb = new ListBuffer<>(); |
|
585 |
for (JCTree t: trees) |
|
586 |
lb.append(visit(t)); |
|
587 |
return lb.toList(); |
|
588 |
} |
|
589 |
||
590 |
@Override |
|
591 |
public void visitTree(JCTree tree) { |
|
592 |
result = syms.errType; |
|
593 |
} |
|
594 |
||
595 |
@Override |
|
596 |
public void visitIdent(JCIdent tree) { |
|
597 |
if (!tree.type.hasTag(ERROR)) { |
|
598 |
result = tree.type; |
|
599 |
} else { |
|
36526 | 600 |
result = synthesizeClass(tree.name, msym.unnamedPackage).type; |
27857 | 601 |
} |
602 |
} |
|
603 |
||
604 |
@Override |
|
605 |
public void visitSelect(JCFieldAccess tree) { |
|
606 |
if (!tree.type.hasTag(ERROR)) { |
|
607 |
result = tree.type; |
|
608 |
} else { |
|
609 |
Type selectedType; |
|
610 |
boolean prev = interfaceExpected; |
|
611 |
try { |
|
612 |
interfaceExpected = false; |
|
613 |
selectedType = visit(tree.selected); |
|
614 |
} finally { |
|
615 |
interfaceExpected = prev; |
|
616 |
} |
|
617 |
ClassSymbol c = synthesizeClass(tree.name, selectedType.tsym); |
|
618 |
result = c.type; |
|
619 |
} |
|
620 |
} |
|
621 |
||
622 |
@Override |
|
623 |
public void visitTypeApply(JCTypeApply tree) { |
|
624 |
if (!tree.type.hasTag(ERROR)) { |
|
625 |
result = tree.type; |
|
626 |
} else { |
|
627 |
ClassType clazzType = (ClassType) visit(tree.clazz); |
|
628 |
if (synthesizedSymbols.contains(clazzType.tsym)) |
|
629 |
synthesizeTyparams((ClassSymbol) clazzType.tsym, tree.arguments.size()); |
|
630 |
final List<Type> actuals = visit(tree.arguments); |
|
631 |
result = new ErrorType(tree.type, clazzType.tsym) { |
|
632 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
633 |
public List<Type> getTypeArguments() { |
|
634 |
return actuals; |
|
635 |
} |
|
636 |
}; |
|
637 |
} |
|
638 |
} |
|
639 |
||
640 |
ClassSymbol synthesizeClass(Name name, Symbol owner) { |
|
641 |
int flags = interfaceExpected ? INTERFACE : 0; |
|
642 |
ClassSymbol c = new ClassSymbol(flags, name, owner); |
|
643 |
c.members_field = new Scope.ErrorScope(c); |
|
644 |
c.type = new ErrorType(originalType, c) { |
|
645 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
646 |
public List<Type> getTypeArguments() { |
|
647 |
return typarams_field; |
|
648 |
} |
|
649 |
}; |
|
650 |
synthesizedSymbols = synthesizedSymbols.prepend(c); |
|
651 |
return c; |
|
652 |
} |
|
653 |
||
654 |
void synthesizeTyparams(ClassSymbol sym, int n) { |
|
655 |
ClassType ct = (ClassType) sym.type; |
|
656 |
Assert.check(ct.typarams_field.isEmpty()); |
|
657 |
if (n == 1) { |
|
658 |
TypeVar v = new TypeVar(names.fromString("T"), sym, syms.botType); |
|
659 |
ct.typarams_field = ct.typarams_field.prepend(v); |
|
660 |
} else { |
|
661 |
for (int i = n; i > 0; i--) { |
|
662 |
TypeVar v = new TypeVar(names.fromString("T" + i), sym, |
|
663 |
syms.botType); |
|
664 |
ct.typarams_field = ct.typarams_field.prepend(v); |
|
665 |
} |
|
666 |
} |
|
667 |
} |
|
668 |
} |
|
669 |
||
670 |
protected void attribSuperTypes(Env<AttrContext> env, Env<AttrContext> baseEnv) { |
|
671 |
JCClassDecl tree = env.enclClass; |
|
672 |
ClassSymbol sym = tree.sym; |
|
673 |
ClassType ct = (ClassType)sym.type; |
|
674 |
// Determine supertype. |
|
675 |
Type supertype; |
|
676 |
JCExpression extending; |
|
677 |
||
678 |
if (tree.extending != null) { |
|
679 |
extending = clearTypeParams(tree.extending); |
|
33366
a113e08cc061
8087349: Test tools/sjavac/IncCompInheritance.java is failing
alundblad
parents:
32913
diff
changeset
|
680 |
supertype = attr.attribBase(extending, baseEnv, true, false, true); |
27857 | 681 |
} else { |
682 |
extending = null; |
|
683 |
supertype = ((tree.mods.flags & Flags.ENUM) != 0) |
|
684 |
? attr.attribBase(enumBase(tree.pos, sym), baseEnv, |
|
685 |
true, false, false) |
|
686 |
: (sym.fullname == names.java_lang_Object) |
|
687 |
? Type.noType |
|
688 |
: syms.objectType; |
|
689 |
} |
|
36526 | 690 |
ct.supertype_field = modelMissingTypes(baseEnv, supertype, extending, false); |
27857 | 691 |
|
692 |
// Determine interfaces. |
|
693 |
ListBuffer<Type> interfaces = new ListBuffer<>(); |
|
694 |
ListBuffer<Type> all_interfaces = null; // lazy init |
|
695 |
List<JCExpression> interfaceTrees = tree.implementing; |
|
696 |
for (JCExpression iface : interfaceTrees) { |
|
697 |
iface = clearTypeParams(iface); |
|
33366
a113e08cc061
8087349: Test tools/sjavac/IncCompInheritance.java is failing
alundblad
parents:
32913
diff
changeset
|
698 |
Type it = attr.attribBase(iface, baseEnv, false, true, true); |
a113e08cc061
8087349: Test tools/sjavac/IncCompInheritance.java is failing
alundblad
parents:
32913
diff
changeset
|
699 |
if (it.hasTag(CLASS)) { |
a113e08cc061
8087349: Test tools/sjavac/IncCompInheritance.java is failing
alundblad
parents:
32913
diff
changeset
|
700 |
interfaces.append(it); |
a113e08cc061
8087349: Test tools/sjavac/IncCompInheritance.java is failing
alundblad
parents:
32913
diff
changeset
|
701 |
if (all_interfaces != null) all_interfaces.append(it); |
a113e08cc061
8087349: Test tools/sjavac/IncCompInheritance.java is failing
alundblad
parents:
32913
diff
changeset
|
702 |
} else { |
a113e08cc061
8087349: Test tools/sjavac/IncCompInheritance.java is failing
alundblad
parents:
32913
diff
changeset
|
703 |
if (all_interfaces == null) |
a113e08cc061
8087349: Test tools/sjavac/IncCompInheritance.java is failing
alundblad
parents:
32913
diff
changeset
|
704 |
all_interfaces = new ListBuffer<Type>().appendList(interfaces); |
36526 | 705 |
all_interfaces.append(modelMissingTypes(baseEnv, it, iface, true)); |
27857 | 706 |
} |
707 |
} |
|
708 |
||
709 |
if ((sym.flags_field & ANNOTATION) != 0) { |
|
710 |
ct.interfaces_field = List.of(syms.annotationType); |
|
711 |
ct.all_interfaces_field = ct.interfaces_field; |
|
712 |
} else { |
|
713 |
ct.interfaces_field = interfaces.toList(); |
|
714 |
ct.all_interfaces_field = (all_interfaces == null) |
|
715 |
? ct.interfaces_field : all_interfaces.toList(); |
|
716 |
} |
|
717 |
} |
|
718 |
//where: |
|
719 |
protected JCExpression clearTypeParams(JCExpression superType) { |
|
720 |
return superType; |
|
721 |
} |
|
722 |
} |
|
723 |
||
32913
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
724 |
private final class HierarchyPhase extends AbstractHeaderPhase implements Completer { |
27857 | 725 |
|
726 |
public HierarchyPhase() { |
|
727 |
super(CompletionCause.HIERARCHY_PHASE, new HeaderPhase()); |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
728 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
729 |
|
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
730 |
@Override |
32913
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
731 |
protected void doCompleteEnvs(List<Env<AttrContext>> envs) { |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
732 |
//The ClassSymbols in the envs list may not be in the dependency order. |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
733 |
//To get proper results, for every class or interface C, the supertypes of |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
734 |
//C must be processed by the HierarchyPhase phase before C. |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
735 |
//To achieve that, the HierarchyPhase is registered as the Completer for |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
736 |
//all the classes first, and then all the classes are completed. |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
737 |
for (Env<AttrContext> env : envs) { |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
738 |
env.enclClass.sym.completer = this; |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
739 |
} |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
740 |
for (Env<AttrContext> env : envs) { |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
741 |
env.enclClass.sym.complete(); |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
742 |
} |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
743 |
} |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
744 |
|
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
745 |
@Override |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
746 |
protected void runPhase(Env<AttrContext> env) { |
27857 | 747 |
JCClassDecl tree = env.enclClass; |
748 |
ClassSymbol sym = tree.sym; |
|
749 |
ClassType ct = (ClassType)sym.type; |
|
750 |
||
751 |
Env<AttrContext> baseEnv = baseEnv(tree, env); |
|
752 |
||
753 |
attribSuperTypes(env, baseEnv); |
|
754 |
||
755 |
if (sym.fullname == names.java_lang_Object) { |
|
756 |
if (tree.extending != null) { |
|
757 |
chk.checkNonCyclic(tree.extending.pos(), |
|
758 |
ct.supertype_field); |
|
759 |
ct.supertype_field = Type.noType; |
|
760 |
} |
|
761 |
else if (tree.implementing.nonEmpty()) { |
|
762 |
chk.checkNonCyclic(tree.implementing.head.pos(), |
|
763 |
ct.interfaces_field.head); |
|
764 |
ct.interfaces_field = List.nil(); |
|
765 |
} |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
766 |
} |
27857 | 767 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
768 |
markDeprecated(sym, tree.mods.annotations, baseEnv); |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
769 |
|
27857 | 770 |
chk.checkNonCyclicDecl(tree); |
771 |
} |
|
772 |
//where: |
|
41637 | 773 |
@Override |
27857 | 774 |
protected JCExpression clearTypeParams(JCExpression superType) { |
775 |
switch (superType.getTag()) { |
|
776 |
case TYPEAPPLY: |
|
777 |
return ((JCTypeApply) superType).clazz; |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
778 |
} |
27857 | 779 |
|
780 |
return superType; |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
781 |
} |
27857 | 782 |
|
32913
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
783 |
@Override |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
784 |
public void complete(Symbol sym) throws CompletionFailure { |
39371
ac04aefa4ba6
8148131: compilation result depends on order of sources
jlahoda
parents:
37942
diff
changeset
|
785 |
Assert.check((topLevelPhase instanceof ImportsPhase) || |
ac04aefa4ba6
8148131: compilation result depends on order of sources
jlahoda
parents:
37942
diff
changeset
|
786 |
(topLevelPhase == this)); |
ac04aefa4ba6
8148131: compilation result depends on order of sources
jlahoda
parents:
37942
diff
changeset
|
787 |
|
ac04aefa4ba6
8148131: compilation result depends on order of sources
jlahoda
parents:
37942
diff
changeset
|
788 |
if (topLevelPhase != this) { |
ac04aefa4ba6
8148131: compilation result depends on order of sources
jlahoda
parents:
37942
diff
changeset
|
789 |
//only do the processing based on dependencies in the HierarchyPhase: |
ac04aefa4ba6
8148131: compilation result depends on order of sources
jlahoda
parents:
37942
diff
changeset
|
790 |
sym.completer = this; |
ac04aefa4ba6
8148131: compilation result depends on order of sources
jlahoda
parents:
37942
diff
changeset
|
791 |
return ; |
ac04aefa4ba6
8148131: compilation result depends on order of sources
jlahoda
parents:
37942
diff
changeset
|
792 |
} |
ac04aefa4ba6
8148131: compilation result depends on order of sources
jlahoda
parents:
37942
diff
changeset
|
793 |
|
32913
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
794 |
Env<AttrContext> env = typeEnvs.get((ClassSymbol) sym); |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
795 |
|
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
796 |
super.doCompleteEnvs(List.of(env)); |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
797 |
} |
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
798 |
|
27857 | 799 |
} |
800 |
||
801 |
private final class HeaderPhase extends AbstractHeaderPhase { |
|
802 |
||
803 |
public HeaderPhase() { |
|
804 |
super(CompletionCause.HEADER_PHASE, new MembersPhase()); |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
805 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
806 |
|
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
807 |
@Override |
32913
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
808 |
protected void runPhase(Env<AttrContext> env) { |
27857 | 809 |
JCClassDecl tree = env.enclClass; |
810 |
ClassSymbol sym = tree.sym; |
|
811 |
ClassType ct = (ClassType)sym.type; |
|
812 |
||
813 |
// create an environment for evaluating the base clauses |
|
814 |
Env<AttrContext> baseEnv = baseEnv(tree, env); |
|
815 |
||
816 |
if (tree.extending != null) |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29149
diff
changeset
|
817 |
annotate.queueScanTreeAndTypeAnnotate(tree.extending, baseEnv, sym, tree.pos()); |
27857 | 818 |
for (JCExpression impl : tree.implementing) |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29149
diff
changeset
|
819 |
annotate.queueScanTreeAndTypeAnnotate(impl, baseEnv, sym, tree.pos()); |
27857 | 820 |
annotate.flush(); |
821 |
||
822 |
attribSuperTypes(env, baseEnv); |
|
823 |
||
824 |
Set<Type> interfaceSet = new HashSet<>(); |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
825 |
|
27857 | 826 |
for (JCExpression iface : tree.implementing) { |
827 |
Type it = iface.type; |
|
828 |
if (it.hasTag(CLASS)) |
|
829 |
chk.checkNotRepeated(iface.pos(), types.erasure(it), interfaceSet); |
|
830 |
} |
|
831 |
||
832 |
annotate.annotateLater(tree.mods.annotations, baseEnv, |
|
833 |
sym, tree.pos()); |
|
53275
f5e601ad26a8
8215482: check for cycles in type variables can provoke NPE
vromero
parents:
50374
diff
changeset
|
834 |
attr.attribTypeVariables(tree.typarams, baseEnv, false); |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
835 |
|
27857 | 836 |
for (JCTypeParameter tp : tree.typarams) |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29149
diff
changeset
|
837 |
annotate.queueScanTreeAndTypeAnnotate(tp, baseEnv, sym, tree.pos()); |
27857 | 838 |
|
839 |
// check that no package exists with same fully qualified name, |
|
840 |
// but admit classes in the unnamed package which have the same |
|
841 |
// name as a top-level package. |
|
842 |
if (checkClash && |
|
36526 | 843 |
sym.owner.kind == PCK && sym.owner != env.toplevel.modle.unnamedPackage && |
844 |
syms.packageExists(env.toplevel.modle, sym.fullname)) { |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
43141
diff
changeset
|
845 |
log.error(tree.pos, Errors.ClashWithPkgOfSameName(Kinds.kindName(sym),sym)); |
27857 | 846 |
} |
847 |
if (sym.owner.kind == PCK && (sym.flags_field & PUBLIC) == 0 && |
|
848 |
!env.toplevel.sourcefile.isNameCompatible(sym.name.toString(),JavaFileObject.Kind.SOURCE)) { |
|
849 |
sym.flags_field |= AUXILIARY; |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
850 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
851 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
852 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
853 |
|
27857 | 854 |
/** Enter member fields and methods of a class |
855 |
*/ |
|
856 |
private final class MembersPhase extends Phase { |
|
857 |
||
858 |
public MembersPhase() { |
|
859 |
super(CompletionCause.MEMBERS_PHASE, null); |
|
860 |
} |
|
861 |
||
37942
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
862 |
private boolean completing; |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
863 |
private List<Env<AttrContext>> todo = List.nil(); |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
864 |
|
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
865 |
@Override |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
866 |
protected void doCompleteEnvs(List<Env<AttrContext>> envs) { |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
867 |
todo = todo.prependList(envs); |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
868 |
if (completing) { |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
869 |
return ; //the top-level invocation will handle all envs |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
870 |
} |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
871 |
boolean prevCompleting = completing; |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
872 |
completing = true; |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
873 |
try { |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
874 |
while (todo.nonEmpty()) { |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
875 |
Env<AttrContext> head = todo.head; |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
876 |
todo = todo.tail; |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
877 |
super.doCompleteEnvs(List.of(head)); |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
878 |
} |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
879 |
} finally { |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
880 |
completing = prevCompleting; |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
881 |
} |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
882 |
} |
b0e834553947
8156097: docs build fails with StackOverflowError on Solaris
jlahoda
parents:
36526
diff
changeset
|
883 |
|
27857 | 884 |
@Override |
32913
586e23a1b116
8075274: Compilation still depends on the order of imports
jlahoda
parents:
32059
diff
changeset
|
885 |
protected void runPhase(Env<AttrContext> env) { |
27857 | 886 |
JCClassDecl tree = env.enclClass; |
887 |
ClassSymbol sym = tree.sym; |
|
888 |
ClassType ct = (ClassType)sym.type; |
|
889 |
||
890 |
// Add default constructor if needed. |
|
891 |
if ((sym.flags() & INTERFACE) == 0 && |
|
892 |
!TreeInfo.hasConstructors(tree.defs)) { |
|
893 |
List<Type> argtypes = List.nil(); |
|
894 |
List<Type> typarams = List.nil(); |
|
895 |
List<Type> thrown = List.nil(); |
|
896 |
long ctorFlags = 0; |
|
897 |
boolean based = false; |
|
898 |
boolean addConstructor = true; |
|
899 |
JCNewClass nc = null; |
|
900 |
if (sym.name.isEmpty()) { |
|
901 |
nc = (JCNewClass)env.next.tree; |
|
902 |
if (nc.constructor != null) { |
|
903 |
addConstructor = nc.constructor.kind != ERR; |
|
904 |
Type superConstrType = types.memberType(sym.type, |
|
905 |
nc.constructor); |
|
906 |
argtypes = superConstrType.getParameterTypes(); |
|
907 |
typarams = superConstrType.getTypeArguments(); |
|
908 |
ctorFlags = nc.constructor.flags() & VARARGS; |
|
909 |
if (nc.encl != null) { |
|
910 |
argtypes = argtypes.prepend(nc.encl.type); |
|
911 |
based = true; |
|
912 |
} |
|
913 |
thrown = superConstrType.getThrownTypes(); |
|
914 |
} |
|
915 |
} |
|
916 |
if (addConstructor) { |
|
917 |
MethodSymbol basedConstructor = nc != null ? |
|
918 |
(MethodSymbol)nc.constructor : null; |
|
919 |
JCTree constrDef = DefaultConstructor(make.at(tree.pos), sym, |
|
920 |
basedConstructor, |
|
921 |
typarams, argtypes, thrown, |
|
922 |
ctorFlags, based); |
|
923 |
tree.defs = tree.defs.prepend(constrDef); |
|
924 |
} |
|
925 |
} |
|
926 |
||
927 |
// enter symbols for 'this' into current scope. |
|
928 |
VarSymbol thisSym = |
|
929 |
new VarSymbol(FINAL | HASINIT, names._this, sym.type, sym); |
|
930 |
thisSym.pos = Position.FIRSTPOS; |
|
931 |
env.info.scope.enter(thisSym); |
|
932 |
// if this is a class, enter symbol for 'super' into current scope. |
|
933 |
if ((sym.flags_field & INTERFACE) == 0 && |
|
934 |
ct.supertype_field.hasTag(CLASS)) { |
|
935 |
VarSymbol superSym = |
|
936 |
new VarSymbol(FINAL | HASINIT, names._super, |
|
937 |
ct.supertype_field, sym); |
|
938 |
superSym.pos = Position.FIRSTPOS; |
|
939 |
env.info.scope.enter(superSym); |
|
940 |
} |
|
941 |
||
53275
f5e601ad26a8
8215482: check for cycles in type variables can provoke NPE
vromero
parents:
50374
diff
changeset
|
942 |
if (!tree.typarams.isEmpty()) { |
f5e601ad26a8
8215482: check for cycles in type variables can provoke NPE
vromero
parents:
50374
diff
changeset
|
943 |
for (JCTypeParameter tvar : tree.typarams) { |
f5e601ad26a8
8215482: check for cycles in type variables can provoke NPE
vromero
parents:
50374
diff
changeset
|
944 |
chk.checkNonCyclic(tvar, (TypeVar)tvar.type); |
f5e601ad26a8
8215482: check for cycles in type variables can provoke NPE
vromero
parents:
50374
diff
changeset
|
945 |
} |
f5e601ad26a8
8215482: check for cycles in type variables can provoke NPE
vromero
parents:
50374
diff
changeset
|
946 |
} |
f5e601ad26a8
8215482: check for cycles in type variables can provoke NPE
vromero
parents:
50374
diff
changeset
|
947 |
|
27857 | 948 |
finishClass(tree, env); |
949 |
||
950 |
if (allowTypeAnnos) { |
|
951 |
typeAnnotations.organizeTypeAnnotationsSignatures(env, (JCClassDecl)env.tree); |
|
952 |
typeAnnotations.validateTypeAnnotationsSignatures(env, (JCClassDecl)env.tree); |
|
953 |
} |
|
954 |
} |
|
955 |
||
956 |
/** Enter members for a class. |
|
957 |
*/ |
|
958 |
void finishClass(JCClassDecl tree, Env<AttrContext> env) { |
|
959 |
if ((tree.mods.flags & Flags.ENUM) != 0 && |
|
43137 | 960 |
!tree.sym.type.hasTag(ERROR) && |
27857 | 961 |
(types.supertype(tree.sym.type).tsym.flags() & Flags.ENUM) == 0) { |
962 |
addEnumMembers(tree, env); |
|
963 |
} |
|
964 |
memberEnter.memberEnter(tree.defs, env); |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29149
diff
changeset
|
965 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29149
diff
changeset
|
966 |
if (tree.sym.isAnnotationType()) { |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
967 |
Assert.check(tree.sym.isCompleted()); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29149
diff
changeset
|
968 |
tree.sym.setAnnotationTypeMetadata(new AnnotationTypeMetadata(tree.sym, annotate.annotationTypeSourceCompleter())); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29149
diff
changeset
|
969 |
} |
27857 | 970 |
} |
971 |
||
972 |
/** Add the implicit members for an enum type |
|
973 |
* to the symbol table. |
|
974 |
*/ |
|
975 |
private void addEnumMembers(JCClassDecl tree, Env<AttrContext> env) { |
|
976 |
JCExpression valuesType = make.Type(new ArrayType(tree.sym.type, syms.arrayClass)); |
|
977 |
||
978 |
// public static T[] values() { return ???; } |
|
979 |
JCMethodDecl values = make. |
|
980 |
MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC), |
|
981 |
names.values, |
|
982 |
valuesType, |
|
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42407
diff
changeset
|
983 |
List.nil(), |
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42407
diff
changeset
|
984 |
List.nil(), |
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42407
diff
changeset
|
985 |
List.nil(), // thrown |
27857 | 986 |
null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))), |
987 |
null); |
|
988 |
memberEnter.memberEnter(values, env); |
|
989 |
||
990 |
// public static T valueOf(String name) { return ???; } |
|
991 |
JCMethodDecl valueOf = make. |
|
992 |
MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC), |
|
993 |
names.valueOf, |
|
994 |
make.Type(tree.sym.type), |
|
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42407
diff
changeset
|
995 |
List.nil(), |
27857 | 996 |
List.of(make.VarDef(make.Modifiers(Flags.PARAMETER | |
997 |
Flags.MANDATED), |
|
998 |
names.fromString("name"), |
|
999 |
make.Type(syms.stringType), null)), |
|
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42407
diff
changeset
|
1000 |
List.nil(), // thrown |
27857 | 1001 |
null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))), |
1002 |
null); |
|
1003 |
memberEnter.memberEnter(valueOf, env); |
|
1004 |
} |
|
1005 |
||
1006 |
} |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1007 |
|
10 | 1008 |
/* *************************************************************************** |
1009 |
* tree building |
|
1010 |
****************************************************************************/ |
|
1011 |
||
1012 |
/** Generate default constructor for given class. For classes different |
|
1013 |
* from java.lang.Object, this is: |
|
1014 |
* |
|
1015 |
* c(argtype_0 x_0, ..., argtype_n x_n) throws thrown { |
|
1016 |
* super(x_0, ..., x_n) |
|
1017 |
* } |
|
1018 |
* |
|
1019 |
* or, if based == true: |
|
1020 |
* |
|
1021 |
* c(argtype_0 x_0, ..., argtype_n x_n) throws thrown { |
|
1022 |
* x_0.super(x_1, ..., x_n) |
|
1023 |
* } |
|
1024 |
* |
|
1025 |
* @param make The tree factory. |
|
1026 |
* @param c The class owning the default constructor. |
|
1027 |
* @param argtypes The parameter types of the constructor. |
|
1028 |
* @param thrown The thrown exceptions of the constructor. |
|
1029 |
* @param based Is first parameter a this$n? |
|
1030 |
*/ |
|
1031 |
JCTree DefaultConstructor(TreeMaker make, |
|
1032 |
ClassSymbol c, |
|
17999
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1033 |
MethodSymbol baseInit, |
10 | 1034 |
List<Type> typarams, |
1035 |
List<Type> argtypes, |
|
1036 |
List<Type> thrown, |
|
1037 |
long flags, |
|
1038 |
boolean based) { |
|
17999
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1039 |
JCTree result; |
10 | 1040 |
if ((c.flags() & ENUM) != 0 && |
16558
07c08ad4a700
8010179: Remove transitional target values from javac
darcy
parents:
15720
diff
changeset
|
1041 |
(types.supertype(c.type).tsym == syms.enumSym)) { |
10 | 1042 |
// constructors of true enums are private |
1043 |
flags = (flags & ~AccessFlags) | PRIVATE | GENERATEDCONSTR; |
|
1044 |
} else |
|
1045 |
flags |= (c.flags() & AccessFlags) | GENERATEDCONSTR; |
|
17999
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1046 |
if (c.name.isEmpty()) { |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1047 |
flags |= ANONCONSTR; |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1048 |
} |
47248 | 1049 |
if (based) { |
1050 |
flags |= ANONCONSTR_BASED; |
|
1051 |
} |
|
17999
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1052 |
Type mType = new MethodType(argtypes, null, thrown, c); |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1053 |
Type initType = typarams.nonEmpty() ? |
24396 | 1054 |
new ForAll(typarams, mType) : |
1055 |
mType; |
|
17999
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1056 |
MethodSymbol init = new MethodSymbol(flags, names.init, |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1057 |
initType, c); |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1058 |
init.params = createDefaultConstructorParams(make, baseInit, init, |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1059 |
argtypes, based); |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1060 |
List<JCVariableDecl> params = make.Params(argtypes, init); |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1061 |
List<JCStatement> stats = List.nil(); |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1062 |
if (c.type != syms.objectType) { |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1063 |
stats = stats.prepend(SuperCall(make, typarams, params, based)); |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1064 |
} |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1065 |
result = make.MethodDef(init, make.Block(0, stats)); |
10 | 1066 |
return result; |
1067 |
} |
|
1068 |
||
17999
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1069 |
private List<VarSymbol> createDefaultConstructorParams( |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1070 |
TreeMaker make, |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1071 |
MethodSymbol baseInit, |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1072 |
MethodSymbol init, |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1073 |
List<Type> argtypes, |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1074 |
boolean based) { |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1075 |
List<VarSymbol> initParams = null; |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1076 |
List<Type> argTypesList = argtypes; |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1077 |
if (based) { |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1078 |
/* In this case argtypes will have an extra type, compared to baseInit, |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1079 |
* corresponding to the type of the enclosing instance i.e.: |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1080 |
* |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1081 |
* Inner i = outer.new Inner(1){} |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1082 |
* |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1083 |
* in the above example argtypes will be (Outer, int) and baseInit |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1084 |
* will have parameter's types (int). So in this case we have to add |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1085 |
* first the extra type in argtypes and then get the names of the |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1086 |
* parameters from baseInit. |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1087 |
*/ |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1088 |
initParams = List.nil(); |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19656
diff
changeset
|
1089 |
VarSymbol param = new VarSymbol(PARAMETER, make.paramName(0), argtypes.head, init); |
17999
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1090 |
initParams = initParams.append(param); |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1091 |
argTypesList = argTypesList.tail; |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1092 |
} |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1093 |
if (baseInit != null && baseInit.params != null && |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1094 |
baseInit.params.nonEmpty() && argTypesList.nonEmpty()) { |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42407
diff
changeset
|
1095 |
initParams = (initParams == null) ? List.nil() : initParams; |
17999
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1096 |
List<VarSymbol> baseInitParams = baseInit.params; |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1097 |
while (baseInitParams.nonEmpty() && argTypesList.nonEmpty()) { |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19656
diff
changeset
|
1098 |
VarSymbol param = new VarSymbol(baseInitParams.head.flags() | PARAMETER, |
17999
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1099 |
baseInitParams.head.name, argTypesList.head, init); |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1100 |
initParams = initParams.append(param); |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1101 |
baseInitParams = baseInitParams.tail; |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1102 |
argTypesList = argTypesList.tail; |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1103 |
} |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1104 |
} |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1105 |
return initParams; |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1106 |
} |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1107 |
|
10 | 1108 |
/** Generate call to superclass constructor. This is: |
1109 |
* |
|
1110 |
* super(id_0, ..., id_n) |
|
1111 |
* |
|
1112 |
* or, if based == true |
|
1113 |
* |
|
1114 |
* id_0.super(id_1,...,id_n) |
|
1115 |
* |
|
1116 |
* where id_0, ..., id_n are the names of the given parameters. |
|
1117 |
* |
|
1118 |
* @param make The tree factory |
|
1119 |
* @param params The parameters that need to be passed to super |
|
1120 |
* @param typarams The type parameters that need to be passed to super |
|
1121 |
* @param based Is first parameter a this$n? |
|
1122 |
*/ |
|
1123 |
JCExpressionStatement SuperCall(TreeMaker make, |
|
1124 |
List<Type> typarams, |
|
1125 |
List<JCVariableDecl> params, |
|
1126 |
boolean based) { |
|
1127 |
JCExpression meth; |
|
1128 |
if (based) { |
|
1129 |
meth = make.Select(make.Ident(params.head), names._super); |
|
1130 |
params = params.tail; |
|
1131 |
} else { |
|
1132 |
meth = make.Ident(names._super); |
|
1133 |
} |
|
1134 |
List<JCExpression> typeargs = typarams.nonEmpty() ? make.Types(typarams) : null; |
|
1135 |
return make.Exec(make.Apply(typeargs, meth, make.Idents(params))); |
|
1136 |
} |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1137 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1138 |
/** |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1139 |
* Mark sym deprecated if annotations contain @Deprecated annotation. |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1140 |
*/ |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1141 |
public void markDeprecated(Symbol sym, List<JCAnnotation> annotations, Env<AttrContext> env) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1142 |
// In general, we cannot fully process annotations yet, but we |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1143 |
// can attribute the annotation types and then check to see if the |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1144 |
// @Deprecated annotation is present. |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1145 |
attr.attribAnnotationTypes(annotations, env); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1146 |
handleDeprecatedAnnotations(annotations, sym); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1147 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1148 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1149 |
/** |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1150 |
* If a list of annotations contains a reference to java.lang.Deprecated, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1151 |
* set the DEPRECATED flag. |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1152 |
* If the annotation is marked forRemoval=true, also set DEPRECATED_REMOVAL. |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1153 |
**/ |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1154 |
private void handleDeprecatedAnnotations(List<JCAnnotation> annotations, Symbol sym) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1155 |
for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1156 |
JCAnnotation a = al.head; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1157 |
if (a.annotationType.type == syms.deprecatedType) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1158 |
sym.flags_field |= (Flags.DEPRECATED | Flags.DEPRECATED_ANNOTATION); |
58713
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
53275
diff
changeset
|
1159 |
setFlagIfAttributeTrue(a, sym, names.forRemoval, DEPRECATED_REMOVAL); |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
53275
diff
changeset
|
1160 |
} else if (a.annotationType.type == syms.previewFeatureType) { |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
53275
diff
changeset
|
1161 |
sym.flags_field |= Flags.PREVIEW_API; |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
53275
diff
changeset
|
1162 |
setFlagIfAttributeTrue(a, sym, names.essentialAPI, PREVIEW_ESSENTIAL_API); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1163 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1164 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
1165 |
} |
58713
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
53275
diff
changeset
|
1166 |
//where: |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
53275
diff
changeset
|
1167 |
private void setFlagIfAttributeTrue(JCAnnotation a, Symbol sym, Name attribute, long flag) { |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
53275
diff
changeset
|
1168 |
a.args.stream() |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
53275
diff
changeset
|
1169 |
.filter(e -> e.hasTag(ASSIGN)) |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
53275
diff
changeset
|
1170 |
.map(e -> (JCAssign) e) |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
53275
diff
changeset
|
1171 |
.filter(assign -> TreeInfo.name(assign.lhs) == attribute) |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
53275
diff
changeset
|
1172 |
.findFirst() |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
53275
diff
changeset
|
1173 |
.ifPresent(assign -> { |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
53275
diff
changeset
|
1174 |
JCExpression rhs = TreeInfo.skipParens(assign.rhs); |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
53275
diff
changeset
|
1175 |
if (rhs.hasTag(LITERAL) |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
53275
diff
changeset
|
1176 |
&& Boolean.TRUE.equals(((JCLiteral) rhs).getValue())) { |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
53275
diff
changeset
|
1177 |
sym.flags_field |= flag; |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
53275
diff
changeset
|
1178 |
} |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
53275
diff
changeset
|
1179 |
}); |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
53275
diff
changeset
|
1180 |
} |
10 | 1181 |
} |