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