Clover coverage report - DrJava Test Coverage (drjava-20120304-r5456)
Coverage timestamp: Sun Mar 4 2012 03:13:23 CST
file stats: LOC: 265   Methods: 30
NCLOC: 167   Classes: 4
 
 Source file Conditionals Statements Methods TOTAL
MainFrameStatics.java 61.1% 56.3% 43.3% 53.8%
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.util.swing.Utilities;
 40    import edu.rice.cs.drjava.model.DrJavaFileUtils;
 41    import edu.rice.cs.drjava.project.MalformedProjectFileException;
 42    import edu.rice.cs.drjava.model.debug.DebugException;
 43    import edu.rice.cs.util.UnexpectedException;
 44    import edu.rice.cs.util.StringOps;
 45   
 46    import edu.rice.cs.drjava.model.OpenDefinitionsDocument;
 47   
 48    import javax.swing.*;
 49    import java.awt.*;
 50    import java.io.*;
 51    import java.net.URL;
 52   
 53    import static edu.rice.cs.plt.object.ObjectUtil.hash;
 54   
 55    /** Utilities for DrJava's main window. */
 56    public class MainFrameStatics {
 57   
 58    /** Propose to the user to change the extension of the file.
 59    * @param parent parent GUI component
 60    * @param input input file
 61    * @param title dialog title
 62    * @param message dialog message
 63    * @param changeButton text for the "yes, change it!" button
 64    * @param keepButton text for the "no, leave it!" button
 65    * @param newExt new extension if changed
 66    */
 67  1 public static File proposeToChangeExtension(Component parent, File input,
 68    String title,
 69    String message,
 70    String changeButton,
 71    String keepButton,
 72    String newExt) {
 73  1 Object[] options = {changeButton, keepButton};
 74  1 int rc = 1;
 75  1 if (!Utilities.TEST_MODE) {
 76  0 rc = JOptionPane.showOptionDialog(parent, message, title, JOptionPane.YES_NO_OPTION,
 77    JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
 78    }
 79  1 if (rc == 0) {
 80  0 try {
 81  0 String fileName = DrJavaFileUtils.removeExtension(input.getCanonicalPath()) + newExt;
 82  0 File file = new File(fileName);
 83  0 return file;
 84    }
 85  0 catch(IOException ioe) { showIOError(parent, ioe); }
 86    }
 87  1 return input;
 88    }
 89   
 90    /** Confirms with the user that the file should be overwritten.
 91    * @param f file to overwrite
 92    * @return <code>true</code> iff the user accepts overwriting.
 93    */
 94  0 public static boolean verifyOverwrite(Component parent, File f) {
 95  0 Object[] options = {"Yes","No"};
 96  0 int n = JOptionPane.showOptionDialog(parent,
 97    "<html>This file already exists. Do you wish to overwrite the file?<br>"+
 98    f.getPath()+"<html>",
 99    "Confirm Overwrite",
 100    JOptionPane.YES_NO_OPTION,
 101    JOptionPane.QUESTION_MESSAGE,
 102    null,
 103    options,
 104    options[1]);
 105  0 return (n == JOptionPane.YES_OPTION);
 106    }
 107   
 108  0 public static void showProjectFileParseError(Component parent, MalformedProjectFileException mpfe) {
 109  0 showError(parent, "Invalid Project File", "DrJava could not read the given project file.");
 110    }
 111   
 112  0 public static void showFileNotFoundError(Component parent, FileNotFoundException fnf) {
 113  0 showErrorWithMessageIfAvailable(parent, fnf, "File Not Found",
 114    "The specified file was not found on disk.");
 115    }
 116   
 117  0 public static void showIOError(Component parent, IOException ioe) {
 118  0 showErrorWithMessageIfAvailable(parent, ioe, "Input/output error",
 119    "An I/O exception occurred during the last operation.");
 120    }
 121   
 122  0 public static void showErrorWithMessageIfAvailable(Component parent, Throwable e, String title, String message) {
 123  0 if ((null != e.getMessage()) && (e.getMessage().length() > 0)) {
 124  0 showError(parent, title, message+"\n"+e.getMessage());
 125    }
 126    else {
 127  0 showError(parent, e, title, message);
 128    }
 129    }
 130   
 131  0 public static void showClassNotFoundError(Component parent, ClassNotFoundException cnfe) {
 132  0 showError(parent, cnfe, "Class Not Found",
 133    "A ClassNotFound exception occurred during the last operation.\n" +
 134    "Please check that your classpath includes all relevant directories.\n\n");
 135    }
 136   
 137  0 public static void showNoClassDefError(Component parent, NoClassDefFoundError ncde) {
 138  0 showError(parent, ncde, "No Class Def",
 139    "A NoClassDefFoundError occurred during the last operation.\n" +
 140    "Please check that your classpath includes all relevant paths.\n\n");
 141    }
 142   
 143  0 public static void showDebugError(Component parent, DebugException de) {
 144  0 showError(parent, de, "Debug Error", "A Debugger error occurred in the last operation.\n\n");
 145    }
 146   
 147  0 public static void showJUnitInterrupted(Component parent, UnexpectedException e) {
 148  0 showWarning(parent, e.getCause(), "JUnit Testing Interrupted",
 149    "The slave JVM has thrown a RemoteException probably indicating that it has been reset.\n\n");
 150    }
 151   
 152  0 public static void showJUnitInterrupted(Component parent, String message) {
 153  0 JOptionPane.showMessageDialog(parent, message, "JUnit Testing Interrupted", JOptionPane.WARNING_MESSAGE);
 154    }
 155   
 156  0 public static void showError(Component parent, Throwable e, String title, String message) {
 157  0 JOptionPane.showMessageDialog(parent, message + "\n" + e + "\n"+ StringOps.getStackTrace(e),
 158    title, JOptionPane.ERROR_MESSAGE);
 159    }
 160   
 161  0 public static void showError(Component parent, String title, String message) {
 162  0 JOptionPane.showMessageDialog(parent, message, title, JOptionPane.ERROR_MESSAGE);
 163    }
 164   
 165  0 public static void showWarning(Component parent, Throwable e, String title, String message) {
 166  0 JOptionPane.showMessageDialog(parent, message + "\n" + e, title, JOptionPane.WARNING_MESSAGE);
 167    }
 168   
 169    public static abstract class AutoCompletePopupEntry implements Comparable<AutoCompletePopupEntry> {
 170    /** Return the simple class name, e.g. "Integer". */
 171    public abstract String getClassName();
 172    /** Return the full package including the last period, e.g. "java.lang.". */
 173    public abstract String getFullPackage();
 174    /** Return the OpenDefinitionsDocument associated with this entry, or null if none. */
 175    public abstract OpenDefinitionsDocument getOpenDefinitionsDocument();
 176   
 177  6 public int compareTo(AutoCompletePopupEntry other) {
 178  6 int res = getClassName().toLowerCase().compareTo(other.getClassName().toLowerCase());
 179  6 if (res != 0) { return res; }
 180  0 return getFullPackage().toLowerCase().compareTo(other.getFullPackage().toLowerCase());
 181    }
 182    // WARNING: this relation is finer grained that the equivalance relation induced by compareTo above
 183  32 public boolean equals(Object other) {
 184  16 if (other == null || ! (other instanceof AutoCompletePopupEntry)) return false; // multiple subclasses defined
 185  16 AutoCompletePopupEntry o = (AutoCompletePopupEntry) other;
 186  16 return (getClassName().equals(o.getClassName()) && getFullPackage().equals(o.getFullPackage()));
 187    }
 188  3279 public int hashCode() { return hash(getClassName(), getFullPackage()); }
 189    }
 190   
 191    /** Wrapper class for the "Go to File" dialog list entries.
 192    * Provides the ability to have the same OpenDefinitionsDocument in there multiple
 193    * times with different toString() results.
 194    */
 195    public static class GoToFileListEntry extends AutoCompletePopupEntry {
 196    private final OpenDefinitionsDocument doc;
 197    private String fullPackage = null;
 198    private final String str;
 199  13 public GoToFileListEntry(OpenDefinitionsDocument d, String s) {
 200  13 doc = d;
 201  13 str = s;
 202    }
 203  32 public String getFullPackage() {
 204  28 if (fullPackage != null) { return fullPackage; }
 205  4 fullPackage = "";
 206  4 if (doc != null) {
 207  1 try {
 208  1 fullPackage = doc.getPackageName();
 209  0 if (fullPackage.length() > 0) { fullPackage += '.'; }
 210    }
 211  0 catch(Exception e) { fullPackage = ""; }
 212    }
 213  4 return fullPackage;
 214    }
 215  44 public String getClassName() { return str; }
 216  1311 public String toString() { return str; }
 217  68 public OpenDefinitionsDocument getOpenDefinitionsDocument() { return doc; }
 218    }
 219   
 220    /** Wrapper class for the "Open Javadoc" and "Auto Import" dialog list entries.
 221    * Provides the ability to have the same class name in there multiple times in different packages.
 222    */
 223    public static class JavaAPIListEntry extends AutoCompletePopupEntry {
 224    private final String str, fullStr;
 225    private final URL url;
 226  3279 public JavaAPIListEntry(String s, String full, URL u) {
 227  3279 str = s;
 228  3279 fullStr = full;
 229  3279 url = u;
 230    }
 231  0 public String toString() { return str; }
 232  0 public String getFullString() { return fullStr; }
 233  0 public URL getURL() { return url; }
 234  3279 public String getClassName() { return str; }
 235  3279 public String getFullPackage() {
 236  3279 int pos = fullStr.lastIndexOf('.');
 237  3279 if (pos>=0) { return fullStr.substring(0,pos+1); }
 238  0 return "";
 239    }
 240  0 public OpenDefinitionsDocument getOpenDefinitionsDocument() { return null; }
 241    }
 242   
 243    /** Returns a JRadioButtonMenuItem that looks like a JCheckBoxMenuItem. This is a workaround for a known
 244    * bug on OS X's version of Java. (See http://developer.apple.com/qa/qa2001/qa1154.html)
 245    * @param action Action for the menu item
 246    * @return JRadioButtonMenuItem with a checkbox icon
 247    */
 248  152 public static JMenuItem newCheckBoxMenuItem(Action action) {
 249  152 String RADIO_ICON_KEY = "RadioButtonMenuItem.checkIcon";
 250  152 String CHECK_ICON_KEY = "CheckBoxMenuItem.checkIcon";
 251   
 252    // Store the default radio button icon to put back later
 253  152 Object radioIcon = UIManager.get(RADIO_ICON_KEY);
 254   
 255    // Replace radio button's checkIcon with that of JCheckBoxMenuItem
 256    // so that our menu item looks like a checkbox
 257  152 UIManager.put(RADIO_ICON_KEY, UIManager.get(CHECK_ICON_KEY));
 258  152 JRadioButtonMenuItem pseudoCheckBox = new JRadioButtonMenuItem(action);
 259   
 260    // Put original radio button checkIcon back.
 261  152 UIManager.put(RADIO_ICON_KEY, radioIcon);
 262   
 263  152 return pseudoCheckBox;
 264    }
 265    }