Reputation: 6087
I am trying to determine the MethodGen of the callee for a given InvokeInstruction in the BCEL library. The problem is that I don't know how to use the InvokeInstruction to get to the MethodGen that it is trying to invoke.
If I have a BCEL MethodGen object for the main method of a program, I can go through the list of instructions and find the ones that are InvokeInstructions:
// Assume MethodGen mainMG is given to us
Instruction[] insns = mainMG.getInstructionList().getInstructions();
for(Instruction insn : insns) {
if(insn instanceof InvokeInstruction) {
// great, found an invoke instruction
InvokeInstruction invoke = (InvokeInstruction)insn;
// what do I do with it now?
}
}
Some of BCEL's documentation is great and other parts are kind of lacking. Any suggestions for how to link an InvokeInstruction to the MethodGen of the method being invoked?
If it simplifies things, I can assume for now that the program doesn't have any polymorphism. Though at some point I will have to deal with it (conservatively).
invoke.getCalledMethodGen()
), but I am wondering if there is some way that I can get enough distinct information from the invoke instruction (e.g. method's FQN or equiv.) that I can link it back to the method being called.
Upvotes: 1
Views: 1389
Reputation: 31795
Generally you can't. BCEL and most of other frameworks for working with bytecode operating on a single class. So, you will have read all available classes (could do that lazily) and build your own repository of MethodGens (e.g. map of FQN method name to MethodGen instances).
Upvotes: 0