Skip to main content



      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 06:27 Go to next message
Eclipse UserFriend
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 07:25 Go to previous messageGo to next message
Eclipse UserFriend
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 07:56 Go to previous messageGo to next message
Eclipse UserFriend
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 09:39 Go to previous messageGo to next message
Eclipse UserFriend
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 10:03 Go to previous message
Eclipse UserFriend
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: Fri Jul 04 15:34:04 EDT 2025

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

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

Back to the top