提交 35b98e79 编写于 作者: J jjg

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

Reviewed-by: mcimadamore
上级 02c40c9b
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
package com.sun.tools.javac.util; package com.sun.tools.javac.util;
import java.util.Collection; import java.util.Collection;
import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
...@@ -226,17 +227,14 @@ public class BasicDiagnosticFormatter extends AbstractDiagnosticFormatter { ...@@ -226,17 +227,14 @@ public class BasicDiagnosticFormatter extends AbstractDiagnosticFormatter {
DiagnosticPart.SOURCE)); DiagnosticPart.SOURCE));
initFormat(); initFormat();
initIndentation(); initIndentation();
if (options.isSet("oldDiags"))
initOldFormat();
String fmt = options.get("diagsFormat"); String fmt = options.get("diagsFormat");
if (fmt != null) { if (fmt != null) {
String[] formats = fmt.split("\\|"); if (fmt.equals("OLD"))
switch (formats.length) { initOldFormat();
case 3: else
setFormat(BasicFormatKind.DEFAULT_CLASS_FORMAT, formats[2]); initFormats(fmt);
case 2:
setFormat(BasicFormatKind.DEFAULT_NO_POS_FORMAT, formats[1]);
default:
setFormat(BasicFormatKind.DEFAULT_POS_FORMAT, formats[0]);
}
} }
String srcPos = null; String srcPos = null;
if ((((srcPos = options.get("sourcePosition")) != null)) && if ((((srcPos = options.get("sourcePosition")) != null)) &&
...@@ -280,14 +278,35 @@ public class BasicDiagnosticFormatter extends AbstractDiagnosticFormatter { ...@@ -280,14 +278,35 @@ public class BasicDiagnosticFormatter extends AbstractDiagnosticFormatter {
initFormat(); initFormat();
initIndentation(); initIndentation();
} }
//where
private void initFormat() { private void initFormat() {
availableFormats = new HashMap<BasicFormatKind, String>(); initFormats("%f:%l:%_%p%L%m", "%p%L%m", "%f:%_%p%L%m");
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");
} }
//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() { private void initIndentation() {
indentationLevels = new HashMap<DiagnosticPart, Integer>(); indentationLevels = new HashMap<DiagnosticPart, Integer>();
setIndentation(DiagnosticPart.SUMMARY, 0); setIndentation(DiagnosticPart.SUMMARY, 0);
......
error: It's a mad, mad, mad, mad world error: It's a mad, mad, mad, mad world
error: Something wicked this way comes error: Something wicked this way comes
HelloWorld.java:2: Boring class name HelloWorld.java:2: error: Boring class name
public class HelloWorld { public class HelloWorld {
^ ^
3 errors 3 errors
Test.java:4: not a statement Test.java:4: error: not a statement
abcdefg abcdefg
^ ^
Test.java:4: ';' expected Test.java:4: error: ';' expected
abcdefg abcdefg
^ ^
2 errors 2 errors
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -261,7 +261,7 @@ public class T6769027 { ...@@ -261,7 +261,7 @@ public class T6769027 {
enum PositionKind { enum PositionKind {
NOPOS(Position.NOPOS, "- ", "error: "), 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; int pos;
String rawOutput; String rawOutput;
......
/*
* 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;
}
}
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
// key: compiler.misc.count.error // key: compiler.misc.count.error
// key: compiler.err.unreported.exception.need.to.catch.or.throw // key: compiler.err.unreported.exception.need.to.catch.or.throw
// key: compiler.err.error
// run: backdoor // run: backdoor
class CountError { class CountError {
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
// key: compiler.misc.count.error.plural // key: compiler.misc.count.error.plural
// key: compiler.err.unreported.exception.need.to.catch.or.throw // key: compiler.err.unreported.exception.need.to.catch.or.throw
// key: compiler.err.error
// run: backdoor // run: backdoor
class CountErrorPlural { class CountErrorPlural {
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
// key: compiler.err.expected // key: compiler.err.expected
// key: compiler.err.invalid.binary.number // key: compiler.err.invalid.binary.number
// key: compiler.misc.count.error.plural // key: compiler.misc.count.error.plural
// key: compiler.err.error
// run: backdoor // run: backdoor
class IdentifierExpected { class IdentifierExpected {
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
// key: compiler.err.cant.resolve.location // key: compiler.err.cant.resolve.location
// key: compiler.misc.location // key: compiler.misc.location
// key: compiler.misc.count.error // key: compiler.misc.count.error
// key: compiler.err.error
// run: backdoor // run: backdoor
class KindnameClass { class KindnameClass {
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
// key: compiler.misc.arg.length.mismatch // key: compiler.misc.arg.length.mismatch
// key: compiler.misc.no.conforming.assignment.exists // key: compiler.misc.no.conforming.assignment.exists
// key: compiler.misc.count.error.plural // key: compiler.misc.count.error.plural
// key: compiler.err.error
// run: backdoor // run: backdoor
class KindnameConstructor { class KindnameConstructor {
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
// key: compiler.err.cant.resolve.location.args // key: compiler.err.cant.resolve.location.args
// key: compiler.misc.location // key: compiler.misc.location
// key: compiler.misc.count.error // key: compiler.misc.count.error
// key: compiler.err.error
// run: backdoor // run: backdoor
class KindnameMethod { class KindnameMethod {
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
// key: compiler.err.cant.resolve.location // key: compiler.err.cant.resolve.location
// key: compiler.misc.location // key: compiler.misc.location
// key: compiler.misc.count.error // key: compiler.misc.count.error
// key: compiler.err.error
// run: backdoor // run: backdoor
class KindnameVariable { class KindnameVariable {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册