KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > ui > SmartSteppingImpl


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.modules.debugger.jpda.ui;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.Set JavaDoc;
26
27 import org.netbeans.api.debugger.jpda.JPDAThread;
28 import org.netbeans.api.debugger.jpda.SmartSteppingFilter;
29 import org.netbeans.spi.debugger.jpda.SourcePathProvider;
30 import org.netbeans.api.debugger.DebuggerEngine;
31 import org.netbeans.spi.debugger.ContextProvider;
32 import org.netbeans.api.debugger.Session;
33 import org.netbeans.spi.debugger.jpda.SmartSteppingCallback;
34
35
36 public class SmartSteppingImpl extends SmartSteppingCallback implements
37 PropertyChangeListener JavaDoc {
38     
39     
40     private Set JavaDoc exclusionPatterns = new HashSet JavaDoc ();
41     private SmartSteppingFilter smartSteppingFilter;
42     
43     
44     /**
45      * Defines default set of smart stepping filters. Method is called when
46      * a new JPDA debugger session is created.
47      *
48      * @param f a filter to be initialized
49      */

50     public void initFilter (SmartSteppingFilter f) {
51         smartSteppingFilter = f;
52     }
53     
54     /**
55      * This method is called during stepping through debugged application.
56      * The execution is stopped when all registerred SmartSteppingListeners
57      * returns true.
58      *
59      * @param thread contains all available information about current position
60      * in debugged application
61      * @param f a filter
62      * @return true if execution should be stopped on the current position
63      */

64     public boolean stopHere (
65         ContextProvider lookupProvider,
66         JPDAThread thread,
67         SmartSteppingFilter f
68     ) {
69         String JavaDoc className = thread.getClassName ();
70         if (className == null) return false;
71
72         SourcePath ectx = getEngineContext (lookupProvider);
73         boolean b = ectx.sourceAvailable (thread, null, false);
74         if (b) return true;
75         
76         // find pattern
77
String JavaDoc name, n1 = className.replace ('.', '/');
78         do {
79             name = n1;
80             int i = name.lastIndexOf ('/');
81             if (i < 0) break;
82             n1 = name.substring (0, i);
83         } while (!ectx.sourceAvailable (n1, false));
84         HashSet JavaDoc s = new HashSet JavaDoc ();
85         s.add (name.replace ('/', '.') + ".*");
86         addExclusionPatterns (s);
87         return false;
88     }
89     
90     private void addExclusionPatterns (
91         Set JavaDoc ep
92     ) {
93         smartSteppingFilter.addExclusionPatterns (ep);
94         exclusionPatterns.addAll (ep);
95     }
96     
97     private void removeExclusionPatterns () {
98         smartSteppingFilter.removeExclusionPatterns (exclusionPatterns);
99         exclusionPatterns = new HashSet JavaDoc ();
100     }
101     
102     private SourcePath engineContext;
103     
104     private SourcePath getEngineContext (ContextProvider lookupProvider) {
105         if (engineContext == null) {
106             engineContext = (SourcePath) lookupProvider.lookupFirst
107                 (null, SourcePath.class);
108             engineContext.addPropertyChangeListener (this);
109         }
110         return engineContext;
111     }
112     
113     public void propertyChange (PropertyChangeEvent JavaDoc evt) {
114         if (evt.getPropertyName () == SourcePathProvider.PROP_SOURCE_ROOTS) {
115             removeExclusionPatterns ();
116         }
117     }
118 }
119
Popular Tags