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.

2
  • 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? Commented Feb 28, 2017 at 12:56
  • Thanks for the response. I can give the method name along with the parameters to differentiate from other methods Commented Mar 2, 2017 at 6:12

1 Answer 1

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. } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.