6733837: Recent work on javac diagnostic affected javac output
Problems with diagnostic path and tab character in the source code Reviewed-by: darcy, jjg
This commit is contained in:
parent
25183c156a
commit
b9c79ae213
@ -73,9 +73,10 @@ public interface DiagnosticFormatter<D extends Diagnostic<?>> {
|
||||
*
|
||||
* @param diag diagnostic to be formatted
|
||||
* @param l locale object to be used for i18n
|
||||
* @param fullname whether the source fullname should be printed
|
||||
* @return string representation of the diagnostic source
|
||||
*/
|
||||
public String formatSource(D diag, Locale l);
|
||||
public String formatSource(D diag, boolean fullname, Locale l);
|
||||
|
||||
/**
|
||||
* Controls the way in which a diagnostic position is displayed.
|
||||
|
@ -94,9 +94,9 @@ public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter
|
||||
}
|
||||
}
|
||||
|
||||
public String formatSource(JCDiagnostic d,Locale l) {
|
||||
public String formatSource(JCDiagnostic d, boolean fullname, Locale l) {
|
||||
assert (d.getSource() != null);
|
||||
return d.getSource().getName();
|
||||
return fullname ? d.getSourceName() : d.getSource().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -108,11 +108,11 @@ public class BasicDiagnosticFormatter extends AbstractDiagnosticFormatter {
|
||||
protected String formatMeta(char c, JCDiagnostic d, Locale l) {
|
||||
switch (c) {
|
||||
case 'b':
|
||||
return formatSource(d, l);
|
||||
return formatSource(d, false, l);
|
||||
case 'e':
|
||||
return formatPosition(d, END, l);
|
||||
case 'f':
|
||||
return formatSource(d, l);
|
||||
return formatSource(d, true, l);
|
||||
case 'l':
|
||||
return formatPosition(d, LINE, l);
|
||||
case 'c':
|
||||
|
@ -81,7 +81,7 @@ public class DiagnosticSource {
|
||||
* for the current source file. Zero is returned if no column exists
|
||||
* for the given position.
|
||||
*/
|
||||
public int getColumnNumber(int pos) {
|
||||
public int getColumnNumber(int pos, boolean expandTabs) {
|
||||
try {
|
||||
if (findLine(pos)) {
|
||||
int column = 0;
|
||||
@ -89,7 +89,7 @@ public class DiagnosticSource {
|
||||
if (bp >= bufLen) {
|
||||
return 0;
|
||||
}
|
||||
if (buf[bp] == '\t') {
|
||||
if (buf[bp] == '\t' && expandTabs) {
|
||||
column = (column / TabInc * TabInc) + TabInc;
|
||||
} else {
|
||||
column++;
|
||||
|
@ -296,7 +296,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
line = column = -1;
|
||||
else {
|
||||
line = source.getLineNumber(n);
|
||||
column = source.getColumnNumber(n);
|
||||
column = source.getColumnNumber(n, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -244,7 +244,7 @@ public class Log extends AbstractLog {
|
||||
String line = (source == null ? null : source.getLine(pos));
|
||||
if (line == null)
|
||||
return;
|
||||
int col = source.getColumnNumber(pos);
|
||||
int col = source.getColumnNumber(pos, false);
|
||||
|
||||
printLines(writer, line);
|
||||
for (int i = 0; i < col - 1; i++) {
|
||||
|
@ -50,7 +50,7 @@ public class RawDiagnosticFormatter extends AbstractDiagnosticFormatter {
|
||||
try {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
if (d.getPosition() != Position.NOPOS) {
|
||||
buf.append(formatSource(d, null));
|
||||
buf.append(formatSource(d, false, null));
|
||||
buf.append(':');
|
||||
buf.append(formatPosition(d, LINE, null));
|
||||
buf.append(':');
|
||||
@ -69,12 +69,6 @@ public class RawDiagnosticFormatter extends AbstractDiagnosticFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatSource(JCDiagnostic d,Locale l) {
|
||||
assert(d.getSource() != null);
|
||||
return d.getSource().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String formatArgument(JCDiagnostic diag, Object arg, Locale l) {
|
||||
String s;
|
||||
|
72
langtools/test/tools/javac/api/6733837/T6733837.java
Normal file
72
langtools/test/tools/javac/api/6733837/T6733837.java
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6733837
|
||||
* @summary Compiler API ignores locale settings
|
||||
* @author Maurizio Cimadamore
|
||||
* @library ../lib
|
||||
*/
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.SimpleJavaFileObject;
|
||||
import static javax.tools.JavaFileObject.Kind;
|
||||
import com.sun.source.util.JavacTask;
|
||||
|
||||
public class T6733837 extends ToolTester {
|
||||
|
||||
public static void main(String... args) {
|
||||
new T6733837().exec();
|
||||
}
|
||||
|
||||
public void exec() {
|
||||
JavaFileObject sfo = new SimpleJavaFileObject(URI.create(""),Kind.SOURCE) {
|
||||
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
|
||||
return "\tclass ErroneousWithTab";
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return "RELATIVEPATH";
|
||||
}
|
||||
};
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter out = new PrintWriter(sw);
|
||||
List<? extends JavaFileObject> files = Arrays.asList(sfo);
|
||||
task = tool.getTask(sw, fm, null, null, null, files);
|
||||
try {
|
||||
((JavacTask)task).analyze();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
throw new Error("Compiler threw an exception");
|
||||
}
|
||||
System.err.println(sw.toString());
|
||||
if (sw.toString().contains("RELATIVEPATH"))
|
||||
throw new Error("Bad source name in diagnostic");
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user