diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrToken.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrToken.java index 0ab3ca442a..4162d72e7d 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrToken.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrToken.java @@ -16,6 +16,7 @@ public class AntlrToken implements GenericToken { private final Token token; private final AntlrToken previousComment; + AntlrToken next; /** * Constructor @@ -30,8 +31,7 @@ public class AntlrToken implements GenericToken { @Override public AntlrToken getNext() { - // Antlr implementation does not require this - return null; + return next; } @Override diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrTokenManager.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrTokenManager.java index 6333f78a72..7c3f648b9a 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrTokenManager.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrTokenManager.java @@ -45,6 +45,9 @@ public class AntlrTokenManager implements TokenManager { 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;