Board index » jbuilder » Scanning Source using Jot

Scanning Source using Jot


2004-06-19 02:50:05 AM
jbuilder24
Hello,
I have a scenario where I want to scan the source to see where a particlaur m,ehtod is being used.
I know about the method signature before so I do somethings like the following
if(jm instanceof JotMethodSource)
{
jms = (JotMethodSource) jm;
methodBlock = jms.getCodeBlock();
fooCount +=methodBlock.getMethodCalls("foo").length;
}
However I realized that I need to scan the method and check for all other blocks like IF,For,While,Try, Catch etc.
My question is that, since a lot of these blocks can be nested within each other
if ()
{
for()
{
if ()
{
try{}
catch{}
}
}
}
is there any direct API to get all instances of a particular method being used.
The reason I am asking this is because if I have recursively to go through every code block, and I have a large project, it would take a lot of time to scan every class in the project.
Thanks for help/ pointers
Dutta:)
 
 

Re:Scanning Source using Jot

Unfortunately you have to use recursion - you only get the methods at
the current level through getMethodCalls().
Basically its:
JotClassSource jClass = (JotClassSource)jSource.getClasses()[0];
for (int index = 0; index < jClass.getMethods().length; index++) {
processCode(((JotMethodSource)jClass.getMethods()[index]).getCodeBlock());
}
private void processCode(JotCodeBlock jCode) {
if (jCode == null) {
return;
}
// Deal with this code block
for (int index = 0; index < jCode.getStatements().length; index++) {
// Then its children
process(jCode.getStatements()[index].getCodeBlock());
}
}
But you also need to specifically look for those statements that have
more than one code block, such as JotIf, JotSwitch, and JotTry.
Cheers
Keith