v4: add ANTLRMessage.getCause(), overridden in GrammarSyntaxMessage instead of keeping 2 separate fields

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9210]
This commit is contained in:
sharwell 2011-10-27 08:55:01 -08:00
parent ad468ee29b
commit 980db2caac
2 changed files with 26 additions and 9 deletions

View File

@ -34,7 +34,7 @@ import java.util.Arrays;
public class ANTLRMessage { public class ANTLRMessage {
public ErrorType errorType; public ErrorType errorType;
public Object[] args; public Object[] args;
public Throwable e; private final Throwable e;
// used for location template // used for location template
public String fileName; public String fileName;
@ -42,20 +42,33 @@ public class ANTLRMessage {
public int charPosition = -1; public int charPosition = -1;
public ANTLRMessage() { public ANTLRMessage() {
this(ErrorType.INVALID, (Throwable)null);
} }
public ANTLRMessage(ErrorType errorType) { public ANTLRMessage(ErrorType errorType) {
this.errorType = errorType; this(errorType, (Throwable)null);
} }
public ANTLRMessage(ErrorType errorType, Object... args) { public ANTLRMessage(ErrorType errorType, Object... args) {
this(errorType); this(errorType, null, args);
}
public ANTLRMessage(ErrorType errorType, /*@Nullable*/ Throwable e, Object... args) {
this.errorType = errorType;
this.e = e;
this.args = args; this.args = args;
} }
public ANTLRMessage(ErrorType errorType, Throwable e, Object... args) { public ErrorType getErrorType() {
this(errorType, args); return errorType;
this.e = e; }
public Object[] getArgs() {
return args;
}
public Throwable getCause() {
return e;
} }
@Override @Override

View File

@ -38,7 +38,6 @@ public class GrammarSyntaxMessage extends ANTLRMessage {
public Grammar g; public Grammar g;
/** Most of the time, we'll have a token and so this will be set. */ /** Most of the time, we'll have a token and so this will be set. */
public Token offendingToken; public Token offendingToken;
public RecognitionException antlrException;
public GrammarSyntaxMessage(ErrorType etype, public GrammarSyntaxMessage(ErrorType etype,
String fileName, String fileName,
@ -46,13 +45,18 @@ public class GrammarSyntaxMessage extends ANTLRMessage {
RecognitionException antlrException, RecognitionException antlrException,
Object... args) Object... args)
{ {
super(etype,args); super(etype, antlrException, args);
this.fileName = fileName; this.fileName = fileName;
this.offendingToken = offendingToken; this.offendingToken = offendingToken;
this.antlrException = antlrException;
if ( offendingToken!=null ) { if ( offendingToken!=null ) {
line = offendingToken.getLine(); line = offendingToken.getLine();
charPosition = offendingToken.getCharPositionInLine(); charPosition = offendingToken.getCharPositionInLine();
} }
} }
@SuppressWarnings({"ThrowableResultOfMethodCallIgnored"})
@Override
public RecognitionException getCause() {
return (RecognitionException)super.getCause();
}
} }