Clover coverage report - DrJava Test Coverage (drjava-20110828-r5448)
Coverage timestamp: Sun Aug 28 2011 03:13:33 CDT
file stats: LOC: 241   Methods: 20
NCLOC: 87   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DefaultPlatform.java 0% 9.8% 30% 14.5%
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.platform;
 38   
 39    import edu.rice.cs.drjava.DrJava;
 40    import edu.rice.cs.drjava.config.Configuration;
 41    import edu.rice.cs.drjava.config.OptionConstants;
 42   
 43    import edu.rice.cs.util.ArgumentTokenizer;
 44    import edu.rice.cs.util.FileOps;
 45    import edu.rice.cs.util.StringOps;
 46   
 47    import javax.swing.*;
 48    import java.io.File;
 49    import java.net.URL;
 50    import java.util.List;
 51   
 52    /** Default platform-neutral implementation of PlatformSupport. Most implementations
 53    * will extend this class to inherit default behaviors.
 54    * @version $Id: DefaultPlatform.java 5436 2011-08-02 06:58:19Z mgricken $
 55    */
 56    class DefaultPlatform implements PlatformSupport {
 57    /** Singleton instance. */
 58    public static DefaultPlatform ONLY = new DefaultPlatform();
 59   
 60    /** Private constructor for singleton pattern. */
 61  299 protected DefaultPlatform() { }
 62   
 63    /** Utility method to determine if the current Swing look and feel is the platform-specific look and feel for the
 64    * client platform.
 65    * @return true if current Swing look and feel is the system look and feel
 66    */
 67  0 public boolean isUsingSystemLAF() {
 68  0 String sysLAF = UIManager.getSystemLookAndFeelClassName();
 69  0 String curLAF = UIManager.getLookAndFeel().getClass().getName();
 70  0 return (sysLAF.equals(curLAF));
 71    }
 72   
 73    /** Hook for performing general UI setup. Called before all other UI setup is done. The default implementation
 74    * does nothing.
 75    */
 76  0 public void beforeUISetup() { }
 77   
 78    /** Hook for performing general UI setup. Called after all other UI setup is done. The default implementation
 79    * does nothing.
 80    *
 81    * @param about the Action associated with openning the About dialog
 82    * @param prefs the Action associated with openning the Preferences dialog
 83    * @param quit the Action associated with quitting the DrJava application
 84    */
 85  38 public void afterUISetup(Action about, Action prefs, Action quit) { }
 86   
 87    /** Returns whether this is a Mac OS X platform. */
 88  12361 public boolean isMacPlatform() { return false; }
 89   
 90    /** Returns whether this is a Windows platform. */
 91  388 public boolean isWindowsPlatform() { return false; }
 92   
 93    /** Returns the current Java specification version. */
 94  0 public String getJavaSpecVersion() {
 95  0 return System.getProperty("java.specification.version");
 96    }
 97   
 98    /** Returns true if the given class object for com.sun.tools.javadoc.Main
 99    * has an execute(String[]) method. If so, that means we have a 1.4
 100    * version of tools.jar.
 101    *
 102    * @param main Class object for com.sun.tools.javadoc.Main
 103    */
 104  0 @SuppressWarnings({"unchecked", "rawtypes"})
 105    private boolean _javadocMainHasExecuteMethod(Class<?> main) {
 106  0 try {
 107  0 Class<String[]>[] arr = new Class[]{String[].class};
 108  0 main.getMethod("execute", arr);
 109  0 return true;
 110    }
 111  0 catch (Throwable t) { return false; }
 112    }
 113   
 114    /** Utility method for opening a URL in a browser in a platform-specific way.
 115    * The default implementation uses Runtime.exec to execute a command specified
 116    * in Preferences. Platform implementations should attempt the default method
 117    * first, then try to use a "default browser", if such a thing exists on the
 118    * specific platform.
 119    *
 120    * @param address the URL to open
 121    * @return true if the URL was successfully handled, false otherwise
 122    */
 123  0 public boolean openURL(URL address) {
 124    // Get the two config options.
 125  0 Configuration config = DrJava.getConfig();
 126  0 File exe = config.getSetting(OptionConstants.BROWSER_FILE);
 127  0 String command = config.getSetting(OptionConstants.BROWSER_STRING);
 128   
 129    // Check for empty settings.
 130  0 if ((exe == FileOps.NULL_FILE) && (command.equals(""))) {
 131    // If the user hasn't specified anything, don't try to run it.
 132  0 return false;
 133    }
 134    else {
 135  0 String addr = address.toString();
 136  0 if (command.equals("")) {
 137    // If there is no command, simply use the URL.
 138  0 command = addr;
 139    }
 140    else {
 141    // Otherwise, replace any <URL> tags in the command with the address.
 142  0 String tag = "<URL>";
 143  0 if (command.indexOf(tag) != -1) {
 144  0 command = StringOps.replace(command, tag, addr);
 145    }
 146    else {
 147    // No <URL> specified, so tack it onto the end.
 148  0 command = command + " " + addr;
 149    }
 150    }
 151   
 152    // Build a string array of command and arguments.
 153  0 List<String> args = ArgumentTokenizer.tokenize(command);
 154   
 155    // Prepend the file only if it exists.
 156  0 if (exe != FileOps.NULL_FILE) args.add(0, exe.getAbsolutePath());
 157   
 158    // Call the command.
 159  0 try {
 160    // Process proc =
 161  0 Runtime.getRuntime().exec(args.toArray(new String[args.size()]));
 162    }
 163    catch (Throwable t) {
 164    // If there was any kind of problem, ignore it and report failure.
 165  0 return false;
 166    }
 167    }
 168   
 169    // Otherwise, trust that it worked.
 170  0 return true;
 171    }
 172   
 173    /** Set the keyboard mnemonic for the component in a way that is consistent with
 174    * the current platform.
 175    * @param obj the component whose mnemonic should be set
 176    * @param mnemonic the key code which represents the mnemonic
 177    * @see javax.swing.AbstractButton#setMnemonic(int)
 178    * @see java.awt.event.KeyEvent */
 179  284 public void setMnemonic(javax.swing.AbstractButton obj, int mnemonic) {
 180    // by default just set the object's mnemonic
 181  284 obj.setMnemonic(mnemonic);
 182    }
 183   
 184    /** Set the keyboard mnemonic for the component in a way that is consistent with
 185    * the current platform.
 186    * @param obj the component whose mnemonic should be set
 187    * @param mnemonic a char specifying the mnemonic value
 188    * @see javax.swing.AbstractButton#setMnemonic(char) */
 189  0 public void setMnemonic(javax.swing.AbstractButton obj, char mnemonic) {
 190    // by default just set the object's mnemonic
 191  0 obj.setMnemonic(mnemonic);
 192    }
 193   
 194    /** Set the keyboard mnemonic for the component in a way that is consistent with
 195    * the current platform.
 196    * @param obj the component whose mnemonic should be set
 197    * @param mnemonic the key code which represents the mnemonic
 198    * @see javax.swing.ButtonModel#setMnemonic(int)
 199    * @see java.awt.event.KeyEvent */
 200  0 public void setMnemonic(javax.swing.ButtonModel obj, int mnemonic) {
 201    // by default just set the object's mnemonic
 202  0 obj.setMnemonic(mnemonic);
 203    }
 204   
 205    /** Set the keyboard mnemonic for the component in a way that is consistent with
 206    * the current platform.
 207    * @param obj the component whose mnemonic should be set
 208    * @param tabIndex the index of the tab that the mnemonic refers to
 209    * @param mnemonic the key code which represents the mnemonic
 210    * @see javax.swing.JTabbedPane#setMnemonicAt(int,int)
 211    * @see java.awt.event.KeyEvent */
 212  0 public void setMnemonicAt(javax.swing.JTabbedPane obj, int tabIndex, int mnemonic) {
 213    // by default just set the object's mnemonic
 214  0 obj.setMnemonicAt(tabIndex, mnemonic);
 215    }
 216   
 217    /** @return true if file extensions can be registered and unregistered. */
 218  76 public boolean canRegisterFileExtensions() { return false; }
 219   
 220    /** Register .drjava and .djapp file extensions.
 221    * @return true if registering succeeded */
 222  0 public boolean registerDrJavaFileExtensions() { return false; }
 223   
 224    /** Unregister .drjava and .djapp file extensions.
 225    * @return true if unregistering succeeded */
 226  0 public boolean unregisterDrJavaFileExtensions() { return false; }
 227   
 228    /** @return true if .drjava and .djapp file extensions are registered. */
 229  0 public boolean areDrJavaFileExtensionsRegistered() { return false; }
 230   
 231    /** Register .java file extension.
 232    * @return true if registering succeeded */
 233  0 public boolean registerJavaFileExtension() { return false; }
 234   
 235    /** Unregister .java file extension.
 236    * @return true if unregistering succeeded */
 237  0 public boolean unregisterJavaFileExtension() { return false; }
 238   
 239    /** @return true if .java file extension is registered. */
 240  0 public boolean isJavaFileExtensionRegistered() { return false; }
 241    }