Example usage for org.objectweb.asm MethodVisitor visitMethodInsn

List of usage examples for org.objectweb.asm MethodVisitor visitMethodInsn

Introduction

In this page you can find the example usage for org.objectweb.asm MethodVisitor visitMethodInsn.

Prototype

public void visitMethodInsn(final int opcode, final String owner, final String name, final String descriptor,
        final boolean isInterface) 

Source Link

Document

Visits a method instruction.

Usage

From source file:com.gargoylesoftware.js.nashorn.internal.codegen.CompilerConstants.java

License:Open Source License

/**
 * Create a call representing an invokeinterface to a given method. Don't
 * attempt to look this up at compile time
 *
 * @param clazz  the class//from   ww  w  . j a  v  a  2s .  c o m
 * @param name   the method name
 * @param rtype  the return type
 * @param ptypes the parameter types
 *
 * @return Call representing specified invokeinterface call
 */
public static Call interfaceCallNoLookup(final Class<?> clazz, final String name, final Class<?> rtype,
        final Class<?>... ptypes) {
    return new Call(null, className(clazz), name, methodDescriptor(rtype, ptypes)) {
        @Override
        MethodEmitter invoke(final MethodEmitter method) {
            return method.invokeinterface(className, name, descriptor);
        }

        @Override
        public void invoke(final MethodVisitor mv) {
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, className, name, descriptor, true);
        }
    };
}

From source file:com.gargoylesoftware.js.nashorn.internal.codegen.CompilerConstants.java

License:Open Source License

/**
 * Create a static call, given an explicit lookup, looking up the method handle for it at the same time
 *
 * @param lookup the lookup//  w w  w . j a v  a2s . c  o m
 * @param clazz  the class
 * @param name   the name of the method
 * @param rtype  the return type
 * @param ptypes the parameter types
 *
 * @return the call object representing the static call
 */
public static Call staticCall(final MethodHandles.Lookup lookup, final Class<?> clazz, final String name,
        final Class<?> rtype, final Class<?>... ptypes) {
    return new Call(MH.findStatic(lookup, clazz, name, MH.type(rtype, ptypes)), className(clazz), name,
            methodDescriptor(rtype, ptypes)) {
        @Override
        MethodEmitter invoke(final MethodEmitter method) {
            return method.invokestatic(className, name, descriptor);
        }

        @Override
        public void invoke(final MethodVisitor mv) {
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, className, name, descriptor, false);
        }
    };
}

From source file:com.gargoylesoftware.js.nashorn.internal.codegen.CompilerConstants.java

License:Open Source License

/**
 * Create a virtual call, given an explicit lookup, looking up the method handle for it at the same time
 *
 * @param lookup the lookup//ww w  . j  a va2  s. c o  m
 * @param clazz  the class
 * @param name   the name of the method
 * @param rtype  the return type
 * @param ptypes the parameter types
 *
 * @return the call object representing the virtual call
 */
public static Call virtualCall(final MethodHandles.Lookup lookup, final Class<?> clazz, final String name,
        final Class<?> rtype, final Class<?>... ptypes) {
    return new Call(MH.findVirtual(lookup, clazz, name, MH.type(rtype, ptypes)), className(clazz), name,
            methodDescriptor(rtype, ptypes)) {
        @Override
        MethodEmitter invoke(final MethodEmitter method) {
            return method.invokevirtual(className, name, descriptor);
        }

        @Override
        public void invoke(final MethodVisitor mv) {
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className, name, descriptor, false);
        }
    };
}

From source file:com.gargoylesoftware.js.nashorn.internal.codegen.CompilerConstants.java

License:Open Source License

/**
 * Create a special call, given an explicit lookup, looking up the method handle for it at the same time.
 * clazz is used as this class/*from   www . j a  va 2s .  com*/
 *
 * @param lookup    the lookup
 * @param clazz     the class
 * @param name      the name of the method
 * @param rtype     the return type
 * @param ptypes    the parameter types
 *
 * @return the call object representing the virtual call
 */
public static Call specialCall(final MethodHandles.Lookup lookup, final Class<?> clazz, final String name,
        final Class<?> rtype, final Class<?>... ptypes) {
    return new Call(MH.findSpecial(lookup, clazz, name, MH.type(rtype, ptypes), clazz), className(clazz), name,
            methodDescriptor(rtype, ptypes)) {
        @Override
        MethodEmitter invoke(final MethodEmitter method) {
            return method.invokespecial(className, name, descriptor);
        }

        @Override
        public void invoke(final MethodVisitor mv) {
            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, className, name, descriptor, false);
        }
    };
}

