Early Access Program Features

New Refactorings Around the Call Hierarchy in IntelliJ IDEA 14.1

 

Sometimes it is convenient to work with all methods in a call hierarchy in the same way: add or remove a parameter throughout the entire call hierarchy, make the whole hierarchy static, or delete the whole call hierarchy completely.

IntelliJ IDEA 14.1 makes this process simpler.

class CallHierarchySample {
   private void foo() { bar();}
   private void bar() { baz();}
   private void baz() { }
}
  1. Change Signature

It’s probably not a very well-known feature that it’s possible (since IntelliJ IDEA 4?) to add a parameter or an exception to all methods in the call hierarchy with a single click:

Screen Shot 2015-01-14 at 10.03.26.png

Result is:

class CallHierarchySample {
  private void foo(int i) { bar(i);}
  private void bar(int i) { baz(i);}
  private void baz(int i) { }
}

 

  1. Safe Delete Parameter

If a parameter is only passed through the call hierarchy and has no usages outside of it, Safe Delete will automatically suggest other methods in the hierarchy where the parameter could be deleted.

Screen Shot 2015-01-14 at 09.56.53.png

Selecting all methods would result in:

class CallHierarchySample {
  private void foo() { bar();}
  private void bar() { baz();}
  private void baz() { }
}
  1. Make Method Static

If you make some method static, and some of it’s callers do not contain any other references to instance members, IntelliJ IDEA will suggest these callers to make them also static.

Result:

class CallHierarchySample {
  private static void foo(int i) { bar(i);}
  private static void bar(int i) { baz(i);}
  private static void baz(int i) { }
}

 

  1. Safe Delete of Method Call Hierarchy

Much the same way, if you delete a method, Safe Delete automatically checks if some of the callees inside the methods body are no longer used and will suggest to delete them also – so you don’t need to apply Safe Delete for each method in the call hierarchy manually.

Result:

class CallHierarchySample {}

 

And all this without any additional actions to learn!

image description