edu.rice.cs.drjava.model.definitions
Class DefinitionsDocument

java.lang.Object
  |
  +--javax.swing.text.AbstractDocument
        |
        +--javax.swing.text.PlainDocument
              |
              +--edu.rice.cs.drjava.model.definitions.DefinitionsDocument
All Implemented Interfaces:
Document, OptionConstants, Serializable

public class DefinitionsDocument
extends PlainDocument
implements OptionConstants

The model for the definitions pane. This implementation of Document contains a "reduced model". The reduced model is automatically kept in sync when this document is updated. Also, that synchronization is maintained even across undo/redo -- this is done by making the undo/redo commands know how to restore the reduced model state. The reduced model is not thread-safe, so it is essential that ONLY this DefinitionsDocument call methods on it. Any information from the reduced model should be obtained through helper methods on DefinitionsDocument, and ALL methods in DefinitionsDocument which reference the reduced model (via the _reduced field) MUST be synchronized. This prevents any thread from seeing an inconsistent state in the middle of another thread's changes.

Version:
$Id: DefinitionsDocument.java,v 1.110 2002/09/10 02:27:04 csreis Exp $
See Also:
BraceReduction, ReducedModelControl, ReducedModelComment, ReducedModelBrace, Serialized Form

Inner Class Summary
private  class DefinitionsDocument.CommandUndoableEdit
           
private  class DefinitionsDocument.InsertCommand
           
private  class DefinitionsDocument.RemoveCommand
           
 
Inner classes inherited from class javax.swing.text.AbstractDocument
AbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BidiElement, AbstractDocument.BidiRootElement, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement
 
Field Summary
private  int _cachedLineNum
          Cached current line number.
private  int _cachedLocation
          Cached location, aides in determining line number.
private  int _cachedNextLineLoc
          Cached location of next line.
private  int _cachedPrevLineLoc
          Cached location of previous line.
private  File _classFile
           
private  boolean _classFileInSync
           
private  int _currentLocation
          The absolute character offset in the document.
private  File _file
           
private  int _indent
          The default indent setting.
private  Indenter _indenter
           
private static HashSet _keywords
          A set of Java keywords.
private  boolean _modifiedSinceSave
          Determines if the document has been modified since the last save.
private static HashSet _normEndings
          A set of normal endings for lines.
private static HashSet _primTypes
          A set of Java keywords.
private  BraceReduction _reduced
          The reduced model of the document that handles most of the document logic and keeps track of state.
private static boolean _tabsRemoved
          Determines if tabs are removed on open and converted to spaces.
private  long _timestamp
           
static int DOCSTART
          Constant for starting position of document.
static int ERROR_INDEX
          Constant used by helper methods to indicate an error
 
Fields inherited from class javax.swing.text.PlainDocument
added, defaultRoot, lineLimitAttribute, removed, tabSizeAttribute
 
Fields inherited from class javax.swing.text.AbstractDocument
AsyncLoadPriority, BAD_LOCATION, BAD_LOCK_STATE, BidiElementName, bidiRoot, ContentElementName, context, currWriter, data, defaultI18NProperty, documentProperties, ElementNameAttribute, I18NProperty, listenerList, numReaders, ParagraphElementName, SectionElementName
 