From source file:com.gargoylesoftware.js.nashorn.internal.codegen.types.Type.java

License:Open Source License

static void invokestatic(final MethodVisitor method, final Call call) {
    method.visitMethodInsn(INVOKESTATIC, call.className(), call.name(), call.descriptor(), false);
}

From source file:com.github.bmsantos.core.cola.injector.ErrorsClassVisitor.java

License:Apache License

private void injectTestMethod() {

    final MethodVisitor mv = classVisitor.visitMethod(ACC_PUBLIC, METHOD_NAME, "()V", null, null);
    mv.visitCode();/*w  w w  . ja  v  a 2s .c  o  m*/
    mv.visitVarInsn(ALOAD, 0);
    mv.visitLdcInsn(errors);
    mv.visitMethodInsn(INVOKESTATIC, "org/junit/Assert", "fail", "(Ljava/lang/String;)V", false);
    mv.visitInsn(RETURN);
    mv.visitAnnotation("Lorg/junit/Test;", true);
    mv.visitEnd();
    mv.visitMaxs(0, 0);
}

From source file:com.github.bmsantos.core.cola.injector.InjectorClassVisitor.java

License:Apache License

private void injectTestMethod(final String feature, final String scenario, final String story,
        final String projectionValues, final String reports) {

    final MethodVisitor mv = infoClassVisitor.visitMethod(ACC_PUBLIC,
            String.format(METHOD_NAME_FORMAT, feature, scenario), "()V", null, null);
    mv.visitCode();/*from   www  .  j a  v  a2 s . c o  m*/
    mv.visitVarInsn(ALOAD, 0);
    mv.visitLdcInsn(feature);
    mv.visitLdcInsn(scenario);
    mv.visitLdcInsn(story);
    mv.visitLdcInsn(projectionValues);
    mv.visitLdcInsn(reports);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESTATIC, "com/github/bmsantos/core/cola/story/processor/StoryProcessor", "process",
            "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)V",
            false);
    mv.visitInsn(RETURN);
    mv.visitAnnotation("Lorg/junit/Test;", true);
    mv.visitEnd();
    mv.visitMaxs(0, 0);
}

From source file:com.github.bmsantos.core.cola.injector.InjectorClassVisitor.java

License:Apache License

private void injectIgnoreMethod(final String feature, final String scenario) {
    final MethodVisitor mv = infoClassVisitor.visitMethod(ACC_PUBLIC,
            String.format(IGNORED_METHOD_NAME_FORMAT, feature, scenario), "()V", null, null);
    mv.visitCode();/*from ww w  . j a v  a  2s. c  om*/
    mv.visitVarInsn(ALOAD, 0);
    mv.visitLdcInsn(feature);
    mv.visitLdcInsn(scenario);
    mv.visitMethodInsn(INVOKESTATIC, "com/github/bmsantos/core/cola/story/processor/StoryProcessor", "ignore",
            "(Ljava/lang/String;Ljava/lang/String;)V", false);
    mv.visitInsn(RETURN);
    mv.visitAnnotation("Lorg/junit/Test;", true);
    mv.visitEnd();
    mv.visitMaxs(0, 0);
}

From source file:com.github.fge.grappa.transform.process.GroupClassGenerator.java

License:Apache License

private void generateConstructor(ClassWriter cw) {
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", CodegenUtils.sig(void.class, String.class), null,
            null);//from  w  w w. j ava  2s  . c om
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKESPECIAL, getBaseType().getInternalName(), "<init>",
            CodegenUtils.sig(void.class, String.class), false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0); // trigger automatic computing
}

From source file:com.github.jasmo.obfuscate.ScrambleStrings.java

License:Open Source License

private void createUnscramble() {
    MethodVisitor mv = unscrambleClass.visitMethod(ACC_PUBLIC | ACC_STATIC, CALL_NAME, CALL_DESC, null, null);
    mv.visitCode();/*from   ww  w .j  a  va  2s  .co m*/
    mv.visitTypeInsn(NEW, "java/lang/String");
    mv.visitInsn(DUP);
    mv.visitMethodInsn(INVOKESTATIC, "java/util/Base64", "getDecoder", "()Ljava/util/Base64$Decoder;", false);
    mv.visitFieldInsn(GETSTATIC, unscrambleClass.name, FIELD_NAME, "[Ljava/lang/String;");
    mv.visitVarInsn(ILOAD, 0);
    mv.visitInsn(AALOAD);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/Base64$Decoder", "decode", "(Ljava/lang/String;)[B", false);
    mv.visitLdcInsn("UTF-8");
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/String", "<init>", "([BLjava/lang/String;)V", false);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}