List of usage examples for org.objectweb.asm.tree MethodNode visitFrame
@Override public void visitFrame(final int type, final int numLocal, final Object[] local, final int numStack, final Object[] stack)
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 ww. jav a2s. co 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: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();/*w w w .jav a2 s.com*/ 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; }
From source file:naftoreiclag.dontdigleft.transformer.ResizePlayerBoudingBox.java
License:Open Source License
@Override public byte[] transform(String name, String transformedName, byte[] basicClass) { if (name.equals("net.minecraft.entity.player.EntityPlayer") || name.equals("xl")) { ClassNode classNode = new ClassNode(); ClassReader classReader = new ClassReader(basicClass); classReader.accept(classNode, 0); MethodNode mv = new MethodNode(ASM4, ACC_PROTECTED, "setSize", "(FF)V", null, null); mv.visitCode();//from www . j av a 2 s. c om Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(FLOAD, 1); mv.visitLdcInsn(new Float("0.6")); mv.visitInsn(FCMPL); Label l1 = new Label(); mv.visitJumpInsn(IFNE, l1); mv.visitVarInsn(FLOAD, 2); mv.visitLdcInsn(new Float("1.8")); mv.visitInsn(FCMPL); mv.visitJumpInsn(IFNE, l1); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLdcInsn(new Float("0.6")); mv.visitVarInsn(FSTORE, 1); Label l3 = new Label(); mv.visitLabel(l3); mv.visitLdcInsn(new Float("0.6")); mv.visitVarInsn(FSTORE, 2); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(FLOAD, 1); mv.visitVarInsn(FLOAD, 2); mv.visitMethodInsn(INVOKESPECIAL, "net/minecraft/entity/Entity", "setSize", "(FF)V"); Label l4 = new Label(); mv.visitLabel(l4); mv.visitInsn(RETURN); Label l5 = new Label(); mv.visitLabel(l5); mv.visitLocalVariable("this", "Lnet/minecraft/entity/player/EntityPlayer;", null, l0, l5, 0); mv.visitLocalVariable("par1", "F", null, l0, l5, 1); mv.visitLocalVariable("par2", "F", null, l0, l5, 2); mv.visitMaxs(3, 3); mv.visitEnd(); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(cw); mv.accept(cw); return cw.toByteArray(); } else { return basicClass; } }