Description
Currently, the message returned from JCDiagnostic.getMessage(Locale) (we access it through Diagnostic.getMessage(Locale)) starts with the absolute path to the file which contains the error and line number where the error occurred. I think that for the users of Diagnostic.getMessage(Locale) it would be more appropriate to get only the "short" error message from this method (like JCDiagnostic.getText()).
Consider the following program:
-----------------------------------
import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import javax.tools.Diagnostic;
import javax.tools.DiagnosticListener;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.ToolProvider;
public class Main {
public static void main(String[] args) throws Exception {
String dest = System.getProperty("java.io.tmpdir");
class DummyFO extends SimpleJavaFileObject {
public DummyFO() {
super(URI.create("nowhere:/Test.java"), JavaFileObject.Kind.SOURCE);
}
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
return "public class Test {sdf}";
}
}
JavaCompiler.CompilationTask task = ToolProvider.getSystemJavaCompiler().getTask(
null, null, new DL(),
Arrays.asList("-d", dest),
null, Collections.singleton(new DummyFO()));
task.call();
}
private static class DL implements DiagnosticListener {
public void report(Diagnostic diagnostic) {
System.err.println("reported diagnostic:");
System.err.println(diagnostic.getMessage(null));
}
}
}
-----------------------------------
Currently, it prints:
reported diagnostic:
nowhere:/Test.java:1: <identifier> expected
But, I think it would be better if it would print:
reported diagnostic:
<identifier> expected
Consider the following program:
-----------------------------------
import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import javax.tools.Diagnostic;
import javax.tools.DiagnosticListener;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.ToolProvider;
public class Main {
public static void main(String[] args) throws Exception {
String dest = System.getProperty("java.io.tmpdir");
class DummyFO extends SimpleJavaFileObject {
public DummyFO() {
super(URI.create("nowhere:/Test.java"), JavaFileObject.Kind.SOURCE);
}
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
return "public class Test {sdf}";
}
}
JavaCompiler.CompilationTask task = ToolProvider.getSystemJavaCompiler().getTask(
null, null, new DL(),
Arrays.asList("-d", dest),
null, Collections.singleton(new DummyFO()));
task.call();
}
private static class DL implements DiagnosticListener {
public void report(Diagnostic diagnostic) {
System.err.println("reported diagnostic:");
System.err.println(diagnostic.getMessage(null));
}
}
}
-----------------------------------
Currently, it prints:
reported diagnostic:
nowhere:/Test.java:1: <identifier> expected
But, I think it would be better if it would print:
reported diagnostic:
<identifier> expected
Attachments
Issue Links
- duplicates
-
JDK-6469079 JSR 199: Diagnostic.getMessage(Locale) includes line numbers
-
- Closed
-