Clover coverage report - DrJava Test Coverage (drjava-20120304-r5456)
Coverage timestamp: Sun Mar 4 2012 03:13:23 CST
file stats: LOC: 125   Methods: 9
NCLOC: 53   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
IndentRuleWithTrace.java 60% 79.2% 88.9% 76.7%
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.model.definitions.indent;
 38   
 39    import edu.rice.cs.drjava.model.AbstractDJDocument;
 40   
 41    // TODO: Check synchronization.
 42    import java.util.ArrayList;
 43    import java.io.PrintStream;
 44   
 45    /** This class does almost all the work for keeping an indent tree trace. IndentRuleQuestion
 46    * also does some of the work, and any subclass may substitute its own version of getRuleName()
 47    * Note: traceing is disabled by default
 48    * @version $Id: IndentRuleWithTrace.java 5175 2010-01-20 08:46:32Z mgricken $
 49    */
 50    public abstract class IndentRuleWithTrace implements IndentRule {
 51   
 52    private static ArrayList<String> trace = null;
 53    private static boolean startOver = true;
 54    private static boolean ruleTraceEnabled = false;
 55   
 56    public static final String YES = "Yes";
 57    public static final String NO = "No";
 58    public static final String TERMINUS_RULE = "";
 59   
 60    /* This method prints the most recent trace through the indent tree */
 61  0 public static void printLastIndentTrace(PrintStream ps) {
 62  0 if (trace == null) {
 63  0 ps.println("No trace to print");
 64    }
 65    else {
 66  0 for (int x = 0; x < trace.size(); x++) {
 67  0 ps.println(trace.get(x));
 68    }
 69  0 ps.println("******************************");
 70    }
 71    }
 72   
 73  1 public static void setRuleTraceEnabled(boolean ruleTraceEnabled) {
 74  1 IndentRuleWithTrace.ruleTraceEnabled = ruleTraceEnabled;
 75    }
 76   
 77  1 static ArrayList<String> getTrace() { return trace; }
 78   
 79    /** This rule just adds to the trace kept in trace */
 80  1994 protected static void _addToIndentTrace(String ruleName, String direction, boolean terminus) {
 81  1994 if (ruleTraceEnabled) {
 82  2 if (startOver) trace = new ArrayList<String>();
 83  8 startOver = terminus;
 84  8 trace.add(ruleName + " " + direction);
 85    }
 86    }
 87   
 88    /** Properly indents the line identified by pos. Replaces all whitespace characters at the beginning of the line with
 89    * the appropriate spacing or characters.
 90    * @param doc the AbstractDJDocument containing the line to be indented.
 91    * @param pos the position identifying the line to be indented
 92    * @param reason the reason that the indentation is taking place
 93    * @return true if the caller should update the current location itself, false if the indenter has already handled it
 94    */
 95  54 public boolean indentLine(AbstractDJDocument doc, int pos, Indenter.IndentReason reason) {
 96  54 int oldPos = doc.getCurrentLocation();
 97  54 doc.setCurrentLocation(pos);
 98  54 indentLine(doc, reason);
 99  5 if (oldPos > doc.getLength()) oldPos = doc.getLength();
 100  54 doc.setCurrentLocation(oldPos);
 101  54 return false;
 102    }
 103   
 104    /** This method does not indent the current line! */
 105  310 public boolean indentLine(AbstractDJDocument doc, Indenter.IndentReason reason) {
 106  310 _addToIndentTrace(getRuleName(), TERMINUS_RULE, true);
 107   
 108    //Add the next line, and every time something is indented, the indent trace will be printed
 109    //printLastIndentTrace(System.out);
 110  310 return true;
 111    }
 112   
 113    /** Convenience method that wraps calls on indentLine in a write lock. Only used in testing. */
 114  52 public boolean testIndentLine(AbstractDJDocument doc, int pos, Indenter.IndentReason reason) {
 115  52 return indentLine(doc, pos, reason);
 116    }
 117   
 118    /** Convenience method that wraps calls on indentLine in a write lock. Only used in testing. */
 119  20 public boolean testIndentLine(AbstractDJDocument doc, Indenter.IndentReason reason) {
 120  20 return indentLine(doc, reason);
 121    }
 122   
 123    /** The rule name to report to _addToIndentTrace */
 124  1994 public String getRuleName() { return this.getClass().getName(); }
 125    }