com.cburch.editor.tokens
Class BasicToken

java.lang.Object
  extended by com.cburch.editor.tokens.BasicToken
Direct Known Subclasses:
Token

public class BasicToken
extends java.lang.Object

Represents a token in the stream, holding minimal information necessary for the tokenizer to work.

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

Constructor Summary
BasicToken(javax.swing.text.Position end, java.lang.String text)
          Constructs a token with the given information.
 
Method Summary
 boolean equals(java.lang.Object other)
          Compares this token with the parameter.
 java.lang.String getAbbreviatedText(int maxLength)
          Returns a formatted string, abbreviated to the given length, with any line breaks replaced with "\n." As an example of the abbreviation, the text veryLargeIdentifierName would be abbreviated to veryLa..me if maxLength were 10.
 int getBeginOffset()
          Returns the offset where this token's first character is currently located within its document.
 int getEndOffset()
          Returns the current offset of the first character following this token within its document.
 javax.swing.text.Position getEndPosition()
          Returns the position within the document just past this token.
 int getLength()
          Returns the number of characters in this token.
 java.lang.String getText()
          Returns the underlying text that this token represents.
 int hashCode()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BasicToken

public BasicToken(javax.swing.text.Position end,
                  java.lang.String text)
Constructs a token with the given information.

Parameters:
end - the position within the source document just past this token's last character.
text - the underlying text that this token represents.
Method Detail

getEndPosition

public final javax.swing.text.Position getEndPosition()
Returns the position within the document just past this token.

Returns:
the position just past this token's last character.

getBeginOffset

public final int getBeginOffset()
Returns the offset where this token's first character is currently located within its document.

Returns:
the offset of the first character.

getEndOffset

public final int getEndOffset()
Returns the current offset of the first character following this token within its document.

Returns:
the offset of the first character after this token.

getLength

public final int getLength()
Returns the number of characters in this token.

Returns:
the token's length.

getText

public java.lang.String getText()
Returns the underlying text that this token represents.

Returns:
the text leading to this token.

getAbbreviatedText

public java.lang.String getAbbreviatedText(int maxLength)
Returns a formatted string, abbreviated to the given length, with any line breaks replaced with "\n." As an example of the abbreviation, the text veryLargeIdentifierName would be abbreviated to veryLa..me if maxLength were 10.

Parameters:
maxLength - the maximum length of the returned string.
Returns:
a string representing the underlying text with no line breaks, and with the middle portion removed if the text exceeds the maximum length.

toString

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

equals

public boolean equals(java.lang.Object other)
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 java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object