Eclipse JDT Tutorial: Find All References of a Method

When using JDT, you may want to find all references of a given method and then do something with the references. This can be done by using method JDTSearchProvider.searchMethodReference().

The following is sample code:

// First of all, get all the type declaration of the class.
IType [] typeDeclarationList = unit.getTypes();
for (IType typeDeclaration : typeDeclarationList) {
     // get methods list
     IMethod [] methodList = typeDeclaration.getMethods();
     for (IMethod method : methodList) {
          final List<String> referenceList = new ArrayList<String>();
          // check each method.
          String methodName = method.getElementName();
          if (!method.isConstructor()) {
              // Finds the references of the method and record references of the method to referenceList parameter.
              JDTSearchProvider.searchMethodReference(referenceList, method, scope, iJavaProject);
Category >> Java Development Tools (JDT)  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
String foo = "bar";
  • zhe chen

    U can use new JDT core and JDT ui to do this.

  • zhe chen

    U can use your own implementation to replace some original dependences . U can use java model in this way.

  • parthasarathi

    yes where we can find it ? After three years you figured it out ?
    I didn’t find it…

  • Anirban Chatterje
  • Anirban Chatterje

    All the jar can be found in MavenRepository, but problem is after doing all one will get error like –
    Exception in thread “main” java.lang.IllegalStateException: Workspace is closed.
    So one needs to load Eclipse workspace first, which I found need lot of effort.

  • bniyaseen

    how i can get library for : JDTSearchProvider.searchMethodReference(referenceList, method, scope, iJavaProject)

  • Réda

    yes where we can find it ? After two years you figured it out ?
    I didn’t find it…

  • Hello
    Where should i find the class JDTSearchProvider? It isn’t included in the JDT.