Fields inherited from interface edu.rice.cs.drjava.config.OptionConstants
COMPILER_ERROR_COLOR, DEBUG_BREAKPOINT_COLOR, DEBUG_SHOW_THREADS, DEBUG_SOURCEPATH, DEBUG_STEP_DRJAVA, DEBUG_STEP_INTERPRETER, DEBUG_STEP_JAVA, DEBUG_THREAD_COLOR, DEFINITIONS_BACKGROUND_COLOR, DEFINITIONS_COMMENT_COLOR, DEFINITIONS_DOUBLE_QUOTED_COLOR, DEFINITIONS_KEYWORD_COLOR, DEFINITIONS_MATCH_COLOR, DEFINITIONS_NORMAL_COLOR, DEFINITIONS_NUMBER_COLOR, DEFINITIONS_SINGLE_QUOTED_COLOR, DEFINITIONS_TYPE_COLOR, EXTRA_CLASSPATH, FONT_DOCLIST, FONT_MAIN, FONT_TOOLBAR, HISTORY_MAX_SIZE, INDENT_LEVEL, INTERACTIONS_EXIT_PROMPT, JAVAC_ALLOW_ASSERT, JAVAC_LOCATION, JSR14_COLLECTIONSPATH, JSR14_LOCATION, KEY_BACKWARD, KEY_BEGIN_DOCUMENT, KEY_BEGIN_LINE, KEY_CLOSE_FILE, KEY_COMPILE, KEY_COMPILE_ALL, KEY_COPY, KEY_CUT, KEY_CUT_LINE, KEY_DEBUG_BREAKPOINT_TOGGLE, KEY_DEBUG_MODE_TOGGLE, KEY_DEBUG_RESUME, KEY_DEBUG_STEP_INTO, KEY_DEBUG_STEP_OUT, KEY_DEBUG_STEP_OVER, KEY_DELETE_NEXT, KEY_DELETE_PREVIOUS, KEY_DOWN, KEY_END_DOCUMENT, KEY_END_LINE, KEY_FIND_NEXT, KEY_FIND_REPLACE, KEY_FORWARD, KEY_GOTO_LINE, KEY_NEW_FILE, KEY_NEXT_DOCUMENT, KEY_NEXT_WORD, KEY_OPEN_FILE, KEY_PAGE_DOWN, KEY_PAGE_UP, KEY_PASTE, KEY_PREVIOUS_DOCUMENT, KEY_PREVIOUS_WORD, KEY_PRINT, KEY_PRINT_PREVIEW, KEY_QUIT, KEY_REDO, KEY_SAVE_FILE, KEY_SAVE_FILE_AS, KEY_SELECT_ALL, KEY_UNDO, KEY_UP, LINEENUM_ENABLED, mask, QUIT_PROMPT, RECENT_FILES, RECENT_FILES_MAX_SIZE, TOOLBAR_ICONS_ENABLED, TOOLBAR_TEXT_ENABLED, WORKING_DIRECTORY
 
Fields inherited from interface javax.swing.text.Document
StreamDescriptionProperty, TitleProperty
 
Constructor Summary
DefinitionsDocument()
          Constructor.
DefinitionsDocument(Indenter i)
           
 
Method Summary
private  void _addCharToReducedModel(char curChar)
          Add a character to the underlying reduced model.
private  int _findKeywordAtToplevel(String keyword, String text, int textOffset)
          Finds the first occurrence of the keyword within the text that is not enclosed within a brace or comment
protected  String _getPackageQualifier()
          Gets an appropriate prefix to fully qualify a class name.
private  int _getRelativeLine()
          This method returns the relative offset of line number from the previous location in the document.
private  boolean _hasOnlySpaces(String text)
          Returns whether the given text only has spaces.
private  int _highlightKeywords(gj.util.Vector v, int i)
          Separates out keywords from normal text for the given HighlightStatus element.
private  void _indentBlock(int start, int end)
          Indents the lines between and including the lines containing points start and end.
private  void _indentLine()
          Indents a line using the Indenter decision tree.
private  boolean _isCommentedOrSpace(int i, String text)
          Determines if the current token is part of a comment or if the i'th character in the given text argument is a space.
protected  boolean _isEndOfComment(String text, int pos)
          Helper method for findPrevNonWSCharPos Determines whether the current character is the end of a comment: "*\/" or a hanging "//"
private  boolean _isNum(String x)
          Checks to see if the current string is a number
protected  boolean _isStartOfComment(String text, int pos)
          Helper method for getFirstNonWSCharPos Determines whether the current character is the start of a comment: "/*" or "//"
private  boolean _isType(String x)
          Checks to see if the current string is a type A type is assumed to be a primitive type OR anything else that begins with a capitalized character
private static HashSet _makeKeywords()
          Create a set of Java/GJ keywords for special coloring.
