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

蓝咒 提交于 2019-12-08 06:44:54

问题


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.

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?


回答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);



回答2:


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?



来源:https://stackoverflow.com/questions/14419171/how-can-i-set-the-region-set-of-java-elements-parameter-in-jdt-typehierarchy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!