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