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