おぉっと,InstructionList から Instruction の配列を取って,別の InstructionList に append していったら,if とか,goto の時に ClassGenException が発生する.
解決策.
InstructionList から getInstuctionHandles で InstructionHandle の配列を取得し,元の InstructionList に insert していく.
insert する場所は取得した InstructionHandle で決める.
return の前にそのメソッドが終わったということを表示するには以下のような感じで実装すればよい.
[/src]
String methodName = methodGen.getMethod().getName();
InstructionList list = methodGen.getInstructionList();
InstructionHandle[] handles = list.getInstructionHandles();
for(int i = 0; i < handles.length; i++){
Instruction i = handles[i].getInstruction();
if(i instanceof ReturnInstruction){
list.append(handls[i].getPrev(),
factory.createPrintln("----- end of " + methodName + " ----- "));
}
}
[/src]
handls[i].getPrev() としなければ return の後ろに println 文が append されるのでそうしている.