Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Using Method Invocation Visitor(Java AST visitor pattern)
Using Method Invocation Visitor [message #554922] Tue, 24 August 2010 18:15 Go to next message
Niranjani S is currently offline Niranjani SFriend
Messages: 3
Registered: August 2010
Junior Member
Hi all,
I wrote this code to trace all the methods called by a member method in a class using the MethodInvocation visitor pattern. When I call resolvebinding, I'm able to differentiate overloaded methods by checking the parameter type and/or number of parameters. But I'm not able to trace overridden methods.

Say for example, there are two classes A and B where A is the superclass and B is the subclass. Then, I have:
A a;
A a=new B();
Suppose there is a method, say, setVal in A which is overridden in B.

Then the call a.setVal() will call B's setVal() but the Method Invocation Visitor pattern resolves it to A's setVal(). Can this be sorted out by some other way?? Or since java uses late binding this resloving can be done at run-time only???

Thanks in advance,

Niranjani S



Re: Using Method Invocation Visitor [message #554987 is a reply to message #554922] Wed, 25 August 2010 06:07 Go to previous messageGo to next message
Satyam Kandula is currently offline Satyam KandulaFriend
Messages: 444
Registered: July 2009
Senior Member
Yes, it will not be possible to figure out the exact binding at compile time. However, you can find out the possible bindings by getting the subtypes of A and then checking if the methods are overriden in the subtype.
BTW, try to use - SearchEngine.searchDeclarationsOfSentMessages(). This is probably what you are writing.
Re: Using Method Invocation Visitor [message #846919 is a reply to message #554987] Mon, 16 April 2012 21:50 Go to previous message
Niranjani S is currently offline Niranjani SFriend
Messages: 3
Registered: August 2010
Junior Member
Method overriding can be detected using IMethodBinding.overrides(IMethodBinding)

Thanks a lot,
Niranjani S
Previous Topic:Create a new xml file from java code
Next Topic:ECLIPSE doesn't start UBUNTU 11.10
Goto Forum:
  


Current Time: Sat Dec 20 08:47:23 GMT 2014

Powered by FUDForum. Page generated in 0.01794 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software