Clover coverage report - DrJava Test Coverage (drjava-20120304-r5456)
Coverage timestamp: Sun Mar 4 2012 03:13:23 CST
file stats: LOC: 237   Methods: 32
NCLOC: 111   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DefaultInteractionsModel.java - 56.2% 56.2% 56.2%
coverage coverage
 1    /*BEGIN_COPYRIGHT_BLOCK
 2    *
 3    * Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu)
 4    * All rights reserved.
 5    *
 6    * Redistribution and use in source and binary forms, with or without
 7    * modification, are permitted provided that the following conditions are met:
 8    * * Redistributions of source code must retain the above copyright
 9    * notice, this list of conditions and the following disclaimer.
 10    * * Redistributions in binary form must reproduce the above copyright
 11    * notice, this list of conditions and the following disclaimer in the
 12    * documentation and/or other materials provided with the distribution.
 13    * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
 14    * names of its contributors may be used to endorse or promote products
 15    * derived from this software without specific prior written permission.
 16    *
 17    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 19    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 20    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 21    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 22    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 23    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 24    * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 25    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 26    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 27    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28    *
 29    * This software is Open Source Initiative approved Open Source Software.
 30    * Open Source Initative Approved is a trademark of the Open Source Initiative.
 31    *
 32    * This file is part of DrJava. Download the current version of this project
 33    * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
 34    *
 35    * END_COPYRIGHT_BLOCK*/
 36   
 37    package edu.rice.cs.drjava.model.repl;
 38   
 39    import java.io.File;
 40    import java.util.List;
 41    import java.util.ArrayList;
 42   
 43    import edu.rice.cs.drjava.DrJava;
 44    import edu.rice.cs.drjava.config.OptionConstants;
 45    import edu.rice.cs.drjava.config.OptionListener;
 46    import edu.rice.cs.drjava.config.OptionEvent;
 47    import edu.rice.cs.drjava.model.DefaultGlobalModel;
 48    import edu.rice.cs.drjava.model.OpenDefinitionsDocument;
 49    import edu.rice.cs.drjava.model.compiler.LanguageLevelStackTraceMapper;
 50    import edu.rice.cs.drjava.model.repl.newjvm.MainJVM;
 51    import edu.rice.cs.util.StringOps;
 52    import edu.rice.cs.util.text.ConsoleDocument;
 53    import edu.rice.cs.util.text.ConsoleDocumentInterface;
 54    import edu.rice.cs.util.swing.Utilities;
 55   
 56    /** Interactions model which can notify GlobalModelListeners on events.
 57    * TODO: remove invokeLater wrappers here and enforce the policy that all of the listener methods must use them
 58    * @version $Id: DefaultInteractionsModel.java 5237 2010-04-27 07:52:59Z mgricken $
 59    */
 60    public class DefaultInteractionsModel extends RMIInteractionsModel {
 61    /** Message to signal that input is required from the console. */
 62    // public static final String INPUT_REQUIRED_MESSAGE =
 63    // "Please enter input in the Console tab." + _newLine;
 64   
 65    /** Model that contains the interpreter to use. */
 66    protected final DefaultGlobalModel _model;
 67   
 68    /** Creates a new InteractionsModel.
 69    * @param model DefaultGlobalModel to do the interpretation
 70    * @param jvm the RMI interface used by the Main JVM to access the Interpreter JVM
 71    * @param cDoc document
 72    * @param wd the working directory for interactions i/o
 73    */
 74  157 public DefaultInteractionsModel(DefaultGlobalModel model, MainJVM jvm, ConsoleDocumentInterface cDoc, File wd) {
 75  157 super(jvm, cDoc, wd, DrJava.getConfig().getSetting(OptionConstants.HISTORY_MAX_SIZE).intValue(),
 76    WRITE_DELAY);
 77  157 _model = model;
 78    // Set whether to allow "assert" statements to be run in the remote JVM.
 79  157 Boolean allow = DrJava.getConfig().getSetting(OptionConstants.RUN_WITH_ASSERT);
 80  157 _jvm.setAllowAssertions(allow.booleanValue());
 81   
 82    // Add option listeners // WHEN ARE THESE EVER REMOVED?
 83  157 DrJava.getConfig().addOptionListener(OptionConstants.HISTORY_MAX_SIZE, _document.getHistoryOptionListener());
 84  157 DrJava.getConfig().addOptionListener(OptionConstants.RUN_WITH_ASSERT,
 85    new OptionListener<Boolean>() {
 86  0 public void optionChanged(OptionEvent<Boolean> oce) {
 87  0 _jvm.setAllowAssertions(oce.value.booleanValue());
 88    }
 89    });
 90    }
 91   
 92    /** Called when the repl prints to System.out. This method can safely be called from outside the event thread.
 93    * @param s String to print
 94    */
 95  8 public void replSystemOutPrint(String s) {
 96  8 super.replSystemOutPrint(s); // Print s to interactions pane
 97  8 _model.systemOutPrint(s); // Print s to console
 98    }
 99   
 100    /** Called when the repl prints to System.err. This method can safely be called from outside the event thread.
 101    * @param s String to print
 102    */
 103  0 public void replSystemErrPrint(String s) {
 104  0 super.replSystemErrPrint(s);
 105  0 _model.systemErrPrint(s);
 106    }
 107   
 108    /** Returns a line of text entered by the user at the equivalent of System.in. This method may be safely called
 109    * from outside the event thread. */
 110  1 public String getConsoleInput() {
 111  1 String s = super.getConsoleInput();
 112    // System.err.println("Returning '" + s + "' as console input");
 113  1 _model.systemInEcho(s);
 114  1 return s;
 115    }
 116   
 117    /** Any extra action to perform (beyond notifying listeners) when the interpreter fails to reset.
 118    * @param t The Throwable thrown by System.exit
 119    */
 120  0 protected void _interpreterResetFailed(final Throwable t) {
 121  0 Utilities.invokeLater(new Runnable() {
 122  0 public void run() {
 123  0 _document.insertBeforeLastPrompt("Reset Failed! See the console tab for details." + StringOps.NEWLINE,
 124    InteractionsDocument.ERROR_STYLE);
 125    // Print the exception to the console
 126  0 _model.systemErrPrint(StringOps.getStackTrace(t)); // redundantly moves code to event thread
 127    }
 128    });
 129    }
 130   
 131  0 protected void _interpreterWontStart(final Exception e) {
 132  0 Utilities.invokeLater(new Runnable() {
 133  0 public void run() {
 134  0 _document.insertBeforeLastPrompt("JVM failed to start. Make sure a firewall is not blocking " +
 135    StringOps.NEWLINE +
 136    "inter-process communication. See the console tab for details." +
 137    StringOps.NEWLINE,
 138    InteractionsDocument.ERROR_STYLE);
 139    // Print the exception to the console
 140  0 _model.systemErrPrint(StringOps.getStackTrace(e)); // redundantly moves code to event thread
 141    }
 142    });
 143    }
 144   
 145    /** Called when the Java interpreter is ready to use. This method body adds actions that involve the global model.
 146    * This method may run outside the event thread.
 147    */
 148  182 public void interpreterReady(File wd) {
 149  182 _model.resetInteractionsClassPath(); // Done here rather than in the superclass because _model is available here.
 150  182 super.interpreterReady(wd);
 151    }
 152   
 153    /** In the event thread, notifies listeners that an interaction has started. */
 154  35 public void _notifyInteractionStarted() {
 155  35 Utilities.invokeLater(new Runnable() { public void run() { _notifier.interactionStarted(); } });
 156    }
 157   
 158    /** In the event thread, notifies listeners that an interaction has ended. */
 159  33 protected void _notifyInteractionEnded() {
 160  33 Utilities.invokeLater(new Runnable() { public void run() { _notifier.interactionEnded(); } });
 161    }
 162   
 163    /** In the event thread, notifies listeners that an error was present in the interaction. */
 164  0 protected void _notifySyntaxErrorOccurred(final int offset, final int length) {
 165  0 Utilities.invokeLater(new Runnable() { public void run() { _notifier.interactionErrorOccurred(offset,length); } });
 166    }
 167   
 168    /** In the event thread, notifies listeners that the interpreter has changed.
 169    * @param inProgress Whether the new interpreter is currently in progress.
 170    */
 171  1 protected void _notifyInterpreterChanged(final boolean inProgress) {
 172  1 Utilities.invokeLater(new Runnable() { public void run() { _notifier.interpreterChanged(inProgress); } });
 173    }
 174   
 175    /** In the event thread, notifies listeners that the interpreter is resetting. */
 176  21 protected void _notifyInterpreterResetting() {
 177  21 Utilities.invokeLater(new Runnable() { public void run() { _notifier.interpreterResetting(); } });
 178    }
 179   
 180    /** In the event thread, notifies listeners that the interpreter is ready. Sometimes called from outside the event
 181    * thread. */
 182  25 public void _notifyInterpreterReady(final File wd) {
 183    // System.out.println("Asynchronously notifying interpreterReady event listeners"); // DEBUG
 184  25 Utilities.invokeLater(new Runnable() { public void run() { _notifier.interpreterReady(wd); } });
 185    }
 186   
 187    /** In the event thread, notifies listeners that the interpreter has exited unexpectedly.
 188    * @param status Status code of the dead process
 189    */
 190  1 protected void _notifyInterpreterExited(final int status) {
 191  1 Utilities.invokeLater(new Runnable() { public void run() { _notifier.interpreterExited(status); } });
 192    }
 193   
 194    /** In the event thread, notifies listeners that the interpreter reset failed.
 195    * @param t Throwable causing the failure
 196    */
 197  0 protected void _notifyInterpreterResetFailed(final Throwable t) {
 198  0 Utilities.invokeLater(new Runnable() { public void run() { _notifier.interpreterResetFailed(t); } });
 199    }
 200   
 201    /** In the event thread, notifies the view that the current interaction is incomplete. */
 202  0 protected void _notifyInteractionIncomplete() {
 203  0 Utilities.invokeLater(new Runnable() { public void run() { _notifier.interactionIncomplete(); } });
 204    }
 205   
 206  0 public ConsoleDocument getConsoleDocument() { return _model.getConsoleDocument(); }
 207   
 208    /**
 209    * overides method in InteractionModel.java and changes stackTrace for a
 210    * throwable if LL files are present
 211    * @param stackTrace the stack trace to change files name and line number in
 212    * @return stack trace with replaced file name and line number (if throwable occured in a .dj* file)
 213    */
 214  0 public StackTraceElement[] replaceLLException(StackTraceElement[] stackTrace) {
 215    // use LLSTM from compiler model.
 216  0 LanguageLevelStackTraceMapper LLSTM = _model.getCompilerModel().getLLSTM();
 217  0 final List<File> files = new ArrayList<File>();
 218  0 for(OpenDefinitionsDocument odd: _model.getLLOpenDefinitionsDocuments()) { files.add(odd.getRawFile()); }
 219   
 220  0 return (LLSTM.replaceStackTrace(stackTrace,files));
 221    }
 222   
 223    /** A compiler can instruct DrJava to include additional elements for the boot
 224    * class path of the Interactions JVM. */
 225  177 public List<File> getCompilerBootClassPath() {
 226  177 return _model.getCompilerModel().getActiveCompiler().additionalBootClassPathForInteractions();
 227    }
 228   
 229    /** Transform the command line to be interpreted into something the Interactions JVM can use.
 230    * This replaces "java MyClass a b c" with Java code to call MyClass.main(new String[]{"a","b","c"}).
 231    * "import MyClass" is not handled here.
 232    * @param interactionsString unprocessed command line
 233    * @return command line with commands transformed */
 234  35 public String transformCommands(String interactionsString) {
 235  35 return _model.getCompilerModel().getActiveCompiler().transformCommands(interactionsString);
 236    }
 237    }