Fri, 22 Aug 2008 11:46:29 +0100
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
1.1 --- a/src/share/classes/com/sun/tools/javac/api/DiagnosticFormatter.java Thu Aug 14 22:17:02 2008 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/api/DiagnosticFormatter.java Fri Aug 22 11:46:29 2008 +0100 1.3 @@ -73,9 +73,10 @@ 1.4 * 1.5 * @param diag diagnostic to be formatted 1.6 * @param l locale object to be used for i18n 1.7 + * @param fullname whether the source fullname should be printed 1.8 * @return string representation of the diagnostic source 1.9 */ 1.10 - public String formatSource(D diag, Locale l); 1.11 + public String formatSource(D diag, boolean fullname, Locale l); 1.12 1.13 /** 1.14 * Controls the way in which a diagnostic position is displayed.
2.1 --- a/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java Thu Aug 14 22:17:02 2008 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java Fri Aug 22 11:46:29 2008 +0100 2.3 @@ -94,9 +94,9 @@ 2.4 } 2.5 } 2.6 2.7 - public String formatSource(JCDiagnostic d,Locale l) { 2.8 + public String formatSource(JCDiagnostic d, boolean fullname, Locale l) { 2.9 assert (d.getSource() != null); 2.10 - return d.getSource().getName(); 2.11 + return fullname ? d.getSourceName() : d.getSource().getName(); 2.12 } 2.13 2.14 /**
3.1 --- a/src/share/classes/com/sun/tools/javac/util/BasicDiagnosticFormatter.java Thu Aug 14 22:17:02 2008 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/util/BasicDiagnosticFormatter.java Fri Aug 22 11:46:29 2008 +0100 3.3 @@ -108,11 +108,11 @@ 3.4 protected String formatMeta(char c, JCDiagnostic d, Locale l) { 3.5 switch (c) { 3.6 case 'b': 3.7 - return formatSource(d, l); 3.8 + return formatSource(d, false, l); 3.9 case 'e': 3.10 return formatPosition(d, END, l); 3.11 case 'f': 3.12 - return formatSource(d, l); 3.13 + return formatSource(d, true, l); 3.14 case 'l': 3.15 return formatPosition(d, LINE, l); 3.16 case 'c':
4.1 --- a/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java Thu Aug 14 22:17:02 2008 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java Fri Aug 22 11:46:29 2008 +0100 4.3 @@ -81,7 +81,7 @@ 4.4 * for the current source file. Zero is returned if no column exists 4.5 * for the given position. 4.6 */ 4.7 - public int getColumnNumber(int pos) { 4.8 + public int getColumnNumber(int pos, boolean expandTabs) { 4.9 try { 4.10 if (findLine(pos)) { 4.11 int column = 0; 4.12 @@ -89,7 +89,7 @@ 4.13 if (bp >= bufLen) { 4.14 return 0; 4.15 } 4.16 - if (buf[bp] == '\t') { 4.17 + if (buf[bp] == '\t' && expandTabs) { 4.18 column = (column / TabInc * TabInc) + TabInc; 4.19 } else { 4.20 column++;
5.1 --- a/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Thu Aug 14 22:17:02 2008 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Fri Aug 22 11:46:29 2008 +0100 5.3 @@ -296,7 +296,7 @@ 5.4 line = column = -1; 5.5 else { 5.6 line = source.getLineNumber(n); 5.7 - column = source.getColumnNumber(n); 5.8 + column = source.getColumnNumber(n, true); 5.9 } 5.10 } 5.11
6.1 --- a/src/share/classes/com/sun/tools/javac/util/Log.java Thu Aug 14 22:17:02 2008 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/util/Log.java Fri Aug 22 11:46:29 2008 +0100 6.3 @@ -244,7 +244,7 @@ 6.4 String line = (source == null ? null : source.getLine(pos)); 6.5 if (line == null) 6.6 return; 6.7 - int col = source.getColumnNumber(pos); 6.8 + int col = source.getColumnNumber(pos, false); 6.9 6.10 printLines(writer, line); 6.11 for (int i = 0; i < col - 1; i++) {
7.1 --- a/src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java Thu Aug 14 22:17:02 2008 -0700 7.2 +++ b/src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java Fri Aug 22 11:46:29 2008 +0100 7.3 @@ -50,7 +50,7 @@ 7.4 try { 7.5 StringBuffer buf = new StringBuffer(); 7.6 if (d.getPosition() != Position.NOPOS) { 7.7 - buf.append(formatSource(d, null)); 7.8 + buf.append(formatSource(d, false, null)); 7.9 buf.append(':'); 7.10 buf.append(formatPosition(d, LINE, null)); 7.11 buf.append(':'); 7.12 @@ -70,12 +70,6 @@ 7.13 } 7.14 7.15 @Override 7.16 - public String formatSource(JCDiagnostic d,Locale l) { 7.17 - assert(d.getSource() != null); 7.18 - return d.getSource().getName(); 7.19 - } 7.20 - 7.21 - @Override 7.22 protected String formatArgument(JCDiagnostic diag, Object arg, Locale l) { 7.23 String s; 7.24 if (arg instanceof Formattable)
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/test/tools/javac/api/6733837/T6733837.java Fri Aug 22 11:46:29 2008 +0100 8.3 @@ -0,0 +1,72 @@ 8.4 +/* 8.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.7 + * 8.8 + * This code is free software; you can redistribute it and/or modify it 8.9 + * under the terms of the GNU General Public License version 2 only, as 8.10 + * published by the Free Software Foundation. 8.11 + * 8.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 8.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.15 + * version 2 for more details (a copy is included in the LICENSE file that 8.16 + * accompanied this code). 8.17 + * 8.18 + * You should have received a copy of the GNU General Public License version 8.19 + * 2 along with this work; if not, write to the Free Software Foundation, 8.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.21 + * 8.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 8.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 8.24 + * have any questions. 8.25 + */ 8.26 + 8.27 +/* 8.28 + * @test 8.29 + * @bug 6733837 8.30 + * @summary Compiler API ignores locale settings 8.31 + * @author Maurizio Cimadamore 8.32 + * @library ../lib 8.33 + */ 8.34 + 8.35 +import java.io.StringWriter; 8.36 +import java.io.PrintWriter; 8.37 +import java.net.URI; 8.38 +import java.util.Arrays; 8.39 +import java.util.List; 8.40 +import javax.tools.JavaFileObject; 8.41 +import javax.tools.SimpleJavaFileObject; 8.42 +import static javax.tools.JavaFileObject.Kind; 8.43 +import com.sun.source.util.JavacTask; 8.44 + 8.45 +public class T6733837 extends ToolTester { 8.46 + 8.47 + public static void main(String... args) { 8.48 + new T6733837().exec(); 8.49 + } 8.50 + 8.51 + public void exec() { 8.52 + JavaFileObject sfo = new SimpleJavaFileObject(URI.create(""),Kind.SOURCE) { 8.53 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 8.54 + return "\tclass ErroneousWithTab"; 8.55 + } 8.56 + @Override 8.57 + public String getName() { 8.58 + return "RELATIVEPATH"; 8.59 + } 8.60 + }; 8.61 + StringWriter sw = new StringWriter(); 8.62 + PrintWriter out = new PrintWriter(sw); 8.63 + List<? extends JavaFileObject> files = Arrays.asList(sfo); 8.64 + task = tool.getTask(sw, fm, null, null, null, files); 8.65 + try { 8.66 + ((JavacTask)task).analyze(); 8.67 + } 8.68 + catch (Throwable t) { 8.69 + throw new Error("Compiler threw an exception"); 8.70 + } 8.71 + System.err.println(sw.toString()); 8.72 + if (sw.toString().contains("RELATIVEPATH")) 8.73 + throw new Error("Bad source name in diagnostic"); 8.74 + } 8.75 +}