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

java.lang.Object
  extended by javax.swing.text.AbstractDocument
      extended by javax.swing.text.DefaultStyledDocument
          extended by edu.rice.cs.util.text.SwingDocument
              extended by edu.rice.cs.drjava.model.AbstractDJDocument
                  extended by edu.rice.cs.drjava.model.definitions.DefinitionsDocument
All Implemented Interfaces:
OptionConstants, DJDocument, Finalizable<DefinitionsDocument>, AbstractDocumentInterface, EditDocumentInterface, SwingDocumentInterface, Serializable, Document, StyledDocument

public class DefinitionsDocument
extends AbstractDJDocument
implements Finalizable<DefinitionsDocument>

The document model for the definitions pane; it contains a reduced model since it extends AbstractDJDocument.

See Also:
AbstractDJDocument, Serialized Form

Nested Class Summary
static class DefinitionsDocument.WrappedPosition
          Wrapper for Position objects to allow relinking to a new Document.
 
Nested classes/interfaces inherited from class edu.rice.cs.drjava.model.AbstractDJDocument
AbstractDJDocument.CharInsertCommand, AbstractDJDocument.InsertCommand, AbstractDJDocument.RemoveCommand, AbstractDJDocument.UninsertCommand, AbstractDJDocument.UnremoveCommand
 
Nested classes/interfaces inherited from class javax.swing.text.DefaultStyledDocument
DefaultStyledDocument.AttributeUndoableEdit, DefaultStyledDocument.ElementBuffer, DefaultStyledDocument.ElementSpec, DefaultStyledDocument.SectionElement
 
Nested classes/interfaces inherited from class javax.swing.text.AbstractDocument
AbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement
 
Nested classes/interfaces inherited from interface edu.rice.cs.drjava.config.OptionConstants
OptionConstants.AccessLevelChoices, OptionConstants.DefaultFont, OptionConstants.HeapSizeChoices, OptionConstants.LookAndFeels, OptionConstants.PlasticThemes, OptionConstants.VersionNotificationChoices
 
Field Summary
static Log _log
           
 
Fields inherited from class edu.rice.cs.drjava.model.AbstractDJDocument
_currentLocation, _indent, _keywords, _normEndings, _primTypes, _reduced, CLOSING_BRACES, delimiters, newline, POS_THRESHOLD
 
Fields inherited from class edu.rice.cs.util.text.SwingDocument
_condition, _styles, _wrappedPosListLock
 
Fields inherited from class javax.swing.text.DefaultStyledDocument
buffer, BUFFER_SIZE_DEFAULT
 
Fields inherited from class javax.swing.text.AbstractDocument
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementName
 
Fields inherited from interface javax.swing.text.Document
StreamDescriptionProperty, TitleProperty
 