private static HashSet _makeNormEndings()
          Create a set of normal endings, i.e., semi-colons and braces for the purposes of indenting.
private static HashSet _makePrimTypes()
          Create a set of Java/GJ primitive types for special coloring.
(package private)  String _removeTabs(String source)
          Given a String, return a new String will all tabs converted to spaces.
private  void _styleChanged()
          Fire event that styles changed from current location to the end.
 int balanceBackward()
          Forwarding method to find the match for the closing brace immediately to the left, assuming there is such a brace.
 int balanceForward()
          Forwarding method to find the match for the open brace immediately to the right, assuming there is such a brace.
 int findCharOnLine(int pos, char findChar)
          Determines if the given character exists on the line where the given cursor position is.
 int findPrevCharPos(int pos, char[] whitespace)
          Finds the position of the first non-whitespace character before pos.
 int findPrevDelimiter(int pos, char[] delims)
          Searching backwards, finds the position of the first character that is one of the given delimiters.
 int findPrevDelimiter(int pos, char[] delims, boolean skipParenPhrases)
          Searching backwards, finds the position of the first character that is one of the given delimiters.
 int findPrevNonWSCharPos(int pos)
           
 File getCachedClassFile()
           
 boolean getClassFileInSync()
           
 int getCurrentCol()
          Return the current column of the cursor position.
 int getCurrentLine()
          Return the current line of the cursor position.
 int getCurrentLocation()
          Get the current location of the cursor in the document.
 String getEnclosingTopLevelClassName(int pos)
          Returns the name of the class or interface enclosing the caret position at the top level.
 File getFile()
          Returns the file for this document.
 String getFilename()
          Returns the name of this file, or "(untitled)" if no file.
 int getFirstNonWSCharPos(int pos)
          Finds the position of the first non-whitespace character after pos.
 int getFirstNonWSCharPos(int pos, char[] whitespace)
          Finds the position of the first non-whitespace character after pos.
 String getFirstTopLevelClassName()
          Gets the name of the top level class in this source file.
 gj.util.Vector getHighlightStatus(int start, int end)
          Return all highlight status info for text between start and end.
 int getIndent()
          Get the indent level.
 IndentInfo getIndentInformation()
           
 String getIndentOfCurrStmt(int pos)
          Returns the indent level of the start of the statement that the cursor is on.
 String getIndentOfCurrStmt(int pos, char[] delims)
          Returns the indent level of the start of the statement that the cursor is on.
 int getLineEndPos(int pos)
          Returns the absolute position of the end of the current line.
 int getLineFirstCharPos(int pos)
          Returns the absolute position of the first non-whitespace character on the current line.
 int getLineStartPos(int pos)
          Returns the absolute position of the beginning of the current line.
 String getNextTopLevelClassName(int startPos, int endPos)
           
 int getOffset(int lineNum)
          Returns the offset corresponding to the first character of the given line number, or -1 if the lineNum is not found.
 String getPackageName()
          Gets the name of the package this source file claims it's in (with the package keyword).
 String getQualifiedClassName()
          Gets the package and class name of this OpenDefinitionsDocument
 String getQualifiedClassName(int pos)
          Gets fully qualified class name of the top level class enclosing the given position.
(package private)  BraceReduction getReduced()
          This method should never be called outside of this class.
 ReducedModelState getStateAtCurrent()
           
 long getTimestamp()
           
 int getWhiteSpace()
          Gets the number of whitespace characters between the current location and the rest of the document or the first non-whitespace character, whichever comes first.
private  int getWhiteSpaceBetween(int relStart, int relEnd)
          Starts at start and gets whitespace starting at relStart and either stopping at relEnd or at the first non-white space char.
 void gotoLine(int line)
          Goes to a particular line in the document.
 void indentLines(int selStart, int selEnd)
           
 void insertString(int offset, String str, AttributeSet a)
          Inserts a string of text into the document.
