Example usage for org.objectweb.asm.tree MethodNode visitIntInsn

List of usage examples for org.objectweb.asm.tree MethodNode visitIntInsn

Introduction

In this page you can find the example usage for org.objectweb.asm.tree MethodNode visitIntInsn.

Prototype

@Override
    public void visitIntInsn(final int opcode, final int operand) 

Source Link

Usage

From source file:com.seovic.pof.PortableTypeGenerator.java

License:Apache License

private void implementReadExternal() {
    int index = 0;

    MethodNode mn = new MethodNode(ACC_PRIVATE, "readExternal", "(Lcom/tangosol/io/pof/PofReader;)V", null,
            new String[] { "java/io/IOException" });
    mn.visitCode();//from  w w  w.  j av  a2  s  .  c o m

    for (int version : properties.keySet()) {
        mn.visitVarInsn(ALOAD, 1);
        mn.visitMethodInsn(INVOKEINTERFACE, "com/tangosol/io/pof/PofReader", "getVersionId", "()I");
        mn.visitIntInsn(BIPUSH, version);
        Label l = new Label();
        mn.visitJumpInsn(IF_ICMPLT, l);

        SortedSet<FieldNode> fields = properties.get(version);
        for (FieldNode fn : fields) {
            Type type = Type.getType(fn.desc);

            if (isDebugEnabled()) {
                mn.visitLdcInsn("reading attribute " + index + " (" + fn.name + ") from POF stream");
                mn.visitIntInsn(BIPUSH, 7);
                mn.visitMethodInsn(INVOKESTATIC, "com/tangosol/net/CacheFactory", "log",
                        "(Ljava/lang/String;I)V");
            }
            mn.visitVarInsn(ALOAD, 0);
            mn.visitVarInsn(ALOAD, 1);
            mn.visitIntInsn(BIPUSH, index++);

            ReadMethod readMethod = getReadMethod(fn, type);
            readMethod.createTemplate(mn, fn, type);
            mn.visitMethodInsn(INVOKEINTERFACE, "com/tangosol/io/pof/PofReader", readMethod.getName(),
                    readMethod.getDescriptor());
            if (type.getSort() == Type.OBJECT || "readObjectArray".equals(readMethod.getName())) {
                mn.visitTypeInsn(CHECKCAST, type.getInternalName());
            }
            mn.visitFieldInsn(PUTFIELD, cn.name, fn.name, fn.desc);
        }

        mn.visitLabel(l);
        mn.visitFrame(F_SAME, 0, null, 0, null);
    }

    mn.visitInsn(RETURN);
    mn.visitMaxs(0, 0);
    mn.visitEnd();

    if (!hasMethod(mn)) {
        cn.methods.add(mn);
    }
    LOG.debug("Implemented method: " + mn.name);
}

From source file:com.seovic.pof.PortableTypeGenerator.java

License:Apache License

private void implementWriteExternal() {
    int index = 0;

    MethodNode mn = new MethodNode(ACC_PRIVATE, "writeExternal", "(Lcom/tangosol/io/pof/PofWriter;)V", null,
            new String[] { "java/io/IOException" });
    mn.visitCode();//from   w w w  .  j  a va 2  s.  co  m

    for (int version : properties.keySet()) {
        SortedSet<FieldNode> fields = properties.get(version);
        for (FieldNode fn : fields) {
            addPofIndex(fn, index);
            Type type = Type.getType(fn.desc);

            if (isDebugEnabled()) {
                mn.visitLdcInsn("writing attribute " + index + " (" + fn.name + ") to POF stream");
                mn.visitIntInsn(BIPUSH, 7);
                mn.visitMethodInsn(INVOKESTATIC, "com/tangosol/net/CacheFactory", "log",
                        "(Ljava/lang/String;I)V");
            }
            mn.visitVarInsn(ALOAD, 1);
            mn.visitIntInsn(BIPUSH, index++);
            mn.visitVarInsn(ALOAD, 0);
            mn.visitFieldInsn(GETFIELD, cn.name, fn.name, fn.desc);

            WriteMethod writeMethod = getWriteMethod(fn, type);
            writeMethod.pushUniformTypes(mn);
            mn.visitMethodInsn(INVOKEINTERFACE, "com/tangosol/io/pof/PofWriter", writeMethod.getName(),
                    writeMethod.getDescriptor());
        }
    }

    mn.visitInsn(RETURN);
    mn.visitMaxs(0, 0);
    mn.visitEnd();

    if (!hasMethod(mn)) {
        cn.methods.add(mn);
    }
    LOG.debug("Implemented method: " + mn.name);
}

From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java

License:Creative Commons License

private static MethodNode injectMethodGetCustomArmorItem() {
    MethodNode method = ASMHelper.getMethodNode(Opcodes.ACC_PRIVATE, ASMNames.MD_SAP_GET_CUSTOM_ARMOR_ITEM);
    method.visitCode();/*from  w w w  .  j  av a  2  s .  com*/
    Label l0 = new Label();
    method.visitLabel(l0);
    method.visitVarInsn(Opcodes.ALOAD, 0);
    ASMHelper.visitFieldInsn(method, Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER);
    method.visitIntInsn(Opcodes.BIPUSH, 23);
    ASMHelper.visitMethodInsn(method, Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_GET_OBJ_STACK, false);
    method.visitInsn(Opcodes.ARETURN);
    Label l1 = new Label();
    method.visitLabel(l1);
    method.visitLocalVariable("this", ASMNames.CL_T_ENTITY_HORSE, null, l0, l1, 0);
    method.visitMaxs(2, 1);
    method.visitEnd();

    return method;
}

From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java

License:Creative Commons License

private static MethodNode injectMethodSetCustomArmorItem() {
    MethodNode method = ASMHelper.getMethodNode(Opcodes.ACC_PRIVATE, ASMNames.MD_SAP_SET_CUSTOM_ARMOR_ITEM);
    method.visitCode();/*www.j ava  2s  .co  m*/
    Label l0 = new Label();
    method.visitLabel(l0);
    method.visitVarInsn(Opcodes.ALOAD, 1);
    Label l1 = new Label();
    method.visitJumpInsn(Opcodes.IFNONNULL, l1);
    method.visitTypeInsn(Opcodes.NEW, ASMNames.CL_ITEM_STACK);
    method.visitInsn(Opcodes.DUP);
    ASMHelper.visitFieldInsn(method, Opcodes.GETSTATIC, ASMNames.FD_ITEMS_IRON_SHOVEL);
    method.visitInsn(Opcodes.ICONST_0);
    ASMHelper.visitMethodInsn(method, Opcodes.INVOKESPECIAL, ASMNames.MD_ITEMSTACK_INIT, false);
    method.visitVarInsn(Opcodes.ASTORE, 1);
    method.visitLabel(l1);
    method.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    method.visitVarInsn(Opcodes.ALOAD, 0);
    ASMHelper.visitFieldInsn(method, Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER);
    method.visitIntInsn(Opcodes.BIPUSH, 23);
    method.visitVarInsn(Opcodes.ALOAD, 1);
    ASMHelper.visitMethodInsn(method, Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_UPDATE_OBJ, false);
    Label l3 = new Label();
    method.visitLabel(l3);
    method.visitInsn(Opcodes.RETURN);
    Label l4 = new Label();
    method.visitLabel(l4);
    method.visitLocalVariable("this", ASMNames.CL_T_ENTITY_HORSE, null, l0, l3, 0);
    method.visitLocalVariable("stack", ASMNames.CL_T_ITEM_STACK, null, l0, l3, 1);
    method.visitMaxs(5, 2);
    method.visitEnd();

    return method;
}