Make Antlr token implementation respect its contract

This commit is contained in:
Clément Fournier
2020-03-22 00:49:55 +01:00
parent 16f30c9ece
commit f6260463d7
2 changed files with 5 additions and 2 deletions

View File

@ -16,6 +16,7 @@ public class AntlrToken implements GenericToken<AntlrToken> {
private final Token token;
private final AntlrToken previousComment;
AntlrToken next;
/**
* Constructor
@ -30,8 +31,7 @@ public class AntlrToken implements GenericToken<AntlrToken> {
@Override
public AntlrToken getNext() {
// Antlr implementation does not require this
return null;
return next;
}
@Override

View File

@ -45,6 +45,9 @@ public class AntlrTokenManager implements TokenManager<AntlrToken> {
private AntlrToken getNextTokenFromAnyChannel() {
final AntlrToken previousComment = previousToken != null && previousToken.isHidden() ? previousToken : null;
final AntlrToken currentToken = new AntlrToken(lexer.nextToken(), previousComment);
if (previousToken != null) {
previousToken.next = currentToken;
}
previousToken = currentToken;
return currentToken;