Using Eclipse's JDT, how does one get an IType from a class name?

◇◆丶佛笑我妖孽 提交于 2019-12-08 19:26:36

问题


Is there a simple, straightforward way to get an IType from a class name? I think there must be some static method somewhere. Basically, I'd like to do something like:

IType objectType = Somewhere.getType("java.lang.Object")

Does anybody know of something like this? I have been searching in vain.


回答1:


Given an IProject, one can use the IJavaProject#findType methods, e.g.

IType objectType = project.findType("java.lang.Object");



回答2:


Look at org.eclipse.jdt.core.search.SearchEngine. I haven't tried it myself, I'm usually using the ASTParser with the Resolve option on (that's when you parse a source), but it should do the trick.



来源:https://stackoverflow.com/questions/3465365/using-eclipses-jdt-how-does-one-get-an-itype-from-a-class-name

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