|
org.netbeans.modules.lexer/2 1.19.0 1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.netbeans.api.lexer.Token<T>
Token describes a lexical element of input text.
It mainly provides an identification by id()
and a textual body (aka token's image) by text()
.
Only lexers should produce token instances and they should do it
solely by using methods of TokenFactory
.
Note:
Do not create custom extensions of this class - lexers may only return
implementations produced by TokenFactory
.
Creation of any other token implementations will be refused.
Token guarantees stability of the id()
and length()
methods.
The hashCode()
and equals(Object)
methods
use the default implementations from java.lang.Object
.
The two tokens are only equal if they are the same object.
Constructor Summary | |
---|---|
protected |
Token()
Create token instance. |
Method Summary | |
---|---|
boolean |
equals(Object o)
Make sure the default implementation of equals() is used
and the token can safely be used in maps. |
abstract Object |
getProperty(Object key)
Get extra property of this token. |
int |
hashCode()
Make sure the default implementation of hashCode() is used
and the token can safely be used in maps. |
abstract boolean |
hasProperties()
Quickly determine whether this token has any extra properties. |
abstract T |
id()
Get identification of this token. |
abstract boolean |
isCustomText()
Check whether text() returns a custom value that may differ
from the original content of the text input. |
abstract boolean |
isFlyweight()
Checks whether this token instance is used for multiple occurrences of this token in this or other inputs. |
abstract boolean |
isPreprocessedText()
Check whether this token has preprocessed text (e.g. |
abstract int |
length()
Get number of characters in the original text input that the token spans. |
abstract int |
offset(TokenHierarchy<?> tokenHierarchy)
Get the offset at which this token is present in the input or -1 if this token is flyweight (and therefore does not store offset). |
abstract PartType |
partType()
Check whether this token represents a complete token or whether it's a part of a complete token. |
abstract CharSequence |
preprocessedText()
Get a text of this token as it was preprocessed by a character preprocessor (e.g. |
abstract String |
preprocessError()
Get an description of the error that occurred during preprocessing of the token's characters. |
abstract int |
preprocessErrorIndex()
Get the index relative to the token's begining (in the original input text) of where the preprocessor error has occurred. |
abstract CharSequence |
text()
Get text of this token (aka token's image) as a character sequence. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected Token()
IllegalStateException
- if a non-lexer-module-implementation token
is attempted to be created.Method Detail |
---|
public abstract T id()
public abstract CharSequence text()
isCustomText()
returns true.
Note for mutable input sources:
This method should only be called
within a readonly (or read-write) transaction
over the underlying input source
(such as javax.swing.text.Document.render()
for Swing documents).
The result returned by this method
is only valid within a readonly (or read-write) transaction
over the input source (method must be re-called
during the next readonly transaction).
null
in case the token was used
for a mutable input and it was removed
from the token list for the given input (but even in such case
the text can be retained in certain cases).
The behavior of equals()
and hashCode()
of the returned character sequence is generally undefined.
The returned character sequence can NOT be compared to another
character sequence by using its equals()
method.
TokenUtilities
contains
utility methods related to token text comparing.
The returned text is just a pointer to the primary source of the data e.g. a swing document. The character data are not duplicated in the tokens.
preprocessedText()
public abstract boolean isCustomText()
text()
returns a custom value that may differ
from the original content of the text input.
public abstract int length()
text()
.length()
unless isCustomText()
returns true.
null
.
public abstract int offset(TokenHierarchy<?> tokenHierarchy)
-1
if this token is flyweight (and therefore does not store offset).
TokenSequence.offset()
is usually preferred over
this method.
TokenSequence.offset()
when positioned on the particular
flyweight token.
TokenSequence.offsetToken()
.
The complexity of the method should generally be constant regardless of the level of the language embedding.
tokenHierarchy
- token hierarchy to which the offset computation
will be related. It may either be the live token hierarchy
(which is equivalent to passing null
)
or a snapshot of the original token hierarchy. For other values
the result is generally undefined.
-1
if this token is flyweight.public abstract boolean isFlyweight()
If the token is flyweight its offset(TokenHierarchy)
returns -1.
public abstract PartType partType()
public abstract boolean isPreprocessedText()
preprocessedText()
returns a valid result.public abstract CharSequence preprocessedText()
public abstract String preprocessError()
public abstract int preprocessErrorIndex()
public abstract boolean hasProperties()
public abstract Object getProperty(Object key)
key
- non-null key of the property to get.
hasProperties()
public final int hashCode()
hashCode()
is used
and the token can safely be used in maps.
public final boolean equals(Object o)
equals()
is used
and the token can safely be used in maps.
|
org.netbeans.modules.lexer/2 1.19.0 1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |