1 9 10 package org.netbeans.modules.retouche.navigation; 11 import java.util.ArrayList ; 12 import java.util.Collections ; 13 import java.util.Iterator ; 14 import java.util.List ; 15 import java.util.Set ; 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 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 } 56 57 public void run(CompilationInfo info) throws Exception { 58 59 canceled = false; 61 63 final List <StructureItem> items = new ArrayList <StructureItem>(); 64 StructureItem rootDescription = new StructureItem() { 65 public String getName() { 66 return null; 67 } 68 69 public String getHtml() { 70 return null; 71 } 72 73 public ElementHandle<? extends Element> getElementHandle() { 74 throw new UnsupportedOperationException ("Not supported on the Root Node."); 75 } 76 77 public ElementKind getKind() { 78 return ElementKind.OTHER; 79 } 80 81 public Set <Modifier> getModifiers() { 82 return Collections.emptySet(); 83 } 84 85 public boolean isLeaf() { 86 return false; 87 } 88 89 public List <? extends StructureItem> getNestedItems() { 90 return items; 91 } 92 93 public long getPosition() { 94 throw new UnsupportedOperationException ("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 <? 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 118 public void name(ElementKind kind, boolean start) { 119 } 121 122 @Override 123 public void parameters(boolean start) { 124 } 126 } 127 } 128 129 | Popular Tags |