Clover coverage report - DynamicJava Test Coverage (dynamicjava-20120303-r5436)
Coverage timestamp: Sat Mar 3 2012 03:02:19 CST
file stats: LOC: 216   Methods: 21
NCLOC: 91   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
SourceInfo.java 12.5% 41.9% 42.9% 38.3%
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    /*
 38    * DynamicJava - Copyright (C) 1999-2001
 39    *
 40    * Permission is hereby granted, free of charge, to any person obtaining a
 41    * copy of this software and associated documentation files
 42    * (the "Software"), to deal in the Software without restriction, including
 43    * without limitation the rights to use, copy, modify, merge, publish,
 44    * distribute, sublicense, and/or sell copies of the Software, and to permit
 45    * persons to whom the Software is furnished to do so, subject to the
 46    * following conditions:
 47    * The above copyright notice and this permission notice shall be included
 48    * in all copies or substantial portions of the Software.
 49    *
 50    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 51    * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 52    * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 53    * IN NO EVENT SHALL DYADE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 54    * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 55    * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 56    * DEALINGS IN THE SOFTWARE.
 57    *
 58    * Except as contained in this notice, the name of Dyade shall not be
 59    * used in advertising or otherwise to promote the sale, use or other
 60    * dealings in this Software without prior written authorization from
 61    * Dyade.
 62    *
 63    */
 64   
 65    package koala.dynamicjava.tree;
 66   
 67    import java.io.*;
 68   
 69    import edu.rice.cs.plt.object.ObjectUtil;
 70    import edu.rice.cs.plt.tuple.Option;
 71   
 72    /** A simple tuple class to represent source location. */
 73    public final class SourceInfo implements Comparable<SourceInfo> {
 74   
 75    public interface Wrapper {
 76    SourceInfo getSourceInfo();
 77    }
 78   
 79    public static final SourceInfo NONE = new SourceInfo(Option.<File>none(), 0, 0, 0, 0);
 80   
 81  1848 public static SourceInfo point(File f, int line, int column) {
 82  1848 return new SourceInfo(Option.wrap(f), line, column, line, column);
 83    }
 84   
 85  9284 public static SourceInfo range(File f, int startLine, int startColumn, int endLine, int endColumn) {
 86  9284 return new SourceInfo(Option.wrap(f), startLine, startColumn, endLine, endColumn);
 87    }
 88   
 89  4733 public static SourceInfo extend(SourceInfo si, int endLine, int endColumn) {
 90  4733 return new SourceInfo(si._file, si._startLine, si._startColumn, endLine, endColumn);
 91    }
 92   
 93  4733 public static SourceInfo extend(Wrapper wrapper, int endLine, int endColumn) {
 94  4733 return extend(wrapper.getSourceInfo(), endLine, endColumn);
 95    }
 96   
 97  1074 public static SourceInfo prepend(int startLine, int startColumn, SourceInfo si) {
 98  1074 return new SourceInfo(si._file, startLine, startColumn, si._endLine, si._endColumn);
 99    }
 100   
 101  1074 public static SourceInfo prepend(int startLine, int startColumn, Wrapper wrapper) {
 102  1074 return prepend(startLine, startColumn, wrapper.getSourceInfo());
 103    }
 104   
 105  1513 public static SourceInfo span(SourceInfo first, SourceInfo second) {
 106  1513 assert ObjectUtil.equal(first._file, second._file);
 107  1513 return new SourceInfo(first._file, first._startLine, first._startColumn, second._endLine, second._endColumn);
 108    }
 109   
 110  0 public static SourceInfo span(SourceInfo first, Wrapper second) {
 111  0 return span(first, second.getSourceInfo());
 112    }
 113   
 114  0 public static SourceInfo span(Wrapper first, SourceInfo second) {
 115  0 return span(first.getSourceInfo(), second);
 116    }
 117   
 118  1509 public static SourceInfo span(Wrapper first, Wrapper second) {
 119  1509 return span(first.getSourceInfo(), second.getSourceInfo());
 120    }
 121   
 122    /**
 123    * The source file.
 124    */
 125    private final Option<File> _file;
 126   
 127    /**
 128    * The starting line of the source location
 129    */
 130    private final int _startLine;
 131   
 132    /**
 133    * The starting column of the source location
 134    */
 135    private final int _startColumn;
 136   
 137    /**
 138    * The ending line of the source location
 139    */
 140    private final int _endLine;
 141   
 142    /**
 143    * The ending column of the source location
 144    */
 145    private final int _endColumn;
 146   
 147  18455 private SourceInfo(Option<File> file, int startLine, int startColumn, int endLine, int endColumn) {
 148  18455 _file = file;
 149  18455 _startLine = startLine;
 150  18455 _startColumn = startColumn;
 151  18455 _endLine = endLine;
 152  18455 _endColumn = endColumn;
 153    }
 154   
 155    /** May be null, if the source file is unknown. TODO: Change this interface to Option<File>. */
 156  0 public File getFile() { return _file.unwrap(null); }
 157   
 158    /** Get the file's name, or {@code "(no file)"}. */
 159  0 public String getFilename() { return _file.isNone() ? "(no file)" : _file.unwrap().getPath(); }
 160   
 161  0 public int getStartLine() { return _startLine; }
 162  0 public int getStartColumn() { return _startColumn; }
 163  0 public int getEndLine() { return _endLine; }
 164  0 public int getEndColumn() { return _endColumn; }
 165   
 166    /**
 167    * Returns a string representation of the source information. The format is as following:
 168    * [fileName: (startLine,startColumn)-(endLine,endColumn)]
 169    * If there is no file then fileName is "(no file)"
 170    * @return The string format of the source info
 171    */
 172  0 public String toString() {
 173  0 return "[" + getFilename() + ": " +
 174    "(" + _startLine + "," + _startColumn + ")-" +
 175    "(" + _endLine + "," + _endColumn + ")]";
 176    }
 177   
 178    /**
 179    * Method for determining the equality of two source locations - overriden from Object
 180    * The method for determining if two source locations are equal is as follows:
 181    *
 182    * The two Files must be equal using the File.equals method
 183    * The integers for the corresponding Start/End Line/Column must be identical
 184    * @return Whether or not the two SourceInfo objects are equal
 185    */
 186  0 @Override public boolean equals(Object obj) {
 187  0 if (obj == null || obj.getClass() != this.getClass()) {
 188  0 return false;
 189    }
 190    else {
 191  0 SourceInfo casted = (SourceInfo) obj;
 192  0 return
 193    this._file.equals(casted._file) &&
 194    this._startLine == casted._startLine &&
 195    this._startColumn == casted._startColumn &&
 196    this._endLine == casted._endLine &&
 197    this._endColumn == casted._endColumn;
 198    }
 199    }
 200   
 201  0 @Override public int hashCode() {
 202  0 return ObjectUtil.hash(getClass(), _file, _startLine, _startColumn, _endLine, _endColumn);
 203    }
 204   
 205  0 public int compareTo(SourceInfo that) {
 206  0 int result = Option.<File>comparator().compare(this._file, that._file);
 207  0 if (result == 0) {
 208  0 result = ObjectUtil.compare(this._startLine, that._startLine,
 209    this._startColumn, that._startColumn,
 210    this._endLine, that._endLine,
 211    this._endColumn, that._endColumn);
 212    }
 213  0 return result;
 214    }
 215   
 216    }