Clover coverage report - DrJava Test Coverage (drjava-20120304-r5456)
Coverage timestamp: Sun Mar 4 2012 03:13:23 CST
file stats: LOC: 127   Methods: 13
NCLOC: 39   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Configuration.java 50% 83.3% 69.2% 76.9%
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.config;
 38   
 39    import java.io.StringWriter;
 40    import java.io.PrintWriter;
 41    import edu.rice.cs.util.swing.Utilities;
 42   
 43    /** Class to store and retrieve all configurable options.
 44    * @version $Id: Configuration.java 5232 2010-04-24 00:14:05Z mgricken $
 45    */
 46    public class Configuration {
 47   
 48    /** OptionMap used to store all option settings. */
 49    protected volatile OptionMap map;
 50   
 51    /** Any exception that is caught when initializing this Configuration object.
 52    * Used later by the UI to display a useful message to the user.
 53    */
 54    protected volatile Exception _startupException;
 55   
 56    /** Initializes this Configuration object with the given OptionMap.
 57    * @param om An empty OptionMap.
 58    */
 59  1650 public Configuration(OptionMap om) {
 60  1650 map = om;
 61  1650 _startupException = null;
 62    }
 63   
 64    /** Sets the given option to the given value and notifies all listeners of that option of the change.
 65    * @param op Option to set
 66    * @param value New value for the option
 67    */
 68  877 public <T> T setSetting(final Option<T> op, final T value) {
 69  877 T ret = map.setOption(op, value);
 70    // System.err.println("setSetting(" + op + ", " + value + ") called");
 71  877 Utilities.invokeLater(new Runnable() { public void run() { op.notifyListeners(Configuration.this, value); } });
 72  877 return ret;
 73    }
 74   
 75    /** Gets the current value of the given Option. */
 76  64433 public <T> T getSetting(Option<T> op) { return map.getOption(op); }
 77   
 78    /** By default, all options are editable. */
 79  104494 public <T> boolean isEditable(Option<T> op) { return true; }
 80   
 81    /** Adds an OptionListener to the given Option, to be notified each time the option changes.
 82    * @param op Option to listen for changes on
 83    * @param l OptionListener wishing to listen
 84    */
 85  0 public <T> void addOptionListener(Option<T> op, OptionListener<T> l) { op.addListener(this,l); }
 86   
 87    /** Removes an OptionListener from an Option to which it was listening. */
 88  0 public <T> void removeOptionListener(Option<T> op, OptionListener<T> l) { op.removeListener(this,l); }
 89   
 90    /** Resets to the default values, overwriting any existing values. */
 91  232 public void resetToDefaults() { OptionMapLoader.DEFAULT.loadInto(map); }
 92   
 93    /** Returns whether there were any exceptions when starting. */
 94  38 public boolean hadStartupException() { return _startupException != null; }
 95   
 96    /** Returns the exception caught during startUp, or null if none were caught. */
 97  0 public Exception getStartupException() { return _startupException; }
 98   
 99    /** Stores exception caught during creation of this Configuration object, so it can be displayed later by the UI.
 100    * @param e Exception caught during startUp
 101    */
 102  0 public void storeStartupException(Exception e) { _startupException = e; }
 103   
 104    /** Returns a string representation of the contents of the OptionMap. */
 105  2 public String toString() {
 106  2 StringWriter sw = new StringWriter();
 107  2 PrintWriter w = new PrintWriter(sw);
 108   
 109    // Write each option
 110  2 for (OptionParser<?> key : map.keys()) {
 111  3 if (!key.getDefault().equals(map.getOption(key))) {
 112  3 String tmpString = map.getString(key);
 113   
 114    // This replaces all backslashes with two backslashes for windows
 115  3 tmpString = tmpString.replaceAll("\\\\", "\\\\\\\\");
 116   
 117  3 w.println(key.getName()+" = "+tmpString);
 118    }
 119    }
 120  2 w.close();
 121   
 122  2 return sw.toString();
 123    }
 124   
 125    /** Return OptionMap. */
 126  11132 public OptionMap getOptionMap() { return map; }
 127    }