Fields inherited from interface edu.rice.cs.drjava.config.OptionConstants
accessLevelChoices, ALLOW_PRIVATE_ACCESS, ALWAYS_COMPILE_BEFORE_JUNIT, ALWAYS_SAVE_BEFORE_COMPILE, ALWAYS_SAVE_BEFORE_DEBUG, ALWAYS_SAVE_BEFORE_JAVADOC, ALWAYS_SAVE_BEFORE_RUN, apiJavadocChoices, apiJavadocVersionChoices, AUTO_CLOSE_COMMENTS, BACKUP_FILES, BOOKMARK_COLOR, BROWSER_FILE, BROWSER_HISTORY_MAX_SIZE, BROWSER_STRING, choices, CLIPBOARD_HISTORY_SIZE, COMPILER_ERROR_COLOR, DEBUG_BREAKPOINT_COLOR, DEBUG_BREAKPOINT_DISABLED_COLOR, DEBUG_MESSAGE_COLOR, DEBUG_PANEL_HEIGHT, DEBUG_SOURCEPATH, DEBUG_STEP_DRJAVA, DEBUG_STEP_EXCLUDE, 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, DETACH_DEBUGGER, DETACH_TABBEDPANES, DIALOG_AUTOIMPORT_ENABLED, DIALOG_AUTOIMPORT_STATE, DIALOG_AUTOIMPORT_STORE_POSITION, DIALOG_CLIPBOARD_HISTORY_STATE, DIALOG_CLIPBOARD_HISTORY_STORE_POSITION, DIALOG_COMPLETE_JAVAAPI, DIALOG_COMPLETE_SCAN_CLASS_FILES, DIALOG_COMPLETE_WORD_STATE, DIALOG_COMPLETE_WORD_STORE_POSITION, DIALOG_DEBUGFRAME_STATE, DIALOG_DEBUGFRAME_STORE_POSITION, DIALOG_DRJAVA_ERROR_POPUP_ENABLED, DIALOG_DRJAVA_SURVEY_ENABLED, DIALOG_EDITEXTERNALPROCESS_STATE, DIALOG_EDITEXTERNALPROCESS_STORE_POSITION, DIALOG_EXTERNALPROCESS_STATE, DIALOG_EXTERNALPROCESS_STORE_POSITION, DIALOG_GOTOFILE_FULLY_QUALIFIED, DIALOG_GOTOFILE_STATE, DIALOG_GOTOFILE_STORE_POSITION, DIALOG_JAROPTIONS_STATE, DIALOG_JAROPTIONS_STORE_POSITION, DIALOG_LIGHTWEIGHT_PARSING_DELAY, DIALOG_OPENJAVADOC_STATE, DIALOG_OPENJAVADOC_STORE_POSITION, DIALOG_TABBEDPANES_STATE, DIALOG_TABBEDPANES_STORE_POSITION, DOC_LIST_WIDTH, DRJAVA_ERRORS_BUTTON_COLOR, DRJAVA_SURVEY_DAYS, DRJAVA_USE_FORCE_QUIT, EXTERNAL_SAVED_CMDLINES, EXTERNAL_SAVED_COUNT, EXTERNAL_SAVED_ENCLOSING_DJAPP_FILES, EXTERNAL_SAVED_NAMES, EXTERNAL_SAVED_PREFIX, EXTERNAL_SAVED_WORKDIRS, EXTPROCESS_FILE_EXTENSION, EXTPROCESS_FILE_NAME_INSIDE_JAR, EXTRA_CLASSPATH, EXTRA_COMPILERS, FIND_ALL_DOCUMENTS, FIND_MATCH_CASE, FIND_NO_COMMENTS_STRINGS, FIND_NO_TEST_CASES, FIND_REPLACE_FOCUS_IN_DEFPANE, FIND_RESULTS_COLOR1, FIND_RESULTS_COLOR2, FIND_RESULTS_COLOR3, FIND_RESULTS_COLOR4, FIND_RESULTS_COLOR5, FIND_RESULTS_COLOR6, FIND_RESULTS_COLOR7, FIND_RESULTS_COLOR8, FIND_RESULTS_COLORS, FIND_SEARCH_BACKWARDS, FIND_WHOLE_WORD, FOLLOW_FILE_DELAY, FOLLOW_FILE_LINES, FONT_DOCLIST, FONT_LINE_NUMBERS, FONT_MAIN, FONT_TOOLBAR, FORCE_TEST_SUFFIX, heapSizeChoices, HISTORY_MAX_SIZE, INDENT_LEVEL, INTERACTIONS_ERROR_COLOR, INTERACTIONS_EXIT_PROMPT, INTERACTIONS_RESET_PROMPT, JAVAC_LOCATION, JAVADOC_1_3_LINK, JAVADOC_1_3_TEXT, JAVADOC_1_4_LINK, JAVADOC_1_4_TEXT, JAVADOC_1_5_LINK, JAVADOC_1_5_TEXT, JAVADOC_1_6_LINK, JAVADOC_1_6_TEXT, JAVADOC_ACCESS_LEVEL, JAVADOC_API_REF_VERSION, JAVADOC_AUTO_TEXT, JAVADOC_CUSTOM_PARAMS, JAVADOC_DESTINATION, JAVADOC_FROM_ROOTS, JAVADOC_LINK_VERSION, JAVADOC_NONE_TEXT, JAVADOC_PROMPT_FOR_DESTINATION, KEY_ABOUT, KEY_BACKWARD, KEY_BEGIN_DOCUMENT, KEY_BEGIN_LINE, KEY_BOOKMARKS_PANEL, KEY_BOOKMARKS_TOGGLE, KEY_BROWSE_BACK, KEY_BROWSE_FORWARD, KEY_CHECK_NEW_VERSION, KEY_CLEAR_CONSOLE, KEY_CLEAR_HISTORY, KEY_CLEAR_LINE, KEY_CLOSE_ALL_FILES, KEY_CLOSE_FILE, KEY_CLOSE_PROJECT, KEY_CLOSING_BRACE, KEY_COMMENT_LINES, KEY_COMPILE, KEY_COMPILE_ALL, KEY_COMPLETE_FILE, KEY_COPY, KEY_CUT, KEY_CUT_LINE, KEY_DEBUG_BREAKPOINT_PANEL, KEY_DEBUG_BREAKPOINT_TOGGLE, KEY_DEBUG_CLEAR_ALL_BREAKPOINTS, 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_DETACH_DEBUGGER, KEY_DETACH_TABBEDPANES, KEY_DOWN, KEY_DRJAVA_ERRORS, KEY_DRJAVA_SURVEY, KEY_END_DOCUMENT, KEY_END_LINE, KEY_EXEC_PROCESS, KEY_EXECUTE_HISTORY, KEY_EXPORT_OLD, KEY_FIND_NEXT, KEY_FIND_PREV, KEY_FIND_REPLACE, KEY_FOLLOW_FILE, KEY_FORCE_QUIT, KEY_FORWARD, KEY_GOTO_FILE, KEY_GOTO_FILE_UNDER_CURSOR, KEY_GOTO_LINE, KEY_HELP, KEY_JAVADOC_ALL, KEY_JAVADOC_CURRENT, KEY_LIFT_CURRENT_INTERACTION, KEY_LOAD_HISTORY_SCRIPT, KEY_NEW_FILE, KEY_NEW_TEST, KEY_NEXT_DOCUMENT, KEY_NEXT_PANE, KEY_NEXT_WORD, KEY_OPEN_FILE, KEY_OPEN_FOLDER, KEY_OPEN_JAVADOC, KEY_OPEN_JAVADOC_UNDER_CURSOR, KEY_OPEN_PROJECT, KEY_OPENING_BRACE, KEY_PAGE_DOWN, KEY_PAGE_SETUP, KEY_PAGE_UP, KEY_PASTE, KEY_PASTE_FROM_HISTORY, KEY_PREFERENCES, KEY_PREVIOUS_DOCUMENT, KEY_PREVIOUS_PANE, KEY_PREVIOUS_WORD, KEY_PRINT, KEY_PRINT_CONSOLE, KEY_PRINT_INTERACTIONS, KEY_PRINT_PREVIEW, KEY_QUICKSTART, KEY_QUIT, KEY_REDO, KEY_RENAME_FILE, KEY_RESET_INTERACTIONS, KEY_REVERT_FILE, KEY_RUN, KEY_RUN_MAIN, KEY_SAVE_ALL_FILES, KEY_SAVE_FILE, KEY_SAVE_FILE_AS, KEY_SAVE_HISTORY, KEY_SELECT_ALL, KEY_SHIFT_DELETE_NEXT, KEY_SHIFT_DELETE_PREVIOUS, KEY_TEST, KEY_TEST_ALL, KEY_UNCOMMENT_LINES, KEY_UNDO, KEY_UP, KEY_VIEW_INTERACTIONS_CLASSPATH, LANGUAGE_LEVEL, LAST_DIRECTORY, LAST_DRJAVA_SURVEY, LAST_DRJAVA_SURVEY_RESULT, LAST_INTERACTIONS_DIRECTORY, LAST_NEW_VERSION_NOTIFICATION, LIGHTWEIGHT_PARSING_ENABLED, LINEENUM_ENABLED, linkVersionChoices, LOOK_AND_FEEL, MASK, MASTER_JVM_ARGS, MASTER_JVM_XMX, NEW_VERSION_NOTIFICATION, NEW_VERSION_NOTIFICATION_CHOICES, NEW_VERSION_NOTIFICATION_DAYS, OLD_PROJECT_FILE_EXTENSION, OPEN_FOLDER_RECURSIVE, PLASTIC_THEMES, PROJECT_FILE_EXTENSION, PROMPT_BEFORE_CLEAN, QUIT_PROMPT, RECENT_FILES, RECENT_FILES_MAX_SIZE, RECENT_PROJECTS, REMOTE_CONTROL_ENABLED, REMOTE_CONTROL_PORT, RESET_CLEAR_CONSOLE, RUN_WITH_ASSERT, SHOW_CODE_PREVIEW_POPUPS, SHOW_DEBUG_CONSOLE, SHOW_DEPRECATION_WARNINGS, SHOW_FALLTHROUGH_WARNINGS, SHOW_FINALLY_WARNINGS, SHOW_PATH_WARNINGS, SHOW_SERIAL_WARNINGS, SHOW_SOURCE_WHEN_SWITCHING, SHOW_UNCHECKED_WARNINGS, SLAVE_JVM_ARGS, SLAVE_JVM_XMX, STICKY_INTERACTIONS_DIRECTORY, SYSTEM_ERR_COLOR, SYSTEM_IN_COLOR, SYSTEM_OUT_COLOR, TABS_HEIGHT, TEXT_ANTIALIAS, TOOLBAR_ENABLED, TOOLBAR_ICONS_ENABLED, TOOLBAR_TEXT_ENABLED, WARN_BREAKPOINT_OUT_OF_SYNC, WARN_CHANGE_LAF, WARN_CHANGE_THEME, WARN_DEBUG_MODIFIED_FILE, WARN_PATH_CONTAINS_POUND, WINDOW_HEIGHT, WINDOW_STATE, WINDOW_STORE_POSITION, WINDOW_WIDTH, WINDOW_X, WINDOW_Y
 
Constructor Summary
DefinitionsDocument(GlobalEventNotifier notifier)
          Main constructor.
DefinitionsDocument(GlobalEventNotifier notifier, CompoundUndoManager undoManager)
          Main constructor.
DefinitionsDocument(Indenter indenter, GlobalEventNotifier notifier)
          Convenience constructor for using a custom indenter.
 
Method Summary
 int _findPrevKeyword(String text, String kw, int pos)
          Assuming that text is a document prefix including offset pos, finds the index of the keyword kw searching back from pos.
 String _getEnclosingClassName(int pos, boolean qual)
          Searches backwards to find the name of the enclosing named class or interface.
 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.
 boolean _isAnonymousInnerClass(int pos, int openCurlyPos)
          Returns true if this position is the instantiation of an anonymous inner class.
protected  void _styleChanged()
          Recolors the rest of the document based on the change that triggered this call.
 void addDocumentClosedListener(DocumentClosedListener l)
           
 void addFinalizationListener(FinalizationListener<DefinitionsDocument> fl)
          Registers a finalization listener with the specific instance of the ddoc
protected  void addUndoRedo(AbstractDocument.DefaultDocumentEvent chng, Runnable undoCommand, Runnable doCommand)
           
 void close()
          Closes this DefinitionsDocument (but not the enclosing OpenDefinitionsDocument).
 int commentLines(int selStart, int selEnd)
          Comments out all lines between selStart and selEnd, inclusive.
 Position createPosition(int offset)
          Factory method for created WrappedPositions.
 void documentSaved()
          Informs this document's undo manager that the document has been saved.
protected  void endCompoundEdit(int key)
           
protected  void endLastCompoundEdit()
           
protected  void finalize()
          This is called when this method is GC'd.
 int getCurrentCol()
          Return the current column of the cursor position.
 int getCurrentLine()
          Return the current line of the cursor position.
 String getEnclosingClassName(int pos, boolean qual)
          Searches backwards to find the name of the enclosing named class or interface.
 String getEnclosingTopLevelClassName(int pos)
          Returns the name of the class or interface enclosing the caret position at the top level.
 List<FinalizationListener<DefinitionsDocument>> getFinalizationListeners()
           
 String getFirstTopLevelClassName()
          Gets the name of the top level class in this source file by finding the first declaration of a class or interface.
 int getLineOfOffset(int offset)
          Return the line number corresponding to offset.
 String getMainClassName()
          Gets the name of the document's main class: the document's only public class/interface or first top level class if document contains no public classes or interfaces.
 UndoableEdit getNextRedo()
          Public accessor for the next undo action.
 String getNextTopLevelClassName(int startPos, int endPos)
           
 UndoableEdit getNextUndo()
          Public accessor for the next undo action.
 OpenDefinitionsDocument getOpenDefDoc()
           
 String getPackageName()
          Gets the package name embedded in the text of this document by minimally parsing the document to find the package statement.
 String getQualifiedClassName()
          Gets the package and main class/interface name of this OpenDefinitionsDocument
 String getQualifiedClassName(int pos)
          Gets fully qualified class name of the top level class enclosing the given position.
 CompoundUndoManager getUndoManager()
          Getter method for CompoundUndoManager
 WeakHashMap<DefinitionsDocument.WrappedPosition,Integer> getWrappedPositionOffsets()
          Remove all positions that have been garbage-collected from the list of positions, then return a weakly-linked hashmap with positions and their current offsets.
 void gotoLine(int line)
          Goes to a particular line in the document.
 void insertString(int offset, String str, AttributeSet a)
          Inserts a string of text into the document.
 boolean isModifiedSinceSave()
          Determines if the document has been modified since the last save.
protected  Indenter makeNewIndenter(int indentLevel)
          Returns a new indenter.
 void remove(int offset, int len)
          Removes a block of text from the specified location.
 void removeDocumentClosedListener(DocumentClosedListener l)
           
 void resetModification()
          Resets the modification state of this document.
 void resetUndoManager()
          Resets the undo manager.
 void setOpenDefDoc(OpenDefinitionsDocument odd)
          Sets the OpenDefinitionsDocument that holds this DefinitionsDocument (the odd can only be set once).
 void setWrappedPositionOffsets(WeakHashMap<DefinitionsDocument.WrappedPosition,Integer> whm)
          Re-create the wrapped positions in the hashmap, update the wrapped position, and add them to the list.
protected  int startCompoundEdit()
           
 boolean tabsRemoved()
          Returns true iff tabs are to removed on text insertion.
 String toString()
           
 int uncommentLines(int selStart, int selEnd)
          Uncomments all lines between selStart and selEnd, inclusive.
 void updateModifiedSinceSave()
          Resets the modification state of this document to be consistent with state of _undoManager.
 
Methods inherited from class edu.rice.cs.drjava.model.AbstractDJDocument
_checkCache, _clearCache, _findPrevCharPos, _findPrevNonWSCharPos, _getEnclosingBrace, _getIndentOfCurrStmt, _getIndentOfCurrStmt, _getIndentOfCurrStmt, _getLineEnclosingBrace, _getLineEndPos, _getLineFirstCharPos, _getLineStartPos, _inBlockComment, _indentLine, _inParenPhrase, _isStartOfComment, _makeKeywords, _makeNormEndings, _makePrimTypes, _removeIndenter, _storeInCache, balanceBackward, balanceForward, clear, findCharInStmtBeforePos, findCharOnLine, findNextEnclosingBrace, findPrevDelimiter, findPrevDelimiter, findPrevEnclosingBrace, getAndResetNumLinesChangedAfter, getBytes, getCurrentLocation, getFirstNonWSCharPos, getFirstNonWSCharPos, getFirstNonWSCharPos, getHighlightStatus, getIndent, getIntelligentBeginLinePos, getReduced, getStateAtCurrent, hasOnlySpaces, indentLines, indentLines, insertUpdate, isShadowed, isShadowed, move, notInBlock, removeUpdate, resetReducedModelLocation, setCurrentLocation, setIndent, setTab, setTab, stateAtRelLocation
 
