KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > repl > InteractionsModelTest


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2005 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32  *END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.model.repl;
35
36 import edu.rice.cs.drjava.DrJavaTestCase;
37 import edu.rice.cs.drjava.model.OpenDefinitionsDocument;
38 import edu.rice.cs.drjava.model.repl.newjvm.MainJVM;
39 import edu.rice.cs.drjava.model.FileSaveSelector;
40
41 import edu.rice.cs.util.FileOpenSelector;
42 import edu.rice.cs.util.Log;
43 import edu.rice.cs.util.OperationCanceledException;
44 import edu.rice.cs.util.text.ConsoleDocument;
45 import edu.rice.cs.util.text.EditDocumentException;
46
47 import java.io.File JavaDoc;
48 import java.io.IOException JavaDoc;
49
50 import java.net.URL JavaDoc;
51
52 import java.rmi.RemoteException JavaDoc;
53
54 /** Tests the functionality of an InteractionsModel.
55  * @version $Id: InteractionsModelTest.java 4031 2006-11-15 22:09:06Z rcartwright $
56  */

57 public final class InteractionsModelTest extends DrJavaTestCase {
58   
59   private static Log _log = new Log("InteractionsModelTest.txt", false);
60   protected InteractionsDJDocument _adapter;
61   protected InteractionsModel _model;
62   
63   public InteractionsModelTest(String JavaDoc name) {
64     super(name);
65     _adapter = new InteractionsDJDocument();
66     _model = new TestInteractionsModel(_adapter);
67   }
68
69     public void tearDown() throws Exception JavaDoc {
70     // dispose the the AbstractMasterJVM supervising the MainJVM if it exists
71
if (_model instanceof IncompleteInputInteractionsModel) ((IncompleteInputInteractionsModel) _model).dispose();
72     _model = null;
73     _adapter = null;
74     super.tearDown();
75   }
76
77   /** Asserts that the given string typed by the user is processed to become the given expected string for an
78    * interpretation.
79    * @param typed A string typed by the user
80    * @param expected What the processor should return
81    */

82   protected void _assertProcessedContents(String JavaDoc typed, String JavaDoc expected) throws EditDocumentException {
83     assertTrue(_model instanceof TestInteractionsModel);
84     TestInteractionsModel model = (TestInteractionsModel)_model;
85     InteractionsDocument doc = model.getDocument();
86     doc.reset("This is a test");
87     doc.append(typed, InteractionsDocument.DEFAULT_STYLE);
88     model.interpretCurrentInteraction();
89     assertEquals("processed output should match expected", expected, model.toEval);
90   }
91
92   /** Asserts that the given string typed by the user of the form "java classname" is transformed to the given
93    * expected main method invocation.
94    * @param typed the "java classname args ..." typed by the user
95    * @param expected the expected main class call
96    */

97   protected void _assertMainTransformation(String JavaDoc typed, String JavaDoc expected) {
98     assertEquals("main transformation should match expected", expected, TestInteractionsModel._testClassCall(typed));
99   }
100
101   /** Tests that the correct text is returned when interpreting. */
102   public void testInterpretCurrentInteraction() throws EditDocumentException {
103     assertTrue(_model instanceof TestInteractionsModel);
104     TestInteractionsModel model = (TestInteractionsModel) _model;
105     String JavaDoc code = "int x = 3;";
106     InteractionsDocument doc = model.getDocument();
107     model.interpretCurrentInteraction();
108     // pretend the call completed
109
model.replReturnedVoid();
110     assertEquals("string being interpreted", "", model.toEval);
111
112     // Insert text and evaluate
113
doc.append(code, InteractionsDocument.DEFAULT_STYLE);
114     model.interpretCurrentInteraction();
115     // pretend the call completed
116
model.replReturnedVoid();
117     assertEquals("string being interpreted", code, model.toEval);
118   }
119
120   // Why do we create a new model (and slave JVM) for each of this trivial tests?
121
public void testInterpretCurrentInteractionWithIncompleteInput() throws EditDocumentException, InterruptedException JavaDoc {
122     _log.log("testInterpretCurrentInteractionWithIncompleteInput started");
123     _model = new IncompleteInputInteractionsModel(_adapter); // override the one initialized in setUp()
124
assertReplThrewContinuationException("void m() {");
125     assertReplThrewContinuationException("void m() {;");
126     assertReplThrewContinuationException("1+");
127     assertReplThrewContinuationException("(1+2");
128     assertReplThrewSyntaxException("(1+2;");
129     assertReplThrewContinuationException("for (;;");
130   }
131
132   protected void assertReplThrewContinuationException(String JavaDoc code) throws EditDocumentException, InterruptedException JavaDoc {
133     assertTrue(_model instanceof IncompleteInputInteractionsModel);
134     IncompleteInputInteractionsModel model = (IncompleteInputInteractionsModel) _model;
135     InteractionsDocument doc = model.getDocument();
136     doc.reset("This is a test");
137     doc.append(code, InteractionsDocument.DEFAULT_STYLE);
138     model._logInteractionStart();
139     model.interpretCurrentInteraction();
140     _log.log("Waiting for InteractionDone()");
141     model._waitInteractionDone();
142     assertTrue("Code '"+code+"' should generate a continuation exception but not a syntax exception",
143                (model.isContinuationException() == true) && (model.isSyntaxException() == false));
144   }
145
146   protected void assertReplThrewSyntaxException(String JavaDoc code) throws EditDocumentException, InterruptedException JavaDoc {
147     assertTrue(_model instanceof IncompleteInputInteractionsModel);
148     IncompleteInputInteractionsModel model = (IncompleteInputInteractionsModel)_model;
149     InteractionsDocument doc = model.getDocument();
150     doc.reset("This is a test");
151     doc.append(code, InteractionsDocument.DEFAULT_STYLE);
152     model._logInteractionStart();
153     model.interpretCurrentInteraction();
154     model._waitInteractionDone();
155     assertTrue("Code '" + code + "' should generate a syntax exception but not a continuation exception",
156                (model.isSyntaxException() == true) && (model.isContinuationException() == false));
157   }
158
159
160   /** Tests that "java Classname [args]" runs the class's main method, with simple delimited arguments. */
161   public void testInterpretJavaArguments() {
162     // java Foo a b c
163
// Foo.main(new String[]{"a", "b", "c"});
164
_assertMainTransformation("java Foo a b c", "Foo.main(new String[]{\"a\",\"b\",\"c\"});");
165     // java Foo "a b c"
166
// Foo.main(new String[]{"a b c"});
167
_assertMainTransformation("java Foo \"a b c\"", "Foo.main(new String[]{\"a b c\"});");
168     // java Foo "a b"c d
169
// Foo.main(new String[]{"a bc", "d"});
170
// This is different behavior than Unix or DOS, but it's more
171
// intuitive to the user (and easier to implement).
172
_assertMainTransformation("java Foo \"a b\"c d", "Foo.main(new String[]{\"a bc\",\"d\"});");
173
174     // java Foo c:\\file.txt
175
// Foo.main("c:\\file.txt");
176
_assertMainTransformation("java Foo c:\\\\file.txt", "Foo.main(new String[]{\"c:\\\\file.txt\"});");
177
178     // java Foo /home/user/file
179
// Foo.main("/home/user/file");
180
_assertMainTransformation("java Foo /home/user/file", "Foo.main(new String[]{\"/home/user/file\"});");
181   }
182
183   /** Tests that escaped characters just return the character itself. Escaped whitespace is considered a character,
184    * not a delimiter. (This is how Unix behaves.)
185    *
186    * not currently enforcing any behavior for a simple implementation using a StreamTokenizer
187    */

188   public void testInterpretJavaEscapedArgs() {
189     // java Foo \j
190
// Foo.main(new String[]{"j"});
191
_assertMainTransformation("java Foo \\j", "Foo.main(new String[]{\"j\"});");
192     // java Foo \"
193
// Foo.main(new String[]{"\""});
194
_assertMainTransformation("java Foo \\\"", "Foo.main(new String[]{\"\\\"\"});");
195     // java Foo \\
196
// Foo.main(new String[]{"\\"});
197
_assertMainTransformation("java Foo \\\\", "Foo.main(new String[]{\"\\\\\"});");
198     // java Foo a\ b
199
// Foo.main(new String[]{"a b"});
200
_assertMainTransformation("java Foo a\\ b", "Foo.main(new String[]{\"a b\"});");
201   }
202
203   /** Tests that within a quote, everything is correctly escaped.
204    * (Special characters are passed to the program correctly.)
205    */

206   public void testInterpretJavaQuotedEscapedArgs() {
207     // java Foo "a \" b"
208
// Foo.main(new String[]{"a \" b"});
209
_assertMainTransformation("java Foo \"a \\\" b\"", "Foo.main(new String[]{\"a \\\" b\"});");
210     // java Foo "\'"
211
// Foo.main(new String[]{"\\'"});
212
_assertMainTransformation("java Foo \"\\'\"", "Foo.main(new String[]{\"\\\\'\"});");
213     // java Foo "\\"
214
// Foo.main(new String[]{"\\"});
215
_assertMainTransformation("java Foo \"\\\\\"", "Foo.main(new String[]{\"\\\\\"});");
216     // java Foo "\" \d"
217
// Foo.main(new String[]{"\" \\d"});
218
_assertMainTransformation("java Foo \"\\\" \\d\"", "Foo.main(new String[]{\"\\\" \\\\d\"});");
219     // java Foo "\n"
220
// Foo.main(new String[]{"\n"});
221
/* _assertMainTransformation("java Foo \"\\n\"",
222                              "Foo.main(new String[]{\"\\n\"});");
223     // java Foo "\t"
224     // Foo.main(new String[]{"\t"});
225     _assertMainTransformation("java Foo \"\\t\"",
226                              "Foo.main(new String[]{\"\\t\"});");
227     // java Foo "\r"
228     // Foo.main(new String[]{"\r"});
229     _assertMainTransformation("java Foo \"\\r\"",
230                              "Foo.main(new String[]{\"\\r\"});");
231     // java Foo "\f"
232     // Foo.main(new String[]{"\f"});
233     _assertMainTransformation("java Foo \"\\f\"",
234                              "Foo.main(new String[]{\"\\f\"});");
235     // java Foo "\b"
236     // Foo.main(new String[]{"\b"});
237     _assertMainTransformation("java Foo \"\\b\"",
238                              "Foo.main(new String[]{\"\\b\"});"); */

239   }
240
241   /** Tests that single quotes can be used as argument delimiters. */
242   public void testInterpretJavaSingleQuotedArgs() {
243     
244     // java Foo 'asdf'
245
_assertMainTransformation("java Foo 'asdf'", "Foo.main(new String[]{\"asdf\"});");
246     
247     // java Foo 'a b c'
248
_assertMainTransformation("java Foo 'a b c'", "Foo.main(new String[]{\"a b c\"});");
249
250     // java Foo 'a b'c
251
_assertMainTransformation("java Foo 'a b'c", "Foo.main(new String[]{\"a bc\"});");
252   }
253
254   //public void testLoadHistory();
255
// TO DO: test that the correct history is returned (careful of last newline)
256

257
258   /** Tests that a debug port can be generated. */
259   public void testDebugPort() throws IOException JavaDoc {
260     int port = _model.getDebugPort();
261     assertTrue("generated debug port", port != -1);
262
263     // Resetting after startUp should change the port
264
_model.setWaitingForFirstInterpreter(false);
265     _model.interpreterResetting();
266     int newPort = _model.getDebugPort();
267     assertTrue("debug port should change", newPort != port);
268
269     // Set port
270
_model.setDebugPort(5);
271     assertEquals("manually set debug port", 5, _model.getDebugPort());
272
273     // Port should stay -1 after setting it
274
_model.setDebugPort(-1);
275     assertEquals("debug port should be -1", -1, _model.getDebugPort());
276   }
277
278   /** Tests that an interactions history can be loaded in as a script. */
279   public void testScriptLoading() throws IOException JavaDoc, OperationCanceledException {
280     assertTrue(_model instanceof TestInteractionsModel);
281     TestInteractionsModel model = (TestInteractionsModel)_model;
282     // Set up a sample history
283
String JavaDoc line1 = "System.out.println(\"hi\")";
284     String JavaDoc line2 = "System.out.println(\"bye\")";
285 // String delim = History.INTERACTION_SEPARATOR + System.getProperty("line.separator");
286
final File JavaDoc temp = File.createTempFile("drjava-test", ".hist").getCanonicalFile();
287     temp.deleteOnExit();
288     History history = new History(5);
289     history.add(line1);
290     history.add(line2);
291     history.writeToFile(new FileSaveSelector() {
292       public File JavaDoc getFile() { return temp; }
293       public boolean warnFileOpen(File JavaDoc f) { return true; }
294       public boolean verifyOverwrite() { return true; }
295       public boolean shouldSaveAfterFileMoved(OpenDefinitionsDocument doc, File JavaDoc oldFile) { return true; }
296     });
297
298     // Load the history as a script
299
InteractionsScriptModel ism = model.loadHistoryAsScript(new FileOpenSelector() {
300       public File JavaDoc[] getFiles() {
301         return new File JavaDoc[] {temp};
302       }
303     });
304     InteractionsDocument doc = model.getDocument();
305
306     // Should not be able to get the previous interaction
307
assertTrue("Should have no previous", !ism.hasPrevInteraction());
308     try {
309       ism.prevInteraction();
310       fail("Should not have been able to get previous interaction!");
311     }
312     catch (IllegalStateException JavaDoc ise) {
313       // good, continue
314
}
315
316     // Get the next (first) interaction
317
assertTrue("Should have next", ism.hasNextInteraction());
318     ism.nextInteraction();
319     assertEquals("Should have put the first line into the document.", line1, doc.getCurrentInteraction());
320
321     // Still should not be able to get the previous interaction
322
assertTrue("Should have no previous", !ism.hasPrevInteraction());
323     try {
324       ism.prevInteraction();
325       fail("Should not have been able to get previous interaction!");
326     }
327     catch (IllegalStateException JavaDoc ise) {
328       // good, continue
329
}
330
331     // Skip it; get the next (second) interaction
332
assertTrue("Should have next", ism.hasNextInteraction());
333     ism.nextInteraction();
334     assertEquals("Should have put the second line into the document.", line2, doc.getCurrentInteraction());
335
336     // Now we should be able to get the previous interaction
337
assertTrue("Should have previous", ism.hasPrevInteraction());
338     ism.prevInteraction();
339     assertEquals("Should have put the first line into the document.", line1, doc.getCurrentInteraction());
340
341     // Go back to the second line and execute it
342
ism.nextInteraction();
343     ism.executeInteraction();
344     assertEquals("Should have \"executed\" the second interaction.", line2, model.toEval);
345     // pretend the call completed
346
model.replReturnedVoid();
347
348     // Should not be able to get the next interaction, since we're at the end
349
assertTrue("Should have no next", !ism.hasNextInteraction());
350     try {
351       ism.nextInteraction();
352       fail("Should not have been able to get next interaction!");
353     }
354     catch (IllegalStateException JavaDoc ise) {
355       // good, continue
356
}
357
358     // Get Previous should return the most recently executed interaction
359
assertTrue("Should have previous", ism.hasPrevInteraction());
360     ism.prevInteraction();
361     assertEquals("Should have put the second line into the document.", line2, doc.getCurrentInteraction());
362
363     // Get Previous should now return the first interaction
364
assertTrue("Should have previous", ism.hasPrevInteraction());
365     ism.prevInteraction();
366     assertEquals("Should have put the first line into the document.", line1, doc.getCurrentInteraction());
367
368     // Should have no more previous
369
assertTrue("Should have no previous", !ism.hasPrevInteraction());
370
371     // Now execute the first interaction
372
ism.executeInteraction();
373     assertEquals("Should have \"executed\" the first interaction.", line1, model.toEval);
374     // pretend the call completed
375
model.replReturnedVoid();
376
377     // Get Previous should return the most recent (first) interaction
378
assertTrue("Should have previous", ism.hasPrevInteraction());
379     ism.prevInteraction();
380     assertEquals("Should have put the first line into the document.", line1, doc.getCurrentInteraction());
381
382     // Should not be able to get the previous interaction this time
383
assertTrue("Should have no previous", !ism.hasPrevInteraction());
384     try {
385       ism.prevInteraction();
386       fail("Should not have been able to get previous interaction!");
387     }
388     catch (IllegalStateException JavaDoc ise) {
389       // good, continue
390
}
391   }
392
393   /** Tests that setting and changing an input listener works correctly. */
394   public void testSetChangeInputListener() {
395     InputListener listener1 = new InputListener() {
396       public String JavaDoc getConsoleInput() { return "input1"; }
397     };
398
399     InputListener listener2 = new InputListener() {
400       public String JavaDoc getConsoleInput() { return "input2"; }
401     };
402
403     try {
404       _model.getConsoleInput();
405       fail("Should not have allowed getting input before a listener is installed!");
406     }
407     catch (IllegalStateException JavaDoc ise) {
408       assertEquals("Should have thrown the correct exception.",
409                    "No input listener installed!", ise.getMessage());
410     }
411
412     _model.setInputListener(listener1);
413     assertEquals("First input listener should return correct input", "input1", _model.getConsoleInput());
414     _model.changeInputListener(listener1, listener2);
415     assertEquals("Second input listener should return correct input", "input2", _model.getConsoleInput());
416   }
417
418   /** Tests that the interactions history is stored correctly. See bug # 992455 */
419   public void testInteractionsHistoryStoredCorrectly() throws EditDocumentException {
420     final Object JavaDoc _lock = new Object JavaDoc();
421     String JavaDoc code = "public class A {\n";
422
423     InteractionsDocument doc = _model.getDocument();
424
425     // Insert text and evaluate
426
doc.insertText(doc.getLength(), code, InteractionsDocument.DEFAULT_STYLE);
427
428     _model.interpretCurrentInteraction();
429     //Simulate result
430
_model.replReturnedSyntaxError("Encountered Unexpected \"<EOF>\"", "public class A {\n", -1, -1, -1, -1);
431
432     assertEquals("Current interaction should still be there - should not have interpreted", "public class A {\n" + System.getProperty("line.separator"),
433                  doc.getCurrentInteraction());
434     History h = doc.getHistory();
435     assertEquals("History should be empty", 0, h.size());
436
437     code = "}\n";
438
439     doc.insertText(doc.getLength(), code, InteractionsDocument.DEFAULT_STYLE);
440
441     synchronized(_lock) {
442       _model.interpretCurrentInteraction();
443       _model.replReturnedVoid();
444     }
445
446     synchronized(_lock) {
447       assertEquals("Current interaction should not be there - should have interpreted", "", doc.getCurrentInteraction());
448       assertEquals("History should contain one interaction", 1, h.size());
449     }
450   }
451
452   /** A generic InteractionsModel for testing purposes. (Used here and in InteractionsPaneTest.) */
453   public static class TestInteractionsModel extends InteractionsModel {
454     String JavaDoc toEval = null;
455     String JavaDoc addedClass = null;
456
457     /** Constructs a new InteractionsModel. */
458     public TestInteractionsModel(InteractionsDJDocument adapter) {
459       // Adapter, history size, write delay
460
super(adapter, new File JavaDoc(System.getProperty("user.dir")), 1000, 25);
461     }
462
463     protected void _interpret(String JavaDoc toEval) { this.toEval = toEval; }
464     
465     public String JavaDoc getVariableToString(String JavaDoc var) {
466       fail("cannot getVariableToString in a test");
467       return null;
468     }
469     public String JavaDoc getVariableClassName(String JavaDoc var) {
470       fail("cannot getVariableClassName in a test");
471       return null;
472     }
473     
474     public void addProjectClassPath(URL JavaDoc path) { fail("cannot add to classpath in a test"); }
475     public void addBuildDirectoryClassPath(URL JavaDoc path) { fail("cannot add to classpath in a test"); }
476     public void addProjectFilesClassPath(URL JavaDoc path) { fail("cannot add to classpath in a test"); }
477     public void addExternalFilesClassPath(URL JavaDoc path) { fail("cannot add to classpath in a test"); }
478     public void addExtraClassPath(URL JavaDoc path) { fail("cannot add to classpath in a test"); }
479     protected void _resetInterpreter(File JavaDoc wd) { fail("cannot reset interpreter in a test"); }
480     
481     protected void _notifyInteractionStarted() { }
482     protected void _notifyInteractionEnded() { }
483     protected void _notifySyntaxErrorOccurred(int offset, int length) { }
484     protected void _notifyInterpreterExited(int status) { }
485     protected void _notifyInterpreterResetting() { }
486     protected void _notifyInterpreterResetFailed(Throwable JavaDoc t) { }
487     public void _notifyInterpreterReady(File JavaDoc wd) { }
488     protected void _interpreterResetFailed(Throwable JavaDoc t) { }
489     protected void _notifyInteractionIncomplete() { }
490     protected void _notifySlaveJVMUsed() { }
491     public ConsoleDocument getConsoleDocument() { return null; }
492   }
493   
494   /** This test model includes a slave JVM, just like a DefaultGlobalModel. It must be disposed before it is
495    * deallocated to kill the slave JVM. TODO: the mutation in this class is disgusting -- Corky 2 June 06.
496    */

497   private static class IncompleteInputInteractionsModel extends RMIInteractionsModel {
498     boolean continuationException; // This appears to be the negation of syntaxException making it redundant!
499
boolean syntaxException;
500     
501     private volatile boolean _interactionDone = false;
502     private final Object JavaDoc _interactionLock = new Object JavaDoc();
503     
504     public void _logInteractionStart() { _interactionDone = false; }
505     
506     public void _waitInteractionDone() throws InterruptedException JavaDoc {
507       synchronized(_interactionLock) { while (! _interactionDone) _interactionLock.wait(); }
508     }
509
510     /** Constructs a new IncompleteInputInteractionsModel. */
511     public IncompleteInputInteractionsModel(InteractionsDJDocument adapter) {
512       // MainJVM, Adapter, history size, write delay
513
super(new MainJVM(null), adapter, new File JavaDoc(System.getProperty("user.dir")), 1000, 25);
514       _jvm.setInteractionsModel(this); // _jvm is set to MainJVM(null) by super call;
515
_jvm.startInterpreterJVM();
516       continuationException = false;
517       syntaxException = false;
518     }
519     
520     protected void _notifyInteractionStarted() { }
521     protected void _notifyInteractionEnded() {
522       _log.log("_notifyInteractionEnded called.");
523       synchronized(_interactionLock) {
524         _interactionDone = true;
525         _interactionLock.notify();
526       }
527     }
528     protected void _notifySyntaxErrorOccurred(int offset, int length) { }
529     protected void _notifyInterpreterExited(int status) { }
530     protected void _notifyInterpreterResetting() { }
531     protected void _notifyInterpreterResetFailed(Throwable JavaDoc t) { }
532     public void _notifyInterpreterReady(File JavaDoc wd) { }
533     protected void _interpreterResetFailed(Throwable JavaDoc t) { }
534     protected void _notifyInteractionIncomplete() { _notifyInteractionEnded(); }
535     protected void _notifyInterpreterChanged(boolean inProgress) { }
536     protected void _notifySlaveJVMUsed() { }
537     
538     public void dispose() throws RemoteException JavaDoc { _jvm.dispose(); }
539     
540     public ConsoleDocument getConsoleDocument() { return null; }
541
542     public void replThrewException(String JavaDoc exceptionClass, String JavaDoc message, String JavaDoc stackTrace, String JavaDoc shortMessage) {
543       _log.log("replThrewException called");
544       if (shortMessage != null) {
545         if (shortMessage.endsWith("<EOF>\"")) {
546           continuationException = true;
547           syntaxException = false;
548           _interactionIsOver();
549           return;
550         }
551       }
552       syntaxException = true;
553       continuationException = false;
554       _interactionIsOver();
555     }
556
557     public void replReturnedSyntaxError(String JavaDoc errorMessage, String JavaDoc interaction, int startRow, int startCol, int endRow,
558                                         int endCol) {
559       _log.log("replReturnedSyntaxError called");
560       if (errorMessage != null) {
561         if (errorMessage.endsWith("<EOF>\"")) {
562           continuationException = true;
563           syntaxException = false;
564           _interactionIsOver();
565           return;
566         }
567       }
568       syntaxException = true;
569       continuationException = false;
570       _interactionIsOver();
571     }
572
573     public boolean isContinuationException() { return continuationException; }
574     public boolean isSyntaxException() { return syntaxException; }
575   }
576   
577 // public class TestInteractionsListener extends DummyInteractionsListener {
578
// private volatile boolean _interactionDone = false; // records when the interaction is done
579
// private final Object _interactionLock = new Object(); // lock for _interactionDone
580
//
581
// /** Relying on the default constructor. */
582
//
583
// public void interactionEnded() {
584
// synchronized(_interactionLock) {
585
// _interactionDone = true;
586
// _interactionLock.notify();
587
// }
588
// }
589
// public void logInteractionStart() { _interactionDone = false; }
590
//
591
// public void waitInteractionDone() throws InterruptedException {
592
// synchronized(_interactionLock) { while (! _interactionDone) _interactionLock.wait(); }
593
// }
594
// }
595
}
596
Popular Tags