简体   繁体   中英

How can I determine if a particular Java method calls another particular Java method several stack levels down?

So let's say that I have method A and I want to know if kicking off method A could possibly result in method D being kicked off. It's obviously easy to determine if A calls D directly, but is there a way to determine if D is called further down the stack (ex: A calls B, B calls C, C calls D)?

Basically I'm looking to do a recursive search of all method calls with in a particular method to find another specific method call. Any help on this would be greatly appreciated.

Regards, Brandon

If you have an IDE (like Eclipse or Netbeans), you could put a breakpoint in method D, and then have a look at the stack at that point in the Debug view.

In Eclipse for example, there will be a panel that looks something like this:

Image from Eclipse Help

You can see in the stack that main() has been called.

In your example it might look something like this:

ClassZ.D() line: P
ClassY.C() line: O
ClassX.B() line: N
ClassW.A() line: M

Found the solution ! Apparently I wasn't the only one that came up with this question, I just didn't word it quite the same. Here's the best solution (and it does use the Call Hierarchy in Eclipse, thanks Raedwald!)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM