KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > debug > model > AntStackFrame


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ant.internal.ui.debug.model;
12
13 import org.eclipse.ant.internal.ui.AntUtil;
14 import org.eclipse.core.resources.IFile;
15 import org.eclipse.core.runtime.Path;
16 import org.eclipse.debug.core.DebugException;
17 import org.eclipse.debug.core.model.IRegisterGroup;
18 import org.eclipse.debug.core.model.IStackFrame;
19 import org.eclipse.debug.core.model.IThread;
20 import org.eclipse.debug.core.model.IVariable;
21
22 /**
23  * Ant stack frame.
24  */

25 public class AntStackFrame extends AntDebugElement implements IStackFrame {
26     
27     private AntThread fThread;
28     private String JavaDoc fName;
29     private int fLineNumber;
30     private String JavaDoc fFilePath;
31     private int fId;
32     private String JavaDoc fFullPath;
33     
34     /**
35      * Constructs a stack frame in the given thread with the given id.
36      *
37      * @param thread
38      * @param id stack frame id (0 is the top of the stack)
39      */

40     public AntStackFrame(AntThread thread, int id, String JavaDoc name, String JavaDoc fullPath, int lineNumber) {
41         super((AntDebugTarget) thread.getDebugTarget());
42         fId = id;
43         fThread = thread;
44         fLineNumber= lineNumber;
45         fName= name;
46         setFilePath(fullPath);
47     }
48     
49     protected void setId(int id) {
50         fId= id;
51     }
52     
53     /* (non-Javadoc)
54      * @see org.eclipse.debug.core.model.IStackFrame#getThread()
55      */

56     public IThread getThread() {
57         return fThread;
58     }
59     
60     /* (non-Javadoc)
61      * @see org.eclipse.debug.core.model.IStackFrame#getVariables()
62      */

63     public IVariable[] getVariables() throws DebugException {
64        return fThread.getVariables();
65     }
66
67     /* (non-Javadoc)
68      * @see org.eclipse.debug.core.model.IStackFrame#hasVariables()
69      */

70     public boolean hasVariables() {
71         return isSuspended();
72     }
73     
74     /* (non-Javadoc)
75      * @see org.eclipse.debug.core.model.IStackFrame#getLineNumber()
76      */

77     public int getLineNumber() {
78         return fLineNumber;
79     }
80     
81     protected void setLineNumber(int lineNumber) {
82         fLineNumber= lineNumber;
83     }
84     
85     protected void setFilePath(String JavaDoc fullPath) {
86         fFullPath= fullPath;
87         IFile file= AntUtil.getFileForLocation(fullPath, null);
88         if (file != null) {
89             fFilePath= file.getProjectRelativePath().toString();
90         } else {
91             fFilePath= new Path(fullPath).lastSegment();
92         }
93     }
94     
95     public String JavaDoc getFilePath() {
96         return fFullPath;
97     }
98     
99     /* (non-Javadoc)
100      * @see org.eclipse.debug.core.model.IStackFrame#getCharStart()
101      */

102     public int getCharStart() {
103         return -1;
104     }
105     
106     /* (non-Javadoc)
107      * @see org.eclipse.debug.core.model.IStackFrame#getCharEnd()
108      */

109     public int getCharEnd() {
110         return -1;
111     }
112     
113     /* (non-Javadoc)
114      * @see org.eclipse.debug.core.model.IStackFrame#getName()
115      */

116     public String JavaDoc getName() {
117         return fName;
118     }
119     
120     protected void setName(String JavaDoc name) {
121         fName= name;
122     }
123     
124     /* (non-Javadoc)
125      * @see org.eclipse.debug.core.model.IStackFrame#getRegisterGroups()
126      */

127     public IRegisterGroup[] getRegisterGroups() {
128         return null;
129     }
130     
131     /* (non-Javadoc)
132      * @see org.eclipse.debug.core.model.IStackFrame#hasRegisterGroups()
133      */

134     public boolean hasRegisterGroups() {
135         return false;
136     }
137     
138     /* (non-Javadoc)
139      * @see org.eclipse.debug.core.model.IStep#canStepInto()
140      */

141     public boolean canStepInto() {
142         return getThread().canStepInto();
143     }
144     
145     /* (non-Javadoc)
146      * @see org.eclipse.debug.core.model.IStep#canStepOver()
147      */

148     public boolean canStepOver() {
149         return getThread().canStepOver();
150     }
151     
152     /* (non-Javadoc)
153      * @see org.eclipse.debug.core.model.IStep#canStepReturn()
154      */

155     public boolean canStepReturn() {
156         return getThread().canStepReturn();
157     }
158     
159     /* (non-Javadoc)
160      * @see org.eclipse.debug.core.model.IStep#isStepping()
161      */

162     public boolean isStepping() {
163         return getThread().isStepping();
164     }
165     
166     /* (non-Javadoc)
167      * @see org.eclipse.debug.core.model.IStep#stepInto()
168      */

169     public void stepInto() throws DebugException {
170         getThread().stepInto();
171     }
172     
173     /* (non-Javadoc)
174      * @see org.eclipse.debug.core.model.IStep#stepOver()
175      */

176     public void stepOver() throws DebugException {
177         getThread().stepOver();
178     }
179     
180     /* (non-Javadoc)
181      * @see org.eclipse.debug.core.model.IStep#stepReturn()
182      */

183     public void stepReturn() throws DebugException {
184         getThread().stepReturn();
185     }
186     
187     /* (non-Javadoc)
188      * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
189      */

190     public boolean canResume() {
191         return getThread().canResume();
192     }
193     
194     /* (non-Javadoc)
195      * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
196      */

197     public boolean canSuspend() {
198         return getThread().canSuspend();
199     }
200     
201     /* (non-Javadoc)
202      * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
203      */

204     public boolean isSuspended() {
205         return getThread().isSuspended();
206     }
207     
208     /* (non-Javadoc)
209      * @see org.eclipse.debug.core.model.ISuspendResume#resume()
210      */

211     public void resume() throws DebugException {
212         getThread().resume();
213     }
214     
215     /* (non-Javadoc)
216      * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
217      */

218     public void suspend() throws DebugException {
219         getThread().suspend();
220     }
221     
222     /* (non-Javadoc)
223      * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
224      */

225     public boolean canTerminate() {
226         return getThread().canTerminate();
227     }
228     
229     /* (non-Javadoc)
230      * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
231      */

232     public boolean isTerminated() {
233         return getThread().isTerminated();
234     }
235     
236     /* (non-Javadoc)
237      * @see org.eclipse.debug.core.model.ITerminate#terminate()
238      */

239     public void terminate() throws DebugException {
240         getThread().terminate();
241     }
242     
243     /**
244      * Returns the name of the buildfile this stack frame is associated
245      * with.
246      *
247      * @return the name of the buildfile this stack frame is associated
248      * with
249      */

250     public String JavaDoc getSourceName() {
251         return fFilePath;
252     }
253     
254     /* (non-Javadoc)
255      * @see java.lang.Object#equals(java.lang.Object)
256      */

257     public boolean equals(Object JavaDoc obj) {
258         if (obj instanceof AntStackFrame) {
259             AntStackFrame sf = (AntStackFrame)obj;
260             if (getSourceName() != null) {
261                 return getSourceName().equals(sf.getSourceName()) &&
262                     sf.getLineNumber() == getLineNumber() &&
263                     sf.fId == fId;
264             }
265             return sf.fId == fId;
266         }
267         return false;
268     }
269     
270     /* (non-Javadoc)
271      * @see java.lang.Object#hashCode()
272      */

273     public int hashCode() {
274         if (getSourceName() == null) {
275             return fId;
276         }
277         return getSourceName().hashCode() + fId;
278     }
279     
280     /**
281      * Returns this stack frame's unique identifier within its thread
282      *
283      * @return this stack frame's unique identifier within its thread
284      */

285     protected int getIdentifier() {
286         return fId;
287     }
288     
289     /**
290      * Returns the system, user or runtime property
291      * name, or <code>null</code> if unable to resolve a property with the name.
292      *
293      * @param propertyName the name of the variable to search for
294      * @return a property, or <code>null</code> if none
295      */

296     public AntProperty findProperty(String JavaDoc propertyName) {
297         try {
298             IVariable[] groups= getVariables();
299             for (int i = 0; i < groups.length; i++) {
300                 AntProperties propertiesGrouping = (AntProperties) groups[i];
301                 AntPropertiesValue value= (AntPropertiesValue) propertiesGrouping.getValue();
302                 IVariable[] properties= value.getVariables();
303                 for (int j = 0; j < properties.length; j++) {
304                     AntProperty property = (AntProperty) properties[j];
305                     if (property.getName().equals(propertyName)) {
306                         return property;
307                     }
308                 }
309             }
310         } catch (DebugException e) {
311         }
312         return null;
313     }
314 }
315
Popular Tags