Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Method trace

 
Kalai Selvan
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Get a stack trace from Thread.getStackTrace(). Examine the StackTraceElement objects, to see how you got to where you are.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 133
Chrome Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic