bf59b502b004295272d5891a07642d1d1982b199
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / model / PHPStackFrame.java
1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
7
8 Contributors:
9     IBM Corporation - Initial implementation
10     Vicente Fernando - www.alfersoft.com.ar
11 **********************************************************************/
12 package net.sourceforge.phpdt.internal.debug.core.model;
13
14 import org.eclipse.debug.core.DebugEvent;
15 import org.eclipse.debug.core.DebugException;
16 import org.eclipse.debug.core.DebugPlugin;
17 import org.eclipse.debug.core.ILaunch;
18 import org.eclipse.debug.core.model.IDebugTarget;
19 import org.eclipse.debug.core.model.IRegisterGroup;
20 import org.eclipse.debug.core.model.IStackFrame;
21 import org.eclipse.debug.core.model.IThread;
22 import org.eclipse.debug.core.model.IVariable;
23 import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy;
24 import net.sourceforge.phpdt.internal.debug.core.model.PHPDebugTarget;
25
26 public class PHPStackFrame implements IStackFrame {
27
28         private PHPThread thread;
29         private String file;
30         private int lineNumber;
31         private int index;
32         private PHPVariable[] variables;
33         private String description;
34
35         public PHPStackFrame(PHPThread thread, String file, int line, int index, String desc) {
36                 this.lineNumber = line;
37                 this.index = index;
38                 this.file = file;
39                 this.thread = thread;
40                 this.description = desc;
41         } 
42         
43         public PHPStackFrame(PHPThread thread, String file, int line, int index) {
44                 this.lineNumber = line;
45                 this.index = index;
46                 this.file = file;
47                 this.thread = thread;
48         } 
49         
50         public IThread getThread() {
51                 return thread;
52         }
53         
54         public void setThread(PHPThread thread) {
55                 this.thread = thread;
56         }
57         
58         public IVariable[] getVariables() throws DebugException {
59                 if (variables == null) {
60                         variables = this.getPHPDBGProxy().readVariables(this);
61                 }
62                 return variables;
63         }
64         
65         public boolean hasVariables() throws DebugException {
66                 if (variables == null) {
67                         return false;
68                 }
69                 return variables.length > 0;
70         }
71         
72         public int getLineNumber() {
73                 return lineNumber;
74         }
75         
76         public int getCharStart() throws DebugException {
77                 // not supported
78                 return -1;
79         }
80         
81         public int getCharEnd() throws DebugException {
82                 // not supported
83                 return -1;
84         }
85         
86         public String getName() {
87                 if(!this.getDescription().equals(""))
88                         return this.getDescription() + " [line: " + this.getLineNumber() + "]";
89                 else
90                         return this.getFileName() + " [line: " + this.getLineNumber() + "]";
91         }
92
93         public String getFileName() {
94                 return file;
95         }
96         
97         public void setDescription(String desc) {
98                 this.description= desc;
99         }
100
101         public String getDescription() {
102                 return this.description;
103         }
104         
105         public IRegisterGroup[] getRegisterGroups() throws DebugException {
106                 return null;
107         }
108         
109         public boolean hasRegisterGroups() throws DebugException {
110                 return false;
111         }
112         
113         public String getModelIdentifier() {
114                 return this.getThread().getModelIdentifier();
115         }
116         
117         public IDebugTarget getDebugTarget() {
118                 return this.getThread().getDebugTarget();
119         }
120         
121         public ILaunch getLaunch() {
122                 return this.getDebugTarget().getLaunch();
123         }
124         
125         public boolean canStepInto() {
126                 return canResume();
127         }
128         
129         public boolean canStepOver() {
130                 return canResume();
131         }
132         
133         public boolean canStepReturn() {
134                 return canResume();
135         }
136         
137         public boolean isStepping() {
138                 return false;
139         }
140         
141         public void stepInto() throws DebugException {
142                 thread.prepareForResume() ;
143                 this.getPHPDBGProxy().readStepIntoEnd(PHPStackFrame.this) ;             
144                 DebugEvent ev = new DebugEvent(this.getThread(), DebugEvent.RESUME, DebugEvent.STEP_INTO);
145                 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });
146         }
147         
148         public void stepOver() throws DebugException {
149                 thread.prepareForResume() ;
150                 this.getPHPDBGProxy().readStepOverEnd(PHPStackFrame.this) ;
151                 DebugEvent ev = new DebugEvent(this.getThread(), DebugEvent.RESUME, DebugEvent.STEP_OVER);
152                 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });
153         }
154
155         public void stepReturn() throws DebugException {
156                 thread.prepareForResume() ;
157                 this.getPHPDBGProxy().readStepReturnEnd(PHPStackFrame.this) ;                           
158                 DebugEvent ev = new DebugEvent(this.getThread(), DebugEvent.RESUME, DebugEvent.STEP_RETURN);
159                 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });            
160         }
161
162         
163         public boolean canResume() {
164                 return this.getThread().canResume();
165         }
166         
167         public boolean canSuspend() {
168                 return this.getThread().canSuspend();
169         }
170         
171         public boolean isSuspended() {
172                 return this.getThread().isSuspended();
173         } 
174         
175         public void resume() throws DebugException {
176                 this.getThread().resume();
177         }
178         
179         public void suspend() throws DebugException {
180         }
181         
182         public boolean canTerminate() {
183                 return this.getThread().canTerminate();
184         }
185         
186         public boolean isTerminated() {
187                 return this.getThread().isTerminated();
188         } 
189         
190         public void terminate() throws DebugException {
191                 getPHPDBGProxy().stop();
192         } 
193         
194         public Object getAdapter(Class arg0) {
195                 return null;
196         }
197
198         public int getIndex() {
199                 return index;
200         }
201
202         public PHPDBGProxy getPHPDBGProxy() {
203                 PHPDebugTarget DebugTarget;
204                 DebugTarget= (PHPDebugTarget)thread.getDebugTarget();
205                 return DebugTarget.getPHPDBGProxy();
206         }
207
208 }