1

Possible Duplicate:
Eclipse find references for method

How to search for the classes (own package+other packages) which use a particular method in Eclipse (java)?

Community
  • 1
  • 1
Swetha P
  • 67
  • 1
  • 2
  • 6

2 Answers2

4

I believe you want "Find references in workspace". This is normally bound to CtrlShiftG

Devon_C_Miller
  • 16,248
  • 3
  • 45
  • 71
  • Is Ctrl+Shift+G similar to the search option given in the menu toolbar? I tried and no luck :( I am not sure if this is a sign that my eclipse is broken but I somehow do not see anything down in the search window – Swetha P Jul 26 '12 at 19:42
1

Right click on the method's name in the code and choose "Open Call Hierarchy" or use the key combination Ctrl+Alt+H after having clicked on the method's name. A panel called Call Hierarchy will open which contains a list of all the locations in the project that the method is called.

You can also search the entire workspace for text strings using File Search. This can be arrived at either through the "Search" menu (click "File..."). Or use Ctrl+H and click the "File Search" tab. Type the string you are looking for into the "Containing text" field. If you want you can also add *.java to the "File name patterns" field in order to just search Java source. Otherwise put * in the file name field in order to search the contents of all files in the workspace.

radicaledward101
  • 555
  • 6
  • 15
  • I tried this but no luck..the call hierarchy is being displayed at the bottom but does not show any classes that contain that method...it just stays blank... – Swetha P Jul 26 '12 at 19:37
  • 1
    If the call hierarchy is blank there are two possibilities. First the method isn't being used anywhere else. Have you tried the same approach on a different method that you know is used in multiple locations? The second possibility is that the source for jars where the method is being used is not attached. If the source is not attached it can not be searched. – radicaledward101 Jul 26 '12 at 19:46
  • There is also the option of searching your entire workspace via text. This will not be quite as useful but may give you better results. Use Ctrl+H and choose the File Search tab. Type the name of your method into the "containing text" field and *.java into the "file name patterns" field. I'll add something about this to my answer. – radicaledward101 Jul 26 '12 at 19:49
  • I did the file search too and still it doesn't work...do you think there is something wrong with eclipse? – Swetha P Jul 26 '12 at 20:12
  • What exactly are you searching for? I might be able to get a better idea of what the problem is with a more specific situation stated. Generally eclipse installations do not fail in this way. – radicaledward101 Jul 26 '12 at 20:14
  • Okay before I get into the details, I would like to know if eclipse displays the class names/project/package of the method being searched for? – Swetha P Jul 26 '12 at 20:16
  • It does highlight the places in the code where the word (method name) is being searched for. But I want to see what all classes are using a specific method be it in its current package or another package. – Swetha P Jul 26 '12 at 20:18
  • I'm a little confused. So the search panel shows the locations in code where the string appears? That's about all either of these techniques can give you. @Devon_C_Miller 's recommendation of Ctrl+Shift+G will give you a list of packages in the search panel which can be expanded to show the classes in those packages which use the method. If neither of these techniques work, I'm not sure if I can be of further assistance. Please add details if you think it might help. – radicaledward101 Jul 26 '12 at 20:28
  • Okay. I actually figured it out. Nothing is displayed in the search window. Eclipse shows the first class file where the search has been found according to the arrangement of packages in the package explorer. There are little icons to the right of that Search window at the bottom which say "Show next match" and "Show previous match" which show the next matches in the present file open and also goes on to other files which use that variable/method until all the packages are explored in the package explorer. – Swetha P Jul 26 '12 at 20:32
  • You are welcome! Also, you should be able to turn the search window into a list. There is a small triangle in the upper right hand corner of the panel. Click on it and select "Show as List." Although, if your interface is identical to mine, you should have already been able to click on the items in the panel to expand them and see the results. Finally, if an answer has helped you please select it as your chosen answer! Thanks! – radicaledward101 Jul 26 '12 at 20:42