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使用JDT获取类型层次结构的示例代码。
如何设置区域(= java元素集)参数? 当我有代码A有SubClass B和SuperClass C.如何设置区域?
答案 0 :(得分:1)
在阅读IRegion Javadocs和Using Eclipse's JDT, how does one get an IType from a class name?后,我得到的印象是您应该可以创建这样的区域:
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);
答案 1 :(得分:0)
我从this site提示的这段代码很好用。
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);
}
相关 - Why I got no super classes with getAllSuperclasses() in JDT API?