How can I get the complete Call Hierarchy of a Java source code?

Viewed 16551

This is a bit tricky to explain. I have a class A:

public class A {
    private Integer a1;
    private Integer a2;
    // getters and setters.
}

There is a static class B that returns my class A:

public static class B {
    public static A getCurrentA() {
        return a;
    }
}

I need to find all usages of class A returned by B. So let's say class C calls c.setA(B.getCurrentA()) and then further along there's a call to c.getA().getA2();, I'd want to find all of these.

In the real scenario, I have 217 different classes that call B.getCurrentA(). I can't manually follow all the calls in Eclipse and find out which methods are getting called.

Eclipse call hierarchy view only shows me all calls to B.getCurrentA().

How can I achieve this?


EDIT

Chris Hayes understood what I want to do. In order to refactor some really bad legacy code without breaking the whole system, I need to first fine-tune some queries using Hibernate's projections (every mapped entity in the system is eagerly loaded, and many entities are related, so some queries take a LONG time fetching everything). But first I need to find which properties are used so that I don't get a NullPointerException somewhere...

Here's an example of what I'd have to do manually:

  1. Use Eclipse's Search to find all calls to B.getCurrentA();
  2. Open the first method found, let's say it's the one below:

    public class CController {
        C c = new C();
        CFacade facade = new CFacade();
        List<C> Cs = new ArrayList<C>();
    
        public void getAllCs() {
            c.setA(B.getCurrentA()); // found it!
            facade.search(c);
        }
    }
    
  3. Open the search method in the CFacade class:

    public class CFacade {
        CBusinessObject cBo = new CBusinessObject();
    
        public List<C> search(C c) {
            // doing stuff...
            cBo.verifyA(c);
            cBo.search(c); // yes, the system is that complicated
        }
    }
    
  4. Open the verifyA method in the CBusinessObject class and identify that field a2 is used:

    public class CBusinessObject {
        public void verifyA(c) {
            if (Integer.valueOf(1).equals(c.getA().getA2())) {
                // do stuff
            else {
                // something else
            }
        }
    }
    
  5. Repeat steps 2-4 for the next 216 matches... Yay.

Please help.

7 Answers
Related