Search code examples
javaeclipseeclipse-plugineclipse-jdt

How can I set the region (=set of java Elements) parameter in JDT TypeHierarchy?


http://www.google.com/url?sa=t&rct=j&q=jdt_fundamentals&source=web&cd=1&ved=0CDIQFjAA&url=http%3A%2F%2Fwww.eclipsecon.org%2F2008%2Fsub%2Fattachments%2FJDT_fundamentals.ppt">JDT Tutorial an example code to get the type hierarchy using JDT.

enter image description here

How can I set the region (=set of java Elements) parameter? When I have code A that has SubClass B, and SuperClass C. How can I set the region?


Solution

  • This code that I got hint from this site works fine.

    IRegion region = JavaCore.newRegion();
    for (IJavaElement i : javaProject.getPackageFragmentRoots())
    {
        String elementName = i.getElementName();
        if (!elementName.endsWith("jar") && !elementName.endsWith("zip"))
            region.add(i);
        }
    
        NullProgressMonitor progressMonitor = new  NullProgressMonitor();
    
        // for getting a class hierarchy for type
        ITypeHierarchy typeHierarchy= type.newTypeHierarchy(progressMonitor);
        // for getting all the class hierarchies of the region in the project
        ITypeHierarchy typeHierarchy= javaProject.newTypeHierarchy(region, progressMonitor);
    }
    

    Related - Why I got no super classes with getAllSuperclasses() in JDT API?