Top Fields Constructors Methods
org.antlr.v4.runtime

public Class CommonToken

extends Object
implements WritableToken, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.antlr.v4.runtime.WritableToken, org.antlr.v4.runtime.Token
Known Direct Subclasses
org.antlr.v4.runtime.tree.pattern.TokenTagToken
Imports
org.antlr.v4.runtime.misc.Interval, .Pair, java.io.Serializable

Field Summary

Modifier and TypeField and Description
protected int
channel

This is the backing field for getChannel and setChannel.

protected int
protected static final Pair<TokenSource, CharStream>
EMPTY_SOURCE

An empty Pair which is used as the default value of source for tokens that do not have a source.

protected int
index

This is the backing field for getTokenIndex and setTokenIndex.

protected int
line

This is the backing field for getLine and setLine.

protected Pair<TokenSource, CharStream>
source

This is the backing field for getTokenSource and getInputStream.

protected int
start

This is the backing field for getStartIndex and setStartIndex.

protected int
stop

This is the backing field for getStopIndex and setStopIndex.

protected String
text

This is the backing field for getText when the token text is explicitly set in the constructor or via setText.

protected int
type

This is the backing field for getType and setType.

Constructor Summary

AccessConstructor and Description
public
CommonToken(int
The token type.
type
)

Constructs a new CommonToken with the specified token type.

public
CommonToken(Pair<TokenSource, CharStream> source, int type, int channel, int start, int stop)

public
CommonToken(int
The token type.
type
,
String
The text of the token.
text
)

Constructs a new CommonToken with the specified token type and text.

public
CommonToken(Token
The token to copy.
oldToken
)

Constructs a new CommonToken as a copy of another Token.

Method Summary

Modifier and TypeMethod and Description
public int
getChannel()

Implements org.antlr.v4.runtime.Token.getChannel.

Return the channel this token.
public int
getCharPositionInLine()

Implements org.antlr.v4.runtime.Token.getCharPositionInLine.

The index of the first character of this token relative to the beginning of the line at which it occurs, 0..n-1
public CharStream
getInputStream()

Implements org.antlr.v4.runtime.Token.getInputStream.

Gets the CharStream from which this token was derived.
public int
getLine()

Implements org.antlr.v4.runtime.Token.getLine.

The line number on which the 1st character of this token was matched, line=1..n
public int
getStartIndex()

Implements org.antlr.v4.runtime.Token.getStartIndex.

The starting character index of the token This method is optional; return -1 if not implemented.
public int
getStopIndex()

Implements org.antlr.v4.runtime.Token.getStopIndex.

The last character index of the token.
public String
getText()

Implements org.antlr.v4.runtime.Token.getText.

Get the text of the token.
public int
getTokenIndex()

Implements org.antlr.v4.runtime.Token.getTokenIndex.

An index from 0..n-1 of the token object in the input stream.
public TokenSource
getTokenSource()

Implements org.antlr.v4.runtime.Token.getTokenSource.

Gets the TokenSource which created this token.
public int
getType()

Implements org.antlr.v4.runtime.Token.getType.

Get the token type of the token
public void
public void
public void
public void
setStartIndex(int start)

public void
setStopIndex(int stop)

public void
setText(String
The explicit text of the token, or null if the text should be obtained from the input along with the start and stop indexes of the token.
text
)

Implements org.antlr.v4.runtime.WritableToken.setText.

Explicitly set the text for this token.
public void
public void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

channelback to summary
protected int channel

This is the backing field for getChannel and setChannel.

charPositionInLineback to summary
protected int charPositionInLine

This is the backing field for getCharPositionInLine and setCharPositionInLine.

EMPTY_SOURCEback to summary
protected static final Pair<TokenSource, CharStream> EMPTY_SOURCE

An empty Pair which is used as the default value of source for tokens that do not have a source.

indexback to summary
protected int index

This is the backing field for getTokenIndex and setTokenIndex.

lineback to summary
protected int line

This is the backing field for getLine and setLine.

sourceback to summary
protected Pair<TokenSource, CharStream> source

This is the backing field for getTokenSource and getInputStream.

These properties share a field to reduce the memory footprint of CommonToken. Tokens created by a CommonTokenFactory from the same source and input stream share a reference to the same Pair containing these values.

startback to summary
protected int start

This is the backing field for getStartIndex and setStartIndex.

stopback to summary
protected int stop

This is the backing field for getStopIndex and setStopIndex.

textback to summary
protected String text

This is the backing field for getText when the token text is explicitly set in the constructor or via setText.

See Also
getText()
typeback to summary
protected int type

This is the backing field for getType and setType.

Constructor Detail

CommonTokenback to summary
public CommonToken(int type)

Constructs a new CommonToken with the specified token type.

Parameters
type:int

The token type.

