|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| DebugAction.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 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 com.sun.jdi.request.*; | |
| 40 | import java.util.Vector; | |
| 41 | import edu.rice.cs.drjava.model.debug.DebugException; | |
| 42 | ||
| 43 | /** Keeps track of information about any request to the debugger, such as Breakpoints. | |
| 44 | * @version $Id: DebugAction.java 5175 2010-01-20 08:46:32Z mgricken $ | |
| 45 | */ | |
| 46 | public abstract class DebugAction<T extends EventRequest> { | |
| 47 | public static final int ANY_LINE = -1; | |
| 48 | ||
| 49 | protected final JPDADebugger _manager; | |
| 50 | ||
| 51 | // Request fields | |
| 52 | ||
| 53 | /** Vector of EventRequests. There might be more than one, since there can be multiple reference types for one class. | |
| 54 | * They all share the same attributes, though, so the other fields don't need to be vectors. | |
| 55 | */ | |
| 56 | protected final Vector<T> _requests; | |
| 57 | protected volatile int _suspendPolicy = EventRequest.SUSPEND_NONE; | |
| 58 | protected volatile boolean _isEnabled = true; | |
| 59 | protected volatile int _countFilter = -1; | |
| 60 | protected volatile int _lineNumber = ANY_LINE; | |
| 61 | ||
| 62 | /** Creates a new DebugAction. Automatically tries to create the EventRequest if a ReferenceType can be found, or | |
| 63 | * else adds this object to the PendingRequestManager. Any subclass should automatically call _initializeRequest | |
| 64 | * in its constructor. | |
| 65 | * @param manager JPDADebugger in charge | |
| 66 | */ | |
| 67 | 0 | public DebugAction(JPDADebugger manager) { |
| 68 | 0 | _manager = manager; |
| 69 | 0 | _requests = new Vector<T>(); |
| 70 | } | |
| 71 | ||
| 72 | /** Returns the EventRequest corresponding to this DebugAction, if it has been created, null otherwise. */ | |
| 73 | 0 | public Vector<T> getRequests() { return _requests; } |
| 74 | ||
| 75 | /** Returns the line number this DebugAction occurs on */ | |
| 76 | 0 | public int getLineNumber() { return _lineNumber; } |
| 77 | ||
| 78 | /** Creates an EventRequest corresponding to this DebugAction, using the given ReferenceType. This is called either | |
| 79 | * from the DebugAction constructor or the PendingRequestManager, depending on when the ReferenceType becomes | |
| 80 | * available. This DebugAction must be an instance of DocumentDebugAction since a ReferenceType is being used. | |
| 81 | * @return true if the EventRequest is successfully created | |
| 82 | */ | |
| 83 | //public abstract boolean createRequests(ReferenceType rt) throws DebugException; | |
| 84 | ||
| 85 | 0 | public boolean createRequests() throws DebugException { |
| 86 | 0 | _createRequests(); |
| 87 | 0 | if (_requests.size() > 0) { |
| 88 | 0 | _prepareRequests(_requests); |
| 89 | 0 | return true; |
| 90 | } | |
| 91 | 0 | else return false; |
| 92 | } | |
| 93 | ||
| 94 | /** This should always be called from the constructor of the subclass. Tries to create all applicable EventRequests | |
| 95 | * for this DebugAction. | |
| 96 | */ | |
| 97 | 0 | protected void _initializeRequests() throws DebugException { |
| 98 | 0 | createRequests(); |
| 99 | 0 | if (_requests.size() == 0) { |
| 100 | 0 | throw new DebugException("Could not create EventRequests for this action!"); |
| 101 | } | |
| 102 | } | |
| 103 | ||
| 104 | /** Creates an appropriate EventRequest from the EventRequestManager and stores it in the _request field. | |
| 105 | * @throws DebugException if the request could not be created. | |
| 106 | */ | |
| 107 | 0 | protected void _createRequests() throws DebugException { } |
| 108 | ||
| 109 | /** Prepares all relevant EventRequests with the current stored values. | |
| 110 | * @param requests the EventRequests to prepare | |
| 111 | */ | |
| 112 | 0 | protected void _prepareRequests(Vector<T> requests) { |
| 113 | 0 | for (int i = 0; i < requests.size(); i++) { |
| 114 | 0 | _prepareRequest(requests.get(i)); |
| 115 | } | |
| 116 | } | |
| 117 | ||
| 118 | /** Prepares this EventRequest with the current stored values. | |
| 119 | * @param request the EventRequest to prepare | |
| 120 | */ | |
| 121 | 0 | protected void _prepareRequest(T request) { |
| 122 | // the request must be disabled to be edited | |
| 123 | 0 | request.setEnabled(false); |
| 124 | ||
| 125 | 0 | if (_countFilter != -1) { |
| 126 | 0 | request.addCountFilter(_countFilter); |
| 127 | } | |
| 128 | 0 | request.setSuspendPolicy(_suspendPolicy); |
| 129 | 0 | request.setEnabled(_isEnabled); |
| 130 | ||
| 131 | // Add properties | |
| 132 | 0 | request.putProperty("debugAction", this); |
| 133 | } | |
| 134 | ||
| 135 | /** @return true if breakpoint is enabled. */ | |
| 136 | 0 | public boolean isEnabled() { return _isEnabled; } |
| 137 | ||
| 138 | ||
| 139 | /** Enable/disable the breakpoint. */ | |
| 140 | 0 | public void setEnabled(boolean isEnabled) { _isEnabled = isEnabled; } |
| 141 | } |
|
||||||||||