KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > debugger > jpda > test > TestContextProvider


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.api.debugger.jpda.test;
21
22 import java.io.File JavaDoc;
23 import java.net.MalformedURLException JavaDoc;
24 import java.net.URI JavaDoc;
25 import java.net.URISyntaxException JavaDoc;
26 import java.net.URL JavaDoc;
27 import org.netbeans.spi.debugger.jpda.EditorContext;
28
29 import java.beans.PropertyChangeListener JavaDoc;
30 import java.beans.PropertyChangeSupport JavaDoc;
31 import org.openide.filesystems.URLMapper;
32
33 /**
34  * A simple (rather empty) implementation of ContextProvider for unit tests.
35  *
36  * @author Maros Sandor
37  */

38 public class TestContextProvider extends EditorContext {
39
40     private String JavaDoc sourceRoot = System.getProperty ("test.dir.src");
41     private PropertyChangeSupport JavaDoc pcs;
42
43     public TestContextProvider() {
44         pcs = new PropertyChangeSupport JavaDoc (this);
45     }
46
47     public boolean showSource(String JavaDoc url, int lineNumber, Object JavaDoc timeStamp) {
48         return false;
49     }
50     
51     public void createTimeStamp (Object JavaDoc timeStamp) {
52     }
53
54     public void disposeTimeStamp (Object JavaDoc timeStamp) {
55     }
56     
57     public void updateTimeStamp (Object JavaDoc timeStamp, String JavaDoc url) {
58     }
59
60     public Object JavaDoc annotate(String JavaDoc url, int lineNumber, String JavaDoc annotationType, Object JavaDoc timeStamp) {
61         return null;
62     }
63
64     public void removeAnnotation(Object JavaDoc annotation) {
65     }
66     
67     public int getLineNumber (Object JavaDoc annotation, Object JavaDoc timeStamp) {
68         return -1;
69     }
70
71     public int getCurrentLineNumber() {
72         return -1;
73     }
74
75     public String JavaDoc getCurrentClassName() {
76         return "";
77     }
78
79     public String JavaDoc getCurrentURL() {
80         return "";
81     }
82
83     public String JavaDoc getCurrentMethodName() {
84         return "";
85     }
86
87     public String JavaDoc getCurrentFieldName() {
88         return null;
89     }
90
91     public String JavaDoc getSelectedIdentifier() {
92         return null;
93     }
94
95     public String JavaDoc getSelectedMethodName() {
96         return "";
97     }
98
99     public int getFieldLineNumber(String JavaDoc url, String JavaDoc className, String JavaDoc fieldName) {
100         return -1;
101     }
102     
103     public String JavaDoc getClassName (
104         String JavaDoc url,
105         int lineNumber
106     ) {
107         URI JavaDoc uri = null;
108         try {
109             url = new File JavaDoc(uri = new URL JavaDoc(url).toURI()).getAbsolutePath();
110         } catch (MalformedURLException JavaDoc ex) {
111             ex.printStackTrace();
112         } catch (URISyntaxException JavaDoc ex) {
113             ex.printStackTrace();
114         } catch (IllegalArgumentException JavaDoc iaex) {
115             System.err.println("Illegal url: "+url+", URI = "+uri);
116             throw iaex;
117         }
118         if (!url.startsWith (sourceRoot)) return null;
119         url = url.substring (sourceRoot.length ());
120         int i = url.lastIndexOf ('.');
121         if (i > 0)
122             url = url.substring (0, i);
123         url = url.replace ('/', '.');
124         return url;
125     }
126
127     public Operation[] getOperations(String JavaDoc url, final int lineNumber,
128                                      final BytecodeProvider bytecodeProvider) {
129         //EditorContextImpl impl = new EditorContextImpl();
130
//return impl.getOperations(url, lineNumber, bytecodeProvider);
131
// Hard-coded operations, because of problematic access to jpda/projects module
132
if (url.endsWith("ExpressionStepApp.java")) {
133             Operation[] ops = createExpressionSteppAppOperations(lineNumber);
134             if (ops == null) {
135                 throw new IllegalStateException JavaDoc(url+":"+lineNumber);
136             }
137             return ops;
138         }
139         return new Operation[] {}; // Called by step out also from various tests.
140
//throw new IllegalStateException(url);
141
}
142     
143     private Operation[] createExpressionSteppAppOperations(int lineNumber) {
144         if (lineNumber == 30) {
145             return new Operation[] {
146                 createMethodOperation(createPosition(1124, 30, 14),
147                                       createPosition(1137, 30, 27),
148                                       createPosition(1124, 30, 14),
149                                       createPosition(1133, 30, 23),
150                                       "factorial",
151                                       "debuggertest1.ExpressionStepApp",
152                                       5)
153             };
154         }
155         if (lineNumber == 31) {
156             return new Operation[] {
157                 createMethodOperation(createPosition(1152, 31, 14),
158                                       createPosition(1165, 31, 27),
159                                       createPosition(1152, 31, 14),
160                                       createPosition(1161, 31, 23),
161                                       "factorial",
162                                       "debuggertest1.ExpressionStepApp",
163                                       17),
164                 createMethodOperation(createPosition(1168, 31, 30),
165                                       createPosition(1181, 31, 43),
166                                       createPosition(1168, 31, 30),
167                                       createPosition(1177, 31, 39),
168                                       "factorial",
169                                       "debuggertest1.ExpressionStepApp",
170                                       22)
171             };
172         }
173         if (lineNumber == 32) {
174             return new Operation[] {
175                 createMethodOperation(createPosition(1196, 32, 14),
176                                       createPosition(1209, 32, 27),
177                                       createPosition(1196, 32, 14),
178                                       createPosition(1205, 32, 23),
179                                       "factorial",
180                                       "debuggertest1.ExpressionStepApp",
181                                       35),
182                 createMethodOperation(createPosition(1216, 32, 34),
183                                       createPosition(1229, 32, 47),
184                                       createPosition(1216, 32, 34),
185                                       createPosition(1225, 32, 43),
186                                       "factorial",
187                                       "debuggertest1.ExpressionStepApp",
188                                       47)
189             };
190         }
191         if (lineNumber == 33) {
192             return new Operation[] {
193                 createMethodOperation(createPosition(1263, 33, 33),
194                                       createPosition(1286, 33, 56),
195                                       createPosition(1267, 33, 37),
196                                       createPosition(1284, 33, 54),
197                                       "<init>",
198                                       "debuggertest1.ExpressionStepApp",
199                                       58)
200             };
201         }
202         if (lineNumber == 34) {
203             return new Operation[] {
204                 createMethodOperation(createPosition(1307, 34, 20),
205                                       createPosition(1322, 34, 35),
206                                       createPosition(1307, 34, 20),
207                                       createPosition(1313, 34, 26),
208                                       "m2",
209                                       "debuggertest1.ExpressionStepApp",
210                                       68),
211                 createMethodOperation(createPosition(1300, 34, 13),
212                                       createPosition(1323, 34, 36),
213                                       createPosition(1300, 34, 13),
214                                       createPosition(1306, 34, 19),
215                                       "m1",
216                                       "debuggertest1.ExpressionStepApp",
217                                       71)
218             };
219         }
220         if (lineNumber == 35) {
221             return new Operation[] {
222                 createMethodOperation(createPosition(1351, 35, 27),
223                                       createPosition(1366, 35, 42),
224                                       createPosition(1351, 35, 27),
225                                       createPosition(1357, 35, 33),
226                                       "m2",
227                                       "debuggertest1.ExpressionStepApp",
228                                       85),
229                 createMethodOperation(createPosition(1344, 35, 20),
230                                       createPosition(1367, 35, 43),
231                                       createPosition(1344, 35, 20),
232                                       createPosition(1350, 35, 26),
233                                       "m1",
234                                       "debuggertest1.ExpressionStepApp",
235                                       88),
236                 createMethodOperation(createPosition(1395, 36, 27),
237                                       createPosition(1410, 36, 42),
238                                       createPosition(1395, 36, 27),
239                                       createPosition(1401, 36, 33),
240                                       "m1",
241                                       "debuggertest1.ExpressionStepApp",
242                                       96),
243                 createMethodOperation(createPosition(1337, 35, 13),
244                                       createPosition(1411, 35, 43),
245                                       createPosition(1337, 35, 13),
246                                       createPosition(1343, 35, 19),
247                                       "m3",
248                                       "debuggertest1.ExpressionStepApp",
249                                       99),
250                 createMethodOperation(createPosition(1337, 35, 13),
251                                       createPosition(1422, 36, 54),
252                                       createPosition(1337, 35, 13),
253                                       createPosition(1420, 36, 52),
254                                       "intValue",
255                                       "debuggertest1.ExpressionStepApp",
256                                       102)
257             };
258         }
259         return null;
260     }
261     
262     public String JavaDoc[] getImports(String JavaDoc url) {
263         return new String JavaDoc[0];
264     }
265
266     public void addPropertyChangeListener(PropertyChangeListener JavaDoc l) {
267         pcs.addPropertyChangeListener (l);
268     }
269
270     public void removePropertyChangeListener(PropertyChangeListener JavaDoc l) {
271         pcs.removePropertyChangeListener (l);
272     }
273
274     public void addPropertyChangeListener(String JavaDoc propertyName, PropertyChangeListener JavaDoc l) {
275         pcs.addPropertyChangeListener (propertyName, l);
276     }
277
278     public void removePropertyChangeListener(String JavaDoc propertyName, PropertyChangeListener JavaDoc l) {
279         pcs.removePropertyChangeListener (propertyName, l);
280     }
281 }
282
Popular Tags