Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse - see which methods of one class are used in another?

Tags:

java

eclipse

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.

like image 505
Konrad Garus Avatar asked Jun 30 '11 06:06

Konrad Garus


2 Answers

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.

like image 59
Vagif Avatar answered Oct 31 '22 08:10

Vagif


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

like image 22
knb Avatar answered Oct 31 '22 08:10

knb