当前位置: 首页>>代码示例>>Java>>正文


Java MethodVisitor类代码示例

本文整理汇总了Java中org.objectweb.asm.MethodVisitor的典型用法代码示例。如果您正苦于以下问题:Java MethodVisitor类的具体用法?Java MethodVisitor怎么用?Java MethodVisitor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MethodVisitor类属于org.objectweb.asm包,在下文中一共展示了MethodVisitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visit

import org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
@Override
public Object visit(ASTStreamBlockElementHdr node, Object data) throws CompileException {

  // function or stream is in here
  TContext func_context = getTopContext().getClosestAncestor(AbsType.FORM_FUNC);
  if (func_context != null) {
    MethodVisitor mv = ((TContextFunc) func_context).getMethodVisitor();
    Debug.assertion(mv != null, "mv should be valid");

    /*
     * Label linelabel = new Label();
     *
     * // line label for debugging mv.visitLabel(linelabel);
     * mv.visitLineNumber(node.jjtGetFirstToken().beginLine, linelabel);
     */

    addLineLable(mv, node.jjtGetFirstToken().beginLine);
  }

  return null;
}
 
开发者ID:Samsung,项目名称:MeziLang,代码行数:22,代码来源:ASTCompileVisitor.java

示例2: hookMethod

import org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
/**
 * (none-javadoc)
 *
 * @see AbstractClassHook#hookMethod(int, String, String, String, String[], MethodVisitor)
 */
@Override
public MethodVisitor hookMethod(int access, String name, String desc,
                                String signature, String[] exceptions, MethodVisitor mv) {
    if (name.equals("compile") && desc.startsWith("()V")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                invokeStatic(Type.getType(HookHandler.class),
                        new Method("preShieldHook", "()V"));
            }

            @Override
            protected void onMethodExit(int i) {
                invokeStatic(Type.getType(HookHandler.class),
                        new Method("postShieldHook", "()V"));
            }
        };
    }
    return mv;
}
 
开发者ID:baidu,项目名称:openrasp,代码行数:26,代码来源:JspCompilationContextHook.java

示例3: generateMethodTest10

import org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
/**
 *  Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 *  MethodHandle of kind get static. The method handle read a static field from a class.
 */
private void generateMethodTest10(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test10", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
      MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallCallingtargetMethod", mt.toMethodDescriptorString(), false);
  mv.visitFieldInsn(Opcodes.GETSTATIC,
      "java/lang/System",
      "out",
      "Ljava/io/PrintStream;");
  mv.visitInvokeDynamicInsn("staticField1", "()Ljava/lang/String;", bootstrap,
      new Handle(Opcodes.H_GETSTATIC, Type.getInternalName(InvokeCustom.class),
          "staticField1", "Ljava/lang/String;", false));
  mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
      "java/io/PrintStream",
      "println",
      "(Ljava/lang/String;)V", false);
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
 
开发者ID:inferjay,项目名称:r8,代码行数:26,代码来源:TestGenerator.java

示例4: generateUnsupportedOperationExceptionMethod

import org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
/**
 * Generates an exception which is going to be thrown in each method.
 * The reason it is in a separate method is because it reduces the bytecode size.
 */
