edu.rice.cs.drjava.model
Interface DJDocument

All Superinterfaces:
AbstractDocumentInterface, Document, StyledDocument, SwingDocumentInterface
All Known Subinterfaces:
OpenDefinitionsDocument
All Known Implementing Classes:
AbstractDJDocument, DefinitionsDocument, DummyOpenDefDoc, InteractionsDJDocument

public interface DJDocument
extends SwingDocumentInterface

Interface shared by the Definitions Document, Open Definitions Document, and Interactions Document. Characteristic of native DrJava Documents (as opposed to DrJava plugin documents).


Field Summary
 
Fields inherited from interface javax.swing.text.Document
StreamDescriptionProperty, TitleProperty
 
Method Summary
 int _getIndentOfCurrStmt(int pos)
          Returns the indent level of the start of the statement that the cursor is on.
 int _getIndentOfCurrStmt(int pos, char[] delims)
          Returns the indent level of the start of the statement that the cursor is on.
 int _getIndentOfCurrStmt(int pos, char[] delims, char[] whitespace)
          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.
 int balanceBackward()
          Finds the match for the closing brace immediately to the left, assuming there is such a brace.
 int balanceForward()
          Finds the match for the open brace immediately to the right, assuming there is such a brace.
 void clear()
          Clears the entire text of the document.
 int findCharOnLine(int pos, char findChar)
          Determines if the given character exists on the line where the given cursor position is.
 int findNextEnclosingBrace(int pos, char opening, char closing)
          Searching forwards, finds the position of the enclosing brace.
 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 findPrevEnclosingBrace(int pos, char opening, char closing)
          Searching backwards, finds the position of the enclosing brace.
 int getCurrentLocation()
          Gets the current location of the cursor the document.
 int getFirstNonWSCharPos(int pos)
          Finds the position of the first non-whitespace character after pos.
 int getFirstNonWSCharPos(int pos, boolean acceptComments)
          Similar to the single-argument version, but allows including comments.
 int getFirstNonWSCharPos(int pos, char[] whitespace, boolean acceptComments)
          Finds the position of the first non-whitespace character after pos.
 ArrayList<HighlightStatus> getHighlightStatus(int start, int end)
          Returns highlight status info for text between start and end, coalescing adjoining blocks with the same status.
 int getIndent()
          Gets the indent level.
 int getIntelligentBeginLinePos(int currPos)
          Returns the "intelligent" beginning of line.
 ReducedModelControl getReduced()
           
 ReducedModelState getStateAtCurrent()
           
 String getText()
          Gets the entire text of the document.
 void indentLines(int selStart, int selEnd)
          Default indentation - uses OTHER flag and no progress indicator.
 void indentLines(int selStart, int selEnd, Indenter.IndentReason reason, ProgressMonitor pm)
          Parameterized indentation for special-case handling.
 void insertString(int offset, String str, AttributeSet a)
          Inserts a string of text into the document.
 void move(int dist)
          Moves the current location the specified number of chars (positive is right; negative is left).
 void remove(int offset, int len)
          Removes a block of text from the specified location.
 void setCurrentLocation(int loc)
          Change the current location of the document
 void setIndent(int indent)
          Sets the indent to a particular number of spaces.
 
Methods inherited from interface edu.rice.cs.util.text.AbstractDocumentInterface
append, createPosition, 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, createPosition, getDefaultRootElement, getEndPosition, getLength, getProperty, getRootElements, getStartPosition, getText, getText, putProperty, removeDocumentListener, removeUndoableEditListener, render
 

Method Detail

getIndent

int getIndent()
Gets the indent level.

Returns:
the indent level

setIndent

void setIndent(int indent)
Sets the indent to a particular number of spaces.

Parameters:
indent - the size of indent that you want for the document

getHighlightStatus

ArrayList<HighlightStatus> getHighlightStatus(int start,
                                              int end)
Returns highlight status info for text between start and end, coalescing adjoining blocks with the same status.


getCurrentLocation

int getCurrentLocation()
Gets the current location of the cursor the document. Unlike the Swing document model, which is stateless, we must maintain a current location as part of the document because the implementation of the reduced model relies on this state information.

Returns:
where the cursor is as the number of characters into the document

setCurrentLocation

void setCurrentLocation(int loc)
Change the current location of the document

Parameters:
loc - the new absolute location

move

void move(int dist)
Moves the current location the specified number of chars (positive is right; negative is left). It is used as a helper for setCurrentLocation(int).

Parameters:
dist - the distance from the current location to the new location.

balanceBackward

int balanceBackward()
Finds 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

int balanceForward()
Finds 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.

getStateAtCurrent

ReducedModelState getStateAtCurrent()

