views:

222

answers:

3

I'm developing an eclipse plugin and need to list of IMethods that belong to an IResource.

I see IType has a getMethods function but not sure how to go about converting an IResource to an IType

Help appreciated

Nicky

A: 

I don't have a full solution, but some ideas:

  • globally an IResource cannot be converted/cast to IType (AFAIK)
  • as IType is specific to the JDT, I suggest opening a Java resource file, converting it to ICompilationUnit, that can be traversed to get the IType

For the basic idea I suggest looking at the tutorial page of Lars Vogel, more specifically Section 4, where it creates a menu item to the Project Navigator, that converts a Java file to HTML.

Zoltán Ujhelyi
+1  A: 

First step, get the ICompilationUnit from the IResource:

 ICompilationUnit icu = (ICompilationUnit) JavaCore.create(resource);

Next, use either getTypes() or getType(String) to get your IType.

zvikico
Works a treat thanks!
Weatherman
A: 

IResource represents a file (or folder, or project) in the workspace. They can be C++, javascript or even image files. As the other repliers said, the IResource itself isn't the Java file; you need the ICompilationUnit.

dplass