Skip to content

Commit 875709e

Browse files
author
rcartwright
committed
This revision fixes a bug in the implementation of FindResultsPanels;
it removes the highlights corresponding to a panel when the panel is removed. The revision also eliminates many commented out lines of document locking code. The following files were modified: M src/edu/rice/cs/drjava/model/GlobalModelTestCase.java M src/edu/rice/cs/drjava/model/definitions/DefinitionsDocumentTest.java M src/edu/rice/cs/drjava/model/definitions/DefinitionsDocument.java M src/edu/rice/cs/drjava/model/definitions/reducedmodel/BraceInfoTest.java M src/edu/rice/cs/drjava/model/definitions/IndentTest.java M src/edu/rice/cs/drjava/model/definitions/IndentHelperTest.java M src/edu/rice/cs/drjava/model/repl/InteractionsDocument.java M src/edu/rice/cs/drjava/model/repl/InteractionsScriptModel.java M src/edu/rice/cs/drjava/model/repl/InteractionsDJDocumentTest.java M src/edu/rice/cs/drjava/model/repl/InteractionsDJDocument.java M src/edu/rice/cs/drjava/model/repl/InteractionsModel.java M src/edu/rice/cs/drjava/model/repl/RMIInteractionsModel.java M src/edu/rice/cs/drjava/model/ConcreteRegionManager.java M src/edu/rice/cs/drjava/model/AbstractDJDocument.java M src/edu/rice/cs/drjava/model/FindReplaceMachine.java M src/edu/rice/cs/drjava/model/AbstractGlobalModel.java M src/edu/rice/cs/drjava/ui/MainFrame.java M src/edu/rice/cs/drjava/ui/DefinitionsPane.java M src/edu/rice/cs/drjava/ui/ErrorPanel.java M src/edu/rice/cs/drjava/ui/BrowserHistoryPanel.java M src/edu/rice/cs/drjava/ui/AbstractDJPane.java M src/edu/rice/cs/drjava/ui/RegionsTreePanel.java M src/edu/rice/cs/drjava/ui/InteractionsPaneTest.java M src/edu/rice/cs/drjava/ui/FindResultsPanel.java M src/edu/rice/cs/drjava/ui/FindReplacePanel.java M src/edu/rice/cs/drjava/ui/InteractionsController.java M src/edu/rice/cs/drjava/ui/AbstractConsoleController.java M src/edu/rice/cs/util/text/ConsoleDocument.java M src/edu/rice/cs/util/text/SwingDocument.java git-svn-id: file:///tmp/test-svn/trunk@4629 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 4ddd740 commit 875709e

29 files changed

Lines changed: 1305 additions & 1700 deletions

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

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -269,19 +269,15 @@ protected static HashSet<String> _makePrimTypes() {
269269
* with the same status into one. Perturbs _currentLocation.
270270
*/
271271
public ArrayList<HighlightStatus> getHighlightStatus(int start, int end) {
272-
// acquireReadLock();
273-
// try {
274272
return _getHighlightStatus(start, end);
275-
// }
276-
// finally { releaseReadLock(); }
277273
}
278274

279275
/** Return all highlight status info for text between start and end. This should collapse adjoining blocks
280-
* with the same status into one. ASSUMES that read lock is already held. Perturbs _currentLocation.
276+
* with the same status into one. ONLY runs in the event thread. Perturbs _currentLocation.
281277
*/
282278
public ArrayList<HighlightStatus> _getHighlightStatus(int start, int end) {
283279

284-
// assert isReadLocked();
280+
assert EventQueue.isDispatchThread();
285281

286282
if (start == end) return new ArrayList<HighlightStatus>(0);
287283
ArrayList<HighlightStatus> v;
@@ -511,13 +507,7 @@ public int _balanceBackward() {
511507
* @return the relative distance forwards to the offset after the matching brace.
512508
*/
513509
public int balanceForward() {
514-
// acquireReadLock();
515-
// try {
516-
// synchronized(_reduced) {
517-
return _balanceForward();
518-
// }
519-
// }
520-
// finally { releaseReadLock(); }
510+
return _balanceForward();
521511
}
522512

523513
/** Raw version of balanceForward. Assumes that read lock and reduced locks are already held. */
@@ -640,7 +630,7 @@ public boolean _isShadowed(int pos) {
640630
* @return position of enclosing brace, or ERROR_INDEX (-1) if beginning of document is reached.
641631
*/
642632
public int _findNextEnclosingBrace(final int pos, final char opening, final char closing) throws BadLocationException {
643-
// assert isReadLocked();
633+
assert EventQueue.isDispatchThread();
644634

645635
// Check cache
646636
final Query key = new Query.NextEnclosingBrace(pos, opening, closing);
@@ -655,8 +645,7 @@ public int _findNextEnclosingBrace(final int pos, final char opening, final char
655645
int braceBalance = 0;
656646

657647
String text = getText();
658-
// try {
659-
// synchronized(_reduced) {
648+
660649
final int origPos = _currentLocation;
661650
// Move reduced model to location pos
662651
_setCurrentLocation(pos); // reduced model points to pos == reducedPos
@@ -687,14 +676,11 @@ public int _findNextEnclosingBrace(final int pos, final char opening, final char
687676
/* Invariant: same as for loop except that pos <= reducedPos <= i <= text.length() */
688677

689678
_setCurrentLocation(origPos); // Restore the state of the reduced model;
690-
// } // end synchronized
691679

692680
if (i == text.length()) reducedPos = -1; // No matching char was found
693681
_storeInCache(key, reducedPos, reducedPos);
694682
// Return position of matching char or ERROR_INDEX (-1)
695683
return reducedPos;
696-
// }
697-
// finally { releaseReadLock(); }
698684
}
699685

700686
/** Searching backwards, finds the position of the first character that is one of the given delimiters. Does
@@ -842,9 +828,7 @@ public boolean _findCharInStmtBeforePos(char findChar, int position) {
842828
// * @return position of first non-whitespace character before pos OR ERROR_INDEX (-1) if no such char
843829
// */
844830
// public int findPrevCharPos(int pos, char[] whitespace) throws BadLocationException {
845-
// acquireReadLock();
846-
// try { return _findPrevCharPos(pos, whitespace); }
847-
// finally { releaseReadLock(); }
831+
// return _findPrevCharPos(pos, whitespace); }
848832
// }
849833

850834
/** Finds the position of the first non-whitespace, non-comment character before pos. Skips comments and all
@@ -997,8 +981,7 @@ public void indentLines(int selStart, int selEnd, Indenter.IndentReason reason,
997981

998982
// Begins a compound edit.
999983
// int key = startCompoundEdit(); // commented out in connection with the FrenchKeyBoard Fix
1000-
1001-
// acquireWriteLock();
984+
1002985
try {
1003986
if (selStart == selEnd) { // single line to indent
1004987
// Utilities.showDebug("selStart = " + selStart + " currentLocation = " + _currentLocation);
@@ -1016,7 +999,6 @@ public void indentLines(int selStart, int selEnd, Indenter.IndentReason reason,
1016999
else _indentBlock(selStart, selEnd, reason, pm);
10171000
}
10181001
catch (BadLocationException e) { throw new UnexpectedException(e); }
1019-
// finally { releaseWriteLock(); }
10201002

10211003
// Ends the compound edit.
10221004
//endCompoundEdit(key); //Changed to endLastCompoundEdit in connection with the FrenchKeyBoard Fix
@@ -1081,14 +1063,12 @@ private void _indentBlock(final int start, final int end, Indenter.IndentReason
10811063
* @param currPos A position on the current line
10821064
*/
10831065
public int getIntelligentBeginLinePos(int currPos) throws BadLocationException {
1066+
// assert EventQueue.isDispatchThread();
1067+
10841068
String prefix;
10851069
int firstChar;
1086-
// acquireReadLock();
1087-
// try {
10881070
firstChar = _getLineStartPos(currPos);
10891071
prefix = getText(firstChar, currPos-firstChar);
1090-
// }
1091-
// finally { releaseReadLock(); }
10921072

10931073
// Walk through string until we find a non-whitespace character
10941074
int i;
@@ -1254,7 +1234,7 @@ public int findCharOnLine(final int pos, final char findChar) {
12541234
*/
12551235
public int _getLineStartPos(final int pos) {
12561236

1257-
// assert isReadLocked();
1237+
// assert EventQueue.isDispatchThread();
12581238

12591239
if (pos < 0 || pos > getLength()) return -1;
12601240
// Check cache
@@ -1263,19 +1243,16 @@ public int _getLineStartPos(final int pos) {
12631243
if (cached != null) return cached.intValue();
12641244

12651245
int dist;
1266-
// synchronized(_reduced) {
1267-
final int oldPos = _currentLocation;
1268-
_setCurrentLocation(pos);
1269-
dist = _reduced.getDistToStart(0);
1270-
_setCurrentLocation(oldPos);
1271-
// }
1272-
1246+
1247+
final int oldPos = _currentLocation;
1248+
_setCurrentLocation(pos);
1249+
dist = _reduced.getDistToStart(0);
1250+
_setCurrentLocation(oldPos);
1251+
12731252
int newPos = 0;
12741253
if (dist >= 0) newPos = pos - dist;
12751254
_storeInCache(key, newPos, pos - 1);
12761255
return newPos; // may equal 0
1277-
// }
1278-
// finally { releaseReadLock(); }
12791256
}
12801257

12811258
/** Returns the absolute position of the end of the current line. (At the next newline, or the end of the document.)
@@ -1819,10 +1796,8 @@ protected void removeUpdate(AbstractDocument.DefaultDocumentEvent chng) {
18191796
public byte[] getBytes() { return getText().getBytes(); }
18201797

18211798
public void clear() {
1822-
// acquireWriteLock();
18231799
try { remove(0, getLength()); }
18241800
catch(BadLocationException e) { throw new UnexpectedException(e); }
1825-
// finally { releaseWriteLock(); }
18261801
}
18271802

18281803
/** @return true if pos is the position of one of the chars in an occurrence of "//" or "/*" in text. */

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3450,21 +3450,13 @@ public void insertString(int offset, String str, AttributeSet a) throws BadLocat
34503450
/** Assumes read lock is already held. */
34513451
public int _getLineStartPos(int pos) {
34523452
DefinitionsDocument doc = getDocument();
3453-
// doc.acquireReadLock();
3454-
// try {
34553453
return doc._getLineStartPos(pos);
3456-
// }
3457-
// finally { doc.releaseReadLock(); }
34583454
}
34593455

34603456
/** Assumes read lock is already held. */
34613457
public int _getLineEndPos(int pos) {
34623458
DefinitionsDocument doc = getDocument();
3463-
// doc.acquireReadLock();
3464-
// try {
3465-
return doc._getLineEndPos(pos);
3466-
// }
3467-
// finally { doc.releaseReadLock(); }
3459+
return doc._getLineEndPos(pos);
34683460
}
34693461

34703462
public int commentLines(int selStart, int selEnd) { return getDocument().commentLines(selStart, selEnd); }
@@ -3475,21 +3467,13 @@ public int uncommentLines(int selStart, int selEnd) {
34753467

34763468
public void indentLines(int selStart, int selEnd) {
34773469
DefinitionsDocument doc = getDocument();
3478-
// doc.acquireWriteLock();
3479-
// try {
34803470
doc.indentLines(selStart, selEnd);
3481-
// }
3482-
// finally { doc.releaseWriteLock(); }
34833471
}
34843472

34853473
public void indentLines(int selStart, int selEnd, Indenter.IndentReason reason, ProgressMonitor pm)
34863474
throws OperationCanceledException {
34873475
DefinitionsDocument doc = getDocument();
3488-
// doc.acquireWriteLock();
3489-
// try {
34903476
doc.indentLines(selStart, selEnd, reason, pm);
3491-
// }
3492-
// finally { doc.releaseWriteLock(); }
34933477
}
34943478

34953479
public int getCurrentLine() { return getDocument().getCurrentLine(); }

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,20 @@ public void removeRegion(final R region) {
223223
}
224224

225225
private void _notifyRegionRemoved(final R region) {
226-
_lock.startRead();
227-
try { for (RegionManagerListener<R> l: _listeners) { l.regionRemoved(region); } }
228-
finally { _lock.endRead(); }
226+
_lock.startRead();
227+
try { for (RegionManagerListener<R> l: _listeners) { l.regionRemoved(region); } }
228+
finally { _lock.endRead(); }
229+
}
230+
231+
private void _notifyRegionsRemoved(Collection<R> regions) {
232+
_lock.startRead();
233+
try {
234+
for (R r: regions) {
235+
for (RegionManagerListener<R> l: _listeners) { l.regionRemoved(r); } }
236+
}
237+
finally { _lock.endRead(); }
229238
}
239+
230240

231241
/** Remove the specified document from _documents and _regions (removing all of its contained regions). */
232242
@SuppressWarnings("unchecked")
@@ -265,7 +275,7 @@ public void clearRegions() {
265275
_regions.clear();
266276
_documents.clear();
267277
// Notify all listeners for this manager that all regions have been removed
268-
// _notifyRegionsRemoved(regions);
278+
_notifyRegionsRemoved(regions);
269279
}
270280

271281
// /** Set the current region.

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

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ public boolean replaceCurrent() {
223223
assert EventQueue.isDispatchThread();
224224

225225
if (! onMatch()) return false;
226-
// _doc.acquireWriteLock();
227226
try {
228227
// boolean atStart = false;
229228
int offset = getCurrentOffset();
@@ -244,7 +243,6 @@ public boolean replaceCurrent() {
244243
return true;
245244
}
246245
catch (BadLocationException e) { throw new UnexpectedException(e); }
247-
// finally { _doc.releaseWriteLock(); }
248246
}
249247

250248
/** Replaces all occurences of the find word with the replace word in the current document of in all documents
@@ -356,9 +354,6 @@ private int processAll(Lambda<Void, FindResult> findAction, boolean searchAll) {
356354
*/
357355
private int _processAllInCurrentDoc(Lambda<Void, FindResult> findAction) {
358356

359-
// _doc.acquireWriteLock(); // the contract stipulates no document modification!
360-
// try {
361-
362357
if (_isForward) setPosition(0);
363358
else setPosition(_doc.getLength());
364359

@@ -371,8 +366,6 @@ private int _processAllInCurrentDoc(Lambda<Void, FindResult> findAction) {
371366
fr = findNext(false); // find next match in current doc
372367
}
373368
return count;
374-
// }
375-
// finally { _doc.releaseWriteLock(); }
376369
}
377370

378371
public FindResult findNext() { return findNext(_searchAllDocuments); }
@@ -522,9 +515,7 @@ private FindResult _findNextInDocSegment(final OpenDefinitionsDocument doc, fina
522515
try {
523516

524517
// if (wrapped && allWrapped) Utilities.show(start +", " + len + ", " + docLen + ", doc = '" + doc.getText() + "'");
525-
//doc.acquireReadLock();
526518
text = doc.getText(start, len);
527-
//finally { doc.releaseReadLock(); }
528519

529520
if (! _matchCase) {
530521
text = text.toLowerCase();
@@ -613,11 +604,7 @@ private FindResult _findNextInOtherDocs(final OpenDefinitionsDocument startDoc,
613604

614605
// find next match in _doc
615606
FindResult fr;
616-
// _doc.acquireReadLock();
617-
// try {
618607
fr = _findNextInDocSegment(_doc, 0, _doc.getLength(), false, allWrapped);
619-
// }
620-
// finally { _doc.releaseReadLock(); }
621608

622609
if (fr.getFoundOffset() >= 0) return fr;
623610
}
@@ -627,11 +614,7 @@ private FindResult _findNextInOtherDocs(final OpenDefinitionsDocument startDoc,
627614
}
628615

629616
// No valid match found; perform wrapped search. _findWrapped assumes acquireReadLock is held.
630-
// startDoc.acquireReadLock();
631-
// try {
632-
return _findWrapped(startDoc, start, len, true);
633-
// } // last arg is true because searching all docs has wrapped
634-
// finally { startDoc.releaseReadLock(); }
617+
return _findWrapped(startDoc, start, len, true); // last arg is true because searching all docs has wrapped
635618
}
636619

637620
/** Determines whether the whole find word is found at the input position. Assumes read lock or hourglass is
@@ -649,16 +632,12 @@ private boolean wholeWordFoundAtCurrent(OpenDefinitionsDocument doc, int foundOf
649632
boolean leftOutOfBounds = false;
650633
boolean rightOutOfBounds = false;
651634

652-
// doc.acquireReadLock();
653-
// try {
654-
try { leftOfMatch = doc.getText(leftLoc, 1).charAt(0); }
655-
catch (BadLocationException e) { leftOutOfBounds = true; }
656-
catch (IndexOutOfBoundsException e) { leftOutOfBounds = true; }
657-
try { rightOfMatch = doc.getText(rightLoc, 1).charAt(0); }
658-
catch (BadLocationException e) { rightOutOfBounds = true; }
659-
catch (IndexOutOfBoundsException e) { rightOutOfBounds = true; }
660-
// }
661-
// finally { doc.releaseReadLock(); }
635+
try { leftOfMatch = doc.getText(leftLoc, 1).charAt(0); }
636+
catch (BadLocationException e) { leftOutOfBounds = true; }
637+
catch (IndexOutOfBoundsException e) { leftOutOfBounds = true; }
638+
try { rightOfMatch = doc.getText(rightLoc, 1).charAt(0); }
639+
catch (BadLocationException e) { rightOutOfBounds = true; }
640+
catch (IndexOutOfBoundsException e) { rightOutOfBounds = true; }
662641

663642
if (! leftOutOfBounds && ! rightOutOfBounds) return isDelimiter(rightOfMatch) && isDelimiter(leftOfMatch);
664643
if (! leftOutOfBounds) return isDelimiter(leftOfMatch);

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,17 +348,13 @@ public void run() {
348348
listener.assertInteractionEndCount(1);
349349

350350
// skip the right length for the newline
351-
// interactionsDoc.acquireReadLock();
352-
// try {
353351
final int resultsEndLocation = interactionsDoc.getLength() - newLineLen - interactionsDoc.getPrompt().length();
354352

355353
final int resultsLen = resultsEndLocation - resultsStartLocation;
356354
_log.log("resultsStartLoc = " + resultsStartLocation + " resultsEndLocation = " + resultsEndLocation);
357355
_log.log("Contents = '" + interactionsDoc.getDocText(0, resultsEndLocation+1) + "'");
358356
if (resultsLen <= 0) return "";
359357
return interactionsDoc.getDocText(resultsStartLocation, resultsLen);
360-
// }
361-
// finally { interactionsDoc.releaseReadLock(); }
362358
}
363359

364360
/** Appends the input string to the interactions pane and interprets it. */

0 commit comments

Comments
 (0)