Methods inherited from class edu.rice.cs.util.text.SwingDocument
_getText, addColoring, append, append, append, createUnwrappedPosition, forceInsertText, forceRemoveText, getDefaultStyle, getDocStyle, getDocText, getEditCondition, getPageable, getText, insertText, print, removeText, setDocStyle, setEditCondition
 
Methods inherited from class javax.swing.text.DefaultStyledDocument
addDocumentListener, addStyle, create, createDefaultRoot, getBackground, getCharacterElement, getDefaultRootElement, getFont, getForeground, getLogicalStyle, getParagraphElement, getStyle, getStyleNames, insert, removeDocumentListener, removeStyle, setCharacterAttributes, setLogicalStyle, setParagraphAttributes, styleChanged
 
Methods inherited from class javax.swing.text.AbstractDocument
addUndoableEditListener, createBranchElement, createLeafElement, dump, fireChangedUpdate, fireInsertUpdate, fireRemoveUpdate, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, postRemoveUpdate, putProperty, readLock, readUnlock, removeUndoableEditListener, render, replace, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties, writeLock, writeUnlock
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.rice.cs.drjava.model.DJDocument
getText
 
Methods inherited from interface edu.rice.cs.util.text.AbstractDocumentInterface
append, getLength, getText
 
Methods inherited from interface javax.swing.text.StyledDocument
addStyle, getBackground, getCharacterElement, getFont, getForeground, getLogicalStyle, getParagraphElement, getStyle, removeStyle, setCharacterAttributes, setLogicalStyle, setParagraphAttributes
 
Methods inherited from interface javax.swing.text.Document
addDocumentListener, addUndoableEditListener, getDefaultRootElement, getEndPosition, getLength, getProperty, getRootElements, getStartPosition, getText, getText, putProperty, removeDocumentListener, removeUndoableEditListener, render
 
Methods inherited from interface edu.rice.cs.util.text.EditDocumentInterface
getLength
 

Field Detail

_log

public static final Log _log
Constructor Detail

DefinitionsDocument

public DefinitionsDocument(Indenter indenter,
                           GlobalEventNotifier notifier)
Convenience constructor for using a custom indenter.

Parameters:
indenter - custom indenter class
notifier - used by CompoundUndoManager to announce undoable edits

DefinitionsDocument

public DefinitionsDocument(GlobalEventNotifier notifier)
Main constructor. This has an obnoxious dependency on GlobalEventNotifier, which is passed through here only for a single usage in CompoundUndoManager. TODO: find a better way.

Parameters:
notifier - used by CompoundUndoManager to announce undoable edits

DefinitionsDocument

public DefinitionsDocument(GlobalEventNotifier notifier,
                           CompoundUndoManager undoManager)
Main constructor. This has an obnoxious dependency on GlobalEventNotifier, which is passed through here only for a single usage in CompoundUndoManager. TODO: find a better way.

Parameters:
notifier - used by CompoundUndoManager to announce undoable edits
Method Detail

addDocumentClosedListener

public void addDocumentClosedListener(DocumentClosedListener l)

removeDocumentClosedListener

public void removeDocumentClosedListener(DocumentClosedListener l)

close

public void close()
Closes this DefinitionsDocument (but not the enclosing OpenDefinitionsDocument). Called when this is kicked out of the document cache so that this can be GC'd.


makeNewIndenter

protected Indenter makeNewIndenter(int indentLevel)
Returns a new indenter.


setOpenDefDoc

public void setOpenDefDoc(OpenDefinitionsDocument odd)
Sets the OpenDefinitionsDocument that holds this DefinitionsDocument (the odd can only be set once).

Parameters:
odd - the OpenDefinitionsDocument to set as this DD's holder

getOpenDefDoc

public OpenDefinitionsDocument getOpenDefDoc()
Returns:
the OpenDefinitonsDocument that is associated with this DefinitionsDocument.

_styleChanged

