Put full filepaths in error messages when not using the default message format.

When the default "antlr" message format is used, ErrorManager deliberately
only includes the filename in any error message, not the full path, to
keep the messages short.  However, if the error message is intended to be
parsed by an IDE, this is no good.

Address this by printing the full path when using alternate message formats.
There are two formats available today -- "gnu" and "vs2005".  I think it's
reasonable to assume that people would use these for IDE compatibility, and
so using the full path for these is appropriate.  Also, they didn't work
until very recently, so this isn't breaking any existing behavior.
This commit is contained in:
Ewan Mellor 2017-10-29 01:10:22 -07:00
parent 6693ba73a5
commit 8f639f28dd
No known key found for this signature in database
GPG Key ID: 7CE1C6BC9EC8645D
1 changed files with 13 additions and 4 deletions

View File

@ -60,11 +60,20 @@ public class ErrorManager {
locationValid = true;
}
if (msg.fileName != null) {
File f = new File(msg.fileName);
// Don't show path to file in messages; too long.
String displayFileName = msg.fileName;
if ( f.exists() ) {
displayFileName = f.getName();
if (format.equals("antlr")) {
// Don't show path to file in messages in ANTLR format;
// they're too long.
File f = new File(msg.fileName);
if ( f.exists() ) {
displayFileName = f.getName();
}
}
else {
// For other message formats, use the full filename in the
// message. This assumes that these formats are intended to
// be parsed by IDEs, and so they need the full path to
// resolve correctly.
}
locationST.add("file", displayFileName);
locationValid = true;