Interface Token
-
@InternalApi public interface Token
A token is an individual element of a SQL statement.The available implementations of
Tokenare primarily guided by the implementation of the tokenization and the needs of the parser and included visitors. It does not distinguish all types of tokens. For example there isQuotedIdentifierTokenbecause the tokenization needs handling for quoted identifiers, while a normal identifier is aGenericToken, because that is handled by the fallback tokenization after checking for all other types. On the other hand, open and close curly braces, square brackets and parentheses each have their own type, as the parser may need this to find nested contexts.- Since:
- 4.0.8
- Author:
- Mark Rotteveel
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidappendTo(java.lang.StringBuilder sb)Appends the current token to the supplied String builder.booleanequalsIgnoreCase(java.lang.String tokenText)Case-insensitive equality of this tokens text using an equivalent ofString.equalsIgnoreCase(String).booleanisValidIdentifier()Detects if the token is valid as an identifier (ignoring length constraints).booleanisWhitespaceOrComment()intlength()Token text length.intposition()Token position.java.lang.Stringtext()Token text.java.lang.CharSequencetextAsCharSequence()Token text asCharSequence.
-
-
-
Method Detail
-
text
java.lang.String text()
Token text.- Returns:
- the text of the token; this is the original text from the source
- See Also:
textAsCharSequence()
-
textAsCharSequence
java.lang.CharSequence textAsCharSequence()
Token text asCharSequence.An basic implementation should return
text(). As an optimization, implementations may return their containedCharSequenceto avoid unnecessary conversion to string.- Returns:
- the text of the token; this is the original text from the source
- See Also:
text()
-
appendTo
void appendTo(java.lang.StringBuilder sb)
Appends the current token to the supplied String builder.A basic implementation should do
sb.append(text())orsb.append(textAsCharSequence()).- Parameters:
sb- String builder to append to
-
position
int position()
Token position.- Returns:
- 0-based position of the occurrence of this token in the source (the first character)
-
length
int length()
Token text length.- Returns:
- Length of the token text
-
isWhitespaceOrComment
boolean isWhitespaceOrComment()
- Returns:
trueif this token is whitespace or a comment,falsefor all other tokens
-
equalsIgnoreCase
boolean equalsIgnoreCase(java.lang.String tokenText)
Case-insensitive equality of this tokens text using an equivalent ofString.equalsIgnoreCase(String).A basic implementation should do
text().equalsIgnoreCase(tokenText).- Parameters:
tokenText- Token text to compare- Returns:
trueiftokenTextis equal - ignoring case - to the text of this token,falseotherwise
-
isValidIdentifier
boolean isValidIdentifier()
Detects if the token is valid as an identifier (ignoring length constraints).This will always return
falseforReservedTokenor other specialised tokens (e.g.OperatorTokenwithISorLIKE) that can't occur as an identifier.- Returns:
trueif the token is valid as an identifier,falseotherwise
-
-