Use generic List instead of generic array for listeners

This commit is contained in:
Sam Harwell 2012-02-23 11:59:01 -06:00
parent 7dcb148d73
commit 6c26917b90
3 changed files with 8 additions and 9 deletions

View File

@ -32,6 +32,7 @@ import org.antlr.v4.runtime.atn.LexerATNSimulator;
import java.util.ArrayDeque;
import java.util.EmptyStackException;
import java.util.List;
/** A lexer is recognizer that draws input symbols from a character stream.
* lexer grammars result in a subclass of this object. A Lexer object
@ -308,8 +309,8 @@ public abstract class Lexer extends Recognizer<Integer, LexerATNSimulator>
public void notifyListeners(LexerNoViableAltException e) {
String msg = "token recognition error at: '"+
_input.substring(_tokenStartCharIndex, _input.index())+"'";
ANTLRErrorListener<Integer>[] listeners = getErrorListeners();
if ( listeners.length == 0 ) {
List<? extends ANTLRErrorListener<Integer>> listeners = getErrorListeners();
if ( listeners.isEmpty() ) {
System.err.println("line "+ _tokenStartLine +":"+
_tokenStartCharPositionInLine +" "+
msg);

View File

@ -255,8 +255,8 @@ public abstract class Parser extends Recognizer<Token, ParserATNSimulator<Token>
line = ((Token) offendingToken).getLine();
charPositionInLine = ((Token) offendingToken).getCharPositionInLine();
}
ANTLRErrorListener<Token>[] listeners = getErrorListeners();
if ( listeners.length == 0 ) {
List<? extends ANTLRErrorListener<Token>> listeners = getErrorListeners();
if ( listeners.isEmpty() ) {
System.err.println("line "+line+":"+charPositionInLine+" "+msg);
return;
}

View File

@ -45,8 +45,6 @@ public abstract class Recognizer<Symbol, ATNInterpreter extends ATNSimulator> {
private List<ANTLRErrorListener<Symbol>> _listeners;
private static final ANTLRErrorListener[] EMPTY_LISTENERS = new ANTLRErrorListener[0];
protected ATNInterpreter _interp;
/** Used to print out token names like ID during debugging and
@ -112,12 +110,12 @@ public abstract class Recognizer<Symbol, ATNInterpreter extends ATNSimulator> {
public void removeErrorListeners() { if ( _listeners!=null ) _listeners.clear(); }
public @NotNull ANTLRErrorListener<Symbol>[] getErrorListeners() {
public @NotNull List<? extends ANTLRErrorListener<Symbol>> getErrorListeners() {
if (_listeners == null) {
return EMPTY_LISTENERS;
return Collections.<ANTLRErrorListener<Symbol>>emptyList();
}
return _listeners.toArray(EMPTY_LISTENERS);
return new ArrayList<ANTLRErrorListener<Symbol>>(_listeners);
}
public ANTLRErrorStrategy getErrorHandler() { return _errHandler; }