Clover coverage report - DrJava Test Coverage (drjava-20120304-r5456)
Coverage timestamp: Sun Mar 4 2012 03:13:23 CST
file stats: LOC: 261   Methods: 14
NCLOC: 131   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JPDABreakpoint.java 0% 0% 0% 0%
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.debug.jpda;
 38   
 39    import edu.rice.cs.drjava.model.OrderedDocumentRegion;
 40    import edu.rice.cs.drjava.model.IDocumentRegion;
 41    import edu.rice.cs.drjava.model.OpenDefinitionsDocument;
 42    import edu.rice.cs.drjava.model.debug.Breakpoint;
 43    import edu.rice.cs.drjava.model.debug.DebugException;
 44    import edu.rice.cs.util.UnexpectedException;
 45   
 46    import java.awt.EventQueue;
 47    import java.util.List;
 48    import java.util.Vector;
 49    import javax.swing.text.BadLocationException;
 50    import javax.swing.text.Position;
 51   
 52    import com.sun.jdi.*;
 53    import com.sun.jdi.request.*;
 54   
 55    /** The breakpoint object which has references to its OpenDefinitionsDocument and its BreakpointRequest. See the
 56    * WARNING below about hashing on this type or its subtypes.
 57    */
 58    public class JPDABreakpoint extends DocumentDebugAction<BreakpointRequest> implements Breakpoint {
 59   
 60    private volatile Position _position;
 61    private volatile Position _startPos;
 62    private volatile Position _endPos;
 63   
 64    /** Note that _position, which records the breakpoint position, is inherited from DocumentDebugAction. */
 65    private volatile OpenDefinitionsDocument _doc;
 66   
 67    /** @throws DebugException if the document does not have a file */
 68  0 public JPDABreakpoint(OpenDefinitionsDocument doc, int offset, boolean isEnabled, JPDADebugger manager)
 69    throws DebugException {
 70   
 71  0 super(manager, doc, offset);
 72   
 73  0 assert EventQueue.isDispatchThread();
 74  0 _doc = doc;
 75  0 try { _position = doc.createPosition(offset); }
 76  0 catch(BadLocationException e) { throw new UnexpectedException(e); }
 77   
 78  0 _suspendPolicy = EventRequest.SUSPEND_EVENT_THREAD;
 79  0 _isEnabled = isEnabled;
 80  0 update();
 81   
 82  0 if (_manager != null && _manager.isReady()) {
 83    // the debugger is on, so initialize now
 84    // otherwise breakpoint gets re-set when debugger is enabled
 85  0 Vector<ReferenceType> refTypes = _manager.getReferenceTypes(_className, _manager.LLBreakpointLineNum(this));
 86  0 _initializeRequests(refTypes);
 87  0 setEnabled(isEnabled);
 88    }
 89    }
 90   
 91    /** Returns the String used on the JTree label for this breakpoint. */
 92  0 public String getString() {
 93  0 try {
 94  0 int start = _startPos.getOffset();
 95  0 int end = _endPos.getOffset();
 96  0 int length = end - start;
 97  0 if (length <= 120) return _doc.getText(start, length);
 98  0 StringBuilder sb = new StringBuilder(124);
 99  0 sb.append(_doc.getText(start, 120)).append(" ...");
 100  0 return sb.toString();
 101    }
 102  0 catch(BadLocationException e) { throw new UnexpectedException(e); }
 103    }
 104   
 105    // public void setTreeNode(DefaultMutableTreeNode node) {
 106    // throw new UnsupportedOperationException("JPDA Breakpoint does not support setTreeNode");
 107    // }
 108    //
 109    // public DefaultMutableTreeNode getTreeNode() {
 110    // throw new UnsupportedOperationException("JPDA Breakpoint does not support getTreeNode");
 111    // }
 112   
 113    /** Creates appropriate EventRequests from the EventRequestManager and stores them in the _requests field.
 114    * @param refTypes All (identical) ReferenceTypes to which this action applies. (There may be multiples if a custom
 115    * class loader is in use.)
 116    * @throws DebugException if the requests could not be created.
 117    */
 118  0 protected void _createRequests(Vector<ReferenceType> refTypes) throws DebugException {
 119  0 try {
 120  0 for (int i = 0; i < refTypes.size(); i++) {
 121  0 ReferenceType rt = refTypes.get(i);
 122   
 123  0 if (! rt.isPrepared()) {
 124    // Not prepared, so skip this one
 125  0 continue;
 126    }
 127   
 128    // Get locations for the line number, use the first
 129  0 List<Location> lines = rt.locationsOfLine(_manager.LLBreakpointLineNum(this));
 130  0 if (lines.size() == 0) {
 131    // Can't find a location on this line
 132  0 setEnabled(false);
 133  0 throw new DebugException("Could not find line number: " + _lineNumber);
 134    }
 135  0 Location loc = lines.get(0);
 136   
 137  0 BreakpointRequest request = _manager.getEventRequestManager().createBreakpointRequest(loc);
 138  0 request.setEnabled(_isEnabled);
 139  0 _requests.add(request);
 140    }
 141    }
 142  0 catch (AbsentInformationException aie) { throw new DebugException("Could not find line number: " + aie); }
 143    }
 144   
 145    /** Accessor for the offset of this breakpoint's start position
 146    * @return the start offset
 147    */
 148  0 public int getStartOffset() { return _startPos.getOffset(); }
 149   
 150    /** Accessor for the offset of this breakpoint's end position
 151    * @return the end offset
 152    */
 153  0 public int getEndOffset() { return _endPos.getOffset(); }
 154   
 155    /** Accessor for the offset of this breakpoint's start position
 156    * @return the start offset
 157    */
 158  0 public int getLineStartOffset() { return _startPos.getOffset(); }
 159   
 160    /** Accessor for the offset of this breakpoint's end position
 161    * @return the end offset
 162    */
 163  0 public int getLineEndOffset() { return _endPos.getOffset(); }
 164   
 165    /** Update _startPos, _endPos and _lineNumber from the position that moves with the document. */
 166  0 public void update() {
 167  0 try { // _doc is inherited from DocumentRegion
 168  0 int offset = _position.getOffset();
 169  0 _startPos = _doc.createPosition(_doc._getLineStartPos(offset));
 170  0 _endPos = _doc.createPosition(_doc._getLineEndPos(offset));
 171  0 _lineNumber = _doc.getLineOfOffset(offset)+1; // our line numbers are 1-based
 172    }
 173  0 catch (BadLocationException ble) { throw new UnexpectedException(ble); } // should never happen
 174    }
 175   
 176  0 public boolean isEmpty() { update(); return getStartOffset() == getEndOffset(); }
 177   
 178    // /** Accessor for this breakpoint's start position
 179    // * @return the start position
 180    // */
 181    // public Position getStartPosition() { return _startPos; }
 182   
 183    // /** Accessor for this breakpoint's end position
 184    // * @return the end position
 185    // */
 186    // public Position getEndPosition() { return _endPos; }
 187   
 188    /** Defines the equality relation on DocumentRegions. This equivalence relation on allocated objects is finer
 189    * grained than the equivalence relation induced by compareTo because it requires equality on Position objects,
 190    * not just equality of the current offsets of Positions.
 191    */
 192  0 public final boolean equals(Object o) {
 193  0 if (o == null || ! (o instanceof IDocumentRegion)) return false;
 194  0 update();
 195  0 IDocumentRegion r = (IDocumentRegion) o;
 196  0 return getDocument() == r.getDocument() && getStartOffset() == r.getStartOffset() && getEndOffset() == r.getEndOffset();
 197    }
 198   
 199    /** Totally orders regions lexicographically based on (_doc, endOffset, startOffset). This method is typically applied
 200    * to regions within the same document.
 201    */
 202  0 public int compareTo(OrderedDocumentRegion r) {
 203  0 int docRel = getDocument().compareTo(r.getDocument());
 204  0 if (docRel != 0) return docRel;
 205    // At this point, we know that this and r have identical file paths, but they do not have to be the same allocation
 206   
 207  0 assert getDocument() == r.getDocument(); // DrJava never creates two ODD objects with the same path
 208  0 int end1 = getEndOffset();
 209  0 int end2 = r.getEndOffset();
 210  0 int endDiff = end1 - end2;
 211  0 if (endDiff != 0) return endDiff;
 212   
 213  0 int start1 = getStartOffset();
 214  0 int start2 = r.getStartOffset();
 215  0 return start1 - start2;
 216    }
 217   
 218    /** Returns the line number this DebugAction occurs on */
 219  0 public int getLineNumber() {
 220  0 update();
 221  0 return _lineNumber;
 222    }
 223   
 224    /* WARNING: overriding hashCode to "agree" with equals is disastrous because Breakpoint offsets change! Hashcode must
 225    * be inconsisent with equals to produce an invariant value. Hence, you must use IdentityHashMap instead of HashMap
 226    * or Hashtable.
 227    */
 228    // public int hashCode() { return ObjectUtil.hash(_doc, getStartOffset(), getEndOffset()); }
 229   
 230    /** Enable/disable the breakpoint. */
 231  0 public void setEnabled(boolean isEnabled) {
 232  0 assert EventQueue.isDispatchThread();
 233  0 boolean old = _isEnabled;
 234  0 super.setEnabled(isEnabled);
 235  0 try {
 236  0 for(BreakpointRequest bpr: _requests) {
 237  0 bpr.setEnabled(isEnabled);
 238    }
 239    }
 240    catch(VMDisconnectedException vmde) { /* just ignore */ }
 241  0 if (_isEnabled!=old) _manager.notifyBreakpointChange(this);
 242    }
 243   
 244  0 public String toString() {
 245  0 String cn = getClassName();
 246  0 if (_exactClassName != null) { cn = _exactClassName.replace('$', '.'); }
 247  0 if (_requests.size() > 0) {
 248    // All BreakpointRequests are identical-- one copy for each loaded
 249    // class. So just print info from the first one, and how many there are.
 250  0 return "Breakpoint[class: " + cn +
 251    ", lineNumber: " + getLineNumber() +
 252    ", method: " + _requests.get(0).location().method() +
 253    ", codeIndex: " + _requests.get(0).location().codeIndex() +
 254    ", numRefTypes: " + _requests.size() + "]";
 255    }
 256    else {
 257  0 return "Breakpoint[class: " + cn +
 258    ", lineNumber: " + getLineNumber() + "]";
 259    }
 260    }
 261    }