protected  void insertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)
          Updates document structure as a result of text insertion.
 boolean isModifiedOnDisk()
          Determines if the document has been modified since the last save.
 boolean isModifiedSinceSave()
          Determines if the document has been modified since the last save.
 boolean isUntitled()
          Returns whether this document is currently untitled (indicating whether it has a file yet or not).
 void move(int dist)
          The actual cursor movement logic.
 boolean posInParenPhrase(int pos)
          Returns true if the given position is inside a paren phrase.
protected  boolean posNotInBlock(int pos)
          Returns true if the given position is not inside a paren/brace/etc phrase.
 void remove(int offset, int len)
          Removes a block of text from the specified location.
protected  void removeUpdate(AbstractDocument.DefaultDocumentEvent chng)
          Updates document structure as a result of text removal.
 void resetModification()
          Whenever this document has been saved, this method should be called so that it knows it's no longer in a modified state.
 void resetReducedModelLocation()
           
 void setCachedClassFile(File classFile)
           
 void setClassFileInSync(boolean inSync)
           
 void setCurrentLocation(int loc)
          Change the current location of the document
 void setFile(File file)
           
 void setIndent(int indent)
          Set the indent to a particular number of spaces.
 void setModifiedSinceSave()
          Originally designed to allow undoManager to set the current document to be modified whenever an undo or redo is performed.
 void setTab(String tab, int pos)
          Sets the text between the previous newline and the first non-whitespace character of the line containing pos to tab.
 ReducedModelState stateAtRelLocation(int dist)
           
(package private)  void tab(int tab, int distToPrevNewline)
          The function that handles what happens when a tab key is pressed.
 boolean tabsRemoved()
          Returns true iff tabs are to removed on text insertion.
 
Methods inherited from class javax.swing.text.PlainDocument
createDefaultRoot, getDefaultRootElement, getParagraphElement, insertComposedTextUpdate
 
Methods inherited from class javax.swing.text.AbstractDocument
addDocumentListener, addUndoableEditListener, calculateBidiLevels, createBranchElement, createLeafElement, createPosition, dump, fireChangedUpdate, fireInsertUpdate, fireRemoveUpdate, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, isComplex, isLeftToRight, postRemoveUpdate, putProperty, readLock, readObject, readUnlock, removeDocumentListener, removeUndoableEditListener, render, setAsynchronousLoadPriority, setDocumentProperties, updateBidi, writeLock, writeUnlock
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

_normEndings

private static HashSet _normEndings
A set of normal endings for lines.

_keywords

private static HashSet _keywords
A set of Java keywords.

_primTypes

private static HashSet _primTypes
A set of Java keywords.

_indent

private int _indent
The default indent setting.

_tabsRemoved

private static boolean _tabsRemoved
Determines if tabs are removed on open and converted to spaces.

_modifiedSinceSave

private boolean _modifiedSinceSave
Determines if the document has been modified since the last save.

_cachedLocation

private int _cachedLocation
Cached location, aides in determining line number.

_cachedLineNum

private int _cachedLineNum
Cached current line number.

_cachedPrevLineLoc

private int _cachedPrevLineLoc
Cached location of previous line.

_cachedNextLineLoc

private int _cachedNextLineLoc
Cached location of next line.

_classFileInSync

private boolean _classFileInSync

_classFile

private File _classFile

_reduced

private BraceReduction _reduced
The reduced model of the document that handles most of the document logic and keeps track of state. Should ONLY be referenced from this class, and all references to it MUST be synchronized.

_currentLocation

private int _currentLocation
The absolute character offset in the document.

_file

private File _file

_timestamp

private long _timestamp

_indenter

private final Indenter _indenter

DOCSTART

public static final int DOCSTART
Constant for starting position of document.

ERROR_INDEX

public static final int ERROR_INDEX
Constant used by helper methods to indicate an error
Constructor Detail

DefinitionsDocument

public DefinitionsDocument()
Constructor.

DefinitionsDocument

public DefinitionsDocument(Indenter i)
Method Detail

getReduced

BraceReduction getReduced()
This method should never be called outside of this class. Doing so can create all sorts of synchronization issues. It is package private for test purposes.
Returns:
The reduced model of this document.

_makeNormEndings

