9

With Eclipse, given the following classes:

class Dao {
    public void one() {}
    public void two() {}
    public void three() {}
}

class ServiceA {
    Dao dao;
    public void a() {
        dao.one();
        dao.two();
    }
    public void b() {
        dao.one();
    }
}

class ServiceB {
    Dao dao;
    public void z() {
        dao.two();
        dao.three();
    }
}

... is it possible to see a list of all Dao methods referenced from ServiceA? I'm looking for one view that will show that ServiceA uses one() and two() (don't mind it if one() is listed twice).

I know how to see callers of one specific method. I really need a list of all methods referenced within a class. Think of legacy code orders of magnitude larger: dao and services that have tens (hundreds?) of methods. I don't feel like going through call hierarchy method by method.

Konrad Garus
  • 53,145
  • 43
  • 157
  • 230

5 Answers5

7

Actually you can click by right mouse button at Dao method and then click at 'Open Call Hierarchy Ctrl+Alt+H' and Eclipse will find for you all Dao method calls.

Vagif
  • 354
  • 3
  • 7
  • Thank you, but I really need a list. I don't feel like going through all methods one by one in legacy monster classes. – Konrad Garus Jun 30 '11 at 06:30
  • Yes, except for that I need it from the opposite side. See all methods called from Service, not all calls of Dao.conreteMethod(). – Konrad Garus Jun 30 '11 at 07:37
5

Konrad Garus Jun 30 '11 at 7:37 said in a comment:

Yes, except for that I need it from the opposite side. See all methods called from Service, not all calls of Dao.conreteMethod().

– I need to create a new answer because I'll use two pictures to illustrate my point. (Cannot use images in comments)

'Ctrl+Alt+H' brings up call hierarchy, as has been mentioned here by other people.

Then you need to click on these icons, depending on what you need:

Show Callee Hierarchy

And

Show Caller Hierarchy

Edit:

What about VonC's answer here (it's the one with the saw-tooth-rimmed screenshot image inside)?

Here I've used CTRL-H to code-search for calls to Dao.one().

Result: In the search result view, there's another little icon "group by type).

code search result

Community
  • 1
  • 1
knb
  • 9,138
  • 4
  • 58
  • 85
  • Right, but it still acts on method, not class level. What I need is not methods called from my method, by all methods called from my *class*. – Konrad Garus Feb 27 '12 at 11:20
1

Press Ctrl+Shift+G to perform a search which shows all the places where your method or selected class is being used.

Additionally, you can temporarily set all the public methods to private visibility and check the places where errors are popping up.

bhagyas
  • 3,050
  • 1
  • 23
  • 21
1

You can use a Code Coverage plugin/tool for this.

For example:

  • Dependency Analyzer (http://www.dependency-analyzer.org/)
  • Codecover
  • UCDetector
  • FindBugs
  • PMD
  • CodePro Analytics (free from Google)
bhagyas
  • 3,050
  • 1
  • 23
  • 21
0

If you right click on a method and select Open Call Hierarchy you all get the list of all the classes using the particular method.

GuruKulki
  • 25,776
  • 50
  • 140
  • 201