Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 831
kc2001 Avatar asked Aug 12 '10 06:08

kc2001


2 Answers

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

IType objectType = project.findType("java.lang.Object");
like image 120
kc2001 Avatar answered Nov 02 '22 04:11

kc2001


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.

like image 35
zvikico Avatar answered Nov 02 '22 04:11

zvikico