OpenJDK / amber / amber
changeset 1109:853d8c191eac
6733837: Recent work on javac diagnostic affected javac output
Summary: Problems with diagnostic path and tab character in the source code
Reviewed-by: darcy, jjg
line wrap: on
line diff
--- a/langtools/src/share/classes/com/sun/tools/javac/api/DiagnosticFormatter.java Wed Jul 05 16:40:31 2017 +0200 +++ b/langtools/src/share/classes/com/sun/tools/javac/api/DiagnosticFormatter.java Fri Aug 22 11:46:29 2008 +0100 @@ -73,9 +73,10 @@ * * @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.
--- a/langtools/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java Wed Jul 05 16:40:31 2017 +0200 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java Fri Aug 22 11:46:29 2008 +0100 @@ -94,9 +94,9 @@ } } - 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(); } /**
--- a/langtools/src/share/classes/com/sun/tools/javac/util/BasicDiagnosticFormatter.java Wed Jul 05 16:40:31 2017 +0200 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/BasicDiagnosticFormatter.java Fri Aug 22 11:46:29 2008 +0100 @@ -108,11 +108,11 @@ 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':
--- a/langtools/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java Wed Jul 05 16:40:31 2017 +0200 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java Fri Aug 22 11:46:29 2008 +0100 @@ -81,7 +81,7 @@ * 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 @@ if (bp >= bufLen) { return 0; } - if (buf[bp] == '\t') { + if (buf[bp] == '\t' && expandTabs) { column = (column / TabInc * TabInc) + TabInc; } else { column++;
--- a/langtools/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Wed Jul 05 16:40:31 2017 +0200 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Fri Aug 22 11:46:29 2008 +0100 @@ -296,7 +296,7 @@ line = column = -1; else { line = source.getLineNumber(n); - column = source.getColumnNumber(n); + column = source.getColumnNumber(n, true); } }
--- a/langtools/src/share/classes/com/sun/tools/javac/util/Log.java Wed Jul 05 16:40:31 2017 +0200 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/Log.java Fri Aug 22 11:46:29 2008 +0100 @@ -244,7 +244,7 @@ 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++) {
--- a/langtools/src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java Wed Jul 05 16:40:31 2017 +0200 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java Fri Aug 22 11:46:29 2008 +0100 @@ -50,7 +50,7 @@ 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(':'); @@ -70,12 +70,6 @@ } @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; if (arg instanceof Formattable)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/api/6733837/T6733837.java Fri Aug 22 11:46:29 2008 +0100 @@ -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"); + } +}