com.cburch.editor
Class Token<T extends TokenType>

java.lang.Object
  extended by com.cburch.editor.tokens.BasicToken
      extended by com.cburch.editor.Token<T>
Type Parameters:
T - The enumeration associated as each token's category.

public class Token<T extends TokenType>
extends BasicToken

Represents a token with an associated category.

Version:
0.1 2005-05-31
Author:
Carl Burch

Constructor Summary
Token(T type, javax.swing.text.Position endPosition, java.lang.String text)
          Constructs a token with the given information.
Token(T type, javax.swing.text.Position endPosition, java.lang.String text, java.lang.Object data)
          Constructs a token with the given information.
 
Method Summary
 boolean equals(java.lang.Object other)
          Compares this token with the parameter.
 javax.swing.text.AttributeSet getAttributeSet()
          Returns the style in which this token should be drawn.
 java.lang.Object getData()
          Retrieves the data associated with this token.
 java.lang.String getErrorMessage()
          Retrieves the error mesage associated with this token.
 T getType()
          Returns the category associated with this token.
 void setData(java.lang.Object value)
          Sets the data value associated with this token.
 void setErrorMessage(java.lang.String value)
          Sets the error message associated with this token.
 java.lang.String toString()
           
 
Methods inherited from class com.cburch.editor.tokens.BasicToken
getAbbreviatedText, getBeginOffset, getEndOffset, getEndPosition, getLength, getText, hashCode
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Token

public Token(T type,
             javax.swing.text.Position endPosition,
             java.lang.String text)
Constructs a token with the given information. The associated data value for this token will be null.

Parameters:
type - the category for this token.
endPosition - the position within the source document just past this token's last character.
text - the underlying text that this token represents.

Token

public Token(T type,
             javax.swing.text.Position endPosition,
             java.lang.String text,
             java.lang.Object data)
Constructs a token with the given information.

Parameters:
type - the category for this token.
endPosition - the position within the source document just past this token's last character.
text - the underlying text that this token represents.
data - the data value associated with this token.
Method Detail

getType

public T getType()
Returns the category associated with this token.

Returns:
this token's category.

getAttributeSet

public javax.swing.text.AttributeSet getAttributeSet()
Returns the style in which this token should be drawn. As implemented here, it is simply whatever the token's type says.

Returns:
this token's style.

getData

public java.lang.Object getData()
Retrieves the data associated with this token. The data value is mutable using the setData method, and it can be used for many purposes. For literals, it might be an object representing the literal values. For error tokens, it might be a description of the error.

Note that BracketMatcher uses the data to track brackets' corresponding tokens.

Returns:
the data associated with this token.

setData

public void setData(java.lang.Object value)
Sets the data value associated with this token.

Parameters:
value - the value to associate with this token.

getErrorMessage

public java.lang.String getErrorMessage()
Retrieves the error mesage associated with this token. The message is mutable using the setErrorMessage method.

Note that BracketMatcher sets the error message for unmatched brackets.

Returns:
the error message associated with this token.

setErrorMessage

public void setErrorMessage(java.lang.String value)
Sets the error message associated with this token.

Parameters:
value - the error message to associate with this token.

toString

public java.lang.String toString()
Overrides:
toString in class BasicToken

equals

public boolean equals(java.lang.Object other)
Description copied from class: BasicToken
Compares this token with the parameter. They are equal if all the end offset and the text are equal.

The tokenizer uses this method to determine when it can legally stop rescanning a file. If the tokens come from a scanner with additional state, then the subclass should override this method to make it more specific, reflecting that the tokens are not equal in the eyes of the scanner.

Overrides:
equals in class BasicToken