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