CommonTokenback to summary
public CommonToken(Pair<TokenSource, CharStream> source, int type, int channel, int start, int stop)
CommonTokenback to summary
public CommonToken(int type, String text)

Constructs a new CommonToken with the specified token type and text.

Parameters
type:int

The token type.

text:String

The text of the token.

CommonTokenback to summary
public CommonToken(Token oldToken)

Constructs a new CommonToken as a copy of another Token.

If oldToken is also a CommonToken instance, the newly constructed token will share a reference to the text field and the Pair stored in source. Otherwise, text will be assigned the result of calling getText, and source will be constructed from the result of Token#getTokenSource and Token#getInputStream.

Parameters
oldToken:Token

The token to copy.

Method Detail

getChannelback to summary
public int getChannel()

Implements org.antlr.v4.runtime.Token.getChannel.

Doc from org.antlr.v4.runtime.Token.getChannel.

Return the channel this token. Each token can arrive at the parser on a different channel, but the parser only "tunes" to a single channel. The parser ignores everything not on DEFAULT_CHANNEL.

Annotations
@Override
getCharPositionInLineback to summary
public int getCharPositionInLine()

Implements org.antlr.v4.runtime.Token.getCharPositionInLine.

Doc from org.antlr.v4.runtime.Token.getCharPositionInLine.

The index of the first character of this token relative to the beginning of the line at which it occurs, 0..n-1

Annotations
@Override
getInputStreamback to summary
public CharStream getInputStream()

Implements org.antlr.v4.runtime.Token.getInputStream.

Doc from org.antlr.v4.runtime.Token.getInputStream.

Gets the CharStream from which this token was derived.

Annotations
@Override
getLineback to summary
public int getLine()

Implements org.antlr.v4.runtime.Token.getLine.

Doc from org.antlr.v4.runtime.Token.getLine.

The line number on which the 1st character of this token was matched, line=1..n

Annotations
@Override
getStartIndexback to summary
public int getStartIndex()

Implements org.antlr.v4.runtime.Token.getStartIndex.

Doc from org.antlr.v4.runtime.Token.getStartIndex.

The starting character index of the token This method is optional; return -1 if not implemented.

Annotations
@Override
getStopIndexback to summary
public int getStopIndex()

Implements org.antlr.v4.runtime.Token.getStopIndex.

Doc from org.antlr.v4.runtime.Token.getStopIndex.

The last character index of the token. This method is optional; return -1 if not implemented.

Annotations
@Override
getTextback to summary
public String getText()

Implements org.antlr.v4.runtime.Token.getText.

Doc from org.antlr.v4.runtime.Token.getText.

Get the text of the token.

Annotations
@Override
getTokenIndexback to summary
public int getTokenIndex()

Implements org.antlr.v4.runtime.Token.getTokenIndex.

Doc from org.antlr.v4.runtime.Token.getTokenIndex.

An index from 0..n-1 of the token object in the input stream. This must be valid in order to print token streams and use TokenRewriteStream. Return -1 to indicate that this token was conjured up since it doesn't have a valid index.

Annotations
@Override
getTokenSourceback to summary
public TokenSource getTokenSource()

Implements org.antlr.v4.runtime.Token.getTokenSource.

Doc from org.antlr.v4.runtime.Token.getTokenSource.

Gets the TokenSource which created this token.

Annotations
@Override
getTypeback to summary
public int getType()

Implements org.antlr.v4.runtime.Token.getType.

Doc from org.antlr.v4.runtime.Token.getType.

Get the token type of the token

Annotations
@Override
setChannelback to summary
public void setChannel(int channel)

Implements org.antlr.v4.runtime.WritableToken.setChannel.

Annotations
@Override
setCharPositionInLineback to summary
public void setCharPositionInLine(int charPositionInLine)

Implements org.antlr.v4.runtime.WritableToken.setCharPositionInLine.

Annotations
@Override
setLineback to summary
public void setLine(int line)

Implements org.antlr.v4.runtime.WritableToken.setLine.

Annotations
@Override
setStartIndexback to summary
public void setStartIndex(int start)
setStopIndexback to summary
public void setStopIndex(int stop)
setTextback to summary
public void setText(String text)

Implements org.antlr.v4.runtime.WritableToken.setText.

Explicitly set the text for this token. If {code text} is not null, then getText will return this value rather than extracting the text from the input.

Parameters
text:String

The explicit text of the token, or null if the text should be obtained from the input along with the start and stop indexes of the token.

Annotations
@Override
setTokenIndexback to summary
public void setTokenIndex(int index)

Implements org.antlr.v4.runtime.WritableToken.setTokenIndex.

Annotations
@Override
setTypeback to summary
public void setType(int type)

Implements org.antlr.v4.runtime.WritableToken.setType.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
toStringback to summary
public String toString(Recognizer<?, ?> r)