Thu, 29 Jan 2009 12:19:14 +0000
6729401: Compiler error when using F-bounded generics with free type variables
Summary: Javac applies wrong substitution to recursive type-variable bounds
Reviewed-by: jjg
1 /*
2 * Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved.
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 */
26 package com.sun.tools.javac.main;
28 import java.io.*;
29 import java.util.HashSet;
30 import java.util.LinkedHashSet;
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;
40 import javax.tools.JavaFileManager;
41 import javax.tools.JavaFileObject;
42 import javax.tools.DiagnosticListener;
44 import com.sun.tools.javac.file.JavacFileManager;
45 import com.sun.source.util.TaskEvent;
46 import com.sun.source.util.TaskListener;
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.*;
55 import com.sun.tools.javac.code.Symbol.*;
56 import com.sun.tools.javac.tree.JCTree.*;
58 import com.sun.tools.javac.processing.*;
59 import javax.annotation.processing.Processor;
61 import static javax.tools.StandardLocation.CLASS_OUTPUT;
62 import static com.sun.tools.javac.util.ListBuffer.lb;
64 // TEMP, until we have a more efficient way to save doc comment info
65 import com.sun.tools.javac.parser.DocCommentScanner;
67 import java.util.HashMap;
68 import java.util.Queue;
69 import javax.lang.model.SourceVersion;
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>();
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 }
94 /** The current version number as a string.
95 */
96 public static String version() {
97 return version("release"); // mm.nn.oo[-milestone]
98 }
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 }
106 private static final String versionRBName = "com.sun.tools.javac.resources.version";
107 private static ResourceBundle versionRB;
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 }
125 /**
126 * Control how the compiler's latter phases (attr, flow, desugar, generate)
127 * are connected. Each individual file is processed by each phase in turn,
128 * but with different compile policies, you can control the order in which
129 * each class is processed through its next phase.
130 *
131 * <p>Generally speaking, the compiler will "fail fast" in the face of
132 * errors, although not aggressively so. flow, desugar, etc become no-ops
133 * once any errors have occurred. No attempt is currently made to determine
134 * if it might be safe to process a class through its next phase because
135 * it does not depend on any unrelated errors that might have occurred.
136 */
137 protected static enum CompilePolicy {
138 /**
139 * Just attribute the parse trees.
140 */
141 ATTR_ONLY,
143 /**
144 * Just attribute and do flow analysis on the parse trees.
145 * This should catch most user errors.
146 */
147 CHECK_ONLY,
149 /**
150 * Attribute everything, then do flow analysis for everything,
151 * then desugar everything, and only then generate output.
152 * This means no output will be generated if there are any
153 * errors in any classes.
154 */
155 SIMPLE,
157 /**
158 * Groups the classes for each source file together, then process
159 * each group in a manner equivalent to the {@code SIMPLE} policy.
160 * This means no output will be generated if there are any
161 * errors in any of the classes in a source file.
162 */
163 BY_FILE,
165 /**
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;
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 }
191 private static CompilePolicy DEFAULT_COMPILE_POLICY = CompilePolicy.BY_TODO;
193 protected static enum ImplicitSourcePolicy {
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;
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 }
213 /** The log to be used for error reporting.
214 */
215 public Log log;
217 /** Factory for creating diagnostic objects
218 */
219 JCDiagnostic.Factory diagFactory;
221 /** The tree factory module.
222 */
223 protected TreeMaker make;
225 /** The class reader.
226 */
227 protected ClassReader reader;
229 /** The class writer.
230 */
231 protected ClassWriter writer;
233 /** The module for the symbol table entry phases.
234 */
235 protected Enter enter;
237 /** The symbol table.
238 */
239 protected Symtab syms;
241 /** The language version.
242 */
243 protected Source source;
245 /** The module for code generation.
246 */
247 protected Gen gen;
249 /** The name table.
250 */
251 protected Names names;
253 /** The attributor.
254 */
255 protected Attr attr;
257 /** The attributor.
258 */
259 protected Check chk;
261 /** The flow analyzer.
262 */
263 protected Flow flow;
265 /** The type eraser.
266 */
267 protected TransTypes transTypes;
269 /** The syntactic sugar desweetener.
270 */
271 protected Lower lower;
273 /** The annotation annotator.
274 */
275 protected Annotate annotate;
277 /** Force a completion failure on this name
278 */
279 protected final Name completionFailureName;
281 /** Type utilities.
282 */
283 protected Types types;
285 /** Access to file objects.
286 */
287 protected JavaFileManager fileManager;
289 /** Factory for parsers.
290 */
291 protected ParserFactory parserFactory;
293 /** Optional listener for progress events
294 */
295 protected TaskListener taskListener;
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;
303 /**
304 * Flag set if any annotation processing occurred.
305 **/
306 protected boolean annotationProcessingOccurred;
308 /**
309 * Flag set if any implicit source files read.
310 **/
311 protected boolean implicitSourceFilesRead;
313 protected Context context;
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);
321 // if fileManager not already set, register the JavacFileManager to be used
322 if (context.get(JavaFileManager.class) == null)
323 JavacFileManager.preRegister(context);
325 names = Names.instance(context);
326 log = Log.instance(context);
327 diagFactory = JCDiagnostic.Factory.instance(context);
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);
334 fileManager = context.get(JavaFileManager.class);
335 parserFactory = ParserFactory.instance(context);
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
342 log.error("cant.access", ex.sym, ex.getDetailValue());
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);
357 reader.sourceCompleter = this;
359 Options options = Options.instance(context);
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;
375 verboseCompilePolicy = options.get("verboseCompilePolicy") != null;
377 if (attrParseOnly)
378 compilePolicy = CompilePolicy.ATTR_ONLY;
379 else
380 compilePolicy = CompilePolicy.decode(options.get("compilePolicy"));
382 implicitSourcePolicy = ImplicitSourcePolicy.decode(options.get("-implicit"));
384 completionFailureName =
385 (options.get("failcomplete") != null)
386 ? names.fromString(options.get("failcomplete"))
387 : null;
388 }
390 /* Switches:
391 */
393 /** Verbose output.
394 */
395 public boolean verbose;
397 /** Emit plain Java source files rather than class files.
398 */
399 public boolean sourceOutput;
401 /** Emit stub source files rather than class files.
402 */
403 public boolean stubOutput;
405 /** Generate attributed parse tree only.
406 */
407 public boolean attrParseOnly;
409 /** Switch: relax some constraints for producing the jsr14 prototype.
410 */
411 boolean relax;
413 /** Debug switch: Emit Java sources after inner class flattening.
414 */
415 public boolean printFlat;
417 /** The encoding to be used for source input.
418 */
419 public String encoding;
421 /** Generate code with the LineNumberTable attribute for debugging
422 */
423 public boolean lineDebugInfo;
425 /** Switch: should we store the ending positions?
426 */
427 public boolean genEndPos;
429 /** Switch: should we debug ignored exceptions
430 */
431 protected boolean devVerbose;
433 /** Switch: should we (annotation) process packages as well
434 */
435 protected boolean processPcks;
437 /** Switch: is annotation processing requested explitly via
438 * CompilationTask.setProcessors?
439 */
440 protected boolean explicitAnnotationProcessingRequested = false;
442 /**
443 * The policy for the order in which to perform the compilation
444 */
445 protected CompilePolicy compilePolicy;
447 /**
448 * The policy for what to do with implicitly read source files
449 */
450 protected ImplicitSourcePolicy implicitSourcePolicy;
452 /**
453 * Report activity related to compilePolicy
454 */
455 public boolean verboseCompilePolicy;
457 /** A queue of all as yet unattributed classes.
458 */
459 public Todo todo;
461 protected enum CompileState {
462 TODO(0),
463 ATTR(1),
464 FLOW(2);
465 CompileState(int value) {
466 this.value = value;
467 }
468 boolean isDone(CompileState other) {
469 return value >= other.value;
470 }
471 private int value;
472 };
473 protected class CompileStates extends HashMap<Env<AttrContext>,CompileState> {
474 private static final long serialVersionUID = 1812267524140424433L;
475 boolean isDone(Env<AttrContext> env, CompileState cs) {
476 CompileState ecs = get(env);
477 return ecs != null && ecs.isDone(cs);
478 }
479 }
480 private CompileStates compileStates = new CompileStates();
482 /** The set of currently compiled inputfiles, needed to ensure
483 * we don't accidentally overwrite an input file when -s is set.
484 * initialized by `compile'.
485 */
486 protected Set<JavaFileObject> inputFiles = new HashSet<JavaFileObject>();
488 /** The number of errors reported so far.
489 */
490 public int errorCount() {
491 if (delegateCompiler != null && delegateCompiler != this)
492 return delegateCompiler.errorCount();
493 else
494 return log.nerrors;
495 }
497 protected final <T> Queue<T> stopIfError(Queue<T> queue) {
498 if (errorCount() == 0)
499 return queue;
500 else
501 return ListBuffer.lb();
502 }
504 protected final <T> List<T> stopIfError(List<T> list) {
505 if (errorCount() == 0)
506 return list;
507 else
508 return List.nil();
509 }
511 /** The number of warnings reported so far.
512 */
513 public int warningCount() {
514 if (delegateCompiler != null && delegateCompiler != this)
515 return delegateCompiler.warningCount();
516 else
517 return log.nwarnings;
518 }
520 /** Whether or not any parse errors have occurred.
521 */
522 public boolean parseErrors() {
523 return parseErrors;
524 }
526 /** Try to open input stream with given name.
527 * Report an error if this fails.
528 * @param filename The file name of the input stream to be opened.
529 */
530 public CharSequence readSource(JavaFileObject filename) {
531 try {
532 inputFiles.add(filename);
533 return filename.getCharContent(false);
534 } catch (IOException e) {
535 log.error("error.reading.file", filename, e.getLocalizedMessage());
536 return null;
537 }
538 }
540 /** Parse contents of input stream.
541 * @param filename The name of the file from which input stream comes.
542 * @param input The input stream to be parsed.
543 */
544 protected JCCompilationUnit parse(JavaFileObject filename, CharSequence content) {
545 long msec = now();
546 JCCompilationUnit tree = make.TopLevel(List.<JCTree.JCAnnotation>nil(),
547 null, List.<JCTree>nil());
548 if (content != null) {
549 if (verbose) {
550 printVerbose("parsing.started", filename);
551 }
552 if (taskListener != null) {
553 TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, filename);
554 taskListener.started(e);
555 }
556 int initialErrorCount = log.nerrors;
557 Parser parser = parserFactory.newParser(content, keepComments(), genEndPos, lineDebugInfo);
558 tree = parser.parseCompilationUnit();
559 parseErrors |= (log.nerrors > initialErrorCount);
560 if (verbose) {
561 printVerbose("parsing.done", Long.toString(elapsed(msec)));
562 }
563 }
565 tree.sourcefile = filename;
567 if (content != null && taskListener != null) {
568 TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, tree);
569 taskListener.finished(e);
570 }
572 return tree;
573 }
574 // where
575 public boolean keepComments = false;
576 protected boolean keepComments() {
577 return keepComments || sourceOutput || stubOutput;
578 }
581 /** Parse contents of file.
582 * @param filename The name of the file to be parsed.
583 */
584 @Deprecated
585 public JCTree.JCCompilationUnit parse(String filename) throws IOException {
586 JavacFileManager fm = (JavacFileManager)fileManager;
587 return parse(fm.getJavaFileObjectsFromStrings(List.of(filename)).iterator().next());
588 }
590 /** Parse contents of file.
591 * @param filename The name of the file to be parsed.
592 */
593 public JCTree.JCCompilationUnit parse(JavaFileObject filename) {
594 JavaFileObject prev = log.useSource(filename);
595 try {
596 JCTree.JCCompilationUnit t = parse(filename, readSource(filename));
597 if (t.endPositions != null)
598 log.setEndPosTable(filename, t.endPositions);
599 return t;
600 } finally {
601 log.useSource(prev);
602 }
603 }
605 /** Resolve an identifier.
606 * @param name The identifier to resolve
607 */
608 public Symbol resolveIdent(String name) {
609 if (name.equals(""))
610 return syms.errSymbol;
611 JavaFileObject prev = log.useSource(null);
612 try {
613 JCExpression tree = null;
614 for (String s : name.split("\\.", -1)) {
615 if (!SourceVersion.isIdentifier(s)) // TODO: check for keywords
616 return syms.errSymbol;
617 tree = (tree == null) ? make.Ident(names.fromString(s))
618 : make.Select(tree, names.fromString(s));
619 }
620 JCCompilationUnit toplevel =
621 make.TopLevel(List.<JCTree.JCAnnotation>nil(), null, List.<JCTree>nil());
622 toplevel.packge = syms.unnamedPackage;
623 return attr.attribIdent(tree, toplevel);
624 } finally {
625 log.useSource(prev);
626 }
627 }
629 /** Emit plain Java source for a class.
630 * @param env The attribution environment of the outermost class
631 * containing this class.
632 * @param cdef The class definition to be printed.
633 */
634 JavaFileObject printSource(Env<AttrContext> env, JCClassDecl cdef) throws IOException {
635 JavaFileObject outFile
636 = fileManager.getJavaFileForOutput(CLASS_OUTPUT,
637 cdef.sym.flatname.toString(),
638 JavaFileObject.Kind.SOURCE,
639 null);
640 if (inputFiles.contains(outFile)) {
641 log.error(cdef.pos(), "source.cant.overwrite.input.file", outFile);
642 return null;
643 } else {
644 BufferedWriter out = new BufferedWriter(outFile.openWriter());
645 try {
646 new Pretty(out, true).printUnit(env.toplevel, cdef);
647 if (verbose)
648 printVerbose("wrote.file", outFile);
649 } finally {
650 out.close();
651 }
652 return outFile;
653 }
654 }
656 /** Generate code and emit a class file for a given class
657 * @param env The attribution environment of the outermost class
658 * containing this class.
659 * @param cdef The class definition from which code is generated.
660 */
661 JavaFileObject genCode(Env<AttrContext> env, JCClassDecl cdef) throws IOException {
662 try {
663 if (gen.genClass(env, cdef))
664 return writer.writeClass(cdef.sym);
665 } catch (ClassWriter.PoolOverflow ex) {
666 log.error(cdef.pos(), "limit.pool");
667 } catch (ClassWriter.StringOverflow ex) {
668 log.error(cdef.pos(), "limit.string.overflow",
669 ex.value.substring(0, 20));
670 } catch (CompletionFailure ex) {
671 chk.completionError(cdef.pos(), ex);
672 }
673 return null;
674 }
676 /** Complete compiling a source file that has been accessed
677 * by the class file reader.
678 * @param c The class the source file of which needs to be compiled.
679 * @param filename The name of the source file.
680 * @param f An input stream that reads the source file.
681 */
682 public void complete(ClassSymbol c) throws CompletionFailure {
683 // System.err.println("completing " + c);//DEBUG
684 if (completionFailureName == c.fullname) {
685 throw new CompletionFailure(c, "user-selected completion failure by class name");
686 }
687 JCCompilationUnit tree;
688 JavaFileObject filename = c.classfile;
689 JavaFileObject prev = log.useSource(filename);
691 try {
692 tree = parse(filename, filename.getCharContent(false));
693 } catch (IOException e) {
694 log.error("error.reading.file", filename, e);
695 tree = make.TopLevel(List.<JCTree.JCAnnotation>nil(), null, List.<JCTree>nil());
696 } finally {
697 log.useSource(prev);
698 }
700 if (taskListener != null) {
701 TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, tree);
702 taskListener.started(e);
703 }
705 enter.complete(List.of(tree), c);
707 if (taskListener != null) {
708 TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, tree);
709 taskListener.finished(e);
710 }
712 if (enter.getEnv(c) == null) {
713 boolean isPkgInfo =
714 tree.sourcefile.isNameCompatible("package-info",
715 JavaFileObject.Kind.SOURCE);
716 if (isPkgInfo) {
717 if (enter.getEnv(tree.packge) == null) {
718 JCDiagnostic diag =
719 diagFactory.fragment("file.does.not.contain.package",
720 c.location());
721 throw reader.new BadClassFile(c, filename, diag);
722 }
723 } else {
724 JCDiagnostic diag =
725 diagFactory.fragment("file.doesnt.contain.class",
726 c.getQualifiedName());
727 throw reader.new BadClassFile(c, filename, diag);
728 }
729 }
731 implicitSourceFilesRead = true;
732 }
734 /** Track when the JavaCompiler has been used to compile something. */
735 private boolean hasBeenUsed = false;
736 private long start_msec = 0;
737 public long elapsed_msec = 0;
739 /** Track whether any errors occurred while parsing source text. */
740 private boolean parseErrors = false;
742 public void compile(List<JavaFileObject> sourceFileObject)
743 throws Throwable {
744 compile(sourceFileObject, List.<String>nil(), null);
745 }
747 /**
748 * Main method: compile a list of files, return all compiled classes
749 *
750 * @param sourceFileObjects file objects to be compiled
751 * @param classnames class names to process for annotations
752 * @param processors user provided annotation processors to bypass
753 * discovery, {@code null} means that no processors were provided
754 */
755 public void compile(List<JavaFileObject> sourceFileObjects,
756 List<String> classnames,
757 Iterable<? extends Processor> processors)
758 throws IOException // TODO: temp, from JavacProcessingEnvironment
759 {
760 if (processors != null && processors.iterator().hasNext())
761 explicitAnnotationProcessingRequested = true;
762 // as a JavaCompiler can only be used once, throw an exception if
763 // it has been used before.
764 if (hasBeenUsed)
765 throw new AssertionError("attempt to reuse JavaCompiler");
766 hasBeenUsed = true;
768 start_msec = now();
769 try {
770 initProcessAnnotations(processors);
772 // These method calls must be chained to avoid memory leaks
773 delegateCompiler = processAnnotations(enterTrees(stopIfError(parseFiles(sourceFileObjects))),
774 classnames);
776 delegateCompiler.compile2();
777 delegateCompiler.close();
778 elapsed_msec = delegateCompiler.elapsed_msec;
779 } catch (Abort ex) {
780 if (devVerbose)
781 ex.printStackTrace();
782 }
783 }
785 /**
786 * The phases following annotation processing: attribution,
787 * desugar, and finally code generation.
788 */
789 private void compile2() {
790 try {
791 switch (compilePolicy) {
792 case ATTR_ONLY:
793 attribute(todo);
794 break;
796 case CHECK_ONLY:
797 flow(attribute(todo));
798 break;
800 case SIMPLE:
801 generate(desugar(flow(attribute(todo))));
802 break;
804 case BY_FILE: {
805 Queue<Queue<Env<AttrContext>>> q = todo.groupByFile();
806 while (!q.isEmpty() && errorCount() == 0) {
807 generate(desugar(flow(attribute(q.remove()))));
808 }
809 }
810 break;
812 case BY_TODO:
813 while (!todo.isEmpty())
814 generate(desugar(flow(attribute(todo.remove()))));
815 break;
817 default:
818 assert false: "unknown compile policy";
819 }
820 } catch (Abort ex) {
821 if (devVerbose)
822 ex.printStackTrace();
823 }
825 if (verbose) {
826 elapsed_msec = elapsed(start_msec);
827 printVerbose("total", Long.toString(elapsed_msec));
828 }
830 reportDeferredDiagnostics();
832 if (!log.hasDiagnosticListener()) {
833 printCount("error", errorCount());
834 printCount("warn", warningCount());
835 }
836 }
838 private List<JCClassDecl> rootClasses;
840 /**
841 * Parses a list of files.
842 */
843 public List<JCCompilationUnit> parseFiles(List<JavaFileObject> fileObjects) throws IOException {
844 if (errorCount() > 0)
845 return List.nil();
847 //parse all files
848 ListBuffer<JCCompilationUnit> trees = lb();
849 for (JavaFileObject fileObject : fileObjects)
850 trees.append(parse(fileObject));
851 return trees.toList();
852 }
854 /**
855 * Enter the symbols found in a list of parse trees.
856 * As a side-effect, this puts elements on the "todo" list.
857 * Also stores a list of all top level classes in rootClasses.
858 */
859 public List<JCCompilationUnit> enterTrees(List<JCCompilationUnit> roots) {
860 //enter symbols for all files
861 if (taskListener != null) {
862 for (JCCompilationUnit unit: roots) {
863 TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, unit);
864 taskListener.started(e);
865 }
866 }
868 enter.main(roots);
870 if (taskListener != null) {
871 for (JCCompilationUnit unit: roots) {
872 TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, unit);
873 taskListener.finished(e);
874 }
875 }
877 //If generating source, remember the classes declared in
878 //the original compilation units listed on the command line.
879 if (sourceOutput || stubOutput) {
880 ListBuffer<JCClassDecl> cdefs = lb();
881 for (JCCompilationUnit unit : roots) {
882 for (List<JCTree> defs = unit.defs;
883 defs.nonEmpty();
884 defs = defs.tail) {
885 if (defs.head instanceof JCClassDecl)
886 cdefs.append((JCClassDecl)defs.head);
887 }
888 }
889 rootClasses = cdefs.toList();
890 }
891 return roots;
892 }
894 /**
895 * Set to true to enable skeleton annotation processing code.
896 * Currently, we assume this variable will be replaced more
897 * advanced logic to figure out if annotation processing is
898 * needed.
899 */
900 boolean processAnnotations = false;
902 /**
903 * Object to handle annotation processing.
904 */
905 JavacProcessingEnvironment procEnvImpl = null;
907 /**
908 * Check if we should process annotations.
909 * If so, and if no scanner is yet registered, then set up the DocCommentScanner
910 * to catch doc comments, and set keepComments so the parser records them in
911 * the compilation unit.
912 *
913 * @param processors user provided annotation processors to bypass
914 * discovery, {@code null} means that no processors were provided
915 */
916 public void initProcessAnnotations(Iterable<? extends Processor> processors) {
917 // Process annotations if processing is not disabled and there
918 // is at least one Processor available.
919 Options options = Options.instance(context);
920 if (options.get("-proc:none") != null) {
921 processAnnotations = false;
922 } else if (procEnvImpl == null) {
923 procEnvImpl = new JavacProcessingEnvironment(context, processors);
924 processAnnotations = procEnvImpl.atLeastOneProcessor();
926 if (processAnnotations) {
927 if (context.get(Scanner.Factory.scannerFactoryKey) == null)
928 DocCommentScanner.Factory.preRegister(context);
929 options.put("save-parameter-names", "save-parameter-names");
930 reader.saveParameterNames = true;
931 keepComments = true;
932 if (taskListener != null)
933 taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));
936 } else { // free resources
937 procEnvImpl.close();
938 }
939 }
940 }
942 // TODO: called by JavacTaskImpl
943 public JavaCompiler processAnnotations(List<JCCompilationUnit> roots) throws IOException {
944 return processAnnotations(roots, List.<String>nil());
945 }
947 /**
948 * Process any anotations found in the specifed compilation units.
949 * @param roots a list of compilation units
950 * @return an instance of the compiler in which to complete the compilation
951 */
952 public JavaCompiler processAnnotations(List<JCCompilationUnit> roots,
953 List<String> classnames)
954 throws IOException { // TODO: see TEMP note in JavacProcessingEnvironment
955 if (errorCount() != 0) {
956 // Errors were encountered. If todo is empty, then the
957 // encountered errors were parse errors. Otherwise, the
958 // errors were found during the enter phase which should
959 // be ignored when processing annotations.
961 if (todo.isEmpty())
962 return this;
963 }
965 // ASSERT: processAnnotations and procEnvImpl should have been set up by
966 // by initProcessAnnotations
968 // NOTE: The !classnames.isEmpty() checks should be refactored to Main.
970 if (!processAnnotations) {
971 // If there are no annotation processors present, and
972 // annotation processing is to occur with compilation,
973 // emit a warning.
974 Options options = Options.instance(context);
975 if (options.get("-proc:only") != null) {
976 log.warning("proc.proc-only.requested.no.procs");
977 todo.clear();
978 }
979 // If not processing annotations, classnames must be empty
980 if (!classnames.isEmpty()) {
981 log.error("proc.no.explicit.annotation.processing.requested",
982 classnames);
983 }
984 return this; // continue regular compilation
985 }
987 try {
988 List<ClassSymbol> classSymbols = List.nil();
989 List<PackageSymbol> pckSymbols = List.nil();
990 if (!classnames.isEmpty()) {
991 // Check for explicit request for annotation
992 // processing
993 if (!explicitAnnotationProcessingRequested()) {
994 log.error("proc.no.explicit.annotation.processing.requested",
995 classnames);
996 return this; // TODO: Will this halt compilation?
997 } else {
998 boolean errors = false;
999 for (String nameStr : classnames) {
1000 Symbol sym = resolveIdent(nameStr);
1001 if (sym == null || (sym.kind == Kinds.PCK && !processPcks)) {
1002 log.error("proc.cant.find.class", nameStr);
1003 errors = true;
1004 continue;
1005 }
1006 try {
1007 if (sym.kind == Kinds.PCK)
1008 sym.complete();
1009 if (sym.exists()) {
1010 Name name = names.fromString(nameStr);
1011 if (sym.kind == Kinds.PCK)
1012 pckSymbols = pckSymbols.prepend((PackageSymbol)sym);
1013 else
1014 classSymbols = classSymbols.prepend((ClassSymbol)sym);
1015 continue;
1016 }
1017 assert sym.kind == Kinds.PCK;
1018 log.warning("proc.package.does.not.exist", nameStr);
1019 pckSymbols = pckSymbols.prepend((PackageSymbol)sym);
1020 } catch (CompletionFailure e) {
1021 log.error("proc.cant.find.class", nameStr);
1022 errors = true;
1023 continue;
1024 }
1025 }
1026 if (errors)
1027 return this;
1028 }
1029 }
1030 JavaCompiler c = procEnvImpl.doProcessing(context, roots, classSymbols, pckSymbols);
1031 if (c != this)
1032 annotationProcessingOccurred = c.annotationProcessingOccurred = true;
1033 return c;
1034 } catch (CompletionFailure ex) {
1035 log.error("cant.access", ex.sym, ex.getDetailValue());
1036 return this;
1038 }
1039 }
1041 boolean explicitAnnotationProcessingRequested() {
1042 Options options = Options.instance(context);
1043 return
1044 explicitAnnotationProcessingRequested ||
1045 options.get("-processor") != null ||
1046 options.get("-processorpath") != null ||
1047 options.get("-proc:only") != null ||
1048 options.get("-Xprint") != null;
1049 }
1051 /**
1052 * Attribute a list of parse trees, such as found on the "todo" list.
1053 * Note that attributing classes may cause additional files to be
1054 * parsed and entered via the SourceCompleter.
1055 * Attribution of the entries in the list does not stop if any errors occur.
1056 * @returns a list of environments for attributd classes.
1057 */
1058 public Queue<Env<AttrContext>> attribute(Queue<Env<AttrContext>> envs) {
1059 ListBuffer<Env<AttrContext>> results = lb();
1060 while (!envs.isEmpty())
1061 results.append(attribute(envs.remove()));
1062 return results;
1063 }
1065 /**
1066 * Attribute a parse tree.
1067 * @returns the attributed parse tree
1068 */
1069 public Env<AttrContext> attribute(Env<AttrContext> env) {
1070 if (compileStates.isDone(env, CompileState.ATTR))
1071 return env;
1073 if (verboseCompilePolicy)
1074 log.printLines(log.noticeWriter, "[attribute " + env.enclClass.sym + "]");
1075 if (verbose)
1076 printVerbose("checking.attribution", env.enclClass.sym);
1078 if (taskListener != null) {
1079 TaskEvent e = new TaskEvent(TaskEvent.Kind.ANALYZE, env.toplevel, env.enclClass.sym);
1080 taskListener.started(e);
1081 }
1083 JavaFileObject prev = log.useSource(
1084 env.enclClass.sym.sourcefile != null ?
1085 env.enclClass.sym.sourcefile :
1086 env.toplevel.sourcefile);
1087 try {
1088 attr.attribClass(env.tree.pos(), env.enclClass.sym);
1089 compileStates.put(env, CompileState.ATTR);
1090 }
1091 finally {
1092 log.useSource(prev);
1093 }
1095 return env;
1096 }
1098 /**
1099 * Perform dataflow checks on attributed parse trees.
1100 * These include checks for definite assignment and unreachable statements.
1101 * If any errors occur, an empty list will be returned.
1102 * @returns the list of attributed parse trees
1103 */
1104 public Queue<Env<AttrContext>> flow(Queue<Env<AttrContext>> envs) {
1105 ListBuffer<Env<AttrContext>> results = lb();
1106 for (Env<AttrContext> env: envs) {
1107 flow(env, results);
1108 }
1109 return stopIfError(results);
1110 }
1112 /**
1113 * Perform dataflow checks on an attributed parse tree.
1114 */
1115 public Queue<Env<AttrContext>> flow(Env<AttrContext> env) {
1116 ListBuffer<Env<AttrContext>> results = lb();
1117 flow(env, results);
1118 return stopIfError(results);
1119 }
1121 /**
1122 * Perform dataflow checks on an attributed parse tree.
1123 */
1124 protected void flow(Env<AttrContext> env, Queue<Env<AttrContext>> results) {
1125 try {
1126 if (errorCount() > 0)
1127 return;
1129 if (relax || compileStates.isDone(env, CompileState.FLOW)) {
1130 results.add(env);
1131 return;
1132 }
1134 if (verboseCompilePolicy)
1135 log.printLines(log.noticeWriter, "[flow " + env.enclClass.sym + "]");
1136 JavaFileObject prev = log.useSource(
1137 env.enclClass.sym.sourcefile != null ?
1138 env.enclClass.sym.sourcefile :
1139 env.toplevel.sourcefile);
1140 try {
1141 make.at(Position.FIRSTPOS);
1142 TreeMaker localMake = make.forToplevel(env.toplevel);
1143 flow.analyzeTree(env.tree, localMake);
1144 compileStates.put(env, CompileState.FLOW);
1146 if (errorCount() > 0)
1147 return;
1149 results.add(env);
1150 }
1151 finally {
1152 log.useSource(prev);
1153 }
1154 }
1155 finally {
1156 if (taskListener != null) {
1157 TaskEvent e = new TaskEvent(TaskEvent.Kind.ANALYZE, env.toplevel, env.enclClass.sym);
1158 taskListener.finished(e);
1159 }
1160 }
1161 }
1163 /**
1164 * Prepare attributed parse trees, in conjunction with their attribution contexts,
1165 * for source or code generation.
1166 * If any errors occur, an empty list will be returned.
1167 * @returns a list containing the classes to be generated
1168 */
1169 public Queue<Pair<Env<AttrContext>, JCClassDecl>> desugar(Queue<Env<AttrContext>> envs) {
1170 ListBuffer<Pair<Env<AttrContext>, JCClassDecl>> results = lb();
1171 for (Env<AttrContext> env: envs)
1172 desugar(env, results);
1173 return stopIfError(results);
1174 }
1176 /**
1177 * Prepare attributed parse trees, in conjunction with their attribution contexts,
1178 * for source or code generation. If the file was not listed on the command line,
1179 * the current implicitSourcePolicy is taken into account.
1180 * The preparation stops as soon as an error is found.
1181 */
1182 protected void desugar(final Env<AttrContext> env, Queue<Pair<Env<AttrContext>, JCClassDecl>> results) {
1183 if (errorCount() > 0)
1184 return;
1186 if (implicitSourcePolicy == ImplicitSourcePolicy.NONE
1187 && !inputFiles.contains(env.toplevel.sourcefile)) {
1188 return;
1189 }
1191 /**
1192 * As erasure (TransTypes) destroys information needed in flow analysis,
1193 * including information in supertypes, we need to ensure that supertypes
1194 * are processed through attribute and flow before subtypes are translated.
1195 */
1196 class ScanNested extends TreeScanner {
1197 Set<Env<AttrContext>> dependencies = new LinkedHashSet<Env<AttrContext>>();
1198 public void visitClassDef(JCClassDecl node) {
1199 Type st = types.supertype(node.sym.type);
1200 if (st.tag == TypeTags.CLASS) {
1201 ClassSymbol c = st.tsym.outermostClass();
1202 Env<AttrContext> stEnv = enter.getEnv(c);
1203 if (stEnv != null && env != stEnv) {
1204 if (dependencies.add(stEnv))
1205 scan(stEnv.tree);
1206 }
1207 }
1208 super.visitClassDef(node);
1209 }
1210 }
1211 ScanNested scanner = new ScanNested();
1212 scanner.scan(env.tree);
1213 for (Env<AttrContext> dep: scanner.dependencies) {
1214 if (!compileStates.isDone(dep, CompileState.FLOW))
1215 flow(attribute(dep));
1216 }
1218 //We need to check for error another time as more classes might
1219 //have been attributed and analyzed at this stage
1220 if (errorCount() > 0)
1221 return;
1223 if (verboseCompilePolicy)
1224 log.printLines(log.noticeWriter, "[desugar " + env.enclClass.sym + "]");
1226 JavaFileObject prev = log.useSource(env.enclClass.sym.sourcefile != null ?
1227 env.enclClass.sym.sourcefile :
1228 env.toplevel.sourcefile);
1229 try {
1230 //save tree prior to rewriting
1231 JCTree untranslated = env.tree;
1233 make.at(Position.FIRSTPOS);
1234 TreeMaker localMake = make.forToplevel(env.toplevel);
1236 if (env.tree instanceof JCCompilationUnit) {
1237 if (!(stubOutput || sourceOutput || printFlat)) {
1238 List<JCTree> pdef = lower.translateTopLevelClass(env, env.tree, localMake);
1239 if (pdef.head != null) {
1240 assert pdef.tail.isEmpty();
1241 results.add(new Pair<Env<AttrContext>, JCClassDecl>(env, (JCClassDecl)pdef.head));
1242 }
1243 }
1244 return;
1245 }
1247 if (stubOutput) {
1248 //emit stub Java source file, only for compilation
1249 //units enumerated explicitly on the command line
1250 JCClassDecl cdef = (JCClassDecl)env.tree;
1251 if (untranslated instanceof JCClassDecl &&
1252 rootClasses.contains((JCClassDecl)untranslated) &&
1253 ((cdef.mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 ||
1254 cdef.sym.packge().getQualifiedName() == names.java_lang)) {
1255 results.add(new Pair<Env<AttrContext>, JCClassDecl>(env, removeMethodBodies(cdef)));
1256 }
1257 return;
1258 }
1260 env.tree = transTypes.translateTopLevelClass(env.tree, localMake);
1262 if (errorCount() != 0)
1263 return;
1265 if (sourceOutput) {
1266 //emit standard Java source file, only for compilation
1267 //units enumerated explicitly on the command line
1268 JCClassDecl cdef = (JCClassDecl)env.tree;
1269 if (untranslated instanceof JCClassDecl &&
1270 rootClasses.contains((JCClassDecl)untranslated)) {
1271 results.add(new Pair<Env<AttrContext>, JCClassDecl>(env, cdef));
1272 }
1273 return;
1274 }
1276 //translate out inner classes
1277 List<JCTree> cdefs = lower.translateTopLevelClass(env, env.tree, localMake);
1279 if (errorCount() != 0)
1280 return;
1282 //generate code for each class
1283 for (List<JCTree> l = cdefs; l.nonEmpty(); l = l.tail) {
1284 JCClassDecl cdef = (JCClassDecl)l.head;
1285 results.add(new Pair<Env<AttrContext>, JCClassDecl>(env, cdef));
1286 }
1287 }
1288 finally {
1289 log.useSource(prev);
1290 }
1292 }
1294 /** Generates the source or class file for a list of classes.
1295 * The decision to generate a source file or a class file is
1296 * based upon the compiler's options.
1297 * Generation stops if an error occurs while writing files.
1298 */
1299 public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue) {
1300 generate(queue, null);
1301 }
1303 public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue, Queue<JavaFileObject> results) {
1304 boolean usePrintSource = (stubOutput || sourceOutput || printFlat);
1306 for (Pair<Env<AttrContext>, JCClassDecl> x: queue) {
1307 Env<AttrContext> env = x.fst;
1308 JCClassDecl cdef = x.snd;
1310 if (verboseCompilePolicy) {
1311 log.printLines(log.noticeWriter, "[generate "
1312 + (usePrintSource ? " source" : "code")
1313 + " " + cdef.sym + "]");
1314 }
1316 if (taskListener != null) {
1317 TaskEvent e = new TaskEvent(TaskEvent.Kind.GENERATE, env.toplevel, cdef.sym);
1318 taskListener.started(e);
1319 }
1321 JavaFileObject prev = log.useSource(env.enclClass.sym.sourcefile != null ?
1322 env.enclClass.sym.sourcefile :
1323 env.toplevel.sourcefile);
1324 try {
1325 JavaFileObject file;
1326 if (usePrintSource)
1327 file = printSource(env, cdef);
1328 else
1329 file = genCode(env, cdef);
1330 if (results != null && file != null)
1331 results.add(file);
1332 } catch (IOException ex) {
1333 log.error(cdef.pos(), "class.cant.write",
1334 cdef.sym, ex.getMessage());
1335 return;
1336 } finally {
1337 log.useSource(prev);
1338 }
1340 if (taskListener != null) {
1341 TaskEvent e = new TaskEvent(TaskEvent.Kind.GENERATE, env.toplevel, cdef.sym);
1342 taskListener.finished(e);
1343 }
1344 }
1345 }
1347 // where
1348 Map<JCCompilationUnit, Queue<Env<AttrContext>>> groupByFile(Queue<Env<AttrContext>> envs) {
1349 // use a LinkedHashMap to preserve the order of the original list as much as possible
1350 Map<JCCompilationUnit, Queue<Env<AttrContext>>> map = new LinkedHashMap<JCCompilationUnit, Queue<Env<AttrContext>>>();
1351 for (Env<AttrContext> env: envs) {
1352 Queue<Env<AttrContext>> sublist = map.get(env.toplevel);
1353 if (sublist == null) {
1354 sublist = new ListBuffer<Env<AttrContext>>();
1355 map.put(env.toplevel, sublist);
1356 }
1357 sublist.add(env);
1358 }
1359 return map;
1360 }
1362 JCClassDecl removeMethodBodies(JCClassDecl cdef) {
1363 final boolean isInterface = (cdef.mods.flags & Flags.INTERFACE) != 0;
1364 class MethodBodyRemover extends TreeTranslator {
1365 public void visitMethodDef(JCMethodDecl tree) {
1366 tree.mods.flags &= ~Flags.SYNCHRONIZED;
1367 for (JCVariableDecl vd : tree.params)
1368 vd.mods.flags &= ~Flags.FINAL;
1369 tree.body = null;
1370 super.visitMethodDef(tree);
1371 }
1372 public void visitVarDef(JCVariableDecl tree) {
1373 if (tree.init != null && tree.init.type.constValue() == null)
1374 tree.init = null;
1375 super.visitVarDef(tree);
1376 }
1377 public void visitClassDef(JCClassDecl tree) {
1378 ListBuffer<JCTree> newdefs = lb();
1379 for (List<JCTree> it = tree.defs; it.tail != null; it = it.tail) {
1380 JCTree t = it.head;
1381 switch (t.getTag()) {
1382 case JCTree.CLASSDEF:
1383 if (isInterface ||
1384 (((JCClassDecl) t).mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 ||
1385 (((JCClassDecl) t).mods.flags & (Flags.PRIVATE)) == 0 && ((JCClassDecl) t).sym.packge().getQualifiedName() == names.java_lang)
1386 newdefs.append(t);
1387 break;
1388 case JCTree.METHODDEF:
1389 if (isInterface ||
1390 (((JCMethodDecl) t).mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 ||
1391 ((JCMethodDecl) t).sym.name == names.init ||
1392 (((JCMethodDecl) t).mods.flags & (Flags.PRIVATE)) == 0 && ((JCMethodDecl) t).sym.packge().getQualifiedName() == names.java_lang)
1393 newdefs.append(t);
1394 break;
1395 case JCTree.VARDEF:
1396 if (isInterface || (((JCVariableDecl) t).mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 ||
1397 (((JCVariableDecl) t).mods.flags & (Flags.PRIVATE)) == 0 && ((JCVariableDecl) t).sym.packge().getQualifiedName() == names.java_lang)
1398 newdefs.append(t);
1399 break;
1400 default:
1401 break;
1402 }
1403 }
1404 tree.defs = newdefs.toList();
1405 super.visitClassDef(tree);
1406 }
1407 }
1408 MethodBodyRemover r = new MethodBodyRemover();
1409 return r.translate(cdef);
1410 }
1412 public void reportDeferredDiagnostics() {
1413 if (annotationProcessingOccurred
1414 && implicitSourceFilesRead
1415 && implicitSourcePolicy == ImplicitSourcePolicy.UNSET) {
1416 if (explicitAnnotationProcessingRequested())
1417 log.warning("proc.use.implicit");
1418 else
1419 log.warning("proc.use.proc.or.implicit");
1420 }
1421 chk.reportDeferredDiagnostics();
1422 }
1424 /** Close the compiler, flushing the logs
1425 */
1426 public void close() {
1427 close(true);
1428 }
1430 public void close(boolean disposeNames) {
1431 rootClasses = null;
1432 reader = null;
1433 make = null;
1434 writer = null;
1435 enter = null;
1436 if (todo != null)
1437 todo.clear();
1438 todo = null;
1439 parserFactory = null;
1440 syms = null;
1441 source = null;
1442 attr = null;
1443 chk = null;
1444 gen = null;
1445 flow = null;
1446 transTypes = null;
1447 lower = null;
1448 annotate = null;
1449 types = null;
1451 log.flush();
1452 try {
1453 fileManager.flush();
1454 } catch (IOException e) {
1455 throw new Abort(e);
1456 } finally {
1457 if (names != null && disposeNames)
1458 names.dispose();
1459 names = null;
1460 }
1461 }
1463 /** Output for "-verbose" option.
1464 * @param key The key to look up the correct internationalized string.
1465 * @param arg An argument for substitution into the output string.
1466 */
1467 protected void printVerbose(String key, Object arg) {
1468 Log.printLines(log.noticeWriter, log.getLocalizedString("verbose." + key, arg));
1469 }
1471 /** Print numbers of errors and warnings.
1472 */
1473 protected void printCount(String kind, int count) {
1474 if (count != 0) {
1475 String text;
1476 if (count == 1)
1477 text = log.getLocalizedString("count." + kind, String.valueOf(count));
1478 else
1479 text = log.getLocalizedString("count." + kind + ".plural", String.valueOf(count));
1480 Log.printLines(log.errWriter, text);
1481 log.errWriter.flush();
1482 }
1483 }
1485 private static long now() {
1486 return System.currentTimeMillis();
1487 }
1489 private static long elapsed(long then) {
1490 return now() - then;
1491 }
1493 public void initRound(JavaCompiler prev) {
1494 keepComments = prev.keepComments;
1495 start_msec = prev.start_msec;
1496 hasBeenUsed = true;
1497 }
1499 public static void enableLogging() {
1500 Logger logger = Logger.getLogger(com.sun.tools.javac.Main.class.getPackage().getName());
1501 logger.setLevel(Level.ALL);
1502 for (Handler h : logger.getParent().getHandlers()) {
1503 h.setLevel(Level.ALL);
1504 }
1506 }
1507 }