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