Clover coverage report - DrJava Test Coverage (drjava-20110828-r5448)
Coverage timestamp: Sun Aug 28 2011 03:13:33 CDT
file stats: LOC: 232   Methods: 14
NCLOC: 131   Classes: 3
 
 Source file Conditionals Statements Methods TOTAL
CompilerErrorPanel.java 25% 64.8% 78.6% 60.4%
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.ui;
 38   
 39    import edu.rice.cs.drjava.DrJava;
 40    import edu.rice.cs.drjava.config.OptionConstants;
 41    import edu.rice.cs.drjava.config.OptionEvent;
 42    import edu.rice.cs.drjava.config.OptionListener;
 43    import edu.rice.cs.drjava.model.SingleDisplayModel;
 44    import edu.rice.cs.drjava.model.compiler.CompilerModel;
 45    import edu.rice.cs.drjava.model.compiler.CompilerErrorModel;
 46    import edu.rice.cs.drjava.model.compiler.CompilerInterface;
 47    import edu.rice.cs.util.UnexpectedException;
 48    import edu.rice.cs.plt.iter.IterUtil;
 49   
 50    import javax.swing.*;
 51    import javax.swing.text.BadLocationException;
 52    import javax.swing.text.Position;
 53    import java.awt.*;
 54    import java.awt.event.ItemEvent;
 55    import java.awt.event.ItemListener;
 56    import java.io.File;
 57    import java.util.Vector;
 58   
 59    /** The panel which houses the list of errors after an unsuccessful compilation. If the user clicks on the combobox,
 60    * it moves the definitions cursor to the error in the source. If the cursor is moved onto a line with an error, it
 61    * selects the appropriate error in the list but do not move the cursor.
 62    * @version $Id: CompilerErrorPanel.java 5439 2011-08-11 17:13:04Z rcartwright $
 63    */
 64    public class CompilerErrorPanel extends ErrorPanel {
 65   
 66    /** Whether a compile has occurred since the last compiler change. */
 67    private volatile boolean _compileHasOccurred;
 68    private volatile CompilerErrorListPane _errorListPane;
 69    private final JComboBox _compilerChoiceBox;
 70   
 71    /** The list of files from the last compilation unit that were not compiled because they were not source files. */
 72    private volatile File[] _excludedFiles = new File[0];
 73   
 74    /** Constructor.
 75    * @param model SingleDisplayModel in which we are running
 76    * @param frame MainFrame in which we are displayed
 77    */
 78  38 public CompilerErrorPanel(SingleDisplayModel model, MainFrame frame) {
 79  38 super(model, frame, "Compiler Output", "Compiler");
 80  38 _compileHasOccurred = false;
 81  38 _numErrors = 0;
 82   
 83  38 _errorListPane = new CompilerErrorListPane();
 84  38 setErrorListPane(_errorListPane);
 85   
 86   
 87    /******** Initialize the drop-down compiler menu ********/
 88    // Limitation: Only compiler choices are those that were available
 89    // at the time this box was created.
 90    // Also: The UI will go out of sync with reality if the active compiler
 91    // is later changed somewhere else. This is because there is no way
 92    // to listen on the active compiler.
 93  38 final CompilerModel compilerModel = getModel().getCompilerModel();
 94  38 Iterable<CompilerInterface> iter = getModel().getCompilerModel().getAvailableCompilers();
 95  38 _compilerChoiceBox = new JComboBox(IterUtil.toArray(iter, CompilerInterface.class));
 96  38 _compilerChoiceBox.setEditable(false);
 97  38 _compilerChoiceBox.setSelectedItem(compilerModel.getActiveCompiler());
 98  38 _compilerChoiceBox.addItemListener(new ItemListener() {
 99  0 public void itemStateChanged(ItemEvent e) {
 100  0 if (e.getStateChange() == ItemEvent.SELECTED) {
 101  0 final CompilerInterface compiler = (CompilerInterface) _compilerChoiceBox.getSelectedItem();
 102  0 compilerModel.resetCompilerErrors();
 103  0 _compileHasOccurred = false;
 104    // set the new compiler (and reset the interactions pane) in a separate thread
 105    // to address [ drjava-Bugs-2985291 ] Delay in GUI when selecting compiler
 106  0 new Thread(new Runnable() {
 107  0 public void run() {
 108  0 compilerModel.setActiveCompiler(compiler);
 109  0 reset();
 110    }
 111    }).start();
 112    }
 113    }
 114    });
 115   
 116  38 customPanel.add(_compilerChoiceBox, BorderLayout.NORTH);
 117   
 118  38 DrJava.getConfig().addOptionListener(OptionConstants.JAVAC_LOCATION, new CompilerLocationOptionListener<File>());
 119  38 DrJava.getConfig().addOptionListener(OptionConstants.EXTRA_COMPILERS, new CompilerLocationOptionListener<Vector<String>>());
 120    }
 121   
 122   
 123    /** The OptionListener for compiler LOCATIONs */
 124    private class CompilerLocationOptionListener<T> implements OptionListener<T> {
 125   
 126  0 public void optionChanged(OptionEvent<T> oce) {
 127  0 _compilerChoiceBox.removeAllItems();
 128  0 for (CompilerInterface c : getModel().getCompilerModel().getAvailableCompilers()) {
 129  0 _compilerChoiceBox.addItem(c);
 130    }
 131    }
 132    }
 133   
 134    /** Returns the CompilerErrorListPane that this panel manages. */
 135  84 public CompilerErrorListPane getErrorListPane() { return _errorListPane; }
 136   
 137    /** Called when compilation begins. */
 138  1 public void setCompilationInProgress() {
 139  1 _errorListPane.setCompilationInProgress();
 140    }
 141   
 142  17 public CompilerErrorModel getErrorModel() { return getModel().getCompilerModel().getCompilerErrorModel(); }
 143   
 144    /** Clean up when the tab is closed. */
 145  4 @Override
 146    protected void _close() {
 147  4 super._close();
 148  4 getModel().getCompilerModel().resetCompilerErrors();
 149  4 reset();
 150    }
 151   
 152    /** Reset the errors to the current error information immediately following compilation. */
 153  1 public void reset(File[] excludedFiles) {
 154  1 _excludedFiles = excludedFiles;
 155  1 reset();
 156    }
 157   
 158    /** Reset the errors to the current error information. */
 159  43 public void reset() {
 160    // _nextErrorButton.setEnabled(false);
 161    // _prevErrorButton.setEnabled(false);
 162    // Utilities.showDebug("Reset being called by CompilerErrorPanel");
 163  43 _numErrors = getModel().getCompilerModel().getNumErrors();
 164   
 165  43 _errorListPane.updateListPane(true);
 166    // _nextErrorButton.setEnabled(_errorListPane.hasNextError());
 167    // _prevErrorButton.setEnabled(_errorListPane.hasPrevError());
 168    }
 169   
 170    class CompilerErrorListPane extends ErrorPanel.ErrorListPane {
 171   
 172  1 protected void _updateWithErrors() throws BadLocationException {
 173  1 ErrorDocument doc = new ErrorDocument(getErrorDocumentTitle());
 174  1 if (_excludedFiles.length != 0) {
 175  0 final StringBuilder msgBuffer =
 176    new StringBuilder("Compilation completed. The following files were not compiled:\n");
 177  0 for (File f: _excludedFiles) {
 178  0 if (f != null) { msgBuffer.append(" ").append(f).append('\n'); } // do not print files from untitled docs
 179    }
 180  0 doc.append(msgBuffer.toString(), NORMAL_ATTRIBUTES);
 181    }
 182   
 183  1 String failureName = "error";
 184  0 if (getErrorModel().hasOnlyWarnings()) failureName = "warning";
 185   
 186  1 _updateWithErrors(failureName, "found", doc);
 187    }
 188   
 189    /** Puts the error pane into "compilation in progress" state. */
 190  1 public void setCompilationInProgress() {
 191  1 _errorListPositions = new Position[0];
 192  1 _compileHasOccurred = true;
 193   
 194  1 ErrorDocument doc = new ErrorDocument(getErrorDocumentTitle());
 195   
 196  1 try { doc.insertString(0, "Compilation in progress, please wait...", NORMAL_ATTRIBUTES); }
 197  0 catch (BadLocationException ble) { throw new UnexpectedException(ble); }
 198   
 199  1 setDocument(doc);
 200  1 selectNothing();
 201    }
 202   
 203    /** Used to show that the last compile was successful.
 204    * @param done ignored: we assume that this is only called after compilation is completed
 205    */
 206  42 protected void _updateNoErrors(boolean done) throws BadLocationException {
 207  42 ErrorDocument doc = new ErrorDocument(getErrorDocumentTitle());
 208  42 String message;
 209  42 if (_compileHasOccurred) {
 210  0 if (_excludedFiles.length == 0) message = "Compilation completed.";
 211    else {
 212  0 final StringBuilder msgBuffer =
 213    new StringBuilder("Compilation completed. The following files were not compiled:\n");
 214  0 for (File f: _excludedFiles) {
 215  0 if (f != null) { msgBuffer.append(" ").append(f).append('\n'); } // do not print files from untitled docs
 216    }
 217  0 message = msgBuffer.toString();
 218    }
 219    }
 220  42 else if (!getModel().getCompilerModel().getActiveCompiler().isAvailable())
 221  0 message = "No compiler available.";
 222    else
 223  42 message = "Compiler ready: " + getModel().getCompilerModel().getActiveCompiler().getDescription() + ".";
 224   
 225  42 doc.insertString(0, message, NORMAL_ATTRIBUTES);
 226  42 setDocument(doc);
 227  42 _updateScrollButtons();
 228  42 selectNothing();
 229    }
 230  82 public String getErrorDocumentTitle() { return "Compiler Errors"; }
 231    }
 232    }