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:
<pre><code> 
String foo = "bar";
</code></pre>
  • 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.