|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.text.AbstractDocument
javax.swing.text.DefaultStyledDocument
edu.rice.cs.util.text.SwingDocument
edu.rice.cs.drjava.model.AbstractDJDocument
public abstract class AbstractDJDocument
This class contains code supporting the concept of a "DJDocument"; it is shared between DefinitionsDocument and
InteractionsDJDocument. This partial 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 its methods are only called from the event thread. In
addition, any information from the reduced model should be obtained through helper methods in this class/subclasses.
BraceReduction
,
ReducedModelControl
,
ReducedModelComment
,
ReducedModelBrace
,
Serialized FormNested Class Summary | |
---|---|
protected class |
AbstractDJDocument.CharInsertCommand
|
protected class |
AbstractDJDocument.InsertCommand
|
protected class |
AbstractDJDocument.RemoveCommand
|
protected class |
AbstractDJDocument.UninsertCommand
|
protected class |
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 | |
---|---|
protected int |
_currentLocation
The absolute character offset in the document. |
protected int |
_indent
The default indent setting. |
protected static HashSet<String> |
_keywords
A set of Java keywords. |
protected static HashSet<String> |
_normEndings
A set of normal endings for lines. |
protected static HashSet<String> |
_primTypes
A set of Java keywords. |
ReducedModelControl |
_reduced
The reduced model of the document (stored in field _reduced) handles most of the document logic and keeps track of state. |
static char[] |
CLOSING_BRACES
The set of closing braces recognized in most indenting operations. |
protected static String |
delimiters
|
protected static char |
newline
|
static int |
POS_THRESHOLD
Constant specifying how large pos must be before incremental analysis is applied in posInBlockComment |
Fields inherited from class edu.rice.cs.util.text.SwingDocument |
---|
_condition, _isModifiedSinceSave, _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 |
Constructor Summary | |
---|---|
protected |
AbstractDJDocument()
Constructor used in super calls from DefinitionsDocument and InteractionsDJDocument. |
protected |
AbstractDJDocument(Indenter indenter)
Constructor used to build a new document with an existing indenter. |
protected |
AbstractDJDocument(int indentLevel)
Constructor used from anonymous test classes. |
Method Summary | |
---|---|
protected Object |
_checkCache(Query key)
Checks the query cache for a stored value. |
protected void |
_clearCache(int offset)
Clears the memozing cache of queries with offset >= than specified value. |
int |
_findPrevCharPos(int pos,
char[] whitespace)
Finds the position of the first non-whitespace, non-comment character before pos. |
int |
_findPrevNonWSCharPos(int pos)
|
BraceInfo |
_getEnclosingBrace()
Cached version of _reduced.getEnclosingBrace(). |
int |
_getIndentOfCurrStmt(int pos)
Returns the number of blanks in the indent prefix for the start of the statement identified by pos. |
int |
_getIndentOfCurrStmt(int pos,
char[] delims)
Returns the number of blanks in the indent prefix of the start of the statement identified by pos. |
int |
_getIndentOfCurrStmt(int pos,
char[] delims,
char[] whitespace)
Returns the number of blanks in the indent prefix of the start of the statement identified by pos, assuming that the statement is already properly indented |
BraceInfo |
_getLineEnclosingBrace()
Cached version of _reduced.getLineEnclosingBrace(). |
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-blank/tab character on the current line including comment text or the end of the line if no non-blank/tab character is found. |
int |
_getLineStartPos(int pos)
Returns the absolute position of the beginning of the current line. |
boolean |
_inBlockComment(int pos)
Determines if pos lies within a block comment using the reduced model (ignoring the cache). |
boolean |
_indentLine(Indenter.IndentReason reason)
Indents a line using the Indenter. |
boolean |
_inParenPhrase(int pos)
Returns true if the given position is inside a paren phrase. |
protected static boolean |
_isStartOfComment(String text,
int pos)
Helper method for getFirstNonWSCharPos Determines whether the current character is the start of a comment: "/*" or "//" |
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(Query query,
Object answer,
int offset)
Stores the given result in the helper method cache. |
protected abstract void |
_styleChanged()
Fire event that styles changed from current location to the end. |
protected abstract void |
addUndoRedo(AbstractDocument.DefaultDocumentEvent chng,
Runnable undoCommand,
Runnable doCommand)
|
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. |
protected abstract void |
endCompoundEdit(int i)
|
protected abstract void |
endLastCompoundEdit()
|
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. |
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 forward, finds the position of the enclosing brace, which may be a pointy bracket. |
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 skipBracePhrases)
Searching backwards, finds position of first character that is a given delimiter, skipping over balanced braces if so instructed. |
int |
findPrevEnclosingBrace(int pos,
char opening,
char closing)
Searching backwards, finds the position of the enclosing brace of specified type. |
int |
getAndResetNumLinesChangedAfter()
Gets the value of _numLinesChangedAfter field and reset it -1. |
byte[] |
getBytes()
Returns the byte image (as written to a file) of this document. |
int |
getCurrentLocation()
Get the current location of the cursor in 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)
Return all highlight status info for text between start and end. |
int |
getIndent()
Get the indent level. |
int |
getIntelligentBeginLinePos(int currPos)
Returns the "intelligent" beginning of line. |
ReducedModelControl |
getReduced()
This method is used ONLY inside of document Read Lock. |
ReducedModelState |
getStateAtCurrent()
Assumes that read lock and reduced lock are already held. |
static boolean |
hasOnlySpaces(String text)
Returns whether the given text only has spaces. |
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. |
protected void |
insertUpdate(AbstractDocument.DefaultDocumentEvent chng,
AttributeSet attr)
Updates document structure as a result of text insertion. |
boolean |
isShadowed()
|
boolean |
isShadowed(int pos)
|
void |
move(int dist)
Moves _currentLocation the specified distance. |
protected boolean |
notInBlock(int pos)
Returns true if the given position is not inside a paren/brace/etc phrase. |
protected void |
removeUpdate(AbstractDocument.DefaultDocumentEvent chng)
Updates document structure as a result of text removal. |
void |
resetReducedModelLocation()
Assumes that read lock and reduced lock are already held. |
void |
setCurrentLocation(int loc)
Change the current location of the document. |
void |
setIndent(int indent)
Set the indent to a particular number of spaces. |
void |
setTab(int tab,
int pos)
Inserts the number of blanks specified as the whitespace prefix for the line identified by pos. |
void |
setTab(String tab,
int pos)
Inserts the string specified by tab at the beginning of the line identified by pos. |
protected abstract int |
startCompoundEdit()
|
ReducedModelState |
stateAtRelLocation(int dist)
Assumes that read lock and reduced lock are already held. |
Methods inherited from class edu.rice.cs.util.text.SwingDocument |
---|
_getText, addColoring, append, append, append, createUnwrappedPosition, forceInsertText, forceRemoveText, getDefaultStyle, getDocStyle, getDocText, getEditCondition, getPageable, getText, insertString, insertText, print, remove, 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 java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface edu.rice.cs.drjava.model.DJDocument |
---|
getText, insertString, remove |
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 |
Methods inherited from interface edu.rice.cs.util.text.EditDocumentInterface |
---|
getLength |
Field Detail |
---|
protected static final String delimiters
protected static final char newline
protected static final HashSet<String> _normEndings
protected static final HashSet<String> _keywords
protected static final HashSet<String> _primTypes
protected volatile int _indent
public static final int POS_THRESHOLD
public static final char[] CLOSING_BRACES
public final ReducedModelControl _reduced
protected volatile int _currentLocation
Constructor Detail |
---|
protected AbstractDJDocument()
protected AbstractDJDocument(int indentLevel)
protected AbstractDJDocument(Indenter indenter)
Method Detail |
---|
public int getIndent()
getIndent
in interface DJDocument
public void setIndent(int indent)
setIndent
in interface DJDocument
indent
- the size of indent that you want for the documentprotected void _removeIndenter()
protected static HashSet<String> _makeNormEndings()
protected static HashSet<String> _makeKeywords()
protected static HashSet<String> _makePrimTypes()
public ArrayList<HighlightStatus> getHighlightStatus(int start, int end)
getHighlightStatus
in interface DJDocument
public static boolean hasOnlySpaces(String text)
protected abstract void _styleChanged()
public int getCurrentLocation()
getCurrentLocation
in interface DJDocument
public void setCurrentLocation(int loc)
setCurrentLocation
in interface DJDocument
loc
- the new absolute locationpublic void move(int dist)
move
in interface DJDocument
dist
- the distance from the current location to the new location.public int balanceBackward()
balanceBackward
in interface DJDocument
public int balanceForward()
balanceForward
in interface DJDocument
public ReducedModelControl getReduced()
getReduced
in interface DJDocument
public ReducedModelState stateAtRelLocation(int dist)
public ReducedModelState getStateAtCurrent()
getStateAtCurrent
in interface DJDocument
public void resetReducedModelLocation()
public int findPrevEnclosingBrace(int pos, char opening, char closing) throws BadLocationException
findPrevEnclosingBrace
in interface DJDocument
pos
- Position to start fromopening
- opening brace characterclosing
- closing brace character
BadLocationException
public boolean isShadowed()
public boolean isShadowed(int pos)
public int findNextEnclosingBrace(int pos, char opening, char closing) throws BadLocationException
findNextEnclosingBrace
in interface DJDocument
pos
- Position to start fromopening
- opening brace characterclosing
- closing brace character
BadLocationException
public int findPrevDelimiter(int pos, char[] delims) throws BadLocationException
findPrevDelimiter
in interface DJDocument
pos
- Position to start fromdelims
- array of characters to search for
BadLocationException
public int findPrevDelimiter(int pos, char[] delims, boolean skipBracePhrases) throws BadLocationException
findPrevDelimiter
in interface DJDocument
pos
- Position to start fromdelims
- array of characters to search forskipBracePhrases
- whether to look for delimiters inside brace phrases
BadLocationException
public boolean findCharInStmtBeforePos(char findChar, int position)
public int _findPrevCharPos(int pos, char[] whitespace) throws BadLocationException
pos
- Position to start fromwhitespace
- chars considered as white space
BadLocationException
protected Object _checkCache(Query key)
key
- Name of the method and argumentsprotected void _storeInCache(Query query, Object answer, int offset)
query
- A canonical description of the queryanswer
- The answer returned for the queryoffset
- The offset bounding the right edge of the text on which the query depends; if (0:offset) in
the document is unchanged, the query should return the same answer.protected void _clearCache(int offset)
public void indentLines(int selStart, int selEnd)
indentLines
in interface DJDocument
selStart
- the offset of the initial character of the region to indentselEnd
- the offset of the last character of the region to indentpublic void indentLines(int selStart, int selEnd, Indenter.IndentReason reason, ProgressMonitor pm) throws OperationCanceledException
indentLines
in interface DJDocument
selStart
- the offset of the initial character of the region to indentselEnd
- the offset of the last character of the region to indentreason
- 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
OperationCanceledException
public boolean _indentLine(Indenter.IndentReason reason)
public int getIntelligentBeginLinePos(int currPos) throws BadLocationException
getIntelligentBeginLinePos
in interface DJDocument
currPos
- A position on the current line
BadLocationException
public int _getIndentOfCurrStmt(int pos)
_getIndentOfCurrStmt
in interface DJDocument
pos
- Cursor positionpublic int _getIndentOfCurrStmt(int pos, char[] delims)
_getIndentOfCurrStmt
in interface DJDocument
pos
- Cursor positionpublic int _getIndentOfCurrStmt(int pos, char[] delims, char[] whitespace)
_getIndentOfCurrStmt
in interface DJDocument
pos
- the position identifying the current statementdelims
- delimiter characters denoting end of statementwhitespace
- characters to skip when looking for beginning of next statementpublic int findCharOnLine(int pos, char findChar)
findCharOnLine
in interface DJDocument
pos
- Cursor positionfindChar
- Character to search for
public int _getLineStartPos(int pos)
_getLineStartPos
in interface DJDocument
pos
- Any position on the current line
public int _getLineEndPos(int pos)
_getLineEndPos
in interface DJDocument
pos
- Any position on the current line
public int _getLineFirstCharPos(int pos)
_getLineFirstCharPos
in interface DJDocument
pos
- position on the line
public int getFirstNonWSCharPos(int pos) throws BadLocationException
getFirstNonWSCharPos
in interface DJDocument
pos
- Position to start from
BadLocationException
public int getFirstNonWSCharPos(int pos, boolean acceptComments) throws BadLocationException
getFirstNonWSCharPos
in interface DJDocument
pos
- Position to start fromacceptComments
- if true, find non-whitespace chars in comments
BadLocationException
public int getFirstNonWSCharPos(int pos, char[] whitespace, boolean acceptComments) throws BadLocationException
getFirstNonWSCharPos
in interface DJDocument
pos
- Position to start fromwhitespace
- array of whitespace chars to ignoreacceptComments
- if true, find non-whitespace chars in comments
BadLocationException
public int _findPrevNonWSCharPos(int pos) throws BadLocationException
BadLocationException
protected static boolean _isStartOfComment(String text, int pos)
public boolean _inParenPhrase(int pos)
pos
- the position we're looking at
public BraceInfo _getLineEnclosingBrace()
public BraceInfo _getEnclosingBrace()
public boolean _inBlockComment(int pos)
protected boolean notInBlock(int pos)
pos
- the position we're looking at
public void setTab(int tab, int pos)
tab
- The string to be placed between previous newline and first non-whitespace characterpublic void setTab(String tab, int pos)
tab
- The string to be placed between previous newline and first non-whitespace characterprotected void insertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)
InsertCommand
) and store
information for how to undo/redo the reduced model changes inside the DefaultDocumentEvent
.
NOTE: an exclusive read lock on the document is already held when this code runs.
insertUpdate
in class DefaultStyledDocument
AbstractDJDocument.InsertCommand
,
AbstractDocument.DefaultDocumentEvent
,
DefinitionsDocument.CommandUndoableEdit
protected void removeUpdate(AbstractDocument.DefaultDocumentEvent chng)
RemoveCommand
) and store information for how to undo/redo the reduced model changes inside the
DefaultDocumentEvent
.
NOTE: an exclusive read lock on the document is already held when this code runs.
removeUpdate
in class DefaultStyledDocument
AbstractDJDocument.RemoveCommand
,
AbstractDocument.DefaultDocumentEvent
public byte[] getBytes()
public void clear()
DJDocument
clear
in interface DJDocument
clear
in class SwingDocument
protected abstract int startCompoundEdit()
protected abstract void endCompoundEdit(int i)
protected abstract void endLastCompoundEdit()
protected abstract void addUndoRedo(AbstractDocument.DefaultDocumentEvent chng, Runnable undoCommand, Runnable doCommand)
public int getAndResetNumLinesChangedAfter()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |