Example usage for org.objectweb.asm.tree InsnList add

List of usage examples for org.objectweb.asm.tree InsnList add

Introduction

In this page you can find the example usage for org.objectweb.asm.tree InsnList add.

Prototype

public void add(final InsnList insnList) 

Source Link

Document

Adds the given instructions to the end of this list.

Usage

From source file:org.coldswap.util.AutoBoxing.java

License:Open Source License

private static InsnList boxLong() {
    InsnList il = new InsnList();
    il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;"));
    return il;//from   ww  w.  j a v a  2 s  .  c  om
}

From source file:org.coldswap.util.AutoBoxing.java

License:Open Source License

private static InsnList unboxLong() {
    InsnList il = new InsnList();
    il.add(new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Number"));
    il.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Number", "longValue", "()J"));
    return il;/*ww  w  .ja  va2  s.c om*/
}

From source file:org.coldswap.util.AutoBoxing.java

License:Open Source License

private static InsnList boxFloat() {
    InsnList il = new InsnList();
    il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;"));
    return il;//from  w w w. j a v  a  2  s. c om
}

From source file:org.coldswap.util.AutoBoxing.java

License:Open Source License

private static InsnList unboxFloat() {
    InsnList il = new InsnList();
    il.add(new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Number"));
    il.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Number", "floatValue", "()F"));
    return il;//from w  ww.j av a2  s. com
}

From source file:org.coldswap.util.AutoBoxing.java

License:Open Source License

private static InsnList boxDouble() {
    InsnList il = new InsnList();
    il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;"));
    return il;// w ww  . j a  va  2s  .co  m
}

From source file:org.coldswap.util.AutoBoxing.java

License:Open Source License

private static InsnList unboxDouble() {
    InsnList il = new InsnList();
    il.add(new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Number"));
    il.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Number", "doubleValue", "()D"));
    return il;/*from  w w w .j  a  v  a 2s . com*/
}

From source file:org.coldswap.util.ByteCodeGenerator.java

License:Open Source License

/**
 * Creates a new class containing the new static field.
 *
 * @param classNode        containing the old class.
 * @param fieldNode        containing the old field.
 * @param initInstructions a list of instructions that goes into <clinit>.
 * @param className        the name of the new class to be generated.
 * @return an array of bytes which builds the new class.
 */// ww  w . j a  va2  s.c  o m
@SuppressWarnings("unchecked")
public static byte[] newFieldClass(ClassNode classNode, FieldNode fieldNode, InsnList initInstructions,
        String className) {
    ClassNode newClass = new ClassNode();
    newClass.version = classNode.version;
    newClass.access = Opcodes.ACC_PUBLIC;
    newClass.signature = "L" + className + ";";
    newClass.name = className;
    newClass.superName = "java/lang/Object";
    newClass.fields.add(
            new FieldNode(fieldNode.access, fieldNode.name, fieldNode.desc, fieldNode.desc, fieldNode.value));
    if (initInstructions != null) {
        if (initInstructions.size() > 0) {
            MethodNode mn = new MethodNode(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null);
            InsnList il = mn.instructions;
            il.add(new LabelNode());
            il.add(initInstructions);
            il.add(new FieldInsnNode(Opcodes.PUTSTATIC, className, fieldNode.name, fieldNode.desc));
            il.add(new InsnNode(Opcodes.RETURN));
            newClass.methods.add(mn);
        }
    }

    ClassWriter newCWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    newClass.accept(newCWriter);
    return newCWriter.toByteArray();
}

From source file:org.coldswap.util.MethodUtil.java

License:Open Source License

public static MethodNode createObjectHelperMethod(String className, int counter) {
    int acc = Opcodes.ACC_PUBLIC;
    String methodName = TransformerNameGenerator.getObjectMethodNameWithCounter(className, counter);
    MethodNode mn = new MethodNode(acc, methodName, "([Ljava/lang/Object;)Ljava/lang/Object;", null, null);
    InsnList insnList = mn.instructions;
    LabelNode l0 = new LabelNode();
    insnList.add(l0);
    insnList.add(new InsnNode(Opcodes.ACONST_NULL));
    insnList.add(new InsnNode(Opcodes.ARETURN));
    LabelNode l1 = new LabelNode();
    insnList.add(l1);//from   w  w w  .  ja  v a 2s  .  com
    String classLiteral = "L" + className + ";";
    mn.localVariables.add(new LocalVariableNode("this", classLiteral, null, l0, l1, 0));
    mn.localVariables.add(new LocalVariableNode("args", "[Ljava/lang/Object;", null, l0, l1, 1));
    mn.maxStack = 1;
    mn.maxLocals = 2;
    return mn;

}

From source file:org.coldswap.util.MethodUtil.java

License:Open Source License

public static MethodNode createIntHelperMethod(String className, int counter) {
    int acc = Opcodes.ACC_PUBLIC;
    String methodName = TransformerNameGenerator.getIntMethodNameWithCounter(className, counter);
    MethodNode mn = new MethodNode(acc, methodName, "(I)Ljava/lang/Object;", null, null);
    InsnList insnList = mn.instructions;
    LabelNode l0 = new LabelNode();
    insnList.add(l0);
    insnList.add(new InsnNode(Opcodes.ACONST_NULL));
    insnList.add(new InsnNode(Opcodes.ARETURN));
    LabelNode l1 = new LabelNode();
    insnList.add(l1);//from  www . j  ava  2s.  c  o  m
    String classLiteral = "L" + className + ";";
    mn.localVariables.add(new LocalVariableNode("this", classLiteral, null, l0, l1, 0));
    mn.localVariables.add(new LocalVariableNode("arg", "I", null, l0, l1, 1));
    mn.maxStack = 1;
    mn.maxLocals = 2;
    return mn;
}

From source file:org.coldswap.util.MethodUtil.java

License:Open Source License

public static MethodNode createLongHelperMethod(String className, int counter) {
    int acc = Opcodes.ACC_PUBLIC;
    String methodName = TransformerNameGenerator.getLongMethodNameWithCounter(className, counter);
    MethodNode mn = new MethodNode(acc, methodName, "(J)Ljava/lang/Object;", null, null);
    InsnList insnList = mn.instructions;
    LabelNode l0 = new LabelNode();
    insnList.add(l0);
    insnList.add(new InsnNode(Opcodes.ACONST_NULL));
    insnList.add(new InsnNode(Opcodes.ARETURN));
    LabelNode l1 = new LabelNode();
    insnList.add(l1);//from   w w  w.  j  av a2 s . c om
    String classLiteral = "L" + className + ";";
    mn.localVariables.add(new LocalVariableNode("this", classLiteral, null, l0, l1, 0));
    mn.localVariables.add(new LocalVariableNode("arg", "J", null, l0, l1, 1));
    mn.maxStack = 1;
    mn.maxLocals = 3;
    return mn;
}