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