2e1d71f12507db62be53c3e0564b1adfe249255d
[phpeclipse.git] /
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 IVariable findVariable(String s) throws DebugException {
68                 if (this.hasVariables()) {
69                         String name="$"+s;
70                         for(int i= 0; i < variables.length; i++) {
71                                 String n= variables[i].getName();
72                                 if((variables[i].getName()).equals(name))
73                                         return variables[i];
74                         }
75                 }       
76                 return null;
77         }
78         
79         public boolean hasVariables() throws DebugException {
80                 if (variables == null) {
81                         return false;
82                 }
83                 return variables.length > 0;
84         }
85         
86         public int getLineNumber() {
87                 return lineNumber;
88         }
89         
90         public int getCharStart() throws DebugException {
91                 // not supported
92                 return -1;
93         }
94         
95         public int getCharEnd() throws DebugException {
96                 // not supported
97                 return -1;
98         }
99         
100         public String getName() {
101                 if(!this.getDescription().equals(""))
102                         return this.getDescription() + " [line: " + this.getLineNumber() + "]";
103                 else
104                         return this.getFileName() + " [line: " + this.getLineNumber() + "]";
105         }
106
107         public String getFileName() {
108                 return file;
109         }
110         
111         public void setDescription(String desc) {
112                 this.description= desc;
113         }
114
115         public String getDescription() {
116                 return this.description;
117         }
118         
119         public IRegisterGroup[] getRegisterGroups() throws DebugException {
120                 return null;
121         }
122         
123         public boolean hasRegisterGroups() throws DebugException {
124                 return false;
125         }
126         
127         public String getModelIdentifier() {
128                 return this.getThread().getModelIdentifier();
129         }
130         
131         public IDebugTarget getDebugTarget() {
132                 return this.getThread().getDebugTarget();
133         }
134         
135         public ILaunch getLaunch() {
136                 return this.getDebugTarget().getLaunch();
137         }
138         
139         public boolean canStepInto() {
140                 return canResume();
141         }
142         
143         public boolean canStepOver() {
144                 return canResume();
145         }
146         
147         public boolean canStepReturn() {
148                 return canResume();
149         }
150         
151         public boolean isStepping() {
152                 return false;
153         }
154         
155         public void stepInto() throws DebugException {
156                 thread.prepareForResume() ;
157                 this.getPHPDBGProxy().readStepIntoEnd(PHPStackFrame.this) ;             
158                 DebugEvent ev = new DebugEvent(this.getThread(), DebugEvent.RESUME, DebugEvent.STEP_INTO);
159                 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });
160         }
161         
162         public void stepOver() throws DebugException {
163                 thread.prepareForResume() ;
164                 this.getPHPDBGProxy().readStepOverEnd(PHPStackFrame.this) ;
165                 DebugEvent ev = new DebugEvent(this.getThread(), DebugEvent.RESUME, DebugEvent.STEP_OVER);
166                 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });
167         }
168
169         public void stepReturn() throws DebugException {
170                 thread.prepareForResume() ;
171                 this.getPHPDBGProxy().readStepReturnEnd(PHPStackFrame.this) ;                           
172                 DebugEvent ev = new DebugEvent(this.getThread(), DebugEvent.RESUME, DebugEvent.STEP_RETURN);
173                 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });            
174         }
175
176         
177         public boolean canResume() {
178                 return this.getThread().canResume();
179         }
180         
181         public boolean canSuspend() {
182                 return this.getThread().canSuspend();
183         }
184         
185         public boolean isSuspended() {
186                 return this.getThread().isSuspended();
187         } 
188         
189         public void resume() throws DebugException {
190                 this.getThread().resume();
191         }
192         
193         public void suspend() throws DebugException {
194         }
195         
196         public boolean canTerminate() {
197                 return this.getThread().canTerminate();
198         }
199         
200         public boolean isTerminated() {
201                 return this.getThread().isTerminated();
202         } 
203         
204         public void terminate() throws DebugException {
205                 getPHPDBGProxy().stop();
206         } 
207         
208         public Object getAdapter(Class arg0) {
209                 if (arg0==PHPStackFrame.class)
210                         return this;
211                 else
212                         return null;
213         }
214
215         public int getIndex() {
216                 return index;
217         }
218
219         public PHPDBGProxy getPHPDBGProxy() {
220                 PHPDebugTarget DebugTarget;
221                 DebugTarget= (PHPDebugTarget)thread.getDebugTarget();
222                 return DebugTarget.getPHPDBGProxy();
223         }
224
225         public void setFile(String file) {
226                 this.file = file;
227         }
228         
229         public int getModNo() {
230                 return modno;
231         }
232 }