Skip to content

Commit b1ebbc0

Browse files
author
rcartwright
committed
This revision contains:
(i) higher performance code for jumping to entries displayed in a "Find All" pane; (ii) cosmetic changes to many classes (inserting spaces around == and != and eliminating redundant parentheses). The following files were modified: M src/edu/rice/cs/drjava/model/debug/jpda/DocumentDebugAction.java M src/edu/rice/cs/drjava/model/debug/jpda/PendingRequestManager.java M src/edu/rice/cs/drjava/model/debug/jpda/JPDABreakpoint.java M src/edu/rice/cs/drjava/model/StaticDocumentRegion.java M src/edu/rice/cs/drjava/model/repl/InteractionsDocument.java M src/edu/rice/cs/drjava/model/repl/InteractionsModel.java M src/edu/rice/cs/drjava/model/compiler/DefaultCompilerModel.java M src/edu/rice/cs/drjava/model/ClipboardHistoryModel.java M src/edu/rice/cs/drjava/model/AbstractGlobalModel.java M src/edu/rice/cs/drjava/model/DefaultLightWeightParsingControl.java M src/edu/rice/cs/drjava/ui/MainFrame.java M src/edu/rice/cs/drjava/ui/CompilerErrorPanel.java M src/edu/rice/cs/drjava/ui/HTMLFrame.java M src/edu/rice/cs/drjava/ui/JarOptionsDialog.java M src/edu/rice/cs/drjava/ui/ErrorPanel.java M src/edu/rice/cs/drjava/ui/predictive/PredictiveInputFrame.java M src/edu/rice/cs/drjava/ui/BrowserHistoryPanel.java M src/edu/rice/cs/drjava/ui/RegionsTreePanel.java M src/edu/rice/cs/drjava/ui/RegionsListPanel.java M src/edu/rice/cs/drjava/ui/AboutDialog.java M src/edu/rice/cs/drjava/ui/FindReplacePanel.java M src/edu/rice/cs/drjava/ui/BookmarksPanel.java M src/edu/rice/cs/drjava/ui/DrJavaErrorWindow.java M src/edu/rice/cs/drjava/ui/DrJavaErrorHandler.java M src/edu/rice/cs/drjava/ui/AbstractConsoleController.java M src/edu/rice/cs/drjava/ui/ClipboardHistoryFrame.java M src/edu/rice/cs/util/FileOps.java M src/edu/rice/cs/util/docnavigation/JListNavigator.java M src/edu/rice/cs/util/swing/Utilities.java M src/edu/rice/cs/util/sexp/Tokens.java git-svn-id: file:///tmp/test-svn/trunk@4142 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 7f94cfd commit b1ebbc0

30 files changed

+119
-113
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ public boolean accept(File parent, String name) {
893893
}
894894
});
895895

