public class TokenImpl extends java.lang.Object implements Token
Token
.
Note: The instances of Token
returned by
RSyntaxDocument
s are pooled and should always be treated as
immutable. They should not be cast to TokenImpl
and modified.
Modifying tokens you did not create yourself can and will result in
rendering issues and/or runtime exceptions. You have been warned!
限定符和类型 | 字段和说明 |
---|---|
char[] |
text
The text this token represents.
|
int |
textCount |
int |
textOffset |
ANNOTATION, COMMENT_DOCUMENTATION, COMMENT_EOL, COMMENT_KEYWORD, COMMENT_MARKUP, COMMENT_MULTILINE, DATA_TYPE, DEFAULT_NUM_TOKEN_TYPES, ERROR_CHAR, ERROR_IDENTIFIER, ERROR_NUMBER_FORMAT, ERROR_STRING_DOUBLE, FUNCTION, IDENTIFIER, LITERAL_BACKQUOTE, LITERAL_BOOLEAN, LITERAL_CHAR, LITERAL_NUMBER_DECIMAL_INT, LITERAL_NUMBER_FLOAT, LITERAL_NUMBER_HEXADECIMAL, LITERAL_STRING_DOUBLE_QUOTE, MARKUP_CDATA, MARKUP_CDATA_DELIMITER, MARKUP_COMMENT, MARKUP_DTD, MARKUP_ENTITY_REFERENCE, MARKUP_PROCESSING_INSTRUCTION, MARKUP_TAG_ATTRIBUTE, MARKUP_TAG_ATTRIBUTE_VALUE, MARKUP_TAG_DELIMITER, MARKUP_TAG_NAME, NULL, OPERATOR, PREPROCESSOR, REGEX, RESERVED_WORD, RESERVED_WORD_2, SEPARATOR, VARIABLE, WHITESPACE
构造器和说明 |
---|
TokenImpl()
Creates a "null token."
|
TokenImpl(char[] line,
int beg,
int end,
int startOffset,
int type)
Constructor.
|
TokenImpl(javax.swing.text.Segment line,
int beg,
int end,
int startOffset,
int type)
Constructor.
|
TokenImpl(Token t2)
Creates this token as a copy of the passed-in token.
|
限定符和类型 | 方法和说明 |
---|---|
java.lang.StringBuilder |
appendHTMLRepresentation(java.lang.StringBuilder sb,
RSyntaxTextArea textArea,
boolean fontFamily)
Appends HTML code for painting this token, using the given text area's
color scheme.
|
java.lang.StringBuilder |
appendHTMLRepresentation(java.lang.StringBuilder sb,
RSyntaxTextArea textArea,
boolean fontFamily,
boolean tabsToSpaces)
Appends HTML code for painting this token, using the given text area's
color scheme.
|
char |
charAt(int index)
Returns the character at the specified offset in the token.
|
boolean |
containsPosition(int pos)
Returns whether the token straddles the specified position in the
document.
|
void |
copyFrom(Token t2)
Makes one token point to the same text segment, and have the same value
as another token.
|
int |
documentToToken(int pos)
Returns the position in the token's internal char array corresponding
to the specified document position.
|
boolean |
endsWith(char[] ch)
Returns whether this token's lexeme ends with the specified characters.
|
int |
getEndOffset()
Returns the end offset of this token in the document (exclusive).
|
java.lang.String |
getHTMLRepresentation(RSyntaxTextArea textArea)
Returns a
String containing HTML code for painting this
token, using the given text area's color scheme. |
int |
getLanguageIndex()
Returns the language index of this token.
|
Token |
getLastNonCommentNonWhitespaceToken()
Returns the last token in this list that is not whitespace or a
comment.
|
Token |
getLastPaintableToken()
Returns the last paintable token in this token list, or
null
if there is no paintable token. |
java.lang.String |
getLexeme()
Returns the text of this token, as a string.
|
int |
getListOffset(RSyntaxTextArea textArea,
javax.swing.text.TabExpander e,
float x0,
float x)
Determines the offset into this token list (i.e., into the
document) that covers pixel location
x if the token list
starts at pixel location x0 . |
Token |
getNextToken()
Returns the token after this one in the linked list.
|
int |
getOffset()
Returns the offset into the document at which this token resides.
|
int |
getOffsetBeforeX(RSyntaxTextArea textArea,
javax.swing.text.TabExpander e,
float startX,
float endBeforeX)
Returns the position in the document that represents the last character
in the token that will fit into
endBeforeX-startX pixels. |
char[] |
getTextArray()
Returns the character array backing the lexeme of this token.
|
int |
getTextOffset()
Returns the offset into the character array of the lexeme in
Token.getTextArray() . |
int |
getType()
Returns the type of this token.
|
float |
getWidth(RSyntaxTextArea textArea,
javax.swing.text.TabExpander e,
float x0)
Returns the width of this token given the specified parameters.
|
float |
getWidthUpTo(int numChars,
RSyntaxTextArea textArea,
javax.swing.text.TabExpander e,
float x0)
Returns the width of a specified number of characters in this token.
|
boolean |
is(char[] lexeme)
Returns whether this token's lexeme matches a specific character array.
|
boolean |
is(int type,
char[] lexeme)
Returns whether this token is of the specified type, with the specified
lexeme.
|
boolean |
is(int type,
java.lang.String lexeme)
Returns whether this token is of the specified type, with the specified
lexeme.
|
boolean |
isComment()
Returns whether this token is a comment.
|
boolean |
isCommentOrWhitespace()
Returns whether this token is a comment or whitespace.
|
boolean |
isHyperlink()
Returns whether this token is a hyperlink.
|
boolean |
isIdentifier()
Returns whether this token is an identifier.
|
boolean |
isLeftCurly()
Returns whether this token is a
TokenTypes.SEPARATOR representing a single
left curly brace. |
boolean |
isPaintable()
Returns whether or not this token is "paintable;" i.e., whether or not
the type of this token is one such that it has an associated syntax
style.
|
boolean |
isRightCurly()
Returns whether this token is a
TokenTypes.SEPARATOR representing a single
right curly brace. |
boolean |
isSingleChar(char ch)
Returns whether this token is the specified single character.
|
boolean |
isSingleChar(int type,
char ch)
Returns whether this token is the specified single character, and of a
specific type.
|
boolean |
isWhitespace()
Returns whether or not this token is whitespace.
|
int |
length()
Returns the length of this token.
|
java.awt.Rectangle |
listOffsetToView(RSyntaxTextArea textArea,
javax.swing.text.TabExpander e,
int pos,
int x0,
java.awt.Rectangle rect)
Returns the bounding box for the specified document location.
|
void |
makeStartAt(int pos)
Makes this token start at the specified offset into the document.
|
void |
moveOffset(int amt)
Moves the starting offset of this token.
|
void |
set(char[] line,
int beg,
int end,
int offset,
int type)
Sets the value of this token to a particular segment of a document.
|
void |
setHyperlink(boolean hyperlink)
Sets whether this token is a hyperlink.
|
void |
setLanguageIndex(int languageIndex)
Sets the language index for this token.
|
void |
setNextToken(Token nextToken)
Sets the "next token" pointer of this token to point to the specified
token.
|
void |
setOffset(int offset)
Sets the offset into the document at which this token resides.
|
void |
setType(int type)
Sets the type of this token.
|
boolean |
startsWith(char[] chars)
Returns whether this token starts with the specified characters.
|
int |
tokenToDocument(int pos)
Returns the position in the document corresponding to the specified
position in this token's internal char array (
textOffset -
textOffset+textCount-1 ). |
java.lang.String |
toString()
Returns this token as a
String , which is useful for
debugging. |
public char[] text
public int textOffset
public int textCount
public TokenImpl()
public TokenImpl(javax.swing.text.Segment line, int beg, int end, int startOffset, int type)
line
- The segment from which to get the token.beg
- The first character's position in line
.end
- The last character's position in line
.startOffset
- The offset into the document at which this
token begins.type
- A token type listed as "generic" above.public TokenImpl(char[] line, int beg, int end, int startOffset, int type)
line
- The segment from which to get the token.beg
- The first character's position in line
.end
- The last character's position in line
.startOffset
- The offset into the document at which this
token begins.type
- A token type listed as "generic" above.public TokenImpl(Token t2)
t2
- The token from which to make a copy.public java.lang.StringBuilder appendHTMLRepresentation(java.lang.StringBuilder sb, RSyntaxTextArea textArea, boolean fontFamily)
Token
appendHTMLRepresentation
在接口中 Token
sb
- The buffer to append to.textArea
- The text area whose color scheme to use.fontFamily
- Whether to include the font family in the HTML for
this token. You can pass false
for this parameter
if, for example, you are making all your HTML be monospaced,
and don't want any crazy fonts being used in the editor to be
reflected in your HTML.Token.getHTMLRepresentation(RSyntaxTextArea)
public java.lang.StringBuilder appendHTMLRepresentation(java.lang.StringBuilder sb, RSyntaxTextArea textArea, boolean fontFamily, boolean tabsToSpaces)
Token
appendHTMLRepresentation
在接口中 Token
sb
- The buffer to append to.textArea
- The text area whose color scheme to use.fontFamily
- Whether to include the font family in the HTML for
this token. You can pass false
for this parameter
if, for example, you are making all your HTML be monospaced,
and don't want any crazy fonts being used in the editor to be
reflected in your HTML.tabsToSpaces
- Whether to convert tabs into spaces.Token.getHTMLRepresentation(RSyntaxTextArea)
public char charAt(int index)
Token
charAt
在接口中 Token
index
- The index. This should be in the range
0-(Token.length()
-1)
.Token.length()
public boolean containsPosition(int pos)
Token
containsPosition
在接口中 Token
pos
- The position in the document to check.public void copyFrom(Token t2)
t2
- The token from which to copy.public int documentToToken(int pos)
Token
Note that this method does NOT do any bounds checking; you can pass in a document position that does not correspond to a position in this token, and you will not receive an Exception or any other notification; it is up to the caller to ensure valid input.
documentToToken
在接口中 Token
pos
- A position in the document that is represented by this token.textOffset
and
< textOffset+textCount
.Token.tokenToDocument(int)
public boolean endsWith(char[] ch)
Token
endsWith
在接口中 Token
ch
- The characters.Token.startsWith(char[])
public int getEndOffset()
Token
[getOffset(), getEndOffset())
.getEndOffset
在接口中 Token
Token.getOffset()
public java.lang.String getHTMLRepresentation(RSyntaxTextArea textArea)
Token
String
containing HTML code for painting this
token, using the given text area's color scheme.getHTMLRepresentation
在接口中 Token
textArea
- The text area whose color scheme to use.Token.appendHTMLRepresentation(StringBuilder, RSyntaxTextArea, boolean)
public int getLanguageIndex()
Token
getLanguageIndex
在接口中 Token
0
denotes the
"main" language, any positive value denotes a specific secondary
language.Token.setLanguageIndex(int)
public Token getLastNonCommentNonWhitespaceToken()
Token
getLastNonCommentNonWhitespaceToken
在接口中 Token
null
if there isn't one.public Token getLastPaintableToken()
Token
null
if there is no paintable token.getLastPaintableToken
在接口中 Token
public java.lang.String getLexeme()
Token
Note that this method isn't used much by the
ryntaxtextarea
package internally, as it tries to limit
memory allocation.
public int getListOffset(RSyntaxTextArea textArea, javax.swing.text.TabExpander e, float x0, float x)
Token
x
if the token list
starts at pixel location x0
.
This method will return the document position "closest" to the
x-coordinate (i.e., if they click on the "right-half" of the
w
in awe
, the caret will be placed in
between the w
and e
; similarly, clicking on
the left-half places the caret between the a
and
w
). This makes it useful for methods such as
viewToModel
found in javax.swing.text.View
subclasses.
getListOffset
在接口中 Token
textArea
- The text area from which the token list was derived.e
- How to expand tabs.x0
- The pixel x-location that is the beginning of
tokenList
.x
- The pixel-position for which you want to get the corresponding
offset.tokenList
is
null
or has type Token.NULL
, then
-1
public Token getNextToken()
Token
getNextToken
在接口中 Token
public int getOffset()
Token
getOffset
在接口中 Token
Token.getEndOffset()
public int getOffsetBeforeX(RSyntaxTextArea textArea, javax.swing.text.TabExpander e, float startX, float endBeforeX)
Token
endBeforeX-startX
pixels.
For example, if you're using a monospaced 8-pixel-per-character font,
have the token "while" and startX
is 0
and
endBeforeX
is 30
, this method will return the
document position of the "i" in "while", because the "i" ends at pixel
24
, while the "l" ends at 32
. If not even the
first character fits in endBeforeX-startX
, the first
character's position is still returned so calling methods don't go into
infinite loops.getOffsetBeforeX
在接口中 Token
textArea
- The text area in which this token is being painted.e
- How to expand tabs.startX
- The x-coordinate at which the token will be painted. This
is needed because of tabs.endBeforeX
- The x-coordinate for which you want to find the last
character of t
which comes before it.public char[] getTextArray()
Token
getTextArray
在接口中 Token
Token.getTextOffset()
,
Token.length()
public int getTextOffset()
Token
Token.getTextArray()
.getTextOffset
在接口中 Token
Token.getTextArray()
public int getType()
Token
getType
在接口中 Token
TokenTypes
,
Token.setType(int)
public float getWidth(RSyntaxTextArea textArea, javax.swing.text.TabExpander e, float x0)
Token
getWidth
在接口中 Token
textArea
- The text area in which the token is being painted.e
- Describes how to expand tabs. This parameter cannot be
null
.x0
- The pixel-location at which the token begins. This is needed
because of tabs.Token.getWidthUpTo(int, com.fr.design.gui.syntax.ui.rsyntaxtextarea.RSyntaxTextArea, javax.swing.text.TabExpander, float)
public float getWidthUpTo(int numChars, RSyntaxTextArea textArea, javax.swing.text.TabExpander e, float x0)
Token
3
here returns the width of the "whi" portion of the token.getWidthUpTo
在接口中 Token
numChars
- The number of characters for which to get the width.textArea
- The text area in which the token is being painted.e
- How to expand tabs. This value cannot be null
.x0
- The pixel-location at which this token begins. This is needed
because of tabs.Token.getWidth(com.fr.design.gui.syntax.ui.rsyntaxtextarea.RSyntaxTextArea, javax.swing.text.TabExpander, float)
public boolean is(char[] lexeme)
Token
is
在接口中 Token
lexeme
- The lexeme to check for.Token.is(int, char[])
,
Token.is(int, String)
,
Token.isSingleChar(int, char)
,
Token.startsWith(char[])
public boolean is(int type, char[] lexeme)
Token
This method is preferred over the other overload in performance-critical code where this operation may be called frequently, since it does not involve any String allocations.
is
在接口中 Token
type
- The type to check for.lexeme
- The lexeme to check for.Token.is(int, String)
,
Token.is(char[])
,
Token.isSingleChar(int, char)
,
Token.startsWith(char[])
public boolean is(int type, java.lang.String lexeme)
Token
The other overload of this method is preferred over this one in performance-critical code, as this one involves a String allocation while the other does not.
is
在接口中 Token
type
- The type to check for.lexeme
- The lexeme to check for.Token.is(int, char[])
,
Token.isSingleChar(int, char)
,
Token.startsWith(char[])
public boolean isComment()
Token
isComment
在接口中 Token
Token.isWhitespace()
,
Token.isCommentOrWhitespace()
public boolean isCommentOrWhitespace()
Token
isCommentOrWhitespace
在接口中 Token
Token.isComment()
,
Token.isWhitespace()
public boolean isHyperlink()
Token
isHyperlink
在接口中 Token
Token.setHyperlink(boolean)
public boolean isIdentifier()
Token
isIdentifier
在接口中 Token
public boolean isLeftCurly()
Token
TokenTypes.SEPARATOR
representing a single
left curly brace.isLeftCurly
在接口中 Token
Token.isRightCurly()
public boolean isRightCurly()
Token
TokenTypes.SEPARATOR
representing a single
right curly brace.isRightCurly
在接口中 Token
Token.isLeftCurly()
public boolean isPaintable()
Token
Token.NULL
.isPaintable
在接口中 Token
public boolean isSingleChar(char ch)
Token
isSingleChar
在接口中 Token
ch
- The character to check for.Token.isSingleChar(int, char)
public boolean isSingleChar(int type, char ch)
Token
isSingleChar
在接口中 Token
type
- The token type.ch
- The character to check for.Token.isSingleChar(char)
public boolean isWhitespace()
Token
isWhitespace
在接口中 Token
true
iff this token is whitespace.Token.isComment()
,
Token.isCommentOrWhitespace()
public int length()
Token
length
在接口中 Token
Token.getOffset()
public java.awt.Rectangle listOffsetToView(RSyntaxTextArea textArea, javax.swing.text.TabExpander e, int pos, int x0, java.awt.Rectangle rect)
Token
null
is returned.listOffsetToView
在接口中 Token
textArea
- The text area from which the token list was derived.e
- How to expand tabs.pos
- The position in the document for which to get the bounding
box in the view.x0
- The pixel x-location that is the beginning of
tokenList
.rect
- The rectangle in which we'll be returning the results. This
object is reused to keep from frequent memory allocations.public void makeStartAt(int pos)
Note: You should not modify Token
instances you
did not create yourself (e.g., came from an
RSyntaxDocument
). If you do, rendering issues and/or
runtime exceptions will likely occur. You have been warned!
pos
- The offset into the document this token should start at.
Note that this token must already contain this position; if
it doesn't, an exception is thrown.java.lang.IllegalArgumentException
- If pos is not already contained by
this token.moveOffset(int)
public void moveOffset(int amt)
Note: You should not modify Token
instances you
did not create yourself (e.g., came from an
RSyntaxDocument
). If you do, rendering issues and/or
runtime exceptions will likely occur. You have been warned!
amt
- The amount to move the starting offset. This should be
between 0
and textCount
, inclusive.java.lang.IllegalArgumentException
- If amt
is an invalid value.makeStartAt(int)
public void set(char[] line, int beg, int end, int offset, int type)
line
- The segment from which to get the token.beg
- The first character's position in line
.end
- The last character's position in line
.offset
- The offset into the document at which this token begins.type
- A token type listed as "generic" above.public void setHyperlink(boolean hyperlink)
setHyperlink
在接口中 Token
hyperlink
- Whether this token is a hyperlink.isHyperlink()
public void setLanguageIndex(int languageIndex)
0
, this token is in the "main" language being edited.
Negative values are invalid and treated as 0
.setLanguageIndex
在接口中 Token
languageIndex
- The new language index. A value of
0
denotes the "main" language, any positive value
denotes a specific secondary language. Negative values will
be treated as 0
.getLanguageIndex()
public void setNextToken(Token nextToken)
nextToken
- The new next token.getNextToken()
public void setOffset(int offset)
offset
- The new offset into the document.getOffset()
public void setType(int type)
setType
在接口中 Token
type
- The new token type.TokenTypes
,
Token.getType()
public boolean startsWith(char[] chars)
startsWith
在接口中 Token
chars
- The characters.Token.endsWith(char[])
,
Token.is(int, char[])
public int tokenToDocument(int pos)
textOffset
-
textOffset+textCount-1
).Note that this method does NOT do any bounds checking; you can pass in an invalid token position, and you will not receive an Exception or any other indication that the returned document position is invalid. It is up to the user to ensure valid input.
tokenToDocument
在接口中 Token
pos
- A position in the token's internal char array
(textOffset
- textOffset+textCount
).Token.documentToToken(int)
public java.lang.String toString()
String
, which is useful for
debugging.toString
在类中 java.lang.Object