001: // This file is part of KeY - Integrated Deductive Software Design
002: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003: // Universitaet Koblenz-Landau, Germany
004: // Chalmers University of Technology, Sweden
005: //
006: // The KeY system is protected by the GNU General Public License.
007: // See LICENSE.TXT for details.
008: package de.uka.ilkd.key.visualdebugger;
009:
010: import java.util.Iterator;
011: import java.util.LinkedList;
012:
013: import de.uka.ilkd.key.proof.IteratorOfNode;
014: import de.uka.ilkd.key.proof.ListOfNode;
015: import de.uka.ilkd.key.proof.Node;
016: import de.uka.ilkd.key.proof.SLListOfNode;
017:
018: public class BreakpointManager {
019: private LinkedList bp = new LinkedList();
020:
021: private boolean noEx = false;
022:
023: private ListOfNode st = SLListOfNode.EMPTY_LIST;
024:
025: private VisualDebugger vd;
026:
027: public BreakpointManager(VisualDebugger vd) {
028: this .vd = vd;
029: }
030:
031: public boolean addBreakpoint(Breakpoint b) {
032: if (containsBp(b.getId()))
033: return false;
034: bp.add(b);
035: return true;
036: }
037:
038: public boolean containsBp(SourceElementId id) {
039: Iterator it = bp.iterator();
040: while (it.hasNext()) {
041: SourceElementId currentId = ((Breakpoint) it.next())
042: .getId();
043: if (currentId.equals(id))
044: return true;
045: }
046: return false;
047: }
048:
049: public Object[] getBreapoints() {
050: return bp.toArray();
051: }
052:
053: public ListOfNode getSteps() {
054: return st;
055: }
056:
057: public boolean isNoEx() {
058: return noEx;
059: }
060:
061: private String print(ListOfNode lon) {
062: IteratorOfNode it = lon.iterator();
063: String result = "";
064: while (it.hasNext()) {
065: result += it.next().serialNr() + " ";
066: }
067: return result;
068: }
069:
070: public void remove(Breakpoint b) {
071: bp.remove(b);
072: }
073:
074: public void setNoEx(boolean noEx) {
075: // System.out.println("noEx set to "+noEx);
076: this .noEx = noEx;
077: }
078:
079: public boolean suspend(Node n, SourceElementId id) {
080: return suspendByBreakpoint(id) || suspendByStep(n, id)
081: || suspendByStepOver(n, id);
082: }
083:
084: public boolean suspendByBreakpoint(SourceElementId id) {
085: if (this .containsBp(id))
086: return true;
087: return false;
088: }
089:
090: public boolean suspendByStep(Node n, SourceElementId id) {
091: if (n.parent() != null) {
092: return n.parent().getNodeInfo().getVisualDebuggerState()
093: .getStatementIdcount() == 0;
094: }
095: return false;
096: }
097:
098: public boolean suspendByStepOver(Node n, SourceElementId id) {
099: final VisualDebuggerState visualDebuggerState = n.getNodeInfo()
100: .getVisualDebuggerState();
101: final boolean suspendedSO = visualDebuggerState.getStepOver() != -1
102: && n.serialNr() != visualDebuggerState
103: .getStepOverFrom()
104: && VisualDebugger.getVisualDebugger()
105: .getMethodStackSize(n) <= n.parent()
106: .getNodeInfo().getVisualDebuggerState()
107: .getStepOver();
108: return suspendedSO;
109: }
110:
111: public String toString() {
112: return "Steps: " + print(st) + " BPs" + this .bp.toString()
113: + " NoEx " + this.noEx;
114: }
115: }
|