2013-01-19 31 views
1

http://www.google.com/url?sa=t & RCT = j的& Q = jdt_fundamentals &源=幅& CD = 1 & VED = 0CDIQFjAA & URL = HTTP%3A%2F%2Fwww.eclipsecon。有机%2F2008%2Fsub%2Fattachments%2FJDT_fundamentals.ppt“> JDT教程的示例代码来获得使用JDT类型层次结构。如何在JDT TypeHierarchy中设置region(= Java元素集)参数?

enter image description here

如何设置的区域(=设置Java元素的)参数? 当我有代码A有子类B和超类C.如何设置区域?

回答

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?

1

阅读IRegion JavadocsUsing 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);