protected void _styleChanged()
Recolors the rest of the document based on the change that triggered this call.

Specified by:
_styleChanged in class AbstractDJDocument

getQualifiedClassName

public String getQualifiedClassName()
                             throws ClassNameNotFoundException
Gets the package and main class/interface name of this OpenDefinitionsDocument

Returns:
the qualified main class/interface name
Throws:
ClassNameNotFoundException

getQualifiedClassName

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

Throws:
ClassNameNotFoundException

insertString

public void insertString(int offset,
                         String str,
                         AttributeSet a)
                  throws BadLocationException
Inserts a string of text into the document. This is not where we do custom processing of the insert; that is done in AbstractDJDocument.insertUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent, javax.swing.text.AttributeSet). If _removeTabs is set to true, remove all tabs from str. It is a current invariant of the tabification functionality that the document contains no tabs, but we want to allow the user to override this functionality.

Specified by:
insertString in interface DJDocument
Specified by:
insertString in interface AbstractDocumentInterface
Specified by:
insertString in interface Document
Overrides:
insertString in class SwingDocument
Throws:
BadLocationException

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 AbstractDJDocument.removeUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent).

Specified by:
remove in interface DJDocument
Specified by:
remove in interface AbstractDocumentInterface
Specified by:
remove in interface Document
Overrides:
remove in class SwingDocument
Throws:
BadLocationException

updateModifiedSinceSave

public void updateModifiedSinceSave()
Resets the modification state of this document to be consistent with state of _undoManager. Called whenever an undo or redo is performed.


resetModification

public void resetModification()
Resets the modification state of this document. Used after a document has been saved or reverted.


isModifiedSinceSave

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

Returns:
true if the document has been modified

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.


getLineOfOffset

public int getLineOfOffset(int offset)
Return the line number corresponding to offset. Uses a 1-based index.


_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. Line number counting begins with 1 not 0. Assumes read lock is already held.

Parameters:
lineNum - the line number for which to calculate the offset.
Returns:
the offset of the first character in the given line number

tabsRemoved

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


commentLines

public int commentLines(int selStart,
                        int selEnd)
Comments out all lines between selStart and selEnd, inclusive. The cursor position is unchanged by the operation.

Parameters:
selStart - the document offset for the start of the selection
selEnd - the document offset for the end of the selection

uncommentLines

public int uncommentLines(int selStart,
                          int selEnd)
Uncomments all lines between selStart and selEnd, inclusive. The cursor position is unchanged by the operation.

Parameters:
selStart - the document offset for the start of the selection
selEnd - the document offset for the end of the selection

gotoLine

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


_findPrevKeyword

public int _findPrevKeyword(String text,
                            String kw,
                            int pos)
                     throws BadLocationException
Assuming that text is a document prefix including offset pos, finds the index of the keyword kw searching back from pos.

Throws:
BadLocationException

getEnclosingClassName

public String getEnclosingClassName(int pos,
                                    boolean qual)
                             throws BadLocationException,
                                    ClassNameNotFoundException
Searches backwards to find the name of the enclosing named class or interface. NB: ignores comments. WARNING: In long source files and when contained in anonymous inner classes, this function might take a LONG time.

Parameters:
pos - Position to start from
qual - true to find the fully qualified class name
Returns:
name of the enclosing named class or interface
Throws:
BadLocationException
ClassNameNotFoundException

_getEnclosingClassName

public String _getEnclosingClassName(int pos,
                                     boolean qual)
                              throws BadLocationException,
                                     ClassNameNotFoundException
Searches backwards to find the name of the enclosing named class or interface. NB: ignores comments. Only runs in event thread. WARNING: In long source files and when contained in anonymous inner classes, this function might take a LONG time.

Parameters:
pos - Position to start from
qual - true to find the fully qualified class name
Returns:
name of the enclosing named class or interface
Throws:
BadLocationException
ClassNameNotFoundException

_isAnonymousInnerClass

public boolean _isAnonymousInnerClass(int pos,
                                      int openCurlyPos)
                               throws BadLocationException
