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