Package org.springframework.asm

Examples of org.springframework.asm.MethodVisitor


      for (FieldAdder fieldAdder: fieldAdders) {
        fieldAdder.generateField(cw,this);
      }
    }
    if (clinitAdders != null) {
      MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "<clinit>", "()V", null, null);
      mv.visitCode();
      nextFreeVariableId = 0; // To 0 because there is no 'this' in a clinit
      for (ClinitAdder clinitAdder: clinitAdders) {
        clinitAdder.generateCode(mv, this);
      }
      mv.visitInsn(RETURN);
      mv.visitMaxs(0,0); // not supplied due to COMPUTE_MAXS
      mv.visitEnd();
    }
  }
View Full Code Here


    String clazzName = "spel/Ex" + getNextSuffix();
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS|ClassWriter.COMPUTE_FRAMES);
    cw.visit(V1_5, ACC_PUBLIC, clazzName, null, "org/springframework/expression/spel/CompiledExpression", null);

    // Create default constructor
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, "org/springframework/expression/spel/CompiledExpression",
        "<init>", "()V", false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(1, 1);
    mv.visitEnd();

    // Create getValue() method
    mv = cw.visitMethod(ACC_PUBLIC, "getValue",
        "(Ljava/lang/Object;Lorg/springframework/expression/EvaluationContext;)Ljava/lang/Object;", null,
        new String[ ]{"org/springframework/expression/EvaluationException"});
    mv.visitCode();

    CodeFlow cf = new CodeFlow(clazzName, cw);

    // Ask the expression AST to generate the body of the method
    try {
      expressionToCompile.generateCode(mv, cf);
    }
    catch (IllegalStateException ex) {
      if (logger.isDebugEnabled()) {
        logger.debug(expressionToCompile.getClass().getSimpleName() +
            ".generateCode opted out of compilation: " + ex.getMessage());
      }
      return null;
    }

    CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor());
    if ("V".equals(cf.lastDescriptor())) {
      mv.visitInsn(ACONST_NULL);
    }
    mv.visitInsn(ARETURN);

    mv.visitMaxs(0, 0)// not supplied due to COMPUTE_MAXS
    mv.visitEnd();
    cw.visitEnd();
   
    cf.finish();
   
    byte[] data = cw.toByteArray();
View Full Code Here

    };
  }

  private MethodVisitor createMethodVisitor(final ProjectModelImpl model, final String className,
      final MemberHandle mh) {
    return new MethodVisitor() {

      public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
        model.addMemberAnnotation(convertAnnotationDescriptor(desc), mh);
        return createAnnotationVisitor(model, mh, desc);
      }
View Full Code Here

    fv.visitEnd();

    String voidNoArgMethodDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {});

    // field class loading
    MethodVisitor mv = cw.visitMethod(ACC_STATIC, CINIT, voidNoArgMethodDescriptor, null, null);
    mv.visitCode();
    mv.visitLdcInsn(Type.getType(clazz));
    mv.visitFieldInsn(PUTSTATIC, className, CLASS_FIELD_NAME, CLASS_DESCRIPTOR);
    mv.visitInsn(RETURN);
    mv.visitMaxs(1, 0);
    mv.visitEnd();

    String voidArgClassAndIntDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {
        Type.getType(Class.class), Type.INT_TYPE });

    // default constructor
    mv = cw.visitMethod(ACC_PUBLIC, INIT, voidNoArgMethodDescriptor, null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETSTATIC, className, CLASS_FIELD_NAME, CLASS_DESCRIPTOR);
    mv.visitFieldInsn(GETSTATIC, className, ID_FIELD_NAME, Type.INT_TYPE.getDescriptor());
    mv.visitMethodInsn(INVOKESPECIAL, className, INIT, voidArgClassAndIntDescriptor);
    mv.visitInsn(RETURN);
    mv.visitMaxs(3, 1);
    mv.visitEnd();

    // two-arg constructor
    mv = cw.visitMethod(ACC_PUBLIC, INIT, voidArgClassAndIntDescriptor, null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitVarInsn(ILOAD, 2);
    mv.visitMethodInsn(INVOKESPECIAL, INSTANTIATOR_NAME, INIT, voidArgClassAndIntDescriptor);
    mv.visitInsn(RETURN);
    mv.visitMaxs(3, 3);
    mv.visitEnd();

    Type customClassType = Type.getType(clazz);
    String customTypeNoArgDesc = Type.getMethodDescriptor(customClassType, new Type[] {});

    // newInstance overloaded method
    mv = cw.visitMethod(ACC_PUBLIC, NEW_INSTANCE, customTypeNoArgDesc, null, null);

    mv.visitCode();
    mv.visitTypeInsn(NEW, customClassType.getInternalName());
    mv.visitInsn(DUP);
    mv.visitMethodInsn(INVOKESPECIAL, customClassType.getInternalName(), INIT, voidNoArgMethodDescriptor);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(2, 1);
    mv.visitEnd();

    // plus original method signature
    mv = cw.visitMethod(ACC_PUBLIC + ACC_BRIDGE + ACC_SYNTHETIC, NEW_INSTANCE, NEW_INSTANCE_DESC, null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKEVIRTUAL, className, NEW_INSTANCE, customTypeNoArgDesc);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(1, 1);
    mv.visitEnd();

    // end class generation
    cw.visitEnd();

    return cw.toByteArray();
View Full Code Here

TOP

Related Classes of org.springframework.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.