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";

  1. Oneiros on 2013-5-26

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

  2. Réda on 2014-12-11

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

  3. bniyaseen on 2015-2-28

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

Leave a comment