author | pgovereau |
Tue, 17 Jun 2014 11:11:59 -0400 | |
changeset 25007 | eb097d3a68f5 |
parent 24604 | 7f68545b5128 |
child 25443 | 9187d77f2c64 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
2 |
* Copyright (c) 1999, 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 |
||
28 |
import java.util.*; |
|
29 |
import javax.tools.JavaFileObject; |
|
30 |
import javax.tools.JavaFileManager; |
|
31 |
||
32 |
import com.sun.tools.javac.code.*; |
|
7615 | 33 |
import com.sun.tools.javac.code.Scope.*; |
34 |
import com.sun.tools.javac.code.Symbol.*; |
|
35 |
import com.sun.tools.javac.code.Type.*; |
|
10 | 36 |
import com.sun.tools.javac.jvm.*; |
11314 | 37 |
import com.sun.tools.javac.main.Option.PkgInfo; |
10 | 38 |
import com.sun.tools.javac.tree.*; |
7615 | 39 |
import com.sun.tools.javac.tree.JCTree.*; |
10 | 40 |
import com.sun.tools.javac.util.*; |
41 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
|
42 |
import com.sun.tools.javac.util.List; |
|
43 |
||
44 |
||
45 |
import static com.sun.tools.javac.code.Flags.*; |
|
46 |
import static com.sun.tools.javac.code.Kinds.*; |
|
47 |
||
48 |
/** This class enters symbols for all encountered definitions into |
|
49 |
* the symbol table. The pass consists of two phases, organized as |
|
50 |
* follows: |
|
51 |
* |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
13844
diff
changeset
|
52 |
* <p>In the first phase, all class symbols are entered into their |
10 | 53 |
* enclosing scope, descending recursively down the tree for classes |
54 |
* which are members of other classes. The class symbols are given a |
|
55 |
* MemberEnter object as completer. |
|
56 |
* |
|
57 |
* <p>In the second phase classes are completed using |
|
58 |
* MemberEnter.complete(). Completion might occur on demand, but |
|
59 |
* any classes that are not completed that way will be eventually |
|
60 |
* completed by processing the `uncompleted' queue. Completion |
|
61 |
* entails (1) determination of a class's parameters, supertype and |
|
62 |
* interfaces, as well as (2) entering all symbols defined in the |
|
63 |
* class into its scope, with the exception of class symbols which |
|
64 |
* have been entered in phase 1. (2) depends on (1) having been |
|
65 |
* completed for a class and all its superclasses and enclosing |
|
66 |
* classes. That's why, after doing (1), we put classes in a |
|
67 |
* `halfcompleted' queue. Only when we have performed (1) for a class |
|
68 |
* and all it's superclasses and enclosing classes, we proceed to |
|
69 |
* (2). |
|
70 |
* |
|
71 |
* <p>Whereas the first phase is organized as a sweep through all |
|
72 |
* compiled syntax trees, the second phase is demand. Members of a |
|
73 |
* class are entered when the contents of a class are first |
|
74 |
* accessed. This is accomplished by installing completer objects in |
|
75 |
* class symbols for compiled classes which invoke the member-enter |
|
76 |
* phase for the corresponding class tree. |
|
77 |
* |
|
78 |
* <p>Classes migrate from one phase to the next via queues: |
|
79 |
* |
|
13844 | 80 |
* <pre>{@literal |
10 | 81 |
* class enter -> (Enter.uncompleted) --> member enter (1) |
82 |
* -> (MemberEnter.halfcompleted) --> member enter (2) |
|
83 |
* -> (Todo) --> attribute |
|
84 |
* (only for toplevel classes) |
|
13844 | 85 |
* }</pre> |
10 | 86 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
87 |
* <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
|
88 |
* If you write code that depends on this, you do so at your own risk. |
10 | 89 |
* This code and its internal interfaces are subject to change or |
90 |
* deletion without notice.</b> |
|
91 |
*/ |
|
92 |
public class Enter extends JCTree.Visitor { |
|
22163 | 93 |
protected static final Context.Key<Enter> enterKey = new Context.Key<>(); |
10 | 94 |
|
95 |
Log log; |
|
96 |
Symtab syms; |
|
97 |
Check chk; |
|
98 |
TreeMaker make; |
|
99 |
Annotate annotate; |
|
100 |
MemberEnter memberEnter; |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
101 |
Types types; |
10 | 102 |
Lint lint; |
4871
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
1264
diff
changeset
|
103 |
Names names; |
10 | 104 |
JavaFileManager fileManager; |
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
105 |
PkgInfo pkginfoOpt; |
25007 | 106 |
TypeEnvs typeEnvs; |
10 | 107 |
|
108 |
private final Todo todo; |
|
109 |
||
110 |
public static Enter instance(Context context) { |
|
111 |
Enter instance = context.get(enterKey); |
|
112 |
if (instance == null) |
|
113 |
instance = new Enter(context); |
|
114 |
return instance; |
|
115 |
} |
|
116 |
||
117 |
protected Enter(Context context) { |
|
118 |
context.put(enterKey, this); |
|
119 |
||
120 |
log = Log.instance(context); |
|
121 |
make = TreeMaker.instance(context); |
|
122 |
syms = Symtab.instance(context); |
|
123 |
chk = Check.instance(context); |
|
124 |
memberEnter = MemberEnter.instance(context); |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
125 |
types = Types.instance(context); |
10 | 126 |
annotate = Annotate.instance(context); |
127 |
lint = Lint.instance(context); |
|
4871
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
1264
diff
changeset
|
128 |
names = Names.instance(context); |
10 | 129 |
|
130 |
predefClassDef = make.ClassDef( |
|
131 |
make.Modifiers(PUBLIC), |
|
15354 | 132 |
syms.predefClass.name, |
133 |
List.<JCTypeParameter>nil(), |
|
134 |
null, |
|
135 |
List.<JCExpression>nil(), |
|
136 |
List.<JCTree>nil()); |
|
10 | 137 |
predefClassDef.sym = syms.predefClass; |
138 |
todo = Todo.instance(context); |
|
139 |
fileManager = context.get(JavaFileManager.class); |
|
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
140 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
141 |
Options options = Options.instance(context); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
142 |
pkginfoOpt = PkgInfo.get(options); |
25007 | 143 |
typeEnvs = TypeEnvs.instance(context); |
10 | 144 |
} |
145 |
||
146 |
/** Accessor for typeEnvs |
|
147 |
*/ |
|
148 |
public Env<AttrContext> getEnv(TypeSymbol sym) { |
|
149 |
return typeEnvs.get(sym); |
|
150 |
} |
|
151 |
||
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
22442
diff
changeset
|
152 |
public Iterable<Env<AttrContext>> getEnvs() { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
22442
diff
changeset
|
153 |
return typeEnvs.values(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
22442
diff
changeset
|
154 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
22442
diff
changeset
|
155 |
|
10 | 156 |
public Env<AttrContext> getClassEnv(TypeSymbol sym) { |
157 |
Env<AttrContext> localEnv = getEnv(sym); |
|
158 |
Env<AttrContext> lintEnv = localEnv; |
|
159 |
while (lintEnv.info.lint == null) |
|
160 |
lintEnv = lintEnv.next; |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
15354
diff
changeset
|
161 |
localEnv.info.lint = lintEnv.info.lint.augment(sym); |
10 | 162 |
return localEnv; |
163 |
} |
|
164 |
||
165 |
/** The queue of all classes that might still need to be completed; |
|
166 |
* saved and initialized by main(). |
|
167 |
*/ |
|
168 |
ListBuffer<ClassSymbol> uncompleted; |
|
169 |
||
170 |
/** A dummy class to serve as enclClass for toplevel environments. |
|
171 |
*/ |
|
172 |
private JCClassDecl predefClassDef; |
|
173 |
||
174 |
/* ************************************************************************ |
|
175 |
* environment construction |
|
176 |
*************************************************************************/ |
|
177 |
||
178 |
||
179 |
/** Create a fresh environment for class bodies. |
|
180 |
* This will create a fresh scope for local symbols of a class, referred |
|
181 |
* to by the environments info.scope field. |
|
182 |
* This scope will contain |
|
183 |
* - symbols for this and super |
|
184 |
* - symbols for any type parameters |
|
185 |
* In addition, it serves as an anchor for scopes of methods and initializers |
|
186 |
* which are nested in this scope via Scope.dup(). |
|
187 |
* This scope should not be confused with the members scope of a class. |
|
188 |
* |
|
189 |
* @param tree The class definition. |
|
190 |
* @param env The environment current outside of the class definition. |
|
191 |
*/ |
|
192 |
public Env<AttrContext> classEnv(JCClassDecl tree, Env<AttrContext> env) { |
|
193 |
Env<AttrContext> localEnv = |
|
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
7681
diff
changeset
|
194 |
env.dup(tree, env.info.dup(new Scope(tree.sym))); |
10 | 195 |
localEnv.enclClass = tree; |
196 |
localEnv.outer = env; |
|
197 |
localEnv.info.isSelfCall = false; |
|
198 |
localEnv.info.lint = null; // leave this to be filled in by Attr, |
|
199 |
// when annotations have been processed |
|
200 |
return localEnv; |
|
201 |
} |
|
202 |
||
203 |
/** Create a fresh environment for toplevels. |
|
204 |
* @param tree The toplevel tree. |
|
205 |
*/ |
|
206 |
Env<AttrContext> topLevelEnv(JCCompilationUnit tree) { |
|
22163 | 207 |
Env<AttrContext> localEnv = new Env<>(tree, new AttrContext()); |
10 | 208 |
localEnv.toplevel = tree; |
209 |
localEnv.enclClass = predefClassDef; |
|
7615 | 210 |
tree.namedImportScope = new ImportScope(tree.packge); |
211 |
tree.starImportScope = new StarImportScope(tree.packge); |
|
10 | 212 |
localEnv.info.scope = tree.namedImportScope; |
213 |
localEnv.info.lint = lint; |
|
214 |
return localEnv; |
|
215 |
} |
|
216 |
||
217 |
public Env<AttrContext> getTopLevelEnv(JCCompilationUnit tree) { |
|
22163 | 218 |
Env<AttrContext> localEnv = new Env<>(tree, new AttrContext()); |
10 | 219 |
localEnv.toplevel = tree; |
220 |
localEnv.enclClass = predefClassDef; |
|
221 |
localEnv.info.scope = tree.namedImportScope; |
|
222 |
localEnv.info.lint = lint; |
|
223 |
return localEnv; |
|
224 |
} |
|
225 |
||
226 |
/** The scope in which a member definition in environment env is to be entered |
|
227 |
* This is usually the environment's scope, except for class environments, |
|
228 |
* where the local scope is for type variables, and the this and super symbol |
|
229 |
* only, and members go into the class member scope. |
|
230 |
*/ |
|
231 |
Scope enterScope(Env<AttrContext> env) { |
|
10950 | 232 |
return (env.tree.hasTag(JCTree.Tag.CLASSDEF)) |
10 | 233 |
? ((JCClassDecl) env.tree).sym.members_field |
234 |
: env.info.scope; |
|
235 |
} |
|
236 |
||
237 |
/* ************************************************************************ |
|
238 |
* Visitor methods for phase 1: class enter |
|
239 |
*************************************************************************/ |
|
240 |
||
241 |
/** Visitor argument: the current environment. |
|
242 |
*/ |
|
243 |
protected Env<AttrContext> env; |
|
244 |
||
245 |
/** Visitor result: the computed type. |
|
246 |
*/ |
|
247 |
Type result; |
|
248 |
||
249 |
/** Visitor method: enter all classes in given tree, catching any |
|
250 |
* completion failure exceptions. Return the tree's type. |
|
251 |
* |
|
252 |
* @param tree The tree to be visited. |
|
253 |
* @param env The environment visitor argument. |
|
254 |
*/ |
|
255 |
Type classEnter(JCTree tree, Env<AttrContext> env) { |
|
256 |
Env<AttrContext> prevEnv = this.env; |
|
257 |
try { |
|
258 |
this.env = env; |
|
259 |
tree.accept(this); |
|
260 |
return result; |
|
261 |
} catch (CompletionFailure ex) { |
|
262 |
return chk.completionError(tree.pos(), ex); |
|
263 |
} finally { |
|
264 |
this.env = prevEnv; |
|
265 |
} |
|
266 |
} |
|
267 |
||
268 |
/** Visitor method: enter classes of a list of trees, returning a list of types. |
|
269 |
*/ |
|
270 |
<T extends JCTree> List<Type> classEnter(List<T> trees, Env<AttrContext> env) { |
|
22163 | 271 |
ListBuffer<Type> ts = new ListBuffer<>(); |
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
10
diff
changeset
|
272 |
for (List<T> l = trees; l.nonEmpty(); l = l.tail) { |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
10
diff
changeset
|
273 |
Type t = classEnter(l.head, env); |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
10
diff
changeset
|
274 |
if (t != null) |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
10
diff
changeset
|
275 |
ts.append(t); |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
10
diff
changeset
|
276 |
} |
10 | 277 |
return ts.toList(); |
278 |
} |
|
279 |
||
5008
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4871
diff
changeset
|
280 |
@Override |
10 | 281 |
public void visitTopLevel(JCCompilationUnit tree) { |
282 |
JavaFileObject prev = log.useSource(tree.sourcefile); |
|
283 |
boolean addEnv = false; |
|
284 |
boolean isPkgInfo = tree.sourcefile.isNameCompatible("package-info", |
|
285 |
JavaFileObject.Kind.SOURCE); |
|
24069 | 286 |
JCPackageDecl pd = tree.getPackage(); |
287 |
if (pd != null) { |
|
288 |
tree.packge = pd.packge = syms.enterPackage(TreeInfo.fullName(pd.pid)); |
|
289 |
if ( pd.annotations.nonEmpty() |
|
290 |
|| pkginfoOpt == PkgInfo.ALWAYS |
|
291 |
|| tree.docComments != null) { |
|
10 | 292 |
if (isPkgInfo) { |
293 |
addEnv = true; |
|
24069 | 294 |
} else if (pd.annotations.nonEmpty()) { |
295 |
log.error(pd.annotations.head.pos(), |
|
10 | 296 |
"pkg.annotations.sb.in.package-info.java"); |
297 |
} |
|
298 |
} |
|
299 |
} else { |
|
300 |
tree.packge = syms.unnamedPackage; |
|
301 |
} |
|
302 |
tree.packge.complete(); // Find all classes in package. |
|
5008
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4871
diff
changeset
|
303 |
Env<AttrContext> topEnv = topLevelEnv(tree); |
24069 | 304 |
Env<AttrContext> packageEnv = isPkgInfo ? topEnv.dup(pd) : null; |
10 | 305 |
|
306 |
// Save environment of package-info.java file. |
|
307 |
if (isPkgInfo) { |
|
308 |
Env<AttrContext> env0 = typeEnvs.get(tree.packge); |
|
24069 | 309 |
if (env0 != null) { |
10 | 310 |
JCCompilationUnit tree0 = env0.toplevel; |
311 |
if (!fileManager.isSameFile(tree.sourcefile, tree0.sourcefile)) { |
|
24069 | 312 |
log.warning(pd != null ? pd.pid.pos() : null, |
10 | 313 |
"pkg-info.already.seen", |
314 |
tree.packge); |
|
315 |
} |
|
316 |
} |
|
24069 | 317 |
typeEnvs.put(tree.packge, packageEnv); |
4871
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
1264
diff
changeset
|
318 |
|
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
1264
diff
changeset
|
319 |
for (Symbol q = tree.packge; q != null && q.kind == PCK; q = q.owner) |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
1264
diff
changeset
|
320 |
q.flags_field |= EXISTS; |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
1264
diff
changeset
|
321 |
|
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
1264
diff
changeset
|
322 |
Name name = names.package_info; |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
323 |
ClassSymbol c = syms.enterClass(name, tree.packge); |
4871
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
1264
diff
changeset
|
324 |
c.flatname = names.fromString(tree.packge + "." + name); |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
1264
diff
changeset
|
325 |
c.sourcefile = tree.sourcefile; |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
1264
diff
changeset
|
326 |
c.completer = null; |
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
7681
diff
changeset
|
327 |
c.members_field = new Scope(c); |
4871
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
1264
diff
changeset
|
328 |
tree.packge.package_info = c; |
10 | 329 |
} |
5008
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4871
diff
changeset
|
330 |
classEnter(tree.defs, topEnv); |
10 | 331 |
if (addEnv) { |
24069 | 332 |
todo.append(packageEnv); |
10 | 333 |
} |
334 |
log.useSource(prev); |
|
335 |
result = null; |
|
336 |
} |
|
337 |
||
5008
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4871
diff
changeset
|
338 |
@Override |
10 | 339 |
public void visitClassDef(JCClassDecl tree) { |
340 |
Symbol owner = env.info.scope.owner; |
|
341 |
Scope enclScope = enterScope(env); |
|
342 |
ClassSymbol c; |
|
343 |
if (owner.kind == PCK) { |
|
344 |
// We are seeing a toplevel class. |
|
345 |
PackageSymbol packge = (PackageSymbol)owner; |
|
346 |
for (Symbol q = packge; q != null && q.kind == PCK; q = q.owner) |
|
347 |
q.flags_field |= EXISTS; |
|
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
348 |
c = syms.enterClass(tree.name, packge); |
10 | 349 |
packge.members().enterIfAbsent(c); |
350 |
if ((tree.mods.flags & PUBLIC) != 0 && !classNameMatchesFileName(c, env)) { |
|
351 |
log.error(tree.pos(), |
|
352 |
"class.public.should.be.in.file", tree.name); |
|
353 |
} |
|
354 |
} else { |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
355 |
if (!tree.name.isEmpty() && |
10 | 356 |
!chk.checkUniqueClassName(tree.pos(), tree.name, enclScope)) { |
357 |
result = null; |
|
358 |
return; |
|
359 |
} |
|
360 |
if (owner.kind == TYP) { |
|
361 |
// We are seeing a member class. |
|
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
362 |
c = syms.enterClass(tree.name, (TypeSymbol)owner); |
10 | 363 |
if ((owner.flags_field & INTERFACE) != 0) { |
364 |
tree.mods.flags |= PUBLIC | STATIC; |
|
365 |
} |
|
366 |
} else { |
|
367 |
// We are seeing a local class. |
|
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
368 |
c = syms.defineClass(tree.name, owner); |
10 | 369 |
c.flatname = chk.localClassName(c); |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
370 |
if (!c.name.isEmpty()) |
10 | 371 |
chk.checkTransparentClass(tree.pos(), c, env.info.scope); |
372 |
} |
|
373 |
} |
|
374 |
tree.sym = c; |
|
375 |
||
376 |
// Enter class into `compiled' table and enclosing scope. |
|
377 |
if (chk.compiled.get(c.flatname) != null) { |
|
378 |
duplicateClass(tree.pos(), c); |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
379 |
result = types.createErrorType(tree.name, (TypeSymbol)owner, Type.noType); |
10 | 380 |
tree.sym = (ClassSymbol)result.tsym; |
381 |
return; |
|
382 |
} |
|
383 |
chk.compiled.put(c.flatname, c); |
|
384 |
enclScope.enter(c); |
|
385 |
||
386 |
// Set up an environment for class block and store in `typeEnvs' |
|
387 |
// table, to be retrieved later in memberEnter and attribution. |
|
388 |
Env<AttrContext> localEnv = classEnv(tree, env); |
|
389 |
typeEnvs.put(c, localEnv); |
|
390 |
||
391 |
// Fill out class fields. |
|
392 |
c.completer = memberEnter; |
|
393 |
c.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, c, tree); |
|
394 |
c.sourcefile = env.toplevel.sourcefile; |
|
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
7681
diff
changeset
|
395 |
c.members_field = new Scope(c); |
10 | 396 |
|
397 |
ClassType ct = (ClassType)c.type; |
|
398 |
if (owner.kind != PCK && (c.flags_field & STATIC) == 0) { |
|
399 |
// We are seeing a local or inner class. |
|
400 |
// Set outer_field of this class to closest enclosing class |
|
401 |
// which contains this class in a non-static context |
|
402 |
// (its "enclosing instance class"), provided such a class exists. |
|
403 |
Symbol owner1 = owner; |
|
404 |
while ((owner1.kind & (VAR | MTH)) != 0 && |
|
405 |
(owner1.flags_field & STATIC) == 0) { |
|
406 |
owner1 = owner1.owner; |
|
407 |
} |
|
408 |
if (owner1.kind == TYP) { |
|
409 |
ct.setEnclosingType(owner1.type); |
|
410 |
} |
|
411 |
} |
|
412 |
||
413 |
// Enter type parameters. |
|
414 |
ct.typarams_field = classEnter(tree.typarams, localEnv); |
|
415 |
||
416 |
// Add non-local class to uncompleted, to make sure it will be |
|
417 |
// completed later. |
|
418 |
if (!c.isLocal() && uncompleted != null) uncompleted.append(c); |
|
419 |
// System.err.println("entering " + c.fullname + " in " + c.owner);//DEBUG |
|
420 |
||
421 |
// Recursively enter all member classes. |
|
422 |
classEnter(tree.defs, localEnv); |
|
423 |
||
424 |
result = c.type; |
|
425 |
} |
|
426 |
//where |
|
427 |
/** Does class have the same name as the file it appears in? |
|
428 |
*/ |
|
429 |
private static boolean classNameMatchesFileName(ClassSymbol c, |
|
430 |
Env<AttrContext> env) { |
|
431 |
return env.toplevel.sourcefile.isNameCompatible(c.name.toString(), |
|
432 |
JavaFileObject.Kind.SOURCE); |
|
433 |
} |
|
434 |
||
435 |
/** Complain about a duplicate class. */ |
|
436 |
protected void duplicateClass(DiagnosticPosition pos, ClassSymbol c) { |
|
437 |
log.error(pos, "duplicate.class", c.fullname); |
|
438 |
} |
|
439 |
||
440 |
/** Class enter visitor method for type parameters. |
|
441 |
* Enter a symbol for type parameter in local scope, after checking that it |
|
442 |
* is unique. |
|
443 |
*/ |
|
5008
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4871
diff
changeset
|
444 |
@Override |
10 | 445 |
public void visitTypeParameter(JCTypeParameter tree) { |
446 |
TypeVar a = (tree.type != null) |
|
447 |
? (TypeVar)tree.type |
|
448 |
: new TypeVar(tree.name, env.info.scope.owner, syms.botType); |
|
449 |
tree.type = a; |
|
450 |
if (chk.checkUnique(tree.pos(), a.tsym, env.info.scope)) { |
|
451 |
env.info.scope.enter(a.tsym); |
|
452 |
} |
|
453 |
result = a; |
|
454 |
} |
|
455 |
||
456 |
/** Default class enter visitor method: do nothing. |
|
457 |
*/ |
|
5008
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4871
diff
changeset
|
458 |
@Override |
10 | 459 |
public void visitTree(JCTree tree) { |
460 |
result = null; |
|
461 |
} |
|
462 |
||
463 |
/** Main method: enter all classes in a list of toplevel trees. |
|
464 |
* @param trees The list of trees to be processed. |
|
465 |
*/ |
|
466 |
public void main(List<JCCompilationUnit> trees) { |
|
467 |
complete(trees, null); |
|
468 |
} |
|
469 |
||
470 |
/** Main method: enter one class from a list of toplevel trees and |
|
471 |
* place the rest on uncompleted for later processing. |
|
472 |
* @param trees The list of trees to be processed. |
|
473 |
* @param c The class symbol to be processed. |
|
474 |
*/ |
|
475 |
public void complete(List<JCCompilationUnit> trees, ClassSymbol c) { |
|
476 |
annotate.enterStart(); |
|
477 |
ListBuffer<ClassSymbol> prevUncompleted = uncompleted; |
|
22163 | 478 |
if (memberEnter.completionEnabled) uncompleted = new ListBuffer<>(); |
10 | 479 |
|
480 |
try { |
|
481 |
// enter all classes, and construct uncompleted list |
|
482 |
classEnter(trees, null); |
|
483 |
||
484 |
// complete all uncompleted classes in memberEnter |
|
485 |
if (memberEnter.completionEnabled) { |
|
486 |
while (uncompleted.nonEmpty()) { |
|
487 |
ClassSymbol clazz = uncompleted.next(); |
|
488 |
if (c == null || c == clazz || prevUncompleted == null) |
|
489 |
clazz.complete(); |
|
490 |
else |
|
491 |
// defer |
|
492 |
prevUncompleted.append(clazz); |
|
493 |
} |
|
494 |
||
495 |
// if there remain any unimported toplevels (these must have |
|
496 |
// no classes at all), process their import statements as well. |
|
497 |
for (JCCompilationUnit tree : trees) { |
|
498 |
if (tree.starImportScope.elems == null) { |
|
499 |
JavaFileObject prev = log.useSource(tree.sourcefile); |
|
5008
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4871
diff
changeset
|
500 |
Env<AttrContext> topEnv = topLevelEnv(tree); |
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4871
diff
changeset
|
501 |
memberEnter.memberEnter(tree, topEnv); |
10 | 502 |
log.useSource(prev); |
503 |
} |
|
504 |
} |
|
505 |
} |
|
506 |
} finally { |
|
507 |
uncompleted = prevUncompleted; |
|
508 |
annotate.enterDone(); |
|
509 |
} |
|
510 |
} |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
22442
diff
changeset
|
511 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
22442
diff
changeset
|
512 |
public void newRound() { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
22442
diff
changeset
|
513 |
typeEnvs.clear(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
22442
diff
changeset
|
514 |
} |
10 | 515 |
} |