7010608: the string 'error' should appear in error messages

Mon, 14 Mar 2011 11:42:15 -0700

author
jjg
date
Mon, 14 Mar 2011 11:42:15 -0700
changeset 929
e2890b8369f7
parent 928
307b065ff2af
child 930
cb119107aeea

7010608: the string 'error' should appear in error messages
Reviewed-by: mcimadamore

src/share/classes/com/sun/tools/javac/util/BasicDiagnosticFormatter.java file | annotate | diff | comparison | revisions
test/tools/apt/Compile/golden.txt file | annotate | diff | comparison | revisions
test/tools/javac/4846262/Test.out file | annotate | diff | comparison | revisions
test/tools/javac/Diagnostics/6769027/T6769027.java file | annotate | diff | comparison | revisions
test/tools/javac/Diagnostics/7010608/Test.java file | annotate | diff | comparison | revisions
test/tools/javac/diags/examples/CountError.java file | annotate | diff | comparison | revisions
test/tools/javac/diags/examples/CountErrorPlural.java file | annotate | diff | comparison | revisions
test/tools/javac/diags/examples/IdentifierExpected.java file | annotate | diff | comparison | revisions
test/tools/javac/diags/examples/KindnameClass.java file | annotate | diff | comparison | revisions
test/tools/javac/diags/examples/KindnameConstructor.java file | annotate | diff | comparison | revisions
test/tools/javac/diags/examples/KindnameMethod.java file | annotate | diff | comparison | revisions
test/tools/javac/diags/examples/KindnameVariable.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/util/BasicDiagnosticFormatter.java	Mon Mar 14 11:33:33 2011 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/util/BasicDiagnosticFormatter.java	Mon Mar 14 11:42:15 2011 -0700
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -26,6 +26,7 @@
    1.11  package com.sun.tools.javac.util;
    1.12  
    1.13  import java.util.Collection;
    1.14 +import java.util.EnumMap;
    1.15  import java.util.EnumSet;
    1.16  import java.util.HashMap;
    1.17  import java.util.Locale;
    1.18 @@ -226,17 +227,14 @@
    1.19                              DiagnosticPart.SOURCE));
    1.20              initFormat();
    1.21              initIndentation();
    1.22 +            if (options.isSet("oldDiags"))
    1.23 +                initOldFormat();
    1.24              String fmt = options.get("diagsFormat");
    1.25              if (fmt != null) {
    1.26 -                String[] formats = fmt.split("\\|");
    1.27 -                switch (formats.length) {
    1.28 -                    case 3:
    1.29 -                        setFormat(BasicFormatKind.DEFAULT_CLASS_FORMAT, formats[2]);
    1.30 -                    case 2:
    1.31 -                        setFormat(BasicFormatKind.DEFAULT_NO_POS_FORMAT, formats[1]);
    1.32 -                    default:
    1.33 -                        setFormat(BasicFormatKind.DEFAULT_POS_FORMAT, formats[0]);
    1.34 -                }
    1.35 +                if (fmt.equals("OLD"))
    1.36 +                    initOldFormat();
    1.37 +                else
    1.38 +                    initFormats(fmt);
    1.39              }
    1.40              String srcPos = null;
    1.41              if ((((srcPos = options.get("sourcePosition")) != null)) &&
    1.42 @@ -280,14 +278,35 @@
    1.43              initFormat();
    1.44              initIndentation();
    1.45          }
    1.46 -        //where
    1.47 +
    1.48          private void initFormat() {
    1.49 -            availableFormats = new HashMap<BasicFormatKind, String>();
    1.50 -            setFormat(BasicFormatKind.DEFAULT_POS_FORMAT, "%f:%l:%_%t%L%m");
    1.51 -            setFormat(BasicFormatKind.DEFAULT_NO_POS_FORMAT, "%p%L%m");
    1.52 -            setFormat(BasicFormatKind.DEFAULT_CLASS_FORMAT, "%f:%_%t%L%m");
    1.53 +            initFormats("%f:%l:%_%p%L%m", "%p%L%m", "%f:%_%p%L%m");
    1.54          }
    1.55 -        //where
    1.56 +
    1.57 +        private void initOldFormat() {
    1.58 +            initFormats("%f:%l:%_%t%L%m", "%p%L%m", "%f:%_%t%L%m");
    1.59 +        }
    1.60 +
    1.61 +        private void initFormats(String pos, String nopos, String clazz) {
    1.62 +            availableFormats = new EnumMap<BasicFormatKind, String>(BasicFormatKind.class);
    1.63 +            setFormat(BasicFormatKind.DEFAULT_POS_FORMAT,    pos);
    1.64 +            setFormat(BasicFormatKind.DEFAULT_NO_POS_FORMAT, nopos);
    1.65 +            setFormat(BasicFormatKind.DEFAULT_CLASS_FORMAT,  clazz);
    1.66 +        }
    1.67 +
    1.68 +        @SuppressWarnings("fallthrough")
    1.69 +        private void initFormats(String fmt) {
    1.70 +            String[] formats = fmt.split("\\|");
    1.71 +            switch (formats.length) {
    1.72 +                case 3:
    1.73 +                    setFormat(BasicFormatKind.DEFAULT_CLASS_FORMAT, formats[2]);
    1.74 +                case 2:
    1.75 +                    setFormat(BasicFormatKind.DEFAULT_NO_POS_FORMAT, formats[1]);
    1.76 +                default:
    1.77 +                    setFormat(BasicFormatKind.DEFAULT_POS_FORMAT, formats[0]);
    1.78 +            }
    1.79 +        }
    1.80 +
    1.81          private void initIndentation() {
    1.82              indentationLevels = new HashMap<DiagnosticPart, Integer>();
    1.83              setIndentation(DiagnosticPart.SUMMARY, 0);
     2.1 --- a/test/tools/apt/Compile/golden.txt	Mon Mar 14 11:33:33 2011 -0700
     2.2 +++ b/test/tools/apt/Compile/golden.txt	Mon Mar 14 11:42:15 2011 -0700
     2.3 @@ -1,6 +1,6 @@
     2.4  error: It's a mad, mad, mad, mad world
     2.5  error: Something wicked this way comes
     2.6 -HelloWorld.java:2: Boring class name
     2.7 +HelloWorld.java:2: error: Boring class name
     2.8  public class HelloWorld {
     2.9         ^
    2.10  3 errors
     3.1 --- a/test/tools/javac/4846262/Test.out	Mon Mar 14 11:33:33 2011 -0700
     3.2 +++ b/test/tools/javac/4846262/Test.out	Mon Mar 14 11:42:15 2011 -0700
     3.3 @@ -1,7 +1,7 @@
     3.4 -Test.java:4: not a statement
     3.5 +Test.java:4: error: not a statement
     3.6          abcdefg
     3.7          ^
     3.8 -Test.java:4: ';' expected
     3.9 +Test.java:4: error: ';' expected
    3.10          abcdefg
    3.11                 ^
    3.12  2 errors
     4.1 --- a/test/tools/javac/Diagnostics/6769027/T6769027.java	Mon Mar 14 11:33:33 2011 -0700
     4.2 +++ b/test/tools/javac/Diagnostics/6769027/T6769027.java	Mon Mar 14 11:42:15 2011 -0700
     4.3 @@ -1,5 +1,5 @@
     4.4  /*
     4.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
     4.6 + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
     4.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.8   *
     4.9   * This code is free software; you can redistribute it and/or modify it
    4.10 @@ -261,7 +261,7 @@
    4.11  
    4.12      enum PositionKind {
    4.13          NOPOS(Position.NOPOS, "- ", "error: "),
    4.14 -        POS(5, "Test.java:1:6: ", "/Test.java:1: ");
    4.15 +        POS(5, "Test.java:1:6: ", "/Test.java:1: error: ");
    4.16  
    4.17          int pos;
    4.18          String rawOutput;
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javac/Diagnostics/7010608/Test.java	Mon Mar 14 11:42:15 2011 -0700
     5.3 @@ -0,0 +1,92 @@
     5.4 +/*
     5.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 + *
     5.8 + * This code is free software; you can redistribute it and/or modify it
     5.9 + * under the terms of the GNU General Public License version 2 only, as
    5.10 + * published by the Free Software Foundation.
    5.11 + *
    5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.15 + * version 2 for more details (a copy is included in the LICENSE file that
    5.16 + * accompanied this code).
    5.17 + *
    5.18 + * You should have received a copy of the GNU General Public License version
    5.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.21 + *
    5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    5.23 + * or visit www.oracle.com if you need additional information or have any
    5.24 + * questions.
    5.25 + */
    5.26 +
    5.27 +/*
    5.28 + * @test
    5.29 + * @bug 7010608
    5.30 + * @summary the string 'error' should appear in error messages
    5.31 + */
    5.32 +
    5.33 +import java.io.*;
    5.34 +import java.net.URI;
    5.35 +import java.util.*;
    5.36 +import javax.tools.*;
    5.37 +import javax.tools.JavaCompiler.CompilationTask;
    5.38 +
    5.39 +public class Test {
    5.40 +    public static void main(String... args) throws Exception {
    5.41 +        new Test().run();
    5.42 +    }
    5.43 +
    5.44 +    void run() throws Exception {
    5.45 +        Locale prev = Locale.getDefault();
    5.46 +        Locale.setDefault(Locale.ENGLISH);
    5.47 +        try {
    5.48 +            test(Arrays.<String>asList(),
    5.49 +                    "myfo://test:1: error: cannot find symbol");
    5.50 +            test(Arrays.asList("-XDdiagsFormat=OLD"),
    5.51 +                    "myfo://test:1: cannot find symbol");
    5.52 +            test(Arrays.asList("-XDoldDiags"),
    5.53 +                    "myfo://test:1: cannot find symbol");
    5.54 +        } finally {
    5.55 +            Locale.setDefault(prev);
    5.56 +        }
    5.57 +    }
    5.58 +
    5.59 +    void test(List<String> options, String expect) throws Exception {
    5.60 +        System.err.println("test: " + options);
    5.61 +        JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
    5.62 +        StringWriter sw = new StringWriter();
    5.63 +        PrintWriter pw = new PrintWriter(sw);
    5.64 +        JavaFileObject f = new MyFileObject("myfo://test", "class Bad { Missing x; }");
    5.65 +        List<? extends JavaFileObject> files = Arrays.asList(f);
    5.66 +        CompilationTask task = javac.getTask(pw, null, null, options, null, files);
    5.67 +        boolean ok = task.call();
    5.68 +        pw.close();
    5.69 +        String out = sw.toString();
    5.70 +        if (!out.isEmpty())
    5.71 +            System.err.println(out);
    5.72 +        if (ok)
    5.73 +            throw new Exception("Compilation succeeded unexpectedly");
    5.74 +        if (!out.contains(expect))
    5.75 +            throw new Exception("expected text not found: " + expect);
    5.76 +    }
    5.77 +
    5.78 +    class MyFileObject extends SimpleJavaFileObject {
    5.79 +        MyFileObject(String uri, String text) {
    5.80 +            super(URI.create(uri), JavaFileObject.Kind.SOURCE);
    5.81 +            this.text = text;
    5.82 +        }
    5.83 +        @Override
    5.84 +        public String getName() {
    5.85 +            return uri.toString();
    5.86 +        }
    5.87 +        @Override
    5.88 +        public String getCharContent(boolean ignoreEncodingErrors) {
    5.89 +            return text;
    5.90 +        }
    5.91 +        final String text;
    5.92 +    }
    5.93 +}
    5.94 +
    5.95 +
     6.1 --- a/test/tools/javac/diags/examples/CountError.java	Mon Mar 14 11:33:33 2011 -0700
     6.2 +++ b/test/tools/javac/diags/examples/CountError.java	Mon Mar 14 11:42:15 2011 -0700
     6.3 @@ -1,5 +1,5 @@
     6.4  /*
     6.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
     6.6 + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
     6.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.8   *
     6.9   * This code is free software; you can redistribute it and/or modify it
    6.10 @@ -23,6 +23,7 @@
    6.11  
    6.12  // key: compiler.misc.count.error
    6.13  // key: compiler.err.unreported.exception.need.to.catch.or.throw
    6.14 +// key: compiler.err.error
    6.15  // run: backdoor
    6.16  
    6.17  class CountError {
     7.1 --- a/test/tools/javac/diags/examples/CountErrorPlural.java	Mon Mar 14 11:33:33 2011 -0700
     7.2 +++ b/test/tools/javac/diags/examples/CountErrorPlural.java	Mon Mar 14 11:42:15 2011 -0700
     7.3 @@ -1,5 +1,5 @@
     7.4  /*
     7.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
     7.6 + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
     7.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.8   *
     7.9   * This code is free software; you can redistribute it and/or modify it
    7.10 @@ -23,6 +23,7 @@
    7.11  
    7.12  // key: compiler.misc.count.error.plural
    7.13  // key: compiler.err.unreported.exception.need.to.catch.or.throw
    7.14 +// key: compiler.err.error
    7.15  // run: backdoor
    7.16  
    7.17  class CountErrorPlural {
     8.1 --- a/test/tools/javac/diags/examples/IdentifierExpected.java	Mon Mar 14 11:33:33 2011 -0700
     8.2 +++ b/test/tools/javac/diags/examples/IdentifierExpected.java	Mon Mar 14 11:42:15 2011 -0700
     8.3 @@ -1,5 +1,5 @@
     8.4  /*
     8.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
     8.6 + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
     8.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     8.8   *
     8.9   * This code is free software; you can redistribute it and/or modify it
    8.10 @@ -25,6 +25,7 @@
    8.11  // key: compiler.err.expected
    8.12  // key: compiler.err.invalid.binary.number
    8.13  // key: compiler.misc.count.error.plural
    8.14 +// key: compiler.err.error
    8.15  // run: backdoor
    8.16  
    8.17  class IdentifierExpected {
     9.1 --- a/test/tools/javac/diags/examples/KindnameClass.java	Mon Mar 14 11:33:33 2011 -0700
     9.2 +++ b/test/tools/javac/diags/examples/KindnameClass.java	Mon Mar 14 11:42:15 2011 -0700
     9.3 @@ -25,6 +25,7 @@
     9.4  // key: compiler.err.cant.resolve.location
     9.5  // key: compiler.misc.location
     9.6  // key: compiler.misc.count.error
     9.7 +// key: compiler.err.error
     9.8  // run: backdoor
     9.9  
    9.10  class KindnameClass {
    10.1 --- a/test/tools/javac/diags/examples/KindnameConstructor.java	Mon Mar 14 11:33:33 2011 -0700
    10.2 +++ b/test/tools/javac/diags/examples/KindnameConstructor.java	Mon Mar 14 11:42:15 2011 -0700
    10.3 @@ -1,5 +1,5 @@
    10.4  /*
    10.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    10.6 + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
    10.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    10.8   *
    10.9   * This code is free software; you can redistribute it and/or modify it
   10.10 @@ -28,6 +28,7 @@
   10.11  // key: compiler.misc.arg.length.mismatch
   10.12  // key: compiler.misc.no.conforming.assignment.exists
   10.13  // key: compiler.misc.count.error.plural
   10.14 +// key: compiler.err.error
   10.15  // run: backdoor
   10.16  
   10.17  class KindnameConstructor {
    11.1 --- a/test/tools/javac/diags/examples/KindnameMethod.java	Mon Mar 14 11:33:33 2011 -0700
    11.2 +++ b/test/tools/javac/diags/examples/KindnameMethod.java	Mon Mar 14 11:42:15 2011 -0700
    11.3 @@ -26,6 +26,7 @@
    11.4  // key: compiler.err.cant.resolve.location.args
    11.5  // key: compiler.misc.location
    11.6  // key: compiler.misc.count.error
    11.7 +// key: compiler.err.error
    11.8  // run: backdoor
    11.9  
   11.10  class KindnameMethod {
    12.1 --- a/test/tools/javac/diags/examples/KindnameVariable.java	Mon Mar 14 11:33:33 2011 -0700
    12.2 +++ b/test/tools/javac/diags/examples/KindnameVariable.java	Mon Mar 14 11:42:15 2011 -0700
    12.3 @@ -26,6 +26,7 @@
    12.4  // key: compiler.err.cant.resolve.location
    12.5  // key: compiler.misc.location
    12.6  // key: compiler.misc.count.error
    12.7 +// key: compiler.err.error
    12.8  // run: backdoor
    12.9  
   12.10  class KindnameVariable {

mercurial