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