@Override
public MethodVisitor visitMethod(int access, String name, String desc,
String signature, String[] exceptions) {
if ((access & Opcodes.ACC_NATIVE) != 0) {
MethodVisitor mv = super.visitMethod(access & ~Opcodes.ACC_NATIVE,
name, desc, signature, exceptions);
if (mv != null) {
mv.visitCode();
String exceptionName = Type.getInternalName(RuntimeException.class);
// <empty>
mv.visitTypeInsn(Opcodes.NEW, exceptionName);
// obj
mv.visitInsn(Opcodes.DUP);
// obj, obj
mv.visitLdcInsn(NATIVE_METHOD_ERROR);
// obj, obj, string
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, exceptionName, "<init>",
"(Ljava/lang/String;)V");
// obj
mv.visitInsn(Opcodes.ATHROW);
// Count argument slots - long and double arguments each take up 2 slots
int numSlots = 0;
for (Type t : Type.getArgumentTypes(desc)) {
numSlots += t.getSize();
}
if ((access & Opcodes.ACC_STATIC) == 0) {
// Add one for 'this' reference
numSlots++;
}
mv.visitMaxs(3, numSlots);
mv.visitEnd();
}
return null;
} else {
return super.visitMethod(access, name, desc, signature, exceptions);
}