Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » scanning method bodys for method invocations
icon9.gif  scanning method bodys for method invocations [message #653076] Tue, 08 February 2011 11:27 Go to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 16
Registered: March 2010
Junior Member
Hi guys,

In my Eclipse plug-in, I am doing some static code analysis using the JDT.
I want to have all methods that are invoked by another method, so I started analysing the body of a MethodDeclaration. My first fault was to scan all statements for being a MethodInvocation. That did not work because of nested Blocks of while loops and so on.
So I started writing a recursive method that goes into that bodys and reinvokes the method that scans for MethodInvocations.
But it's very annoying, that those classes with bodys have no common interface for the method getBody().
Do I really have to do something like that?:
if (node instanceof MethodDeclaration)
{
((MethodDeclaration) node).getBody();
}
else if (node instanceof WhileStatement)
{
((WhileStatement) node).getBody();
}
else if (node instanceof ForStatement)
{
((ForStatement) node).getBody();
}
I does not feel good...
Re: scanning method bodys for method invocations [message #653086 is a reply to message #653076] Tue, 08 February 2011 12:25 Go to previous messageGo to next message
Deepak Azad is currently offline Deepak AzadFriend
Messages: 543
Registered: July 2009
Senior Member
On 2/8/2011 4:57 PM, mc.platenius@gmail.com wrote:
> Hi guys,
> In my Eclipse plug-in, I am doing some static code analysis using the JDT.
> I want to have all methods that are invoked by another method, so I
> started analysing the body of a MethodDeclaration. My first fault was to
> scan all statements for being a MethodInvocation. That did not work
> because of nested Blocks of while loops and so on.
> So I started writing a recursive method that goes into that bodys and
> reinvokes the method that scans for MethodInvocations.
> But it's very annoying, that those classes with bodys have no common
> interface for the method getBody().
> Do I really have to do something like that?:
> if (node instanceof MethodDeclaration)
> {
> ((MethodDeclaration) node).getBody();
> }
> else if (node instanceof WhileStatement)
> {
> ((WhileStatement) node).getBody();
> }
> else if (node instanceof ForStatement)
> {
> ((ForStatement) node).getBody();
> }
> I does not feel good...
Have you tried to use
org.eclipse.jdt.core.search.SearchEngine.searchDeclarationsO fSentMessages(IJavaElement,
SearchRequestor, IProgressMonitor) to achieve the same ?
Re: scanning method bodys for method invocations [message #653088 is a reply to message #653086] Tue, 08 February 2011 12:56 Go to previous messageGo to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 16
Registered: March 2010
Junior Member
woah!
That's exactly what I needed! Smile
Thank you very very much!!
Re: scanning method bodys for method invocations [message #653109 is a reply to message #653076] Tue, 08 February 2011 14:39 Go to previous messageGo to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 16
Registered: March 2010
Junior Member
One further question:

SearchEngine.searchDeclarationsOfSentMessages does not find constructor calls.
How can I define a search for constructor calls?
Re: scanning method bodys for method invocations [message #653120 is a reply to message #653109] Tue, 08 February 2011 15:03 Go to previous message
Deepak Azad is currently offline Deepak AzadFriend
Messages: 543
Registered: July 2009
Senior Member
On 2/8/2011 8:09 PM, mc.platenius@gmail.com wrote:
> One further question:
>
> SearchEngine.searchDeclarationsOfSentMessages does not find constructor
> calls.
> How can I define a search for constructor calls?
Well.. the JDT/Core search API treats constructors as different from
methods. See type hierarchy of
org.eclipse.jdt.internal.core.search.matching.JavaSearchPatt ern.

Don't think there is an API for constructor calls. You are on your own
for that :) (Though you can probably write some code on the lines of
SearchEngine.searchDeclarationsOfSentMessages to search for constructors.)
Previous Topic:Debug panel call stack problem
Next Topic:CVS local revision
Goto Forum:
  


Current Time: Sat Apr 27 02:31:08 GMT 2024

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

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

Back to the top