Clover coverage report - DrJava Test Coverage (drjava-20110828-r5448)
Coverage timestamp: Sun Aug 28 2011 03:13:33 CDT
file stats: LOC: 113   Methods: 2
NCLOC: 38   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ActionStartPrevLinePlusMultilinePreserve.java 100% 95.5% 100% 96.2%
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 javax.swing.text.*;
 40    import edu.rice.cs.util.UnexpectedException;
 41    import edu.rice.cs.drjava.model.AbstractDJDocument;
 42   
 43    /** Indents the current line in the document to the indent level of the
 44    * start of the previous line, preserving any text on the current line,
 45    * and adds several lines of text at that indent level,
 46    * and moves the cursor to a particular line and position.
 47    * @version $Id: ActionStartPrevLinePlusMultilinePreserve.java 5175 2010-01-20 08:46:32Z mgricken $
 48    */
 49    class ActionStartPrevLinePlusMultilinePreserve extends IndentRuleAction {
 50    private String[] _suffices;
 51    private int _cursorLine, _cursorPos, _psrvLine, _psrvPos;
 52   
 53    /** Creates a multiline insert rule, properly preserving any text on current line.
 54    * @param suffices the new lines to be added
 55    * @param cursorLine the line on which to place the cursor
 56    * @param cursorPos the character within the line string before which to place
 57    * the cursor
 58    * @param psrvLine the line in suffices on which to place the preserved text
 59    * @param psrvPos the character within the line string in suffices before which
 60    * to place the preserved text
 61    * @throws IllegalArgumentException if the integer params are negative or
 62    * outside the appropriate bounds
 63    */
 64  2959 public ActionStartPrevLinePlusMultilinePreserve(String suffices[],
 65    int cursorLine, int cursorPos,
 66    int psrvLine, int psrvPos) {
 67  2959 _suffices = suffices;
 68  2959 _cursorLine = cursorLine;
 69  2959 _cursorPos = cursorPos;
 70  2960 _psrvLine = psrvLine;
 71  2960 _psrvPos = psrvPos;
 72    }
 73   
 74    /** Forwards the call to the enclosed ActionStartPrevLinePlusMultiline. Only runs in event thread.
 75    * @param doc AbstractDJDocument containing the line to be indented.
 76    * @param reason The reason that the indentation is taking place
 77    * @return this is always false, since we are updating the cursor location
 78    */
 79  10 public boolean indentLine(AbstractDJDocument doc, Indenter.IndentReason reason) {
 80  10 try {
 81    // copy it so any changes are not remembered
 82  10 String[] suffices = new String[_suffices.length];
 83  20 for(int i = 0; i < _suffices.length; i++) suffices[i] = _suffices[i];
 84   
 85    // get the absolute boundaries of the text on this line
 86  10 int here = doc.getCurrentLocation();
 87  10 int lineStart = doc._getLineStartPos(here);
 88  10 int lineEnd = doc._getLineEndPos(here);
 89   
 90    // cut the original text out of the current line
 91  10 int lineLength = lineEnd-lineStart;
 92  10 String preserved = doc.getText(lineStart, lineLength);
 93  10 doc.remove(lineStart, lineLength);
 94   
 95    // Paste the cut text in the correct place in the suffices array
 96  10 String prefix = suffices[_psrvLine].substring(0,_psrvPos);
 97  10 String suffix = suffices[_psrvLine].substring(_psrvPos);
 98  10 suffices[_psrvLine] = prefix + preserved + suffix;
 99   
 100    // forward the rest of the work to the other rule
 101  10 ActionStartPrevLinePlusMultiline a;
 102    //for(int i = 0; i < _suffices.length; i++)
 103    // javax.swing.JOptionPane.showMessageDialog(null, "\"" + suffices[i] + "\"", "suffices[" + i + "]",
 104    // javax.swing.JOptionPane.PLAIN_MESSAGE);
 105  10 a = new ActionStartPrevLinePlusMultiline(suffices, _cursorLine, _cursorPos);
 106  10 return a.indentLine(doc, reason);
 107    }
 108    catch (BadLocationException e) {
 109    // Shouldn't happen
 110  0 throw new UnexpectedException(e);
 111    }
 112    }
 113    }