Skip to content

Commit f1caed5

Browse files
committed
This revision consists of a tiny semantic change in
FindReplaceMachine.java (forcing _searchSelectionOnly to be false when searching all documents) and many minor changes in formatting and documentation. The following files were modified: modified: drjava/README modified: drjava/build.xml modified: drjava/lib/plt.jar modified: drjava/src/edu/rice/cs/drjava/model/FindReplaceMachine.java modified: drjava/src/edu/rice/cs/drjava/ui/FindReplacePanel.java modified: drjava/src/edu/rice/cs/util/IterableOps.java
1 parent b8a88c3 commit f1caed5

File tree

6 files changed

+88
-56
lines changed

6 files changed

+88
-56
lines changed

drjava/README

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,29 @@ The following guide presumes that you already have the following
1818
software systems installed on your system and accessible via your
1919
shell search path:
2020

21-
* Java 5.0 or 6.0 SDK,
22-
* subversion (svn) 1.4 or above, and
23-
* ant 1.7 or above.
21+
* Java 8.0 SDK,
22+
* ant 1.7 or above, and
23+
* Git (git) 2.7.4 or above.
2424

2525
If not, follow the instructions at http://www.drjava.org/devdocs/ for
2626
setting up a DrJava development environment.
2727

2828
1) Make a directory to be the top-level container for you drjava code
29-
tree. I recommend "dj".
29+
tree. I recommend "dj" or "drjava-top.
3030

3131
2) Descend into this new directory by typing the command
3232

3333
cd ~/dj
3434

3535
3) Download the drjava source code base by typing the command
3636

37-
svn co https://drjava.svn.sourceforge.net/svnroot/drjava/trunk/drjava
37+
git clone https://github.com/DrJavaAtRice/drjava.git
38+
39+
You can grab the URL (beginning with "https") at
40+
41+
https://github.com/DrJavaAtRice/drjava
42+
43+
and clicking on the green button labeled "Clone or download".
3844

3945
4) After this download completes, descend into the root directory of
4046
the dowloaded code base by typing the command
@@ -55,3 +61,12 @@ entering the command
5561

5662
If you encounter any problems, consult the Developer Docs at
5763
drjava.org by visiting http://www.drjava.org/devdocs/.
64+
65+
You can run the unit tests by entering the command
66+
67+
ant test
68+
69+
To delete all compiled and unjarred class files (from jar files in
70+
drjava/lib and drjava/lib/buildlib), enter the command
71+
72+
ant clean

drjava/build.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,8 @@
553553
</target>
554554

555555
<target name="do-run-jar" depends="resolve-jvm-args">
556-
<echo message="Running ${version-tag}.jar with command '${run-jvm}'" />
557-
<java jar="${version-tag}.jar" jvm="${run-jvm}" fork="yes" spawn="yes">
556+
<echo message="Running ${ant.project.name}.jar with command '${run-jvm}'" />
557+
<java jar="${ant.project.name}.jar" jvm="${run-jvm}" fork="yes" spawn="yes">
558558
<assertions>
559559
<enable />
560560
</assertions>
@@ -577,7 +577,7 @@
577577
<available property="junit-jar-to-include-exists" file="${junit-jar-to-include}" />
578578
<fail message="Can't find ${junit-jar-to-include}"
579579
unless="junit-jar-to-include-exists" />
580-
<jar jarfile="${version-tag}.jar">
580+
<jar jarfile="${ant.project.name}.jar">
581581
<manifest>
582582
<attribute name="Main-Class" value="${main-class}" />
583583
<attribute name="Built-By" value="${user.name}" />

drjava/lib/plt.jar

1 Byte
Binary file not shown.

drjava/src/edu/rice/cs/drjava/model/FindReplaceMachine.java

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
*/
5555
public class FindReplaceMachine {
5656

57-
static private Log _log = new Log("FindReplace.txt", false);
57+
static private final Log _log = new Log("FindReplace.txt", false);
5858

5959
/* Visible machine state; manipulated directly or indirectly by FindReplacePanel. */
6060
private volatile OpenDefinitionsDocument _doc; // Current search document
@@ -90,6 +90,8 @@ public FindReplaceMachine(SingleDisplayModel model, DocumentIterator docIterator
9090
_frame = frame;
9191
_docIterator = docIterator;
9292
_current = -1;
93+
/* Using setters for internal initilization is VERY BAD taste; it obscures the initial state. What
94+
* is the invariant for instances of this class? Who knows? */
9395
setFindAnyOccurrence();
9496
setFindWord("");
9597
setReplaceWord("");
@@ -258,7 +260,8 @@ public boolean replaceCurrent() {
258260
*/
259261
public void setSelection(MovingDocumentRegion s) { _selectionRegion = s; }
260262

261-
/** Alternative interface for the private method replaceAll(...) */
263+
/** Alternative interface for the private method replaceAll(...)
264+
* @return the number of replacements */
262265
public int replaceAll() { return replaceAll(_searchAllDocuments, _searchSelectionOnly); }
263266

264267
/** Replaces all occurences of the find word with the replace word
@@ -313,11 +316,12 @@ private int _replaceAllInCurrentDoc(boolean searchSelectionOnly) {
313316

314317
assert EventQueue.isDispatchThread();
315318

316-
if (!searchSelectionOnly) {
319+
if (! searchSelectionOnly) {
317320
_selectionRegion = new MovingDocumentRegion(_doc, 0, _doc.getLength(),
318321
_doc._getLineStartPos(0),
319322
_doc._getLineEndPos(_doc.getLength()));
320323
}
324+
/* _selectionRegion is not degenerate unless document is degenerate; may be entire document. */
321325
if (_isForward) setPosition(_selectionRegion.getStartOffset());
322326
else setPosition(_selectionRegion.getEndOffset());
323327

@@ -336,39 +340,45 @@ private int _replaceAllInCurrentDoc(boolean searchSelectionOnly) {
336340
return count;
337341
}
338342

339-
/** Processes all occurrences of the find word with the replace word in the current document or in all documents
340-
* depending the values of fields _searchAllDocuments and _searchSelectionOnly and parameter region. Assumes that
341-
* findAction does not modify the document it processes. Only executes in event thread.
343+
/** Replaces all occurrences of the find word with the replace word in the specified region while performing the
344+
* which occurs within the current document. On each match, the findAction command is executed, assuming that
345+
* indAction does not modify the document it processes. Saves value of _searchAllDocuments and _searchSelectionOnly
346+
* and restores trem, an ugly hack dictated by embedding this information in the FindReplaceMachine. During this
347+
* particular search action, _searchAllDocuments is false since it is confined to a region within the current document.
348+
* Only executes in event thread.
342349
* @param findAction action to perform on the occurrences; input is the FindResult, output is ignored
343350
* @param region the selection region
344351
* @return the number of processed occurrences
345352
*/
346353
public int processAll(Runnable1<FindResult> findAction, MovingDocumentRegion region) {
347354

348355
assert EventQueue.isDispatchThread();
349-
356+
350357
_selectionRegion = region;
351-
return processAll(findAction);
358+
359+
int count = processAll(findAction);
360+
361+
return count;
352362
}
353363

354364
/** Processes all occurences of the find word with the replace word in the current document or in all documents
355365
* depending the value of fields _searchAllDocuments, _searchSelectionOnly, _selectionRegion. Assumes that
356366
* findAction does not modify the document it processes. Only executes in event thread.
357-
* @param findAction action to perform on the occurrences; input is the FindResult, output is ignored
358-
* @param searchAll true if we should search for occurrences in all documents
359-
* @param searchSelectionOnly true if we should only search in the current selection of document
367+
* Modifies _searchSelectionOnly if it is inconsistent with _searchAllDocuments
368+
* @param findAction action to perform on the occurrences; input is the FindResult, output is ignored.
360369
* @return the number of replacements
361370
*/
362371
private int processAll(Runnable1<FindResult> findAction) {
363372

364373
assert EventQueue.isDispatchThread();
365374

366375
if (_searchAllDocuments) {
367-
int count = 0; // the number of replacements done so far
376+
int count = 0; // the number of replacements done so far
377+
_searchSelectionOnly = false; // force _searchSelectionOnly to be false
368378
final int n = _docIterator.getDocumentCount();
369379
for (int i = 0; i < n; i++) {
370380
// process all in the rest of the documents
371-
_searchSelectionOnly = false; // force _searchSelectionOnly to be false
381+
372382
count += _processAllInCurrentDoc(findAction);
373383
_doc = _docIterator.getNextDocument(_doc, _frame);
374384

@@ -385,25 +395,27 @@ else if (_searchSelectionOnly) {
385395
count += _processAllInCurrentDoc(findAction);
386396
return count;
387397
}
388-
else return _processAllInCurrentDoc(findAction);
398+
else /* search entire current document */
399+
return _processAllInCurrentDoc(findAction);
389400
}
390401

391-
/** Processes all occurences of _findWord in _doc. Never processes other documents. Starts at the beginning or the
392-
* end of the document (depending on find direction). This convention ensures that matches created by string
393-
* replacement will not be replaced as in the following example:<p>
394-
* findString: "hello"<br>
395-
* replaceString: "e"<br>
396-
* document text: "hhellollo"<p>
397-
* Only executes in event thread. Assumes (i) this has exclusive access to _doc (since it only runs in event thread)
398-
* and (ii) findAction does not modify _doc.
399-
* @param findAction action to perform on the occurrences; input is the FindResult, output is ignored
400-
* @return the number of replacements
401-
*/
402+
/** Processes all occurences of _findWord in _doc depending the values of fields _searchSelectionOnly,
403+
* _selectionRegion and _isForward. Ignores value of _searchAllDocuments. Processes selected region (which may be
404+
* the whole document) sequentially depending on find direction. This convention ensures that matches created by
405+
* string replacement will not be replaced as in the following example:<p>
406+
* findString: "hello"<br>
407+
* replaceString: "e"<br>
408+
* document text: "hhellollo"<p>
409+
* Only executes in event thread. Assumes (i) this has exclusive access to _doc (since it only runs in event thread)
410+
* and (ii) findAction does not modify _doc.
411+
* @param findAction action to perform on the occurrences; input is the FindResult, output is ignored
412+
* @return the number of replacements
413+
*/
402414
private int _processAllInCurrentDoc(Runnable1<FindResult> findAction) {
403415

404416
assert EventQueue.isDispatchThread();
405417

406-
if (!_searchSelectionOnly) {
418+
if (! _searchSelectionOnly) {
407419
_selectionRegion = new MovingDocumentRegion(_doc, 0, _doc.getLength(), _doc._getLineStartPos(0),
408420
_doc._getLineEndPos(_doc.getLength()));
409421
}

drjava/src/edu/rice/cs/drjava/ui/FindReplacePanel.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class FindReplacePanel extends TabbedPanel implements ClipboardOwner {
9494

9595
private volatile JLabel _findLabelBot; // Dynamically updated
9696

97+
/* The choice of fields names here is really obnoxious because this class is closely linked with FindReplaceMachine
98+
* and the SAME field (property) names have completely different meanings in that class! */
9799
private volatile JCheckBox _ignoreCommentsAndStrings;
98100
private volatile JCheckBox _matchCase;
99101
private volatile JCheckBox _searchAllDocuments;
@@ -115,17 +117,15 @@ class FindReplacePanel extends TabbedPanel implements ClipboardOwner {
115117
/** Listens for changes to the cursor position in order to reset the start position */
116118
private CaretListener _caretListener = new CaretListener() {
117119
public void caretUpdate(CaretEvent e) {
118-
120+
119121
assert EventQueue.isDispatchThread();
120-
// Utilities.invokeLater(new Runnable() {
121-
// public void run() {
122-
_replaceAction.setEnabled(false);
123-
_replaceFindNextAction.setEnabled(false);
124-
_replaceFindPreviousAction.setEnabled(false);
125-
_machine.positionChanged();
126-
_caretChanged = true;
127-
// }
128-
// });
122+
123+
_replaceAction.setEnabled(false);
124+
_replaceFindNextAction.setEnabled(false);
125+
_replaceFindPreviousAction.setEnabled(false);
126+
_machine.positionChanged();
127+
_caretChanged = true;
128+
129129
}
130130
};
131131

@@ -355,7 +355,7 @@ public void itemStateChanged(ItemEvent e) {
355355
public void itemStateChanged(ItemEvent e) {
356356
boolean isSelected = (e.getStateChange() == ItemEvent.SELECTED);
357357
_machine.setSearchSelectionOnly(isSelected);
358-
if(isSelected) {
358+
if (isSelected) {
359359
_ignoreTestCases.setSelected(false);
360360
_searchAllDocuments.setSelected(false);
361361
_findNextAction.setEnabled(false);
@@ -555,7 +555,7 @@ public boolean requestFocusInWindow() {
555555

556556
/** Performs "find all" command. */
557557
private void _findAll() {
558-
// The following two line was moved to _findAll(...) so it is executed by FindResultsPanel._findAgain
558+
// The following line was moved to _findAll(...) so it is executed by FindResultsPanel._findAgain
559559
// _machine.setSearchBackwards(false);
560560

561561
_findLabelBot.setText("Next");
@@ -603,12 +603,17 @@ private void _findAll() {
603603
* @param region a MovingDocumentRegion
604604
* @param panel panel in which to display search results
605605
*/
606-
public void findAll(String searchStr, final boolean searchAll,
607-
final boolean searchSelectionOnly, final boolean matchCase,
608-
final boolean wholeWord, final boolean noComments,
609-
final boolean noTestCases, final OpenDefinitionsDocument startDoc,
610-
final RegionManager<MovingDocumentRegion> rm,
611-
final MovingDocumentRegion region, final FindResultsPanel panel) {
606+
public void findAll(String searchStr,
607+
final boolean searchAll,
608+
final boolean searchSelectionOnly,
609+
final boolean matchCase,
610+
final boolean wholeWord,
611+
final boolean noComments,
612+
final boolean noTestCases,
613+
final OpenDefinitionsDocument startDoc,
614+
final RegionManager<MovingDocumentRegion> rm,
615+
final MovingDocumentRegion region,
616+
final FindResultsPanel panel) {
612617

613618
_machine.setSearchBackwards(false);
614619

@@ -648,10 +653,10 @@ public void findAll(String searchStr, final boolean searchAll,
648653
_frame.hourglassOn();
649654
try {
650655
/* Accumulate all occurrences of searchStr in results. */
651-
final int count = _machine.processAll(new Runnable1<FindResult>() {
652-
public void run(FindResult fr) { results.add(fr); }
653-
}, region);
656+
final int count =
657+
_machine.processAll(new Runnable1<FindResult>() { public void run(FindResult fr) { results.add(fr); }}, region);
654658

659+
/* Restore state of FindReplaceMachine */
655660
_machine.setDocument(oldDoc);
656661
_machine.setFirstDoc(oldFirstDoc);
657662
_machine.setFindWord(oldFindWord);

drjava/src/edu/rice/cs/util/IterableOps.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public abstract class IterableOps {
4646
*/
4747
@SuppressWarnings("unchecked")
4848
public static <T> T[] toArray(Iterable<T> iter, Class<T> elemType) {
49-
ArrayList<T> al = new ArrayList();
49+
ArrayList<T> al = (ArrayList<T>) new ArrayList();
5050

5151
for (T elem : iter) {
5252
al.add(elem);

0 commit comments

Comments
 (0)