Example usage for org.objectweb.asm MethodVisitor visitCode

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

Introduction

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

Prototype

public void visitCode() 

Source Link

Document

Starts the visit of the method's code, if any (i.e.

Usage

From source file:org.apache.cxf.jaxws.WrapperClassGenerator.java

License:Apache License

private void generateMessagePart(ClassWriter cw, MessagePartInfo mpi, Method method, String className) {
    if (Boolean.TRUE.equals(mpi.getProperty(ReflectionServiceFactoryBean.HEADER))) {
        return;/*from w  ww .ja  v  a  2 s  . c  o m*/
    }
    String classFileName = periodToSlashes(className);
    String name = mpi.getName().getLocalPart();
    Class clz = mpi.getTypeClass();
    Object obj = mpi.getProperty(ReflectionServiceFactoryBean.RAW_CLASS);
    if (obj != null) {
        clz = (Class) obj;
    }
    Type genericType = (Type) mpi.getProperty(ReflectionServiceFactoryBean.GENERIC_TYPE);
    if (genericType instanceof ParameterizedType) {
        ParameterizedType tp = (ParameterizedType) genericType;
        if (tp.getRawType() instanceof Class && Holder.class.isAssignableFrom((Class) tp.getRawType())) {
            genericType = tp.getActualTypeArguments()[0];
        }
    }
    String classCode = getClassCode(clz);
    String fieldDescriptor = null;

    if (genericType instanceof ParameterizedType) {
        if (Collection.class.isAssignableFrom(clz) || clz.isArray()) {
            ParameterizedType ptype = (ParameterizedType) genericType;

            Type[] types = ptype.getActualTypeArguments();
            // TODO: more complex Parameterized type
            if (types.length > 0) {
                if (types[0] instanceof Class) {
                    fieldDescriptor = getClassCode(genericType);
                } else if (types[0] instanceof GenericArrayType) {
                    fieldDescriptor = getClassCode(genericType);
                } else if (types[0] instanceof ParameterizedType) {
                    classCode = getClassCode(((ParameterizedType) types[0]).getRawType());
                    fieldDescriptor = getClassCode(genericType);
                }
            }
        } else {
            classCode = getClassCode(((ParameterizedType) genericType).getRawType());
            fieldDescriptor = getClassCode(genericType);
        }
    }
    String fieldName = JavaUtils.isJavaKeyword(name) ? JavaUtils.makeNonJavaKeyword(name) : name;

    FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, fieldName, classCode, fieldDescriptor, null);

    AnnotationVisitor av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlElement;", true);
    av0.visit("name", name);
    if (factory.isWrapperPartQualified(mpi)) {
        av0.visit("namespace", mpi.getConcreteName().getNamespaceURI());
    }
    if (factory.isWrapperPartNillable(mpi)) {
        av0.visit("nillable", Boolean.TRUE);
    }
    if (factory.getWrapperPartMinOccurs(mpi) == 1) {
        av0.visit("required", Boolean.TRUE);
    }
    av0.visitEnd();

    List<Annotation> jaxbAnnos = getJaxbAnnos(mpi);
    addJAXBAnnotations(fv, jaxbAnnos);
    fv.visitEnd();

    String methodName = JAXBUtils.nameToIdentifier(name, JAXBUtils.IdentifierType.GETTER);
    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "()" + classCode,
            fieldDescriptor == null ? null : "()" + fieldDescriptor, null);
    mv.visitCode();

    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, classFileName, fieldName, classCode);
    mv.visitInsn(org.objectweb.asm.Type.getType(classCode).getOpcode(Opcodes.IRETURN));
    mv.visitMaxs(0, 0);
    mv.visitEnd();

    methodName = JAXBUtils.nameToIdentifier(name, JAXBUtils.IdentifierType.SETTER);
    mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "(" + classCode + ")V",
            fieldDescriptor == null ? null : "(" + fieldDescriptor + ")V", null);
    mv.visitCode();
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    org.objectweb.asm.Type setType = org.objectweb.asm.Type.getType(classCode);
    mv.visitVarInsn(setType.getOpcode(Opcodes.ILOAD), 1);
    mv.visitFieldInsn(Opcodes.PUTFIELD, className, fieldName, classCode);
    mv.visitInsn(Opcodes.RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();

}

From source file:org.apache.directmemory.lightning.internal.generator.BytecodeMarshallerGenerator.java

License:Apache License

private void createConstructor(ClassWriter cw, String className, List<PropertyDescriptor> propertyDescriptors) {
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", MARSHALLER_CONSTRUCTOR_SIGNATURE, null, null);
    mv.visitCode();

    // Load this//from  w  ww  .  ja  v a 2s . com
    mv.visitVarInsn(ALOAD, 0);

    // Load first parameter type (Class)
    mv.visitVarInsn(ALOAD, 1);

    // Load second parameter type (Map)
    mv.visitVarInsn(ALOAD, 2);

    // Load third parameter type (ClassDescriptorAwaySerializer)
    mv.visitVarInsn(ALOAD, 3);

    // Load fourth parameter type (ObjenesisSerializer)
    mv.visitVarInsn(ALOAD, 4);

    // Call super(Class, Map)
    mv.visitMethodInsn(INVOKESPECIAL, SUPER_CLASS_INTERNAL_TYPE, "<init>",
            MARSHALLER_SUPER_CONSTRUCTOR_SIGNATURE);

    // Fill fields with marshallers
    for (int i = 0; i < propertyDescriptors.size(); i++) {
        PropertyDescriptor propertyDescriptor = propertyDescriptors.get(i);
        String fieldName = toFinalFieldName("marshaller", propertyDescriptor);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 0);

        // Load property type
        mv.visitVarInsn(ALOAD, 5);
        mv.visitIntInsn(BIPUSH, i);
        mv.visitMethodInsn(INVOKEINTERFACE, LIST_CLASS_INTERNAL_TYPE, "get", "(I)Ljava/lang/Object;");

        // Store PropertyDescriptor
        mv.visitTypeInsn(CHECKCAST, PROPERTYDESCRIPTOR_CLASS_INTERNAL_TYPE);
        mv.visitFieldInsn(PUTFIELD, className, toFinalFieldName("descriptor", propertyDescriptor),
                PROPERTYDESCRIPTOR_CLASS_DESCRIPTOR);

        if (propertyDescriptor.getType().isArray()
                && !propertyDescriptor.getType().getComponentType().isPrimitive()) {
            Label labelNonNull = new Label();

            // Get type from PropertyAccessor
            mv.visitVarInsn(ALOAD, 0);
            mv.visitFieldInsn(GETFIELD, className, toFinalFieldName("descriptor", propertyDescriptor),
                    PROPERTYDESCRIPTOR_CLASS_DESCRIPTOR);
            mv.visitMethodInsn(INVOKEINTERFACE, PROPERTYDESCRIPTOR_CLASS_INTERNAL_TYPE, "getType",
                    "()Ljava/lang/Class;");

            // Get array component type
            mv.visitMethodInsn(INVOKEVIRTUAL, CLASS_CLASS_INTERNAL_TYPE, "getComponentType",
                    CLASS_GET_COMPONENT_TYPE);
            mv.visitVarInsn(ASTORE, 9);

            // Generate cheating PropertyDescriptor for component type
            mv.visitVarInsn(ALOAD, 0);
            mv.visitTypeInsn(NEW, CHEATINGPROPERTYDESCRIPTOR_CLASS_INTERNAL_TYPE);
            mv.visitInsn(DUP);
            mv.visitLdcInsn(propertyDescriptor.getPropertyName() + "Element");
            mv.visitVarInsn(ALOAD, 9);
            mv.visitInsn(ACONST_NULL);
            mv.visitMethodInsn(INVOKESPECIAL, CHEATINGPROPERTYDESCRIPTOR_CLASS_INTERNAL_TYPE, "<init>",
                    CHEATINGPROPERTYDESCRIPTOR_CONSTRUCTOR);
            mv.visitFieldInsn(PUTFIELD, className, toFinalFieldName("component", propertyDescriptor),
                    CHEATINGPROPERTYDESCRIPTOR_CLASS_DESCRIPTOR);

            // Search marshaller by using interal ones
            mv.visitVarInsn(ALOAD, 6);
            mv.visitVarInsn(ALOAD, 9);
            mv.visitInsn(ACONST_NULL);
            mv.visitMethodInsn(INVOKEINTERFACE, MARSHALLERSTRATEGY_CLASS_INTERNAL_TYPE, "getMarshaller",
                    MARSHALLERSTRATEGY_GET_MARSHALLER_SIGNATURE);
            mv.visitVarInsn(ASTORE, 8);
            mv.visitVarInsn(ALOAD, 8);

            // Search marshaller for property type
            mv.visitJumpInsn(IFNONNULL, labelNonNull);
            mv.visitVarInsn(ALOAD, 0);
            mv.visitVarInsn(ALOAD, 0);
            mv.visitFieldInsn(GETFIELD, className, toFinalFieldName("component", propertyDescriptor),
                    CHEATINGPROPERTYDESCRIPTOR_CLASS_DESCRIPTOR);
            mv.visitMethodInsn(INVOKEVIRTUAL, SUPER_CLASS_INTERNAL_TYPE, "findMarshaller",
                    MARSHALLER_FIND_MARSHALLER_SIGNATURE);
            mv.visitVarInsn(ASTORE, 8);

            // Save marshaller to field
            mv.visitLabel(labelNonNull);
            mv.visitVarInsn(ALOAD, 0);
            mv.visitVarInsn(ALOAD, 8);
            mv.visitFieldInsn(PUTFIELD, className, toFinalFieldName("marshaller", propertyDescriptor),
                    MARSHALLER_CLASS_DESCRIPTOR);
        } else {
            // Check if marshaller is defined
            mv.visitVarInsn(ALOAD, 0);
            mv.visitVarInsn(ALOAD, 0);
            mv.visitVarInsn(ALOAD, 0);
            mv.visitFieldInsn(GETFIELD, className, toFinalFieldName("descriptor", propertyDescriptor),
                    PROPERTYDESCRIPTOR_CLASS_DESCRIPTOR);
            mv.visitMethodInsn(INVOKEVIRTUAL, SUPER_CLASS_INTERNAL_TYPE, "findMarshaller",
                    MARSHALLER_FIND_MARSHALLER_SIGNATURE);
            mv.visitFieldInsn(PUTFIELD, className, fieldName, MARSHALLER_CLASS_DESCRIPTOR);
        }

        // Load this to method stack
        mv.visitVarInsn(ALOAD, 0);
        mv.visitInsn(DUP);

        // Load property accessor
        mv.visitFieldInsn(GETFIELD, className, toFinalFieldName("descriptor", propertyDescriptor),
                PROPERTYDESCRIPTOR_CLASS_DESCRIPTOR);
        mv.visitMethodInsn(INVOKEINTERFACE, PROPERTYDESCRIPTOR_CLASS_INTERNAL_TYPE, "getPropertyAccessor",
                PROPERTY_DESCRIPTOR_GET_PROPERTYACCESSOR_SIGNATURE);

        // Save PropertyAccessor to field
        mv.visitFieldInsn(PUTFIELD, className, toFinalFieldName("accessor", propertyDescriptor),
                PROPERTYACCESSOR_CLASS_DESCRIPTOR);
    }

    mv.visitInsn(RETURN);
    mv.visitMaxs(-1, 12);
    mv.visitEnd();
}

From source file:org.apache.felix.ipojo.handler.temporal.ProxyGenerator.java

License:Apache License

/**
 * Generates a delegated method.//w w w.  j a  v  a 2  s  . co  m
 * @param cw the class writer
 * @param method the method object to delegate
 * @param className the generated class name
 * @param itfName the internal specification class name
 */
private static void generateDelegator(ClassWriter cw, Method method, String className, String itfName) {
    String methodName = method.getName();
    String desc = Type.getMethodDescriptor(method);
    String[] exceptions = getInternalClassNames(method.getExceptionTypes());
    int modifiers = method.getModifiers() & ~(Modifier.ABSTRACT | Modifier.NATIVE | Modifier.SYNCHRONIZED);
    Type[] types = Type.getArgumentTypes(method);

    int freeRoom = 1;
    for (int t = 0; t < types.length; t++) {
        freeRoom = freeRoom + types[t].getSize();
    }

    MethodVisitor mv = cw.visitMethod(modifiers, methodName, desc, null, exceptions);
    mv.visitCode();

    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, DEPENDENCY, DEPENDENCY_DESC); // The temporal dependency is on the stack.
    mv.visitMethodInsn(INVOKEVIRTUAL, TEMPORAL_DEPENDENCY, "getService", // Call getService
            "()Ljava/lang/Object;"); // The service object is on the stack.
    int varSvc = freeRoom;
    freeRoom = freeRoom + 1; // Object Reference.
    mv.visitVarInsn(ASTORE, varSvc); // Store the service object.

    // Invoke the method on the service object.
    mv.visitVarInsn(ALOAD, varSvc);
    // Push argument on the stack.
    int i = 1; // Arguments. (non static method)
    for (int t = 0; t < types.length; t++) {
        mv.visitVarInsn(types[t].getOpcode(ILOAD), i);
        i = i + types[t].getSize();
    }
    // Invocation
    mv.visitMethodInsn(INVOKEINTERFACE, itfName, methodName, desc);

    // Return the result
    Type returnType = Type.getReturnType(desc);
    if (returnType.getSort() != Type.VOID) {
        mv.visitInsn(returnType.getOpcode(IRETURN));
    } else {
        mv.visitInsn(RETURN);
    }

    // End of the method.
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}

