> > Or the other way around.. Is there a way to know what classes
>
> > call Test2's method test2Method()..?
>
> Not without static analysis, if you don't want to actually run the
> program and see.
>>> Is there a way, using anything (probably reflection) to know that the
>>> method testMethod of this class calls test2Method() method of Test2
[quoted text clipped - 3 lines]
>
> Hmmm.. I believe that could be pretty hard.. ;)
Parsing bytecode is actually relatively easy. I have source code to
handle most of the bytecode parsing, if you would like me to send you a
modified copy that can come close to doing what you want it to do.
>> > Or the other way around.. Is there a way to know what classes
>>
[quoted text clipped - 7 lines]
> does static analysis. Is it basically a program that uses the
> reflection api? Or is it something more than that?
Reflection doesn't retain enough API: static analysis typically either
uses the bytecode (see above) or the actual source code. The apt tool
might be able to be used as a platform for this, but I do not have
sufficient experience to help you in this regard.
>> Note that these can be at best heuristics, since anything with a
>> Method.invoke() can invalidate number one and the second option has its
>> own problems.
>
> Sorry, but I didn't quite understood that.
Method.invoke() (and maybe the invokedynamic opcode) allows run to
specify a method to be invoked at runtime, possibly without any possible
verification. Therefore, any code which uses Method.invoke() cannot be
fully verified for correctness.
The second method has the problem that it can only check code which you
know to exist: it can guarantee, for example, thread safety from your
code which calls it, but not from anyone else's.
For various reasons, I prefer the first (transformations can also be
applied at source code level here, but I would probably find bytecode
easier to work with).

Signature
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
pek - 30 Oct 2007 12:19 GMT
> >>> Is there a way, using anything (probably reflection) to know that the
> >>> method testMethod of this class calls test2Method() method of Test2
[quoted text clipped - 7 lines]
> handle most of the bytecode parsing, if you would like me to send you a
> modified copy that can come close to doing what you want it to do.
If reading what I want and believing that one way to solve my problem
is using this, then please, do so. And thank you also.
> >> > Or the other way around.. Is there a way to know what classes
>
[quoted text clipped - 12 lines]
> might be able to be used as a platform for this, but I do not have
> sufficient experience to help you in this regard.
Nor do I. Even after spending so much time, I couldn't find any good
documentation.
> >> Note that these can be at best heuristics, since anything with a
> >> Method.invoke() can invalidate number one and the second option has its
[quoted text clipped - 14 lines]
> applied at source code level here, but I would probably find bytecode
> easier to work with).
So, concluding, I should ask you for the code you mentioned earlier.
Correct?
If so, can you please explain to me (or refer a site) about what
should I do (or look for).
> --
> Beware of bugs in the above code; I have only proved it correct, not
> tried it. -- Donald E. Knuth
Thank you very much for your help.
-pek