| edu.rice.cs.util.text.SwingDocument edu.rice.cs.drjava.model.AbstractDJDocument
All known Subclasses: edu.rice.cs.drjava.model.repl.InteractionsDJDocument, edu.rice.cs.drjava.model.definitions.DefinitionsDocument,
Inner Class :protected class InsertCommand implements Runnable | |
Inner Class :protected class RemoveCommand implements Runnable | |
Field Summary | |
final public static int | DOCSTART Constant for starting position of document. | final public static int | ERROR_INDEX Constant used by helper methods to indicate an error. | protected volatile boolean | _cacheInUse Whether anything is stored in the cache. | protected volatile int | _currentLocation The absolute character offset in the document. | protected volatile int | _indent The default indent setting. | final protected static HashSet<String> | _keywords A set of Java keywords. | final protected static HashSet<String> | _normEndings A set of normal endings for lines. | final protected static HashSet<String> | _primTypes A set of Java keywords. | final public BraceReduction | _reduced The reduced model of the document (stored in field _reduced) handles most of the document logic and keeps
track of state. |
Constructor Summary | |
protected | AbstractDJDocument() Standard default constructor; required because a unary constructor is defined. | protected | AbstractDJDocument(Indenter indent) Constructor used to build a new document with an existing indenter. |
Method Summary | |
protected Object | _checkCache(String key) Checks the helper method cache for a stored value. | public boolean | _indentLine(Indenter.IndentReason reason) Indents a line using the Indenter. | protected static boolean | _isReversteStartOfComment(String text, int pos) Helper method for findPrevNonWSCharPos. | protected static boolean | _isStartOfComment(String text, int pos) | protected static HashSet<String> | _makeKeywords() Create a set of Java/GJ keywords for special coloring. | protected static HashSet<String> | _makeNormEndings() Create a set of normal endings, i.e., semi-colons and braces for the purposes of indenting. | protected static HashSet<String> | _makePrimTypes() Create a set of Java/GJ primitive types for special coloring. | protected void | _removeIndenter() | protected void | _storeInCache(String key, Object result) Stores the given result in the helper method cache. | abstract protected 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:
- Only fire changed event if text other than that which was inserted
or removed *actually* changed status.
| abstract protected void | addUndoRedo(AbstractDocument.DefaultDocumentEvent chng, Runnable undoCommand, Runnable doCommand) | public int | balanceBackward() Forwarding method to find the match for the closing brace immediately to the left, assuming
there is such a brace. | public int | balanceForward() Forwarding method to find the match for the open brace immediately to the right, assuming there
is such a brace. | public void | clear() | protected void | clearCache() Clears the memoizing cache for read operations on the document. | abstract protected void | endCompoundEdit(int i) | abstract protected void | endLastCompoundEdit() | public boolean | findCharInStmtBeforePos(char findChar, int position) This function finds the given character in the same statement as the given position, and before the given
position. | public int | findCharOnLine(int pos, char findChar) Determines if the given character exists on the line where the given cursor position is. | public int | findNextEnclosingBrace(int pos, char opening, char closing) Searching forward, finds the position of the enclosing squiggly brace. | public int | findPrevCharPos(int pos, char[] whitespace) Finds the position of the first non-whitespace, non-comment character before pos. | public int | findPrevDelimiter(int pos, char[] delims) Searching backwards, finds the position of the first character that is one of the given delimiters. | public int | findPrevDelimiter(int pos, char[] delims, boolean skipParenPhrases) Searching backwards, finds the position of the first character that is one of the given delimiters. | public int | findPrevEnclosingBrace(int pos, char opening, char closing) Searching backwards, finds the position of the enclosing brace. | public int | findPrevNonWSCharPos(int pos) | public byte[] | getBytes() Returns the byte image (as written to a file) of this document. | public int | getCurrentLocation() Get the current location of the cursor in the document. | public int | getFirstNonWSCharPos(int pos) Finds the position of the first non-whitespace character after pos. | public int | getFirstNonWSCharPos(int pos, boolean acceptComments) Similar to the single-argument version, but allows including comments. | public int | getFirstNonWSCharPos(int pos, char[] whitespace, boolean acceptComments) Finds the position of the first non-whitespace character after pos. | public Vector<HighlightStatus> | getHighlightStatus(int start, int end) Return all highlight status info for text between start and end. | public int | getIndent() Get the indent level. | public IndentInfo | getIndentInformation() Returns the indent information for the current location. | public String | getIndentOfCurrStmt(int pos) Returns the indent level of the start of the statement that the cursor is on. | public String | getIndentOfCurrStmt(int pos, char[] delims) Returns the indent level of the start of the statement that the cursor is on. | public String | getIndentOfCurrStmt(int pos, char[] delims, char[] whitespace) Returns the indent level of the start of the statement that the cursor is on. | public int | getIntelligentBeginLinePos(int currPos) Returns the "intelligent" beginning of line. | public int | getLineEndPos(int pos) Returns the absolute position of the end of the current line. | public int | getLineFirstCharPos(int pos) Returns the absolute position of the first non-whitespace character on the current line. | public int | getLineStartPos(int pos) Returns the absolute position of the beginning of the current line. | public BraceReduction | getReduced() This method is used ONLY for testing. | public ReducedModelState | getStateAtCurrent() | public String | getText() | public int | getWhiteSpace() Gets the number of whitespace characters between the current location and the end of
the document or the first non-whitespace character, whichever comes first. | public void | indentLines(int selStart, int selEnd) Default indentation - uses OTHER flag and no progress indicator. | public void | indentLines(int selStart, int selEnd, Indenter.IndentReason reason, ProgressMonitor pm) Parameterized indentation for special-case handling. | public 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. | abstract protected Indenter | makeNewIndenter(int indentLevel) Returns a new indenter. | public void | move(int dist) The actual cursor movement logic. | public boolean | posInParenPhrase(int pos) Returns true if the given position is inside a paren phrase. | public boolean | posInParenPhrase() Returns true if the reduced model's current 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. | public 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. | public void | resetReducedModelLocation() | public void | setCurrentLocation(int loc) | public void | setIndent(int indent) Set the indent to a particular number of spaces. | public void | setTab(String tab, int pos) Sets text between previous newline and first non-whitespace character of line containing pos to tab. | abstract protected int | startCompoundEdit() | public ReducedModelState | stateAtRelLocation(int dist) |
DOCSTART | final public static int DOCSTART(Code) | | Constant for starting position of document.
|
ERROR_INDEX | final public static int ERROR_INDEX(Code) | | Constant used by helper methods to indicate an error.
|
_cacheInUse | protected volatile boolean _cacheInUse(Code) | | Whether anything is stored in the cache. It is used to avoid clearing the table
unnecessarily on every change to the document.
|
_currentLocation | protected volatile int _currentLocation(Code) | | The absolute character offset in the document.
|
_indent | protected volatile int _indent(Code) | | The default indent setting.
|
_normEndings | final protected static HashSet<String> _normEndings(Code) | | A set of normal endings for lines.
|
_reduced | final public BraceReduction _reduced(Code) | | The reduced model of the document (stored in field _reduced) handles most of the document logic and keeps
track of state. This field together with _currentLocation function as a virtual object for purposes of
synchronization. All operations that access or modify this virtual object should be synchronized on _reduced.
|
AbstractDJDocument | protected AbstractDJDocument()(Code) | | Standard default constructor; required because a unary constructor is defined.
|
AbstractDJDocument | protected AbstractDJDocument(Indenter indent)(Code) | | Constructor used to build a new document with an existing indenter. Only used in tests.
|
_checkCache | protected Object _checkCache(String key)(Code) | | Checks the helper method cache for a stored value. Returns the value if it has been cached, or null
otherwise. Calling convention for keys: methodName:arg1:arg2
Parameters: key - Name of the method and arguments |
_indentLine | public boolean _indentLine(Indenter.IndentReason reason)(Code) | | Indents a line using the Indenter. Public ONLY for testing purposes. Assumes writeLock is already held.
|
_isReversteStartOfComment | protected static boolean _isReversteStartOfComment(String text, int pos)(Code) | | Helper method for findPrevNonWSCharPos. Determines whether the current character is the start of a comment
encountered from the end: '/' or '*' preceded by a '/'.
true if (pos-1,pos) == '/*' or '//' |
_isStartOfComment | protected static boolean _isStartOfComment(String text, int pos)(Code) | | Helper method for getFirstNonWSCharPos Determines whether the current character is the start of a comment:
"/*" or "//"
|
_makeKeywords | protected static HashSet<String> _makeKeywords()(Code) | | Create a set of Java/GJ keywords for special coloring.
the set of keywords |
_makeNormEndings | protected static HashSet<String> _makeNormEndings()(Code) | | Create a set of normal endings, i.e., semi-colons and braces for the purposes of indenting.
the set of normal endings |
_makePrimTypes | protected static HashSet<String> _makePrimTypes()(Code) | | Create a set of Java/GJ primitive types for special coloring.
the set of primitive types |
_removeIndenter | protected void _removeIndenter()(Code) | | |
_storeInCache | protected void _storeInCache(String key, Object result)(Code) | | Stores the given result in the helper method cache. Calling convention for keys: methodName:arg1:arg2
Parameters: key - Name of method and arguments Parameters: result - Result of the method call |
_styleChanged | abstract protected void _styleChanged()(Code) | | 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:
- 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.
- 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.
|
balanceBackward | public int balanceBackward()(Code) | | Forwarding method to find the match for the closing brace immediately to the left, assuming
there is such a brace.
the relative distance backwards to the offset before the matching brace. |
balanceForward | public int balanceForward()(Code) | | Forwarding method to find the match for the open brace immediately to the right, assuming there
is such a brace.
the relative distance forwards to the offset after the matching brace. |
clear | public void clear()(Code) | | |
clearCache | protected void clearCache()(Code) | | Clears the memoizing cache for read operations on the document. This
operation must be done before the document is modified since the contents
of this cache are invalidated by any modification to the document.
|
endCompoundEdit | abstract protected void endCompoundEdit(int i)(Code) | | |
endLastCompoundEdit | abstract protected void endLastCompoundEdit()(Code) | | |
findCharInStmtBeforePos | public boolean findCharInStmtBeforePos(char findChar, int position)(Code) | | This function finds the given character in the same statement as the given position, and before the given
position. It is used by QuestionExistsCharInStmt and QuestionExistsCharInPrevStmt
|
findCharOnLine | public int findCharOnLine(int pos, char findChar)(Code) | | 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 Parameters: findChar - Character to search for true if this node's rule holds. |
findNextEnclosingBrace | public int findNextEnclosingBrace(int pos, char opening, char closing) throws BadLocationException(Code) | | Searching forward, finds the position of the enclosing squiggly brace. NB: ignores comments.
Parameters: pos - Position to start from Parameters: opening - opening brace character Parameters: closing - closing brace character position of enclosing squiggly brace, or ERROR_INDEX if beginning of document is reached. |
findPrevCharPos | public int findPrevCharPos(int pos, char[] whitespace) throws BadLocationException(Code) | | Finds the position of the first non-whitespace, non-comment character before pos.
Skips comments and all whitespace, including newlines.
Parameters: pos - Position to start from Parameters: whitespace - chars considered as white space position of first non-whitespace character before pos OR ERROR_INDEX if no such char |
findPrevDelimiter | public int findPrevDelimiter(int pos, char[] delims) throws BadLocationException(Code) | | Searching backwards, finds the position of the first character that is one of the given delimiters. Does
not look for delimiters inside paren phrases (e.g., skips semicolons used inside for statements.)
NB: ignores comments.
Parameters: pos - Position to start from Parameters: delims - array of characters to search for 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(Code) | | 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 Parameters: delims - array of characters to search for Parameters: skipParenPhrases - whether to look for delimiters inside paren phrases position of first matching delimiter, or ERROR_INDEX if beginning of document is reached. |
findPrevEnclosingBrace | public int findPrevEnclosingBrace(int pos, char opening, char closing) throws BadLocationException(Code) | | Searching backwards, finds the position of the enclosing brace. NB: ignores comments.
Parameters: pos - Position to start from Parameters: opening - opening brace character Parameters: closing - closing brace character position of enclosing squiggly brace, or ERROR_INDEX if beginningof document is reached. |
getBytes | public byte[] getBytes()(Code) | | Returns the byte image (as written to a file) of this document.
|
getCurrentLocation | public int getCurrentLocation()(Code) | | 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 of the current location.
where the cursor is as the number of characters into the document |
getFirstNonWSCharPos | public int getFirstNonWSCharPos(int pos) throws BadLocationException(Code) | | 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 position of first non-whitespace character after pos, or ERROR_INDEX if end of document is reached |
getFirstNonWSCharPos | public int getFirstNonWSCharPos(int pos, boolean acceptComments) throws BadLocationException(Code) | | Similar to the single-argument version, but allows including comments.
Parameters: pos - Position to start from Parameters: acceptComments - if true, find non-whitespace chars in comments 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, boolean acceptComments) throws BadLocationException(Code) | | 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 Parameters: whitespace - array of whitespace chars to ignore Parameters: acceptComments - if true, find non-whitespace chars in comments position of first non-whitespace character after pos, or ERROR_INDEX if end of document is reached |
getHighlightStatus | public Vector<HighlightStatus> getHighlightStatus(int start, int end)(Code) | | Return all highlight status info for text between start and end. This should collapse adjoining blocks
with the same status into one.
|
getIndent | public int getIndent()(Code) | | Get the indent level.
the indent level |
getIndentInformation | public IndentInfo getIndentInformation()(Code) | | Returns the indent information for the current location.
|
getIndentOfCurrStmt | public String getIndentOfCurrStmt(int pos) throws BadLocationException(Code) | | 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 |
getIndentOfCurrStmt | public String getIndentOfCurrStmt(int pos, char[] delims) throws BadLocationException(Code) | | 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 |
getIndentOfCurrStmt | public String getIndentOfCurrStmt(int pos, char[] delims, char[] whitespace) throws BadLocationException(Code) | | Returns the indent level of the start of the statement that the cursor is on.
Parameters: pos - Cursor position Parameters: delims - Delimiter characters denoting end of statement Parameters: whitespace - characters to skip when looking for beginning of next statement |
getIntelligentBeginLinePos | public int getIntelligentBeginLinePos(int currPos) throws BadLocationException(Code) | | 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 |
getLineEndPos | public int getLineEndPos(int pos)(Code) | | 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 position of the end of this line |
getLineFirstCharPos | public int getLineFirstCharPos(int pos) throws BadLocationException(Code) | | 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 position of first non-whitespace character on this line, or the endof the line if no non-whitespace character is found. |
getLineStartPos | public int getLineStartPos(int pos)(Code) | | 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 position of the beginning of this line |
getReduced | public BraceReduction getReduced()(Code) | | This method is used ONLY for testing. This method is UNSAFE in any other context!
The reduced model of this document. |
getWhiteSpace | public int getWhiteSpace()(Code) | | Gets the number of whitespace characters between the current location and the end of
the document or the first non-whitespace character, whichever comes first.
the number of whitespace characters |
indentLines | public void indentLines(int selStart, int selEnd)(Code) | | Default indentation - uses OTHER flag and no progress indicator.
Parameters: selStart - the offset of the initial character of the region to indent Parameters: selEnd - the offset of the last character of the region to indent |
indentLines | public void indentLines(int selStart, int selEnd, Indenter.IndentReason reason, ProgressMonitor pm) throws OperationCanceledException(Code) | | Parameterized indentation for special-case handling. If selStart == selEnd, then the line containing the
_currentLocation is indented. The values of selStart and selEnd are ignored!
Parameters: selStart - the offset of the initial character of the region to indent Parameters: selEnd - the offset of the last character of the region to indent Parameters: reason - a flag from Indenter to indicate the reason for the indent(indent logic may vary slightly based on the trigger action) Parameters: pm - used to display progress, null if no reporting is desired |
insertUpdate | protected void insertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)(Code) | | Updates document structure as a result of text insertion. This happens after the text has actually been inserted.
Here we update the reduced model (using an
AbstractDJDocument.InsertCommand InsertCommand ) and store
information for how to undo/redo the reduced model changes inside the
javax.swing.text.AbstractDocument.DefaultDocumentEvent DefaultDocumentEvent .
See Also: edu.rice.cs.drjava.model.AbstractDJDocument.InsertCommand See Also: javax.swing.text.AbstractDocument.DefaultDocumentEvent See Also: edu.rice.cs.drjava.model.definitions.DefinitionsDocument.CommandUndoableEdit |
makeNewIndenter | abstract protected Indenter makeNewIndenter(int indentLevel)(Code) | | Returns a new indenter. Assumes writeLock is held.
|
move | public void move(int dist)(Code) | | The actual cursor movement logic. Helper for setCurrentLocation(int).
Parameters: dist - the distance from the current location to the new location. |
posInParenPhrase | public boolean posInParenPhrase(int pos)(Code) | | Returns true if the given position is inside a paren phrase.
Parameters: pos - the position we're looking at true if pos is immediately inside parentheses |
posInParenPhrase | public boolean posInParenPhrase()(Code) | | Returns true if the reduced model's current position is inside a paren phrase.
true if pos is immediately inside parentheses |
posNotInBlock | protected boolean posNotInBlock(int pos)(Code) | | Returns true if the given position is not inside a paren/brace/etc phrase. Assumes that read lock is ALREADY HELD.
Parameters: pos - the position we're looking at true if pos is immediately inside a paren/brace/etc |
removeUpdate | protected void removeUpdate(AbstractDocument.DefaultDocumentEvent chng)(Code) | | Updates document structure as a result of text removal. This happens within the swing remove operation before
the text has actually been removed. Here we update the reduced model (using a
AbstractDJDocument.RemoveCommandRemoveCommand ) and store information for how to undo/redo the reduced model changes inside the
javax.swing.text.AbstractDocument.DefaultDocumentEvent DefaultDocumentEvent .
See Also: AbstractDJDocument.RemoveCommand See Also: javax.swing.text.AbstractDocument.DefaultDocumentEvent |
resetReducedModelLocation | public void resetReducedModelLocation()(Code) | | |
setCurrentLocation | public void setCurrentLocation(int loc)(Code) | | Change the current location of the document
Parameters: loc - the new absolute location |
setIndent | public void setIndent(int indent)(Code) | | Set the indent to a particular number of spaces.
Parameters: indent - the size of indent that you want for the document |
setTab | public void setTab(String tab, int pos)(Code) | | Sets text between previous newline and first non-whitespace character of line containing pos to tab.
Parameters: tab - String to be placed between previous newline and firstnon-whitespace character |
startCompoundEdit | abstract protected int startCompoundEdit()(Code) | | |
Methods inherited from edu.rice.cs.util.text.SwingDocument | public void _forceInsertText(int offs, String str, String style)(Code)(Java Doc) public void _insertText(int offs, String str, String style)(Code)(Java Doc) public void _removeText(int offs, int len)(Code)(Java Doc) public void acquireReadLock()(Code)(Java Doc) public void acquireWriteLock()(Code)(Java Doc) public void addColoring(int start, int end, String style)(Code)(Java Doc) public void append(String str, AttributeSet set)(Code)(Java Doc) public void append(String str, String style)(Code)(Java Doc) public void clear()(Code)(Java Doc) public Position createUnwrappedPosition(int offs) throws BadLocationException(Code)(Java Doc) public void forceInsertText(int offs, String str, String style)(Code)(Java Doc) public void forceRemoveText(int offs, int len)(Code)(Java Doc) public String getDefaultStyle()(Code)(Java Doc) public AttributeSet getDocStyle(String name)(Code)(Java Doc) public String getDocText(int offs, int len)(Code)(Java Doc) public DocumentEditCondition getEditCondition()(Code)(Java Doc) public Pageable getPageable()(Code)(Java Doc) public String getText()(Code)(Java Doc) public void insertString(int offs, String str, AttributeSet set) throws BadLocationException(Code)(Java Doc) public void insertText(int offs, String str, String style)(Code)(Java Doc) public void print()(Code)(Java Doc) public void releaseReadLock()(Code)(Java Doc) public void releaseWriteLock()(Code)(Java Doc) public void remove(int offs, int len) throws BadLocationException(Code)(Java Doc) public void removeText(int offs, int len)(Code)(Java Doc) public void setDocStyle(String name, AttributeSet s)(Code)(Java Doc) public void setEditCondition(DocumentEditCondition condition)(Code)(Java Doc)
|
|
|