author | jjg |
Fri, 26 Jun 2009 19:47:12 -0700 | |
changeset 3151 | 41800a86aad3 |
parent 2984 | e15ff3a34054 |
child 3557 | a803afefa115 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
2212 | 2 |
* Copyright 1999-2009 Sun Microsystems, Inc. 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 |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
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 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.tools.javac.main; |
|
27 |
||
28 |
import java.io.*; |
|
29 |
import java.util.HashSet; |
|
1046
e395ce284cbf
6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents:
936
diff
changeset
|
30 |
import java.util.LinkedHashSet; |
10 | 31 |
import java.util.LinkedHashMap; |
32 |
import java.util.Map; |
|
33 |
import java.util.MissingResourceException; |
|
34 |
import java.util.ResourceBundle; |
|
35 |
import java.util.Set; |
|
36 |
import java.util.logging.Handler; |
|
37 |
import java.util.logging.Level; |
|
38 |
import java.util.logging.Logger; |
|
39 |
||
40 |
import javax.tools.JavaFileManager; |
|
41 |
import javax.tools.JavaFileObject; |
|
42 |
import javax.tools.DiagnosticListener; |
|
43 |
||
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
44 |
import com.sun.tools.javac.file.JavacFileManager; |
10 | 45 |
import com.sun.source.util.TaskEvent; |
46 |
import com.sun.source.util.TaskListener; |
|
47 |
||
48 |
import com.sun.tools.javac.util.*; |
|
49 |
import com.sun.tools.javac.code.*; |
|
50 |
import com.sun.tools.javac.tree.*; |
|
51 |
import com.sun.tools.javac.parser.*; |
|
52 |
import com.sun.tools.javac.comp.*; |
|
53 |
import com.sun.tools.javac.jvm.*; |
|
54 |
||
55 |
import com.sun.tools.javac.code.Symbol.*; |
|
56 |
import com.sun.tools.javac.tree.JCTree.*; |
|
57 |
||
58 |
import com.sun.tools.javac.processing.*; |
|
59 |
import javax.annotation.processing.Processor; |
|
60 |
||
61 |
import static javax.tools.StandardLocation.CLASS_OUTPUT; |
|
62 |
import static com.sun.tools.javac.util.ListBuffer.lb; |
|
63 |
||
64 |
// TEMP, until we have a more efficient way to save doc comment info |
|
65 |
import com.sun.tools.javac.parser.DocCommentScanner; |
|
66 |
||
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
67 |
import java.util.HashMap; |
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
68 |
import java.util.Queue; |
10 | 69 |
import javax.lang.model.SourceVersion; |
70 |
||
71 |
/** This class could be the main entry point for GJC when GJC is used as a |
|
72 |
* component in a larger software system. It provides operations to |
|
73 |
* construct a new compiler, and to run a new compiler on a set of source |
|
74 |
* files. |
|
75 |
* |
|
76 |
* <p><b>This is NOT part of any API supported by Sun Microsystems. If |
|
77 |
* you write code that depends on this, you do so at your own risk. |
|
78 |
* This code and its internal interfaces are subject to change or |
|
79 |
* deletion without notice.</b> |
|
80 |
*/ |
|
81 |
public class JavaCompiler implements ClassReader.SourceCompleter { |
|
82 |
/** The context key for the compiler. */ |
|
83 |
protected static final Context.Key<JavaCompiler> compilerKey = |
|
84 |
new Context.Key<JavaCompiler>(); |
|
85 |
||
86 |
/** Get the JavaCompiler instance for this context. */ |
|
87 |
public static JavaCompiler instance(Context context) { |
|
88 |
JavaCompiler instance = context.get(compilerKey); |
|
89 |
if (instance == null) |
|
90 |
instance = new JavaCompiler(context); |
|
91 |
return instance; |
|
92 |
} |
|
93 |
||
94 |
/** The current version number as a string. |
|
95 |
*/ |
|
96 |
public static String version() { |
|
97 |
return version("release"); // mm.nn.oo[-milestone] |
|
98 |
} |
|
99 |
||
100 |
/** The current full version number as a string. |
|
101 |
*/ |
|
102 |
public static String fullVersion() { |
|
103 |
return version("full"); // mm.mm.oo[-milestone]-build |
|
104 |
} |
|
105 |
||
106 |
private static final String versionRBName = "com.sun.tools.javac.resources.version"; |
|
107 |
private static ResourceBundle versionRB; |
|
108 |
||
109 |
private static String version(String key) { |
|
110 |
if (versionRB == null) { |
|
111 |
try { |
|
112 |
versionRB = ResourceBundle.getBundle(versionRBName); |
|
113 |
} catch (MissingResourceException e) { |
|
114 |
return Log.getLocalizedString("version.resource.missing", System.getProperty("java.version")); |
|
115 |
} |
|
116 |
} |
|
117 |
try { |
|
118 |
return versionRB.getString(key); |
|
119 |
} |
|
120 |
catch (MissingResourceException e) { |
|
121 |
return Log.getLocalizedString("version.unknown", System.getProperty("java.version")); |
|
122 |
} |
|
123 |
} |
|
124 |
||
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
125 |
/** |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
126 |
* Control how the compiler's latter phases (attr, flow, desugar, generate) |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
127 |
* are connected. Each individual file is processed by each phase in turn, |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
128 |
* but with different compile policies, you can control the order in which |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
129 |
* each class is processed through its next phase. |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
130 |
* |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
131 |
* <p>Generally speaking, the compiler will "fail fast" in the face of |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
132 |
* errors, although not aggressively so. flow, desugar, etc become no-ops |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
133 |
* once any errors have occurred. No attempt is currently made to determine |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
134 |
* if it might be safe to process a class through its next phase because |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
135 |
* it does not depend on any unrelated errors that might have occurred. |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
136 |
*/ |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
137 |
protected static enum CompilePolicy { |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
138 |
/** |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
139 |
* Just attribute the parse trees. |
10 | 140 |
*/ |
141 |
ATTR_ONLY, |
|
142 |
||
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
143 |
/** |
10 | 144 |
* Just attribute and do flow analysis on the parse trees. |
145 |
* This should catch most user errors. |
|
146 |
*/ |
|
147 |
CHECK_ONLY, |
|
148 |
||
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
149 |
/** |
10 | 150 |
* Attribute everything, then do flow analysis for everything, |
151 |
* then desugar everything, and only then generate output. |
|
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
152 |
* This means no output will be generated if there are any |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
153 |
* errors in any classes. |
10 | 154 |
*/ |
155 |
SIMPLE, |
|
156 |
||
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
157 |
/** |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
158 |
* Groups the classes for each source file together, then process |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
159 |
* each group in a manner equivalent to the {@code SIMPLE} policy. |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
160 |
* This means no output will be generated if there are any |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
161 |
* errors in any of the classes in a source file. |
10 | 162 |
*/ |
163 |
BY_FILE, |
|
164 |
||
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
165 |
/** |
10 | 166 |
* Completely process each entry on the todo list in turn. |
167 |
* -- this is the same for 1.5. |
|
168 |
* Means output might be generated for some classes in a compilation unit |
|
169 |
* and not others. |
|
170 |
*/ |
|
171 |
BY_TODO; |
|
172 |
||
173 |
static CompilePolicy decode(String option) { |
|
174 |
if (option == null) |
|
175 |
return DEFAULT_COMPILE_POLICY; |
|
176 |
else if (option.equals("attr")) |
|
177 |
return ATTR_ONLY; |
|
178 |
else if (option.equals("check")) |
|
179 |
return CHECK_ONLY; |
|
180 |
else if (option.equals("simple")) |
|
181 |
return SIMPLE; |
|
182 |
else if (option.equals("byfile")) |
|
183 |
return BY_FILE; |
|
184 |
else if (option.equals("bytodo")) |
|
185 |
return BY_TODO; |
|
186 |
else |
|
187 |
return DEFAULT_COMPILE_POLICY; |
|
188 |
} |
|
189 |
} |
|
190 |
||
191 |
private static CompilePolicy DEFAULT_COMPILE_POLICY = CompilePolicy.BY_TODO; |
|
192 |
||
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
193 |
protected static enum ImplicitSourcePolicy { |
10 | 194 |
/** Don't generate or process implicitly read source files. */ |
195 |
NONE, |
|
196 |
/** Generate classes for implicitly read source files. */ |
|
197 |
CLASS, |
|
198 |
/** Like CLASS, but generate warnings if annotation processing occurs */ |
|
199 |
UNSET; |
|
200 |
||
201 |
static ImplicitSourcePolicy decode(String option) { |
|
202 |
if (option == null) |
|
203 |
return UNSET; |
|
204 |
else if (option.equals("none")) |
|
205 |
return NONE; |
|
206 |
else if (option.equals("class")) |
|
207 |
return CLASS; |
|
208 |
else |
|
209 |
return UNSET; |
|
210 |
} |
|
211 |
} |
|
212 |
||
213 |
/** The log to be used for error reporting. |
|
214 |
*/ |
|
215 |
public Log log; |
|
216 |
||
169 | 217 |
/** Factory for creating diagnostic objects |
218 |
*/ |
|
219 |
JCDiagnostic.Factory diagFactory; |
|
220 |
||
10 | 221 |
/** The tree factory module. |
222 |
*/ |
|
223 |
protected TreeMaker make; |
|
224 |
||
225 |
/** The class reader. |
|
226 |
*/ |
|
227 |
protected ClassReader reader; |
|
228 |
||
229 |
/** The class writer. |
|
230 |
*/ |
|
231 |
protected ClassWriter writer; |
|
232 |
||
233 |
/** The module for the symbol table entry phases. |
|
234 |
*/ |
|
235 |
protected Enter enter; |
|
236 |
||
237 |
/** The symbol table. |
|
238 |
*/ |
|
239 |
protected Symtab syms; |
|
240 |
||
241 |
/** The language version. |
|
242 |
*/ |
|
243 |
protected Source source; |
|
244 |
||
245 |
/** The module for code generation. |
|
246 |
*/ |
|
247 |
protected Gen gen; |
|
248 |
||
249 |
/** The name table. |
|
250 |
*/ |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1258
diff
changeset
|
251 |
protected Names names; |
10 | 252 |
|
253 |
/** The attributor. |
|
254 |
*/ |
|
255 |
protected Attr attr; |
|
256 |
||
257 |
/** The attributor. |
|
258 |
*/ |
|
259 |
protected Check chk; |
|
260 |
||
261 |
/** The flow analyzer. |
|
262 |
*/ |
|
263 |
protected Flow flow; |
|
264 |
||
265 |
/** The type eraser. |
|
266 |
*/ |
|
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
267 |
protected TransTypes transTypes; |
10 | 268 |
|
269 |
/** The syntactic sugar desweetener. |
|
270 |
*/ |
|
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
271 |
protected Lower lower; |
10 | 272 |
|
273 |
/** The annotation annotator. |
|
274 |
*/ |
|
275 |
protected Annotate annotate; |
|
276 |
||
277 |
/** Force a completion failure on this name |
|
278 |
*/ |
|
279 |
protected final Name completionFailureName; |
|
280 |
||
281 |
/** Type utilities. |
|
282 |
*/ |
|
283 |
protected Types types; |
|
284 |
||
285 |
/** Access to file objects. |
|
286 |
*/ |
|
287 |
protected JavaFileManager fileManager; |
|
288 |
||
289 |
/** Factory for parsers. |
|
290 |
*/ |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
1046
diff
changeset
|
291 |
protected ParserFactory parserFactory; |
10 | 292 |
|
293 |
/** Optional listener for progress events |
|
294 |
*/ |
|
295 |
protected TaskListener taskListener; |
|
296 |
||
297 |
/** |
|
298 |
* Annotation processing may require and provide a new instance |
|
299 |
* of the compiler to be used for the analyze and generate phases. |
|
300 |
*/ |
|
301 |
protected JavaCompiler delegateCompiler; |
|
302 |
||
303 |
/** |
|
304 |
* Flag set if any annotation processing occurred. |
|
305 |
**/ |
|
306 |
protected boolean annotationProcessingOccurred; |
|
307 |
||
308 |
/** |
|
309 |
* Flag set if any implicit source files read. |
|
310 |
**/ |
|
311 |
protected boolean implicitSourceFilesRead; |
|
312 |
||
313 |
protected Context context; |
|
314 |
||
315 |
/** Construct a new compiler using a shared context. |
|
316 |
*/ |
|
317 |
public JavaCompiler(final Context context) { |
|
318 |
this.context = context; |
|
319 |
context.put(compilerKey, this); |
|
320 |
||
321 |
// if fileManager not already set, register the JavacFileManager to be used |
|
322 |
if (context.get(JavaFileManager.class) == null) |
|
323 |
JavacFileManager.preRegister(context); |
|
324 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1258
diff
changeset
|
325 |
names = Names.instance(context); |
10 | 326 |
log = Log.instance(context); |
169 | 327 |
diagFactory = JCDiagnostic.Factory.instance(context); |
10 | 328 |
reader = ClassReader.instance(context); |
329 |
make = TreeMaker.instance(context); |
|
330 |
writer = ClassWriter.instance(context); |
|
331 |
enter = Enter.instance(context); |
|
332 |
todo = Todo.instance(context); |
|
333 |
||
334 |
fileManager = context.get(JavaFileManager.class); |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
1046
diff
changeset
|
335 |
parserFactory = ParserFactory.instance(context); |
10 | 336 |
|
337 |
try { |
|
338 |
// catch completion problems with predefineds |
|
339 |
syms = Symtab.instance(context); |
|
340 |
} catch (CompletionFailure ex) { |
|
341 |
// inlined Check.completionError as it is not initialized yet |
|
169 | 342 |
log.error("cant.access", ex.sym, ex.getDetailValue()); |
10 | 343 |
if (ex instanceof ClassReader.BadClassFile) |
344 |
throw new Abort(); |
|
345 |
} |
|
346 |
source = Source.instance(context); |
|
347 |
attr = Attr.instance(context); |
|
348 |
chk = Check.instance(context); |
|
349 |
gen = Gen.instance(context); |
|
350 |
flow = Flow.instance(context); |
|
351 |
transTypes = TransTypes.instance(context); |
|
352 |
lower = Lower.instance(context); |
|
353 |
annotate = Annotate.instance(context); |
|
354 |
types = Types.instance(context); |
|
355 |
taskListener = context.get(TaskListener.class); |
|
356 |
||
357 |
reader.sourceCompleter = this; |
|
358 |
||
359 |
Options options = Options.instance(context); |
|
360 |
||
361 |
verbose = options.get("-verbose") != null; |
|
362 |
sourceOutput = options.get("-printsource") != null; // used to be -s |
|
363 |
stubOutput = options.get("-stubs") != null; |
|
364 |
relax = options.get("-relax") != null; |
|
365 |
printFlat = options.get("-printflat") != null; |
|
366 |
attrParseOnly = options.get("-attrparseonly") != null; |
|
367 |
encoding = options.get("-encoding"); |
|
368 |
lineDebugInfo = options.get("-g:") == null || |
|
369 |
options.get("-g:lines") != null; |
|
370 |
genEndPos = options.get("-Xjcov") != null || |
|
371 |
context.get(DiagnosticListener.class) != null; |
|
372 |
devVerbose = options.get("dev") != null; |
|
373 |
processPcks = options.get("process.packages") != null; |
|
1996 | 374 |
werror = options.get("-Werror") != null; |
10 | 375 |
|
376 |
verboseCompilePolicy = options.get("verboseCompilePolicy") != null; |
|
377 |
||
378 |
if (attrParseOnly) |
|
379 |
compilePolicy = CompilePolicy.ATTR_ONLY; |
|
380 |
else |
|
381 |
compilePolicy = CompilePolicy.decode(options.get("compilePolicy")); |
|
382 |
||
383 |
implicitSourcePolicy = ImplicitSourcePolicy.decode(options.get("-implicit")); |
|
384 |
||
385 |
completionFailureName = |
|
386 |
(options.get("failcomplete") != null) |
|
387 |
? names.fromString(options.get("failcomplete")) |
|
388 |
: null; |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
389 |
|
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
390 |
shouldStopPolicy = |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
391 |
(options.get("shouldStopPolicy") != null) |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
392 |
? CompileState.valueOf(options.get("shouldStopPolicy")) |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
393 |
: null; |
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2514
diff
changeset
|
394 |
if (options.get("oldDiags") == null) |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2514
diff
changeset
|
395 |
log.setDiagnosticFormatter(RichDiagnosticFormatter.instance(context)); |
10 | 396 |
} |
397 |
||
398 |
/* Switches: |
|
399 |
*/ |
|
400 |
||
401 |
/** Verbose output. |
|
402 |
*/ |
|
403 |
public boolean verbose; |
|
404 |
||
405 |
/** Emit plain Java source files rather than class files. |
|
406 |
*/ |
|
407 |
public boolean sourceOutput; |
|
408 |
||
409 |
/** Emit stub source files rather than class files. |
|
410 |
*/ |
|
411 |
public boolean stubOutput; |
|
412 |
||
413 |
/** Generate attributed parse tree only. |
|
414 |
*/ |
|
415 |
public boolean attrParseOnly; |
|
416 |
||
417 |
/** Switch: relax some constraints for producing the jsr14 prototype. |
|
418 |
*/ |
|
419 |
boolean relax; |
|
420 |
||
421 |
/** Debug switch: Emit Java sources after inner class flattening. |
|
422 |
*/ |
|
423 |
public boolean printFlat; |
|
424 |
||
425 |
/** The encoding to be used for source input. |
|
426 |
*/ |
|
427 |
public String encoding; |
|
428 |
||
429 |
/** Generate code with the LineNumberTable attribute for debugging |
|
430 |
*/ |
|
431 |
public boolean lineDebugInfo; |
|
432 |
||
433 |
/** Switch: should we store the ending positions? |
|
434 |
*/ |
|
435 |
public boolean genEndPos; |
|
436 |
||
437 |
/** Switch: should we debug ignored exceptions |
|
438 |
*/ |
|
439 |
protected boolean devVerbose; |
|
440 |
||
441 |
/** Switch: should we (annotation) process packages as well |
|
442 |
*/ |
|
443 |
protected boolean processPcks; |
|
444 |
||
1996 | 445 |
/** Switch: treat warnings as errors |
446 |
*/ |
|
447 |
protected boolean werror; |
|
448 |
||
10 | 449 |
/** Switch: is annotation processing requested explitly via |
450 |
* CompilationTask.setProcessors? |
|
451 |
*/ |
|
452 |
protected boolean explicitAnnotationProcessingRequested = false; |
|
453 |
||
454 |
/** |
|
455 |
* The policy for the order in which to perform the compilation |
|
456 |
*/ |
|
457 |
protected CompilePolicy compilePolicy; |
|
458 |
||
459 |
/** |
|
460 |
* The policy for what to do with implicitly read source files |
|
461 |
*/ |
|
462 |
protected ImplicitSourcePolicy implicitSourcePolicy; |
|
463 |
||
464 |
/** |
|
465 |
* Report activity related to compilePolicy |
|
466 |
*/ |
|
467 |
public boolean verboseCompilePolicy; |
|
468 |
||
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
469 |
/** |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
470 |
* Policy of how far to continue processing. null means until first |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
471 |
* error. |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
472 |
*/ |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
473 |
public CompileState shouldStopPolicy; |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
474 |
|
10 | 475 |
/** A queue of all as yet unattributed classes. |
476 |
*/ |
|
477 |
public Todo todo; |
|
478 |
||
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
479 |
/** Ordered list of compiler phases for each compilation unit. */ |
3151
41800a86aad3
6854796: update JSR308 impl with latest code from type-annotations repo
jjg
parents:
2984
diff
changeset
|
480 |
public enum CompileState { |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
481 |
PARSE(1), |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
482 |
ENTER(2), |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
483 |
PROCESS(3), |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
484 |
ATTR(4), |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
485 |
FLOW(5), |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
486 |
TRANSTYPES(6), |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
487 |
LOWER(7), |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
488 |
GENERATE(8); |
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
489 |
CompileState(int value) { |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
490 |
this.value = value; |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
491 |
} |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
492 |
boolean isDone(CompileState other) { |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
493 |
return value >= other.value; |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
494 |
} |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
495 |
private int value; |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
496 |
}; |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
497 |
/** Partial map to record which compiler phases have been executed |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
498 |
* for each compilation unit. Used for ATTR and FLOW phases. |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
499 |
*/ |
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
500 |
protected class CompileStates extends HashMap<Env<AttrContext>,CompileState> { |
1870
57a1138dffc8
6795903: fix latent build warnings in langtools repository
jjg
parents:
1355
diff
changeset
|
501 |
private static final long serialVersionUID = 1812267524140424433L; |
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
502 |
boolean isDone(Env<AttrContext> env, CompileState cs) { |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
503 |
CompileState ecs = get(env); |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
504 |
return ecs != null && ecs.isDone(cs); |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
505 |
} |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
506 |
} |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
507 |
private CompileStates compileStates = new CompileStates(); |
10 | 508 |
|
509 |
/** The set of currently compiled inputfiles, needed to ensure |
|
510 |
* we don't accidentally overwrite an input file when -s is set. |
|
511 |
* initialized by `compile'. |
|
512 |
*/ |
|
513 |
protected Set<JavaFileObject> inputFiles = new HashSet<JavaFileObject>(); |
|
514 |
||
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
515 |
protected boolean shouldStop(CompileState cs) { |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
516 |
if (shouldStopPolicy == null) |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
517 |
return (errorCount() > 0); |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
518 |
else |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
519 |
return cs.ordinal() > shouldStopPolicy.ordinal(); |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
520 |
} |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
521 |
|
10 | 522 |
/** The number of errors reported so far. |
523 |
*/ |
|
524 |
public int errorCount() { |
|
525 |
if (delegateCompiler != null && delegateCompiler != this) |
|
526 |
return delegateCompiler.errorCount(); |
|
1996 | 527 |
else { |
528 |
if (werror && log.nerrors == 0 && log.nwarnings > 0) { |
|
529 |
log.error("warnings.and.werror"); |
|
530 |
} |
|
531 |
} |
|
10 | 532 |
return log.nerrors; |
533 |
} |
|
534 |
||
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
535 |
protected final <T> Queue<T> stopIfError(CompileState cs, Queue<T> queue) { |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
536 |
return shouldStop(cs) ? ListBuffer.<T>lb() : queue; |
10 | 537 |
} |
538 |
||
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
539 |
protected final <T> List<T> stopIfError(CompileState cs, List<T> list) { |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
540 |
return shouldStop(cs) ? List.<T>nil() : list; |
10 | 541 |
} |
542 |
||
543 |
/** The number of warnings reported so far. |
|
544 |
*/ |
|
545 |
public int warningCount() { |
|
546 |
if (delegateCompiler != null && delegateCompiler != this) |
|
547 |
return delegateCompiler.warningCount(); |
|
548 |
else |
|
549 |
return log.nwarnings; |
|
550 |
} |
|
551 |
||
552 |
/** Whether or not any parse errors have occurred. |
|
553 |
*/ |
|
554 |
public boolean parseErrors() { |
|
555 |
return parseErrors; |
|
556 |
} |
|
557 |
||
558 |
/** Try to open input stream with given name. |
|
559 |
* Report an error if this fails. |
|
560 |
* @param filename The file name of the input stream to be opened. |
|
561 |
*/ |
|
562 |
public CharSequence readSource(JavaFileObject filename) { |
|
563 |
try { |
|
564 |
inputFiles.add(filename); |
|
565 |
return filename.getCharContent(false); |
|
566 |
} catch (IOException e) { |
|
567 |
log.error("error.reading.file", filename, e.getLocalizedMessage()); |
|
568 |
return null; |
|
569 |
} |
|
570 |
} |
|
571 |
||
572 |
/** Parse contents of input stream. |
|
573 |
* @param filename The name of the file from which input stream comes. |
|
574 |
* @param input The input stream to be parsed. |
|
575 |
*/ |
|
576 |
protected JCCompilationUnit parse(JavaFileObject filename, CharSequence content) { |
|
577 |
long msec = now(); |
|
578 |
JCCompilationUnit tree = make.TopLevel(List.<JCTree.JCAnnotation>nil(), |
|
579 |
null, List.<JCTree>nil()); |
|
580 |
if (content != null) { |
|
581 |
if (verbose) { |
|
582 |
printVerbose("parsing.started", filename); |
|
583 |
} |
|
584 |
if (taskListener != null) { |
|
585 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, filename); |
|
586 |
taskListener.started(e); |
|
587 |
} |
|
588 |
int initialErrorCount = log.nerrors; |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
1046
diff
changeset
|
589 |
Parser parser = parserFactory.newParser(content, keepComments(), genEndPos, lineDebugInfo); |
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
1046
diff
changeset
|
590 |
tree = parser.parseCompilationUnit(); |
10 | 591 |
parseErrors |= (log.nerrors > initialErrorCount); |
592 |
if (verbose) { |
|
593 |
printVerbose("parsing.done", Long.toString(elapsed(msec))); |
|
594 |
} |
|
595 |
} |
|
596 |
||
597 |
tree.sourcefile = filename; |
|
598 |
||
599 |
if (content != null && taskListener != null) { |
|
600 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, tree); |
|
601 |
taskListener.finished(e); |
|
602 |
} |
|
603 |
||
604 |
return tree; |
|
605 |
} |
|
606 |
// where |
|
607 |
public boolean keepComments = false; |
|
608 |
protected boolean keepComments() { |
|
609 |
return keepComments || sourceOutput || stubOutput; |
|
610 |
} |
|
611 |
||
612 |
||
613 |
/** Parse contents of file. |
|
614 |
* @param filename The name of the file to be parsed. |
|
615 |
*/ |
|
616 |
@Deprecated |
|
617 |
public JCTree.JCCompilationUnit parse(String filename) throws IOException { |
|
618 |
JavacFileManager fm = (JavacFileManager)fileManager; |
|
619 |
return parse(fm.getJavaFileObjectsFromStrings(List.of(filename)).iterator().next()); |
|
620 |
} |
|
621 |
||
622 |
/** Parse contents of file. |
|
623 |
* @param filename The name of the file to be parsed. |
|
624 |
*/ |
|
625 |
public JCTree.JCCompilationUnit parse(JavaFileObject filename) { |
|
626 |
JavaFileObject prev = log.useSource(filename); |
|
627 |
try { |
|
628 |
JCTree.JCCompilationUnit t = parse(filename, readSource(filename)); |
|
629 |
if (t.endPositions != null) |
|
630 |
log.setEndPosTable(filename, t.endPositions); |
|
631 |
return t; |
|
632 |
} finally { |
|
633 |
log.useSource(prev); |
|
634 |
} |
|
635 |
} |
|
636 |
||
637 |
/** Resolve an identifier. |
|
638 |
* @param name The identifier to resolve |
|
639 |
*/ |
|
640 |
public Symbol resolveIdent(String name) { |
|
641 |
if (name.equals("")) |
|
642 |
return syms.errSymbol; |
|
643 |
JavaFileObject prev = log.useSource(null); |
|
644 |
try { |
|
645 |
JCExpression tree = null; |
|
646 |
for (String s : name.split("\\.", -1)) { |
|
647 |
if (!SourceVersion.isIdentifier(s)) // TODO: check for keywords |
|
648 |
return syms.errSymbol; |
|
649 |
tree = (tree == null) ? make.Ident(names.fromString(s)) |
|
650 |
: make.Select(tree, names.fromString(s)); |
|
651 |
} |
|
652 |
JCCompilationUnit toplevel = |
|
653 |
make.TopLevel(List.<JCTree.JCAnnotation>nil(), null, List.<JCTree>nil()); |
|
654 |
toplevel.packge = syms.unnamedPackage; |
|
655 |
return attr.attribIdent(tree, toplevel); |
|
656 |
} finally { |
|
657 |
log.useSource(prev); |
|
658 |
} |
|
659 |
} |
|
660 |
||
661 |
/** Emit plain Java source for a class. |
|
662 |
* @param env The attribution environment of the outermost class |
|
663 |
* containing this class. |
|
664 |
* @param cdef The class definition to be printed. |
|
665 |
*/ |
|
666 |
JavaFileObject printSource(Env<AttrContext> env, JCClassDecl cdef) throws IOException { |
|
667 |
JavaFileObject outFile |
|
668 |
= fileManager.getJavaFileForOutput(CLASS_OUTPUT, |
|
669 |
cdef.sym.flatname.toString(), |
|
670 |
JavaFileObject.Kind.SOURCE, |
|
671 |
null); |
|
672 |
if (inputFiles.contains(outFile)) { |
|
673 |
log.error(cdef.pos(), "source.cant.overwrite.input.file", outFile); |
|
674 |
return null; |
|
675 |
} else { |
|
676 |
BufferedWriter out = new BufferedWriter(outFile.openWriter()); |
|
677 |
try { |
|
678 |
new Pretty(out, true).printUnit(env.toplevel, cdef); |
|
679 |
if (verbose) |
|
680 |
printVerbose("wrote.file", outFile); |
|
681 |
} finally { |
|
682 |
out.close(); |
|
683 |
} |
|
684 |
return outFile; |
|
685 |
} |
|
686 |
} |
|
687 |
||
688 |
/** Generate code and emit a class file for a given class |
|
689 |
* @param env The attribution environment of the outermost class |
|
690 |
* containing this class. |
|
691 |
* @param cdef The class definition from which code is generated. |
|
692 |
*/ |
|
693 |
JavaFileObject genCode(Env<AttrContext> env, JCClassDecl cdef) throws IOException { |
|
694 |
try { |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
695 |
if (gen.genClass(env, cdef) && (errorCount() == 0)) |
10 | 696 |
return writer.writeClass(cdef.sym); |
697 |
} catch (ClassWriter.PoolOverflow ex) { |
|
698 |
log.error(cdef.pos(), "limit.pool"); |
|
699 |
} catch (ClassWriter.StringOverflow ex) { |
|
700 |
log.error(cdef.pos(), "limit.string.overflow", |
|
701 |
ex.value.substring(0, 20)); |
|
702 |
} catch (CompletionFailure ex) { |
|
703 |
chk.completionError(cdef.pos(), ex); |
|
704 |
} |
|
705 |
return null; |
|
706 |
} |
|
707 |
||
708 |
/** Complete compiling a source file that has been accessed |
|
709 |
* by the class file reader. |
|
710 |
* @param c The class the source file of which needs to be compiled. |
|
711 |
* @param filename The name of the source file. |
|
712 |
* @param f An input stream that reads the source file. |
|
713 |
*/ |
|
714 |
public void complete(ClassSymbol c) throws CompletionFailure { |
|
715 |
// System.err.println("completing " + c);//DEBUG |
|
716 |
if (completionFailureName == c.fullname) { |
|
717 |
throw new CompletionFailure(c, "user-selected completion failure by class name"); |
|
718 |
} |
|
719 |
JCCompilationUnit tree; |
|
720 |
JavaFileObject filename = c.classfile; |
|
721 |
JavaFileObject prev = log.useSource(filename); |
|
722 |
||
723 |
try { |
|
724 |
tree = parse(filename, filename.getCharContent(false)); |
|
725 |
} catch (IOException e) { |
|
726 |
log.error("error.reading.file", filename, e); |
|
727 |
tree = make.TopLevel(List.<JCTree.JCAnnotation>nil(), null, List.<JCTree>nil()); |
|
728 |
} finally { |
|
729 |
log.useSource(prev); |
|
730 |
} |
|
731 |
||
732 |
if (taskListener != null) { |
|
733 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, tree); |
|
734 |
taskListener.started(e); |
|
735 |
} |
|
736 |
||
737 |
enter.complete(List.of(tree), c); |
|
738 |
||
739 |
if (taskListener != null) { |
|
740 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, tree); |
|
741 |
taskListener.finished(e); |
|
742 |
} |
|
743 |
||
744 |
if (enter.getEnv(c) == null) { |
|
745 |
boolean isPkgInfo = |
|
746 |
tree.sourcefile.isNameCompatible("package-info", |
|
747 |
JavaFileObject.Kind.SOURCE); |
|
748 |
if (isPkgInfo) { |
|
749 |
if (enter.getEnv(tree.packge) == null) { |
|
169 | 750 |
JCDiagnostic diag = |
751 |
diagFactory.fragment("file.does.not.contain.package", |
|
10 | 752 |
c.location()); |
169 | 753 |
throw reader.new BadClassFile(c, filename, diag); |
10 | 754 |
} |
755 |
} else { |
|
169 | 756 |
JCDiagnostic diag = |
757 |
diagFactory.fragment("file.doesnt.contain.class", |
|
758 |
c.getQualifiedName()); |
|
759 |
throw reader.new BadClassFile(c, filename, diag); |
|
10 | 760 |
} |
761 |
} |
|
762 |
||
763 |
implicitSourceFilesRead = true; |
|
764 |
} |
|
765 |
||
766 |
/** Track when the JavaCompiler has been used to compile something. */ |
|
767 |
private boolean hasBeenUsed = false; |
|
768 |
private long start_msec = 0; |
|
769 |
public long elapsed_msec = 0; |
|
770 |
||
771 |
/** Track whether any errors occurred while parsing source text. */ |
|
772 |
private boolean parseErrors = false; |
|
773 |
||
774 |
public void compile(List<JavaFileObject> sourceFileObject) |
|
775 |
throws Throwable { |
|
776 |
compile(sourceFileObject, List.<String>nil(), null); |
|
777 |
} |
|
778 |
||
779 |
/** |
|
780 |
* Main method: compile a list of files, return all compiled classes |
|
781 |
* |
|
782 |
* @param sourceFileObjects file objects to be compiled |
|
783 |
* @param classnames class names to process for annotations |
|
784 |
* @param processors user provided annotation processors to bypass |
|
785 |
* discovery, {@code null} means that no processors were provided |
|
786 |
*/ |
|
787 |
public void compile(List<JavaFileObject> sourceFileObjects, |
|
788 |
List<String> classnames, |
|
789 |
Iterable<? extends Processor> processors) |
|
790 |
throws IOException // TODO: temp, from JavacProcessingEnvironment |
|
791 |
{ |
|
792 |
if (processors != null && processors.iterator().hasNext()) |
|
793 |
explicitAnnotationProcessingRequested = true; |
|
794 |
// as a JavaCompiler can only be used once, throw an exception if |
|
795 |
// it has been used before. |
|
796 |
if (hasBeenUsed) |
|
797 |
throw new AssertionError("attempt to reuse JavaCompiler"); |
|
798 |
hasBeenUsed = true; |
|
799 |
||
800 |
start_msec = now(); |
|
801 |
try { |
|
802 |
initProcessAnnotations(processors); |
|
803 |
||
804 |
// These method calls must be chained to avoid memory leaks |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
805 |
delegateCompiler = |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
806 |
processAnnotations( |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
807 |
enterTrees(stopIfError(CompileState.PARSE, parseFiles(sourceFileObjects))), |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
808 |
classnames); |
10 | 809 |
|
810 |
delegateCompiler.compile2(); |
|
811 |
delegateCompiler.close(); |
|
812 |
elapsed_msec = delegateCompiler.elapsed_msec; |
|
813 |
} catch (Abort ex) { |
|
814 |
if (devVerbose) |
|
815 |
ex.printStackTrace(); |
|
816 |
} |
|
817 |
} |
|
818 |
||
819 |
/** |
|
820 |
* The phases following annotation processing: attribution, |
|
821 |
* desugar, and finally code generation. |
|
822 |
*/ |
|
823 |
private void compile2() { |
|
824 |
try { |
|
825 |
switch (compilePolicy) { |
|
826 |
case ATTR_ONLY: |
|
827 |
attribute(todo); |
|
828 |
break; |
|
829 |
||
830 |
case CHECK_ONLY: |
|
831 |
flow(attribute(todo)); |
|
832 |
break; |
|
833 |
||
834 |
case SIMPLE: |
|
835 |
generate(desugar(flow(attribute(todo)))); |
|
836 |
break; |
|
837 |
||
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
838 |
case BY_FILE: { |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
839 |
Queue<Queue<Env<AttrContext>>> q = todo.groupByFile(); |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
840 |
while (!q.isEmpty() && !shouldStop(CompileState.ATTR)) { |
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
841 |
generate(desugar(flow(attribute(q.remove())))); |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
842 |
} |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
843 |
} |
10 | 844 |
break; |
845 |
||
846 |
case BY_TODO: |
|
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
847 |
while (!todo.isEmpty()) |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
848 |
generate(desugar(flow(attribute(todo.remove())))); |
10 | 849 |
break; |
850 |
||
851 |
default: |
|
852 |
assert false: "unknown compile policy"; |
|
853 |
} |
|
854 |
} catch (Abort ex) { |
|
855 |
if (devVerbose) |
|
856 |
ex.printStackTrace(); |
|
857 |
} |
|
858 |
||
859 |
if (verbose) { |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
860 |
elapsed_msec = elapsed(start_msec); |
10 | 861 |
printVerbose("total", Long.toString(elapsed_msec)); |
862 |
} |
|
863 |
||
864 |
reportDeferredDiagnostics(); |
|
865 |
||
866 |
if (!log.hasDiagnosticListener()) { |
|
867 |
printCount("error", errorCount()); |
|
868 |
printCount("warn", warningCount()); |
|
869 |
} |
|
870 |
} |
|
871 |
||
872 |
private List<JCClassDecl> rootClasses; |
|
873 |
||
874 |
/** |
|
875 |
* Parses a list of files. |
|
876 |
*/ |
|
877 |
public List<JCCompilationUnit> parseFiles(List<JavaFileObject> fileObjects) throws IOException { |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
878 |
if (shouldStop(CompileState.PARSE)) |
10 | 879 |
return List.nil(); |
880 |
||
881 |
//parse all files |
|
882 |
ListBuffer<JCCompilationUnit> trees = lb(); |
|
883 |
for (JavaFileObject fileObject : fileObjects) |
|
884 |
trees.append(parse(fileObject)); |
|
885 |
return trees.toList(); |
|
886 |
} |
|
887 |
||
888 |
/** |
|
889 |
* Enter the symbols found in a list of parse trees. |
|
890 |
* As a side-effect, this puts elements on the "todo" list. |
|
891 |
* Also stores a list of all top level classes in rootClasses. |
|
892 |
*/ |
|
893 |
public List<JCCompilationUnit> enterTrees(List<JCCompilationUnit> roots) { |
|
894 |
//enter symbols for all files |
|
895 |
if (taskListener != null) { |
|
896 |
for (JCCompilationUnit unit: roots) { |
|
897 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, unit); |
|
898 |
taskListener.started(e); |
|
899 |
} |
|
900 |
} |
|
901 |
||
902 |
enter.main(roots); |
|
903 |
||
904 |
if (taskListener != null) { |
|
905 |
for (JCCompilationUnit unit: roots) { |
|
906 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, unit); |
|
907 |
taskListener.finished(e); |
|
908 |
} |
|
909 |
} |
|
910 |
||
911 |
//If generating source, remember the classes declared in |
|
912 |
//the original compilation units listed on the command line. |
|
913 |
if (sourceOutput || stubOutput) { |
|
914 |
ListBuffer<JCClassDecl> cdefs = lb(); |
|
915 |
for (JCCompilationUnit unit : roots) { |
|
916 |
for (List<JCTree> defs = unit.defs; |
|
917 |
defs.nonEmpty(); |
|
918 |
defs = defs.tail) { |
|
919 |
if (defs.head instanceof JCClassDecl) |
|
920 |
cdefs.append((JCClassDecl)defs.head); |
|
921 |
} |
|
922 |
} |
|
923 |
rootClasses = cdefs.toList(); |
|
924 |
} |
|
925 |
return roots; |
|
926 |
} |
|
927 |
||
928 |
/** |
|
929 |
* Set to true to enable skeleton annotation processing code. |
|
930 |
* Currently, we assume this variable will be replaced more |
|
931 |
* advanced logic to figure out if annotation processing is |
|
932 |
* needed. |
|
933 |
*/ |
|
934 |
boolean processAnnotations = false; |
|
935 |
||
936 |
/** |
|
937 |
* Object to handle annotation processing. |
|
938 |
*/ |
|
939 |
JavacProcessingEnvironment procEnvImpl = null; |
|
940 |
||
941 |
/** |
|
942 |
* Check if we should process annotations. |
|
943 |
* If so, and if no scanner is yet registered, then set up the DocCommentScanner |
|
944 |
* to catch doc comments, and set keepComments so the parser records them in |
|
945 |
* the compilation unit. |
|
946 |
* |
|
947 |
* @param processors user provided annotation processors to bypass |
|
948 |
* discovery, {@code null} means that no processors were provided |
|
949 |
*/ |
|
950 |
public void initProcessAnnotations(Iterable<? extends Processor> processors) { |
|
951 |
// Process annotations if processing is not disabled and there |
|
952 |
// is at least one Processor available. |
|
953 |
Options options = Options.instance(context); |
|
954 |
if (options.get("-proc:none") != null) { |
|
955 |
processAnnotations = false; |
|
956 |
} else if (procEnvImpl == null) { |
|
957 |
procEnvImpl = new JavacProcessingEnvironment(context, processors); |
|
958 |
processAnnotations = procEnvImpl.atLeastOneProcessor(); |
|
959 |
||
960 |
if (processAnnotations) { |
|
961 |
if (context.get(Scanner.Factory.scannerFactoryKey) == null) |
|
962 |
DocCommentScanner.Factory.preRegister(context); |
|
963 |
options.put("save-parameter-names", "save-parameter-names"); |
|
964 |
reader.saveParameterNames = true; |
|
965 |
keepComments = true; |
|
966 |
if (taskListener != null) |
|
967 |
taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING)); |
|
968 |
||
969 |
||
970 |
} else { // free resources |
|
971 |
procEnvImpl.close(); |
|
972 |
} |
|
973 |
} |
|
974 |
} |
|
975 |
||
976 |
// TODO: called by JavacTaskImpl |
|
977 |
public JavaCompiler processAnnotations(List<JCCompilationUnit> roots) throws IOException { |
|
978 |
return processAnnotations(roots, List.<String>nil()); |
|
979 |
} |
|
980 |
||
981 |
/** |
|
982 |
* Process any anotations found in the specifed compilation units. |
|
983 |
* @param roots a list of compilation units |
|
984 |
* @return an instance of the compiler in which to complete the compilation |
|
985 |
*/ |
|
986 |
public JavaCompiler processAnnotations(List<JCCompilationUnit> roots, |
|
987 |
List<String> classnames) |
|
988 |
throws IOException { // TODO: see TEMP note in JavacProcessingEnvironment |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
989 |
if (shouldStop(CompileState.PROCESS)) { |
10 | 990 |
// Errors were encountered. If todo is empty, then the |
991 |
// encountered errors were parse errors. Otherwise, the |
|
992 |
// errors were found during the enter phase which should |
|
993 |
// be ignored when processing annotations. |
|
994 |
||
995 |
if (todo.isEmpty()) |
|
996 |
return this; |
|
997 |
} |
|
998 |
||
999 |
// ASSERT: processAnnotations and procEnvImpl should have been set up by |
|
1000 |
// by initProcessAnnotations |
|
1001 |
||
1002 |
// NOTE: The !classnames.isEmpty() checks should be refactored to Main. |
|
1003 |
||
1004 |
if (!processAnnotations) { |
|
1005 |
// If there are no annotation processors present, and |
|
1006 |
// annotation processing is to occur with compilation, |
|
1007 |
// emit a warning. |
|
1008 |
Options options = Options.instance(context); |
|
1009 |
if (options.get("-proc:only") != null) { |
|
1010 |
log.warning("proc.proc-only.requested.no.procs"); |
|
1011 |
todo.clear(); |
|
1012 |
} |
|
1013 |
// If not processing annotations, classnames must be empty |
|
1014 |
if (!classnames.isEmpty()) { |
|
1015 |
log.error("proc.no.explicit.annotation.processing.requested", |
|
1016 |
classnames); |
|
1017 |
} |
|
1018 |
return this; // continue regular compilation |
|
1019 |
} |
|
1020 |
||
1021 |
try { |
|
1022 |
List<ClassSymbol> classSymbols = List.nil(); |
|
1023 |
List<PackageSymbol> pckSymbols = List.nil(); |
|
1024 |
if (!classnames.isEmpty()) { |
|
1025 |
// Check for explicit request for annotation |
|
1026 |
// processing |
|
1027 |
if (!explicitAnnotationProcessingRequested()) { |
|
1028 |
log.error("proc.no.explicit.annotation.processing.requested", |
|
1029 |
classnames); |
|
1030 |
return this; // TODO: Will this halt compilation? |
|
1031 |
} else { |
|
1032 |
boolean errors = false; |
|
1033 |
for (String nameStr : classnames) { |
|
1034 |
Symbol sym = resolveIdent(nameStr); |
|
1035 |
if (sym == null || (sym.kind == Kinds.PCK && !processPcks)) { |
|
1036 |
log.error("proc.cant.find.class", nameStr); |
|
1037 |
errors = true; |
|
1038 |
continue; |
|
1039 |
} |
|
1040 |
try { |
|
1041 |
if (sym.kind == Kinds.PCK) |
|
1042 |
sym.complete(); |
|
1043 |
if (sym.exists()) { |
|
1044 |
Name name = names.fromString(nameStr); |
|
1045 |
if (sym.kind == Kinds.PCK) |
|
1046 |
pckSymbols = pckSymbols.prepend((PackageSymbol)sym); |
|
1047 |
else |
|
1048 |
classSymbols = classSymbols.prepend((ClassSymbol)sym); |
|
1049 |
continue; |
|
1050 |
} |
|
1051 |
assert sym.kind == Kinds.PCK; |
|
1052 |
log.warning("proc.package.does.not.exist", nameStr); |
|
1053 |
pckSymbols = pckSymbols.prepend((PackageSymbol)sym); |
|
1054 |
} catch (CompletionFailure e) { |
|
1055 |
log.error("proc.cant.find.class", nameStr); |
|
1056 |
errors = true; |
|
1057 |
continue; |
|
1058 |
} |
|
1059 |
} |
|
1060 |
if (errors) |
|
1061 |
return this; |
|
1062 |
} |
|
1063 |
} |
|
1064 |
JavaCompiler c = procEnvImpl.doProcessing(context, roots, classSymbols, pckSymbols); |
|
1065 |
if (c != this) |
|
1066 |
annotationProcessingOccurred = c.annotationProcessingOccurred = true; |
|
1067 |
return c; |
|
1068 |
} catch (CompletionFailure ex) { |
|
169 | 1069 |
log.error("cant.access", ex.sym, ex.getDetailValue()); |
10 | 1070 |
return this; |
1071 |
||
1072 |
} |
|
1073 |
} |
|
1074 |
||
1075 |
boolean explicitAnnotationProcessingRequested() { |
|
1076 |
Options options = Options.instance(context); |
|
1077 |
return |
|
1078 |
explicitAnnotationProcessingRequested || |
|
1079 |
options.get("-processor") != null || |
|
1080 |
options.get("-processorpath") != null || |
|
1081 |
options.get("-proc:only") != null || |
|
1082 |
options.get("-Xprint") != null; |
|
1083 |
} |
|
1084 |
||
1085 |
/** |
|
1086 |
* Attribute a list of parse trees, such as found on the "todo" list. |
|
1087 |
* Note that attributing classes may cause additional files to be |
|
1088 |
* parsed and entered via the SourceCompleter. |
|
1089 |
* Attribution of the entries in the list does not stop if any errors occur. |
|
1090 |
* @returns a list of environments for attributd classes. |
|
1091 |
*/ |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1092 |
public Queue<Env<AttrContext>> attribute(Queue<Env<AttrContext>> envs) { |
10 | 1093 |
ListBuffer<Env<AttrContext>> results = lb(); |
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1094 |
while (!envs.isEmpty()) |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1095 |
results.append(attribute(envs.remove())); |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1096 |
return stopIfError(CompileState.ATTR, results); |
10 | 1097 |
} |
1098 |
||
1099 |
/** |
|
1100 |
* Attribute a parse tree. |
|
1101 |
* @returns the attributed parse tree |
|
1102 |
*/ |
|
1103 |
public Env<AttrContext> attribute(Env<AttrContext> env) { |
|
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1104 |
if (compileStates.isDone(env, CompileState.ATTR)) |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1105 |
return env; |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1106 |
|
10 | 1107 |
if (verboseCompilePolicy) |
1108 |
log.printLines(log.noticeWriter, "[attribute " + env.enclClass.sym + "]"); |
|
1109 |
if (verbose) |
|
1110 |
printVerbose("checking.attribution", env.enclClass.sym); |
|
1111 |
||
1112 |
if (taskListener != null) { |
|
1113 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.ANALYZE, env.toplevel, env.enclClass.sym); |
|
1114 |
taskListener.started(e); |
|
1115 |
} |
|
1116 |
||
1117 |
JavaFileObject prev = log.useSource( |
|
1118 |
env.enclClass.sym.sourcefile != null ? |
|
1119 |
env.enclClass.sym.sourcefile : |
|
1120 |
env.toplevel.sourcefile); |
|
1121 |
try { |
|
1122 |
attr.attribClass(env.tree.pos(), env.enclClass.sym); |
|
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1123 |
compileStates.put(env, CompileState.ATTR); |
10 | 1124 |
} |
1125 |
finally { |
|
1126 |
log.useSource(prev); |
|
1127 |
} |
|
1128 |
||
1129 |
return env; |
|
1130 |
} |
|
1131 |
||
1132 |
/** |
|
1133 |
* Perform dataflow checks on attributed parse trees. |
|
1134 |
* These include checks for definite assignment and unreachable statements. |
|
1135 |
* If any errors occur, an empty list will be returned. |
|
1136 |
* @returns the list of attributed parse trees |
|
1137 |
*/ |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1138 |
public Queue<Env<AttrContext>> flow(Queue<Env<AttrContext>> envs) { |
10 | 1139 |
ListBuffer<Env<AttrContext>> results = lb(); |
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1140 |
for (Env<AttrContext> env: envs) { |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1141 |
flow(env, results); |
10 | 1142 |
} |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1143 |
return stopIfError(CompileState.FLOW, results); |
10 | 1144 |
} |
1145 |
||
1146 |
/** |
|
1147 |
* Perform dataflow checks on an attributed parse tree. |
|
1148 |
*/ |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1149 |
public Queue<Env<AttrContext>> flow(Env<AttrContext> env) { |
10 | 1150 |
ListBuffer<Env<AttrContext>> results = lb(); |
1151 |
flow(env, results); |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1152 |
return stopIfError(CompileState.FLOW, results); |
10 | 1153 |
} |
1154 |
||
1155 |
/** |
|
1156 |
* Perform dataflow checks on an attributed parse tree. |
|
1157 |
*/ |
|
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
1158 |
protected void flow(Env<AttrContext> env, Queue<Env<AttrContext>> results) { |
10 | 1159 |
try { |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1160 |
if (shouldStop(CompileState.FLOW)) |
10 | 1161 |
return; |
1162 |
||
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1163 |
if (relax || compileStates.isDone(env, CompileState.FLOW)) { |
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
1164 |
results.add(env); |
10 | 1165 |
return; |
1166 |
} |
|
1167 |
||
1168 |
if (verboseCompilePolicy) |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1169 |
printNote("[flow " + env.enclClass.sym + "]"); |
10 | 1170 |
JavaFileObject prev = log.useSource( |
1171 |
env.enclClass.sym.sourcefile != null ? |
|
1172 |
env.enclClass.sym.sourcefile : |
|
1173 |
env.toplevel.sourcefile); |
|
1174 |
try { |
|
1175 |
make.at(Position.FIRSTPOS); |
|
1176 |
TreeMaker localMake = make.forToplevel(env.toplevel); |
|
1177 |
flow.analyzeTree(env.tree, localMake); |
|
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1178 |
compileStates.put(env, CompileState.FLOW); |
10 | 1179 |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1180 |
if (shouldStop(CompileState.FLOW)) |
10 | 1181 |
return; |
1182 |
||
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
1183 |
results.add(env); |
10 | 1184 |
} |
1185 |
finally { |
|
1186 |
log.useSource(prev); |
|
1187 |
} |
|
1188 |
} |
|
1189 |
finally { |
|
1190 |
if (taskListener != null) { |
|
1191 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.ANALYZE, env.toplevel, env.enclClass.sym); |
|
1192 |
taskListener.finished(e); |
|
1193 |
} |
|
1194 |
} |
|
1195 |
} |
|
1196 |
||
1197 |
/** |
|
1198 |
* Prepare attributed parse trees, in conjunction with their attribution contexts, |
|
1199 |
* for source or code generation. |
|
1200 |
* If any errors occur, an empty list will be returned. |
|
1201 |
* @returns a list containing the classes to be generated |
|
1202 |
*/ |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1203 |
public Queue<Pair<Env<AttrContext>, JCClassDecl>> desugar(Queue<Env<AttrContext>> envs) { |
10 | 1204 |
ListBuffer<Pair<Env<AttrContext>, JCClassDecl>> results = lb(); |
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1205 |
for (Env<AttrContext> env: envs) |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1206 |
desugar(env, results); |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1207 |
return stopIfError(CompileState.FLOW, results); |
10 | 1208 |
} |
1209 |
||
1210 |
/** |
|
1211 |
* Prepare attributed parse trees, in conjunction with their attribution contexts, |
|
1212 |
* for source or code generation. If the file was not listed on the command line, |
|
1213 |
* the current implicitSourcePolicy is taken into account. |
|
1214 |
* The preparation stops as soon as an error is found. |
|
1215 |
*/ |
|
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1216 |
protected void desugar(final Env<AttrContext> env, Queue<Pair<Env<AttrContext>, JCClassDecl>> results) { |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1217 |
if (shouldStop(CompileState.TRANSTYPES)) |
10 | 1218 |
return; |
1219 |
||
1220 |
if (implicitSourcePolicy == ImplicitSourcePolicy.NONE |
|
1221 |
&& !inputFiles.contains(env.toplevel.sourcefile)) { |
|
1222 |
return; |
|
1223 |
} |
|
1224 |
||
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1225 |
/** |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1226 |
* As erasure (TransTypes) destroys information needed in flow analysis, |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1227 |
* including information in supertypes, we need to ensure that supertypes |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1228 |
* are processed through attribute and flow before subtypes are translated. |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1229 |
*/ |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1230 |
class ScanNested extends TreeScanner { |
1046
e395ce284cbf
6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents:
936
diff
changeset
|
1231 |
Set<Env<AttrContext>> dependencies = new LinkedHashSet<Env<AttrContext>>(); |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1232 |
@Override |
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1233 |
public void visitClassDef(JCClassDecl node) { |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1234 |
Type st = types.supertype(node.sym.type); |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1235 |
if (st.tag == TypeTags.CLASS) { |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1236 |
ClassSymbol c = st.tsym.outermostClass(); |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1237 |
Env<AttrContext> stEnv = enter.getEnv(c); |
1046
e395ce284cbf
6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents:
936
diff
changeset
|
1238 |
if (stEnv != null && env != stEnv) { |
e395ce284cbf
6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents:
936
diff
changeset
|
1239 |
if (dependencies.add(stEnv)) |
e395ce284cbf
6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents:
936
diff
changeset
|
1240 |
scan(stEnv.tree); |
e395ce284cbf
6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents:
936
diff
changeset
|
1241 |
} |
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1242 |
} |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1243 |
super.visitClassDef(node); |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1244 |
} |
10 | 1245 |
} |
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1246 |
ScanNested scanner = new ScanNested(); |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1247 |
scanner.scan(env.tree); |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1248 |
for (Env<AttrContext> dep: scanner.dependencies) { |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1249 |
if (!compileStates.isDone(dep, CompileState.FLOW)) |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1250 |
flow(attribute(dep)); |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1251 |
} |
10 | 1252 |
|
1046
e395ce284cbf
6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents:
936
diff
changeset
|
1253 |
//We need to check for error another time as more classes might |
e395ce284cbf
6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents:
936
diff
changeset
|
1254 |
//have been attributed and analyzed at this stage |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1255 |
if (shouldStop(CompileState.TRANSTYPES)) |
1046
e395ce284cbf
6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents:
936
diff
changeset
|
1256 |
return; |
e395ce284cbf
6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents:
936
diff
changeset
|
1257 |
|
10 | 1258 |
if (verboseCompilePolicy) |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1259 |
printNote("[desugar " + env.enclClass.sym + "]"); |
10 | 1260 |
|
1261 |
JavaFileObject prev = log.useSource(env.enclClass.sym.sourcefile != null ? |
|
1262 |
env.enclClass.sym.sourcefile : |
|
1263 |
env.toplevel.sourcefile); |
|
1264 |
try { |
|
1265 |
//save tree prior to rewriting |
|
1266 |
JCTree untranslated = env.tree; |
|
1267 |
||
1268 |
make.at(Position.FIRSTPOS); |
|
1269 |
TreeMaker localMake = make.forToplevel(env.toplevel); |
|
1270 |
||
1271 |
if (env.tree instanceof JCCompilationUnit) { |
|
1272 |
if (!(stubOutput || sourceOutput || printFlat)) { |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1273 |
if (shouldStop(CompileState.LOWER)) |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1274 |
return; |
10 | 1275 |
List<JCTree> pdef = lower.translateTopLevelClass(env, env.tree, localMake); |
1276 |
if (pdef.head != null) { |
|
1277 |
assert pdef.tail.isEmpty(); |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1278 |
results.add(new Pair<Env<AttrContext>, JCClassDecl>(env, (JCClassDecl)pdef.head)); |
10 | 1279 |
} |
1280 |
} |
|
1281 |
return; |
|
1282 |
} |
|
1283 |
||
1284 |
if (stubOutput) { |
|
1285 |
//emit stub Java source file, only for compilation |
|
1286 |
//units enumerated explicitly on the command line |
|
1287 |
JCClassDecl cdef = (JCClassDecl)env.tree; |
|
1288 |
if (untranslated instanceof JCClassDecl && |
|
1289 |
rootClasses.contains((JCClassDecl)untranslated) && |
|
1290 |
((cdef.mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 || |
|
1291 |
cdef.sym.packge().getQualifiedName() == names.java_lang)) { |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1292 |
results.add(new Pair<Env<AttrContext>, JCClassDecl>(env, removeMethodBodies(cdef))); |
10 | 1293 |
} |
1294 |
return; |
|
1295 |
} |
|
1296 |
||
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1297 |
if (shouldStop(CompileState.TRANSTYPES)) |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1298 |
return; |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1299 |
|
10 | 1300 |
env.tree = transTypes.translateTopLevelClass(env.tree, localMake); |
1301 |
||
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1302 |
if (shouldStop(CompileState.LOWER)) |
10 | 1303 |
return; |
1304 |
||
1305 |
if (sourceOutput) { |
|
1306 |
//emit standard Java source file, only for compilation |
|
1307 |
//units enumerated explicitly on the command line |
|
1308 |
JCClassDecl cdef = (JCClassDecl)env.tree; |
|
1309 |
if (untranslated instanceof JCClassDecl && |
|
1310 |
rootClasses.contains((JCClassDecl)untranslated)) { |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1311 |
results.add(new Pair<Env<AttrContext>, JCClassDecl>(env, cdef)); |
10 | 1312 |
} |
1313 |
return; |
|
1314 |
} |
|
1315 |
||
1316 |
//translate out inner classes |
|
1317 |
List<JCTree> cdefs = lower.translateTopLevelClass(env, env.tree, localMake); |
|
1318 |
||
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1319 |
if (shouldStop(CompileState.LOWER)) |
10 | 1320 |
return; |
1321 |
||
1322 |
//generate code for each class |
|
1323 |
for (List<JCTree> l = cdefs; l.nonEmpty(); l = l.tail) { |
|
1324 |
JCClassDecl cdef = (JCClassDecl)l.head; |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1325 |
results.add(new Pair<Env<AttrContext>, JCClassDecl>(env, cdef)); |
10 | 1326 |
} |
1327 |
} |
|
1328 |
finally { |
|
1329 |
log.useSource(prev); |
|
1330 |
} |
|
1331 |
||
1332 |
} |
|
1333 |
||
1334 |
/** Generates the source or class file for a list of classes. |
|
1335 |
* The decision to generate a source file or a class file is |
|
1336 |
* based upon the compiler's options. |
|
1337 |
* Generation stops if an error occurs while writing files. |
|
1338 |
*/ |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1339 |
public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue) { |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1340 |
generate(queue, null); |
10 | 1341 |
} |
1342 |
||
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
1343 |
public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue, Queue<JavaFileObject> results) { |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1344 |
if (shouldStop(CompileState.GENERATE)) |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1345 |
return; |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1346 |
|
10 | 1347 |
boolean usePrintSource = (stubOutput || sourceOutput || printFlat); |
1348 |
||
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1349 |
for (Pair<Env<AttrContext>, JCClassDecl> x: queue) { |
10 | 1350 |
Env<AttrContext> env = x.fst; |
1351 |
JCClassDecl cdef = x.snd; |
|
1352 |
||
1353 |
if (verboseCompilePolicy) { |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1354 |
printNote("[generate " |
10 | 1355 |
+ (usePrintSource ? " source" : "code") |
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
1356 |
+ " " + cdef.sym + "]"); |
10 | 1357 |
} |
1358 |
||
1359 |
if (taskListener != null) { |
|
1360 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.GENERATE, env.toplevel, cdef.sym); |
|
1361 |
taskListener.started(e); |
|
1362 |
} |
|
1363 |
||
1364 |
JavaFileObject prev = log.useSource(env.enclClass.sym.sourcefile != null ? |
|
1365 |
env.enclClass.sym.sourcefile : |
|
1366 |
env.toplevel.sourcefile); |
|
1367 |
try { |
|
1368 |
JavaFileObject file; |
|
1369 |
if (usePrintSource) |
|
1370 |
file = printSource(env, cdef); |
|
1371 |
else |
|
1372 |
file = genCode(env, cdef); |
|
1373 |
if (results != null && file != null) |
|
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
1374 |
results.add(file); |
10 | 1375 |
} catch (IOException ex) { |
1376 |
log.error(cdef.pos(), "class.cant.write", |
|
1377 |
cdef.sym, ex.getMessage()); |
|
1378 |
return; |
|
1379 |
} finally { |
|
1380 |
log.useSource(prev); |
|
1381 |
} |
|
1382 |
||
1383 |
if (taskListener != null) { |
|
1384 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.GENERATE, env.toplevel, cdef.sym); |
|
1385 |
taskListener.finished(e); |
|
1386 |
} |
|
1387 |
} |
|
1388 |
} |
|
1389 |
||
1390 |
// where |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1391 |
Map<JCCompilationUnit, Queue<Env<AttrContext>>> groupByFile(Queue<Env<AttrContext>> envs) { |
10 | 1392 |
// use a LinkedHashMap to preserve the order of the original list as much as possible |
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1393 |
Map<JCCompilationUnit, Queue<Env<AttrContext>>> map = new LinkedHashMap<JCCompilationUnit, Queue<Env<AttrContext>>>(); |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1394 |
for (Env<AttrContext> env: envs) { |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1395 |
Queue<Env<AttrContext>> sublist = map.get(env.toplevel); |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1396 |
if (sublist == null) { |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1397 |
sublist = new ListBuffer<Env<AttrContext>>(); |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1398 |
map.put(env.toplevel, sublist); |
10 | 1399 |
} |
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1400 |
sublist.add(env); |
10 | 1401 |
} |
1402 |
return map; |
|
1403 |
} |
|
1404 |
||
1405 |
JCClassDecl removeMethodBodies(JCClassDecl cdef) { |
|
1406 |
final boolean isInterface = (cdef.mods.flags & Flags.INTERFACE) != 0; |
|
1407 |
class MethodBodyRemover extends TreeTranslator { |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1408 |
@Override |
10 | 1409 |
public void visitMethodDef(JCMethodDecl tree) { |
1410 |
tree.mods.flags &= ~Flags.SYNCHRONIZED; |
|
1411 |
for (JCVariableDecl vd : tree.params) |
|
1412 |
vd.mods.flags &= ~Flags.FINAL; |
|
1413 |
tree.body = null; |
|
1414 |
super.visitMethodDef(tree); |
|
1415 |
} |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1416 |
@Override |
10 | 1417 |
public void visitVarDef(JCVariableDecl tree) { |
1418 |
if (tree.init != null && tree.init.type.constValue() == null) |
|
1419 |
tree.init = null; |
|
1420 |
super.visitVarDef(tree); |
|
1421 |
} |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1422 |
@Override |
10 | 1423 |
public void visitClassDef(JCClassDecl tree) { |
1424 |
ListBuffer<JCTree> newdefs = lb(); |
|
1425 |
for (List<JCTree> it = tree.defs; it.tail != null; it = it.tail) { |
|
1426 |
JCTree t = it.head; |
|
1427 |
switch (t.getTag()) { |
|
1428 |
case JCTree.CLASSDEF: |
|
1429 |
if (isInterface || |
|
1430 |
(((JCClassDecl) t).mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 || |
|
1431 |
(((JCClassDecl) t).mods.flags & (Flags.PRIVATE)) == 0 && ((JCClassDecl) t).sym.packge().getQualifiedName() == names.java_lang) |
|
1432 |
newdefs.append(t); |
|
1433 |
break; |
|
1434 |
case JCTree.METHODDEF: |
|
1435 |
if (isInterface || |
|
1436 |
(((JCMethodDecl) t).mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 || |
|
1437 |
((JCMethodDecl) t).sym.name == names.init || |
|
1438 |
(((JCMethodDecl) t).mods.flags & (Flags.PRIVATE)) == 0 && ((JCMethodDecl) t).sym.packge().getQualifiedName() == names.java_lang) |
|
1439 |
newdefs.append(t); |
|
1440 |
break; |
|
1441 |
case JCTree.VARDEF: |
|
1442 |
if (isInterface || (((JCVariableDecl) t).mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 || |
|
1443 |
(((JCVariableDecl) t).mods.flags & (Flags.PRIVATE)) == 0 && ((JCVariableDecl) t).sym.packge().getQualifiedName() == names.java_lang) |
|
1444 |
newdefs.append(t); |
|
1445 |
break; |
|
1446 |
default: |
|
1447 |
break; |
|
1448 |
} |
|
1449 |
} |
|
1450 |
tree.defs = newdefs.toList(); |
|
1451 |
super.visitClassDef(tree); |
|
1452 |
} |
|
1453 |
} |
|
1454 |
MethodBodyRemover r = new MethodBodyRemover(); |
|
1455 |
return r.translate(cdef); |
|
1456 |
} |
|
1457 |
||
1458 |
public void reportDeferredDiagnostics() { |
|
1459 |
if (annotationProcessingOccurred |
|
1460 |
&& implicitSourceFilesRead |
|
1461 |
&& implicitSourcePolicy == ImplicitSourcePolicy.UNSET) { |
|
1462 |
if (explicitAnnotationProcessingRequested()) |
|
1463 |
log.warning("proc.use.implicit"); |
|
1464 |
else |
|
1465 |
log.warning("proc.use.proc.or.implicit"); |
|
1466 |
} |
|
1467 |
chk.reportDeferredDiagnostics(); |
|
1468 |
} |
|
1469 |
||
1470 |
/** Close the compiler, flushing the logs |
|
1471 |
*/ |
|
1472 |
public void close() { |
|
1473 |
close(true); |
|
1474 |
} |
|
1475 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1258
diff
changeset
|
1476 |
public void close(boolean disposeNames) { |
10 | 1477 |
rootClasses = null; |
1478 |
reader = null; |
|
1479 |
make = null; |
|
1480 |
writer = null; |
|
1481 |
enter = null; |
|
1482 |
if (todo != null) |
|
1483 |
todo.clear(); |
|
1484 |
todo = null; |
|
1485 |
parserFactory = null; |
|
1486 |
syms = null; |
|
1487 |
source = null; |
|
1488 |
attr = null; |
|
1489 |
chk = null; |
|
1490 |
gen = null; |
|
1491 |
flow = null; |
|
1492 |
transTypes = null; |
|
1493 |
lower = null; |
|
1494 |
annotate = null; |
|
1495 |
types = null; |
|
1496 |
||
1497 |
log.flush(); |
|
1498 |
try { |
|
1499 |
fileManager.flush(); |
|
1500 |
} catch (IOException e) { |
|
1501 |
throw new Abort(e); |
|
1502 |
} finally { |
|
1503 |
if (names != null && disposeNames) |
|
1504 |
names.dispose(); |
|
1505 |
names = null; |
|
1506 |
} |
|
1507 |
} |
|
1508 |
||
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1509 |
protected void printNote(String lines) { |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1510 |
Log.printLines(log.noticeWriter, lines); |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1511 |
} |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1512 |
|
10 | 1513 |
/** Output for "-verbose" option. |
1514 |
* @param key The key to look up the correct internationalized string. |
|
1515 |
* @param arg An argument for substitution into the output string. |
|
1516 |
*/ |
|
1517 |
protected void printVerbose(String key, Object arg) { |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1518 |
Log.printLines(log.noticeWriter, Log.getLocalizedString("verbose." + key, arg)); |
10 | 1519 |
} |
1520 |
||
1521 |
/** Print numbers of errors and warnings. |
|
1522 |
*/ |
|
1523 |
protected void printCount(String kind, int count) { |
|
1524 |
if (count != 0) { |
|
1525 |
String text; |
|
1526 |
if (count == 1) |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1527 |
text = Log.getLocalizedString("count." + kind, String.valueOf(count)); |
10 | 1528 |
else |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1529 |
text = Log.getLocalizedString("count." + kind + ".plural", String.valueOf(count)); |
10 | 1530 |
Log.printLines(log.errWriter, text); |
1531 |
log.errWriter.flush(); |
|
1532 |
} |
|
1533 |
} |
|
1534 |
||
1535 |
private static long now() { |
|
1536 |
return System.currentTimeMillis(); |
|
1537 |
} |
|
1538 |
||
1539 |
private static long elapsed(long then) { |
|
1540 |
return now() - then; |
|
1541 |
} |
|
1542 |
||
1543 |
public void initRound(JavaCompiler prev) { |
|
1544 |
keepComments = prev.keepComments; |
|
1545 |
start_msec = prev.start_msec; |
|
1546 |
hasBeenUsed = true; |
|
1547 |
} |
|
1548 |
||
1549 |
public static void enableLogging() { |
|
1550 |
Logger logger = Logger.getLogger(com.sun.tools.javac.Main.class.getPackage().getName()); |
|
1551 |
logger.setLevel(Level.ALL); |
|
1552 |
for (Handler h : logger.getParent().getHandlers()) { |
|
1553 |
h.setLevel(Level.ALL); |
|
1554 |
} |
|
1555 |
||
1556 |
} |
|
1557 |
} |