KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > debugger > jpda > EditorContext


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 Micro//S ystems, Inc. Portions Copyright 1997-2006 Sun
17  * Micro//S ystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.spi.debugger.jpda;
20
21 import java.beans.PropertyChangeListener JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import org.netbeans.api.debugger.jpda.LineBreakpoint;
28 import org.netbeans.api.debugger.jpda.Variable;
29
30 /**
31  * Defines bridge to editor and src hierarchy. It allows to use different
32  * source viewer for debugger (like some UML view).
33  *
34  * @author Jan Jancura
35  */

36 public abstract class EditorContext {
37
38     /** Annotation type constant. */
39     public static final String JavaDoc BREAKPOINT_ANNOTATION_TYPE = "Breakpoint";
40     /** Annotation type constant. */
41     public static final String JavaDoc DISABLED_BREAKPOINT_ANNOTATION_TYPE = "DisabledBreakpoint";
42     /** Annotation type constant. */
43     public static final String JavaDoc CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE = "CondBreakpoint";
44     /** Annotation type constant. */
45     public static final String JavaDoc DISABLED_CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE = "DisabledCondBreakpoint";
46     /** Annotation type constant. */
47     public static final String JavaDoc CURRENT_LINE_ANNOTATION_TYPE = "CurrentPC";
48     /** Annotation type constant. */
49     public static final String JavaDoc CALL_STACK_FRAME_ANNOTATION_TYPE = "CallSite";
50     /** Annotation type constant. */
51     public static final String JavaDoc CURRENT_LAST_OPERATION_ANNOTATION_TYPE = "LastOperation";
52     /** Annotation type constant. */
53     public static final String JavaDoc CURRENT_OUT_OPERATION_ANNOTATION_TYPE = "StepOutOperation";
54     /** Annotation type constant. */
55     public static final String JavaDoc CURRENT_EXPRESSION_SECONDARY_LINE_ANNOTATION_TYPE = "CurrentExpression";
56     /** Annotation type constant. */
57     public static final String JavaDoc CURRENT_EXPRESSION_CURRENT_LINE_ANNOTATION_TYPE = "CurrentExpressionLine";
58
59     /** Property name constant. */
60     public static final String JavaDoc PROP_LINE_NUMBER = "lineNumber";
61
62
63     /**
64      * Shows source with given url on given line number.
65      *
66      * @param url a url of source to be shown
67      * @param lineNumber a number of line to be shown
68      * @param timeStamp a time stamp to be used
69      */

70     public abstract boolean showSource (
71         String JavaDoc url,
72         int lineNumber,
73         Object JavaDoc timeStamp
74     );
75
76     /**
77      * Creates a new time stamp.
78      *
79      * @param timeStamp a new time stamp
80      */

81     public abstract void createTimeStamp (Object JavaDoc timeStamp);
82
83     /**
84      * Disposes given time stamp.
85      *
86      * @param timeStamp a time stamp to be disposed
87      */

88     public abstract void disposeTimeStamp (Object JavaDoc timeStamp);
89     
90     /**
91      * Updates timeStamp for gived url.
92      *
93      * @param timeStamp time stamp to be updated
94      * @param url an url
95      */

96     public abstract void updateTimeStamp (Object JavaDoc timeStamp, String JavaDoc url);
97
98     /**
99      * Adds annotation to given url on given line.
100      *
101      * @param url a url of source annotation should be set into
102      * @param lineNumber a number of line annotation should be set into
103      * @param annotationType a type of annotation to be set
104      * @param timeStamp a time stamp to be used
105      *
106      * @return annotation or <code>null</code>, when the annotation can not be
107      * created at the given URL or line number.
108      */

109     public abstract Object JavaDoc annotate (
110         String JavaDoc url,
111         int lineNumber,
112         String JavaDoc annotationType,
113         Object JavaDoc timeStamp
114     );
115
116     /**
117      * Adds annotation to given url on given character range.
118      *
119      * @param url a url of source annotation should be set into
120      * @param startPosition the offset of the starting position of the annotation
121      * @param endPosition the offset of the ending position of the annotation
122      * @param annotationType a type of annotation to be set
123
124      * @return annotation or <code>null</code>, when the annotation can not be
125      * created at the given URL or line number.
126      */

127     public Object JavaDoc annotate (
128         String JavaDoc url,
129         int startPosition,
130         int endPosition,
131         String JavaDoc annotationType,
132         Object JavaDoc timeStamp
133     ) {
134         return null;
135     }
136
137     /**
138      * Returns line number given annotation is associated with.
139      *
140      * @param annotation a annotation
141      * @param timeStamp a time stamp to be used
142      *
143      * @return line number given annotation is associated with
144      */

145     public abstract int getLineNumber (
146         Object JavaDoc annotation,
147         Object JavaDoc timeStamp
148     );
149
150     /**
151      * Removes given annotation.
152      */

153     public abstract void removeAnnotation (
154         Object JavaDoc annotation
155     );
156
157     /**
158      * Returns number of line currently selected in editor or <code>-1</code>.
159      *
160      * @return number of line currently selected in editor or <code>-1</code>
161      */

162     public abstract int getCurrentLineNumber ();
163
164     /**
165      * Returns name of class currently selected in editor or empty string.
166      *
167      * @return name of class currently selected in editor or empty string
168      */

169     public abstract String JavaDoc getCurrentClassName ();
170
171     /**
172      * Returns URL of source currently selected in editor or empty string.
173      *
174      * @return URL of source currently selected in editor or empty string
175      */

176     public abstract String JavaDoc getCurrentURL ();
177
178     /**
179      * Returns name of method currently selected in editor or empty string.
180      *
181      * @return name of method currently selected in editor or empty string
182      */

183     public abstract String JavaDoc getCurrentMethodName ();
184
185     /**
186      * Returns name of field currently selected in editor or <code>null</code>.
187      *
188      * @return name of field currently selected in editor or <code>null</code>
189      */

190     public abstract String JavaDoc getCurrentFieldName ();
191
192     /**
193      * Returns identifier currently selected in editor or <code>null</code>.
194      *
195      * @return identifier currently selected in editor or <code>null</code>
196      */

197     public abstract String JavaDoc getSelectedIdentifier ();
198
199     /**
200      * Returns method name currently selected in editor or empty string.
201      *
202      * @return method name currently selected in editor or empty string
203      */

204     public abstract String JavaDoc getSelectedMethodName ();
205     
206     /**
207      * Returns line number of given field in given class.
208      *
209      * @param url the url of file the class is deined in
210      * @param className the name of class (or innerclass) the field is
211      * defined in
212      * @param fieldName the name of field
213      *
214      * @return line number or -1
215      */

216     public abstract int getFieldLineNumber (
217         String JavaDoc url,
218         String JavaDoc className,
219         String JavaDoc fieldName
220     );
221     
222     /**
223      * Returns class name for given url and line number or null.
224      *
225      * @param url a url
226      * @param lineNumber a line number
227      *
228      * @return class name for given url and line number or null
229      */

230     public abstract String JavaDoc getClassName (
231         String JavaDoc url,
232         int lineNumber
233     );
234     
235     /**
236      * Returns list of imports for given source url.
237      *
238      * @param url the url of source file
239      *
240      * @return list of imports for given source url
241      */

242     public abstract String JavaDoc[] getImports (String JavaDoc url);
243     
244     /**
245      * Creates an operation which is determined by starting and ending position.
246      *
247     protected final Operation createOperation(Position startPosition,
248                                               Position endPosition,
249                                               int bytecodeIndex) {
250         return new Operation(startPosition, endPosition, bytecodeIndex);
251     }
252      */

253     
254     /**
255      * Creates a method operation.
256      * @param startPosition The starting position of the operation
257      * @param endPosition The ending position of the operation
258      * @param methodStartPosition The starting position of the method name
259      * @param methodEndPosition The ending position of the method name
260      * @param methodName The string representation of the method name
261      * @param methodClassType The class type, which defines this method
262      * @param bytecodeIndex The bytecode index of this method call
263      */

264     protected final Operation createMethodOperation(Position startPosition,
265                                                     Position endPosition,
266                                                     Position methodStartPosition,
267                                                     Position methodEndPosition,
268                                                     String JavaDoc methodName,
269                                                     String JavaDoc methodClassType,
270                                                     int bytecodeIndex) {
271         return new Operation(startPosition, endPosition,
272                              methodStartPosition, methodEndPosition,
273                              methodName, methodClassType, bytecodeIndex);
274     }
275     
276     /**
277      * Assign a next operation, concatenates operations.
278      * @param operation The first operation
279      * @param next The next operation
280      */

281     protected final void addNextOperationTo(Operation operation, Operation next) {
282         operation.addNextOperation(next);
283     }
284     
285     /**
286      * Creates a new {@link Position} object.
287      * @param offset The offset
288      * @param line The line number
289      * @param column The column number
290      */

291     protected final Position createPosition(
292             int offset, int line, int column) {
293         
294         return new Position(offset, line, column);
295     }
296     
297     /**
298      * Get the list of operations that are in expression(s) located at the given line.
299      * @param url The file's URL
300      * @param lineNumber The line number
301      * @param bytecodeProvider The provider of method bytecodes.
302      */

303     public Operation[] getOperations(String JavaDoc url, int lineNumber,
304                                      BytecodeProvider bytecodeProvider) {
305         throw new UnsupportedOperationException JavaDoc("This method is not implemented.");
306     }
307     
308     /**
309      * Adds a property change listener.
310      *
311      * @param l the listener to add
312      */

313     public abstract void addPropertyChangeListener (PropertyChangeListener JavaDoc l);
314     
315     /**
316      * Removes a property change listener.
317      *
318      * @param l the listener to remove
319      */

320     public abstract void removePropertyChangeListener (PropertyChangeListener JavaDoc l);
321     
322     /**
323      * Adds a property change listener.
324      *
325      * @param propertyName the name of property
326      * @param l the listener to add
327      */

328     public abstract void addPropertyChangeListener (
329         String JavaDoc propertyName,
330         PropertyChangeListener JavaDoc l
331     );
332     
333     /**
334      * Removes a property change listener.
335      *
336      * @param propertyName the name of property
337      * @param l the listener to remove
338      */

339     public abstract void removePropertyChangeListener (
340         String JavaDoc propertyName,
341         PropertyChangeListener JavaDoc l
342     );
343     
344     /**
345      * A provider of method bytecode information.
346      */

347     public interface BytecodeProvider {
348         
349         /**
350          * Retrieve the class' constant pool.
351          */

352         byte[] constantPool();
353         
354         /**
355          * Retrieve the bytecodes of the method.
356          */

357         byte[] byteCodes();
358         
359         /**
360          * Get an array of bytecode indexes of operations between the starting
361          * and ending line.
362          * @param startLine The starting line
363          * @param endLine The ending line
364          */

365         int[] indexAtLines(int startLine, int endLine);
366         
367     }
368     
369     /**
370      * The operation definition.
371      */

372     public static final class Operation {
373         
374         private final Position startPosition;
375         private final Position endPosition;
376         private final int bytecodeIndex;
377
378         private Position methodStartPosition;
379         private Position methodEndPosition;
380         private String JavaDoc methodName;
381         private String JavaDoc methodClassType;
382         private Variable returnValue;
383         
384         private List JavaDoc<Operation> nextOperations;
385         
386         /*
387         Operation(Position startPosition, Position endPosition,
388                   int bytecodeIndex) {
389             this.startPosition = startPosition;
390             this.endPosition = endPosition;
391             this.bytecodeIndex = bytecodeIndex;
392         }
393          */

394         
395         /**
396          * Creates a new method operation.
397          */

398         Operation(Position startPosition, Position endPosition,
399                   Position methodStartPosition, Position methodEndPosition,
400                   String JavaDoc methodName, String JavaDoc methodClassType,
401                   int bytecodeIndex) {
402             this.startPosition = startPosition;
403             this.endPosition = endPosition;
404             this.bytecodeIndex = bytecodeIndex;
405             this.methodStartPosition = methodStartPosition;
406             this.methodEndPosition = methodEndPosition;
407             this.methodName = methodName;
408             this.methodClassType = methodClassType;
409         }
410         
411         synchronized void addNextOperation(Operation next) {
412             if (nextOperations == null) {
413                 nextOperations = new ArrayList JavaDoc<Operation>();
414             }
415             nextOperations.add(next);
416         }
417         
418         /**
419          * Get the starting position of this operation.
420          */

421         public Position getStartPosition() {
422             return startPosition;
423         }
424         
425         /**
426          * Get the ending position of this operation.
427          */

428         public Position getEndPosition() {
429             return endPosition;
430         }
431         
432         /**
433          * Get the starting position of the method call of this operation.
434          */

435         public Position getMethodStartPosition() {
436             return methodStartPosition;
437         }
438
439         /**
440          * Get the ending position of the method call of this operation.
441          */

442         public Position getMethodEndPosition() {
443             return methodEndPosition;
444         }
445
446         /**
447          * Get the method name.
448          */

449         public String JavaDoc getMethodName() {
450             return methodName;
451         }
452         
453         /**
454          * Get the class type declaring the method.
455          */

456         public String JavaDoc getMethodClassType() {
457             return methodClassType;
458         }
459         
460         /**
461          * Get the bytecode index of this operation.
462          */

463         public int getBytecodeIndex() {
464             return bytecodeIndex;
465         }
466
467         /**
468          * Set the return value of this operation.
469          */

470         public void setReturnValue(Variable returnValue) {
471             this.returnValue = returnValue;
472         }
473         
474         /**
475          * Get the return value of this operation.
476          */

477         public Variable getReturnValue() {
478             return returnValue;
479         }
480         
481         /**
482          * Get the list of following operations.
483          */

484         public List JavaDoc<Operation> getNextOperations() {
485             if (nextOperations == null) {
486                 return Collections.emptyList();
487             } else {
488                 synchronized (this) {
489                     return Collections.unmodifiableList(nextOperations);
490                 }
491             }
492         }
493
494         public boolean equals(Object JavaDoc obj) {
495             if (obj instanceof Operation) {
496                 Operation op2 = (Operation) obj;
497                 return bytecodeIndex == op2.bytecodeIndex &&
498                         ((startPosition == null) ?
499                             op2.startPosition == null :
500                             startPosition.equals(op2.startPosition)) &&
501                         ((endPosition == null) ?
502                             op2.endPosition == null :
503                             endPosition.equals(op2.endPosition));
504             }
505             return false;
506         }
507
508         public int hashCode() {
509             return bytecodeIndex;
510         }
511
512     }
513     
514     /**
515      * Representation of a position in a source code.
516      */

517     public static final class Position {
518
519         private final int offset;
520         private final int line;
521         private final int column;
522
523         Position(int offset, int line, int column) {
524             this.offset = offset;
525             this.line = line;
526             this.column = column;
527         }
528
529         /**
530          * Get the offset of this position.
531          */

532         public int getOffset() {
533             return offset;
534         }
535
536         /**
537          * Get the line number of this position.
538          */

539         public int getLine() {
540             return line;
541         }
542
543         /**
544          * Get the column number of this position.
545          */

546         public int getColumn() {
547             return column;
548         }
549
550         public boolean equals(Object JavaDoc obj) {
551             if (obj instanceof Position) {
552                 Position pos = (Position) obj;
553                 return pos.offset == offset;
554             }
555             return false;
556         }
557
558         public int hashCode() {
559             return offset;
560         }
561         
562     }
563
564 }
565
566
Popular Tags