use of org.objectweb.asm.tree.VarInsnNode in project pinpoint by naver.
the class ASMClassNodeAdapter method addGetterMethod.
public void addGetterMethod(final String methodName, final ASMFieldNodeAdapter fieldNode) {
if (methodName == null || fieldNode == null) {
throw new IllegalArgumentException("method name or fieldNode annotation must not be null.");
}
// no argument is ().
final String desc = "()" + fieldNode.getDesc();
final MethodNode methodNode = new MethodNode(Opcodes.ACC_PUBLIC, methodName, desc, null, null);
if (methodNode.instructions == null) {
methodNode.instructions = new InsnList();
}
final InsnList instructions = methodNode.instructions;
// load this.
instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
// get fieldNode.
instructions.add(new FieldInsnNode(Opcodes.GETFIELD, classNode.name, fieldNode.getName(), fieldNode.getDesc()));
// return of type.
final Type type = Type.getType(fieldNode.getDesc());
instructions.add(new InsnNode(type.getOpcode(Opcodes.IRETURN)));
if (this.classNode.methods == null) {
this.classNode.methods = new ArrayList<MethodNode>();
}
this.classNode.methods.add(methodNode);
}
use of org.objectweb.asm.tree.VarInsnNode in project Bookshelf by Darkhax-Minecraft.
the class TransformerEnchantmentHelper method transform.
public static byte[] transform(String name, String transformedName, byte[] classBytes) {
final ClassNode clazz = ASMUtils.createClassFromByteArray(classBytes);
final MethodNode method = METHOD_GET_ENCH_LEVEL.getMethodNode(clazz);
final InsnList n1 = new InsnList();
final LabelNode start = new LabelNode();
n1.add(start);
n1.add(new TypeInsnNode(Opcodes.NEW, "net/darkhax/bookshelf/events/EnchantmentModifierEvent"));
n1.add(new InsnNode(Opcodes.DUP));
n1.add(new VarInsnNode(Opcodes.ALOAD, 0));
n1.add(new VarInsnNode(Opcodes.ALOAD, 1));
n1.add(METHOD_INIT_EVENT.getMethodInsn(Opcodes.INVOKESPECIAL, false));
n1.add(new VarInsnNode(Opcodes.ASTORE, 2));
final LabelNode l1 = new LabelNode();
n1.add(l1);
n1.add(FIELD_EVENT_BUS.getFieldNode(Opcodes.GETSTATIC));
n1.add(new VarInsnNode(Opcodes.ALOAD, 2));
n1.add(METHOD_POST.getMethodInsn(Opcodes.INVOKEVIRTUAL, false));
n1.add(new InsnNode(Opcodes.POP));
final LabelNode l2 = new LabelNode();
n1.add(l2);
n1.add(new VarInsnNode(Opcodes.ALOAD, 2));
n1.add(METHOD_CANCELED.getMethodInsn(Opcodes.INVOKEVIRTUAL, false));
final LabelNode vanillaLogic = new LabelNode();
n1.add(new JumpInsnNode(Opcodes.IFEQ, vanillaLogic));
final LabelNode l4 = new LabelNode();
n1.add(l4);
n1.add(new VarInsnNode(Opcodes.ALOAD, 2));
n1.add(METHOD_GET_LEVELS.getMethodInsn(Opcodes.INVOKEVIRTUAL, false));
n1.add(new InsnNode(Opcodes.IRETURN));
n1.add(vanillaLogic);
method.instructions.insertBefore(method.instructions.getFirst(), n1);
return ASMUtils.createByteArrayFromClass(clazz, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
}
Aggregations