private static HashSet _makeNormEndings()
Create a set of normal endings, i.e., semi-colons and braces for the purposes of indenting.
Returns:
the set of normal endings

_makeKeywords

private static HashSet _makeKeywords()
Create a set of Java/GJ keywords for special coloring.
Returns:
the set of keywords

_makePrimTypes

private static HashSet _makePrimTypes()
Create a set of Java/GJ primitive types for special coloring.
Returns:
the set of primitive types

isUntitled

public boolean isUntitled()
Returns whether this document is currently untitled (indicating whether it has a file yet or not).
Returns:
true if the document is untitled and has no file

getFile

public File getFile()
             throws IllegalStateException,
                    FileMovedException
Returns the file for this document. If the document is untitled and has no file, it throws an IllegalStateException.
Returns:
the file for this document
Throws:
IllegalStateException - if file has not been set
FileMovedException - if file has been moved or deleted from its previous location

getFilename

public String getFilename()
Returns the name of this file, or "(untitled)" if no file.

setFile

public void setFile(File file)

getTimestamp

public long getTimestamp()

getQualifiedClassName

public String getQualifiedClassName()
                             throws ClassNameNotFoundException
Gets the package and class name of this OpenDefinitionsDocument
Returns:
the qualified class name

getQualifiedClassName

public String getQualifiedClassName(int pos)
                             throws ClassNameNotFoundException
Gets fully qualified class name of the top level class enclosing the given position.

_getPackageQualifier

protected String _getPackageQualifier()
Gets an appropriate prefix to fully qualify a class name. Returns this class's package followed by a dot, or the empty string if no package name is found.

setClassFileInSync

public void setClassFileInSync(boolean inSync)

getClassFileInSync

public boolean getClassFileInSync()

setCachedClassFile

public void setCachedClassFile(File classFile)

getCachedClassFile

public File getCachedClassFile()

insertString

public void insertString(int offset,
                         String str,
                         AttributeSet a)
                  throws BadLocationException
Inserts a string of text into the document. It turns out that this is not where we should do custom processing of the insert; that is done in insertUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent, javax.swing.text.AttributeSet).
Overrides:
insertString in class AbstractDocument

insertUpdate

protected void insertUpdate(AbstractDocument.DefaultDocumentEvent chng,
                            AttributeSet attr)
Updates document structure as a result of text insertion. This happens after the text has actually been inserted. Here we update the reduced model (via an DefinitionsDocument.InsertCommand) and store information for how to undo/redo the reduced model changes inside the DefaultDocumentEvent.
Overrides:
insertUpdate in class PlainDocument
See Also:
DefinitionsDocument.InsertCommand, DefaultDocumentEvent, DefinitionsDocument.CommandUndoableEdit

remove

public void remove(int offset,
                   int len)
            throws BadLocationException
Removes a block of text from the specified location. We don't update the reduced model here; that happens in removeUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent).
Overrides:
remove in class AbstractDocument

removeUpdate

protected void removeUpdate(AbstractDocument.DefaultDocumentEvent chng)
Updates document structure as a result of text removal. This happens before the text has actually been removed. Here we update the reduced model (via an DefinitionsDocument.RemoveCommand) and store information for how to undo/redo the reduced model changes inside the DefaultDocumentEvent.
Overrides:
removeUpdate in class PlainDocument
See Also:
DefinitionsDocument.RemoveCommand, DefaultDocumentEvent, DefinitionsDocument.CommandUndoableEdit

_removeTabs

String _removeTabs(String source)
Given a String, return a new String will all tabs converted to spaces. Each tab is converted to one space, since changing the number of characters within insertString screws things up.
Parameters:
source - the String to be converted.
Returns:
a String will all the tabs converted to spaces

_addCharToReducedModel

private void _addCharToReducedModel(char curChar)
Add a character to the underlying reduced model.
Parameters:
curChar - the character to be added.

_styleChanged

private void _styleChanged()
Fire event that styles changed from current location to the end. Right now we do this every time there is an insertion or removal. Two possible future optimizations:
  1. Only fire changed event if text other than that which was inserted or removed *actually* changed status. If we didn't changed the status of other text (by inserting or deleting unmatched pair of quote or comment chars), no change need be fired.
  2. If a change must be fired, we could figure out the exact end of what has been changed. Right now we fire the event saying that everything changed to the end of the document.
