GeeCON Prague 2014*
The moose likes Java in General and the fly likes Method trace Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Method trace" Watch "Method trace" New topic
Author

Method trace

Kalai Selvan
Ranch Hand

Joined: Jul 07, 2004
Posts: 79
Hi All,

Is there any way by which I can find from which method a particular method has been called.



Thanks in advance.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Get a stack trace from Thread.getStackTrace(). Examine the StackTraceElement objects, to see how you got to where you are.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
You don't say why you want this information. If it's just for tracing, diagnostics or maybe assertion, that's fine. If you're thinking of writing logic that depends on who called the method, think again - that's appalling design.
Arun Kumar
Ranch Hand

Joined: Jan 21, 2005
Posts: 129

If you are using Rad as your IDE it has an option by right clicking on the particular method you can select the option Open Call Hierarchy

I think Latest version of Eclipse also supports this option

Even in older versions you can right click a method and search for references that would display all methods that refers to this particular method
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Arun, those are things you can do while you're writing the program, but the original poster wants a programmatic approach, that can be done during run-time.
 
GeeCON Prague 2014
 
subject: Method trace