author | emc |
Fri, 06 Jun 2014 16:00:59 -0400 | |
changeset 24895 | dd091d389fbf |
parent 24604 | 7f68545b5128 |
child 24903 | 41e1812d6b4c |
permissions | -rw-r--r-- |
10 | 1 |
/* |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
2 |
* Copyright (c) 2003, 2014, 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.*; |
|
34 |
import com.sun.tools.javac.jvm.*; |
|
35 |
import com.sun.tools.javac.tree.*; |
|
36 |
import com.sun.tools.javac.util.*; |
|
37 |
||
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
38 |
import com.sun.tools.javac.code.Symbol.*; |
10 | 39 |
import com.sun.tools.javac.code.Type.*; |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
40 |
import com.sun.tools.javac.code.TypeAnnotationPosition.*; |
10 | 41 |
import com.sun.tools.javac.tree.JCTree.*; |
42 |
||
43 |
import static com.sun.tools.javac.code.Flags.*; |
|
10950 | 44 |
import static com.sun.tools.javac.code.Flags.ANNOTATION; |
10 | 45 |
import static com.sun.tools.javac.code.Kinds.*; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
46 |
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
|
47 |
import static com.sun.tools.javac.code.TypeTag.ERROR; |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
48 |
import static com.sun.tools.javac.code.TypeTag.TYPEVAR; |
10950 | 49 |
import static com.sun.tools.javac.tree.JCTree.Tag.*; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24396
diff
changeset
|
50 |
|
11709
0d56d3fc22e6
7129225: javac fails to run annotation processors when star import of package of gensrc
jjh
parents:
10950
diff
changeset
|
51 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; |
10 | 52 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
53 |
||
54 |
/** This is the second phase of Enter, in which classes are completed |
|
55 |
* by entering their members into the class scope using |
|
56 |
* MemberEnter.complete(). See Enter for an overview. |
|
57 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
58 |
* <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
|
59 |
* If you write code that depends on this, you do so at your own risk. |
10 | 60 |
* This code and its internal interfaces are subject to change or |
61 |
* deletion without notice.</b> |
|
62 |
*/ |
|
63 |
public class MemberEnter extends JCTree.Visitor implements Completer { |
|
22163 | 64 |
protected static final Context.Key<MemberEnter> memberEnterKey = new Context.Key<>(); |
10 | 65 |
|
66 |
/** A switch to determine whether we check for package/class conflicts |
|
67 |
*/ |
|
68 |
final static boolean checkClash = true; |
|
69 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1045
diff
changeset
|
70 |
private final Names names; |
10 | 71 |
private final Enter enter; |
72 |
private final Log log; |
|
73 |
private final Check chk; |
|
74 |
private final Attr attr; |
|
75 |
private final Symtab syms; |
|
76 |
private final TreeMaker make; |
|
77 |
private final Todo todo; |
|
78 |
private final Annotate annotate; |
|
79 |
private final Types types; |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
80 |
private final JCDiagnostic.Factory diags; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12917
diff
changeset
|
81 |
private final Source source; |
10 | 82 |
private final Target target; |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
83 |
private final DeferredLintHandler deferredLintHandler; |
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
84 |
private final Lint lint; |
10 | 85 |
|
86 |
public static MemberEnter instance(Context context) { |
|
87 |
MemberEnter instance = context.get(memberEnterKey); |
|
88 |
if (instance == null) |
|
89 |
instance = new MemberEnter(context); |
|
90 |
return instance; |
|
91 |
} |
|
92 |
||
93 |
protected MemberEnter(Context context) { |
|
94 |
context.put(memberEnterKey, this); |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1045
diff
changeset
|
95 |
names = Names.instance(context); |
10 | 96 |
enter = Enter.instance(context); |
97 |
log = Log.instance(context); |
|
98 |
chk = Check.instance(context); |
|
99 |
attr = Attr.instance(context); |
|
100 |
syms = Symtab.instance(context); |
|
101 |
make = TreeMaker.instance(context); |
|
102 |
todo = Todo.instance(context); |
|
103 |
annotate = Annotate.instance(context); |
|
104 |
types = Types.instance(context); |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
105 |
diags = JCDiagnostic.Factory.instance(context); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12917
diff
changeset
|
106 |
source = Source.instance(context); |
10 | 107 |
target = Target.instance(context); |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
108 |
deferredLintHandler = DeferredLintHandler.instance(context); |
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
109 |
lint = Lint.instance(context); |
18643
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18389
diff
changeset
|
110 |
allowTypeAnnos = source.allowTypeAnnotations(); |
10 | 111 |
} |
112 |
||
18643
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18389
diff
changeset
|
113 |
/** Switch: support type annotations. |
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18389
diff
changeset
|
114 |
*/ |
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18389
diff
changeset
|
115 |
boolean allowTypeAnnos; |
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18389
diff
changeset
|
116 |
|
10 | 117 |
/** A queue for classes whose members still need to be entered into the |
118 |
* symbol table. |
|
119 |
*/ |
|
22163 | 120 |
ListBuffer<Env<AttrContext>> halfcompleted = new ListBuffer<>(); |
10 | 121 |
|
122 |
/** Set to true only when the first of a set of classes is |
|
18643
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18389
diff
changeset
|
123 |
* processed from the half completed queue. |
10 | 124 |
*/ |
125 |
boolean isFirst = true; |
|
126 |
||
127 |
/** A flag to disable completion from time to time during member |
|
128 |
* enter, as we only need to look up types. This avoids |
|
129 |
* unnecessarily deep recursion. |
|
130 |
*/ |
|
131 |
boolean completionEnabled = true; |
|
132 |
||
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
133 |
/** The creator that will be used for any varDef's we visit. This |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
134 |
* is used to create the position for any type annotations (or |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
135 |
* annotations that potentially are type annotations) that we |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
136 |
* encounter. |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
137 |
*/ |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
138 |
Annotate.PositionCreator creator; |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
139 |
|
10 | 140 |
/* ---------- Processing import clauses ---------------- |
141 |
*/ |
|
142 |
||
143 |
/** Import all classes of a class or package on demand. |
|
144 |
* @param pos Position to be used for error reporting. |
|
145 |
* @param tsym The class or package the members of which are imported. |
|
14259 | 146 |
* @param env The env in which the imported classes will be entered. |
10 | 147 |
*/ |
148 |
private void importAll(int pos, |
|
149 |
final TypeSymbol tsym, |
|
150 |
Env<AttrContext> env) { |
|
151 |
// Check that packages imported from exist (JLS ???). |
|
152 |
if (tsym.kind == PCK && tsym.members().elems == null && !tsym.exists()) { |
|
153 |
// If we can't find java.lang, exit immediately. |
|
154 |
if (((PackageSymbol)tsym).fullname.equals(names.java_lang)) { |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
155 |
JCDiagnostic msg = diags.fragment("fatal.err.no.java.lang"); |
10 | 156 |
throw new FatalError(msg); |
157 |
} else { |
|
11709
0d56d3fc22e6
7129225: javac fails to run annotation processors when star import of package of gensrc
jjh
parents:
10950
diff
changeset
|
158 |
log.error(DiagnosticFlag.RESOLVE_ERROR, pos, "doesnt.exist", tsym); |
10 | 159 |
} |
160 |
} |
|
7615 | 161 |
env.toplevel.starImportScope.importAll(tsym.members()); |
10 | 162 |
} |
163 |
||
164 |
/** Import all static members of a class or package on demand. |
|
165 |
* @param pos Position to be used for error reporting. |
|
166 |
* @param tsym The class or package the members of which are imported. |
|
14259 | 167 |
* @param env The env in which the imported classes will be entered. |
10 | 168 |
*/ |
169 |
private void importStaticAll(int pos, |
|
170 |
final TypeSymbol tsym, |
|
171 |
Env<AttrContext> env) { |
|
172 |
final JavaFileObject sourcefile = env.toplevel.sourcefile; |
|
173 |
final Scope toScope = env.toplevel.starImportScope; |
|
174 |
final PackageSymbol packge = env.toplevel.packge; |
|
175 |
final TypeSymbol origin = tsym; |
|
176 |
||
177 |
// enter imported types immediately |
|
178 |
new Object() { |
|
22163 | 179 |
Set<Symbol> processed = new HashSet<>(); |
10 | 180 |
void importFrom(TypeSymbol tsym) { |
181 |
if (tsym == null || !processed.add(tsym)) |
|
182 |
return; |
|
183 |
||
184 |
// also import inherited names |
|
185 |
importFrom(types.supertype(tsym.type).tsym); |
|
186 |
for (Type t : types.interfaces(tsym.type)) |
|
187 |
importFrom(t.tsym); |
|
188 |
||
189 |
final Scope fromScope = tsym.members(); |
|
190 |
for (Scope.Entry e = fromScope.elems; e != null; e = e.sibling) { |
|
191 |
Symbol sym = e.sym; |
|
192 |
if (sym.kind == TYP && |
|
193 |
(sym.flags() & STATIC) != 0 && |
|
194 |
staticImportAccessible(sym, packge) && |
|
195 |
sym.isMemberOf(origin, types) && |
|
196 |
!toScope.includes(sym)) |
|
19492
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
18919
diff
changeset
|
197 |
toScope.enter(sym, fromScope, origin.members(), true); |
10 | 198 |
} |
199 |
} |
|
200 |
}.importFrom(tsym); |
|
201 |
||
202 |
// enter non-types before annotations that might use them |
|
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
203 |
annotate.earlier(new Annotate.Worker() { |
22163 | 204 |
Set<Symbol> processed = new HashSet<>(); |
10 | 205 |
|
206 |
public String toString() { |
|
207 |
return "import static " + tsym + ".*" + " in " + sourcefile; |
|
208 |
} |
|
209 |
void importFrom(TypeSymbol tsym) { |
|
210 |
if (tsym == null || !processed.add(tsym)) |
|
211 |
return; |
|
212 |
||
213 |
// also import inherited names |
|
214 |
importFrom(types.supertype(tsym.type).tsym); |
|
215 |
for (Type t : types.interfaces(tsym.type)) |
|
216 |
importFrom(t.tsym); |
|
217 |
||
218 |
final Scope fromScope = tsym.members(); |
|
219 |
for (Scope.Entry e = fromScope.elems; e != null; e = e.sibling) { |
|
220 |
Symbol sym = e.sym; |
|
221 |
if (sym.isStatic() && sym.kind != TYP && |
|
222 |
staticImportAccessible(sym, packge) && |
|
223 |
!toScope.includes(sym) && |
|
224 |
sym.isMemberOf(origin, types)) { |
|
19492
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
18919
diff
changeset
|
225 |
toScope.enter(sym, fromScope, origin.members(), true); |
10 | 226 |
} |
227 |
} |
|
228 |
} |
|
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
229 |
public void run() { |
10 | 230 |
importFrom(tsym); |
231 |
} |
|
232 |
}); |
|
233 |
} |
|
234 |
||
235 |
// is the sym accessible everywhere in packge? |
|
236 |
boolean staticImportAccessible(Symbol sym, PackageSymbol packge) { |
|
237 |
int flags = (int)(sym.flags() & AccessFlags); |
|
238 |
switch (flags) { |
|
239 |
default: |
|
240 |
case PUBLIC: |
|
241 |
return true; |
|
242 |
case PRIVATE: |
|
243 |
return false; |
|
244 |
case 0: |
|
245 |
case PROTECTED: |
|
246 |
return sym.packge() == packge; |
|
247 |
} |
|
248 |
} |
|
249 |
||
250 |
/** Import statics types of a given name. Non-types are handled in Attr. |
|
251 |
* @param pos Position to be used for error reporting. |
|
252 |
* @param tsym The class from which the name is imported. |
|
253 |
* @param name The (simple) name being imported. |
|
254 |
* @param env The environment containing the named import |
|
255 |
* scope to add to. |
|
256 |
*/ |
|
257 |
private void importNamedStatic(final DiagnosticPosition pos, |
|
258 |
final TypeSymbol tsym, |
|
259 |
final Name name, |
|
260 |
final Env<AttrContext> env) { |
|
261 |
if (tsym.kind != TYP) { |
|
12917
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
12916
diff
changeset
|
262 |
log.error(DiagnosticFlag.RECOVERABLE, pos, "static.imp.only.classes.and.interfaces"); |
10 | 263 |
return; |
264 |
} |
|
265 |
||
266 |
final Scope toScope = env.toplevel.namedImportScope; |
|
267 |
final PackageSymbol packge = env.toplevel.packge; |
|
268 |
final TypeSymbol origin = tsym; |
|
269 |
||
270 |
// enter imported types immediately |
|
271 |
new Object() { |
|
22163 | 272 |
Set<Symbol> processed = new HashSet<>(); |
10 | 273 |
void importFrom(TypeSymbol tsym) { |
274 |
if (tsym == null || !processed.add(tsym)) |
|
275 |
return; |
|
276 |
||
277 |
// also import inherited names |
|
278 |
importFrom(types.supertype(tsym.type).tsym); |
|
279 |
for (Type t : types.interfaces(tsym.type)) |
|
280 |
importFrom(t.tsym); |
|
281 |
||
282 |
for (Scope.Entry e = tsym.members().lookup(name); |
|
283 |
e.scope != null; |
|
284 |
e = e.next()) { |
|
285 |
Symbol sym = e.sym; |
|
286 |
if (sym.isStatic() && |
|
287 |
sym.kind == TYP && |
|
288 |
staticImportAccessible(sym, packge) && |
|
289 |
sym.isMemberOf(origin, types) && |
|
290 |
chk.checkUniqueStaticImport(pos, sym, toScope)) |
|
19492
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
18919
diff
changeset
|
291 |
toScope.enter(sym, sym.owner.members(), origin.members(), true); |
10 | 292 |
} |
293 |
} |
|
294 |
}.importFrom(tsym); |
|
295 |
||
296 |
// enter non-types before annotations that might use them |
|
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
297 |
annotate.earlier(new Annotate.Worker() { |
22163 | 298 |
Set<Symbol> processed = new HashSet<>(); |
10 | 299 |
boolean found = false; |
300 |
||
301 |
public String toString() { |
|
302 |
return "import static " + tsym + "." + name; |
|
303 |
} |
|
304 |
void importFrom(TypeSymbol tsym) { |
|
305 |
if (tsym == null || !processed.add(tsym)) |
|
306 |
return; |
|
307 |
||
308 |
// also import inherited names |
|
309 |
importFrom(types.supertype(tsym.type).tsym); |
|
310 |
for (Type t : types.interfaces(tsym.type)) |
|
311 |
importFrom(t.tsym); |
|
312 |
||
313 |
for (Scope.Entry e = tsym.members().lookup(name); |
|
314 |
e.scope != null; |
|
315 |
e = e.next()) { |
|
316 |
Symbol sym = e.sym; |
|
317 |
if (sym.isStatic() && |
|
318 |
staticImportAccessible(sym, packge) && |
|
319 |
sym.isMemberOf(origin, types)) { |
|
320 |
found = true; |
|
19492
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
18919
diff
changeset
|
321 |
if (sym.kind != TYP) { |
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
18919
diff
changeset
|
322 |
toScope.enter(sym, sym.owner.members(), origin.members(), true); |
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
18919
diff
changeset
|
323 |
} |
10 | 324 |
} |
325 |
} |
|
326 |
} |
|
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
327 |
public void run() { |
10 | 328 |
JavaFileObject prev = log.useSource(env.toplevel.sourcefile); |
329 |
try { |
|
330 |
importFrom(tsym); |
|
331 |
if (!found) { |
|
332 |
log.error(pos, "cant.resolve.location", |
|
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
333 |
KindName.STATIC, |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
334 |
name, List.<Type>nil(), List.<Type>nil(), |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
335 |
Kinds.typeKindName(tsym.type), |
10 | 336 |
tsym.type); |
337 |
} |
|
338 |
} finally { |
|
339 |
log.useSource(prev); |
|
340 |
} |
|
341 |
} |
|
342 |
}); |
|
343 |
} |
|
344 |
/** Import given class. |
|
345 |
* @param pos Position to be used for error reporting. |
|
346 |
* @param tsym The class to be imported. |
|
347 |
* @param env The environment containing the named import |
|
348 |
* scope to add to. |
|
349 |
*/ |
|
350 |
private void importNamed(DiagnosticPosition pos, Symbol tsym, Env<AttrContext> env) { |
|
351 |
if (tsym.kind == TYP && |
|
352 |
chk.checkUniqueImport(pos, tsym, env.toplevel.namedImportScope)) |
|
353 |
env.toplevel.namedImportScope.enter(tsym, tsym.owner.members()); |
|
354 |
} |
|
355 |
||
356 |
/** Construct method type from method signature. |
|
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
357 |
* @param msym The MethodSymbol for the method. |
10 | 358 |
* @param typarams The method's type parameters. |
359 |
* @param params The method's value parameters. |
|
360 |
* @param res The method's result type, |
|
361 |
* null if it is a constructor. |
|
15385 | 362 |
* @param recvparam The method's receiver parameter, |
363 |
* null if none given; TODO: or already set here? |
|
10 | 364 |
* @param thrown The method's thrown exceptions. |
365 |
* @param env The method's (local) environment. |
|
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
366 |
* @param declAnnos The annotations on the method declaration, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
367 |
* some of which may be type annotations on |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
368 |
* the return type. |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
369 |
* @param deferPos The deferred diagnostic position for error |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
370 |
* reporting. |
10 | 371 |
*/ |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
372 |
Type signature(final MethodSymbol msym, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
373 |
final List<JCTypeParameter> typarams, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
374 |
final List<JCVariableDecl> params, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
375 |
final JCTree res, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
376 |
final JCVariableDecl recvparam, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
377 |
final List<JCExpression> thrown, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
378 |
final Env<AttrContext> env, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
379 |
final List<JCAnnotation> declAnnos, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
380 |
final DiagnosticPosition deferPos) { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
381 |
int i; |
10 | 382 |
|
383 |
// Enter and attribute type parameters. |
|
384 |
List<Type> tvars = enter.classEnter(typarams, env); |
|
385 |
attr.attribTypeVariables(typarams, env); |
|
386 |
||
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
387 |
// Handle type annotations on type parameters. |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
388 |
i = 0; |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
389 |
for (List<JCTypeParameter> l = typarams; l.nonEmpty(); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
390 |
l = l.tail, i++) { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
391 |
final JCTypeParameter param = l.head; |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
392 |
annotate.annotateTypeLater(param, env, msym, deferPos, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
393 |
annotate.methodTypeParamCreator(i)); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
394 |
// ...and bounds on type parameters. |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
395 |
int j = 0; |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
396 |
for (List<JCExpression> bounds = param.bounds; |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
397 |
bounds.nonEmpty(); bounds = bounds.tail, j++) { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
398 |
annotate.annotateTypeLater(bounds.head, env, msym, deferPos, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
399 |
annotate.methodTypeParamBoundCreator(param, i, j)); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
400 |
} |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
401 |
} |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
402 |
|
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
403 |
// Enter and attribute value parameters. Type annotations get |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
404 |
// METHOD_FORMAL_PARAMETER positions. |
22163 | 405 |
ListBuffer<Type> argbuf = new ListBuffer<>(); |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
406 |
i = 0; |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
407 |
for (List<JCVariableDecl> l = params; l.nonEmpty(); l = l.tail, i++) { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
408 |
// The types will get annotated by visitVarDef |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
409 |
memberEnter(l.head, env, annotate.paramCreator(i)); |
10 | 410 |
argbuf.append(l.head.vartype.type); |
411 |
} |
|
412 |
||
413 |
// Attribute result type, if one is given. |
|
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
414 |
Type restype; |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
415 |
|
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
416 |
if (res != null) { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
417 |
// If we have any declaration annotations, they might |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
418 |
// be/also be type annotations on the return type. We |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
419 |
// pass them in, so they get classified and then attached |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
420 |
// to the method, or the return type, or both. |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
421 |
restype = attr.attribType(res, env); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
422 |
annotate.annotateTypeLater(res, declAnnos, env, msym, deferPos, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
423 |
annotate.returnCreator); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
424 |
} else { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
425 |
// For constructors, we don't actually have a type, so we |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
426 |
// can't have a type path (except for INNER_TYPE), and we |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
427 |
// don't have annotations on arrays, type arguments, and |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
428 |
// the like. |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
429 |
|
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
430 |
// The only type path we have is if we are in an inner type. |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
431 |
List<TypePathEntry> typepath = Annotate.makeInners(msym.owner.type); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
432 |
TypeAnnotationPosition tapos = |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
433 |
TypeAnnotationPosition.methodReturn(typepath, env.getLambda(), -1); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
434 |
|
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
435 |
// We don't have to walk down a type. We just have to do |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
436 |
// repeating annotation handling, then classify and attach |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
437 |
// the annotations. |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
438 |
annotate.annotateWithClassifyLater(declAnnos, env, msym, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
439 |
deferPos, tapos); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
440 |
restype = syms.voidType; |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
441 |
} |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
442 |
|
10 | 443 |
|
15385 | 444 |
// Attribute receiver type, if one is given. |
445 |
Type recvtype; |
|
446 |
if (recvparam!=null) { |
|
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
447 |
// The type will get annotated by visitVarDef |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
448 |
memberEnter(recvparam, env, annotate.receiverCreator); |
15385 | 449 |
recvtype = recvparam.vartype.type; |
450 |
} else { |
|
451 |
recvtype = null; |
|
452 |
} |
|
453 |
||
10 | 454 |
// Attribute thrown exceptions. |
22163 | 455 |
ListBuffer<Type> thrownbuf = new ListBuffer<>(); |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
456 |
i = 0; |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
457 |
for (List<JCExpression> l = thrown; l.nonEmpty(); l = l.tail, i++) { |
10 | 458 |
Type exc = attr.attribType(l.head, env); |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
459 |
// Annotate each exception type. |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
460 |
annotate.annotateTypeLater(l.head, env, msym, deferPos, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
461 |
annotate.throwCreator(i)); |
18909
8f9fc5d876e4
8012242: Lambda compatibility and checked exceptions
mcimadamore
parents:
18643
diff
changeset
|
462 |
if (!exc.hasTag(TYPEVAR)) { |
10 | 463 |
exc = chk.checkClassType(l.head.pos(), exc); |
18909
8f9fc5d876e4
8012242: Lambda compatibility and checked exceptions
mcimadamore
parents:
18643
diff
changeset
|
464 |
} else if (exc.tsym.owner == msym) { |
8f9fc5d876e4
8012242: Lambda compatibility and checked exceptions
mcimadamore
parents:
18643
diff
changeset
|
465 |
//mark inference variables in 'throws' clause |
8f9fc5d876e4
8012242: Lambda compatibility and checked exceptions
mcimadamore
parents:
18643
diff
changeset
|
466 |
exc.tsym.flags_field |= THROWS; |
8f9fc5d876e4
8012242: Lambda compatibility and checked exceptions
mcimadamore
parents:
18643
diff
changeset
|
467 |
} |
10 | 468 |
thrownbuf.append(exc); |
469 |
} |
|
15385 | 470 |
MethodType mtype = new MethodType(argbuf.toList(), |
10 | 471 |
restype, |
472 |
thrownbuf.toList(), |
|
473 |
syms.methodClass); |
|
15385 | 474 |
mtype.recvtype = recvtype; |
475 |
||
10 | 476 |
return tvars.isEmpty() ? mtype : new ForAll(tvars, mtype); |
477 |
} |
|
478 |
||
479 |
/* ******************************************************************** |
|
480 |
* Visitor methods for member enter |
|
481 |
*********************************************************************/ |
|
482 |
||
483 |
/** Visitor argument: the current environment |
|
484 |
*/ |
|
485 |
protected Env<AttrContext> env; |
|
486 |
||
487 |
/** Enter field and method definitions and process import |
|
488 |
* clauses, catching any completion failure exceptions. |
|
489 |
*/ |
|
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
490 |
protected void memberEnter(JCTree tree, Env<AttrContext> env, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
491 |
Annotate.PositionCreator creator) { |
10 | 492 |
Env<AttrContext> prevEnv = this.env; |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
493 |
Annotate.PositionCreator prevCreator = this.creator; |
10 | 494 |
try { |
495 |
this.env = env; |
|
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
496 |
this.creator = creator; |
10 | 497 |
tree.accept(this); |
498 |
} catch (CompletionFailure ex) { |
|
499 |
chk.completionError(tree.pos(), ex); |
|
500 |
} finally { |
|
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
501 |
this.creator = prevCreator; |
10 | 502 |
this.env = prevEnv; |
503 |
} |
|
504 |
} |
|
505 |
||
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
506 |
|
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
507 |
protected void memberEnter(JCTree tree, Env<AttrContext> env) { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
508 |
memberEnter(tree, env, annotate.noCreator); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
509 |
} |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
510 |
|
10 | 511 |
/** Enter members from a list of trees. |
512 |
*/ |
|
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
513 |
void memberEnter(List<? extends JCTree> trees, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
514 |
Env<AttrContext> env, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
515 |
Annotate.PositionCreator creator) { |
10 | 516 |
for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail) |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
517 |
memberEnter(l.head, env, creator); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
518 |
} |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
519 |
|
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
520 |
void memberEnter(List<? extends JCTree> trees, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
521 |
Env<AttrContext> env) { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
522 |
memberEnter(trees, env, annotate.noCreator); |
10 | 523 |
} |
524 |
||
525 |
/** Enter members for a class. |
|
526 |
*/ |
|
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
527 |
void finishClass(final JCClassDecl tree, final Env<AttrContext> env) { |
10 | 528 |
if ((tree.mods.flags & Flags.ENUM) != 0 && |
529 |
(types.supertype(tree.sym.type).tsym.flags() & Flags.ENUM) == 0) { |
|
530 |
addEnumMembers(tree, env); |
|
531 |
} |
|
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
532 |
memberEnter(tree.defs, env, annotate.fieldCreator); |
10 | 533 |
} |
534 |
||
535 |
/** Add the implicit members for an enum type |
|
536 |
* to the symbol table. |
|
537 |
*/ |
|
538 |
private void addEnumMembers(JCClassDecl tree, Env<AttrContext> env) { |
|
24396 | 539 |
JCExpression valuesType = make.Type(new ArrayType(tree.sym.type, syms.arrayClass, |
540 |
Type.noAnnotations)); |
|
10 | 541 |
|
542 |
// public static T[] values() { return ???; } |
|
543 |
JCMethodDecl values = make. |
|
544 |
MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC), |
|
545 |
names.values, |
|
546 |
valuesType, |
|
547 |
List.<JCTypeParameter>nil(), |
|
548 |
List.<JCVariableDecl>nil(), |
|
549 |
List.<JCExpression>nil(), // thrown |
|
550 |
null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))), |
|
551 |
null); |
|
552 |
memberEnter(values, env); |
|
553 |
||
554 |
// public static T valueOf(String name) { return ???; } |
|
555 |
JCMethodDecl valueOf = make. |
|
556 |
MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC), |
|
557 |
names.valueOf, |
|
558 |
make.Type(tree.sym.type), |
|
559 |
List.<JCTypeParameter>nil(), |
|
15720
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15385
diff
changeset
|
560 |
List.of(make.VarDef(make.Modifiers(Flags.PARAMETER | |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15385
diff
changeset
|
561 |
Flags.MANDATED), |
10 | 562 |
names.fromString("name"), |
563 |
make.Type(syms.stringType), null)), |
|
564 |
List.<JCExpression>nil(), // thrown |
|
565 |
null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))), |
|
566 |
null); |
|
567 |
memberEnter(valueOf, env); |
|
568 |
} |
|
569 |
||
570 |
public void visitTopLevel(JCCompilationUnit tree) { |
|
571 |
if (tree.starImportScope.elems != null) { |
|
572 |
// we must have already processed this toplevel |
|
573 |
return; |
|
574 |
} |
|
575 |
||
24069 | 576 |
DiagnosticPosition prevLintPos = deferredLintHandler.immediate(); |
577 |
Lint prevLint = chk.setLint(lint); |
|
578 |
||
579 |
try { |
|
580 |
// Import-on-demand java.lang. |
|
581 |
importAll(tree.pos, syms.enterPackage(names.java_lang), env); |
|
582 |
||
583 |
// Process the package def and all import clauses. |
|
584 |
memberEnter(tree.defs, env); |
|
585 |
} finally { |
|
586 |
chk.setLint(prevLint); |
|
587 |
deferredLintHandler.setPos(prevLintPos); |
|
588 |
} |
|
589 |
} |
|
590 |
||
591 |
public void visitPackageDef(JCPackageDecl tree) { |
|
10 | 592 |
// check that no class exists with same fully qualified name as |
593 |
// toplevel package |
|
594 |
if (checkClash && tree.pid != null) { |
|
24069 | 595 |
Symbol p = env.toplevel.packge; |
10 | 596 |
while (p.owner != syms.rootPackage) { |
597 |
p.owner.complete(); // enter all class members of p |
|
598 |
if (syms.classes.get(p.getQualifiedName()) != null) { |
|
599 |
log.error(tree.pos, |
|
600 |
"pkg.clashes.with.class.of.same.name", |
|
601 |
p); |
|
602 |
} |
|
603 |
p = p.owner; |
|
604 |
} |
|
605 |
} |
|
606 |
// process package annotations |
|
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
607 |
annotate.annotateLater(tree.annotations, env, env.toplevel.packge); |
10 | 608 |
} |
609 |
||
610 |
// process the non-static imports and the static imports of types. |
|
611 |
public void visitImport(JCImport tree) { |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
11709
diff
changeset
|
612 |
JCFieldAccess imp = (JCFieldAccess)tree.qualid; |
10 | 613 |
Name name = TreeInfo.name(imp); |
614 |
||
615 |
// Create a local environment pointing to this tree to disable |
|
616 |
// effects of other imports in Resolve.findGlobalType |
|
617 |
Env<AttrContext> localEnv = env.dup(tree); |
|
618 |
||
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
11709
diff
changeset
|
619 |
TypeSymbol p = attr.attribImportQualifier(tree, localEnv).tsym; |
10 | 620 |
if (name == names.asterisk) { |
621 |
// Import on demand. |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
11709
diff
changeset
|
622 |
chk.checkCanonical(imp.selected); |
10 | 623 |
if (tree.staticImport) |
624 |
importStaticAll(tree.pos, p, env); |
|
625 |
else |
|
626 |
importAll(tree.pos, p, env); |
|
627 |
} else { |
|
628 |
// Named type import. |
|
629 |
if (tree.staticImport) { |
|
630 |
importNamedStatic(tree.pos(), p, name, localEnv); |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
11709
diff
changeset
|
631 |
chk.checkCanonical(imp.selected); |
10 | 632 |
} else { |
633 |
TypeSymbol c = attribImportType(imp, localEnv).tsym; |
|
634 |
chk.checkCanonical(imp); |
|
635 |
importNamed(tree.pos(), c, env); |
|
636 |
} |
|
637 |
} |
|
638 |
} |
|
639 |
||
640 |
public void visitMethodDef(JCMethodDecl tree) { |
|
641 |
Scope enclScope = enter.enterScope(env); |
|
642 |
MethodSymbol m = new MethodSymbol(0, tree.name, null, enclScope.owner); |
|
643 |
m.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, m, tree); |
|
644 |
tree.sym = m; |
|
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
645 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
646 |
//if this is a default method, add the DEFAULT flag to the enclosing interface |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
647 |
if ((tree.mods.flags & DEFAULT) != 0) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
648 |
m.enclClass().flags_field |= DEFAULT; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
649 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
650 |
|
10 | 651 |
Env<AttrContext> localEnv = methodEnv(tree, env); |
652 |
||
21498
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
653 |
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
654 |
try { |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
655 |
// Compute the method type |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
656 |
m.type = signature(m, tree.typarams, tree.params, |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
657 |
tree.restype, tree.recvparam, |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
658 |
tree.thrown, localEnv, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
659 |
tree.mods.annotations, tree.pos()); |
21498
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
660 |
} finally { |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
661 |
deferredLintHandler.setPos(prevLintPos); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
662 |
} |
10 | 663 |
|
21498
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
664 |
if (types.isSignaturePolymorphic(m)) { |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
665 |
m.flags_field |= SIGNATURE_POLYMORPHIC; |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
666 |
} |
18389
a425d0819f36
8016569: javac, add new flag for polymorphic method signatures
vromero
parents:
18010
diff
changeset
|
667 |
|
21498
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
668 |
// Set m.params |
22163 | 669 |
ListBuffer<VarSymbol> params = new ListBuffer<>(); |
21498
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
670 |
JCVariableDecl lastParam = null; |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
671 |
for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
672 |
JCVariableDecl param = lastParam = l.head; |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
673 |
params.append(Assert.checkNonNull(param.sym)); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
674 |
} |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
675 |
m.params = params.toList(); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
676 |
|
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
677 |
// mark the method varargs, if necessary |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
678 |
if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0) |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
679 |
m.flags_field |= Flags.VARARGS; |
10 | 680 |
|
21498
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
681 |
localEnv.info.scope.leave(); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
682 |
if (chk.checkUnique(tree.pos(), m, enclScope)) { |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
683 |
enclScope.enter(m); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
684 |
} |
10 | 685 |
|
21498
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
686 |
if (tree.defaultValue != null) |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
687 |
annotateDefaultValueLater(tree.defaultValue, localEnv, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
688 |
m, annotate.noCreator); |
10 | 689 |
} |
690 |
||
691 |
/** Create a fresh environment for method bodies. |
|
692 |
* @param tree The method definition. |
|
693 |
* @param env The environment current outside of the method definition. |
|
694 |
*/ |
|
695 |
Env<AttrContext> methodEnv(JCMethodDecl tree, Env<AttrContext> env) { |
|
696 |
Env<AttrContext> localEnv = |
|
697 |
env.dup(tree, env.info.dup(env.info.scope.dupUnshared())); |
|
698 |
localEnv.enclMethod = tree; |
|
699 |
localEnv.info.scope.owner = tree.sym; |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
700 |
if (tree.sym.type != null) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
701 |
//when this is called in the enter stage, there's no type to be set |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
702 |
localEnv.info.returnResult = attr.new ResultInfo(VAL, tree.sym.type.getReturnType()); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
703 |
} |
10 | 704 |
if ((tree.mods.flags & STATIC) != 0) localEnv.info.staticLevel++; |
705 |
return localEnv; |
|
706 |
} |
|
707 |
||
708 |
public void visitVarDef(JCVariableDecl tree) { |
|
709 |
Env<AttrContext> localEnv = env; |
|
710 |
if ((tree.mods.flags & STATIC) != 0 || |
|
711 |
(env.info.scope.owner.flags() & INTERFACE) != 0) { |
|
712 |
localEnv = env.dup(tree, env.info.dup()); |
|
713 |
localEnv.info.staticLevel++; |
|
714 |
} |
|
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
715 |
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); |
21498
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
716 |
annotate.enterStart(); |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
717 |
try { |
21498
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
718 |
try { |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
719 |
if (TreeInfo.isEnumInit(tree)) { |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
720 |
attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
721 |
} else { |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
722 |
attr.attribType(tree.vartype, localEnv); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
723 |
if (tree.nameexpr != null) { |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
724 |
attr.attribExpr(tree.nameexpr, localEnv); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
725 |
MethodSymbol m = localEnv.enclMethod.sym; |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
726 |
if (m.isConstructor()) { |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
727 |
Type outertype = m.owner.owner.type; |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
728 |
if (outertype.hasTag(TypeTag.CLASS)) { |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
729 |
checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type"); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
730 |
checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name"); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
731 |
} else { |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
732 |
log.error(tree, "receiver.parameter.not.applicable.constructor.toplevel.class"); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
733 |
} |
17578 | 734 |
} else { |
21498
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
735 |
checkType(tree.vartype, m.owner.type, "incorrect.receiver.type"); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
736 |
checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name"); |
17578 | 737 |
} |
738 |
} |
|
739 |
} |
|
21498
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
740 |
} finally { |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
741 |
deferredLintHandler.setPos(prevLintPos); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
742 |
} |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
743 |
|
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
744 |
if ((tree.mods.flags & VARARGS) != 0) { |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
745 |
//if we are entering a varargs parameter, we need to |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
746 |
//replace its type (a plain array type) with the more |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
747 |
//precise VarargsType --- we need to do it this way |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
748 |
//because varargs is represented in the tree as a |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
749 |
//modifier on the parameter declaration, and not as a |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
750 |
//distinct type of array node. |
24396 | 751 |
ArrayType atype = (ArrayType)tree.vartype.type; |
21498
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
752 |
tree.vartype.type = atype.makeVarargs(); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
753 |
} |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
754 |
Scope enclScope = enter.enterScope(env); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
755 |
VarSymbol v = |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
756 |
new VarSymbol(0, tree.name, tree.vartype.type, enclScope.owner); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
757 |
v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
758 |
tree.sym = v; |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
759 |
if (tree.init != null) { |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
760 |
v.flags_field |= HASINIT; |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
761 |
if ((v.flags_field & FINAL) != 0 && |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
762 |
needsLazyConstValue(tree.init)) { |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
763 |
Env<AttrContext> initEnv = getInitEnv(tree, env); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
764 |
initEnv.info.enclVar = v; |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
765 |
v.setLazyConstValue(initEnv(tree, initEnv), attr, tree); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
766 |
} |
12916
021c069e8e27
7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents:
12335
diff
changeset
|
767 |
} |
21498
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
768 |
if (chk.checkUnique(tree.pos(), v, enclScope)) { |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
769 |
chk.checkTransparentVar(tree.pos(), v, enclScope); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
770 |
enclScope.enter(v); |
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
771 |
} |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
772 |
if (tree.name.equals(names._this)) { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
773 |
// If we are dealing with a receiver parameter, then |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
774 |
// we only allow base type annotations to be type |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
775 |
// annotations. Receivers are not allowed to have |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
776 |
// declaration annotations. |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
777 |
annotate.annotateStrictTypeLater(tree.vartype, tree.mods.annotations, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
778 |
localEnv, v, tree.pos(), creator); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
779 |
} else { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
780 |
// Otherwise, we annotate the type. |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
781 |
annotate.annotateTypeLater(tree.vartype, tree.mods.annotations, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
782 |
localEnv, v, tree.pos(), creator); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
783 |
} |
21498
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
784 |
v.pos = tree.pos; |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
785 |
} finally { |
21498
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
786 |
annotate.enterDone(); |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7615
diff
changeset
|
787 |
} |
10 | 788 |
} |
17578 | 789 |
// where |
790 |
void checkType(JCTree tree, Type type, String diag) { |
|
791 |
if (!tree.type.isErroneous() && !types.isSameType(tree.type, type)) { |
|
792 |
log.error(tree, diag, type, tree.type); |
|
793 |
} |
|
794 |
} |
|
10 | 795 |
|
19656
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
796 |
public boolean needsLazyConstValue(JCTree tree) { |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
797 |
InitTreeVisitor initTreeVisitor = new InitTreeVisitor(); |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
798 |
tree.accept(initTreeVisitor); |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
799 |
return initTreeVisitor.result; |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
800 |
} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
801 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
802 |
/** Visitor class for expressions which might be constant expressions. |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
803 |
*/ |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
804 |
static class InitTreeVisitor extends JCTree.Visitor { |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
805 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
806 |
private boolean result = true; |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
807 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
808 |
@Override |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
809 |
public void visitTree(JCTree tree) {} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
810 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
811 |
@Override |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
812 |
public void visitNewClass(JCNewClass that) { |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
813 |
result = false; |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
814 |
} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
815 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
816 |
@Override |
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
817 |
public void visitNewArray(JCNewArray that) { |
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
818 |
result = false; |
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
819 |
} |
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
820 |
|
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
821 |
@Override |
19656
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
822 |
public void visitLambda(JCLambda that) { |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
823 |
result = false; |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
824 |
} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
825 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
826 |
@Override |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
827 |
public void visitReference(JCMemberReference that) { |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
828 |
result = false; |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
829 |
} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
830 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
831 |
@Override |
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
832 |
public void visitApply(JCMethodInvocation that) { |
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
833 |
result = false; |
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
834 |
} |
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
835 |
|
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
836 |
@Override |
19656
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
837 |
public void visitSelect(JCFieldAccess tree) { |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
838 |
tree.selected.accept(this); |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
839 |
} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
840 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
841 |
@Override |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
842 |
public void visitConditional(JCConditional tree) { |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
843 |
tree.cond.accept(this); |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
844 |
tree.truepart.accept(this); |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
845 |
tree.falsepart.accept(this); |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
846 |
} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
847 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
848 |
@Override |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
849 |
public void visitParens(JCParens tree) { |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
850 |
tree.expr.accept(this); |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
851 |
} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
852 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
853 |
@Override |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
854 |
public void visitTypeCast(JCTypeCast tree) { |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
855 |
tree.expr.accept(this); |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
856 |
} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
857 |
} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
858 |
|
10 | 859 |
/** Create a fresh environment for a variable's initializer. |
860 |
* If the variable is a field, the owner of the environment's scope |
|
861 |
* is be the variable itself, otherwise the owner is the method |
|
862 |
* enclosing the variable definition. |
|
863 |
* |
|
864 |
* @param tree The variable definition. |
|
865 |
* @param env The environment current outside of the variable definition. |
|
866 |
*/ |
|
867 |
Env<AttrContext> initEnv(JCVariableDecl tree, Env<AttrContext> env) { |
|
868 |
Env<AttrContext> localEnv = env.dupto(new AttrContextEnv(tree, env.info.dup())); |
|
869 |
if (tree.sym.owner.kind == TYP) { |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
870 |
localEnv.info.scope = env.info.scope.dupUnshared(); |
10 | 871 |
localEnv.info.scope.owner = tree.sym; |
872 |
} |
|
873 |
if ((tree.mods.flags & STATIC) != 0 || |
|
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
874 |
((env.enclClass.sym.flags() & INTERFACE) != 0 && env.enclMethod == null)) |
10 | 875 |
localEnv.info.staticLevel++; |
876 |
return localEnv; |
|
877 |
} |
|
878 |
||
879 |
/** Default member enter visitor method: do nothing |
|
880 |
*/ |
|
881 |
public void visitTree(JCTree tree) { |
|
882 |
} |
|
883 |
||
884 |
public void visitErroneous(JCErroneous tree) { |
|
6929
81a6a7c1bef1
6988407: javac crashes running processor on errant code; it used to print error message
jjg
parents:
6721
diff
changeset
|
885 |
if (tree.errs != null) |
81a6a7c1bef1
6988407: javac crashes running processor on errant code; it used to print error message
jjg
parents:
6721
diff
changeset
|
886 |
memberEnter(tree.errs, env); |
10 | 887 |
} |
888 |
||
889 |
public Env<AttrContext> getMethodEnv(JCMethodDecl tree, Env<AttrContext> env) { |
|
890 |
Env<AttrContext> mEnv = methodEnv(tree, env); |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17999
diff
changeset
|
891 |
mEnv.info.lint = mEnv.info.lint.augment(tree.sym); |
10 | 892 |
for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail) |
893 |
mEnv.info.scope.enterIfAbsent(l.head.type.tsym); |
|
894 |
for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) |
|
895 |
mEnv.info.scope.enterIfAbsent(l.head.sym); |
|
896 |
return mEnv; |
|
897 |
} |
|
898 |
||
899 |
public Env<AttrContext> getInitEnv(JCVariableDecl tree, Env<AttrContext> env) { |
|
900 |
Env<AttrContext> iEnv = initEnv(tree, env); |
|
901 |
return iEnv; |
|
902 |
} |
|
903 |
||
904 |
/* ******************************************************************** |
|
905 |
* Type completion |
|
906 |
*********************************************************************/ |
|
907 |
||
908 |
Type attribImportType(JCTree tree, Env<AttrContext> env) { |
|
8032 | 909 |
Assert.check(completionEnabled); |
10 | 910 |
try { |
911 |
// To prevent deep recursion, suppress completion of some |
|
912 |
// types. |
|
913 |
completionEnabled = false; |
|
914 |
return attr.attribType(tree, env); |
|
915 |
} finally { |
|
916 |
completionEnabled = true; |
|
917 |
} |
|
918 |
} |
|
919 |
||
920 |
/** |
|
921 |
* Check if a list of annotations contains a reference to |
|
922 |
* java.lang.Deprecated. |
|
923 |
**/ |
|
924 |
private boolean hasDeprecatedAnnotation(List<JCAnnotation> annotations) { |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12917
diff
changeset
|
925 |
for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) { |
10 | 926 |
JCAnnotation a = al.head; |
927 |
if (a.annotationType.type == syms.deprecatedType && a.args.isEmpty()) |
|
928 |
return true; |
|
929 |
} |
|
930 |
return false; |
|
931 |
} |
|
932 |
||
933 |
/** Queue processing of an attribute default value. */ |
|
934 |
void annotateDefaultValueLater(final JCExpression defaultValue, |
|
935 |
final Env<AttrContext> localEnv, |
|
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
936 |
final MethodSymbol m, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
937 |
final Annotate.PositionCreator creator) { |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
938 |
annotate.normal(new Annotate.Worker() { |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12917
diff
changeset
|
939 |
@Override |
10 | 940 |
public String toString() { |
941 |
return "annotate " + m.owner + "." + |
|
942 |
m + " default " + defaultValue; |
|
943 |
} |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12917
diff
changeset
|
944 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12917
diff
changeset
|
945 |
@Override |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
946 |
public void run() { |
10 | 947 |
JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); |
948 |
try { |
|
949 |
enterDefaultValue(defaultValue, localEnv, m); |
|
950 |
} finally { |
|
951 |
log.useSource(prev); |
|
952 |
} |
|
953 |
} |
|
954 |
}); |
|
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
955 |
annotate.validate(new Annotate.Worker() { //validate annotations |
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
956 |
@Override |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
957 |
public void run() { |
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
958 |
JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
959 |
try { |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
960 |
// if default value is an annotation, check it is a well-formed |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
961 |
// annotation value (e.g. no duplicate values, no missing values, etc.) |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
962 |
chk.validateAnnotationTree(defaultValue); |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
963 |
} finally { |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
964 |
log.useSource(prev); |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
965 |
} |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
966 |
} |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
967 |
}); |
10 | 968 |
} |
969 |
||
970 |
/** Enter a default value for an attribute method. */ |
|
971 |
private void enterDefaultValue(final JCExpression defaultValue, |
|
972 |
final Env<AttrContext> localEnv, |
|
973 |
final MethodSymbol m) { |
|
974 |
m.defaultValue = annotate.enterAttributeValue(m.type.getReturnType(), |
|
975 |
defaultValue, |
|
976 |
localEnv); |
|
977 |
} |
|
978 |
||
979 |
/* ******************************************************************** |
|
980 |
* Source completer |
|
981 |
*********************************************************************/ |
|
982 |
||
983 |
/** Complete entering a class. |
|
984 |
* @param sym The symbol of the class to be completed. |
|
985 |
*/ |
|
986 |
public void complete(Symbol sym) throws CompletionFailure { |
|
987 |
// Suppress some (recursive) MemberEnter invocations |
|
988 |
if (!completionEnabled) { |
|
989 |
// Re-install same completer for next time around and return. |
|
8032 | 990 |
Assert.check((sym.flags() & Flags.COMPOUND) == 0); |
10 | 991 |
sym.completer = this; |
992 |
return; |
|
993 |
} |
|
994 |
||
995 |
ClassSymbol c = (ClassSymbol)sym; |
|
996 |
ClassType ct = (ClassType)c.type; |
|
997 |
Env<AttrContext> env = enter.typeEnvs.get(c); |
|
998 |
JCClassDecl tree = (JCClassDecl)env.tree; |
|
999 |
boolean wasFirst = isFirst; |
|
1000 |
isFirst = false; |
|
1001 |
||
1002 |
JavaFileObject prev = log.useSource(env.toplevel.sourcefile); |
|
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
1003 |
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); |
10 | 1004 |
try { |
1005 |
// Save class environment for later member enter (2) processing. |
|
1006 |
halfcompleted.append(env); |
|
1007 |
||
1043
11ea4773b0af
6695838: javac does not detect cyclic inheritance involving static inner classes after import clause
mcimadamore
parents:
1040
diff
changeset
|
1008 |
// Mark class as not yet attributed. |
11ea4773b0af
6695838: javac does not detect cyclic inheritance involving static inner classes after import clause
mcimadamore
parents:
1040
diff
changeset
|
1009 |
c.flags_field |= UNATTRIBUTED; |
11ea4773b0af
6695838: javac does not detect cyclic inheritance involving static inner classes after import clause
mcimadamore
parents:
1040
diff
changeset
|
1010 |
|
10 | 1011 |
// If this is a toplevel-class, make sure any preceding import |
1012 |
// clauses have been seen. |
|
1013 |
if (c.owner.kind == PCK) { |
|
10950 | 1014 |
memberEnter(env.toplevel, env.enclosing(TOPLEVEL)); |
10 | 1015 |
todo.append(env); |
1016 |
} |
|
1017 |
||
1018 |
if (c.owner.kind == TYP) |
|
1019 |
c.owner.complete(); |
|
1020 |
||
1021 |
// create an environment for evaluating the base clauses |
|
1022 |
Env<AttrContext> baseEnv = baseEnv(tree, env); |
|
1023 |
||
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1024 |
// Annotations. |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1025 |
// In general, we cannot fully process annotations yet, but we |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1026 |
// can attribute the annotation types and then check to see if the |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1027 |
// @Deprecated annotation is present. |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1028 |
attr.attribAnnotationTypes(tree.mods.annotations, baseEnv); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1029 |
if (hasDeprecatedAnnotation(tree.mods.annotations)) |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1030 |
c.flags_field |= DEPRECATED; |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1031 |
|
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1032 |
// Don't attach declaration annotations to anonymous |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1033 |
// classes, they get handled specially below. |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1034 |
if (!sym.isAnonymous()) { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1035 |
annotate.annotateLater(tree.mods.annotations, baseEnv, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1036 |
c, tree.pos()); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1037 |
} |
15385 | 1038 |
|
10 | 1039 |
// Determine supertype. |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1040 |
Type supertype; |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1041 |
|
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1042 |
if (tree.extending != null) { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1043 |
supertype = attr.attribBase(tree.extending, baseEnv, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1044 |
true, false, true); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1045 |
if (sym.isAnonymous()) { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1046 |
annotate.annotateAnonClassDefLater(tree.extending, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1047 |
tree.mods.annotations, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1048 |
baseEnv, sym, tree.pos(), |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1049 |
annotate.extendsCreator); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1050 |
} else { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1051 |
annotate.annotateTypeLater(tree.extending, baseEnv, sym, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1052 |
tree.pos(), annotate.extendsCreator); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1053 |
} |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1054 |
} else { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1055 |
supertype = ((tree.mods.flags & Flags.ENUM) != 0) |
10 | 1056 |
? attr.attribBase(enumBase(tree.pos, c), baseEnv, |
1057 |
true, false, false) |
|
1058 |
: (c.fullname == names.java_lang_Object) |
|
1059 |
? Type.noType |
|
1060 |
: syms.objectType; |
|
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1061 |
} |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1062 |
ct.supertype_field = modelMissingTypes(supertype, tree.extending, false); |
10 | 1063 |
|
1064 |
// Determine interfaces. |
|
22163 | 1065 |
ListBuffer<Type> interfaces = new ListBuffer<>(); |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1066 |
ListBuffer<Type> all_interfaces = null; // lazy init |
22163 | 1067 |
Set<Type> interfaceSet = new HashSet<>(); |
10 | 1068 |
List<JCExpression> interfaceTrees = tree.implementing; |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1069 |
int i = 0; |
10 | 1070 |
for (JCExpression iface : interfaceTrees) { |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1071 |
Type it = attr.attribBase(iface, baseEnv, false, true, true); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1072 |
if (it.hasTag(CLASS)) { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1073 |
interfaces.append(it); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1074 |
if (all_interfaces != null) all_interfaces.append(it); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1075 |
chk.checkNotRepeated(iface.pos(), types.erasure(it), interfaceSet); |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1076 |
} else { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1077 |
if (all_interfaces == null) |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1078 |
all_interfaces = new ListBuffer<Type>().appendList(interfaces); |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1079 |
all_interfaces.append(modelMissingTypes(it, iface, true)); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1080 |
|
10 | 1081 |
} |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1082 |
if (sym.isAnonymous()) { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1083 |
// Note: if an anonymous class ever has more than |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1084 |
// one supertype for some reason, this will |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1085 |
// incorrectly attach tree.mods.annotations to ALL |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1086 |
// supertypes, not just the first. |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1087 |
annotate.annotateAnonClassDefLater(iface, tree.mods.annotations, |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1088 |
baseEnv, sym, tree.pos(), |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1089 |
annotate.implementsCreator(i++)); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1090 |
} else { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1091 |
annotate.annotateTypeLater(iface, baseEnv, sym, tree.pos(), |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1092 |
annotate.implementsCreator(i++)); |
10 | 1093 |
} |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1094 |
} |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1095 |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1096 |
if ((c.flags_field & ANNOTATION) != 0) { |
10 | 1097 |
ct.interfaces_field = List.of(syms.annotationType); |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1098 |
ct.all_interfaces_field = ct.interfaces_field; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1099 |
} else { |
10 | 1100 |
ct.interfaces_field = interfaces.toList(); |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1101 |
ct.all_interfaces_field = (all_interfaces == null) |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1102 |
? ct.interfaces_field : all_interfaces.toList(); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1103 |
} |
10 | 1104 |
|
1105 |
if (c.fullname == names.java_lang_Object) { |
|
1106 |
if (tree.extending != null) { |
|
1107 |
chk.checkNonCyclic(tree.extending.pos(), |
|
1108 |
supertype); |
|
1109 |
ct.supertype_field = Type.noType; |
|
1110 |
} |
|
1111 |
else if (tree.implementing.nonEmpty()) { |
|
1112 |
chk.checkNonCyclic(tree.implementing.head.pos(), |
|
1113 |
ct.interfaces_field.head); |
|
1114 |
ct.interfaces_field = List.nil(); |
|
1115 |
} |
|
1116 |
} |
|
1117 |
||
15385 | 1118 |
// class type parameters use baseEnv but everything uses env |
10 | 1119 |
|
6711
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6709
diff
changeset
|
1120 |
chk.checkNonCyclicDecl(tree); |
10 | 1121 |
|
165
1875ac59896a
6663588: Compiler goes into infinite loop for Cyclic Inheritance test case
mcimadamore
parents:
10
diff
changeset
|
1122 |
attr.attribTypeVariables(tree.typarams, baseEnv); |
15385 | 1123 |
// Do this here, where we have the symbol. |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1124 |
int j = 0; |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1125 |
for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1126 |
l = l.tail, j++) { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1127 |
final JCTypeParameter typaram = l.head; |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1128 |
annotate.annotateTypeLater(typaram, baseEnv, sym, tree.pos(), |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1129 |
annotate.typeParamCreator(j)); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1130 |
|
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1131 |
int k = 0; |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1132 |
for(List<JCExpression> b = typaram.bounds; b.nonEmpty(); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1133 |
b = b.tail, k++) { |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1134 |
final JCExpression bound = b.head; |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1135 |
annotate.annotateTypeLater(bound, baseEnv, sym, tree.pos(), |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1136 |
annotate.typeParamBoundCreator(typaram, j, k)); |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1137 |
} |
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1138 |
|
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
1139 |
} |
10 | 1140 |
|
1141 |
// Add default constructor if needed. |
|
1142 |
if ((c.flags() & INTERFACE) == 0 && |
|
1143 |
!TreeInfo.hasConstructors(tree.defs)) { |
|
1144 |
List<Type> argtypes = List.nil(); |
|
1145 |
List<Type> typarams = List.nil(); |
|
1146 |
List<Type> thrown = List.nil(); |
|
1147 |
long ctorFlags = 0; |
|
1148 |
boolean based = false; |
|
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
1149 |
boolean addConstructor = true; |
17999
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1150 |
JCNewClass nc = null; |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1045
diff
changeset
|
1151 |
if (c.name.isEmpty()) { |
17999
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1152 |
nc = (JCNewClass)env.next.tree; |
10 | 1153 |
if (nc.constructor != null) { |
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
1154 |
addConstructor = nc.constructor.kind != ERR; |
10 | 1155 |
Type superConstrType = types.memberType(c.type, |
1156 |
nc.constructor); |
|
1157 |
argtypes = superConstrType.getParameterTypes(); |
|
1158 |
typarams = superConstrType.getTypeArguments(); |
|
1159 |
ctorFlags = nc.constructor.flags() & VARARGS; |
|
1160 |
if (nc.encl != null) { |
|
1161 |
argtypes = argtypes.prepend(nc.encl.type); |
|
1162 |
based = true; |
|
1163 |
} |
|
1164 |
thrown = superConstrType.getThrownTypes(); |
|
1165 |
} |
|
1166 |
} |
|
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
1167 |
if (addConstructor) { |
17999
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1168 |
MethodSymbol basedConstructor = nc != null ? |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1169 |
(MethodSymbol)nc.constructor : null; |
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
1170 |
JCTree constrDef = DefaultConstructor(make.at(tree.pos), c, |
17999
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1171 |
basedConstructor, |
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
1172 |
typarams, argtypes, thrown, |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
1173 |
ctorFlags, based); |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
1174 |
tree.defs = tree.defs.prepend(constrDef); |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
1175 |
} |
10 | 1176 |
} |
1177 |
||
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
1178 |
// enter symbols for 'this' into current scope. |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
1179 |
VarSymbol thisSym = |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
1180 |
new VarSymbol(FINAL | HASINIT, names._this, c.type, c); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
1181 |
thisSym.pos = Position.FIRSTPOS; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
1182 |
env.info.scope.enter(thisSym); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
1183 |
// if this is a class, enter symbol for 'super' into current scope. |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
1184 |
if ((c.flags_field & INTERFACE) == 0 && |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
1185 |
ct.supertype_field.hasTag(CLASS)) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
1186 |
VarSymbol superSym = |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
1187 |
new VarSymbol(FINAL | HASINIT, names._super, |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
1188 |
ct.supertype_field, c); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
1189 |
superSym.pos = Position.FIRSTPOS; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
1190 |
env.info.scope.enter(superSym); |
10 | 1191 |
} |
1192 |
||
1193 |
// check that no package exists with same fully qualified name, |
|
1194 |
// but admit classes in the unnamed package which have the same |
|
1195 |
// name as a top-level package. |
|
1196 |
if (checkClash && |
|
1197 |
c.owner.kind == PCK && c.owner != syms.unnamedPackage && |
|
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
1198 |
syms.packageExists(c.fullname)) { |
14369
3d660d08d1f7
7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents:
14359
diff
changeset
|
1199 |
log.error(tree.pos, "clash.with.pkg.of.same.name", Kinds.kindName(sym), c); |
3d660d08d1f7
7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents:
14359
diff
changeset
|
1200 |
} |
3d660d08d1f7
7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents:
14359
diff
changeset
|
1201 |
if (c.owner.kind == PCK && (c.flags_field & PUBLIC) == 0 && |
3d660d08d1f7
7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents:
14359
diff
changeset
|
1202 |
!env.toplevel.sourcefile.isNameCompatible(c.name.toString(),JavaFileObject.Kind.SOURCE)) { |
3d660d08d1f7
7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents:
14359
diff
changeset
|
1203 |
c.flags_field |= AUXILIARY; |
3d660d08d1f7
7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents:
14359
diff
changeset
|
1204 |
} |
10 | 1205 |
} catch (CompletionFailure ex) { |
1206 |
chk.completionError(tree.pos(), ex); |
|
1207 |
} finally { |
|
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
1208 |
deferredLintHandler.setPos(prevLintPos); |
10 | 1209 |
log.useSource(prev); |
1210 |
} |
|
1211 |
||
1212 |
// Enter all member fields and methods of a set of half completed |
|
1213 |
// classes in a second phase. |
|
1214 |
if (wasFirst) { |
|
1215 |
try { |
|
1216 |
while (halfcompleted.nonEmpty()) { |
|
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
1217 |
Env<AttrContext> toFinish = halfcompleted.next(); |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
1218 |
finish(toFinish); |
10 | 1219 |
} |
1220 |
} finally { |
|
1221 |
isFirst = true; |
|
1222 |
} |
|
15385 | 1223 |
} |
1224 |
} |
|
10 | 1225 |
|
1226 |
private Env<AttrContext> baseEnv(JCClassDecl tree, Env<AttrContext> env) { |
|
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8241
diff
changeset
|
1227 |
Scope baseScope = new Scope(tree.sym); |
6352
217d5a69681a
6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents:
5857
diff
changeset
|
1228 |
//import already entered local classes into base scope |
217d5a69681a
6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents:
5857
diff
changeset
|
1229 |
for (Scope.Entry e = env.outer.info.scope.elems ; e != null ; e = e.sibling) { |
217d5a69681a
6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents:
5857
diff
changeset
|
1230 |
if (e.sym.isLocal()) { |
217d5a69681a
6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents:
5857
diff
changeset
|
1231 |
baseScope.enter(e.sym); |
217d5a69681a
6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents:
5857
diff
changeset
|
1232 |
} |
217d5a69681a
6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents:
5857
diff
changeset
|
1233 |
} |
217d5a69681a
6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents:
5857
diff
changeset
|
1234 |
//import current type-parameters into base scope |
10 | 1235 |
if (tree.typarams != null) |
1236 |
for (List<JCTypeParameter> typarams = tree.typarams; |
|
1237 |
typarams.nonEmpty(); |
|
1238 |
typarams = typarams.tail) |
|
6352
217d5a69681a
6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents:
5857
diff
changeset
|
1239 |
baseScope.enter(typarams.head.type.tsym); |
10 | 1240 |
Env<AttrContext> outer = env.outer; // the base clause can't see members of this class |
6352
217d5a69681a
6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents:
5857
diff
changeset
|
1241 |
Env<AttrContext> localEnv = outer.dup(tree, outer.info.dup(baseScope)); |
10 | 1242 |
localEnv.baseClause = true; |
1243 |
localEnv.outer = outer; |
|
1244 |
localEnv.info.isSelfCall = false; |
|
1245 |
return localEnv; |
|
1246 |
} |
|
1247 |
||
1248 |
/** Enter member fields and methods of a class |
|
1249 |
* @param env the environment current for the class block. |
|
1250 |
*/ |
|
1251 |
private void finish(Env<AttrContext> env) { |
|
1252 |
JavaFileObject prev = log.useSource(env.toplevel.sourcefile); |
|
1253 |
try { |
|
1254 |
JCClassDecl tree = (JCClassDecl)env.tree; |
|
1255 |
finishClass(tree, env); |
|
1256 |
} finally { |
|
1257 |
log.useSource(prev); |
|
1258 |
} |
|
1259 |
} |
|
1260 |
||
1261 |
/** Generate a base clause for an enum type. |
|
1262 |
* @param pos The position for trees and diagnostics, if any |
|
1263 |
* @param c The class symbol of the enum |
|
1264 |
*/ |
|
1265 |
private JCExpression enumBase(int pos, ClassSymbol c) { |
|
1266 |
JCExpression result = make.at(pos). |
|
1267 |
TypeApply(make.QualIdent(syms.enumSym), |
|
1268 |
List.<JCExpression>of(make.Type(c.type))); |
|
1269 |
return result; |
|
1270 |
} |
|
1271 |
||
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1272 |
Type modelMissingTypes(Type t, final JCExpression tree, final boolean interfaceExpected) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1273 |
if (!t.hasTag(ERROR)) |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1274 |
return t; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1275 |
|
21015
f3bec12a63e7
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents:
21010
diff
changeset
|
1276 |
return new ErrorType(t.getOriginalType(), t.tsym) { |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1277 |
private Type modelType; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1278 |
|
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1279 |
@Override |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1280 |
public Type getModelType() { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1281 |
if (modelType == null) |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1282 |
modelType = new Synthesizer(getOriginalType(), interfaceExpected).visit(tree); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1283 |
return modelType; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1284 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1285 |
}; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1286 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1287 |
// where |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1288 |
private class Synthesizer extends JCTree.Visitor { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1289 |
Type originalType; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1290 |
boolean interfaceExpected; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1291 |
List<ClassSymbol> synthesizedSymbols = List.nil(); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1292 |
Type result; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1293 |
|
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1294 |
Synthesizer(Type originalType, boolean interfaceExpected) { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1295 |
this.originalType = originalType; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1296 |
this.interfaceExpected = interfaceExpected; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1297 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1298 |
|
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1299 |
Type visit(JCTree tree) { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1300 |
tree.accept(this); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1301 |
return result; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1302 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1303 |
|
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1304 |
List<Type> visit(List<? extends JCTree> trees) { |
22163 | 1305 |
ListBuffer<Type> lb = new ListBuffer<>(); |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1306 |
for (JCTree t: trees) |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1307 |
lb.append(visit(t)); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1308 |
return lb.toList(); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1309 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1310 |
|
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1311 |
@Override |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1312 |
public void visitTree(JCTree tree) { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1313 |
result = syms.errType; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1314 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1315 |
|
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1316 |
@Override |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1317 |
public void visitIdent(JCIdent tree) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1318 |
if (!tree.type.hasTag(ERROR)) { |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1319 |
result = tree.type; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1320 |
} else { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1321 |
result = synthesizeClass(tree.name, syms.unnamedPackage).type; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1322 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1323 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1324 |
|
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1325 |
@Override |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1326 |
public void visitSelect(JCFieldAccess tree) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1327 |
if (!tree.type.hasTag(ERROR)) { |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1328 |
result = tree.type; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1329 |
} else { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1330 |
Type selectedType; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1331 |
boolean prev = interfaceExpected; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1332 |
try { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1333 |
interfaceExpected = false; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1334 |
selectedType = visit(tree.selected); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1335 |
} finally { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1336 |
interfaceExpected = prev; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1337 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1338 |
ClassSymbol c = synthesizeClass(tree.name, selectedType.tsym); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1339 |
result = c.type; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1340 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1341 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1342 |
|
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1343 |
@Override |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1344 |
public void visitTypeApply(JCTypeApply tree) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1345 |
if (!tree.type.hasTag(ERROR)) { |
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1346 |
result = tree.type; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1347 |
} else { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1348 |
ClassType clazzType = (ClassType) visit(tree.clazz); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1349 |
if (synthesizedSymbols.contains(clazzType.tsym)) |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1350 |
synthesizeTyparams((ClassSymbol) clazzType.tsym, tree.arguments.size()); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1351 |
final List<Type> actuals = visit(tree.arguments); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1352 |
result = new ErrorType(tree.type, clazzType.tsym) { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1353 |
@Override |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1354 |
public List<Type> getTypeArguments() { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1355 |
return actuals; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1356 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1357 |
}; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1358 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1359 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1360 |
|
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1361 |
ClassSymbol synthesizeClass(Name name, Symbol owner) { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1362 |
int flags = interfaceExpected ? INTERFACE : 0; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1363 |
ClassSymbol c = new ClassSymbol(flags, name, owner); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1364 |
c.members_field = new Scope.ErrorScope(c); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1365 |
c.type = new ErrorType(originalType, c) { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1366 |
@Override |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1367 |
public List<Type> getTypeArguments() { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1368 |
return typarams_field; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1369 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1370 |
}; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1371 |
synthesizedSymbols = synthesizedSymbols.prepend(c); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1372 |
return c; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1373 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1374 |
|
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1375 |
void synthesizeTyparams(ClassSymbol sym, int n) { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1376 |
ClassType ct = (ClassType) sym.type; |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1377 |
Assert.check(ct.typarams_field.isEmpty()); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1378 |
if (n == 1) { |
24396 | 1379 |
TypeVar v = new TypeVar(names.fromString("T"), sym, syms.botType, |
1380 |
Type.noAnnotations); |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1381 |
ct.typarams_field = ct.typarams_field.prepend(v); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1382 |
} else { |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1383 |
for (int i = n; i > 0; i--) { |
24396 | 1384 |
TypeVar v = new TypeVar(names.fromString("T" + i), sym, |
1385 |
syms.botType, Type.noAnnotations); |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1386 |
ct.typarams_field = ct.typarams_field.prepend(v); |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1387 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1388 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1389 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1390 |
} |
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1391 |
|
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8242
diff
changeset
|
1392 |
|
10 | 1393 |
/* *************************************************************************** |
1394 |
* tree building |
|
1395 |
****************************************************************************/ |
|
1396 |
||
1397 |
/** Generate default constructor for given class. For classes different |
|
1398 |
* from java.lang.Object, this is: |
|
1399 |
* |
|
1400 |
* c(argtype_0 x_0, ..., argtype_n x_n) throws thrown { |
|
1401 |
* super(x_0, ..., x_n) |
|
1402 |
* } |
|
1403 |
* |
|
1404 |
* or, if based == true: |
|
1405 |
* |
|
1406 |
* c(argtype_0 x_0, ..., argtype_n x_n) throws thrown { |
|
1407 |
* x_0.super(x_1, ..., x_n) |
|
1408 |
* } |
|
1409 |
* |
|
1410 |
* @param make The tree factory. |
|
1411 |
* @param c The class owning the default constructor. |
|
1412 |
* @param argtypes The parameter types of the constructor. |
|
1413 |
* @param thrown The thrown exceptions of the constructor. |
|
1414 |
* @param based Is first parameter a this$n? |
|
1415 |
*/ |
|
1416 |
JCTree DefaultConstructor(TreeMaker make, |
|
1417 |
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
|
1418 |
MethodSymbol baseInit, |
10 | 1419 |
List<Type> typarams, |
1420 |
List<Type> argtypes, |
|
1421 |
List<Type> thrown, |
|
1422 |
long flags, |
|
1423 |
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
|
1424 |
JCTree result; |
10 | 1425 |
if ((c.flags() & ENUM) != 0 && |
16558
07c08ad4a700
8010179: Remove transitional target values from javac
darcy
parents:
15720
diff
changeset
|
1426 |
(types.supertype(c.type).tsym == syms.enumSym)) { |
10 | 1427 |
// constructors of true enums are private |
1428 |
flags = (flags & ~AccessFlags) | PRIVATE | GENERATEDCONSTR; |
|
1429 |
} else |
|
1430 |
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
|
1431 |
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
|
1432 |
flags |= ANONCONSTR; |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1433 |
} |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1434 |
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
|
1435 |
Type initType = typarams.nonEmpty() ? |
24396 | 1436 |
new ForAll(typarams, mType) : |
1437 |
mType; |
|
17999
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1438 |
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
|
1439 |
initType, c); |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1440 |
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
|
1441 |
argtypes, based); |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1442 |
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
|
1443 |
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
|
1444 |
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
|
1445 |
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
|
1446 |
} |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1447 |
result = make.MethodDef(init, make.Block(0, stats)); |
10 | 1448 |
return result; |
1449 |
} |
|
1450 |
||
17999
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1451 |
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
|
1452 |
TreeMaker make, |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1453 |
MethodSymbol baseInit, |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1454 |
MethodSymbol init, |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1455 |
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
|
1456 |
boolean based) { |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1457 |
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
|
1458 |
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
|
1459 |
if (based) { |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1460 |
/* 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
|
1461 |
* 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
|
1462 |
* |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1463 |
* 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
|
1464 |
* |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1465 |
* 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
|
1466 |
* 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
|
1467 |
* 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
|
1468 |
* 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
|
1469 |
*/ |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1470 |
initParams = List.nil(); |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19656
diff
changeset
|
1471 |
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
|
1472 |
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
|
1473 |
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
|
1474 |
} |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1475 |
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
|
1476 |
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
|
1477 |
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
|
1478 |
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
|
1479 |
while (baseInitParams.nonEmpty() && argTypesList.nonEmpty()) { |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19656
diff
changeset
|
1480 |
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
|
1481 |
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
|
1482 |
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
|
1483 |
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
|
1484 |
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
|
1485 |
} |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1486 |
} |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1487 |
return initParams; |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1488 |
} |
42ae6fe53718
8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
17578
diff
changeset
|
1489 |
|
10 | 1490 |
/** Generate call to superclass constructor. This is: |
1491 |
* |
|
1492 |
* super(id_0, ..., id_n) |
|
1493 |
* |
|
1494 |
* or, if based == true |
|
1495 |
* |
|
1496 |
* id_0.super(id_1,...,id_n) |
|
1497 |
* |
|
1498 |
* where id_0, ..., id_n are the names of the given parameters. |
|
1499 |
* |
|
1500 |
* @param make The tree factory |
|
1501 |
* @param params The parameters that need to be passed to super |
|
1502 |
* @param typarams The type parameters that need to be passed to super |
|
1503 |
* @param based Is first parameter a this$n? |
|
1504 |
*/ |
|
1505 |
JCExpressionStatement SuperCall(TreeMaker make, |
|
1506 |
List<Type> typarams, |
|
1507 |
List<JCVariableDecl> params, |
|
1508 |
boolean based) { |
|
1509 |
JCExpression meth; |
|
1510 |
if (based) { |
|
1511 |
meth = make.Select(make.Ident(params.head), names._super); |
|
1512 |
params = params.tail; |
|
1513 |
} else { |
|
1514 |
meth = make.Ident(names._super); |
|
1515 |
} |
|
1516 |
List<JCExpression> typeargs = typarams.nonEmpty() ? make.Types(typarams) : null; |
|
1517 |
return make.Exec(make.Apply(typeargs, meth, make.Idents(params))); |
|
1518 |
} |
|
1519 |
} |