KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > retouche > navigation > ElementScanningTask


1 /*
2  * ElementScanningTask.java
3  *
4  * Created on November 9, 2006, 6:04 PM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.modules.retouche.navigation;
11 import java.util.ArrayList JavaDoc;
12 import java.util.Collections JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.List JavaDoc;
15 import java.util.Set JavaDoc;
16 import org.netbeans.api.gsf.CancellableTask;
17 import org.netbeans.api.gsf.Parser;
18 import org.netbeans.api.gsf.ParserResult;
19 import org.netbeans.api.gsf.StructureScanner;
20 import org.netbeans.api.gsf.Element;
21 import org.netbeans.api.gsf.ElementHandle;
22 import org.netbeans.api.gsf.ElementKind;
23 import org.netbeans.api.gsf.Modifier;
24 import org.netbeans.api.gsf.StructureItem;
25 import org.netbeans.api.retouche.source.CompilationInfo;
26 import org.netbeans.modules.gsf.GsfHtmlFormatter;
27 import org.netbeans.modules.retouche.navigation.ElementNode.Description;
28
29 /**
30  * This file is originally from Retouche, the Java Support
31  * infrastructure in NetBeans. I have modified the file as little
32  * as possible to make merging Retouche fixes back as simple as
33  * possible.
34  * <p>
35  *
36  * XXX Remove the ElementScanner class from here it should be wenough to
37  * consult the Elements class. It should also permit for showing inherited members.
38  *
39  * @author phrebejk
40  */

41 public class ElementScanningTask implements CancellableTask<CompilationInfo>{
42     
43     private ClassMemberPanelUI ui;
44     private volatile boolean canceled;
45     
46     public ElementScanningTask( ClassMemberPanelUI ui ) {
47         this.ui = ui;
48     }
49     
50     public void cancel() {
51         canceled = true;
52 // if ( scanner != null ) {
53
// scanner.cancel();
54
// }
55
}
56
57     public void run(CompilationInfo info) throws Exception JavaDoc {
58         
59         canceled = false; // Task shared for one file needs reset first
60

61         //System.out.println("The task is running" + info.getFileObject().getNameExt() + "=====================================" ) ;
62

63         final List JavaDoc<StructureItem> items = new ArrayList JavaDoc<StructureItem>();
64         StructureItem rootDescription = new StructureItem() {
65             public String JavaDoc getName() {
66                 return null;
67             }
68
69             public String JavaDoc getHtml() {
70                 return null;
71             }
72
73             public ElementHandle<? extends Element> getElementHandle() {
74                 throw new UnsupportedOperationException JavaDoc("Not supported on the Root Node.");
75             }
76
77             public ElementKind getKind() {
78                 return ElementKind.OTHER;
79             }
80
81             public Set JavaDoc<Modifier> getModifiers() {
82                 return Collections.emptySet();
83             }
84
85             public boolean isLeaf() {
86                 return false;
87             }
88
89             public List JavaDoc<? extends StructureItem> getNestedItems() {
90                 return items;
91             }
92
93             public long getPosition() {
94                 throw new UnsupportedOperationException JavaDoc("Not supported on the Root Node.");
95             }
96         };
97         
98         ParserResult pr = info.getParserResult();
99         if (pr != null) {
100             StructureScanner scanner = info.getLanguage().getStructure();
101             Parser parser = info.getParser();
102             if (scanner != null && parser != null) {
103                 List JavaDoc<? extends StructureItem> children = scanner.scan(info, new NavigatorFormatter());
104                 for (StructureItem co : children) {
105                     items.add(co);
106                 }
107             }
108         }
109         
110         if ( !canceled ) {
111             ui.refresh( rootDescription, info.getFileObject() );
112             
113         }
114     }
115     
116     private class NavigatorFormatter extends GsfHtmlFormatter {
117         @Override JavaDoc
118         public void name(ElementKind kind, boolean start) {
119             // No special formatting for names
120
}
121
122         @Override JavaDoc
123         public void parameters(boolean start) {
124             // No special formatting for parameters
125
}
126     }
127 }
128     
129
Popular Tags