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