findPrevEnclosingBrace

int findPrevEnclosingBrace(int pos,
                           char opening,
                           char closing)
                           throws BadLocationException
Searching backwards, finds the position of the enclosing brace. NB: ignores comments.

Parameters:
pos - Position to start from
opening - opening brace character
closing - closing brace character
Returns:
position of enclosing curly brace, or ERROR_INDEX (-1) if beginning of document is reached.
Throws:
BadLocationException

findNextEnclosingBrace

int findNextEnclosingBrace(int pos,
                           char opening,
                           char closing)
                           throws BadLocationException
Searching forwards, finds the position of the enclosing brace. NB: ignores comments.

Parameters:
pos - Position to start from
opening - opening brace character
closing - closing brace character
Returns:
position of enclosing curly brace, or ERROR_INDEX (-1) if beginning of document is reached.
Throws:
BadLocationException

findPrevDelimiter

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 (-1) if beginning of document is reached.
Throws:
BadLocationException

findPrevDelimiter

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 (-1) if beginning of document is reached.
Throws:
BadLocationException

indentLines

void indentLines(int selStart,
                 int selEnd)
Default indentation - uses OTHER flag and no progress indicator.

Parameters:
selStart - the offset of the initial character of the region to indent
selEnd - the offset of the last character of the region to indent

indentLines

void indentLines(int selStart,
                 int selEnd,
                 Indenter.IndentReason reason,
                 ProgressMonitor pm)
                 throws OperationCanceledException
Parameterized indentation for special-case handling.

Parameters:
selStart - the offset of the initial character of the region to indent
selEnd - the offset of the last character of the region to indent
reason - a flag from Indenter to indicate the reason for the indent (indent logic may vary slightly based on the trigger action)
pm - used to display progress, null if no reporting is desired
Throws:
OperationCanceledException

getIntelligentBeginLinePos

int getIntelligentBeginLinePos(int currPos)
                               throws BadLocationException
Returns the "intelligent" beginning of line. If currPos is to the right of the first non-whitespace character, the position of the first non-whitespace character is returned. If currPos is at or to the left of the first non-whitespace character, the beginning of the line is returned.

Parameters:
currPos - A position on the current line
Throws:
BadLocationException

_getIndentOfCurrStmt

int _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. (';', '{', '}') and a default set of whitespace characters (' ', '\t', n', ',').

Parameters:
pos - Cursor position
Throws:
BadLocationException

_getIndentOfCurrStmt

int _getIndentOfCurrStmt(int pos,
                         char[] delims)
                         throws BadLocationException
Returns the indent level of the start of the statement that the cursor is on. Uses a default set of whitespace characters (' ', '\t', '\n', ',').

Parameters:
pos - Cursor position
Throws:
BadLocationException

_getIndentOfCurrStmt

int _getIndentOfCurrStmt(int pos,
                         char[] delims,
                         char[] whitespace)
                         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
whitespace - characters to skip when looking for beginning of next statement
Throws:
BadLocationException

findCharOnLine

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

int _getLineStartPos(int pos)
Returns the absolute position of the beginning of the current line. (Just after most recent newline, or 0) Doesn't ignore comments.

Parameters:
pos - Any position on the current line
Returns:
position of the beginning of this line

_getLineEndPos

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

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.
Throws:
BadLocationException

getFirstNonWSCharPos

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 (-1) if end of document is reached
Throws:
BadLocationException

getFirstNonWSCharPos

int getFirstNonWSCharPos(int pos,
                         boolean acceptComments)
                         throws BadLocationException
Similar to the single-argument version, but allows including comments.

Parameters:
pos - Position to start from
acceptComments - if true, find non-whitespace chars in comments
Returns:
position of first non-whitespace character after pos, or ERROR_INDEX (-1) if end of document is reached
Throws:
BadLocationException

getFirstNonWSCharPos

int getFirstNonWSCharPos(int pos,
                         char[] whitespace,
                         boolean acceptComments)
                         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
acceptComments - if true, find non-whitespace chars in comments
Returns:
position of first non-whitespace character after pos, or ERROR_INDEX (-1) if end of document is reached
Throws:
BadLocationException

insertString

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

Specified by:
insertString in interface AbstractDocumentInterface
Specified by:
insertString in interface Document
Throws:
BadLocationException

remove

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 AbstractDocumentInterface
Specified by:
remove in interface Document
Throws:
BadLocationException

getText

String getText()
Gets the entire text of the document. Without this operation, a client must use locking to perform this task safely.

Specified by:
getText in interface AbstractDocumentInterface

clear

void clear()
Clears the entire text of the document. Without this operation, a client must use locking to perform this task safely.


getReduced

ReducedModelControl getReduced()