Package org.fife.ui.rsyntaxtextarea
Class TokenMap
- java.lang.Object
-
- org.fife.ui.rsyntaxtextarea.TokenMap
-
public class TokenMap extends java.lang.Object
A hash table for reserved words, etc. defined by aTokenMaker
. This class is designed for the quick lookup of tokens, as it can compareSegment
s without the need to allocate a new string.The
org.fife.ui.rsyntaxtextarea
package uses this class to help identify reserved words in programming languages. An instance ofTokenMaker
will create and initialize an instance of this class containing all reserved words, data types, and all other words that need to be syntax-highlighted for that particular language. When the token maker parses a line and identifies an individual token, it is looked up in theTokenMap
to see if it should be syntax-highlighted.- Version:
- 0.6
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
TokenMap.TokenMapToken
The "token" used by a token map.
-
Field Summary
Fields Modifier and Type Field Description private static int
DEFAULT_TOKEN_MAP_SIZE
private boolean
ignoreCase
private int
size
private TokenMap.TokenMapToken[]
tokenMap
-
Constructor Summary
Constructors Constructor Description TokenMap()
Constructs a new token map that is case-sensitive.TokenMap(boolean ignoreCase)
Constructs a new token map.TokenMap(int size)
Constructs a new token map that is case-sensitive.TokenMap(int size, boolean ignoreCase)
Constructs a new token map.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addTokenToBucket(int bucket, TokenMap.TokenMapToken token)
Adds a token to a specified bucket in the token map.int
get(char[] array1, int start, int end)
Returns the token type associated with the given text, if the given text is in this token map.int
get(javax.swing.text.Segment text, int start, int end)
Returns the token type associated with the given text, if the given text is in this token map.private int
getHashCode(char[] text, int offset, int length)
Returns the hash code for a given string.protected boolean
isIgnoringCase()
Returns whether this token map ignores case when checking for tokens.private void
put(char[] string, int tokenType)
Adds a string to this token map.void
put(java.lang.String string, int tokenType)
Adds a string to this token map.
-
-
-
Field Detail
-
size
private int size
-
tokenMap
private TokenMap.TokenMapToken[] tokenMap
-
ignoreCase
private boolean ignoreCase
-
DEFAULT_TOKEN_MAP_SIZE
private static final int DEFAULT_TOKEN_MAP_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TokenMap
public TokenMap()
Constructs a new token map that is case-sensitive.
-
TokenMap
public TokenMap(int size)
Constructs a new token map that is case-sensitive.- Parameters:
size
- The size of the token map.
-
TokenMap
public TokenMap(boolean ignoreCase)
Constructs a new token map.- Parameters:
ignoreCase
- Whether this token map should ignore case when comparing tokens.
-
TokenMap
public TokenMap(int size, boolean ignoreCase)
Constructs a new token map.- Parameters:
size
- The size of the token map.ignoreCase
- Whether this token map should ignore case when comparing tokens.
-
-
Method Detail
-
addTokenToBucket
private void addTokenToBucket(int bucket, TokenMap.TokenMapToken token)
Adds a token to a specified bucket in the token map.- Parameters:
bucket
- The bucket in which to add the token.token
- The token to add.
-
get
public int get(javax.swing.text.Segment text, int start, int end)
Returns the token type associated with the given text, if the given text is in this token map. If it isn't,-1
is returned.- Parameters:
text
- The segment from which to get the text to compare.start
- The starting index in the segment of the text.end
- The ending index in the segment of the text.- Returns:
- The token type associated with the given text, or
-1
if this token was not specified in this map.
-
get
public int get(char[] array1, int start, int end)
Returns the token type associated with the given text, if the given text is in this token map. If it isn't,-1
is returned.- Parameters:
array1
- An array of characters containing the text.start
- The starting index in the array of the text.end
- The ending index in the array of the text.- Returns:
- The token type associated with the given text, or
-1
if this token was not specified in this map.
-
getHashCode
private int getHashCode(char[] text, int offset, int length)
Returns the hash code for a given string.- Parameters:
text
- The text to hash.offset
- The offset into the text at which to start hashing.length
- The last character in the text to hash.- Returns:
- The hash code.
-
isIgnoringCase
protected boolean isIgnoringCase()
Returns whether this token map ignores case when checking for tokens. This property is set in the constructor and cannot be changed, as this is an intrinsic property of a particular programming language.- Returns:
- Whether this token maker is ignoring case.
-
put
public void put(java.lang.String string, int tokenType)
Adds a string to this token map.- Parameters:
string
- The string to add.tokenType
- The type of token the string is.
-
put
private void put(char[] string, int tokenType)
Adds a string to this token map. The char array passed-in will be used as the actual data for the token, so it may well be modified (such as lower-casing it ifignoreCase
istrue
). This shouldn't be an issue though as this method is only called from the publicput
method, which allocates a new char array.- Parameters:
string
- The string to add.tokenType
- The type of token the string is.
-
-