public void pushOntoStack()

in bytekit-core/src/main/java/com/alibaba/bytekit/asm/binding/MethodBinding.java [18:52]


    public void pushOntoStack(InsnList instructions, BindingContext bindingContext) {
        // 先获取类本身的 class ,再调用 getDeclaredMethod ,它需要一个变长参数,实际上要传一个数组
        /**
         * @see java.lang.Class.getDeclaredMethod(String, Class<?>...)
         */
        MethodProcessor methodProcessor = bindingContext.getMethodProcessor();
        AsmOpUtils.ldc(instructions, Type.getObjectType(methodProcessor.getOwner()));
        
        AsmOpUtils.push(instructions, methodProcessor.getMethodNode().name);
        
        Type[] argumentTypes = Type.getMethodType(methodProcessor.getMethodNode().desc).getArgumentTypes();
        
        AsmOpUtils.push(instructions, argumentTypes.length);
        AsmOpUtils.newArray(instructions, AsmOpUtils.CLASS_TYPE);

        for(int i = 0; i < argumentTypes.length; ++i) {
            AsmOpUtils.dup(instructions);

            AsmOpUtils.push(instructions, i);

            if (AsmOpUtils.needBox(argumentTypes[i])) {
                // 相当于 Boolean.TYPE;
                AsmOpUtils.getStatic(instructions, AsmOpUtils.getBoxedType(argumentTypes[i]), "TYPE",
                        AsmOpUtils.CLASS_TYPE);
            } else {
                AsmOpUtils.ldc(instructions, argumentTypes[i]);
            }

            AsmOpUtils.arrayStore(instructions, AsmOpUtils.CLASS_TYPE);
        }
        
        MethodInsnNode declaredMethodInsnNode = new MethodInsnNode(Opcodes.INVOKEVIRTUAL, AsmOpUtils.CLASS_TYPE.getInternalName(),
                "getDeclaredMethod", "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;", false);
        instructions.add(declaredMethodInsnNode);
    }