author | sadayapalam |
Sun, 28 Jun 2015 12:58:24 +0530 | |
changeset 31299 | 81ce5febcae8 |
parent 30066 | d74c06a92bd8 |
child 32059 | ea04f56aeacd |
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; |
15385 | 30 |
|
10 | 31 |
import javax.tools.JavaFileObject; |
32 |
||
33 |
import com.sun.tools.javac.code.*; |
|
27854
22b4bfc4e22f
8032211: Don't issue deprecation warnings on import statements
jlahoda
parents:
27231
diff
changeset
|
34 |
import com.sun.tools.javac.code.Lint.LintCategory; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25007
diff
changeset
|
35 |
import com.sun.tools.javac.code.Scope.ImportFilter; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25007
diff
changeset
|
36 |
import com.sun.tools.javac.code.Scope.NamedImportScope; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25007
diff
changeset
|
37 |
import com.sun.tools.javac.code.Scope.StarImportScope; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25007
diff
changeset
|
38 |
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
|
39 |
import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata; |
10 | 40 |
import com.sun.tools.javac.tree.*; |
41 |
import com.sun.tools.javac.util.*; |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
42 |
import com.sun.tools.javac.util.DefinedBy.Api; |
10 | 43 |
|
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
44 |
import com.sun.tools.javac.code.Symbol.*; |
10 | 45 |
import com.sun.tools.javac.code.Type.*; |
46 |
import com.sun.tools.javac.tree.JCTree.*; |
|
47 |
||
48 |
import static com.sun.tools.javac.code.Flags.*; |
|
10950 | 49 |
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
import static com.sun.tools.javac.code.TypeTag.ERROR; |
10950 | 54 |
import static com.sun.tools.javac.tree.JCTree.Tag.*; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24396
diff
changeset
|
55 |
|
25844
48eab270456c
8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents:
25443
diff
changeset
|
56 |
import com.sun.tools.javac.util.Dependencies.AttributionKind; |
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 { |
|
196 |
queue = completeClass.runPhase(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 |
||
239 |
public List<Env<AttrContext>> runPhase(List<Env<AttrContext>> envs) { |
|
240 |
boolean firstToComplete = queue.isEmpty(); |
|
241 |
||
242 |
for (Env<AttrContext> env : envs) { |
|
243 |
JCClassDecl tree = (JCClassDecl)env.tree; |
|
244 |
||
245 |
queue.add(env); |
|
246 |
||
247 |
JavaFileObject prev = log.useSource(env.toplevel.sourcefile); |
|
248 |
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); |
|
249 |
try { |
|
250 |
dependencies.push(env.enclClass.sym, phaseName); |
|
251 |
doRunPhase(env); |
|
252 |
} catch (CompletionFailure ex) { |
|
253 |
chk.completionError(tree.pos(), ex); |
|
254 |
} finally { |
|
255 |
dependencies.pop(); |
|
256 |
deferredLintHandler.setPos(prevLintPos); |
|
257 |
log.useSource(prev); |
|
258 |
} |
|
259 |
} |
|
260 |
||
261 |
if (firstToComplete) { |
|
262 |
List<Env<AttrContext>> out = queue.toList(); |
|
263 |
||
264 |
queue.clear(); |
|
265 |
return next != null ? next.runPhase(out) : out; |
|
266 |
} else { |
|
267 |
return List.nil(); |
|
268 |
} |
|
269 |
} |
|
270 |
||
271 |
protected abstract void doRunPhase(Env<AttrContext> env); |
|
10 | 272 |
} |
273 |
||
27857 | 274 |
private final ImportsPhase completeClass = new ImportsPhase(); |
275 |
||
276 |
/**Analyze import clauses. |
|
277 |
*/ |
|
278 |
private final class ImportsPhase extends Phase { |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
279 |
|
27857 | 280 |
public ImportsPhase() { |
281 |
super(CompletionCause.IMPORTS_PHASE, new HierarchyPhase()); |
|
282 |
} |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
283 |
|
27857 | 284 |
Env<AttrContext> env; |
285 |
ImportFilter staticImportFilter; |
|
29149
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
286 |
ImportFilter typeImportFilter; |
27857 | 287 |
|
288 |
@Override |
|
289 |
protected void doRunPhase(Env<AttrContext> env) { |
|
290 |
JCClassDecl tree = env.enclClass; |
|
291 |
ClassSymbol sym = tree.sym; |
|
292 |
||
293 |
// If sym is a toplevel-class, make sure any import |
|
294 |
// clauses in its source file have been seen. |
|
295 |
if (sym.owner.kind == PCK) { |
|
296 |
resolveImports(env.toplevel, env.enclosing(TOPLEVEL)); |
|
297 |
todo.append(env); |
|
298 |
} |
|
299 |
||
300 |
if (sym.owner.kind == TYP) |
|
301 |
sym.owner.complete(); |
|
302 |
} |
|
303 |
||
304 |
private void resolveImports(JCCompilationUnit tree, Env<AttrContext> env) { |
|
29149
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
305 |
if (tree.starImportScope.isFilled()) { |
27857 | 306 |
// we must have already processed this toplevel |
307 |
return; |
|
308 |
} |
|
309 |
||
310 |
ImportFilter prevStaticImportFilter = staticImportFilter; |
|
29149
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
311 |
ImportFilter prevTypeImportFilter = typeImportFilter; |
27857 | 312 |
DiagnosticPosition prevLintPos = deferredLintHandler.immediate(); |
313 |
Lint prevLint = chk.setLint(lint); |
|
314 |
Env<AttrContext> prevEnv = this.env; |
|
315 |
try { |
|
316 |
this.env = env; |
|
317 |
final PackageSymbol packge = env.toplevel.packge; |
|
29149
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
318 |
this.staticImportFilter = |
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
319 |
(origin, sym) -> sym.isStatic() && |
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
320 |
chk.importAccessible(sym, packge) && |
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
321 |
sym.isMemberOf((TypeSymbol) origin.owner, types); |
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
322 |
this.typeImportFilter = |
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
323 |
(origin, sym) -> sym.kind == TYP && |
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
324 |
chk.importAccessible(sym, packge); |
27857 | 325 |
|
326 |
// Import-on-demand java.lang. |
|
31299
81ce5febcae8
4869999: Error on import statement naming package containing no class files
sadayapalam
parents:
30066
diff
changeset
|
327 |
PackageSymbol javaLang = syms.enterPackage(names.java_lang); |
81ce5febcae8
4869999: Error on import statement naming package containing no class files
sadayapalam
parents:
30066
diff
changeset
|
328 |
if (javaLang.members().isEmpty() && !javaLang.exists()) |
81ce5febcae8
4869999: Error on import statement naming package containing no class files
sadayapalam
parents:
30066
diff
changeset
|
329 |
throw new FatalError(diags.fragment("fatal.err.no.java.lang")); |
81ce5febcae8
4869999: Error on import statement naming package containing no class files
sadayapalam
parents:
30066
diff
changeset
|
330 |
importAll(tree.pos, javaLang, env); |
27857 | 331 |
|
332 |
// Process the package def and all import clauses. |
|
333 |
if (tree.getPackage() != null) |
|
334 |
checkClassPackageClash(tree.getPackage()); |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
335 |
|
27857 | 336 |
for (JCImport imp : tree.getImports()) { |
337 |
doImport(imp); |
|
338 |
} |
|
339 |
} finally { |
|
340 |
this.env = prevEnv; |
|
341 |
chk.setLint(prevLint); |
|
342 |
deferredLintHandler.setPos(prevLintPos); |
|
343 |
this.staticImportFilter = prevStaticImportFilter; |
|
29149
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
27857
diff
changeset
|
344 |
this.typeImportFilter = prevTypeImportFilter; |
27857 | 345 |
} |
346 |
} |
|
347 |
||
348 |
private void checkClassPackageClash(JCPackageDecl tree) { |
|
349 |
// check that no class exists with same fully qualified name as |
|
350 |
// toplevel package |
|
351 |
if (checkClash && tree.pid != null) { |
|
352 |
Symbol p = env.toplevel.packge; |
|
353 |
while (p.owner != syms.rootPackage) { |
|
354 |
p.owner.complete(); // enter all class members of p |
|
355 |
if (syms.classes.get(p.getQualifiedName()) != null) { |
|
356 |
log.error(tree.pos, |
|
357 |
"pkg.clashes.with.class.of.same.name", |
|
358 |
p); |
|
359 |
} |
|
360 |
p = p.owner; |
|
361 |
} |
|
362 |
} |
|
363 |
// process package annotations |
|
364 |
annotate.annotateLater(tree.annotations, env, env.toplevel.packge, null); |
|
365 |
} |
|
366 |
||
367 |
private void doImport(JCImport tree) { |
|
368 |
dependencies.push(AttributionKind.IMPORT, tree); |
|
369 |
JCFieldAccess imp = (JCFieldAccess)tree.qualid; |
|
370 |
Name name = TreeInfo.name(imp); |
|
371 |
||
372 |
// Create a local environment pointing to this tree to disable |
|
373 |
// effects of other imports in Resolve.findGlobalType |
|
374 |
Env<AttrContext> localEnv = env.dup(tree); |
|
375 |
||
376 |
TypeSymbol p = attr.attribImportQualifier(tree, localEnv).tsym; |
|
377 |
if (name == names.asterisk) { |
|
378 |
// Import on demand. |
|
379 |
chk.checkCanonical(imp.selected); |
|
380 |
if (tree.staticImport) |
|
381 |
importStaticAll(tree.pos, p, env); |
|
382 |
else |
|
383 |
importAll(tree.pos, p, env); |
|
384 |
} else { |
|
385 |
// Named type import. |
|
386 |
if (tree.staticImport) { |
|
387 |
importNamedStatic(tree.pos(), p, name, localEnv, tree); |
|
388 |
chk.checkCanonical(imp.selected); |
|
389 |
} else { |
|
390 |
TypeSymbol c = attribImportType(imp, localEnv).tsym; |
|
391 |
chk.checkCanonical(imp); |
|
392 |
importNamed(tree.pos(), c, env, tree); |
|
393 |
} |
|
394 |
} |
|
395 |
dependencies.pop(); |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
396 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
397 |
|
27857 | 398 |
Type attribImportType(JCTree tree, Env<AttrContext> env) { |
399 |
Assert.check(completionEnabled); |
|
400 |
Lint prevLint = chk.setLint(allowDeprecationOnImport ? |
|
401 |
lint : lint.suppress(LintCategory.DEPRECATION)); |
|
402 |
try { |
|
403 |
// To prevent deep recursion, suppress completion of some |
|
404 |
// types. |
|
405 |
completionEnabled = false; |
|
406 |
return attr.attribType(tree, env); |
|
407 |
} finally { |
|
408 |
completionEnabled = true; |
|
409 |
chk.setLint(prevLint); |
|
410 |
} |
|
411 |
} |
|
412 |
||
413 |
/** Import all classes of a class or package on demand. |
|
414 |
* @param pos Position to be used for error reporting. |
|
415 |
* @param tsym The class or package the members of which are imported. |
|
416 |
* @param env The env in which the imported classes will be entered. |
|
417 |
*/ |
|
418 |
private void importAll(int pos, |
|
419 |
final TypeSymbol tsym, |
|
420 |
Env<AttrContext> env) { |
|
421 |
env.toplevel.starImportScope.importAll(types, tsym.members(), typeImportFilter, false); |
|
422 |
} |
|
423 |
||
424 |
/** Import all static members of a class or package on demand. |
|
425 |
* @param pos Position to be used for error reporting. |
|
426 |
* @param tsym The class or package the members of which are imported. |
|
427 |
* @param env The env in which the imported classes will be entered. |
|
428 |
*/ |
|
429 |
private void importStaticAll(int pos, |
|
430 |
final TypeSymbol tsym, |
|
431 |
Env<AttrContext> env) { |
|
432 |
final StarImportScope toScope = env.toplevel.starImportScope; |
|
433 |
final TypeSymbol origin = tsym; |
|
434 |
||
435 |
toScope.importAll(types, origin.members(), staticImportFilter, true); |
|
436 |
} |
|
437 |
||
438 |
/** Import statics types of a given name. Non-types are handled in Attr. |
|
439 |
* @param pos Position to be used for error reporting. |
|
440 |
* @param tsym The class from which the name is imported. |
|
441 |
* @param name The (simple) name being imported. |
|
442 |
* @param env The environment containing the named import |
|
443 |
* scope to add to. |
|
444 |
*/ |
|
445 |
private void importNamedStatic(final DiagnosticPosition pos, |
|
446 |
final TypeSymbol tsym, |
|
447 |
final Name name, |
|
448 |
final Env<AttrContext> env, |
|
449 |
final JCImport imp) { |
|
450 |
if (tsym.kind != TYP) { |
|
451 |
log.error(DiagnosticFlag.RECOVERABLE, pos, "static.imp.only.classes.and.interfaces"); |
|
452 |
return; |
|
453 |
} |
|
454 |
||
455 |
final NamedImportScope toScope = env.toplevel.namedImportScope; |
|
456 |
final Scope originMembers = tsym.members(); |
|
457 |
||
458 |
imp.importScope = toScope.importByName(types, originMembers, name, staticImportFilter); |
|
459 |
} |
|
460 |
||
461 |
/** Import given class. |
|
462 |
* @param pos Position to be used for error reporting. |
|
463 |
* @param tsym The class to be imported. |
|
464 |
* @param env The environment containing the named import |
|
465 |
* scope to add to. |
|
466 |
*/ |
|
467 |
private void importNamed(DiagnosticPosition pos, final Symbol tsym, Env<AttrContext> env, JCImport imp) { |
|
468 |
if (tsym.kind == TYP) |
|
469 |
imp.importScope = env.toplevel.namedImportScope.importType(tsym.owner.members(), tsym.owner.members(), tsym); |
|
470 |
} |
|
471 |
||
472 |
} |
|
473 |
||
474 |
/**Defines common utility methods used by the HierarchyPhase and HeaderPhase. |
|
475 |
*/ |
|
476 |
private abstract class AbstractHeaderPhase extends Phase { |
|
477 |
||
478 |
public AbstractHeaderPhase(CompletionCause phaseName, Phase next) { |
|
479 |
super(phaseName, next); |
|
480 |
} |
|
481 |
||
482 |
protected Env<AttrContext> baseEnv(JCClassDecl tree, Env<AttrContext> env) { |
|
483 |
WriteableScope baseScope = WriteableScope.create(tree.sym); |
|
484 |
//import already entered local classes into base scope |
|
485 |
for (Symbol sym : env.outer.info.scope.getSymbols(NON_RECURSIVE)) { |
|
486 |
if (sym.isLocal()) { |
|
487 |
baseScope.enter(sym); |
|
488 |
} |
|
489 |
} |
|
490 |
//import current type-parameters into base scope |
|
491 |
if (tree.typarams != null) |
|
492 |
for (List<JCTypeParameter> typarams = tree.typarams; |
|
493 |
typarams.nonEmpty(); |
|
494 |
typarams = typarams.tail) |
|
495 |
baseScope.enter(typarams.head.type.tsym); |
|
496 |
Env<AttrContext> outer = env.outer; // the base clause can't see members of this class |
|
497 |
Env<AttrContext> localEnv = outer.dup(tree, outer.info.dup(baseScope)); |
|
498 |
localEnv.baseClause = true; |
|
499 |
localEnv.outer = outer; |
|
500 |
localEnv.info.isSelfCall = false; |
|
501 |
return localEnv; |
|
502 |
} |
|
503 |
||
504 |
/** Generate a base clause for an enum type. |
|
505 |
* @param pos The position for trees and diagnostics, if any |
|
506 |
* @param c The class symbol of the enum |
|
507 |
*/ |
|
508 |
protected JCExpression enumBase(int pos, ClassSymbol c) { |
|
509 |
JCExpression result = make.at(pos). |
|
510 |
TypeApply(make.QualIdent(syms.enumSym), |
|
511 |
List.<JCExpression>of(make.Type(c.type))); |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
512 |
return result; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
513 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
514 |
|
27857 | 515 |
protected Type modelMissingTypes(Type t, final JCExpression tree, final boolean interfaceExpected) { |
516 |
if (!t.hasTag(ERROR)) |
|
517 |
return t; |
|
518 |
||
519 |
return new ErrorType(t.getOriginalType(), t.tsym) { |
|
520 |
private Type modelType; |
|
521 |
||
522 |
@Override |
|
523 |
public Type getModelType() { |
|
524 |
if (modelType == null) |
|
525 |
modelType = new Synthesizer(getOriginalType(), interfaceExpected).visit(tree); |
|
526 |
return modelType; |
|
527 |
} |
|
528 |
}; |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
529 |
} |
27857 | 530 |
// where: |
531 |
private class Synthesizer extends JCTree.Visitor { |
|
532 |
Type originalType; |
|
533 |
boolean interfaceExpected; |
|
534 |
List<ClassSymbol> synthesizedSymbols = List.nil(); |
|
535 |
Type result; |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
536 |
|
27857 | 537 |
Synthesizer(Type originalType, boolean interfaceExpected) { |
538 |
this.originalType = originalType; |
|
539 |
this.interfaceExpected = interfaceExpected; |
|
540 |
} |
|
541 |
||
542 |
Type visit(JCTree tree) { |
|
543 |
tree.accept(this); |
|
544 |
return result; |
|
545 |
} |
|
546 |
||
547 |
List<Type> visit(List<? extends JCTree> trees) { |
|
548 |
ListBuffer<Type> lb = new ListBuffer<>(); |
|
549 |
for (JCTree t: trees) |
|
550 |
lb.append(visit(t)); |
|
551 |
return lb.toList(); |
|
552 |
} |
|
553 |
||
554 |
@Override |
|
555 |
public void visitTree(JCTree tree) { |
|
556 |
result = syms.errType; |
|
557 |
} |
|
558 |
||
559 |
@Override |
|
560 |
public void visitIdent(JCIdent tree) { |
|
561 |
if (!tree.type.hasTag(ERROR)) { |
|
562 |
result = tree.type; |
|
563 |
} else { |
|
564 |
result = synthesizeClass(tree.name, syms.unnamedPackage).type; |
|
565 |
} |
|
566 |
} |
|
567 |
||
568 |
@Override |
|
569 |
public void visitSelect(JCFieldAccess tree) { |
|
570 |
if (!tree.type.hasTag(ERROR)) { |
|
571 |
result = tree.type; |
|
572 |
} else { |
|
573 |
Type selectedType; |
|
574 |
boolean prev = interfaceExpected; |
|
575 |
try { |
|
576 |
interfaceExpected = false; |
|
577 |
selectedType = visit(tree.selected); |
|
578 |
} finally { |
|
579 |
interfaceExpected = prev; |
|
580 |
} |
|
581 |
ClassSymbol c = synthesizeClass(tree.name, selectedType.tsym); |
|
582 |
result = c.type; |
|
583 |
} |
|
584 |
} |
|
585 |
||
586 |
@Override |
|
587 |
public void visitTypeApply(JCTypeApply tree) { |
|
588 |
if (!tree.type.hasTag(ERROR)) { |
|
589 |
result = tree.type; |
|
590 |
} else { |
|
591 |
ClassType clazzType = (ClassType) visit(tree.clazz); |
|
592 |
if (synthesizedSymbols.contains(clazzType.tsym)) |
|
593 |
synthesizeTyparams((ClassSymbol) clazzType.tsym, tree.arguments.size()); |
|
594 |
final List<Type> actuals = visit(tree.arguments); |
|
595 |
result = new ErrorType(tree.type, clazzType.tsym) { |
|
596 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
597 |
public List<Type> getTypeArguments() { |
|
598 |
return actuals; |
|
599 |
} |
|
600 |
}; |
|
601 |
} |
|
602 |
} |
|
603 |
||
604 |
ClassSymbol synthesizeClass(Name name, Symbol owner) { |
|
605 |
int flags = interfaceExpected ? INTERFACE : 0; |
|
606 |
ClassSymbol c = new ClassSymbol(flags, name, owner); |
|
607 |
c.members_field = new Scope.ErrorScope(c); |
|
608 |
c.type = new ErrorType(originalType, c) { |
|
609 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
|
610 |
public List<Type> getTypeArguments() { |
|
611 |
return typarams_field; |
|
612 |
} |
|
613 |
}; |
|
614 |
synthesizedSymbols = synthesizedSymbols.prepend(c); |
|
615 |
return c; |
|
616 |
} |
|
617 |
||
618 |
void synthesizeTyparams(ClassSymbol sym, int n) { |
|
619 |
ClassType ct = (ClassType) sym.type; |
|
620 |
Assert.check(ct.typarams_field.isEmpty()); |
|
621 |
if (n == 1) { |
|
622 |
TypeVar v = new TypeVar(names.fromString("T"), sym, syms.botType); |
|
623 |
ct.typarams_field = ct.typarams_field.prepend(v); |
|
624 |
} else { |
|
625 |
for (int i = n; i > 0; i--) { |
|
626 |
TypeVar v = new TypeVar(names.fromString("T" + i), sym, |
|
627 |
syms.botType); |
|
628 |
ct.typarams_field = ct.typarams_field.prepend(v); |
|
629 |
} |
|
630 |
} |
|
631 |
} |
|
632 |
} |
|
633 |
||
634 |
protected void attribSuperTypes(Env<AttrContext> env, Env<AttrContext> baseEnv) { |
|
635 |
JCClassDecl tree = env.enclClass; |
|
636 |
ClassSymbol sym = tree.sym; |
|
637 |
ClassType ct = (ClassType)sym.type; |
|
638 |
// Determine supertype. |
|
639 |
Type supertype; |
|
640 |
JCExpression extending; |
|
641 |
||
642 |
if (tree.extending != null) { |
|
643 |
extending = clearTypeParams(tree.extending); |
|
644 |
dependencies.push(AttributionKind.EXTENDS, tree.extending); |
|
645 |
try { |
|
646 |
supertype = attr.attribBase(extending, baseEnv, |
|
647 |
true, false, true); |
|
648 |
} finally { |
|
649 |
dependencies.pop(); |
|
650 |
} |
|
651 |
} else { |
|
652 |
extending = null; |
|
653 |
supertype = ((tree.mods.flags & Flags.ENUM) != 0) |
|
654 |
? attr.attribBase(enumBase(tree.pos, sym), baseEnv, |
|
655 |
true, false, false) |
|
656 |
: (sym.fullname == names.java_lang_Object) |
|
657 |
? Type.noType |
|
658 |
: syms.objectType; |
|
659 |
} |
|
660 |
ct.supertype_field = modelMissingTypes(supertype, extending, false); |
|
661 |
||
662 |
// Determine interfaces. |
|
663 |
ListBuffer<Type> interfaces = new ListBuffer<>(); |
|
664 |
ListBuffer<Type> all_interfaces = null; // lazy init |
|
665 |
List<JCExpression> interfaceTrees = tree.implementing; |
|
666 |
for (JCExpression iface : interfaceTrees) { |
|
667 |
iface = clearTypeParams(iface); |
|
668 |
dependencies.push(AttributionKind.IMPLEMENTS, iface); |
|
669 |
try { |
|
670 |
Type it = attr.attribBase(iface, baseEnv, false, true, true); |
|
671 |
if (it.hasTag(CLASS)) { |
|
672 |
interfaces.append(it); |
|
673 |
if (all_interfaces != null) all_interfaces.append(it); |
|
674 |
} else { |
|
675 |
if (all_interfaces == null) |
|
676 |
all_interfaces = new ListBuffer<Type>().appendList(interfaces); |
|
677 |
all_interfaces.append(modelMissingTypes(it, iface, true)); |
|
678 |
||
679 |
} |
|
680 |
} finally { |
|
681 |
dependencies.pop(); |
|
682 |
} |
|
683 |
} |
|
684 |
||
685 |
if ((sym.flags_field & ANNOTATION) != 0) { |
|
686 |
ct.interfaces_field = List.of(syms.annotationType); |
|
687 |
ct.all_interfaces_field = ct.interfaces_field; |
|
688 |
} else { |
|
689 |
ct.interfaces_field = interfaces.toList(); |
|
690 |
ct.all_interfaces_field = (all_interfaces == null) |
|
691 |
? ct.interfaces_field : all_interfaces.toList(); |
|
692 |
} |
|
693 |
} |
|
694 |
//where: |
|
695 |
protected JCExpression clearTypeParams(JCExpression superType) { |
|
696 |
return superType; |
|
697 |
} |
|
698 |
} |
|
699 |
||
700 |
private final class HierarchyPhase extends AbstractHeaderPhase { |
|
701 |
||
702 |
public HierarchyPhase() { |
|
703 |
super(CompletionCause.HIERARCHY_PHASE, new HeaderPhase()); |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
704 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
705 |
|
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
706 |
@Override |
27857 | 707 |
protected void doRunPhase(Env<AttrContext> env) { |
708 |
JCClassDecl tree = env.enclClass; |
|
709 |
ClassSymbol sym = tree.sym; |
|
710 |
ClassType ct = (ClassType)sym.type; |
|
711 |
||
712 |
Env<AttrContext> baseEnv = baseEnv(tree, env); |
|
713 |
||
714 |
attribSuperTypes(env, baseEnv); |
|
715 |
||
716 |
if (sym.fullname == names.java_lang_Object) { |
|
717 |
if (tree.extending != null) { |
|
718 |
chk.checkNonCyclic(tree.extending.pos(), |
|
719 |
ct.supertype_field); |
|
720 |
ct.supertype_field = Type.noType; |
|
721 |
} |
|
722 |
else if (tree.implementing.nonEmpty()) { |
|
723 |
chk.checkNonCyclic(tree.implementing.head.pos(), |
|
724 |
ct.interfaces_field.head); |
|
725 |
ct.interfaces_field = List.nil(); |
|
726 |
} |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
727 |
} |
27857 | 728 |
|
729 |
// Annotations. |
|
730 |
// In general, we cannot fully process annotations yet, but we |
|
731 |
// can attribute the annotation types and then check to see if the |
|
732 |
// @Deprecated annotation is present. |
|
733 |
attr.attribAnnotationTypes(tree.mods.annotations, baseEnv); |
|
734 |
if (hasDeprecatedAnnotation(tree.mods.annotations)) |
|
735 |
sym.flags_field |= DEPRECATED; |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
736 |
|
27857 | 737 |
chk.checkNonCyclicDecl(tree); |
738 |
} |
|
739 |
//where: |
|
740 |
protected JCExpression clearTypeParams(JCExpression superType) { |
|
741 |
switch (superType.getTag()) { |
|
742 |
case TYPEAPPLY: |
|
743 |
return ((JCTypeApply) superType).clazz; |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
744 |
} |
27857 | 745 |
|
746 |
return superType; |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
747 |
} |
27857 | 748 |
|
749 |
/** |
|
750 |
* Check if a list of annotations contains a reference to |
|
751 |
* java.lang.Deprecated. |
|
752 |
**/ |
|
753 |
private boolean hasDeprecatedAnnotation(List<JCAnnotation> annotations) { |
|
754 |
for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) { |
|
755 |
JCAnnotation a = al.head; |
|
756 |
if (a.annotationType.type == syms.deprecatedType && a.args.isEmpty()) |
|
757 |
return true; |
|
758 |
} |
|
759 |
return false; |
|
760 |
} |
|
761 |
} |
|
762 |
||
763 |
private final class HeaderPhase extends AbstractHeaderPhase { |
|
764 |
||
765 |
public HeaderPhase() { |
|
766 |
super(CompletionCause.HEADER_PHASE, new MembersPhase()); |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
767 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
768 |
|
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
769 |
@Override |
27857 | 770 |
protected void doRunPhase(Env<AttrContext> env) { |
771 |
JCClassDecl tree = env.enclClass; |
|
772 |
ClassSymbol sym = tree.sym; |
|
773 |
ClassType ct = (ClassType)sym.type; |
|
774 |
||
775 |
// create an environment for evaluating the base clauses |
|
776 |
Env<AttrContext> baseEnv = baseEnv(tree, env); |
|
777 |
||
778 |
if (tree.extending != null) |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29149
diff
changeset
|
779 |
annotate.queueScanTreeAndTypeAnnotate(tree.extending, baseEnv, sym, tree.pos()); |
27857 | 780 |
for (JCExpression impl : tree.implementing) |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29149
diff
changeset
|
781 |
annotate.queueScanTreeAndTypeAnnotate(impl, baseEnv, sym, tree.pos()); |
27857 | 782 |
annotate.flush(); |
783 |
||
784 |
attribSuperTypes(env, baseEnv); |
|
785 |
||
786 |
Set<Type> interfaceSet = new HashSet<>(); |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
787 |
|
27857 | 788 |
for (JCExpression iface : tree.implementing) { |
789 |
Type it = iface.type; |
|
790 |
if (it.hasTag(CLASS)) |
|
791 |
chk.checkNotRepeated(iface.pos(), types.erasure(it), interfaceSet); |
|
792 |
} |
|
793 |
||
794 |
annotate.annotateLater(tree.mods.annotations, baseEnv, |
|
795 |
sym, tree.pos()); |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
796 |
|
27857 | 797 |
attr.attribTypeVariables(tree.typarams, baseEnv); |
798 |
for (JCTypeParameter tp : tree.typarams) |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29149
diff
changeset
|
799 |
annotate.queueScanTreeAndTypeAnnotate(tp, baseEnv, sym, tree.pos()); |
27857 | 800 |
|
801 |
// check that no package exists with same fully qualified name, |
|
802 |
// but admit classes in the unnamed package which have the same |
|
803 |
// name as a top-level package. |
|
804 |
if (checkClash && |
|
805 |
sym.owner.kind == PCK && sym.owner != syms.unnamedPackage && |
|
806 |
syms.packageExists(sym.fullname)) { |
|
807 |
log.error(tree.pos, "clash.with.pkg.of.same.name", Kinds.kindName(sym), sym); |
|
808 |
} |
|
809 |
if (sym.owner.kind == PCK && (sym.flags_field & PUBLIC) == 0 && |
|
810 |
!env.toplevel.sourcefile.isNameCompatible(sym.name.toString(),JavaFileObject.Kind.SOURCE)) { |
|
811 |
sym.flags_field |= AUXILIARY; |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
812 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
813 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
814 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
815 |
|
27857 | 816 |
/** Enter member fields and methods of a class |
817 |
*/ |
|
818 |
private final class MembersPhase extends Phase { |
|
819 |
||
820 |
public MembersPhase() { |
|
821 |
super(CompletionCause.MEMBERS_PHASE, null); |
|
822 |
} |
|
823 |
||
824 |
@Override |
|
825 |
protected void doRunPhase(Env<AttrContext> env) { |
|
826 |
JCClassDecl tree = env.enclClass; |
|
827 |
ClassSymbol sym = tree.sym; |
|
828 |
ClassType ct = (ClassType)sym.type; |
|
829 |
||
830 |
// Add default constructor if needed. |
|
831 |
if ((sym.flags() & INTERFACE) == 0 && |
|
832 |
!TreeInfo.hasConstructors(tree.defs)) { |
|
833 |
List<Type> argtypes = List.nil(); |
|
834 |
List<Type> typarams = List.nil(); |
|
835 |
List<Type> thrown = List.nil(); |
|
836 |
long ctorFlags = 0; |
|
837 |
boolean based = false; |
|
838 |
boolean addConstructor = true; |
|
839 |
JCNewClass nc = null; |
|
840 |
if (sym.name.isEmpty()) { |
|
841 |
nc = (JCNewClass)env.next.tree; |
|
842 |
if (nc.constructor != null) { |
|
843 |
addConstructor = nc.constructor.kind != ERR; |
|
844 |
Type superConstrType = types.memberType(sym.type, |
|
845 |
nc.constructor); |
|
846 |
argtypes = superConstrType.getParameterTypes(); |
|
847 |
typarams = superConstrType.getTypeArguments(); |
|
848 |
ctorFlags = nc.constructor.flags() & VARARGS; |
|
849 |
if (nc.encl != null) { |
|
850 |
argtypes = argtypes.prepend(nc.encl.type); |
|
851 |
based = true; |
|
852 |
} |
|
853 |
thrown = superConstrType.getThrownTypes(); |
|
854 |
} |
|
855 |
} |
|
856 |
if (addConstructor) { |
|
857 |
MethodSymbol basedConstructor = nc != null ? |
|
858 |
(MethodSymbol)nc.constructor : null; |
|
859 |
JCTree constrDef = DefaultConstructor(make.at(tree.pos), sym, |
|
860 |
basedConstructor, |
|
861 |
typarams, argtypes, thrown, |
|
862 |
ctorFlags, based); |
|
863 |
tree.defs = tree.defs.prepend(constrDef); |
|
864 |
} |
|
865 |
} |
|
866 |
||
867 |
// enter symbols for 'this' into current scope. |
|
868 |
VarSymbol thisSym = |
|
869 |
new VarSymbol(FINAL | HASINIT, names._this, sym.type, sym); |
|
870 |
thisSym.pos = Position.FIRSTPOS; |
|
871 |
env.info.scope.enter(thisSym); |
|
872 |
// if this is a class, enter symbol for 'super' into current scope. |
|
873 |
if ((sym.flags_field & INTERFACE) == 0 && |
|
874 |
ct.supertype_field.hasTag(CLASS)) { |
|
875 |
VarSymbol superSym = |
|
876 |
new VarSymbol(FINAL | HASINIT, names._super, |
|
877 |
ct.supertype_field, sym); |
|
878 |
superSym.pos = Position.FIRSTPOS; |
|
879 |
env.info.scope.enter(superSym); |
|
880 |
} |
|
881 |
||
882 |
finishClass(tree, env); |
|
883 |
||
884 |
if (allowTypeAnnos) { |
|
885 |
typeAnnotations.organizeTypeAnnotationsSignatures(env, (JCClassDecl)env.tree); |
|
886 |
typeAnnotations.validateTypeAnnotationsSignatures(env, (JCClassDecl)env.tree); |
|
887 |
} |
|
888 |
} |
|
889 |
||
890 |
/** Enter members for a class. |
|
891 |
*/ |
|
892 |
void finishClass(JCClassDecl tree, Env<AttrContext> env) { |
|
893 |
if ((tree.mods.flags & Flags.ENUM) != 0 && |
|
894 |
(types.supertype(tree.sym.type).tsym.flags() & Flags.ENUM) == 0) { |
|
895 |
addEnumMembers(tree, env); |
|
896 |
} |
|
897 |
memberEnter.memberEnter(tree.defs, env); |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29149
diff
changeset
|
898 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29149
diff
changeset
|
899 |
if (tree.sym.isAnnotationType()) { |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
900 |
Assert.check(tree.sym.isCompleted()); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29149
diff
changeset
|
901 |
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
|
902 |
} |
27857 | 903 |
} |
904 |
||
905 |
/** Add the implicit members for an enum type |
|
906 |
* to the symbol table. |
|
907 |
*/ |
|
908 |
private void addEnumMembers(JCClassDecl tree, Env<AttrContext> env) { |
|
909 |
JCExpression valuesType = make.Type(new ArrayType(tree.sym.type, syms.arrayClass)); |
|
910 |
||
911 |
// public static T[] values() { return ???; } |
|
912 |
JCMethodDecl values = make. |
|
913 |
MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC), |
|
914 |
names.values, |
|
915 |
valuesType, |
|
916 |
List.<JCTypeParameter>nil(), |
|
917 |
List.<JCVariableDecl>nil(), |
|
918 |
List.<JCExpression>nil(), // thrown |
|
919 |
null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))), |
|
920 |
null); |
|
921 |
memberEnter.memberEnter(values, env); |
|
922 |
||
923 |
// public static T valueOf(String name) { return ???; } |
|
924 |
JCMethodDecl valueOf = make. |
|
925 |
MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC), |
|
926 |
names.valueOf, |
|
927 |
make.Type(tree.sym.type), |
|
928 |
List.<JCTypeParameter>nil(), |
|
929 |
List.of(make.VarDef(make.Modifiers(Flags.PARAMETER | |
|
930 |
Flags.MANDATED), |
|
931 |
names.fromString("name"), |
|
932 |
make.Type(syms.stringType), null)), |
|
933 |
List.<JCExpression>nil(), // thrown |
|
934 |
null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))), |
|
935 |
null); |
|
936 |
memberEnter.memberEnter(valueOf, env); |
|
937 |
} |
|
938 |
||
939 |
} |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
940 |
|
10 | 941 |
/* *************************************************************************** |
942 |
* tree building |
|
943 |
****************************************************************************/ |
|
944 |
||
945 |
/** Generate default constructor for given class. For classes different |
|
946 |
* from java.lang.Object, this is: |
|
947 |
* |
|
948 |
* c(argtype_0 x_0, ..., argtype_n x_n) throws thrown { |
|
949 |
* super(x_0, ..., x_n) |
|
950 |
* } |
|
951 |
* |
|
952 |
* or, if based == true: |
|
953 |
* |
|
954 |
* c(argtype_0 x_0, ..., argtype_n x_n) throws thrown { |
|
955 |
* x_0.super(x_1, ..., x_n) |
|
956 |
* } |
|
957 |
* |
|
958 |
* @param make The tree factory. |
|
959 |
* @param c The class owning the default constructor. |
|
960 |
* @param argtypes The parameter types of the constructor. |
|
961 |
* @param thrown The thrown exceptions of the constructor. |
|
962 |
* @param based Is first parameter a this$n? |
|
963 |
*/ |
|
964 |
JCTree DefaultConstructor(TreeMaker make, |
|
965 |
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
|
966 |
MethodSymbol baseInit, |
10 | 967 |
List<Type> typarams, |
968 |
List<Type> argtypes, |
|
969 |
List<Type> thrown, |
|
970 |
long flags, |
|
971 |
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
|
972 |
JCTree result; |
10 | 973 |
if ((c.flags() & ENUM) != 0 && |
16558
07c08ad4a700
8010179: Remove transitional target values from javac
darcy
parents:
15720
diff
changeset
|
974 |
(types.supertype(c.type).tsym == syms.enumSym)) { |
10 | 975 |
// constructors of true enums are private |
976 |
flags = (flags & ~AccessFlags) | PRIVATE | GENERATEDCONSTR; |
|
977 |
} else |
|
978 |
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
|
979 |
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
|
980 |
flags |= ANONCONSTR; |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
981 |
} |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
982 |
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
|
983 |
Type initType = typarams.nonEmpty() ? |
24396 | 984 |
new ForAll(typarams, mType) : |
985 |
mType; |
|
17999
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
986 |
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
|
987 |
initType, c); |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
988 |
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
|
989 |
argtypes, based); |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
990 |
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
|
991 |
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
|
992 |
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
|
993 |
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
|
994 |
} |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
995 |
result = make.MethodDef(init, make.Block(0, stats)); |
10 | 996 |
return result; |
997 |
} |
|
998 |
||
17999
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
999 |
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
|
1000 |
TreeMaker make, |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1001 |
MethodSymbol baseInit, |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1002 |
MethodSymbol init, |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1003 |
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
|
1004 |
boolean based) { |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1005 |
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
|
1006 |
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
|
1007 |
if (based) { |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1008 |
/* 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
|
1009 |
* 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
|
1010 |
* |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1011 |
* 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
|
1012 |
* |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1013 |
* 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
|
1014 |
* 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
|
1015 |
* 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
|
1016 |
* 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
|
1017 |
*/ |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1018 |
initParams = List.nil(); |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19656
diff
changeset
|
1019 |
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
|
1020 |
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
|
1021 |
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
|
1022 |
} |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1023 |
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
|
1024 |
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
|
1025 |
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
|
1026 |
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
|
1027 |
while (baseInitParams.nonEmpty() && argTypesList.nonEmpty()) { |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19656
diff
changeset
|
1028 |
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
|
1029 |
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
|
1030 |
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
|
1031 |
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
|
1032 |
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
|
1033 |
} |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1034 |
} |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1035 |
return initParams; |
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 |
|
10 | 1038 |
/** Generate call to superclass constructor. This is: |
1039 |
* |
|
1040 |
* super(id_0, ..., id_n) |
|
1041 |
* |
|
1042 |
* or, if based == true |
|
1043 |
* |
|
1044 |
* id_0.super(id_1,...,id_n) |
|
1045 |
* |
|
1046 |
* where id_0, ..., id_n are the names of the given parameters. |
|
1047 |
* |
|
1048 |
* @param make The tree factory |
|
1049 |
* @param params The parameters that need to be passed to super |
|
1050 |
* @param typarams The type parameters that need to be passed to super |
|
1051 |
* @param based Is first parameter a this$n? |
|
1052 |
*/ |
|
1053 |
JCExpressionStatement SuperCall(TreeMaker make, |
|
1054 |
List<Type> typarams, |
|
1055 |
List<JCVariableDecl> params, |
|
1056 |
boolean based) { |
|
1057 |
JCExpression meth; |
|
1058 |
if (based) { |
|
1059 |
meth = make.Select(make.Ident(params.head), names._super); |
|
1060 |
params = params.tail; |
|
1061 |
} else { |
|
1062 |
meth = make.Ident(names._super); |
|
1063 |
} |
|
1064 |
List<JCExpression> typeargs = typarams.nonEmpty() ? make.Types(typarams) : null; |
|
1065 |
return make.Exec(make.Apply(typeargs, meth, make.Idents(params))); |
|
1066 |
} |
|
1067 |
} |