當前位置: 首頁>>代碼示例>>Java>>正文


Java MethodVisitor.visitLocalVariable方法代碼示例

本文整理匯總了Java中org.objectweb.asm.MethodVisitor.visitLocalVariable方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodVisitor.visitLocalVariable方法的具體用法?Java MethodVisitor.visitLocalVariable怎麽用?Java MethodVisitor.visitLocalVariable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.objectweb.asm.MethodVisitor的用法示例。


在下文中一共展示了MethodVisitor.visitLocalVariable方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createObjectRender

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private void createObjectRender(ClassWriter cw, String className, String classDesc, Type data) {
    Label start = new Label();
    Label end = new Label();

    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC + ACC_BRIDGE + ACC_SYNTHETIC, "render",
            Type.getMethodDescriptor(BytecodeGenerator.STRING, BytecodeGenerator.OBJECT), null, null);
    mv.visitCode();
    mv.visitLabel(start);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitTypeInsn(CHECKCAST, data.getInternalName());
    mv.visitMethodInsn(INVOKEVIRTUAL, className, "render", Type.getMethodDescriptor(BytecodeGenerator.STRING, data), false);
    mv.visitInsn(ARETURN);
    mv.visitLabel(end);
    mv.visitLocalVariable("this", classDesc, null, start, end, 0);
    //mv.visitLocalVariable("obj", data.getDescriptor(), null, start, end, 1);
    mv.visitMaxs(2, 2);
    mv.visitEnd();
}
 
開發者ID:Guichaguri,項目名稱:FastMustache,代碼行數:20,代碼來源:MustacheCompiler.java

示例2: createMainMethod

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private static void createMainMethod(ClassWriter cw) {
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    for (SysProp type : SysProp.values()) {
        if (type != SysProp.Z_ERROR) {
            dumpProperty(mv, type.sysProp);
        }
    }
    mv.visitInsn(RETURN);
    Label l3 = new Label();
    mv.visitLabel(l3);
    mv.visitLocalVariable("args", "[Ljava/lang/String;", null, l0, l3, 0);
    mv.visitMaxs(3, 1);
    mv.visitEnd();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:18,代碼來源:JavaInstallationProbe.java

示例3: generateUpdateMethod

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private static void generateUpdateMethod(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor,
        String argsClassInternalName,
        String constDesc, Parameter[] parameters) {
    MethodVisitor mv;
    mv = cw.visitMethod(ACC_PUBLIC, "update", "()Lio/primeval/reflex/arguments/Arguments;", null, null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitTypeInsn(NEW, argsClassInternalName);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, selfClassInternalName, "parameters", "Ljava/util/List;");
    for (int i = 0; i < parameters.length; i++) {
        Parameter parameter = parameters[i];
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, selfClassInternalName, parameter.getName(), Type.getDescriptor(parameter.getType()));
    }
    mv.visitMethodInsn(INVOKESPECIAL, argsClassInternalName, "<init>", constDesc, false);
    mv.visitInsn(ARETURN);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l1, 0);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}
 
開發者ID:primeval-io,項目名稱:primeval-reflex,代碼行數:26,代碼來源:MethodArgumentssUpdaterGenerator.java

示例4: generateUpdaterMethod

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private static void generateUpdaterMethod(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor,
        String updaterClassInternalName,
        String constDesc, Parameter[] parameters) {
    MethodVisitor mv;

    mv = cw.visitMethod(ACC_PUBLIC, "updater", "()Lio/primeval/reflex/arguments/ArgumentsUpdater;", null, null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitTypeInsn(NEW, updaterClassInternalName);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, selfClassInternalName, "parameters", "Ljava/util/List;");
    for (int i = 0; i < parameters.length; i++) {
        Parameter parameter = parameters[i];
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, selfClassInternalName, parameter.getName(), Type.getDescriptor(parameter.getType()));
    }
    mv.visitMethodInsn(INVOKESPECIAL, updaterClassInternalName, "<init>", constDesc, false);
    mv.visitInsn(ARETURN);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l1, 0);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}
 
