|
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.TokenHierarchy<I>
public final class TokenHierarchy<I>
Token hierarchy represents a given input source as a browsable hierarchy of tokens.
It's is an entry point into the Lexer API.
It allows to create token sequences for hierarchy exploration
and watching for token changes by attaching the token hierarchy listeners.
The hierarchy may either be flat or it can be a tree if the
corresponding language hierarchy contains language embeddings.
createSnapshot()
on the live token hierarchy.
Method Summary | ||
---|---|---|
void |
addTokenHierarchyListener(TokenHierarchyListener listener)
Add listener for token changes inside this hierarchy. |
|
static
|
create(CharSequence inputText,
boolean copyInputText,
Language<T> language,
Set<T> skipTokenIds,
InputAttributes inputAttributes)
Create token hierarchy for the given input text. |
|
static TokenHierarchy<Void> |
create(CharSequence inputText,
Language<? extends TokenId> language)
Create token hierarchy for the given non-mutating input text (for example java.lang.String). |
|
static
|
create(Reader inputReader,
Language<T> language,
Set<T> skipTokenIds,
InputAttributes inputAttributes)
Create token hierarchy for the given reader. |
|
TokenHierarchy<I> |
createSnapshot()
Create a snapshot of the present mutable token hierarchy. |
|
static
|
get(D doc)
Get or create mutable token hierarchy for the given swing document. |
|
boolean |
isActive()
Token hierarchy may be set inactive to release resources consumed by tokens. |
|
boolean |
isMutable()
Whether input text of this token hierarchy is mutable or not. |
|
boolean |
isSnapshot()
Check whether this token hierarchy is a snapshot. |
|
boolean |
isSnapshotReleased()
Check whether this snapshot is released. |
|
Set<LanguagePath> |
languagePaths()
Get a set of language paths used by this token hierarchy. |
|
I |
mutableInputSource()
Get mutable input source providing text over which this token hierarchy was constructed. |
|
void |
removeTokenHierarchyListener(TokenHierarchyListener listener)
Remove listener for token changes inside this hierarchy. |
|
TokenHierarchy<I> |
snapshotOf()
If this token hierarchy is snapshot then return the token hierarchy for which this snapshot was constructed. |
|
void |
snapshotRelease()
Release snapshot - should only be called if this token hierarchy is a snapshot. |
|
TokenSequence<? extends TokenId> |
tokenSequence()
Get token sequence of the top level language of the token hierarchy. |
|
|
tokenSequence(Language<T> language)
Get token sequence of the top level of the language hierarchy only if it's of the given language. |
|
List<TokenSequence<? extends TokenId>> |
tokenSequenceList(LanguagePath languagePath,
int startOffset,
int endOffset)
Get list of token sequences with the given language path from this hierarchy. |
|
int |
tokenShiftEndOffset()
Get end offset of the area where the tokens in the token hierarchy snapshot have explicitly shifted offsets. |
|
int |
tokenShiftStartOffset()
Get start offset of the area where the tokens in the token hierarchy snapshot have explicitly shifted offsets. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <D extends Document> TokenHierarchy<D> get(D doc)
doc
- swing text document for which the token hiearchy should be obtained.
null
in case the token hierarchy
does not exist yet and the Language.class
document property was not yet initialized with the valid language
so the hierarchy cannot be created.public static TokenHierarchy<Void> create(CharSequence inputText, Language<? extends TokenId> language)
public static <T extends TokenId> TokenHierarchy<Void> create(CharSequence inputText, boolean copyInputText, Language<T> language, Set<T> skipTokenIds, InputAttributes inputAttributes)
inputText
- input text containing the characters to tokenize.copyInputText
- true
in case the content of the input
will not be modified in the future so the created tokens can reference it.
false
means that the text can change in the future
and the tokens should not directly reference it. Instead copy of the necessary text
from the input should be made and the original text should not be referenced.language
- language defining how the input
will be tokenized.skipTokenIds
- set containing the token ids for which the tokens
should not be created in the created token hierarchy.
null
may be passed which means that no tokens will be skipped.
Language.tokenCategoryMembers(String)
or Language.merge(Collection,Collection)
.inputAttributes
- additional properties related to the input
that may influence token creation or lexer operation
for the particular language (such as version of the language to be used).
public static <T extends TokenId> TokenHierarchy<Void> create(Reader inputReader, Language<T> language, Set<T> skipTokenIds, InputAttributes inputAttributes)
inputReader
- input reader containing the characters to tokenize.language
- language defining how the input
will be tokenized.skipTokenIds
- set containing the token ids for which the tokens
should not be created in the created token hierarchy.
null
may be passed which means that no tokens will be skipped.
Language.tokenCategoryMembers(String)
or Language.merge(Collection,Collection)
.inputAttributes
- additional properties related to the input
that may influence token creation or lexer operation
for the particular language (such as version of the language to be used).
public TokenSequence<? extends TokenId> tokenSequence()
TokenSequence.embedded()
.
public <T extends TokenId> TokenSequence<T> tokenSequence(Language<T> language)
(tokenSequence().language() == language)
.
Null is returned otherwise.public List<TokenSequence<? extends TokenId>> tokenSequenceList(LanguagePath languagePath, int startOffset, int endOffset)
languagePath
- non-null language path that the obtained token sequences
will all have.startOffset
- starting offset of the TSs to get. Use 0 for no limit.
If the particular TS ends after this offset then it will be returned.endOffset
- ending offset of the TS to get. Use Integer.MAX_VALUE for no limit.
If the particular TS starts before this offset then it will be returned.public Set<LanguagePath> languagePaths()
LanguageHierarchy.embedding(Token,LanguagePath,InputAttributes)
.
public boolean isMutable()
public I mutableInputSource()
Document
in case the token hierarchy
was constructed for its text.
public boolean isActive()
public void addTokenHierarchyListener(TokenHierarchyListener listener)
listener
- token change listener to be added.public void removeTokenHierarchyListener(TokenHierarchyListener listener)
listener
- token change listener to be removed.public TokenHierarchy<I> createSnapshot()
snapshotRelease()
.
Another way is to forget the reference to the snapshot token hierarchy
but it depends on the garbage collector's releasing of the weak reference.
token.offset(snapshotHierarchy)
will give the offset
of the token in a snapshot while token.offset(null)
will return the offset of the token in the live hierarchy.
The snapshot attempts to share tokens with the live token hierarchy.
public boolean isSnapshot()
public void snapshotRelease()
IllegalStateException
- if this token hierarchy was already released
or it's not a snapshot.public boolean isSnapshotReleased()
IllegalStateException
- if this token hierarchy is not a snapshot.public TokenHierarchy<I> snapshotOf()
public int tokenShiftStartOffset()
tokenShiftEndOffset()
the tokens
are either removed from the live token hierarchy or still present in it
but all of them have explicitly corrected offsets.
tokenShiftEndOffset()
public int tokenShiftEndOffset()
Token.offset(null)
.
tokenShiftStartOffset()
|
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 |