private void generateUnsupportedOperationExceptionMethod() {
    MethodVisitor mv = cv.visitMethod(
        ACC_PRIVATE | ACC_STATIC | ACC_SYNTHETIC, UOE_METHOD,
        "()Ljava/lang/UnsupportedOperationException;", null, null);
    mv.visitCode();
    mv.visitTypeInsn(NEW, "java/lang/UnsupportedOperationException");
    mv.visitInsn(DUP);
    mv.visitLdcInsn(
        "You tried to call a method on an API class. Is the API jar on the classpath instead of the runtime jar?");
    mv.visitMethodInsn(
        INVOKESPECIAL, "java/lang/UnsupportedOperationException", "<init>", "(Ljava/lang/String;)V", false);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(3, 0);
    mv.visitEnd();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:20,代码来源:MethodStubbingApiMemberAdapter.java

示例5: visitHttpMethod

import org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
/**
 * Instrument HTTP request methods
 * 
 * @param mv
 *            original MethodVisitor
 * @param access
 * @param name
 * @param desc
 * @param signature
 * @param exceptions
 * @return original MethodVisitor or new MethodVisitor chained to original
 */
private MethodVisitor visitHttpMethod(MethodVisitor mv, int access, String name, String desc, String signature,
        String[] exceptions) {

    MethodVisitor httpMv = mv;

    /*
     * Instrument _jspService method for JSP. Instrument doGet, doPost and
     * service methods for servlets.
     */
    if ((httpInstrumentJsp && name.equals("_jspService")) || (httpInstrumentServlet
            && (name.equals("doGet") || name.equals("doPost") || name.equals("service")))) {

        // Only instrument if method has the correct signature
        if (HTTP_REQUEST_METHOD_DESC.equals(desc)) {
            httpMv = new ServletCallBackAdapter(className, mv, access, name, desc);
        }
    }

    return httpMv;
}
 
开发者ID:RuntimeTools,项目名称:javametrics,代码行数:33,代码来源:ClassAdapter.java

示例6: generateMethodTest6

import org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
/**
 *  Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 *  MethodHandle of kind invoke interface. The target method is a default method into an interface
 *  that is at the end of a chain of interfaces.
 */
private void generateMethodTest6(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test6", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
      MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallCallingtargetMethodTest7", mt.toMethodDescriptorString(), false);
  mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(InvokeCustom.class));
  mv.visitInsn(Opcodes.DUP);
  mv.visitMethodInsn(
      Opcodes.INVOKESPECIAL, Type.getInternalName(InvokeCustom.class), "<init>", "()V", false);
  mv.visitInvokeDynamicInsn("targetMethodTest7", "(Linvokecustom/J;)V", bootstrap,
      new Handle(Opcodes.H_INVOKEINTERFACE, Type.getInternalName(J.class),
          "targetMethodTest7", "()V", true));
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
 
开发者ID:inferjay,项目名称:r8,代码行数:23,代码来源:TestGenerator.java

示例7: begin

import org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
@Override
public void begin(final String name, final Attributes attrs) {
    String desc = attrs.getValue("desc");
    boolean visible = Boolean.valueOf(attrs.getValue("visible"))
            .booleanValue();
    int typeRef = Integer.parseInt(attrs.getValue("typeRef"));
    TypePath typePath = TypePath.fromString(attrs.getValue("typePath"));

    Object v = peek();
    if (v instanceof ClassVisitor) {
        push(((ClassVisitor) v).visitTypeAnnotation(typeRef, typePath,
                desc, visible));
    } else if (v instanceof FieldVisitor) {
        push(((FieldVisitor) v).visitTypeAnnotation(typeRef, typePath,
                desc, visible));
    } else if (v instanceof MethodVisitor) {
        push(((MethodVisitor) v).visitTypeAnnotation(typeRef, typePath,
                desc, visible));
    }
}
 
开发者ID:acmerli,项目名称:fastAOP,代码行数:21,代码来源:ASMContentHandler.java

示例8: visitMethod

import org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
@Override
public MethodVisitor visitMethod(final int access, final String name,
        final String desc, final String signature, final String[] exceptions) {
    MethodVisitor mv;
    if ("<clinit>".equals(name)) {
        int a = Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC;
        String n = prefix + counter++;
        mv = cv.visitMethod(a, n, desc, signature, exceptions);

        if (clinit == null) {
            clinit = cv.visitMethod(a, name, desc, null, null);
        }
        clinit.visitMethodInsn(Opcodes.INVOKESTATIC, this.name, n, desc,
                false);
    } else {
        mv = cv.visitMethod(access, name, desc, signature, exceptions);
    }
    return mv;
}
 
开发者ID:ItzSomebody,项目名称:DirectLeaks-AntiReleak-Remover,代码行数:20,代码来源:StaticInitMerger.java

示例9: writeSetter

import org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
private void writeSetter(ClassVisitor visitor, Type generatedType, String propertyName, Class<?> propertyClass, WeaklyTypeReferencingMethod<?, ?> weakSetter) {
    Type propertyType = Type.getType(propertyClass);
    Label calledOutsideOfConstructor = new Label();

    Method setter = weakSetter.getMethod();

    // the regular typed setter
    String methodDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, propertyType);
    MethodVisitor methodVisitor = declareMethod(visitor, setter.getName(), methodDescriptor, AsmClassGeneratorUtils.signature(setter));

    putCanCallSettersFieldValueOnStack(methodVisitor, generatedType);
    jumpToLabelIfStackEvaluatesToTrue(methodVisitor, calledOutsideOfConstructor);
    throwExceptionBecauseCalledOnItself(methodVisitor);

    methodVisitor.visitLabel(calledOutsideOfConstructor);
    putStateFieldValueOnStack(methodVisitor, generatedType);
    putConstantOnStack(methodVisitor, propertyName);
    putFirstMethodArgumentOnStack(methodVisitor, propertyType);
    if (propertyClass.isPrimitive()) {
        boxType(methodVisitor, propertyClass);
    }
    invokeStateSetMethod(methodVisitor);

    finishVisitingMethod(methodVisitor);
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:26,代码来源:ManagedProxyClassGenerator.java

示例10: visitMethod

import org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
@Override
public MethodVisitor visitMethod(final int access, final String name,
        final String desc, final String signature, final String[] exceptions) {
    if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
        cp.newUTF8("Synthetic");
    }
    if ((access & Opcodes.ACC_DEPRECATED) != 0) {
        cp.newUTF8("Deprecated");
    }
    cp.newUTF8(name);
    cp.newUTF8(desc);
    if (signature != null) {
        cp.newUTF8("Signature");
        cp.newUTF8(signature);
    }
    if (exceptions != null) {
        cp.newUTF8("Exceptions");
        for (int i = 0; i < exceptions.length; ++i) {
            cp.newClass(exceptions[i]);
        }
    }
    return new MethodConstantsCollector(cv.visitMethod(access, name, desc,
            signature, exceptions), cp);
}
 
