changeset 987:0f9e5b7f0d7e

6988079: Errors reported via Messager.printMessage(ERROR,"error message") are not tallied correctly Reviewed-by: darcy
author jjg
date Tue, 15 Mar 2011 11:48:55 -0700
parents edf03ca74991
children 480de7832e2f
files src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java test/tools/javac/processing/6994946/SemanticErrorTest.2.out test/tools/javac/processing/errors/TestErrorCount.java test/tools/javac/processing/errors/TestErrorCount.out
diffstat 4 files changed, 62 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Tue Mar 15 11:41:21 2011 -0700
+++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Tue Mar 15 11:48:55 2011 -0700
@@ -820,13 +820,17 @@
         /** The set of package-info files to be processed this round. */
         List<PackageSymbol> packageInfoFiles;
 
+        /** The number of Messager errors generated in this round. */
+        int nMessagerErrors;
+
         /** Create a round (common code). */
-        private Round(Context context, int number, int priorWarnings) {
+        private Round(Context context, int number, int priorErrors, int priorWarnings) {
             this.context = context;
             this.number = number;
 
             compiler = JavaCompiler.instance(context);
             log = Log.instance(context);
+            log.nerrors = priorErrors;
             log.nwarnings += priorWarnings;
             log.deferDiagnostics = true;
 
@@ -840,7 +844,7 @@
 
         /** Create the first round. */
         Round(Context context, List<JCCompilationUnit> roots, List<ClassSymbol> classSymbols) {
-            this(context, 1, 0);
+            this(context, 1, 0, 0);
             this.roots = roots;
             genClassFiles = new HashMap<String,JavaFileObject>();
 
@@ -860,7 +864,10 @@
         /** Create a new round. */
         private Round(Round prev,
                 Set<JavaFileObject> newSourceFiles, Map<String,JavaFileObject> newClassFiles) {
-            this(prev.nextContext(), prev.number+1, prev.compiler.log.nwarnings);
+            this(prev.nextContext(),
+                    prev.number+1,
+                    prev.nMessagerErrors,
+                    prev.compiler.log.nwarnings);
             this.genClassFiles = prev.genClassFiles;
 
             List<JCCompilationUnit> parsedFiles = compiler.parseFiles(newSourceFiles);
@@ -1014,6 +1021,8 @@
                 if (taskListener != null)
                     taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND));
             }
+
+            nMessagerErrors = messager.errorCount();
         }
 
         void showDiagnostics(boolean showAll) {
--- a/test/tools/javac/processing/6994946/SemanticErrorTest.2.out	Tue Mar 15 11:41:21 2011 -0700
+++ b/test/tools/javac/processing/6994946/SemanticErrorTest.2.out	Tue Mar 15 11:48:55 2011 -0700
@@ -1,4 +1,4 @@
 SemanticErrorTest.java:11:46: compiler.err.repeated.interface
 - compiler.err.proc.messager: Deliberate Error
 SemanticErrorTest.java:11:46: compiler.err.repeated.interface
-1 error
+2 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/processing/errors/TestErrorCount.java	Tue Mar 15 11:48:55 2011 -0700
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 6988079
+ * @summary Errors reported via Messager.printMessage(ERROR,"error message") are not tallied correctly
+ * @library ../../lib
+ * @build JavacTestingAbstractProcessor TestErrorCount
+ * @compile/fail/ref=TestErrorCount.out -XDrawDiagnostics -processor TestErrorCount TestErrorCount.java
+ */
+
+import java.io.*;
+import java.util.*;
+import javax.annotation.processing.*;
+import javax.lang.model.element.*;
+import javax.tools.*;
+
+public class TestErrorCount extends JavacTestingAbstractProcessor {
+    @Override
+    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+        messager.printMessage(Diagnostic.Kind.ERROR, "intentional error");
+        return true;
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/processing/errors/TestErrorCount.out	Tue Mar 15 11:48:55 2011 -0700
@@ -0,0 +1,3 @@
+- compiler.err.proc.messager: intentional error
+- compiler.err.proc.messager: intentional error
+2 errors