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

Reviewed-by: mcimadamore
This commit is contained in:
Jonathan Gibbons 2011-03-14 11:42:15 -07:00
parent c2e4376861
commit 593927cf2d
12 changed files with 143 additions and 25 deletions

View File

@ -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 @@ public class BasicDiagnosticFormatter extends AbstractDiagnosticFormatter {
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 @@ public class BasicDiagnosticFormatter extends AbstractDiagnosticFormatter {
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");
}
//where
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);
}
@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);

View File

@ -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

View File

@ -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

View File

@ -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 @@ public class T6769027 {
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;

View File

@ -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;
}
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {