7010608: the string 'error' should appear in error messages
authorjjg
Mon, 14 Mar 2011 11:42:15 -0700
changeset 8843 2602bd5c9c5f
parent 8842 d532916921b7
child 8844 18170a311747
7010608: the string 'error' should appear in error messages Reviewed-by: mcimadamore
langtools/src/share/classes/com/sun/tools/javac/util/BasicDiagnosticFormatter.java
langtools/test/tools/apt/Compile/golden.txt
langtools/test/tools/javac/4846262/Test.out
langtools/test/tools/javac/Diagnostics/6769027/T6769027.java
langtools/test/tools/javac/Diagnostics/7010608/Test.java
langtools/test/tools/javac/diags/examples/CountError.java
langtools/test/tools/javac/diags/examples/CountErrorPlural.java
langtools/test/tools/javac/diags/examples/IdentifierExpected.java
langtools/test/tools/javac/diags/examples/KindnameClass.java
langtools/test/tools/javac/diags/examples/KindnameConstructor.java
langtools/test/tools/javac/diags/examples/KindnameMethod.java
langtools/test/tools/javac/diags/examples/KindnameVariable.java
--- a/langtools/src/share/classes/com/sun/tools/javac/util/BasicDiagnosticFormatter.java	Mon Mar 14 11:33:33 2011 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/BasicDiagnosticFormatter.java	Mon Mar 14 11:42:15 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -26,6 +26,7 @@
 package com.sun.tools.javac.util;
 
 import java.util.Collection;
+import java.util.EnumMap;
 import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.Locale;
@@ -226,17 +227,14 @@
                             DiagnosticPart.SOURCE));
             initFormat();
             initIndentation();
+            if (options.isSet("oldDiags"))
+                initOldFormat();
             String fmt = options.get("diagsFormat");
             if (fmt != null) {
-                String[] formats = fmt.split("\\|");
-                switch (formats.length) {
-                    case 3:
-                        setFormat(BasicFormatKind.DEFAULT_CLASS_FORMAT, formats[2]);
-                    case 2:
-                        setFormat(BasicFormatKind.DEFAULT_NO_POS_FORMAT, formats[1]);
-                    default:
-                        setFormat(BasicFormatKind.DEFAULT_POS_FORMAT, formats[0]);
-                }
+                if (fmt.equals("OLD"))
+                    initOldFormat();
+                else
+                    initFormats(fmt);
             }
             String srcPos = null;
             if ((((srcPos = options.get("sourcePosition")) != null)) &&
@@ -280,14 +278,35 @@
             initFormat();
             initIndentation();
         }
-        //where
+
         private void initFormat() {
-            availableFormats = new HashMap<BasicFormatKind, String>();
-            setFormat(BasicFormatKind.DEFAULT_POS_FORMAT, "%f:%l:%_%t%L%m");
-            setFormat(BasicFormatKind.DEFAULT_NO_POS_FORMAT, "%p%L%m");
-            setFormat(BasicFormatKind.DEFAULT_CLASS_FORMAT, "%f:%_%t%L%m");
+            initFormats("%f:%l:%_%p%L%m", "%p%L%m", "%f:%_%p%L%m");
+        }
+
+        private void initOldFormat() {
+            initFormats("%f:%l:%_%t%L%m", "%p%L%m", "%f:%_%t%L%m");
+        }
+
+        private void initFormats(String pos, String nopos, String clazz) {
+            availableFormats = new EnumMap<BasicFormatKind, String>(BasicFormatKind.class);
+            setFormat(BasicFormatKind.DEFAULT_POS_FORMAT,    pos);
+            setFormat(BasicFormatKind.DEFAULT_NO_POS_FORMAT, nopos);
+            setFormat(BasicFormatKind.DEFAULT_CLASS_FORMAT,  clazz);
         }
