|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.swing.text.AbstractDocument | +--javax.swing.text.PlainDocument | +--edu.rice.cs.drjava.model.definitions.DefinitionsDocument
The model for the definitions pane.
This implementation of Document
contains a
"reduced model". The reduced model is automatically kept in sync
when this document is updated. Also, that synchronization is maintained
even across undo/redo -- this is done by making the undo/redo commands know
how to restore the reduced model state.
The reduced model is not thread-safe, so it is essential that ONLY this
DefinitionsDocument call methods on it. Any information from the reduced
model should be obtained through helper methods on DefinitionsDocument,
and ALL methods in DefinitionsDocument which reference the reduced model
(via the _reduced field) MUST be synchronized. This prevents any thread
from seeing an inconsistent state in the middle of another thread's changes.
BraceReduction
,
ReducedModelControl
,
ReducedModelComment
,
ReducedModelBrace
, Serialized FormInner Class Summary | |
private class |
DefinitionsDocument.CommandUndoableEdit
|
private class |
DefinitionsDocument.InsertCommand
|
private class |
DefinitionsDocument.RemoveCommand
|
Field Summary | |
private int |
_cachedLineNum
Cached current line number. |
private int |
_cachedLocation
Cached location, aides in determining line number. |
private int |
_cachedNextLineLoc
Cached location of next line. |
private int |
_cachedPrevLineLoc
Cached location of previous line. |
private File |
_classFile
|
private boolean |
_classFileInSync
|
private int |
_currentLocation
The absolute character offset in the document. |
private File |
_file
|
private int |
_indent
The default indent setting. |
private Indenter |
_indenter
|
private static HashSet |
_keywords
A set of Java keywords. |
private boolean |
_modifiedSinceSave
Determines if the document has been modified since the last save. |
private static HashSet |
_normEndings
A set of normal endings for lines. |
private static HashSet |
_primTypes
A set of Java keywords. |
private BraceReduction |
_reduced
The reduced model of the document that handles most of the document logic and keeps track of state. |
private static boolean |
_tabsRemoved
Determines if tabs are removed on open and converted to spaces. |
private long |
_timestamp
|
static int |
DOCSTART
Constant for starting position of document. |
static int |
ERROR_INDEX
Constant used by helper methods to indicate an error |
Fields inherited from class javax.swing.text.PlainDocument |
added, defaultRoot, lineLimitAttribute, removed, tabSizeAttribute |
Fields inherited from class javax.swing.text.AbstractDocument |
AsyncLoadPriority, BAD_LOCATION, BAD_LOCK_STATE, BidiElementName, bidiRoot, ContentElementName, context, currWriter, data, defaultI18NProperty, documentProperties, ElementNameAttribute, I18NProperty, listenerList, numReaders, ParagraphElementName, SectionElementName |
Fields inherited from interface javax.swing.text.Document |
StreamDescriptionProperty, TitleProperty |
Constructor Summary | |
DefinitionsDocument()
Constructor. |
|
DefinitionsDocument(Indenter i)
|
Method Summary | |
private void |
_addCharToReducedModel(char curChar)
Add a character to the underlying reduced model. |
private int |
_findKeywordAtToplevel(String keyword,
String text,
int textOffset)
Finds the first occurrence of the keyword within the text that is not enclosed within a brace or comment |
protected String |
_getPackageQualifier()
Gets an appropriate prefix to fully qualify a class name. |
private int |
_getRelativeLine()
This method returns the relative offset of line number from the previous location in the document. |
private boolean |
_hasOnlySpaces(String text)
Returns whether the given text only has spaces. |
private int |
_highlightKeywords(gj.util.Vector v,
int i)
Separates out keywords from normal text for the given HighlightStatus element. |
private void |
_indentBlock(int start,
int end)
Indents the lines between and including the lines containing points start and end. |
private void |
_indentLine()
Indents a line using the Indenter decision tree. |
private boolean |
_isCommentedOrSpace(int i,
String text)
Determines if the current token is part of a comment or if the i'th character in the given text argument is a space. |
protected boolean |
_isEndOfComment(String text,
int pos)
Helper method for findPrevNonWSCharPos Determines whether the current character is the end of a comment: "*\/" or a hanging "//" |
private boolean |
_isNum(String x)
Checks to see if the current string is a number |
protected boolean |
_isStartOfComment(String text,
int pos)
Helper method for getFirstNonWSCharPos Determines whether the current character is the start of a comment: "/*" or "//" |
private boolean |
_isType(String x)
Checks to see if the current string is a type A type is assumed to be a primitive type OR anything else that begins with a capitalized character |
private static HashSet |
_makeKeywords()
Create a set of Java/GJ keywords for special coloring. |
private static HashSet |
_makeNormEndings()
Create a set of normal endings, i.e., semi-colons and braces for the purposes of indenting. |
private static HashSet |
_makePrimTypes()
Create a set of Java/GJ primitive types for special coloring. |
(package private) String |
_removeTabs(String source)
Given a String, return a new String will all tabs converted to spaces. |
private void |
_styleChanged()
Fire event that styles changed from current location to the end. |
int |
balanceBackward()
Forwarding method to find the match for the closing brace immediately to the left, assuming there is such a brace. |
int |
balanceForward()
Forwarding method to find the match for the open brace immediately to the right, assuming there is such a brace. |
int |
findCharOnLine(int pos,
char findChar)
Determines if the given character exists on the line where the given cursor position is. |
int |
findPrevCharPos(int pos,
char[] whitespace)
Finds the position of the first non-whitespace character before pos. |
int |
findPrevDelimiter(int pos,
char[] delims)
Searching backwards, finds the position of the first character that is one of the given delimiters. |
int |
findPrevDelimiter(int pos,
char[] delims,
boolean skipParenPhrases)
Searching backwards, finds the position of the first character that is one of the given delimiters. |
int |
findPrevNonWSCharPos(int pos)
|
File |
getCachedClassFile()
|
boolean |
getClassFileInSync()
|
int |
getCurrentCol()
Return the current column of the cursor position. |
int |
getCurrentLine()
Return the current line of the cursor position. |
int |
getCurrentLocation()
Get the current location of the cursor in the document. |
String |
getEnclosingTopLevelClassName(int pos)
Returns the name of the class or interface enclosing the caret position at the top level. |
File |
getFile()
Returns the file for this document. |
String |
getFilename()
Returns the name of this file, or "(untitled)" if no file. |
int |
getFirstNonWSCharPos(int pos)
Finds the position of the first non-whitespace character after pos. |
int |
getFirstNonWSCharPos(int pos,
char[] whitespace)
Finds the position of the first non-whitespace character after pos. |
String |
getFirstTopLevelClassName()
Gets the name of the top level class in this source file. |
gj.util.Vector |
getHighlightStatus(int start,
int end)
Return all highlight status info for text between start and end. |
int |
getIndent()
Get the indent level. |
IndentInfo |
getIndentInformation()
|
String |
getIndentOfCurrStmt(int pos)
Returns the indent level of the start of the statement that the cursor is on. |
String |
getIndentOfCurrStmt(int pos,
char[] delims)
Returns the indent level of the start of the statement that the cursor is on. |
int |
getLineEndPos(int pos)
Returns the absolute position of the end of the current line. |
int |
getLineFirstCharPos(int pos)
Returns the absolute position of the first non-whitespace character on the current line. |
int |
getLineStartPos(int pos)
Returns the absolute position of the beginning of the current line. |
String |
getNextTopLevelClassName(int startPos,
int endPos)
|
int |
getOffset(int lineNum)
Returns the offset corresponding to the first character of the given line number, or -1 if the lineNum is not found. |
String |
getPackageName()
Gets the name of the package this source file claims it's in (with the package keyword). |
String |
getQualifiedClassName()
Gets the package and class name of this OpenDefinitionsDocument |
String |
getQualifiedClassName(int pos)
Gets fully qualified class name of the top level class enclosing the given position. |
(package private) BraceReduction |
getReduced()
This method should never be called outside of this class. |
ReducedModelState |
getStateAtCurrent()
|
long |
getTimestamp()
|
int |
getWhiteSpace()
Gets the number of whitespace characters between the current location and the rest of the document or the first non-whitespace character, whichever comes first. |
private int |
getWhiteSpaceBetween(int relStart,
int relEnd)
Starts at start and gets whitespace starting at relStart and either stopping at relEnd or at the first non-white space char. |
void |
gotoLine(int line)
Goes to a particular line in the document. |
void |
indentLines(int selStart,
int selEnd)
|
void |
insertString(int offset,
String str,
AttributeSet a)
Inserts a string of text into the document. |
protected void |
insertUpdate(AbstractDocument.DefaultDocumentEvent chng,
AttributeSet attr)
Updates document structure as a result of text insertion. |
boolean |
isModifiedOnDisk()
Determines if the document has been modified since the last save. |
boolean |
isModifiedSinceSave()
Determines if the document has been modified since the last save. |
boolean |
isUntitled()
Returns whether this document is currently untitled (indicating whether it has a file yet or not). |
void |
move(int dist)
The actual cursor movement logic. |
boolean |
posInParenPhrase(int pos)
Returns true if the given position is inside a paren phrase. |
protected boolean |
posNotInBlock(int pos)
Returns true if the given position is not inside a paren/brace/etc phrase. |
void |
remove(int offset,
int len)
Removes a block of text from the specified location. |
protected void |
removeUpdate(AbstractDocument.DefaultDocumentEvent chng)
Updates document structure as a result of text removal. |
void |
resetModification()
Whenever this document has been saved, this method should be called so that it knows it's no longer in a modified state. |
void |
resetReducedModelLocation()
|
void |
setCachedClassFile(File classFile)
|
void |
setClassFileInSync(boolean inSync)
|
void |
setCurrentLocation(int loc)
Change the current location of the document |
void |
setFile(File file)
|
void |
setIndent(int indent)
Set the indent to a particular number of spaces. |
void |
setModifiedSinceSave()
Originally designed to allow undoManager to set the current document to be modified whenever an undo or redo is performed. |
void |
setTab(String tab,
int pos)
Sets the text between the previous newline and the first non-whitespace character of the line containing pos to tab. |
ReducedModelState |
stateAtRelLocation(int dist)
|
(package private) void |
tab(int tab,
int distToPrevNewline)
The function that handles what happens when a tab key is pressed. |
boolean |
tabsRemoved()
Returns true iff tabs are to removed on text insertion. |
Methods inherited from class javax.swing.text.PlainDocument |
createDefaultRoot, getDefaultRootElement, getParagraphElement, insertComposedTextUpdate |
Methods inherited from class java.lang.Object |
|
Field Detail |
private static HashSet _normEndings
private static HashSet _keywords
private static HashSet _primTypes
private int _indent
private static boolean _tabsRemoved
private boolean _modifiedSinceSave
private int _cachedLocation
private int _cachedLineNum
private int _cachedPrevLineLoc
private int _cachedNextLineLoc
private boolean _classFileInSync
private File _classFile
private BraceReduction _reduced
private int _currentLocation
private File _file
private long _timestamp
private final Indenter _indenter
public static final int DOCSTART
public static final int ERROR_INDEX
Constructor Detail |
public DefinitionsDocument()
public DefinitionsDocument(Indenter i)
Method Detail |
BraceReduction getReduced()
private static HashSet _makeNormEndings()
private static HashSet _makeKeywords()
private static HashSet _makePrimTypes()
public boolean isUntitled()
public File getFile() throws IllegalStateException, FileMovedException
IllegalStateException
- if file has not been setFileMovedException
- if file has been moved or deleted from its previous locationpublic String getFilename()
public void setFile(File file)
public long getTimestamp()
public String getQualifiedClassName() throws ClassNameNotFoundException
public String getQualifiedClassName(int pos) throws ClassNameNotFoundException
protected String _getPackageQualifier()
public void setClassFileInSync(boolean inSync)
public boolean getClassFileInSync()
public void setCachedClassFile(File classFile)
public File getCachedClassFile()
public void insertString(int offset, String str, AttributeSet a) throws BadLocationException
insertUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent, javax.swing.text.AttributeSet)
.insertString
in class AbstractDocument
protected void insertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)
DefinitionsDocument.InsertCommand
)
and store information for how to undo/redo the reduced model changes
inside the DefaultDocumentEvent
.insertUpdate
in class PlainDocument
DefinitionsDocument.InsertCommand
,
DefaultDocumentEvent
,
DefinitionsDocument.CommandUndoableEdit
public void remove(int offset, int len) throws BadLocationException
removeUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent)
.remove
in class AbstractDocument
protected void removeUpdate(AbstractDocument.DefaultDocumentEvent chng)
DefinitionsDocument.RemoveCommand
)
and store information for how to undo/redo the reduced model changes
inside the DefaultDocumentEvent
.removeUpdate
in class PlainDocument
DefinitionsDocument.RemoveCommand
,
DefaultDocumentEvent
,
DefinitionsDocument.CommandUndoableEdit
String _removeTabs(String source)
source
- the String to be converted.private void _addCharToReducedModel(char curChar)
curChar
- the character to be added.private void _styleChanged()
public void setModifiedSinceSave()
public void resetModification()
public boolean isModifiedSinceSave()
public boolean isModifiedOnDisk()
public int getCurrentLocation()
public void setCurrentLocation(int loc)
loc
- the new absolute locationpublic void move(int dist)
dist
- the distance from the current location to the new location.public int getCurrentCol()
public int getCurrentLine()
private int _getRelativeLine()
public int getIndent()
public void setIndent(int indent)
indent
- the size of indent that you want for the documentpublic int findPrevDelimiter(int pos, char[] delims) throws BadLocationException
pos
- Position to start fromdelims
- array of characters to search forpublic int findPrevDelimiter(int pos, char[] delims, boolean skipParenPhrases) throws BadLocationException
pos
- Position to start fromdelims
- array of characters to search forskipParenPhrases
- whether to look for delimiters inside paren phrases
(eg. semicolons in a for statement)public boolean posInParenPhrase(int pos)
pos
- the position we're looking atprotected boolean posNotInBlock(int pos)
pos
- the position we're looking atpublic String getIndentOfCurrStmt(int pos) throws BadLocationException
pos
- Cursor positionpublic String getIndentOfCurrStmt(int pos, char[] delims) throws BadLocationException
pos
- Cursor positiondelims
- Delimiter characters denoting end of statementpublic int findCharOnLine(int pos, char findChar)
Does not work if character being searched for is a '/' or a '*'
pos
- Cursor positionfindChar
- Character to search forpublic int getLineStartPos(int pos)
pos
- Any position on the current linepublic int getLineEndPos(int pos)
pos
- Any position on the current linepublic int getLineFirstCharPos(int pos) throws BadLocationException
pos
- position on the linepublic int getFirstNonWSCharPos(int pos) throws BadLocationException
pos
- Position to start frompublic int getFirstNonWSCharPos(int pos, char[] whitespace) throws BadLocationException
pos
- Position to start fromwhitespace
- array of whitespace chars to ignorepublic int findPrevNonWSCharPos(int pos) throws BadLocationException
public int getOffset(int lineNum)
lineNum
- the line number for which to calculate the offset.public int findPrevCharPos(int pos, char[] whitespace) throws BadLocationException
pos
- Position to start fromwhitespace
- chars considered as white spaceprotected boolean _isStartOfComment(String text, int pos)
protected boolean _isEndOfComment(String text, int pos)
public boolean tabsRemoved()
public int balanceBackward()
public int balanceForward()
public void indentLines(int selStart, int selEnd)
private void _indentBlock(int start, int end)
start
- Position in document to start indenting fromend
- Position in document to end indenting atprivate void _indentLine()
private boolean _isCommentedOrSpace(int i, String text)
i
- the index to look at for the space in texttext
- a block of textpublic int getWhiteSpace()
private int getWhiteSpaceBetween(int relStart, int relEnd) throws BadLocationException
BadLocationException
- void tab(int tab, int distToPrevNewline) throws BadLocationException
tab
- number of indents, i.e., level of nestingdistToPrevNewline
- distance to end of previous lineBadLocationException
- public void setTab(String tab, int pos)
tab
- String to be placed between previous newline and first
non-whitespace characterprivate boolean _hasOnlySpaces(String text)
public gj.util.Vector getHighlightStatus(int start, int end)
private int _highlightKeywords(gj.util.Vector v, int i)
v
- Vector with highlight infoi
- Index of the single HighlightStatus to check for keywords inprivate boolean _isNum(String x)
private boolean _isType(String x)
public void gotoLine(int line)
public String getPackageName() throws InvalidPackageException
InvalidPackageException
- if there is some sort of a
package statement but it
is invalid.public IndentInfo getIndentInformation()
public ReducedModelState stateAtRelLocation(int dist)
public ReducedModelState getStateAtCurrent()
public void resetReducedModelLocation()
public String getEnclosingTopLevelClassName(int pos) throws ClassNameNotFoundException
ClassNameNotFoundException
- if no enclosing class foundpublic String getFirstTopLevelClassName() throws ClassNameNotFoundException
ClassNameNotFoundException
- if no top level class foundpublic String getNextTopLevelClassName(int startPos, int endPos) throws ClassNameNotFoundException
private int _findKeywordAtToplevel(String keyword, String text, int textOffset)
keyword
- the keyword for which to searchtext
- in which to searchtextOffset
- Offset at which the text occurs in the document
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |