If you want to copy a whole method body, you can simply add
a CtMethod from class A to class B.
If you want to insert only part of a method body, you must use
CodeIterator. For example,
CtClass b = ... ;
CtMethod m = b.getMethod(...);
MethodInfo minfo = m.getMethodInfo();
CodeAttribute ca = minfo.getCodeAttribute();
CodeIterator it = ca.iterator();
code specifies a byte array containing the bytecode that you want
to inject. For details, please look at the last section of the tutorial
of version 3.
Is this what you need?
Thank you Shiba,
I think I should be fine with your explanations.