I don't think we'll need to do either one since it's still fast now. I think this is because the UI only actually paints the things on the screen anyway.

setModifiedSinceSave

public void setModifiedSinceSave()
Originally designed to allow undoManager to set the current document to be modified whenever an undo or redo is performed.

resetModification

public void resetModification()
Whenever this document has been saved, this method should be called so that it knows it's no longer in a modified state.

isModifiedSinceSave

public boolean isModifiedSinceSave()
Determines if the document has been modified since the last save.
Returns:
true if the document has been modified

isModifiedOnDisk

public boolean isModifiedOnDisk()
Determines if the document has been modified since the last save.
Returns:
true if the document has been modified

getCurrentLocation

public int getCurrentLocation()
Get the current location of the cursor in the document. Unlike the usual swing document model, which is stateless, because of our implementation of the underlying reduced model, we need to keep track fo the current location.
Returns:
where the cursor is as the number of characters into the document

setCurrentLocation

public void setCurrentLocation(int loc)
Change the current location of the document
Parameters:
loc - the new absolute location

move

public void move(int dist)
The actual cursor movement logic. Helper for setCurrentLocation(int).
Parameters:
dist - the distance from the current location to the new location.

getCurrentCol

public int getCurrentCol()
Return the current column of the cursor position. Uses a 0 based index.

getCurrentLine

public int getCurrentLine()
Return the current line of the cursor position. Uses a 1 based index.

_getRelativeLine

private int _getRelativeLine()
This method returns the relative offset of line number from the previous location in the document.

getIndent

public int getIndent()
Get the indent level.
Returns:
the indent level

setIndent

public void setIndent(int indent)
Set the indent to a particular number of spaces.
Parameters:
indent - the size of indent that you want for the document

findPrevDelimiter

public int findPrevDelimiter(int pos,
                             char[] delims)
                      throws BadLocationException
Searching backwards, finds the position of the first character that is one of the given delimiters. Does not look for delimiters inside paren phrases. (eg. skips semicolons used inside for statements.) NB: ignores comments.
Parameters:
pos - Position to start from
delims - array of characters to search for
Returns:
position of first matching delimiter, or ERROR_INDEX if beginning of document is reached.

findPrevDelimiter

public int findPrevDelimiter(int pos,
                             char[] delims,
                             boolean skipParenPhrases)
                      throws BadLocationException
Searching backwards, finds the position of the first character that is one of the given delimiters. Will not look for delimiters inside a paren phrase if skipParenPhrases is true. NB: ignores comments.
Parameters:
pos - Position to start from
delims - array of characters to search for
skipParenPhrases - whether to look for delimiters inside paren phrases (eg. semicolons in a for statement)
Returns:
position of first matching delimiter, or ERROR_INDEX if beginning of document is reached.

posInParenPhrase

public boolean posInParenPhrase(int pos)
Returns true if the given position is inside a paren phrase.
Parameters:
pos - the position we're looking at
Returns:
true if pos is immediately inside parentheses

posNotInBlock

protected boolean posNotInBlock(int pos)
Returns true if the given position is not inside a paren/brace/etc phrase.
Parameters:
pos - the position we're looking at
Returns:
true if pos is immediately inside a paren/brace/etc

getIndentOfCurrStmt

public String getIndentOfCurrStmt(int pos)
                           throws BadLocationException
Returns the indent level of the start of the statement that the cursor is on. Uses a default set of delimiters. (';', '{', '}')
Parameters:
pos - Cursor position

getIndentOfCurrStmt

public String getIndentOfCurrStmt(int pos,
                                  char[] delims)
                           throws BadLocationException
Returns the indent level of the start of the statement that the cursor is on.
Parameters:
pos - Cursor position
delims - Delimiter characters denoting end of statement

findCharOnLine

public int findCharOnLine(int pos,
                          char findChar)