開發者ID:primeval-io,項目名稱:primeval-reflex,代碼行數:27,代碼來源:MethodArgumentsGenerator.java

示例5: createConstructor

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private static void createConstructor(ClassWriter cw) {
    MethodVisitor mv;
    mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
    mv.visitInsn(RETURN);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", "LJavaProbe;", null, l0, l1, 0);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:16,代碼來源:JavaInstallationProbe.java

示例6: addBooleanGetGetter

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private void addBooleanGetGetter(String booleanField) {
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, "get" + StringUtils.capitalize(booleanField), "()Z", null, null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, className, booleanField, "Z");
    mv.visitInsn(Opcodes.IRETURN);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", "L" + className + ";", null, l0, l1, 0);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:15,代碼來源:MixInLegacyTypesClassLoader.java

示例7: generateToStringMethod

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private static void generateToStringMethod(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor,
        Parameter[] parameters) {
    MethodVisitor mv;
    mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
    mv.visitInsn(DUP);
    mv.visitLdcInsn(Type.getType(selfClassDescriptor));
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getSimpleName", "()Ljava/lang/String;", false);
    mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(Ljava/lang/Object;)Ljava/lang/String;", false);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V", false);
    mv.visitLdcInsn(" [");
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);

    for (int i = 0; i < parameters.length; i++) {
        Parameter param = parameters[i];
        mv.visitLdcInsn(param.getName() + "=");
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;",
                false);
        mv.visitVarInsn(ALOAD, 0); // this
        mv.visitFieldInsn(GETFIELD, selfClassInternalName, param.getName(), Type.getDescriptor(param.getType()));
        Class<?> paramType = param.getType();
        if (paramType.isPrimitive()) {
            // special case with StringBuilder, no specific method we default to append(int)
            if (paramType == short.class || paramType == byte.class) {
                paramType = int.class;
            }
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
                    Type.getMethodDescriptor(Type.getType(StringBuilder.class), Type.getType(paramType)), false);
        } else {
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
                    "(Ljava/lang/Object;)Ljava/lang/StringBuilder;", false);
        }
        if (i + 1 < parameters.length) {
            mv.visitLdcInsn(", ");
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;",
                    false);
        }
    }
    mv.visitLdcInsn("]");
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
    mv.visitInsn(ARETURN);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l1, 0);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}
 
開發者ID:primeval-io,項目名稱:primeval-reflex,代碼行數:52,代碼來源:MethodArgumentssUpdaterGenerator.java

示例8: generateParametersGetter

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private static void generateParametersGetter(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor) {
    MethodVisitor mv;
    mv = cw.visitMethod(ACC_PUBLIC, "parameters", "()Ljava/util/List;", "()Ljava/util/List<Ljava/lang/reflect/Parameter;>;", null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, selfClassInternalName, "parameters", "Ljava/util/List;");
    mv.visitInsn(ARETURN);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l1, 0);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}
 
開發者ID:primeval-io,項目名稱:primeval-reflex,代碼行數:16,代碼來源:MethodArgumentssUpdaterGenerator.java

示例9: visitDefaultConstructor

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
public static void visitDefaultConstructor(ClassWriter cw, String classTypeDescriptor) {
	MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
	mv.visitCode();
	Label l0 = new Label();
	mv.visitLabel(l0);
	mv.visitVarInsn(ALOAD, 0);
	mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
	mv.visitInsn(RETURN);
	Label l1 = new Label();
	mv.visitLabel(l1);
	mv.visitLocalVariable("this", classTypeDescriptor, null, l0, l1, 0);
	mv.visitMaxs(1, 1);
	mv.visitEnd();
}
 
開發者ID:Javalbert,項目名稱:faster-than-reflection,代碼行數:15,代碼來源:AsmUtils.java

