|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rice.cs.drjava.model.FindReplaceMachine
public class FindReplaceMachine
Implementation of logic of find/replace over a document.
| Field Summary | |
|---|---|
private int |
_current
|
private OpenDefinitionsDocument |
_doc
|
private DocumentIterator |
_docIterator
|
private String |
_findWord
|
private OpenDefinitionsDocument |
_firstDoc
|
private Component |
_frame
|
private boolean |
_ignoreCommentsAndStrings
|
private boolean |
_ignoreTestCases
|
private boolean |
_isForward
|
private String |
_lastFindWord
|
private static Log |
_log
|
private boolean |
_matchCase
|
private boolean |
_matchWholeWord
|
private SingleDisplayModel |
_model
|
private String |
_replaceWord
|
private boolean |
_searchAllDocuments
|
private boolean |
_searchSelectionOnly
|
private MovingDocumentRegion |
_selectionRegion
|
private boolean |
_skipText
|
| Constructor Summary | |
|---|---|
FindReplaceMachine(SingleDisplayModel model,
DocumentIterator docIterator,
Component frame)
Standard Constructor. |
|
| Method Summary | |
|---|---|
private FindResult |
_findNextInDoc(OpenDefinitionsDocument doc,
int start,
int len,
boolean searchAll)
Finds next match in specified doc only. |
private FindResult |
_findNextInDocSegment(OpenDefinitionsDocument doc,
int start,
int len)
Find first valid match withing specified segment of doc. |
private FindResult |
_findNextInDocSegment(OpenDefinitionsDocument doc,
int start,
int len,
boolean wrapped,
boolean allWrapped)
Main helper method for findNext... |
private FindResult |
_findNextInOtherDocs(OpenDefinitionsDocument startDoc,
int start,
int len)
Searches all documents following startDoc for _findWord, cycling through the documents in the direction specified by _isForward. |
private FindResult |
_findWrapped(OpenDefinitionsDocument doc,
int start,
int len,
boolean allWrapped)
Helper method for findNext that looks for a match after searching has wrapped off the "end" (start if searching backward) of the document. |
private int |
_processAllInCurrentDoc(Runnable1<FindResult> findAction,
boolean searchSelectionOnly)
Processes all occurences of _findWord in _doc. |
private int |
_replaceAllInCurrentDoc(boolean searchSelectionOnly)
Replaces all occurences of _findWord with _replaceWord in _doc. |
private boolean |
_shouldIgnore(int foundOffset,
OpenDefinitionsDocument odd)
Returns true if the currently found instance should be ignored (either because it is inside a string or comment or because it does not match the whole word when either or both of those conditions are set to true). |
void |
cleanUp()
|
FindResult |
findNext()
|
private FindResult |
findNext(boolean searchAll)
Finds the next occurrence of the find word and returns an offset at the end of that occurrence or -1 if the word was not found. |
int |
getCurrentOffset()
Gets the character offset to which this machine is currently pointing. |
OpenDefinitionsDocument |
getDocument()
|
String |
getFindWord()
|
OpenDefinitionsDocument |
getFirstDoc()
|
boolean |
getIgnoreCommentsAndStrings()
|
boolean |
getIgnoreTestCases()
|
boolean |
getMatchCase()
|
boolean |
getMatchWholeWord()
|
String |
getReplaceWord()
|
boolean |
getSearchAllDocuments()
|
boolean |
getSearchSelectionOnly()
|
private boolean |
isDelimiter(char ch)
Determines whether a character is a delimiter (not a letter or digit) as a helper to wholeWordFoundAtCurrent |
boolean |
isSearchBackwards()
|
boolean |
onMatch()
Determine if the machine is on an instance of the find word. |
void |
positionChanged()
Called when the current position is updated in the document implying _skipText should not be set if the user toggles _searchBackwards |
private int |
processAll(Runnable1<FindResult> findAction,
boolean searchAll,
boolean searchSelectionOnly)
Processes all occurences of the find word with the replace word in the current document or in all documents depending the value of the flag searchAll. |
int |
processAll(Runnable1<FindResult> findAction,
MovingDocumentRegion region)
Processes all occurences of the find word with the replace word in the current document or in all documents depending the value of the machine register _searchAllDocuments. |
int |
replaceAll()
Replaces all occurrences of the find word with the replace word in the current document of in all documents depending the value of the machine register _searchAllDocuments. |
private int |
replaceAll(boolean searchAll,
boolean searchSelectionOnly)
Replaces all occurences of the find word with the replace word in the current document of in all documents or in the current selection of the current document depending the value of the flag searchAll |
boolean |
replaceCurrent()
If we're on a match for the find word, replace it with the replace word. |
void |
setDocument(OpenDefinitionsDocument doc)
|
void |
setFindAnyOccurrence()
|
void |
setFindWord(String word)
Change the word being sought. |
void |
setFirstDoc(OpenDefinitionsDocument firstDoc)
|
void |
setIgnoreCommentsAndStrings(boolean ignoreCommentsAndStrings)
|
void |
setIgnoreTestCases(boolean ignoreTestCases)
|
void |
setLastFindWord()
|
void |
setMatchCase(boolean matchCase)
|
void |
setMatchWholeWord()
|
void |
setPosition(int pos)
|
void |
setReplaceWord(String word)
Change the replacing word. |
void |
setSearchAllDocuments(boolean searchAllDocuments)
|
void |
setSearchBackwards(boolean searchBackwards)
|
void |
setSearchSelectionOnly(boolean searchSelectionOnly)
|
void |
setSelection(MovingDocumentRegion s)
Set the selected text region. |
private boolean |
wholeWordFoundAtCurrent(OpenDefinitionsDocument doc,
int foundOffset)
Determines whether the whole find word is found at the input position. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static Log _log
private OpenDefinitionsDocument _doc
private OpenDefinitionsDocument _firstDoc
private int _current
private MovingDocumentRegion _selectionRegion
private String _findWord
private String _replaceWord
private boolean _matchCase
private boolean _matchWholeWord
private boolean _searchAllDocuments
private boolean _searchSelectionOnly
private boolean _isForward
private boolean _ignoreCommentsAndStrings
private boolean _ignoreTestCases
private String _lastFindWord
private boolean _skipText
private DocumentIterator _docIterator
private SingleDisplayModel _model
private Component _frame
| Constructor Detail |
|---|
public FindReplaceMachine(SingleDisplayModel model,
DocumentIterator docIterator,
Component frame)
docIterator - an object that allows navigation through open Swing documents (it is DefaultGlobalModel)| Method Detail |
|---|
public void cleanUp()
public void positionChanged()
public void setLastFindWord()
public boolean isSearchBackwards()
public void setSearchBackwards(boolean searchBackwards)
public void setMatchCase(boolean matchCase)
public boolean getMatchCase()
public void setMatchWholeWord()
public boolean getMatchWholeWord()
public void setFindAnyOccurrence()
public void setSearchAllDocuments(boolean searchAllDocuments)
public void setSearchSelectionOnly(boolean searchSelectionOnly)
public void setIgnoreCommentsAndStrings(boolean ignoreCommentsAndStrings)
public boolean getIgnoreCommentsAndStrings()
public void setIgnoreTestCases(boolean ignoreTestCases)
public boolean getIgnoreTestCases()
public void setDocument(OpenDefinitionsDocument doc)
public void setFirstDoc(OpenDefinitionsDocument firstDoc)
public void setPosition(int pos)
public int getCurrentOffset()
public String getFindWord()
public String getReplaceWord()
public boolean getSearchAllDocuments()
public boolean getSearchSelectionOnly()
public OpenDefinitionsDocument getDocument()
public OpenDefinitionsDocument getFirstDoc()
public void setFindWord(String word)
word - the new word to seekpublic void setReplaceWord(String word)
word - the new replacing wordpublic boolean onMatch()
public boolean replaceCurrent()
public void setSelection(MovingDocumentRegion s)
s - selected regionpublic int replaceAll()
private int replaceAll(boolean searchAll,
boolean searchSelectionOnly)
private int _replaceAllInCurrentDoc(boolean searchSelectionOnly)
findString: "hello"
replaceString: "e"
document text: "hhellollo"
Depending on the cursor position, clicking replace all could either make the document text read "hello" (which is correct) or "e". This is because of the behavior of findNext(), and it would be incorrect to change that behavior. Only executes in event thread.
public int processAll(Runnable1<FindResult> findAction,
MovingDocumentRegion region)
findAction - action to perform on the occurrences; input is the FindResult, output is ignored
private int processAll(Runnable1<FindResult> findAction,
boolean searchAll,
boolean searchSelectionOnly)
findAction - action to perform on the occurrences; input is the FindResult, output is ignored
private int _processAllInCurrentDoc(Runnable1<FindResult> findAction,
boolean searchSelectionOnly)
findString: "hello"
replaceString: "e"
document text: "hhellollo"
Assumes this has mutually exclusive access to _doc (e.g., by hourglassOn) and findAction does not modify _doc. Only executes in event thread.
findAction - action to perform on the occurrences; input is the FindResult, output is ignored
public FindResult findNext()
private FindResult findNext(boolean searchAll)
searchAll - whether to search all documents (or just _doc)
private FindResult _findNextInDoc(OpenDefinitionsDocument doc,
int start,
int len,
boolean searchAll)
private FindResult _findWrapped(OpenDefinitionsDocument doc,
int start,
int len,
boolean allWrapped)
doc - the document in which search wrappedstart - the location of preceding text segment where search FAILED.len - the length of text segment previously searchedallWrapped - whether this wrapped search is being performed after an all document search has wrapped
private FindResult _findNextInDocSegment(OpenDefinitionsDocument doc,
int start,
int len)
private FindResult _findNextInDocSegment(OpenDefinitionsDocument doc,
int start,
int len,
boolean wrapped,
boolean allWrapped)
doc - document to be searchedstart - the location (offset/left edge) of the text segment to be searchedlen - the requested length of the text segment to be searchedwrapped - whether this search is after wrapping around the documentallWrapped - whether this seach is after wrapping around all documents
private FindResult _findNextInOtherDocs(OpenDefinitionsDocument startDoc,
int start,
int len)
startDoc - document where searching started and just failedstart - location in startDoc of the document segment where search failed.len - length of the text segment where search failed.
private boolean wholeWordFoundAtCurrent(OpenDefinitionsDocument doc,
int foundOffset)
doc - - the document where an instance of the find word was foundfoundOffset - - the position where that instance was found
private boolean isDelimiter(char ch)
ch - - a character
private boolean _shouldIgnore(int foundOffset,
OpenDefinitionsDocument odd)
foundOffset - the location of the instance foundodd - the current document where the instance was found
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||