From source file:org.apache.felix.ipojo.handler.temporal.ProxyGenerator.java

License:Apache License

/**
 * Generates the constructors. The constructor receives a temporal dependency
 * and set the {@link ProxyGenerator#DEPENDENCY} field.
 * @param cw the class writer//from  w  ww.  j a v a2s  .  c o  m
 * @param className the generated class name.
 */
private static void generateConstructor(ClassWriter cw, String className) {
    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", '(' + DEPENDENCY_DESC + ")V", null, null);
    mv.visitCode();

    mv.visitVarInsn(ALOAD, 0); // Load this
    mv.visitInsn(DUP); // Dup
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); // Call  super
    mv.visitVarInsn(ALOAD, 1); // Load the argument
    mv.visitFieldInsn(PUTFIELD, className, DEPENDENCY, DEPENDENCY_DESC); // Assign the dependency field
    mv.visitInsn(RETURN); // Return void

    mv.visitMaxs(0, 0);
    mv.visitEnd();
}

From source file:org.apache.felix.ipojo.manipulation.ClassManipulator.java

License:Apache License

/**
 * Creates a simple constructor with an instance manager
 * in argument if no suitable constructor is found during
 * the visit./*from w ww .  j av  a2s  . com*/
 */
private void createSimpleConstructor() {
    MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "<init>", "(Lorg/apache/felix/ipojo/InstanceManager;)V", null,
            null);
    mv.visitCode();

    // Super call
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, m_superclass, "<init>", "()V", false);

    // Call set instance manager
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEVIRTUAL, m_owner, "_setInstanceManager",
            "(Lorg/apache/felix/ipojo/InstanceManager;)V", false);

    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}

From source file:org.apache.felix.ipojo.manipulation.ClassManipulator.java

License:Apache License

/**
 * Create the setter method for the __cm field.
 *//*from   w  ww.ja v  a  2  s .com*/
private void createSetInstanceManagerMethod() {
    MethodVisitor mv = cv.visitMethod(ACC_PRIVATE, "_setInstanceManager",
            "(Lorg/apache/felix/ipojo/InstanceManager;)V", null, null);
    mv.visitCode();

    // If the given instance manager is null, just returns.
    mv.visitVarInsn(ALOAD, 1);
    Label l1 = new Label();
    mv.visitJumpInsn(IFNONNULL, l1);
    mv.visitInsn(RETURN);
    mv.visitLabel(l1);

    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitFieldInsn(PUTFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");

    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
    mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "getRegistredFields",
            "()Ljava/util/Set;", false);
    mv.visitVarInsn(ASTORE, 2);

    mv.visitVarInsn(ALOAD, 2);
    Label endif = new Label();
    mv.visitJumpInsn(IFNULL, endif);
    for (String field : m_fields) {
        mv.visitVarInsn(ALOAD, 2);
        mv.visitLdcInsn(field);
        mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Set", "contains", "(Ljava/lang/Object;)Z", true);
        Label l3 = new Label();
        mv.visitJumpInsn(IFEQ, l3);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitInsn(ICONST_1);
        mv.visitFieldInsn(PUTFIELD, m_owner, FIELD_FLAG_PREFIX + field, "Z");
        mv.visitLabel(l3);
    }
    mv.visitLabel(endif);

    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
    mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "getRegistredMethods",
            "()Ljava/util/Set;", false);
    mv.visitVarInsn(ASTORE, 2);

    mv.visitVarInsn(ALOAD, 2);
    Label endif2 = new Label();
    mv.visitJumpInsn(IFNULL, endif2);

    for (String methodId : m_methods) {
        if (!methodId.equals("<init>")) {
            mv.visitVarInsn(ALOAD, 2);
            mv.visitLdcInsn(methodId);
            mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Set", "contains", "(Ljava/lang/Object;)Z", true);
            Label l3 = new Label();
            mv.visitJumpInsn(IFEQ, l3);
            mv.visitVarInsn(ALOAD, 0);
            mv.visitInsn(ICONST_1);
            mv.visitFieldInsn(PUTFIELD, m_owner, METHOD_FLAG_PREFIX + methodId, "Z");
            mv.visitLabel(l3);
        }
    }

    mv.visitLabel(endif2);
    mv.visitInsn(RETURN);

    mv.visitMaxs(0, 0);
    mv.visitEnd();
}

From source file:org.apache.felix.ipojo.manipulation.ClassManipulator.java

License:Apache License

/**
 * Create the getComponentInstance method.
 *//*from w  w  w .  j a  va 2 s. c om*/
private void createGetComponentInstanceMethod() {
    MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "getComponentInstance",
            "()Lorg/apache/felix/ipojo/ComponentInstance;", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
    mv.visitInsn(ARETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}

From source file:org.apache.felix.ipojo.manipulation.ClassManipulator.java

License:Apache License

/**
 * Create a getter method for an array./*from   www . j a  va2 s .c o m*/
 * @param name : field name
 * @param desc : method description
 */
private void createArraySetter(String name, String desc) {
    MethodVisitor mv = cv.visitMethod(0, "__set" + name, desc, null, null);
    mv.visitCode();

    String internalType = desc.substring(1);
    internalType = internalType.substring(0, internalType.length() - 2);

    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, m_owner, FIELD_FLAG_PREFIX + name, "Z");
    Label l2 = new Label();
    mv.visitJumpInsn(IFNE, l2);

    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitFieldInsn(PUTFIELD, m_owner, name, internalType);
    mv.visitInsn(RETURN);
    mv.visitLabel(l2);

    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
    mv.visitVarInsn(ALOAD, 0);
    mv.visitLdcInsn(name);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", SET,
            "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V", false);

    mv.visitInsn(RETURN);

    // End
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}

From source file:org.apache.felix.ipojo.manipulation.ClassManipulator.java

License:Apache License

/**
 * Create a setter method for an array.//  ww  w.j  av a2s. co  m
 * @param name : field name
 * @param desc : method description
 */
private void createArrayGetter(String name, String desc) {
    String methodName = "__get" + name;
    MethodVisitor mv = cv.visitMethod(0, methodName, desc, null, null);
    mv.visitCode();

    String internalType = desc.substring(2);

    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, m_owner, FIELD_FLAG_PREFIX + name, "Z");
    Label l1 = new Label();
    mv.visitJumpInsn(IFNE, l1);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, m_owner, name, internalType);
    mv.visitInsn(ARETURN);
    mv.visitLabel(l1);

    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
    mv.visitVarInsn(ALOAD, 0);
    mv.visitLdcInsn(name);
    mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", GET,
            "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;", false);
    mv.visitTypeInsn(CHECKCAST, internalType);
    mv.visitInsn(ARETURN);

    // End
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}

From source file:org.apache.felix.ipojo.manipulation.ClassManipulator.java

License:Apache License

/**
 * Create the getter for a field./* w ww  .  j a va  2s .c om*/
 * @param name : field of the dependency
 * @param desc : description of the getter method
 * @param type : type to return
 */
