Skip to content

Commit efdc09a

Browse files
committed
This revision includes many patches to support using the JShell in place of DynamicJava and the incompatible (!) changes to Java 11 since Java 8.
1 parent 650c21d commit efdc09a

16 files changed

+148
-95
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,16 +2518,21 @@ public void optionChanged(OptionEvent<Boolean> oce) {
25182518
* @param style the style to print with
25192519
*/
25202520
protected void _docAppend(final ConsoleDocument doc, final String s, final String style) {
2521-
Utilities.invokeLater(new Runnable() {
2522-
public void run() { doc.insertBeforeLastPrompt(s, style); }
2523-
});
2521+
assert EventQueue.isDispatchThread();
2522+
doc.insertBeforeLastPrompt(s, style);
25242523
}
25252524

25262525
/** Prints System.out to the DrJava console. This method can safely be run outside the event thread. */
2527-
public void systemOutPrint(final String s) { _docAppend(_consoleDoc, s, EditDocumentInterface.SYSTEM_OUT_STYLE); }
2526+
public void systemOutPrint(final String s) {
2527+
// Utilities.show("AbstractGlobalModel.systemOutPrint(" + s + ") called");
2528+
_docAppend(_consoleDoc, s, EditDocumentInterface.SYSTEM_OUT_STYLE);
2529+
}
25282530

25292531
/** Prints System.err to the DrJava console. This method can safely be run outside the event thread. */
2530-
public void systemErrPrint(final String s) { _docAppend(_consoleDoc, s, EditDocumentInterface.SYSTEM_ERR_STYLE); }
2532+
public void systemErrPrint(final String s) {
2533+
// Utilities.show("AbstractGlobalModel.systemErrPrint(" + s + ") called");
2534+
_docAppend(_consoleDoc, s, EditDocumentInterface.SYSTEM_ERR_STYLE);
2535+
}
25312536

25322537
/** Prints to the DrJava console as an echo of System.in. This method can safely be run outside the event thread. */
25332538
public void systemInEcho(final String s) { _docAppend(_consoleDoc, s, EditDocumentInterface.SYSTEM_IN_STYLE); }

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ public void setBuildDirectory(File f) {
416416

417417
/** Prepares this model to be thrown away. Never called in practice outside of quit(), except in tests. */
418418
public void dispose() {
419+
/* Disposing this model is performed in test code that does not run in the dispatch thread. */
420+
// assert EventQueue.isDispatchThread();
419421
ensureJVMStarterFinished();
420422
_jvm.dispose();
421423
_notifier.removeAllListeners(); // removes the global model listeners!

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,10 +1095,10 @@ public synchronized boolean shouldRevertFile(OpenDefinitionsDocument doc) {
10951095
}
10961096

10971097
/** Interprets some statements, saves the history, clears the history, then loads the history.
1098-
* @throws EditDocumentException if an error occurs while editing
1099-
* @throws IOException if an IO operation fails
1100-
* @throws InterruptedException if execution is interrupted unexpectedly
1101-
*/
1098+
* @throws EditDocumentException if an error occurs while editing
1099+
* @throws IOException if an IO operation fails
1100+
* @throws InterruptedException if execution is interrupted unexpectedly
1101+
*/
11021102
public void testSaveClearAndLoadHistory() throws EditDocumentException, IOException, InterruptedException {
11031103
String newLine = StringOps.EOL;
11041104
final InteractionListener listener = new InteractionListener();
@@ -1126,6 +1126,10 @@ public void testSaveClearAndLoadHistory() throws EditDocumentException, IOExcept
11261126
interpretIgnoreResult(s3);
11271127
listener.waitInteractionDone();
11281128

1129+
ConsoleDocument con0 = _model.getConsoleDocument();
1130+
// Utilities.show("Length of console document = " + con0.getLength());
1131+
// Utilities.show("History as string = " + _model.getHistoryAsString());
1132+
11291133
// System.err.println("history is '" + _model.getHistoryAsString() + "'");
11301134
// check that the history contains the correct value
11311135
assertEquals("History and getHistoryAsString should be the same.",
@@ -1142,10 +1146,13 @@ public void testSaveClearAndLoadHistory() throws EditDocumentException, IOExcept
11421146
// check that the file contains the correct value
11431147
assertEquals("contents of saved file", History.HISTORY_FORMAT_VERSION_2 + s1 + delim + s2 + delim + s3 + delim,
11441148
IOUtil.toString(f));
1145-
1149+
ConsoleDocument con1 = _model.getConsoleDocument();
1150+
// Utilities.show("Length of loaded history [?] = " + con1.getLength());
1151+
// Utilities.show("Length of history string [?] = " + _model.getHistoryAsString().length());
11461152
_model.clearHistory();
11471153
// confirm that the history is clear
11481154
assertEquals("History is not clear", "", _model.getHistoryAsString());
1155+
// Utilities.show("Length of loaded history [0] = " + con1.getLength());
11491156

11501157
Utilities.invokeLater(new Runnable() {
11511158
public void run() {
@@ -1160,9 +1167,11 @@ public void run() {
11601167
listener.waitInteractionDone();
11611168

11621169
// check that output of loaded history is correct
1163-
ConsoleDocument con = _model.getConsoleDocument();
1164-
debug.log(con.getDocText(0, con.getLength()).trim());
1165-
assertEquals("Output of loaded history is not correct", "x = 5", con.getDocText(0, con.getLength()).trim());
1170+
ConsoleDocument con2 = _model.getConsoleDocument();
1171+
Utilities.clearEventQueue();
1172+
// Utilities.show("Length of loaded history = " + con2.getLength());
1173+
debug.log(con2.getDocText(0, con2.getLength()).trim());
1174+
assertEquals("Output of loaded history is not correct", "x = 5", con2.getDocText(0, con2.getLength()).trim());
11661175
listener.assertInteractionStartCount(4);
11671176
listener.assertInteractionEndCount(4);
11681177
_model.removeListener(listener);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ protected void safeLoadHistory(final FileSelector fs) {
264264
Utilities.invokeAndWait(new Runnable() { public void run() { _model.loadHistory(fs); } });
265265
}
266266

267+
/* Only called from GlobalModelIOTest. */
267268
protected void safeSaveHistory(final FileSelector fs) {
268269
Utilities.invokeAndWait(new Runnable() {
269270
public void run() {

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,12 @@ public final void resetInterpreter(File wd, boolean force) {
304304
*/
305305
protected abstract void _notifySyntaxErrorOccurred(int offset, int length);
306306

307-
308-
/** Interprets the files selected in the FileOpenSelector. Assumes all
309-
* strings have no trailing whitespace.
310-
* Interprets the array all at once so if there are any errors, none of the
311-
* statements after the first erroneous one are processed. Only runs in
312-
* the event thread.
313-
* @param selector a FileOpenSelector
314-
* @throws IOException if an IO operation fails
315-
*/
307+
/** Interprets the files selected in the FileOpenSelector. Assumes all strings have no trailing whitespace. Interprets
308+
* the array all at once so if there are any errors, none of the statements after the first erroneous one are processed.
309+
* Only runs in the event thread.
310+
* @param selector a FileOpenSelector
311+
* @throws IOException if an IO operation fails
312+
*/
316313
public void loadHistory(final FileOpenSelector selector) throws IOException {
317314
ArrayList<String> histories;
318315
try { histories = _getHistoryText(selector); }
@@ -333,11 +330,10 @@ public void loadHistory(final FileOpenSelector selector) throws IOException {
333330
}
334331
}
335332
String text = buf.toString().trim();
336-
// System.err.println("Histtory is: '" + text + "'");
333+
// Utilities.show("History is: '" + text + "'");
337334
append(text, ConsoleDocument.DEFAULT_STYLE);
338335
interpretCurrentInteraction();
339336
// System.err.println("Interpreting loaded history");
340-
341337
}
342338

343339
/** Opens the files chosen in the given file selector, and returns an

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public void resetView() {
180180
/** Default cut action. */
181181
Action cutAction = new DefaultEditorKit.CutAction() {
182182
public void actionPerformed(ActionEvent e) {
183-
183+
assert EventQueue.isDispatchThread();
184184
if (_pane.getSelectedText() != null) {
185185
super.actionPerformed(e);
186186
String s = edu.rice.cs.util.swing.Utilities.getClipboardSelection(_pane);
@@ -192,6 +192,7 @@ public void actionPerformed(ActionEvent e) {
192192
/** Default copy action. */
193193
Action copyAction = new DefaultEditorKit.CopyAction() {
194194
public void actionPerformed(ActionEvent e) {
195+
assert EventQueue.isDispatchThread();
195196
if (_pane.getSelectedText() != null) {
196197
super.actionPerformed(e);
197198
String s = edu.rice.cs.util.swing.Utilities.getClipboardSelection(_pane);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ public void setCurrentDirectory(File dir) {
311311

312312
/** Method that handles the OK button */
313313
private void _ok() {
314+
assert EventQueue.isDispatchThread();
314315
_lastState = new FrameState(this);
315316
DrJava.getConfig().setSetting(OptionConstants.EXTERNAL_SAVED_COUNT,
316317
DrJava.getConfig().getSetting(OptionConstants.EXTERNAL_SAVED_COUNT));
@@ -319,6 +320,7 @@ private void _ok() {
319320

320321
/** Edit a command. */
321322
private void _edit() {
323+
assert EventQueue.isDispatchThread();
322324
final int selectedIndex = _list.getSelectedIndex();
323325
if ((selectedIndex < 0) || (selectedIndex>=DrJava.getConfig().getSetting(OptionConstants.EXTERNAL_SAVED_COUNT))) {
324326
return;
@@ -550,7 +552,7 @@ public void updateList(int selectedIndex) {
550552

551553
/** Toggle visibility of this frame. Warning, it behaves like a modal dialog. */
552554
public void setVisible(boolean vis) {
553-
assert EventQueue.isDispatchThread();
555+
assert ! _mainFrame.isVisible() || EventQueue.isDispatchThread();
554556
validate();
555557
if (vis) {
556558
updateList(0);

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

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@
3737
import edu.rice.cs.drjava.model.DJError;
3838
import edu.rice.cs.drjava.model.compiler.CompilerErrorModel;
3939
import edu.rice.cs.drjava.model.ClipboardHistoryModel;
40+
import edu.rice.cs.drjava.model.print.DrJavaBook;
4041
import edu.rice.cs.util.UnexpectedException;
4142
import edu.rice.cs.util.swing.HighlightManager;
4243
import edu.rice.cs.util.swing.BorderlessScrollPane;
44+
import edu.rice.cs.util.swing.Utilities;
4345
import edu.rice.cs.util.text.SwingDocument;
44-
import edu.rice.cs.drjava.model.print.DrJavaBook;
46+
4547

4648
import edu.rice.cs.util.swing.RightClickMouseAdapter;
4749

@@ -116,6 +118,7 @@ protected static final SimpleAttributeSet _getNormalAttributes() {
116118
return s;
117119
}
118120

121+
/* Primary constructor for ErrorPanel class */
119122
public ErrorPanel(SingleDisplayModel model, MainFrame frame, String tabString, String labelString) {
120123
super(frame, tabString);
121124
_model = model;
@@ -156,11 +159,10 @@ public ErrorPanel(SingleDisplayModel model, MainFrame frame, String tabString, S
156159

157160
// _mainPanel.setMinimumSize(new Dimension(225,60));
158161
// We make the vertical scrollbar always there.
159-
// If we don't, when it pops up it cuts away the right edge of the
160-
// text. Very bad.
162+
// If we don't, when it pops up it cuts away the right edge of thetext. Very bad.
161163
_scroller = new BorderlessScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
162164
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
163-
165+
164166
_leftPanel.add(_scroller, BorderLayout.CENTER);
165167
_leftPanel.add(_errorNavPanel, BorderLayout.EAST);
166168

@@ -175,9 +177,10 @@ public ErrorPanel(SingleDisplayModel model, MainFrame frame, String tabString, S
175177
_mainPanel.add(_leftPanel, BorderLayout.CENTER);
176178
_mainPanel.add(_rightPanel, BorderLayout.EAST);
177179

178-
/** Default copy action. Returns focus to the correct pane. */
180+
/** Default copy action. Returns focus to the correct pane. Executes in dispatch thread. */
179181
final Action copyAction = new AbstractAction("Copy Contents to Clipboard", MainFrame.getIcon("Copy16.gif")) {
180182
public void actionPerformed(ActionEvent e) {
183+
assert EventQueue.isDispatchThread();
181184
getErrorListPane().selectAll();
182185
String t = getErrorListPane().getSelectedText();
183186
if (t != null) {
@@ -188,54 +191,68 @@ public void actionPerformed(ActionEvent e) {
188191
ClipboardHistoryModel.singleton().put(t);
189192
}
190193
}
191-
}
194+
};
192195
};
196+
193197
addPopupMenu(copyAction);
198+
194199
getPopupMenu().add(new AbstractAction("Save Copy of Contents...", MainFrame.getIcon("Save16.gif")) {
200+
/* Executes in dispatch thread. */
195201
public void actionPerformed(ActionEvent e) {
202+
assert EventQueue.isDispatchThread();
196203
_frame._saveDocumentCopy(getErrorListPane().getErrorDocument());
197204
}
198205
});
206+
199207
getPopupMenu().addSeparator();
208+
200209
getPopupMenu().add(new AbstractAction("Print...", MainFrame.getIcon("Print16.gif")) {
210+
/* Executes in dispatch thread. */
201211
public void actionPerformed(ActionEvent e) {
212+
assert EventQueue.isDispatchThread();
202213
getErrorListPane().getErrorDocument().print();
203214
}
204215
});
216+
205217
getPopupMenu().add(new AbstractAction("Print Preview...", MainFrame.getIcon("PrintPreview16.gif")) {
218+
/* Executes in dispatch thread. */
206219
public void actionPerformed(ActionEvent e) {
220+
assert EventQueue.isDispatchThread();
207221
getErrorListPane().getErrorDocument().preparePrintJob();
208222
new PreviewErrorFrame();
209223
}
210224
});
211225
}
212-
226+
213227
protected void setErrorListPane(final ErrorListPane elp) {
214-
if (_popupMenuListener!=null) {
215-
if ((_scroller!=null) && // unnecessary?
216-
(_scroller.getViewport()!=null) &&
217-
(_scroller.getViewport().getView()!=null)) {
228+
/* Should this action be performed in the dispatch thread? */
229+
if (_popupMenuListener != null) {
230+
if ((_scroller.getViewport() != null) && (_scroller.getViewport().getView() != null)) {
218231
_scroller.getViewport().getView().removeMouseListener(_popupMenuListener);
219232
}
220233
}
221234

222235
_scroller.setViewportView(elp);
223236

224-
if (_popupMenuListener!=null) {
225-
_scroller.getViewport().getView().addMouseListener(_popupMenuListener);
226-
}
237+
if (_popupMenuListener!=null) { _scroller.getViewport().getView().addMouseListener(_popupMenuListener); }
227238

228239
_nextErrorButton.setEnabled(false);
240+
229241
_nextErrorButton.addActionListener(new ActionListener() {
242+
/* Executes in dispatch thread. */
230243
public void actionPerformed(ActionEvent e) {
244+
assert EventQueue.isDispatchThread();
231245
elp.nextError();
232246
// _prevErrorButton.setEnabled(_errorListPane.hasPrevError());
233247
// _nextErrorButton.setEnabled(_errorListPane.hasNextError());
234248
}
235249
});
250+
236251
_prevErrorButton.setEnabled(false);
237252
_prevErrorButton.addActionListener(new ActionListener() {
253+
/* Executes in dispatch thread. */
238254
public void actionPerformed(ActionEvent e) {
255+
assert EventQueue.isDispatchThread();
239256
elp.prevError();
240257
// _prevErrorButton.setEnabled(_errorListPane.hasPrevError());
241258
// _nextErrorButton.setEnabled(_errorListPane.hasNextError());
@@ -301,28 +318,34 @@ public abstract class ErrorListPane extends JEditorPane implements ClipboardOwne
301318

302319
/** Default cut action. */
303320
volatile Action cutAction = new DefaultEditorKit.CutAction() {
321+
322+
/* Executes in dispatch thread. */
304323
public void actionPerformed(ActionEvent e) {
324+
assert EventQueue.isDispatchThread();
305325
if (getSelectedText() != null) {
306326
super.actionPerformed(e);
307-
String s = edu.rice.cs.util.swing.Utilities.getClipboardSelection(ErrorListPane.this);
327+
String s = Utilities.getClipboardSelection(ErrorListPane.this);
308328
if ((s != null) && (s.length() != 0)) { ClipboardHistoryModel.singleton().put(s); }
309329
}
310330
}
311331
};
312-
332+
313333
/** Default copy action. */
314334
volatile Action copyAction = new DefaultEditorKit.CopyAction() {
335+
/* Executes in dispatch thread. */
315336
public void actionPerformed(ActionEvent e) {
337+
assert EventQueue.isDispatchThread();
316338
if (getSelectedText() != null) {
317339
super.actionPerformed(e);
318-
String s = edu.rice.cs.util.swing.Utilities.getClipboardSelection(ErrorListPane.this);
340+
String s = Utilities.getClipboardSelection(ErrorListPane.this);
319341
if (s != null && s.length() != 0) { ClipboardHistoryModel.singleton().put(s); }
320342
}
321343
}
322344
};
323345

324346
/** No-op paste action. */
325347
volatile Action pasteAction = new DefaultEditorKit.PasteAction() {
348+
/* Executes in any thread. */
326349
public void actionPerformed(ActionEvent e) { }
327350
};
328351

@@ -498,14 +521,13 @@ private int _getIndexForError(DJError error) {
498521
/** @return true if the text selection interval is empty. */
499522
protected boolean _isEmptySelection() { return getSelectionStart() == getSelectionEnd(); }
500523

501-
/** Update the pane which holds the list of errors for the viewer.
502-
* @param done boolean
503-
*/
524+
/** Update the pane which holds the list of errors for the viewer. Only executes in the dispatch thread.
525+
* @param done boolean
526+
*/
504527
protected void updateListPane(boolean done) {
505528
try {
506529
_errorListPositions = new Position[_numErrors];
507530
_errorTable.clear();
508-
509531
if (_numErrors == 0) _updateNoErrors(done);
510532
else _updateWithErrors();
511533
}
@@ -818,9 +840,8 @@ void switchToError(DJError error) {
818840
if (! prevDoc.equals(doc)) {
819841
model.setActiveDocument(doc);
820842
EventQueue.invokeLater(new Runnable() {
821-
public void run() {
822-
model.addToBrowserHistory();
823-
} });
843+
public void run() { model.addToBrowserHistory(); }
844+
});
824845
}
825846
else model.refreshActiveDocument();
826847

@@ -837,8 +858,7 @@ public void run() {
837858
* is unhighlighted and the new error is not highlighted because the CaretListener does not act because there
838859
* is no change in caret position. (This is the only place where updateHighlight was called from before) */
839860
defPane.getErrorCaretListener().updateHighlight(errPos);
840-
}
841-
861+
}
842862
}
843863
// The following line is a brute force hack that fixed a bug plaguing the DefinitionsPane immediately after a compilation
844864
// with errors. In some cases (which were consistently reproducible), the DefinitionsPane editing functions would break
@@ -961,11 +981,10 @@ protected void _popupAction(MouseEvent e) {
961981
}
962982
};
963983
addMouseListener(_popupMenuListener);
964-
if (_scroller!=null) { // test unnecessary?
965-
_scroller.addMouseListener(_popupMenuListener);
966-
if (_scroller.getViewport().getView()!=null) {
967-
_scroller.getViewport().getView().addMouseListener(_popupMenuListener);
968-
}
984+
985+
_scroller.addMouseListener(_popupMenuListener);
986+
if (_scroller.getViewport().getView() != null) {
987+
_scroller.getViewport().getView().addMouseListener(_popupMenuListener);
969988
}
970989
}
971990
}

0 commit comments

Comments
 (0)