-        //where
+
+        @SuppressWarnings("fallthrough")
+        private void initFormats(String fmt) {
+            String[] formats = fmt.split("\\|");
+            switch (formats.length) {
+                case 3:
+                    setFormat(BasicFormatKind.DEFAULT_CLASS_FORMAT, formats[2]);
+                case 2:
+                    setFormat(BasicFormatKind.DEFAULT_NO_POS_FORMAT, formats[1]);
+                default:
+                    setFormat(BasicFormatKind.DEFAULT_POS_FORMAT, formats[0]);
+            }
+        }
+
         private void initIndentation() {
             indentationLevels = new HashMap<DiagnosticPart, Integer>();
             setIndentation(DiagnosticPart.SUMMARY, 0);
--- a/langtools/test/tools/apt/Compile/golden.txt	Mon Mar 14 11:33:33 2011 -0700
+++ b/langtools/test/tools/apt/Compile/golden.txt	Mon Mar 14 11:42:15 2011 -0700
@@ -1,6 +1,6 @@
 error: It's a mad, mad, mad, mad world
 error: Something wicked this way comes
-HelloWorld.java:2: Boring class name
+HelloWorld.java:2: error: Boring class name
 public class HelloWorld {
        ^
 3 errors
--- a/langtools/test/tools/javac/4846262/Test.out	Mon Mar 14 11:33:33 2011 -0700
+++ b/langtools/test/tools/javac/4846262/Test.out	Mon Mar 14 11:42:15 2011 -0700
@@ -1,7 +1,7 @@
-Test.java:4: not a statement
+Test.java:4: error: not a statement
         abcdefg
         ^
-Test.java:4: ';' expected
+Test.java:4: error: ';' expected
         abcdefg
                ^
 2 errors
--- a/langtools/test/tools/javac/Diagnostics/6769027/T6769027.java	Mon Mar 14 11:33:33 2011 -0700
+++ b/langtools/test/tools/javac/Diagnostics/6769027/T6769027.java	Mon Mar 14 11:42:15 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 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
@@ -261,7 +261,7 @@
 
     enum PositionKind {
         NOPOS(Position.NOPOS, "- ", "error: "),
-        POS(5, "Test.java:1:6: ", "/Test.java:1: ");
+        POS(5, "Test.java:1:6: ", "/Test.java:1: error: ");
 
         int pos;
         String rawOutput;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/Diagnostics/7010608/Test.java	Mon Mar 14 11:42:15 2011 -0700
@@ -0,0 +1,92 @@
+/*
+ * 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 7010608
+ * @summary the string 'error' should appear in error messages
+ */
+
+import java.io.*;
+import java.net.URI;
+import java.util.*;
+import javax.tools.*;
+import javax.tools.JavaCompiler.CompilationTask;
+
+public class Test {
+    public static void main(String... args) throws Exception {
+        new Test().run();
+    }
+
+    void run() throws Exception {
+        Locale prev = Locale.getDefault();
+        Locale.setDefault(Locale.ENGLISH);
+        try {
+            test(Arrays.<String>asList(),
+                    "myfo://test:1: error: cannot find symbol");
+            test(Arrays.asList("-XDdiagsFormat=OLD"),
+                    "myfo://test:1: cannot find symbol");
+            test(Arrays.asList("-XDoldDiags"),
+                    "myfo://test:1: cannot find symbol");
+        } finally {
+            Locale.setDefault(prev);
+        }
+    }
+
+    void test(List<String> options, String expect) throws Exception {
+        System.err.println("test: " + options);
+        JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter(sw);
+        JavaFileObject f = new MyFileObject("myfo://test", "class Bad { Missing x; }");
+        List<? extends JavaFileObject> files = Arrays.asList(f);
+        CompilationTask task = javac.getTask(pw, null, null, options, null, files);
+        boolean ok = task.call();
+        pw.close();
+        String out = sw.toString();
+        if (!out.isEmpty())
+            System.err.println(out);
+        if (ok)
+            throw new Exception("Compilation succeeded unexpectedly");
+        if (!out.contains(expect))
+            throw new Exception("expected text not found: " + expect);
+    }
+
+    class MyFileObject extends SimpleJavaFileObject {
+        MyFileObject(String uri, String text) {
+            super(URI.create(uri), JavaFileObject.Kind.SOURCE);
+            this.text = text;
+        }
+        @Override
+        public String getName() {
+            return uri.toString();
+        }
+        @Override
+        public String getCharContent(boolean ignoreEncodingErrors) {
+            return text;
+        }
+        final String text;
+    }
+}
+
+
--- a/langtools/test/tools/javac/diags/examples/CountError.java	Mon Mar 14 11:33:33 2011 -0700
+++ b/langtools/test/tools/javac/diags/examples/CountError.java	Mon Mar 14 11:42:15 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -23,6 +23,7 @@
 
 // key: compiler.misc.count.error
 // key: compiler.err.unreported.exception.need.to.catch.or.throw
+// key: compiler.err.error
 // run: backdoor
 
 class CountError {
--- a/langtools/test/tools/javac/diags/examples/CountErrorPlural.java	Mon Mar 14 11:33:33 2011 -0700
+++ b/langtools/test/tools/javac/diags/examples/CountErrorPlural.java	Mon Mar 14 11:42:15 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -23,6 +23,7 @@
 
 // key: compiler.misc.count.error.plural
 // key: compiler.err.unreported.exception.need.to.catch.or.throw
+// key: compiler.err.error
 // run: backdoor
 
 class CountErrorPlural {
--- a/langtools/test/tools/javac/diags/examples/IdentifierExpected.java	Mon Mar 14 11:33:33 2011 -0700
+++ b/langtools/test/tools/javac/diags/examples/IdentifierExpected.java	Mon Mar 14 11:42:15 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -25,6 +25,7 @@
 // key: compiler.err.expected
 // key: compiler.err.invalid.binary.number
 // key: compiler.misc.count.error.plural
+// key: compiler.err.error
 // run: backdoor
 
 class IdentifierExpected {
--- a/langtools/test/tools/javac/diags/examples/KindnameClass.java	Mon Mar 14 11:33:33 2011 -0700
+++ b/langtools/test/tools/javac/diags/examples/KindnameClass.java	Mon Mar 14 11:42:15 2011 -0700
@@ -25,6 +25,7 @@
 // key: compiler.err.cant.resolve.location
 // key: compiler.misc.location
 // key: compiler.misc.count.error
+// key: compiler.err.error
 // run: backdoor
 
 class KindnameClass {
--- a/langtools/test/tools/javac/diags/examples/KindnameConstructor.java	Mon Mar 14 11:33:33 2011 -0700
+++ b/langtools/test/tools/javac/diags/examples/KindnameConstructor.java	Mon Mar 14 11:42:15 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -28,6 +28,7 @@
 // key: compiler.misc.arg.length.mismatch
 // key: compiler.misc.no.conforming.assignment.exists
 // key: compiler.misc.count.error.plural
+// key: compiler.err.error
 // run: backdoor
 
 class KindnameConstructor {
--- a/langtools/test/tools/javac/diags/examples/KindnameMethod.java	Mon Mar 14 11:33:33 2011 -0700
+++ b/langtools/test/tools/javac/diags/examples/KindnameMethod.java	Mon Mar 14 11:42:15 2011 -0700
@@ -26,6 +26,7 @@
 // key: compiler.err.cant.resolve.location.args
 // key: compiler.misc.location
 // key: compiler.misc.count.error
+// key: compiler.err.error
 // run: backdoor
 
 class KindnameMethod {
--- a/langtools/test/tools/javac/diags/examples/KindnameVariable.java	Mon Mar 14 11:33:33 2011 -0700
+++ b/langtools/test/tools/javac/diags/examples/KindnameVariable.java	Mon Mar 14 11:42:15 2011 -0700
@@ -26,6 +26,7 @@
 // key: compiler.err.cant.resolve.location
 // key: compiler.misc.location
 // key: compiler.misc.count.error
+// key: compiler.err.error
 // run: backdoor
 
 class KindnameVariable {