Javassist doesn't allow you to achieve your requirements out of the box. But you can easily extend the behaviour of ExprEditor to achieve it.
The first step is to create an ExprEditor subclass,let's call it ExprEditorMethodCallAware. The only thing you need to know is that ExprEditor's entry point is called doit as you can easily see in the code.
public class ExprEditorMethodCallAware extends ExprEditor {
private boolean processedMethodCalls;
public void setProcessedMethodCalls(boolean processedMethodCalls) {
this.processedMethodCalls = processedMethodCalls;
}
public boolean isProcessedMethodCalls() {
return this.processedMethodCalls;
}
@Override
public boolean doit(CtClass arg0, MethodInfo arg1)
throws CannotCompileException {
processedMethodCalls = false;
boolean doit = super.doit(arg0, arg1);
return doit;
}
}
Now with this small nifty trick you rewrite your code as the following:
/// ... your existing code
// we create an instance using our base class instead of ExprEditor
ExprEditorMethodCallAware exprEditor = new ExprEditorMethodCallAware() {
public void edit(MethodCall m)
throws CannotCompileException
{
// notice the set
setProcessedMethodCalls(true);
System.out.println(m.getClassName() + "." + m.getMethodName() + " " + m.getSignature());
}
};
// we now instrument the code as you were already doing it
method.instrument(exprEditor);
// And now you check if there were or not methodCalls processed
if(!exprEditor.isProcessedMethodCalls()) {
System.out.println("No methodCalls found in " + method.getMethodName());
}