I'm trying to implement a transformation in ASM that requires two passes over each method. The first to collect information about where instrumentation is needed (has to do with jump target, which is why I need two passes), and the second completes the collected information and adds the instrumentation. This also means that I have to complete the first pass (i.e. process all instructions) before I start the second pass. That's why the normal chaining pattern that's discussed in the manual does not work.
My question is: Is there an elegant and convenient way to do it?
The only solution I could come up with so far is to call the second visitor from visitEnd() in the first visitor. The outline looks like this
public class Pass1Visitor extends MethodVisitor {
...
public void visitEnd() {
//do stuff the call the second visitor
thisMethodNode.accept( new Pass2Visitor() );
}
}
I don't like this solution too much, because I suspect that in future I will have to chain more visitors and I might want to be able to pick and chose. Which with this is really not possible.