1

I need to analyze the call hierarchy of methods in a Java Spring Boot application.

IntelliJ IDEA gets confused when I have:

  • a interface I declaring I.foo()
  • an abstract class A with implementation of I.foo()
  • several concrete classes B, C etc extending A and B overrides A.foo()

I'd like to get the call hierarchy of B.foo() however I get also all callers of C.foo().

If that matters, the classes are autowired similar to the following:

@Component
public class Caller1 {
   @Autowired B b;

   public void bar(){ b.foo()} 
}

@Component
public class Caller2 {
   @Autowired C c;

   public void bar(){ c.foo()} 
}

public interface I {
   void foo();
}

public abstract class A implements I {
   void foo(){..}
}

@Component
public B extends A {
   @Override
   void foo() {..}
}

@Component
public C extends A {
   ..
}

In IntelliJ IDEA, the call hierarchy of B.foo() includes both Caller1.bar() and Caller2.bar(). But I only want callers of B.foo() such as Caller1.bar().

Niccolò
  • 2,854
  • 4
  • 24
  • 38
  • You might be able to get away with temporarily removing `extends A` just for the purpose of the search. It might give you some compiler errors (certainly will if you don't remove @Override too), but it should be enough to make IntelliJ only consider the direct callers of `B::foo` – Michael Mar 10 '21 at 10:24
  • That might work in some cases, however these methods are often in the middle of longer call hierarchy trees. It is time consuming and error prone to find and remove them in the final analysis. But thx for the tip! – Niccolò Mar 10 '21 at 12:52

0 Answers0