1

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?

prosseek
  • 182,215
  • 215
  • 566
  • 871

2 Answers2

1

After reading the IRegion Javadocs and Using Eclipse's JDT, how does one get an IType from a class name?, I get the impression you should be able to create a region like this:

final IJavaProject project = ...;
final IProgressMonitor monitor = ...;
final IRegion region = JavaCore.newRegion();
region.add(project.findType("some.packagename.B"));
final ITypeHierarchy typeHierarchy = project.newTypeHierarchy(region, monitor);
Community
  • 1
  • 1
Freek de Bruijn
  • 3,552
  • 2
  • 22
  • 28
0

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?

Community
  • 1
  • 1
prosseek
  • 182,215
  • 215
  • 566
  • 871