Class CommonTokenStream
- java.lang.Object
- 
- org.antlr.v4.runtime.BufferedTokenStream
- 
- org.antlr.v4.runtime.CommonTokenStream
 
 
- 
- All Implemented Interfaces:
- IntStream,- TokenStream
 
 public class CommonTokenStream extends BufferedTokenStream This class extendsBufferedTokenStreamwith functionality to filter token streams to tokens on a particular channel (tokens whereToken.getChannel()returns a particular value).This token stream provides access to all tokens by index or when calling methods like BufferedTokenStream.getText(). The channel filtering is only used for code accessing tokens via the lookahead methodsBufferedTokenStream.LA(int),LT(int), andLB(int).By default, tokens are placed on the default channel ( Token.DEFAULT_CHANNEL), but may be reassigned by using the->channel(HIDDEN)lexer command, or by using an embedded action to callLexer.setChannel(int).Note: lexer rules which use the we->skiplexer command or callLexer.skip()do not produce tokens at all, so input text matched by such a rule will not be available as part of the token stream, regardless of channel.
- 
- 
Field SummaryFields Modifier and Type Field Description protected intchannelSpecifies the channel to use for filtering tokens.- 
Fields inherited from class org.antlr.v4.runtime.BufferedTokenStreamfetchedEOF, p, tokens, tokenSource
 - 
Fields inherited from interface org.antlr.v4.runtime.IntStreamEOF, UNKNOWN_SOURCE_NAME
 
- 
 - 
Constructor SummaryConstructors Constructor Description CommonTokenStream(TokenSource tokenSource)Constructs a newCommonTokenStreamusing the specified token source and the default token channel (Token.DEFAULT_CHANNEL).CommonTokenStream(TokenSource tokenSource, int channel)Constructs a newCommonTokenStreamusing the specified token source and filtering tokens to the specified channel.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intadjustSeekIndex(int i)Allowed derived classes to modify the behavior of operations which change the current stream position by adjusting the target token index of a seek operation.intgetNumberOfOnChannelTokens()Count EOF just once.protected TokenLB(int k)TokenLT(int k)- 
Methods inherited from class org.antlr.v4.runtime.BufferedTokenStreamconsume, fetch, fill, filterForChannel, get, get, getHiddenTokensToLeft, getHiddenTokensToLeft, getHiddenTokensToRight, getHiddenTokensToRight, getSourceName, getText, getText, getText, getText, getTokens, getTokens, getTokens, getTokens, getTokenSource, index, LA, lazyInit, mark, nextTokenOnChannel, previousTokenOnChannel, release, reset, seek, setTokenSource, setup, size, sync
 
- 
 
- 
- 
- 
Field Detail- 
channelprotected int channel Specifies the channel to use for filtering tokens.The default value is Token.DEFAULT_CHANNEL, which matches the default channel assigned to tokens created by the lexer.
 
- 
 - 
Constructor Detail- 
CommonTokenStreampublic CommonTokenStream(TokenSource tokenSource) Constructs a newCommonTokenStreamusing the specified token source and the default token channel (Token.DEFAULT_CHANNEL).- Parameters:
- tokenSource- The token source.
 
 - 
CommonTokenStreampublic CommonTokenStream(TokenSource tokenSource, int channel) Constructs a newCommonTokenStreamusing the specified token source and filtering tokens to the specified channel. Only tokens whoseToken.getChannel()matcheschannelor have theToken.getType()equal toToken.EOFwill be returned by the token stream lookahead methods.- Parameters:
- tokenSource- The token source.
- channel- The channel to use for filtering tokens.
 
 
- 
 - 
Method Detail- 
adjustSeekIndexprotected int adjustSeekIndex(int i) Description copied from class:BufferedTokenStreamAllowed derived classes to modify the behavior of operations which change the current stream position by adjusting the target token index of a seek operation. The default implementation simply returnsi. If an exception is thrown in this method, the current stream index should not be changed.For example, CommonTokenStreamoverrides this method to ensure that the seek target is always an on-channel token.- Overrides:
- adjustSeekIndexin class- BufferedTokenStream
- Parameters:
- i- The target token index.
- Returns:
- The adjusted target token index.
 
 - 
LBprotected Token LB(int k) - Overrides:
- LBin class- BufferedTokenStream
 
 - 
LTpublic Token LT(int k) Description copied from interface:TokenStreamGet theTokeninstance associated with the value returned byLA(k). This method has the same pre- and post-conditions asIntStream.LA(int). In addition, when the preconditions of this method are met, the return value is non-null and the value ofLT(k).getType()==LA(k).- Specified by:
- LTin interface- TokenStream
- Overrides:
- LTin class- BufferedTokenStream
- See Also:
- IntStream.LA(int)
 
 - 
getNumberOfOnChannelTokenspublic int getNumberOfOnChannelTokens() Count EOF just once.
 
- 
 
-