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