0

I'm looking for a way to find the IMethod, given the method name as input for developing my eclipse plugin further.

Couldn't figure out a way to do so.

can someone please direct me in the right path.

greg-449
  • 109,219
  • 232
  • 102
  • 145
ARUNA DEVI
  • 11
  • 3
  • Method name is not unique, methods with same name can exist in the same class (overloading) or other classes. What else do you pass as input to your plug-in? – Unni Kris Feb 28 '17 at 12:56
  • Thanks for the response. I can give the method name along with the parameters to differentiate from other methods – ARUNA DEVI Mar 02 '17 at 06:12

1 Answers1

0

There can be two approaches:

  1. You can use the ASTVisitor pattern to visit the MethodDeclaration nodes, do a check for name and arguments, and get IMethod from them by resolving the binding. Refer the below posts:

  2. Get the ITypes from the compilation unit and loop through the IMethods, do check for name and arguments to find the required one.

    IType [] typeDeclarationList = unit.getTypes();
    for (IType typeDeclaration : typeDeclarationList) {
       // Get methods under each type declaration.
       IMethod [] methodList = typeDeclaration.getMethods();
       for (IMethod method : methodList) {
          // Logic here.
       }
    }
    
Community
  • 1
  • 1
Unni Kris
  • 3,081
  • 4
  • 35
  • 57