Package software.amazon.smithy.syntax
Class CapturedToken
- java.lang.Object
-
- software.amazon.smithy.syntax.CapturedToken
-
- All Implemented Interfaces:
FromSourceLocation
,ToSmithyBuilder<CapturedToken>
public final class CapturedToken extends java.lang.Object implements FromSourceLocation, ToSmithyBuilder<CapturedToken>
A persisted token captured from anIdlTokenizer
.For performance,
IdlTokenizer
does not create new tokens types for each encountered token. Instead, it updates the current state of the tokenizer and allows the caller to inspect the tokenizer for information about each token. Because smithy-syntax needs to create a token-tree rather than go directly to an AST, it requires arbitrary lookahead of tokens, requiring it to persist tokens in memory.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CapturedToken.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static CapturedToken.Builder
builder()
static CapturedToken
from(IdlTokenizer tokenizer)
Persist the current token of anIdlTokenizer
.static CapturedToken
from(IdlTokenizer tokenizer, java.util.function.Function<java.lang.CharSequence,java.lang.String> stringTable)
Persist the current token of anIdlTokenizer
.int
getEndColumn()
int
getEndLine()
java.lang.String
getErrorMessage()
Gets the associated error message with the token if it's an error.java.lang.String
getFilename()
IdlToken
getIdlToken()
Get the token IDL token of the captured token.java.lang.CharSequence
getLexeme()
Get the raw lexeme of the current token.java.lang.Number
getNumberValue()
Get the computedNumber
of the current token if it's a number.int
getPosition()
SourceLocation
getSourceLocation()
Gets the source location of a value.int
getSpan()
int
getStartColumn()
int
getStartLine()
java.lang.String
getStringContents()
Get the associated String contents of the token if it's a string, text block, or identifier.CapturedToken.Builder
toBuilder()
Take this object and create a builder that contains all of the current property values of this object.
-
-
-
Method Detail
-
builder
public static CapturedToken.Builder builder()
-
from
public static CapturedToken from(IdlTokenizer tokenizer)
Persist the current token of anIdlTokenizer
.- Parameters:
tokenizer
- Tokenizer to capture.- Returns:
- Returns the persisted token.
-
from
public static CapturedToken from(IdlTokenizer tokenizer, java.util.function.Function<java.lang.CharSequence,java.lang.String> stringTable)
Persist the current token of anIdlTokenizer
.- Parameters:
tokenizer
- Tokenizer to capture.stringTable
- String table that caches previously created strings.- Returns:
- Returns the persisted token.
-
toBuilder
public CapturedToken.Builder toBuilder()
Description copied from interface:ToSmithyBuilder
Take this object and create a builder that contains all of the current property values of this object.- Specified by:
toBuilder
in interfaceToSmithyBuilder<CapturedToken>
- Returns:
- a builder for type T
-
getIdlToken
public IdlToken getIdlToken()
Get the token IDL token of the captured token.- Returns:
- Returns the underlying token type.
-
getSourceLocation
public SourceLocation getSourceLocation()
Description copied from interface:FromSourceLocation
Gets the source location of a value.- Specified by:
getSourceLocation
in interfaceFromSourceLocation
- Returns:
- Returns the source location of the value.
-
getFilename
public java.lang.String getFilename()
-
getPosition
public int getPosition()
-
getStartLine
public int getStartLine()
-
getStartColumn
public int getStartColumn()
-
getEndLine
public int getEndLine()
-
getEndColumn
public int getEndColumn()
-
getSpan
public int getSpan()
-
getLexeme
public java.lang.CharSequence getLexeme()
Get the raw lexeme of the current token.- Returns:
- Returns the underlying lexeme of the token.
-
getStringContents
public java.lang.String getStringContents()
Get the associated String contents of the token if it's a string, text block, or identifier.- Returns:
- Returns the string contents of the lexeme, or null if not a string|text block|identifier.
-
getErrorMessage
public java.lang.String getErrorMessage()
Gets the associated error message with the token if it's an error.- Returns:
- Returns the error message or null if not an error.
-
getNumberValue
public java.lang.Number getNumberValue()
Get the computedNumber
of the current token if it's a number.- Returns:
- Returns the computed Number or null if not a number.
-
-