Determines if the given character exists on the line where the given cursor position is. Does not search in quotes or comments.

Does not work if character being searched for is a '/' or a '*'

Parameters:
pos - Cursor position
findChar - Character to search for
Returns:
true if this node's rule holds.

getLineStartPos

public int getLineStartPos(int pos)
Returns the absolute position of the beginning of the current line. (Just after most recent newline, or DOCSTART) Doesn't ignore comments.
Parameters:
pos - Any position on the current line
Returns:
position of the beginning of this line

getLineEndPos

public int getLineEndPos(int pos)
Returns the absolute position of the end of the current line. (At the next newline, or the end of the document.)
Parameters:
pos - Any position on the current line
Returns:
position of the end of this line

getLineFirstCharPos

public int getLineFirstCharPos(int pos)
                        throws BadLocationException
Returns the absolute position of the first non-whitespace character on the current line. NB: Doesn't ignore comments.
Parameters:
pos - position on the line
Returns:
position of first non-whitespace character on this line, or the end of the line if no non-whitespace character is found.

getFirstNonWSCharPos

public int getFirstNonWSCharPos(int pos)
                         throws BadLocationException
Finds the position of the first non-whitespace character after pos. NB: Skips comments and all whitespace, including newlines
Parameters:
pos - Position to start from
Returns:
position of first non-whitespace character after pos, or ERROR_INDEX if end of document is reached

getFirstNonWSCharPos

public int getFirstNonWSCharPos(int pos,
                                char[] whitespace)
                         throws BadLocationException
Finds the position of the first non-whitespace character after pos. NB: Skips comments and all whitespace, including newlines
Parameters:
pos - Position to start from
whitespace - array of whitespace chars to ignore
Returns:
position of first non-whitespace character after pos, or ERROR_INDEX if end of document is reached

findPrevNonWSCharPos

public int findPrevNonWSCharPos(int pos)
                         throws BadLocationException

getOffset

public int getOffset(int lineNum)
Returns the offset corresponding to the first character of the given line number, or -1 if the lineNum is not found.
Parameters:
lineNum - the line number for which to calculate the offset.
Returns:
the offset of the first character in the given line number

findPrevCharPos

public int findPrevCharPos(int pos,
                           char[] whitespace)
                    throws BadLocationException
Finds the position of the first non-whitespace character before pos. NB: Skips comments and all whitespace, including newlines
Parameters:
pos - Position to start from
whitespace - chars considered as white space
Returns:
position of first non-whitespace character before pos, or ERROR_INDEX if begining of document is reached

_isStartOfComment

protected boolean _isStartOfComment(String text,
                                    int pos)
Helper method for getFirstNonWSCharPos Determines whether the current character is the start of a comment: "/*" or "//"

_isEndOfComment

protected boolean _isEndOfComment(String text,
                                  int pos)
Helper method for findPrevNonWSCharPos Determines whether the current character is the end of a comment: "*\/" or a hanging "//"
Returns:
true if (pos-1,pos) == '*\/' or '//'

tabsRemoved

public boolean tabsRemoved()
Returns true iff tabs are to removed on text insertion.

balanceBackward

public int balanceBackward()
Forwarding method to find the match for the closing brace immediately to the left, assuming there is such a brace.
Returns:
the relative distance backwards to the offset before the matching brace.

balanceForward

public int balanceForward()
Forwarding method to find the match for the open brace immediately to the right, assuming there is such a brace.
Returns:
the relative distance forwards to the offset after the matching brace.

indentLines

public void indentLines(int selStart,
                        int selEnd)

_indentBlock

private void _indentBlock(int start,
                          int end)
Indents the lines between and including the lines containing points start and end.
Parameters:
start - Position in document to start indenting from
end - Position in document to end indenting at

_indentLine

private void _indentLine()
Indents a line using the Indenter decision tree.

_isCommentedOrSpace

private boolean _isCommentedOrSpace(int i,
                                    String text)
Determines if the current token is part of a comment or if the i'th character in the given text argument is a space.
Parameters:
i - the index to look at for the space in text
text - a block of text
Returns:
true if the conditions are met

