November 20, 2008, 03:01:12 pm *
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: calls method's tree  (Read 962 times)
tployaert
Newbie
*
Posts: 1


« on: October 04, 2007, 02:53:03 pm »

Hello,

I would like to build a query to get the complete calls method's tree of an application :

the root will be the package arbo.root and the branches and leaves will be all the packages beginning with arbo ... It has to be recursive, not only the first level of calls.
Any idea ?

This one gives me only first level calls :

from Method caller, Method callee
where caller.calls(callee)
and caller. fromSource()
and callee.fromSource()
and caller != callee
and caller.getDeclaringType().getPackage().getName().matches("com.xxx.yyy.batch%")
and callee.getDeclaringType().getPackage().getName().matches("com.xxx.yyy%")
select caller.getDeclaringType(),callee.getDeclaringType().getPackage()

If I try to add a second level calls the executing query never ends ...

Thanks in advance
Thierry
Logged
Mathieu Verbaere
Administrator
Newbie
*****
Posts: 26


« Reply #1 on: October 08, 2007, 09:44:09 am »

Hi,

If I understand correctly, you are trying to visualise a graph as a tree where you can expand each node like Eclipse allows it in its call graph viewer. We do not provide such feature yet, but you can write a query to visualise as a graph the calls between the packages you are interested in. Here is how I would do it:

Code:
class ArboSourcePackage extends Package {
  ArboSourcePackage() {
    this.fromSource() and
    this.getName().matches("arbo%")
  }
  ArboSourcePackage getACallee() {
    exists(Call c |
      c.getCaller().getDeclaringType().getPackage() = this and
      c.getCallee().getDeclaringType().getPackage() = result)             
  }
}

from ArboSourcePackage root, ArboSourcePackage p
where root.getName().matches("arbo.root")
  and root.getACallee*() = p
select p, p.getACallee()

I first define a new class for any source package whose name starts with "arbo". I also define there a method that yields any other "arbo" source package that is called from this package.   

Then I write a query that finds the "arbo.root" package, and any
"arbo" source package p that is transitively called from the root. I select each p
with its direct callees to obtain a binary relation that can be depicted as a graph.

Hope it helps,

mathieu
Logged
Pages: [1]
  Print  
 
Jump to: