Re: About Reflection (or not)
Daniel Pitts wrote:
pek wrote:
Hello everyone..
Here I am again for another question.. :P
Suppose we have the following class
public class Test {
private Test2 test2 = new Test2();
public void testMethod() {
test2.test2Method();
}
}
Is there a way, using anything (probably reflection) to know that the
method testMethod of this class calls test2Method() method of Test2
class..? Or the other way around.. Is there a way to know what classes
call Test2's method test2Method()..?
Any help/reference/book etc. is appreciated.
Thank you very much.
Reflection wouldn't work. In general, the only way to find this out is
to build an index of the calls to test2Method. This index cannot ever
be complete because a new class that hasn't yet been created could
eventually call that method.
If you want to see references within one codebase, there are tools to do
that with static analysis. Personally, I use IntellI IDEA, and it has a
"find references" tool. There may be ones that don't come with a
commercial IDE.
Another tool that may help is opengrok. opengrok will build a search
index based on your codebase. Its quite useful in my opinion.
HTH,
Daniel.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>