src/share/classes/com/sun/tools/javac/util/Log.java

changeset 664
4124840b35fe
parent 604
a5454419dd46
child 700
7b413ac1a720
equal deleted inserted replaced
663:eb7c263aab73 664:4124840b35fe
25 25
26 package com.sun.tools.javac.util; 26 package com.sun.tools.javac.util;
27 27
28 import java.io.*; 28 import java.io.*;
29 import java.util.Arrays; 29 import java.util.Arrays;
30 import java.util.EnumSet;
30 import java.util.HashSet; 31 import java.util.HashSet;
31 import java.util.Map; 32 import java.util.Map;
33 import java.util.Queue;
32 import java.util.Set; 34 import java.util.Set;
33 import javax.tools.DiagnosticListener; 35 import javax.tools.DiagnosticListener;
34 import javax.tools.JavaFileObject; 36 import javax.tools.JavaFileObject;
35 37
36 import com.sun.tools.javac.tree.JCTree; 38 import com.sun.tools.javac.tree.JCTree;
108 /** 110 /**
109 * JavacMessages object used for localization. 111 * JavacMessages object used for localization.
110 */ 112 */
111 private JavacMessages messages; 113 private JavacMessages messages;
112 114
115 /**
116 * Deferred diagnostics
117 */
118 public boolean deferDiagnostics;
119 public Queue<JCDiagnostic> deferredDiagnostics = new ListBuffer<JCDiagnostic>();
120
113 /** Construct a log with given I/O redirections. 121 /** Construct a log with given I/O redirections.
114 */ 122 */
115 @Deprecated 123 @Deprecated
116 protected Log(Context context, PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter) { 124 protected Log(Context context, PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter) {
117 super(JCDiagnostic.Factory.instance(context)); 125 super(JCDiagnostic.Factory.instance(context));
201 public int nerrors = 0; 209 public int nerrors = 0;
202 210
203 /** The number of warnings encountered so far. 211 /** The number of warnings encountered so far.
204 */ 212 */
205 public int nwarnings = 0; 213 public int nwarnings = 0;
206
207 /**
208 * Whether or not an unrecoverable error has been seen.
209 * Unrecoverable errors prevent subsequent annotation processing.
210 */
211 public boolean unrecoverableError;
212 214
213 /** A set of all errors generated so far. This is used to avoid printing an 215 /** A set of all errors generated so far. This is used to avoid printing an
214 * error message more than once. For each error, a pair consisting of the 216 * error message more than once. For each error, a pair consisting of the
215 * source file name and source code position of the error is added to the set. 217 * source file name and source code position of the error is added to the set.
216 */ 218 */
345 public void strictWarning(DiagnosticPosition pos, String key, Object ... args) { 347 public void strictWarning(DiagnosticPosition pos, String key, Object ... args) {
346 writeDiagnostic(diags.warning(source, pos, key, args)); 348 writeDiagnostic(diags.warning(source, pos, key, args));
347 nwarnings++; 349 nwarnings++;
348 } 350 }
349 351
352 /** Report all deferred diagnostics, and clear the deferDiagnostics flag. */
353 public void reportDeferredDiagnostics() {
354 reportDeferredDiagnostics(EnumSet.allOf(JCDiagnostic.Kind.class));
355 }
356
357 /** Report selected deferred diagnostics, and clear the deferDiagnostics flag. */
358 public void reportDeferredDiagnostics(Set<JCDiagnostic.Kind> kinds) {
359 deferDiagnostics = false;
360 JCDiagnostic d;
361 while ((d = deferredDiagnostics.poll()) != null) {
362 if (kinds.contains(d.getKind()))
363 report(d);
364 }
365 }
366
350 /** 367 /**
351 * Common diagnostic handling. 368 * Common diagnostic handling.
352 * The diagnostic is counted, and depending on the options and how many diagnostics have been 369 * The diagnostic is counted, and depending on the options and how many diagnostics have been
353 * reported so far, the diagnostic may be handed off to writeDiagnostic. 370 * reported so far, the diagnostic may be handed off to writeDiagnostic.
354 */ 371 */
355 public void report(JCDiagnostic diagnostic) { 372 public void report(JCDiagnostic diagnostic) {
373 if (deferDiagnostics) {
374 deferredDiagnostics.add(diagnostic);
375 return;
376 }
377
356 if (expectDiagKeys != null) 378 if (expectDiagKeys != null)
357 expectDiagKeys.remove(diagnostic.getCode()); 379 expectDiagKeys.remove(diagnostic.getCode());
358 380
359 switch (diagnostic.getType()) { 381 switch (diagnostic.getType()) {
360 case FRAGMENT: 382 case FRAGMENT:

mercurial