1

I often meet following problem:

I have following code:

void  rootMethod(){
    C c = method1(a,b);
    method2(c);
}

C looks like this:

class C{
   Type1 param1;
   Type2 param2;
}

I want to find all places where inside method2 and all methods are invoked in this method(recursively in deep) uses c.param1 field.

enter image description here

UPDATE

enter image description here enter image description here

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

2 Answers2

3

I can suggest you Ctrl-Alt-H in eclipse. This is the closest option to what you need. Press this shortcut on your field and you will see all call hierarchies that Eclipse can see. Then select the root element in hierarchy, right click and choose "Copy Expanded Hierarchy". Paste this into text editor. Now search for method2.

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • I know this feature. but problem that target method can invokes in deep.... I try to draw. Please read update. – gstackoverflow Aug 05 '14 at 09:01
  • Often method2 has a lot of messed invokation – gstackoverflow Aug 05 '14 at 09:02
  • Copy Expanded Hierarchy - I should expand it on its own – gstackoverflow Aug 05 '14 at 09:25
  • There are 2 buttons in that view: "show caller hierarchy" and "show callee hierarchy". Play with them. As far as I see they can expand the tree automatically, so you will see the `method2` even if it is indirect caller. – AlexR Aug 05 '14 at 10:08
  • I mean: press `Ctrl-alt-h`, the "Call Hierarchy" view will be opened. Take a look on the right-upper corner of this view. The view's toolbar should contain several buttons including those that I have mentioned. – AlexR Aug 05 '14 at 13:17
  • http://cdn.joxi.ru/uploads/prod/2014/08/05/57b/961/06d528969f618676d35f4e3b1da403c301684f3e.jpg – gstackoverflow Aug 05 '14 at 13:31
  • I tryed to play with all these buttons - all don't expand – gstackoverflow Aug 05 '14 at 13:32
  • Oh, my bad. This indeed expands one level only. BTW could you explain why do you need this? Probably other solution exists. – AlexR Aug 05 '14 at 13:59
  • I have very messed business logic. I novice at this code. But I should to understand affection one parameter in request on another code – gstackoverflow Aug 05 '14 at 14:01
0

The following is possible (only) in the just released IntelliJ IDEA 16 EAP:

  • Invoke Call Hierarchy on method2
  • Browse the hierarchy tree to show all methods you are interested in
  • Invoke Find Usages on the C.param1 field
  • Edit the Find Usages Settings to Include overloaded methods and search in the Scope Hierarchy 'Callees of method2'

This will show everywhere in the hierarchy the C.param1 field is used.

Bas Leijdekkers
  • 23,709
  • 4
  • 70
  • 68