开发者ID:acmerli,项目名称:fastAOP,代码行数:25,代码来源:ClassConstantsCollector.java

示例11: accept

import org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
/**
 * Makes the given visitor visit this stack map frame.
 * 
 * @param mv
 *            a method visitor.
 */
@Override
public void accept(final MethodVisitor mv) {
    switch (type) {
    case Opcodes.F_NEW:
    case Opcodes.F_FULL:
        mv.visitFrame(type, local.size(), asArray(local), stack.size(),
                asArray(stack));
        break;
    case Opcodes.F_APPEND:
        mv.visitFrame(type, local.size(), asArray(local), 0, null);
        break;
    case Opcodes.F_CHOP:
        mv.visitFrame(type, local.size(), null, 0, null);
        break;
    case Opcodes.F_SAME:
        mv.visitFrame(type, 0, null, 0, null);
        break;
    case Opcodes.F_SAME1:
        mv.visitFrame(type, 0, null, 1, asArray(stack));
        break;
    }
}
 
开发者ID:ItzSomebody,项目名称:Spigot-Nonce-ID-Finder,代码行数:29,代码来源:FrameNode.java

示例12: hookMethod

import org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
/**
 * (none-javadoc)
 *
 * @see AbstractClassHook#hookMethod(int, String, String, String, String[], MethodVisitor)
 */
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
    if ("lookup".equals(name) && desc.startsWith("(Ljava/lang/String;)")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            public void onMethodExit(int opcode) {
                if (opcode == Opcodes.ARETURN) {
                    mv.visitVarInsn(ALOAD, 2);
                    mv.visitMethodInsn(INVOKESTATIC, "com/fuxi/javaagent/hook/ProxyDirContextHook", "checkResourceCacheEntry",
                            "(Ljava/lang/Object;)V", false);
                }
                super.onMethodExit(opcode);
            }

        };
    }
    return mv;
}
 
开发者ID:baidu,项目名称:openrasp,代码行数:24,代码来源:ProxyDirContextHook.java

示例13: callUserMethodOrDirect

import org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
private static void callUserMethodOrDirect(ClassLoader classLoader, InterceptedCall call, MethodVisitor mv) {
    /* Check if we have a user-provided validation method */
    String validationMethodOwnerName = getClassForMethod(classLoader, call.desc, call);
    if (validationMethodOwnerName != null) {
        /* we have, so call it... */
        mv.visitMethodInsn(INVOKESTATIC, validationMethodOwnerName, call.name, call.desc, false);
    } else {
        /* we don't have a user-defined validation method yet, so just call the target method directly */
        mv.visitMethodInsn(INVOKESTATIC, call.receiverInternalName, call.name, call.desc, false);
    }
    /* Check GL error if it was a GL call */
    if (VALIDATE.enabled && call.glName != null && !call.glName.equals("glGetError")) {
        mv.visitLdcInsn(call.name);
        mv.visitMethodInsn(INVOKESTATIC, RT_InternalName, "checkError", "(Ljava/lang/String;)V", false);
    }
}
 
开发者ID:LWJGLX,项目名称:debug,代码行数:17,代码来源:InterceptClassGenerator.java

示例14: insertBooleanGetter

import org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
@Override
public void insertBooleanGetter(MethodVisitor mv, int var, String key) throws CompilerException {
    Class<?> type = insertGetter(mv, var, key, true).clazz;

    if(type == boolean.class) {
        // The correct type. We don't need to adapt it :D
        return;
    }

    if(type == Boolean.class) {
        // b.booleanValue()
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
    } else if(type.isPrimitive()) {
        throw new CompilerException("Can't parse a primitive into a boolean: " + type);
    } else {
        // Boolean.parseBoolean(object.toString())
        mv.visitMethodInsn(INVOKEVIRTUAL, OBJECT.getInternalName(), "toString", Type.getMethodDescriptor(STRING), false);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "parseBoolean", Type.getMethodDescriptor(STRING, Type.BOOLEAN_TYPE), false);
    }
}
 
开发者ID:Guichaguri,项目名称:FastMustache,代码行数:21,代码来源:ClassDataManager.java

示例15: visitMethod

import org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
public MethodVisitor visitMethod(int access, String name, String desc,
    String signature, String[] exceptions) {
  if ((access & Opcodes.ACC_PRIVATE) != 0) {
    return null;
  }
  pendingMethod = name + desc;
  line = -1;
  return new LineNumberMethodVisitor();
}
 
开发者ID:maetrive,项目名称:businessworks,代码行数:10,代码来源:LineNumbers.java


注:本文中的org.objectweb.asm.MethodVisitor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。