Package org.objectweb.asm

Examples of org.objectweb.asm.MethodVisitor


    mv.visitEnd();
  }

  public void testError() {
    TraceMethodVisitor tmv = new TraceMethodVisitor(null);
    MethodVisitor mv = new BasicVerifierAdapter("C", ACC_PUBLIC, "m",
        "(I)LC;", tmv);
    mv.visitCode();
    mv.visitVarInsn(ILOAD, 1);
    mv.visitVarInsn(ISTORE, 1);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(1, 2);
    try {
      mv.visitEnd();
      fail();
    } catch (RuntimeException e) {
    }
  }
View Full Code Here


        }
        MethodNode meth = (MethodNode) classNode.visitMethod(
            access, name1, desc, signature, exceptions);
        List text = ((AbstractVisitor) cv).getText();
        int size = text.size();
        MethodVisitor mv = cv.visitMethod(
            access, name1, desc, signature, exceptions);
        mv = new DecompilerMethodVisitor(this.name, meth, mv, modes);
        methods.add(mv);
        for (int i = size; i < text.size(); ++i) {
            if (text.get(i) instanceof List) {
View Full Code Here

    return null;
  }

  protected void generateBasicClass(ClassVisitor cv) {
    FieldVisitor fv;
    MethodVisitor mv;
    cv.visit(V1_1, ACC_PUBLIC, "C", null, "java/lang/Object", null);
    cv.visitSource("C.java", null);
    fv = cv.visitField(ACC_PUBLIC, "f", "I", null, null);
    if (fv != null) {
      fv.visitEnd();
    }
    mv = cv.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    if (mv != null) {
      mv.visitCode();
      mv.visitVarInsn(ALOAD, 0);
      mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>",
          "()V");
      mv.visitInsn(RETURN);
      mv.visitMaxs(1, 1);
      mv.visitEnd();
    }
    mv = cv.visitMethod(ACC_PUBLIC, "m", "()V", null, null);
    if (mv != null) {
      mv.visitCode();
      mv.visitLdcInsn(new Long(100));
      mv.visitMethodInsn(INVOKESTATIC, "java/lang/Thread", "sleep",
          "(J)V");
      mv.visitInsn(RETURN);
      mv.visitMaxs(3, 1);
      mv.visitEnd();
    }
    cv.visitEnd();
  }
View Full Code Here

  }

  @Override
  public MethodVisitor visitMethod(int access, String name,
      String desc, String signature, String[] exceptions) {
    MethodVisitor mv;
    mv = cv.visitMethod(access, name, desc, signature, exceptions);
    if (mv != null) {
      mv = new RemoveNopAdapter(mv);
    }
    return mv;
View Full Code Here

            break;
          }
        }
      }
      if (!isPresent) {
        MethodVisitor mv = cn.visitMethod(ACC_PUBLIC, "getThis",
            "()Ljava/lang/Object;", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitInsn(ARETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
      }
    }
    super.transform(cn);
  }
View Full Code Here

    this.name = name;
    this.fields = fields;
  }

  public void generate(ClassVisitor cv) {
    MethodVisitor mv;
    cv.visit(V1_1, ACC_PUBLIC, name, null, "java/lang/Object", null);

    // generate default constructor
    mv = cv.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    if (mv != null) {
      mv.visitCode();
      mv.visitVarInsn(ALOAD, 0);
      mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>",
          "()V");
      mv.visitInsn(RETURN);
      mv.visitMaxs(1, 1);
      mv.visitEnd();
    }

    Iterator<Map.Entry<String, Type>> i = fields.entrySet().iterator();
    while (i.hasNext()) {
      Map.Entry<String, Type> e = i.next();
      String fName = e.getKey();
      String fDesc = e.getValue().getDescriptor();
      Type fType = e.getValue();
      String mName;
      String mDesc;

      // generate field
      cv.visitField(ACC_PRIVATE, fName, fDesc, null, null).visitEnd();

      // generate getter
      mName = "get" + up(fName);
      mDesc = "()" + fDesc;
      mv = cv.visitMethod(ACC_PUBLIC, mName, mDesc, null, null);
      if (mv != null) {
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, name, fName, fDesc);
        mv.visitInsn(fType.getOpcode(IRETURN));
        mv.visitMaxs(fType.getSize(), 1);
        mv.visitEnd();
      }

      // generate setter
      mName = "set" + up(fName);
      mDesc = "(" + fDesc + ")V";
      mv = cv.visitMethod(ACC_PUBLIC, mName, mDesc, null, null);
      if (mv != null) {
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(fType.getOpcode(ILOAD), 1);
        mv.visitFieldInsn(PUTFIELD, name, fName, fDesc);
        mv.visitInsn(RETURN);
        mv.visitMaxs(1 + fType.getSize(), 1 + fType.getSize());
        mv.visitEnd();
      }
    }

    cv.visitEnd();
  }
View Full Code Here

    return cv.visitMethod(access, name, desc, signature, exceptions);
  }

  public void visitEnd() {
    if (!isMethodPresent && !isInterface) {
      MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "getThis",
          "()Ljava/lang/Object;", null, null);
      mv.visitCode();
      mv.visitVarInsn(ALOAD, 0);
      mv.visitInsn(ARETURN);
      mv.visitMaxs(1, 1);
      mv.visitEnd();
    }
    cv.visitEnd();
  }
View Full Code Here

    cv.visitSource("Bean.java", null);
    FieldVisitor fv = cv.visitField(ACC_PRIVATE, "f", "I", null, null);
    if (fv != null) {
      fv.visitEnd();
    }
    MethodVisitor mv;
    mv = cv.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    if (mv != null) {
      Method m = Method.getMethod("void <init>()");
      GeneratorAdapter ga = new GeneratorAdapter(ACC_PUBLIC, m, mv);
      ga.visitCode();
View Full Code Here

  public void generate(Type type, ClassVisitor cv) {
    cv.visit(V1_5, ACC_PUBLIC, type.getInternalName(), null, PROXY
        .getInternalName(), new String[] { Type.getType(itf)
        .getInternalName() });

    MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, INIT.getName(), INIT
        .getDescriptor(), null, null);
    if (mv != null) {
      GeneratorAdapter init = new GeneratorAdapter(ACC_PUBLIC, INIT, mv);
      init.visitCode();
      init.loadThis();
View Full Code Here

    isInterface = (access & ACC_INTERFACE) != 0;
  }

  public MethodVisitor visitMethod(int access, String name,
      String desc, String signature, String[] exceptions) {
    MethodVisitor mv = cv.visitMethod(access, name, desc, signature,
        exceptions);
    if (!isInterface && mv != null && !name.equals("<init>")) {
      mv = new AddTimerMethodAdapter(mv);
    }
    return mv;
View Full Code Here

TOP

Related Classes of org.objectweb.asm.MethodVisitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.