public final class Language<T extends TokenId> extends Object
TokenHierarchy
which is an entry point into the Lexer API.
TokenId
s
that can be retrieved by Language.tokenIds()
and token categories
Language.tokenCategories()
.
The language cannot be instantiated directly.
Instead it should be obtained from LanguageHierarchy.language()
on an existing language hierarchy.
LanguageHierarchy
,
TokenId
Modifier and Type | Method and Description |
---|---|
String |
dumpInfo()
Dump list of token ids for this language into string.
|
boolean |
equals(Object obj)
The languages are equal only if they are the same objects.
|
static Language<? extends TokenId> |
find(String mimeType)
Finds a language by its mime type.
|
int |
hashCode()
The hashCode of the language is the identity hashCode.
|
int |
maxOrdinal()
Get maximum ordinal of all the token ids that this language contains.
|
Set<T> |
merge(Collection<T> tokenIds1,
Collection<T> tokenIds2)
Merge two collections of token ids from this language
into an efficient indexed set (the implementation similar
to
EnumSet ). |
String |
mimeType()
Gets the mime type of this language.
|
List<String> |
nonPrimaryTokenCategories(T tokenId)
Get list of non-primary token categories (not containing the primary category)
for the particular token id.
|
Set<String> |
tokenCategories()
Get names of all token categories of this language.
|
List<String> |
tokenCategories(T tokenId)
Get list of all token categories for the particular token id.
|
Set<T> |
tokenCategoryMembers(String tokenCategory)
Get members of the category with given name.
|
T |
tokenId(int ordinal)
Get tokenId for the given ordinal.
|
T |
tokenId(String name)
Find the tokenId from its name.
|
Set<T> |
tokenIds()
Get unmodifiable set of ids contained in this language.
|
String |
toString() |
T |
validTokenId(int ordinal)
Similar to
Language.tokenId(int) however it guarantees
that it will always return non-null tokenId. |
T |
validTokenId(String name)
Similar to
Language.tokenId(String) but guarantees a valid tokenId to be returned. |
public static Language<? extends TokenId> find(String mimeType)
This method uses information from LanguageProvider
s registered
in the default lookup to find Language
for a given
mime type.
Netbeans provide an implementation of LanguageProvider
that reads data from the Editors
folder on the system filesystem.
Therefore Netbeans modules can register their Language
s
in MimeLookup as any other mime-type related service.
mimeType
- The mime type of a language that you want to find.Language
registered
for the given mimeType
. Null is returned for null mimeType.public Set<T> tokenIds()
public T tokenId(int ordinal)
ordinal
- ordinal to be translated to corresponding tokenId.IndexOutOfBoundsException
.IndexOutOfBoundsException
- if the ordinal is
<0 or higher than Language.maxOrdinal()
.public T validTokenId(int ordinal)
Language.tokenId(int)
however it guarantees
that it will always return non-null tokenId. Typically for a lexer
just being developed it's possible that there are some integer
token ids defined in the generated lexer for which there is
no correspondence in the language. The lexer wrapper should
always call this method if it expects to find a valid
counterpart for given integer id.ordinal
- ordinal to translate to token id.IndexOutOfBoundsException
- if the ordinal is
<0 or higher than Language.maxOrdinal()
or when there is no corresponding
token id for it.public T tokenId(String name)
name
- name of the tokenId to find.public T validTokenId(String name)
Language.tokenId(String)
but guarantees a valid tokenId to be returned.IllegalArgumentException
- if no token in this language has the given name.public int maxOrdinal()
-1
if the language contains no token ids.public Set<String> tokenCategories()
public Set<T> tokenCategoryMembers(String tokenCategory)
tokenCategory
- non-null name of the category.public List<String> tokenCategories(T tokenId)
IllegalArgumentException
- if the given token id does not belong
to this language.public List<String> nonPrimaryTokenCategories(T tokenId)
Language.tokenCategories(TokenId)
.IllegalArgumentException
- if the given token id does not belong
to this language.public Set<T> merge(Collection<T> tokenIds1, Collection<T> tokenIds2)
EnumSet
).tokenIds1
- non-null collection of token ids to be contained in the returned set.tokenIds2
- collection of token ids to be contained in the returned set.public String mimeType()
public boolean equals(Object obj)
public int hashCode()
public String dumpInfo()