src/share/classes/com/sun/tools/javac/main/JavaCompiler.java

changeset 664
4124840b35fe
parent 663
eb7c263aab73
child 676
bfdfc13fe641
     1.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Fri Aug 27 17:59:08 2010 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Mon Aug 30 18:03:35 2010 -0700
     1.3 @@ -59,6 +59,7 @@
     1.4  import javax.annotation.processing.Processor;
     1.5  
     1.6  import static javax.tools.StandardLocation.CLASS_OUTPUT;
     1.7 +import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
     1.8  import static com.sun.tools.javac.util.ListBuffer.lb;
     1.9  
    1.10  // TEMP, until we have a more efficient way to save doc comment info
    1.11 @@ -579,10 +580,8 @@
    1.12                  TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, filename);
    1.13                  taskListener.started(e);
    1.14              }
    1.15 -            int initialErrorCount = log.nerrors;
    1.16              Parser parser = parserFactory.newParser(content, keepComments(), genEndPos, lineDebugInfo);
    1.17              tree = parser.parseCompilationUnit();
    1.18 -            log.unrecoverableError |= (log.nerrors > initialErrorCount);
    1.19              if (verbose) {
    1.20                  printVerbose("parsing.done", Long.toString(elapsed(msec)));
    1.21              }
    1.22 @@ -967,8 +966,7 @@
    1.23                  keepComments = true;
    1.24                  if (taskListener != null)
    1.25                      taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));
    1.26 -
    1.27 -
    1.28 +                log.deferDiagnostics = true;
    1.29              } else { // free resources
    1.30                  procEnvImpl.close();
    1.31              }
    1.32 @@ -985,15 +983,23 @@
    1.33       * @param roots a list of compilation units
    1.34       * @return an instance of the compiler in which to complete the compilation
    1.35       */
    1.36 +    // Implementation note: when this method is called, log.deferredDiagnostics
    1.37 +    // will have been set true by initProcessAnnotations, meaning that any diagnostics
    1.38 +    // that are reported will go into the log.deferredDiagnostics queue.
    1.39 +    // By the time this method exits, log.deferDiagnostics must be set back to false,
    1.40 +    // and all deferredDiagnostics must have been handled: i.e. either reported
    1.41 +    // or determined to be transient, and therefore suppressed.
    1.42      public JavaCompiler processAnnotations(List<JCCompilationUnit> roots,
    1.43                                             List<String> classnames) {
    1.44          if (shouldStop(CompileState.PROCESS)) {
    1.45              // Errors were encountered.
    1.46 -            // If log.unrecoverableError is set, the errors were parse errors
    1.47 +            // Unless all the errors are resolve errors, the errors were parse errors
    1.48              // or other errors during enter which cannot be fixed by running
    1.49              // any annotation processors.
    1.50 -            if (log.unrecoverableError)
    1.51 +            if (unrecoverableError()) {
    1.52 +                log.reportDeferredDiagnostics();
    1.53                  return this;
    1.54 +            }
    1.55          }
    1.56  
    1.57          // ASSERT: processAnnotations and procEnvImpl should have been set up by
    1.58 @@ -1015,6 +1021,7 @@
    1.59                  log.error("proc.no.explicit.annotation.processing.requested",
    1.60                            classnames);
    1.61              }
    1.62 +            log.reportDeferredDiagnostics();
    1.63              return this; // continue regular compilation
    1.64          }
    1.65  
    1.66 @@ -1027,6 +1034,7 @@
    1.67                  if (!explicitAnnotationProcessingRequested()) {
    1.68                      log.error("proc.no.explicit.annotation.processing.requested",
    1.69                                classnames);
    1.70 +                    log.reportDeferredDiagnostics();
    1.71                      return this; // TODO: Will this halt compilation?
    1.72                  } else {
    1.73                      boolean errors = false;
    1.74 @@ -1041,7 +1049,6 @@
    1.75                              if (sym.kind == Kinds.PCK)
    1.76                                  sym.complete();
    1.77                              if (sym.exists()) {
    1.78 -                                Name name = names.fromString(nameStr);
    1.79                                  if (sym.kind == Kinds.PCK)
    1.80                                      pckSymbols = pckSymbols.prepend((PackageSymbol)sym);
    1.81                                  else
    1.82 @@ -1057,23 +1064,36 @@
    1.83                              continue;
    1.84                          }
    1.85                      }
    1.86 -                    if (errors)
    1.87 +                    if (errors) {
    1.88 +                        log.reportDeferredDiagnostics();
    1.89                          return this;
    1.90 +                    }
    1.91                  }
    1.92              }
    1.93              try {
    1.94                  JavaCompiler c = procEnvImpl.doProcessing(context, roots, classSymbols, pckSymbols);
    1.95                  if (c != this)
    1.96                      annotationProcessingOccurred = c.annotationProcessingOccurred = true;
    1.97 +                // doProcessing will have handled deferred diagnostics
    1.98 +                assert c.log.deferDiagnostics == false;
    1.99 +                assert c.log.deferredDiagnostics.size() == 0;
   1.100                  return c;
   1.101              } finally {
   1.102                  procEnvImpl.close();
   1.103              }
   1.104          } catch (CompletionFailure ex) {
   1.105              log.error("cant.access", ex.sym, ex.getDetailValue());
   1.106 +            log.reportDeferredDiagnostics();
   1.107              return this;
   1.108 +        }
   1.109 +    }
   1.110  
   1.111 +    private boolean unrecoverableError() {
   1.112 +        for (JCDiagnostic d: log.deferredDiagnostics) {
   1.113 +            if (d.getKind() == JCDiagnostic.Kind.ERROR && !d.isFlagSet(RESOLVE_ERROR))
   1.114 +                return true;
   1.115          }
   1.116 +        return false;
   1.117      }
   1.118  
   1.119      boolean explicitAnnotationProcessingRequested() {

mercurial