34

In the "Call Hierarchy" View, it shows all methods calling a selected method. I'd like to be able to filter out everything in src/test/java so I can see what actual code is calling, instead of 100 Unit test methods.

I tried adding a name filter on Test but it didn't seem to work. I think that filters based on method name, and I'm using JUnit 4 so method names don't contian test, just an annotation, though our class names generally end in Test or TestIT. Any other ways to filter based on source folder or Class name?

I'm using Indigo with M2Eclipse to configure standard Java projects.

Thanks,

Mark A. Fitzgerald
  • 1,249
  • 1
  • 9
  • 20
RLZaleski
  • 616
  • 6
  • 17

2 Answers2

51
  1. In the Call Hierarchy view, click the white downwards arrow icon.
  2. Select "Filters...".
  3. Check "Filter Test Code".
  4. Click the refresh button (or press F5).

The test classes and methods should not be visible anymore.

The "Filter Test Code" checkbox was added in Eclipse Photon. In earlier versions, you can select the "Name filter patterns" checkbox and filter tests based on your naming convention (e.g. if the classes end with "Test" then enter *Test).

Toper
  • 114
  • 7
arin
  • 1,774
  • 22
  • 35
  • 2
    Solution by E-Riz works perfectly and is more "safe" - doesn't need naming convention. – Jakub Feb 28 '13 at 09:16
  • 1
    @Jakub But you need to add all dependencies by hand. I ended up using both answers, E-Riz's if I don't need to search in dependencies, too. – jan Apr 24 '14 at 09:08
  • If all end with "Test", you don't need * in the end. – Line May 10 '17 at 13:55
  • In Eclipse Photon, the Filters dialog now includes a "Filter Test Code" option, so no naming conventions or working sets are required. – Toper Oct 10 '18 at 14:40
  • I am no longer using Eclipse. Feel free to edit the answer @Toper with the new steps. – arin Oct 10 '18 at 16:41
14

You can define a Working Set that only includes Java source but excludes your unit tests, then select Search Scope > Working Set... in the Call Hierarchy view menu.

Search the help for more details on Working Sets.

E-Riz
  • 31,431
  • 9
  • 97
  • 134
  • I wish there was a better solution, but this one does seem to work. – RLZaleski Feb 24 '12 at 00:31
  • 2
    This approach is not useful for also searching in dependencies of production code, as they need to be selected all individually, i.e. it is not possible to add only src/main/java. Even if one selects all by hand the working set has to be changed each time dependencies change. – jan Apr 24 '14 at 09:04
  • @jan so it is and it isn't. It isn't because you can't just have a quick click to do it. It is because life finds a way. You can find your working set saved off in `\.metadata\.plugins\org.eclipse.ui.workbench\workingsets.xml` and edit it in a programmatic way and restart your eclipse. I wrote a python script to do it for me. Sure it's not as convenient as a point and click, but you're using eclipse because you're a developer so this shouldn't be too invasive. – searchengine27 Apr 17 '18 at 19:16
  • @searchengine27 So it is and it isn't. I'm a developer, but want to be productive. That's why I won't accept this solution or describe it as not "too invasive". :) – jan Apr 18 '18 at 06:45