private void createSimpleGetter(String name, String desc, Type type) {
    String methodName = "__get" + name;
    MethodVisitor mv = cv.visitMethod(0, methodName, desc, null, null);
    mv.visitCode();

    switch (type.getSort()) {
    case Type.BOOLEAN:
    case Type.CHAR:
    case Type.BYTE:
    case Type.SHORT:
    case Type.INT:

        String internalName = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][0];
        String boxingType = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][1];
        String unboxingMethod = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][2];

        Label l0 = new Label();
        mv.visitLabel(l0);

        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, m_owner, FIELD_FLAG_PREFIX + name, "Z");
        Label l1 = new Label();
        mv.visitJumpInsn(IFNE, l1);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, m_owner, name, internalName);
        mv.visitInsn(IRETURN);

        mv.visitLabel(l1);

        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitLdcInsn(name);
        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", GET,
                "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;", false);
        mv.visitVarInsn(ASTORE, 1);

        mv.visitVarInsn(ALOAD, 1);
        mv.visitTypeInsn(CHECKCAST, boxingType);
        mv.visitVarInsn(ASTORE, 2);

        mv.visitVarInsn(ALOAD, 2);
        mv.visitMethodInsn(INVOKEVIRTUAL, boxingType, unboxingMethod, "()" + internalName, false);
        mv.visitInsn(type.getOpcode(IRETURN));
        break;

    case Type.LONG:
        internalName = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][0];
        boxingType = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][1];
        unboxingMethod = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][2];

        l0 = new Label();
        mv.visitLabel(l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, m_owner, FIELD_FLAG_PREFIX + name, "Z");
        l1 = new Label();
        mv.visitJumpInsn(IFNE, l1);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, m_owner, name, internalName);
        mv.visitInsn(LRETURN);
        mv.visitLabel(l1);

        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitLdcInsn(name);
        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", GET,
                "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;", false);
        mv.visitVarInsn(ASTORE, 1);

        mv.visitVarInsn(ALOAD, 1);
        mv.visitTypeInsn(CHECKCAST, boxingType);
        mv.visitVarInsn(ASTORE, 2);

        mv.visitVarInsn(ALOAD, 2);
        mv.visitMethodInsn(INVOKEVIRTUAL, boxingType, unboxingMethod, "()" + internalName, false);
        mv.visitInsn(LRETURN);

        break;

    case Type.DOUBLE:
        internalName = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][0];
        boxingType = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][1];
        unboxingMethod = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][2];

        l0 = new Label();
        mv.visitLabel(l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, m_owner, FIELD_FLAG_PREFIX + name, "Z");
        l1 = new Label();
        mv.visitJumpInsn(IFNE, l1);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, m_owner, name, internalName);
        mv.visitInsn(DRETURN);
        mv.visitLabel(l1);

        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitLdcInsn(name);
        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", GET,
                "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;", false);
        mv.visitVarInsn(ASTORE, 1);

        mv.visitVarInsn(ALOAD, 1);
        mv.visitTypeInsn(CHECKCAST, boxingType);
        mv.visitVarInsn(ASTORE, 2);

        mv.visitVarInsn(ALOAD, 2);
        mv.visitMethodInsn(INVOKEVIRTUAL, boxingType, unboxingMethod, "()" + internalName, false);
        mv.visitInsn(DRETURN);

        break;

    case Type.FLOAT:
        internalName = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][0];
        boxingType = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][1];
        unboxingMethod = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][2];

        l0 = new Label();
        mv.visitLabel(l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, m_owner, FIELD_FLAG_PREFIX + name, "Z");
        l1 = new Label();
        mv.visitJumpInsn(IFNE, l1);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, m_owner, name, internalName);
        mv.visitInsn(FRETURN);
        mv.visitLabel(l1);

        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitLdcInsn(name);
        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", GET,
                "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;", false);
        mv.visitVarInsn(ASTORE, 1);

        mv.visitVarInsn(ALOAD, 1);
        mv.visitTypeInsn(CHECKCAST, boxingType);
        mv.visitVarInsn(ASTORE, 2);

        mv.visitVarInsn(ALOAD, 2);
        mv.visitMethodInsn(INVOKEVIRTUAL, boxingType, unboxingMethod, "()" + internalName, false);
        mv.visitInsn(FRETURN);

        break;

    case Type.OBJECT:
        l0 = new Label();
        mv.visitLabel(l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, m_owner, FIELD_FLAG_PREFIX + name, "Z");
        l1 = new Label();
        mv.visitJumpInsn(IFNE, l1);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, m_owner, name, "L" + type.getInternalName() + ";");
        mv.visitInsn(ARETURN);
        mv.visitLabel(l1);

        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitLdcInsn(name);
        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", GET,
                "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;", false);
        mv.visitTypeInsn(CHECKCAST, type.getInternalName());
        mv.visitInsn(ARETURN);

        break;

    default:
        ManipulationProperty.getLogger().log(ManipulationProperty.SEVERE,
                "Manipulation problem in " + m_owner + " : a type is not implemented : " + type);
        break;
    }

    mv.visitMaxs(0, 0);
    mv.visitEnd();
}