示例10: generateHashCodeMethod

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private static void generateHashCodeMethod(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor,
        Parameter[] parameters) {
    MethodVisitor mv;
    mv = cw.visitMethod(ACC_PUBLIC, "hashCode", "()I", null, null);
    mv.visitCode();

    // int result = 1;

    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitInsn(ICONST_1);
    mv.visitVarInsn(ISTORE, 1);

    for (Parameter param : parameters) {
        Class<?> type = param.getType();
        mv.visitIntInsn(BIPUSH, 31);
        mv.visitVarInsn(ILOAD, 1);
        mv.visitInsn(IMUL);
        mv.visitVarInsn(ALOAD, 0);
        Type typeType = Type.getType(type);
        mv.visitFieldInsn(GETFIELD, selfClassInternalName, param.getName(), typeType.getDescriptor());
        if (type.isPrimitive()) {
            Class<?> boxed = BytecodeGenUtils.getBoxed(type);
            mv.visitMethodInsn(INVOKESTATIC, Type.getInternalName(boxed), "hashCode",
                    Type.getMethodDescriptor(Type.INT_TYPE, typeType), false);

        } else {
            mv.visitMethodInsn(INVOKESTATIC, "java/util/Objects", "hashCode", "(Ljava/lang/Object;)I", false);
        }
        mv.visitInsn(IADD);
        mv.visitVarInsn(ISTORE, 1);
    }

    mv.visitVarInsn(ILOAD, 1);
    mv.visitInsn(IRETURN);
    Label l7 = new Label();
    mv.visitLabel(l7);
    mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l7, 0);
    mv.visitLocalVariable("result", "I", null, l0, l7, 1);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}
 
開發者ID:primeval-io,項目名稱:primeval-reflex,代碼行數:43,代碼來源:MethodArgumentssUpdaterGenerator.java

示例11: findClass

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
    if (name.equals(NAME)) {
        ClassWriter cw = new ClassWriter(0);
        MethodVisitor mv;
        cw.visit(52, ACC_PUBLIC + ACC_SUPER, NAME, null, "java/lang/Object", null);

        mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "run", "(I)J", null, null);
        mv.visitCode();
        Label begin = new Label();
        mv.visitLabel(begin);
        mv.visitVarInsn(ILOAD, 0);
        Label[] labels = new Label[numberBlocks];
        int[] keys = new int[numberBlocks];
        for (int i = 0; i < labels.length; i++) {
            labels[i] = new Label();
            keys[i] = i;
        }
        Label defaultLabel = new Label();
        mv.visitLookupSwitchInsn(defaultLabel, keys, labels);
        for (int i = 0; i < labels.length; i++) {
            mv.visitLabel(labels[i]);
            mv.visitFrame(Opcodes.F_NEW, 1, new Object[]{Opcodes.INTEGER}, 0, new Object[]{});
            mv.visitLdcInsn(new Long(LARGE_CONSTANT + i));
            mv.visitInsn(LRETURN);
        }
        mv.visitLabel(defaultLabel);
        mv.visitFrame(Opcodes.F_NEW, 1, new Object[]{Opcodes.INTEGER}, 0, new Object[]{});
        mv.visitLdcInsn(new Long(3L));
        mv.visitInsn(LRETURN);
        Label end = new Label();
        mv.visitLabel(end);
        mv.visitLocalVariable("a", "I", null, begin, end, 0);
        mv.visitMaxs(2, 1);
        mv.visitEnd();
        byte[] bytes = cw.toByteArray();
        return defineClass(name, bytes, 0, bytes.length);
    } else {
        return super.findClass(name);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:42,代碼來源:LargeConstantSectionTest.java

示例12: accept

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
/**
 * Makes the given visitor visit this local variable declaration.
 * 
 * @param mv
 *            a method visitor.
 */
public void accept(final MethodVisitor mv) {
    mv.visitLocalVariable(name, desc, signature, start.getLabel(),
            end.getLabel(), index);
}
 
開發者ID:ItzSomebody,項目名稱:DirectLeaks-AntiReleak-Remover,代碼行數:11,代碼來源:LocalVariableNode.java


注:本文中的org.objectweb.asm.MethodVisitor.visitLocalVariable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。