getWhiteSpace

public int getWhiteSpace()
Gets the number of whitespace characters between the current location and the rest of the document or the first non-whitespace character, whichever comes first.
Returns:
the number of whitespace characters

getWhiteSpaceBetween

private int getWhiteSpaceBetween(int relStart,
                                 int relEnd)
                          throws BadLocationException
Starts at start and gets whitespace starting at relStart and either stopping at relEnd or at the first non-white space char. NOTE: relStart and relEnd are relative to where we are in the document relStart must be <= _currentLocation
Throws:
BadLocationException -  

tab

void tab(int tab,
         int distToPrevNewline)
   throws BadLocationException
The function that handles what happens when a tab key is pressed. It is given the size of the leading whitespace and based on the current indent information, either shrinks or expands that whitespace.
Parameters:
tab - number of indents, i.e., level of nesting
distToPrevNewline - distance to end of previous line
Throws:
BadLocationException -  

setTab

public void setTab(String tab,
                   int pos)
Sets the text between the previous newline and the first non-whitespace character of the line containing pos to tab.
Parameters:
tab - String to be placed between previous newline and first non-whitespace character

_hasOnlySpaces

private boolean _hasOnlySpaces(String text)
Returns whether the given text only has spaces.

getHighlightStatus

public gj.util.Vector getHighlightStatus(int start,
                                         int end)
Return all highlight status info for text between start and end. This should collapse adjoining blocks with the same status into one.

_highlightKeywords

private int _highlightKeywords(gj.util.Vector v,
                               int i)
Separates out keywords from normal text for the given HighlightStatus element. What this does is it looks to see if the given part of the text contains a keyword. If it does, it splits the HighlightStatus into separate blocks so that each keyword is in its own block. This will find all keywords in a given block. Note that the given block must have state NORMAL.
Parameters:
v - Vector with highlight info
i - Index of the single HighlightStatus to check for keywords in
Returns:
the index into the vector of the last processed element

_isNum

private boolean _isNum(String x)
Checks to see if the current string is a number
Returns:
true if x is a parseable number

_isType

private boolean _isType(String x)
Checks to see if the current string is a type A type is assumed to be a primitive type OR anything else that begins with a capitalized character

gotoLine

public void gotoLine(int line)
Goes to a particular line in the document.

getPackageName

public String getPackageName()
                      throws InvalidPackageException
Gets the name of the package this source file claims it's in (with the package keyword). It does this by minimally parsing the source file to find the package statement.
Returns:
The name of package this source file declares itself to be in, or the empty string if there is no package statement (and thus the source file is in the empty package).
Throws:
InvalidPackageException - if there is some sort of a package statement but it is invalid.

getIndentInformation

public IndentInfo getIndentInformation()

stateAtRelLocation

public ReducedModelState stateAtRelLocation(int dist)

getStateAtCurrent

public ReducedModelState getStateAtCurrent()

resetReducedModelLocation

public void resetReducedModelLocation()

getEnclosingTopLevelClassName

public String getEnclosingTopLevelClassName(int pos)
                                     throws ClassNameNotFoundException
Returns the name of the class or interface enclosing the caret position at the top level.
Returns:
Name of enclosing class or interface
Throws:
ClassNameNotFoundException - if no enclosing class found

getFirstTopLevelClassName

public String getFirstTopLevelClassName()
                                 throws ClassNameNotFoundException
Gets the name of the top level class in this source file. This attempts to find the first declaration of a class or interface.
Returns:
The name of first class in the file
Throws:
ClassNameNotFoundException - if no top level class found

getNextTopLevelClassName

public String getNextTopLevelClassName(int startPos,
                                       int endPos)
                                throws ClassNameNotFoundException

_findKeywordAtToplevel

private int _findKeywordAtToplevel(String keyword,
                                   String text,
                                   int textOffset)
Finds the first occurrence of the keyword within the text that is not enclosed within a brace or comment
Parameters:
keyword - the keyword for which to search
text - in which to search
textOffset - Offset at which the text occurs in the document