public class MutableToken extends Object implements Token
Token that is mutable. Mutable tokens can be
modified and are commonly used by LanguageParsers to
reduce memory usage during parsing.| Constructor and Description |
|---|
MutableToken()
Create a new empty token.
|
MutableToken(TokenType type,
Location start,
Location end,
CharSequence text)
Create a new token with a given type, location and text.
|
| Modifier and Type | Method and Description |
|---|---|
Token |
copy()
Get a copy of this token as an
ImmutableToken. |
void |
copyFrom(Token other)
Copy data from another token into this one.
|
<T> T |
get(TokenProperty<T> property)
Get some optional data for this token.
|
Location |
getEnd()
Get where this token ends.
|
Map<String,Object> |
getProperties()
Get properties as a
Map. |
Location |
getStart()
Get where this token starts.
|
String |
getText()
Get the text of the token.
|
TokenType |
getType()
Get the type of token.
|
boolean |
has(TokenProperty<?> property)
Get if this token has the given data.
|
static MutableToken |
ofType(TokenType type) |
<T> MutableToken |
set(TokenProperty<T> property,
T value)
Set a property for this token.
|
MutableToken |
setEnd(Location end) |
MutableToken |
setStart(Location start) |
MutableToken |
setText(CharSequence text) |
MutableToken |
setType(TokenType type) |
String |
toString() |
void |
update(TokenType type,
Location start,
Location end,
CharSequence text)
Update the data within the token.
|
void |
update(TokenType type,
Location start,
Location end,
CharSequence text,
Map<String,Object> otherProperties)
Update the data within the token including properties.
|
public MutableToken()
public MutableToken(TokenType type, Location start, Location end, CharSequence text)
type - the type of the tokenstart - the start of the tokenend - the end of the tokentext - text of the sequence, will be turned into a String internallypublic void update(TokenType type, Location start, Location end, CharSequence text)
type - the type of the tokenstart - the start of the tokenend - the end of the tokentext - text of the sequence, will be turned into a String internallypublic void update(TokenType type, Location start, Location end, CharSequence text, Map<String,Object> otherProperties)
type - the type of the tokenstart - the start of the tokenend - the end of the tokentext - text of the sequence, will be turned into a String internallyotherProperties - properties for the tokenpublic void copyFrom(Token other)
other - public MutableToken setType(TokenType type)
public MutableToken setText(CharSequence text)
public Location getStart()
Tokenpublic MutableToken setStart(Location start)
public MutableToken setEnd(Location end)
public <T> T get(TokenProperty<T> property)
Tokenpublic boolean has(TokenProperty<?> property)
Tokenpublic <T> MutableToken set(TokenProperty<T> property, T value)
property - the property to setvalue - the value of the propertypublic Map<String,Object> getProperties()
TokenMap.getProperties in interface Tokenpublic Token copy()
TokenImmutableToken.public static MutableToken ofType(TokenType type)
Copyright © 2018. All rights reserved.