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

筅森魡賤 提交于 2019-12-04 09:01:39
prosseek

This may be a temporary solution, but it worked for me.

Short Answer

Make a lib directory, and copy this rtstubs.jar into the directory. You may need to refresh(F5) the eclipse IDE to see the jar file is included in the project.

Then, in "Java Build Path", you need to add this jar file.

After the inclusion of the jar file in package fragment, you'll get the class hierarchy.

Long Answer (why does this solve the issue)

CompilationUnitDeclaration (org.eclipse.jdt.internal.compiler.ast) and Hierarchy Resolver (org.eclipse.jdt.internal.core.hierarchy)

It has a field ignoreFurtherInvestigation, and a method hasErrors() returns this field.

org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver#resolve() method invokes hasError() to add type information to cache. However, without the inclusion of the jar file, the hasError() method always returns false to prevent any class hierarchical information is stored.

org.eclipse.jdt.internal.core.JavaProjectElementInfo

This class has cache initialization methods such as initializePackageNames and getProjectCache. In getProjectCache() method, package fragment element roots are loaded and added to the cache.

With the rtstubs.jar in the package fragment, the cache now contains all the Java class hierarchy. Without this setup, in the course of cache build up, the ignoreFurtherInvestigation filed is on, and hasError() method returns true not to contain the class hierarchical information to return just nothing.

ADDED

The other solution can be using IRegion.

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

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