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:
- Use Eclipse's Search to find all calls to B.getCurrentA();
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); } }
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 } }
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 } } }
Repeat steps 2-4 for the next 216 matches... Yay.
Please help.
B.getCurrentA()
and you have access to the code where it's called, you might be able to print the current stack trace to a log. Or set a breakpoint there and then run the program so that execution stops at the breakpoint.Thread.dumpStack()
to see from where you method was callen