1 19 20 package org.netbeans.modules.java.navigation; 21 22 import com.sun.source.tree.CompilationUnitTree; 23 import com.sun.source.tree.Tree; 24 import com.sun.source.util.Trees; 25 import org.netbeans.api.java.source.CancellableTask; 26 import org.netbeans.api.java.source.CompilationController; 27 import org.netbeans.api.java.source.JavaSource; 28 import org.netbeans.api.java.source.JavaSource.Phase; 29 import org.openide.ErrorManager; 30 import java.io.IOException ; 31 import java.util.LinkedHashSet ; 32 import java.util.List ; 33 import java.util.Set ; 34 import javax.lang.model.element.Element; 35 import javax.swing.JDialog ; 36 import org.openide.filesystems.FileObject; 37 import org.openide.util.NbBundle; 38 39 43 public final class JavaHierarchy { 44 45 50 public static void show(final FileObject fileObject) { 51 if (fileObject != null) { 52 JavaSource javaSource = JavaSource.forFileObject(fileObject); 53 54 if (javaSource != null) { 55 try { 56 javaSource.runUserActionTask(new CancellableTask<CompilationController>() { 57 public void cancel() { 58 } 59 60 public void run( 61 CompilationController compilationController) 62 throws Exception { 63 compilationController.toPhase(Phase.ELEMENTS_RESOLVED); 64 65 Trees trees = compilationController.getTrees(); 66 CompilationUnitTree compilationUnitTree = compilationController.getCompilationUnit(); 67 List <?extends Tree> typeDecls = compilationUnitTree.getTypeDecls(); 68 69 Set <Element> elementsSet = new LinkedHashSet <Element>(typeDecls.size() + 1); 70 71 for (Tree tree : typeDecls) { 72 Element element = trees.getElement(trees.getPath(compilationUnitTree, tree)); 73 74 if (element != null) { 75 elementsSet.add(element); 76 } 77 } 78 79 Element[] elements = elementsSet.toArray(JavaMembersModel.EMPTY_ELEMENTS_ARRAY); 80 show(fileObject, elements, compilationController); 81 } 82 }, false); 83 84 return; 85 } catch (IOException ioe) { 86 ErrorManager.getDefault().notify(ioe); 87 } 88 } 89 } 90 } 91 92 static void show(FileObject fileObject, Element[] elements, 93 CompilationController compilationController) { 94 if (fileObject != null) { 95 JDialog dialog = ResizablePopup.getDialog(); 96 dialog.setTitle(NbBundle.getMessage(JavaHierarchy.class, "TITLE_Hierarchy")); dialog.setContentPane(new JavaHierarchyPanel(fileObject, elements, compilationController)); 98 dialog.setVisible(true); 99 } 100 } 101 102 } 103 | Popular Tags |