Returns true if this position is the instantiation of an anonymous inner class. Only runs in the event thread.

Parameters:
pos - position of "new"
openCurlyPos - position of the next '{'
Returns:
true if anonymous inner class instantiation
Throws:
BadLocationException

getPackageName

public String getPackageName()
Gets the package name embedded in the text of this document by minimally parsing the document to find the package statement. If package statement is not found or is ill-formed, returns "" as the package name.

Returns:
the name of package embedded in this document. If there is no well-formed package statement, returns "" as the package name.

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

getMainClassName

public String getMainClassName()
                        throws ClassNameNotFoundException
Gets the name of the document's main class: the document's only public class/interface or first top level class if document contains no public classes or interfaces.

Throws:
ClassNameNotFoundException

getFirstTopLevelClassName

public String getFirstTopLevelClassName()
                                 throws ClassNameNotFoundException
Gets the name of the top level class in this source file by finding 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
Throws:
ClassNameNotFoundException

createPosition

public Position createPosition(int offset)
                        throws BadLocationException
Factory method for created WrappedPositions. Stores the created Position instance so it can be linked to a different DefinitionsDocument later.

Specified by:
createPosition in interface AbstractDocumentInterface
Specified by:
createPosition in interface Document
Overrides:
createPosition in class AbstractDocument
Throws:
BadLocationException

getWrappedPositionOffsets

public WeakHashMap<DefinitionsDocument.WrappedPosition,Integer> getWrappedPositionOffsets()
Remove all positions that have been garbage-collected from the list of positions, then return a weakly-linked hashmap with positions and their current offsets.

Returns:
list of weak references to all positions that have been created and that have not been garbage-collected yet.

setWrappedPositionOffsets

public void setWrappedPositionOffsets(WeakHashMap<DefinitionsDocument.WrappedPosition,Integer> whm)
                               throws BadLocationException
Re-create the wrapped positions in the hashmap, update the wrapped position, and add them to the list.

Parameters:
whm - weakly-linked hashmap of wrapped positions and their offsets
Throws:
BadLocationException

getUndoManager

public CompoundUndoManager getUndoManager()
Getter method for CompoundUndoManager

Returns:
_undoManager

resetUndoManager

public void resetUndoManager()
Resets the undo manager.


getNextUndo

public UndoableEdit getNextUndo()
Public accessor for the next undo action.


getNextRedo

public UndoableEdit getNextRedo()
Public accessor for the next undo action.


documentSaved

public void documentSaved()
Informs this document's undo manager that the document has been saved.


startCompoundEdit

protected int startCompoundEdit()
Specified by:
startCompoundEdit in class AbstractDJDocument

endCompoundEdit

protected void endCompoundEdit(int key)
Specified by:
endCompoundEdit in class AbstractDJDocument

endLastCompoundEdit

protected void endLastCompoundEdit()
Specified by:
endLastCompoundEdit in class AbstractDJDocument

addUndoRedo

protected void addUndoRedo(AbstractDocument.DefaultDocumentEvent chng,
                           Runnable undoCommand,
                           Runnable doCommand)
Specified by:
addUndoRedo in class AbstractDJDocument

addFinalizationListener

public void addFinalizationListener(FinalizationListener<DefinitionsDocument> fl)
Registers a finalization listener with the specific instance of the ddoc

NOTE:This should only be used by test cases. This is to ensure that we don't spring memory leaks by allowing our unit tests to keep track of whether objects are being finalized (garbage collected)

Specified by:
addFinalizationListener in interface Finalizable<DefinitionsDocument>
Parameters:
fl - the listener to register

getFinalizationListeners

public List<FinalizationListener<DefinitionsDocument>> getFinalizationListeners()
Specified by:
getFinalizationListeners in interface Finalizable<DefinitionsDocument>
Returns:
the list of registered FinalizationListeners

finalize

protected void finalize()
This is called when this method is GC'd. Since this class implements edu.rice.cs.drjava.model.Finalizable, it must notify its listeners

Overrides:
finalize in class Object

toString

public String toString()
Overrides:
toString in class Object