cf68846dc5610dced5774b7575d10e5b832b2049
[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 int modno;
33         private PHPVariable[] variables;
34         private String description;
35
36         public PHPStackFrame(PHPThread thread, String file, int line, int index, String desc, int modno) {
37                 this.lineNumber = line;
38                 this.index = index;
39                 this.file = file;
40                 this.thread = thread;
41                 this.description = desc;
42                 this.modno = modno;
43         } 
44         
45         public PHPStackFrame(PHPThread thread, String file, int line, int index) {
46                 this.lineNumber = line;
47                 this.index = index;
48                 this.file = file;
49                 this.thread = thread;
50         } 
51         
52         public IThread getThread() {
53                 return thread;
54         }
55         
56         public void setThread(PHPThread thread) {
57                 this.thread = thread;
58         }
59         
60         public IVariable[] getVariables() throws DebugException {
61                 if (variables == null) {
62                         variables = this.getPHPDBGProxy().readVariables(this);
63                 }
64                 return variables;
65         }
66         
67         public boolean hasVariables() throws DebugException {
68                 if (variables == null) {
69                         return false;
70                 }
71                 return variables.length > 0;
72         }
73         
74         public int getLineNumber() {
75                 return lineNumber;
76         }
77         
78         public int getCharStart() throws DebugException {
79                 // not supported
80                 return -1;
81         }
82         
83         public int getCharEnd() throws DebugException {
84                 // not supported
85                 return -1;
86         }
87         
88         public String getName() {
89                 if(!this.getDescription().equals(""))
90                         return this.getDescription() + " [line: " + this.getLineNumber() + "]";
91                 else
92                         return this.getFileName() + " [line: " + this.getLineNumber() + "]";
93         }
94
95         public String getFileName() {
96                 return file;
97         }
98         
99         public void setDescription(String desc) {
100                 this.description= desc;
101         }
102
103         public String getDescription() {
104                 return this.description;
105         }
106         
107         public IRegisterGroup[] getRegisterGroups() throws DebugException {
108                 return null;
109         }
110         
111         public boolean hasRegisterGroups() throws DebugException {
112                 return false;
113         }
114         
115         public String getModelIdentifier() {
116                 return this.getThread().getModelIdentifier();
117         }
118         
119         public IDebugTarget getDebugTarget() {
120                 return this.getThread().getDebugTarget();
121         }
122         
123         public ILaunch getLaunch() {
124                 return this.getDebugTarget().getLaunch();
125         }
126         
127         public boolean canStepInto() {
128                 return canResume();
129         }
130         
131         public boolean canStepOver() {
132                 return canResume();
133         }
134         
135         public boolean canStepReturn() {
136                 return canResume();
137         }
138         
139         public boolean isStepping() {
140                 return false;
141         }
142         
143         public void stepInto() throws DebugException {
144                 thread.prepareForResume() ;
145                 this.getPHPDBGProxy().readStepIntoEnd(PHPStackFrame.this) ;             
146                 DebugEvent ev = new DebugEvent(this.getThread(), DebugEvent.RESUME, DebugEvent.STEP_INTO);
147                 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });
148         }
149         
150         public void stepOver() throws DebugException {
151                 thread.prepareForResume() ;
152                 this.getPHPDBGProxy().readStepOverEnd(PHPStackFrame.this) ;
153                 DebugEvent ev = new DebugEvent(this.getThread(), DebugEvent.RESUME, DebugEvent.STEP_OVER);
154                 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });
155         }
156
157         public void stepReturn() throws DebugException {
158                 thread.prepareForResume() ;
159                 this.getPHPDBGProxy().readStepReturnEnd(PHPStackFrame.this) ;                           
160                 DebugEvent ev = new DebugEvent(this.getThread(), DebugEvent.RESUME, DebugEvent.STEP_RETURN);
161                 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });            
162         }
163
164         
165         public boolean canResume() {
166                 return this.getThread().canResume();
167         }
168         
169         public boolean canSuspend() {
170                 return this.getThread().canSuspend();
171         }
172         
173         public boolean isSuspended() {
174                 return this.getThread().isSuspended();
175         } 
176         
177         public void resume() throws DebugException {
178                 this.getThread().resume();
179         }
180         
181         public void suspend() throws DebugException {
182         }
183         
184         public boolean canTerminate() {
185                 return this.getThread().canTerminate();
186         }
187         
188         public boolean isTerminated() {
189                 return this.getThread().isTerminated();
190         } 
191         
192         public void terminate() throws DebugException {
193                 getPHPDBGProxy().stop();
194         } 
195         
196         public Object getAdapter(Class arg0) {
197                 return null;
198         }
199
200         public int getIndex() {
201                 return index;
202         }
203
204         public PHPDBGProxy getPHPDBGProxy() {
205                 PHPDebugTarget DebugTarget;
206                 DebugTarget= (PHPDebugTarget)thread.getDebugTarget();
207                 return DebugTarget.getPHPDBGProxy();
208         }
209
210         public void setFile(String file) {
211                 this.file = file;
212         }
213         
214         public int getModNo() {
215                 return modno;
216         }
217 }