On Oct 26, 3:33 am, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.net> wrote:
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/>
OK, let me tell you about my idea.
I basically want to create an annotation system for threading. For
example, you have a method that you know it creates a thread, so you
annotate it with @ThreadStarter. That thread will call another class's
method. You have to make sure that everything the method does is
thread safe in that other class. So eventually you know that method is
thread safe. Now you annotate that method as @ThreadSafe. What I want
basically to do is create a system that would lookup all the
@ThreadStarter methods and look inside those methods what other
methods they call. If a method they call isn't annotated as
@ThreadSafe, then the system will generate an error/warning etc.
I know that Reflection will help me in some way. Annotation will too.
I also found out about apt (Annotation Processing Tool). But I can't
find a way to find out what other methods a method calls. I also can't
find a desent tutorial/documentation/help/examples about the apt.
Eclipse has a wonderful plugin for adding your own apt jar and it
works just like a jvm! It throws warnings/errors/etc. while writing
code. It's pretty incredible and really want to find out how to do
this.
I also heard about a JSR exactly for this reason. JSR-305 (http://
groups.google.com/group/jsr-305). One of the creators is Brian Goetz
(developer of FindBugs and an incredible "researcher" of concurrency).
So, any help? :S
Thanks again.
thread safety annotations in that book.
<http://virtualinfinity.net/wordpress/technical-book-recommendations/java-concurrency-in-practice/>
programatic manor. It is easier to prove that something is *not* thread
safe, but you'll get a lot of false positives.