896-
if (fs!=null) { // listFiles may return null if there's an IO error
896+
if (fs != null) { // listFiles may return null if there's an IO error
897897
for (File kid: fs) { getClassFilesHelper(kid, acc); }
898898
}
899899

@@ -2477,7 +2477,7 @@ public R nextCurrentRegion() {
24772477
/** Make the region that is less recent the current region.
24782478
* @return new current region */
24792479
public R prevCurrentRegion() {
2480-
if (_current!=null) {
2480+
if (_current != null) {
24812481
int index = getIndexOf(_current);
24822482
if (index-1 >= 0) {
24832483
_current = _regions.get(index-1);
@@ -3716,7 +3716,7 @@ File _getSourceRoot(String packageName) throws InvalidPackageException {
37163716

37173717
// Make sure the package piece matches the directory name
37183718
boolean equal;
3719-
if (grandParentDir!=null) {
3719+
if (grandParentDir != null) {
37203720
// grand parent exists, compare File objects
37213721
// this handles case-insensitivity for packages on Windows
37223722
File packageDir = new File(grandParentDir,part);
@@ -4060,7 +4060,7 @@ public void setParagraphAttributes(int offset, int length, AttributeSet s, boole
40604060
// public int getLockState() { return getDocument().getLockState(); }
40614061

40624062
/** @return the number of lines in this document. */
4063-
public int getNumberOfLines() { return getLineOfOffset(getEndPosition().getOffset()-1); }
4063+
public int getNumberOfLines() { return getLineOfOffset(getLength()); }
40644064

40654065
/** Translates an offset into the components text to a line number.
40664066
* @param offset the offset >= 0

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ public class ClipboardHistoryModel {
5151

5252
/** Singleton accessor. */
5353
public static synchronized ClipboardHistoryModel singleton() {
54-
if (ONLY==null) {
55-
ONLY = new ClipboardHistoryModel(10);
56-
}
54+
if (ONLY == null) ONLY = new ClipboardHistoryModel(10);
5755
return ONLY;
5856
}
5957

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void run() {
104104
if (current>=_beginUpdates) {
105105
OpenDefinitionsDocument doc = _model.getActiveDocument();
106106
Long last = _lastUpdates.get(doc);
107-
if ((last==null) || (last<_lastDelay)) {
107+
if ((last == null) || (last < _lastDelay)) {
108108
update(doc);
109109
// _log.logTime("Update done.");
110110
}
@@ -137,7 +137,7 @@ public synchronized void update(final OpenDefinitionsDocument doc) {
137137
_lastUpdates.put(doc, System.currentTimeMillis());
138138
final String old = _enclosingClassNames.get(doc);
139139
final String updated = doc.getEnclosingClassName(doc.getCaretPosition(), true);
140-
if ((old==null) || (!old.equals(updated))) {
140+
if ((old == null) || (!old.equals(updated))) {
141141
_enclosingClassNames.put(doc, updated);
142142
Utilities.invokeLater(new Runnable() {
143143
public void run() {

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ public class StaticDocumentRegion implements DocumentRegion {
4848
protected final int _endOffset;
4949
protected final String _string;
5050

51-
/** Create a new static document region. */
51+
/** Create a new static document region. Precondition: s != null. */
5252
public StaticDocumentRegion(OpenDefinitionsDocument doc, File file, int so, int eo, String s) {
53+
assert s != null;
5354
_doc = doc;
5455
_file = file;
5556
_startOffset = so;
@@ -65,31 +66,40 @@ public StaticDocumentRegion(OpenDefinitionsDocument doc, File file, int so, int
6566

6667
/** @return the start offset */
6768
public int getStartOffset() {
68-
return ((_doc==null)||(_doc.getLength()>=_startOffset))?_startOffset:_doc.getLength();
69+
return (_doc == null || _doc.getLength() >= _startOffset) ? _startOffset : _doc.getLength();
6970
}
7071

7172
/** @return the end offset */
7273
public int getEndOffset() {
73-
return ((_doc==null)||(_doc.getLength()>=_endOffset))?_endOffset:_doc.getLength();
74+
return (_doc == null || _doc.getLength()>=_endOffset) ? _endOffset : _doc.getLength();
7475
}
7576

7677
/** @return the string it was assigned */
7778
public String getString() {
7879
return _string;
7980
}
8081

82+
private static boolean equals(OpenDefinitionsDocument doc1, OpenDefinitionsDocument doc2) {
83+
if (doc1 == null) return (doc2 == null);
84+
if (doc2 == null) return false;
85+
return doc1.equals(doc2);
86+
}
87+
88+
private static boolean equals(File f1, File f2) {
89+
if (f1 == null) return (f2 == null);
90+
if (f2 == null) return false;
91+
return f1.equals(f2);
92+
}
93+
8194
/** @return true if the specified region is equal to this one. */
8295
public boolean equals(Object other) {
83-
if (!(other instanceof StaticDocumentRegion) || (other==null)) return false;
84-
StaticDocumentRegion o = (StaticDocumentRegion)other;
85-
return ((((_doc==null) && (o._doc==null)) || (_doc.equals(o._doc))) &&
86-
(((_file==null) && (o._file==null)) || (_file.equals(o._file))) &&
87-
(_startOffset == o._startOffset) &&
88-
(_endOffset == o._endOffset) &&
89-
(_string.equals(o._string)));
96+
if (other == null || !(other instanceof StaticDocumentRegion)) return false;
97+
StaticDocumentRegion o = (StaticDocumentRegion) other;
98+
return (equals(_doc, o._doc) && equals(_file, o._file) && _startOffset == o._startOffset &&
99+
_endOffset == o._endOffset && _string.equals(o._string));
90100
}
91101

92102
public String toString() {
93-
return ((_doc!=null)?_doc.toString():"null") + " "+_startOffset+" .. "+_endOffset;
103+
return (_doc != null ? _doc.toString() : "null") + " " + _startOffset + " .. " + _endOffset;
94104
}
95105
}

drjava/src/edu/rice/cs/drjava/model/compiler/DefaultCompilerModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private void _doCompile(List<OpenDefinitionsDocument> docs) throws IOException {
240240
}
241241

242242
File buildDir = _model.getBuildDirectory();
243-
if ((buildDir!=null) && !buildDir.exists() && !buildDir.mkdirs()) {
243+
if ((buildDir != null) && !buildDir.exists() && !buildDir.mkdirs()) {
244244
throw new IOException("Could not create build directory: "+buildDir);
245245
}
246246

drjava/src/edu/rice/cs/drjava/model/debug/jpda/DocumentDebugAction.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public abstract class DocumentDebugAction<T extends EventRequest> extends DebugA
5757
protected volatile OpenDefinitionsDocument _doc;
5858
protected int _offset;
5959

60+
public final int SHORT_DOC_MAX_LENGTH = 20000;
61+
6062

6163
/** Creates a new DocumentDebugAction. Automatically tries to create the EventRequest if a ReferenceType can be
6264
* found, or else adds this object to the PendingRequestManager. Any subclass should automatically call
@@ -70,7 +72,7 @@ public DocumentDebugAction (JPDADebugger manager, OpenDefinitionsDocument doc, i
7072
_exactClassName = null;
7173
try {
7274
if (offset >= 0) {
73-
if (doc.getNumberOfLines() < 500) {
75+
if (doc.getLength() < SHORT_DOC_MAX_LENGTH) {
7476
// only do this on short files
7577
// in long files, getEnclosingClassName might take too long
7678
_exactClassName = doc.getEnclosingClassName(offset, true);
@@ -137,7 +139,7 @@ public boolean createRequests(Vector<ReferenceType> refTypes) throws DebugExcept
137139
protected void _initializeRequests(Vector<ReferenceType> refTypes) throws DebugException {
138140
if (refTypes.size() > 0) createRequests(refTypes);
139141
else {
140-
if (_exactClassName!=null) {
142+
if (_exactClassName != null) {
141143
List<ReferenceType> referenceTypes = _manager.getVM().classesByName(_exactClassName);
142144
if (referenceTypes.size()>0) {
143145
// class has been loaded, but couldn't find this line number

drjava/src/edu/rice/cs/drjava/model/debug/jpda/JPDABreakpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void setEnabled(boolean isEnabled) {
145145

146146
public String toString() {
147147
String cn = getClassName();
148-
if (_exactClassName!=null) { cn = _exactClassName.replace('$', '.'); }
148+
if (_exactClassName != null) { cn = _exactClassName.replace('$', '.'); }
149149
if (_requests.size() > 0) {
150150
// All BreakpointRequests are identical-- one copy for each loaded
151151
// class. So just print info from the first one, and how many there are.

drjava/src/edu/rice/cs/drjava/model/debug/jpda/PendingRequestManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ else if (actions.isEmpty()) {
170170
if (lines.size() == 0) {
171171
// Do not disable action; the line number might just be in another class in the same file
172172
String exactClassName = a.getExactClassName();
173-
if ((exactClassName!=null) && (exactClassName.equals(rt.name()))) {
173+
if (exactClassName != null && exactClassName.equals(rt.name())) {
174174
_manager.printMessage(actions.get(i).toString()+" not on an executable line; disabled.");
175175
actions.get(i).setEnabled(false);
176176
}

drjava/src/edu/rice/cs/drjava/model/repl/InteractionsDocument.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public void forwardSearchInteractionsInHistory() {
317317
public void appendExceptionResult(String exceptionClass, String message, String stackTrace, String styleName) {
318318
// TODO: should probably log this error, or figure out what causes it
319319
// it does not seem to affect the program negatively, though
320-
if ((message!=null) && (message.equals("Connection refused to host: 127.0.0.1; nested exception is: \n" +
320+
if (message != null && (message.equals("Connection refused to host: 127.0.0.1; nested exception is: \n" +
321321
"\tjava.net.ConnectException: Connection refused: connect"))) return;
322322

323323
if (null == message || "null".equals(message)) message = "";

drjava/src/edu/rice/cs/drjava/model/repl/InteractionsModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ public void replReturnedResult(String result, String style) {
477477
* @param stackTrace The stack trace of the exception
478478
*/
479479
public void replThrewException(String exceptionClass, String message, String stackTrace, String shortMessage) {
480-
if (shortMessage!=null) {
480+
if (shortMessage != null) {
481481
if (shortMessage.endsWith("<EOF>\"")) {
482482
interactionContinues();
483483
return;
@@ -497,7 +497,7 @@ public void replThrewException(String exceptionClass, String message, String sta
497497
*/
498498
public void replReturnedSyntaxError(String errorMessage, String interaction, int startRow, int startCol,
499499
int endRow, int endCol ) {
500-
if (errorMessage!=null) {
500+
if (errorMessage != null) {
501501
if (errorMessage.endsWith("<EOF>\"")) {
502502
interactionContinues();
503503
return;

0 commit comments

Comments
 (0)