Package org.eclipse.persistence.internal.libraries.asm

Examples of org.eclipse.persistence.internal.libraries.asm.CodeVisitor


         * At some time later in the class' lifecycle, the XRFI
         * static is populated with the required info w.r.t the index for a field
         */
        String classNameAsSlashes = className.replace('.', '/');
        ClassWriter cw = new ClassWriter(true);
        CodeVisitor cv;
        // special-case: build sub-class of XRDynamicEntityCollection
        if (className.endsWith(COLLECTION_WRAPPER_SUFFIX)) {
            cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, classNameAsSlashes,
                XR_DYNAMIC_ENTITY_COLLECTION_CLASSNAME_SLASHES, null, null);
            cv = cw.visitMethod(ACC_PUBLIC, INIT, "()V", null, null);
            cv.visitVarInsn(ALOAD, 0);
            cv.visitMethodInsn(INVOKESPECIAL, XR_DYNAMIC_ENTITY_COLLECTION_CLASSNAME_SLASHES,
                INIT, "()V");
            cv.visitInsn(RETURN);
            cv.visitMaxs(0, 0);
        }
        else {
            cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, classNameAsSlashes,
                XR_DYNAMIC_ENTITY_CLASSNAME_SLASHES, null, null);
            cw.visitField(ACC_PUBLIC + ACC_STATIC, XR_FIELD_INFO_STATIC,
                "L" + XRFIELDINFO_CLASSNAME_SLASHES + ";", null, null);
            cv = cw.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null);
            cv.visitTypeInsn(NEW, XRFIELDINFO_CLASSNAME_SLASHES);
            cv.visitInsn(DUP);
            cv.visitMethodInsn(INVOKESPECIAL, XRFIELDINFO_CLASSNAME_SLASHES, INIT, "()V");
            cv.visitFieldInsn(PUTSTATIC, classNameAsSlashes, XR_FIELD_INFO_STATIC,
                "L" + XRFIELDINFO_CLASSNAME_SLASHES + ";");
            cv.visitInsn(RETURN);
            cv.visitMaxs(0, 0);
            cv = cw.visitMethod(ACC_PUBLIC, INIT, "()V", null, null);
            cv.visitVarInsn(ALOAD, 0);
            cv.visitMethodInsn(INVOKESPECIAL, XR_DYNAMIC_ENTITY_CLASSNAME_SLASHES, INIT, "()V");
            cv.visitInsn(RETURN);
            cv.visitMaxs(0, 0);
            cv = cw.visitMethod(ACC_PUBLIC, "getFieldInfo",
                "()L" + XRFIELDINFO_CLASSNAME_SLASHES + ";", null, null);
            cv.visitFieldInsn(GETSTATIC, classNameAsSlashes, XR_FIELD_INFO_STATIC,
                "L" + XRFIELDINFO_CLASSNAME_SLASHES + ";");
            cv.visitInsn(ARETURN);
            cv.visitMaxs(0, 0);
        }
        cw.visitEnd();
        return cw.toByteArray();
    }
View Full Code Here


       *   }
       */
      ClassWriter cw = new ClassWriter(true);
      cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, className, SOAP_RESPONSE_CLASSNAME_SLASHES, null, null);

      CodeVisitor cv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
      cv.visitVarInsn(ALOAD, 0);
      cv.visitMethodInsn(INVOKESPECIAL, SOAP_RESPONSE_CLASSNAME_SLASHES, "<init>", "()V");
      cv.visitInsn(RETURN);
      cv.visitMaxs(0, 0);

      cw.visitEnd();
      return cw.toByteArray();
    }
View Full Code Here

         * Later, via reflection, the setNumAttributes method is called with the
         * correct number of attributes
         */
        String classNameAsSlashes = className.replace('.', '/');
        ClassWriter cw = new ClassWriter(true);
        CodeVisitor cv;

        if (className.endsWith(COLLECTION_WRAPPER_SUFFIX)) {
            cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, classNameAsSlashes,
                BASE_ENTITY_COLLECTION_WRAPPER_CLASSNAME_SLASHES, null, null);

            cv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
            cv.visitVarInsn(ALOAD, 0);
            cv.visitMethodInsn(INVOKESPECIAL, BASE_ENTITY_COLLECTION_WRAPPER_CLASSNAME_SLASHES,
                "<init>", "()V");
            cv.visitInsn(RETURN);
            cv.visitMaxs(0, 0);
        }

        else {
            cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, classNameAsSlashes, BASE_ENTITY_CLASSNAME_SLASHES,
                null, null);
          
            cw.visitField(ACC_PUBLIC + ACC_STATIC, "NUM_ATTRIBUTES", "I", null, null);
            cv = cw.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null);
            cv.visitInsn(ICONST_1);
            cv.visitFieldInsn(PUTSTATIC, classNameAsSlashes, "NUM_ATTRIBUTES", "I");
            cv.visitInsn(RETURN);
            cv.visitMaxs(0, 0);
   
            cv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "setNumAttributes", "(Ljava/lang/Integer;)V",
                null, null);
            cv.visitVarInsn(ALOAD, 0);
            cv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I");
            cv.visitFieldInsn(PUTSTATIC, classNameAsSlashes, "NUM_ATTRIBUTES", "I");
            cv.visitInsn(RETURN);
            cv.visitMaxs(0, 0);
   
            cv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "getNumAttributes", "()I", null, null);
            cv.visitFieldInsn(GETSTATIC, classNameAsSlashes, "NUM_ATTRIBUTES", "I");
            cv.visitInsn(IRETURN);
            cv.visitMaxs(0, 0);
   
            cv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
            cv.visitVarInsn(ALOAD, 0);
            cv.visitMethodInsn(INVOKESPECIAL, BASE_ENTITY_CLASSNAME_SLASHES, "<init>", "()V");
            cv.visitVarInsn(ALOAD, 0);
            cv.visitMethodInsn(INVOKESTATIC, classNameAsSlashes, "getNumAttributes", "()I");
            cv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
            cv.visitFieldInsn(PUTFIELD, classNameAsSlashes, "fields", "[Ljava/lang/Object;");
            cv.visitInsn(RETURN);
            cv.visitMaxs(0, 0);
        }
        cw.visitEnd();
        return cw.toByteArray();
    }
View Full Code Here

         * At some time later in the class' lifecycle, the XRFI
         * static is populated with the required info w.r.t the index for a field
         */
    String classNameAsSlashes = className.replace('.', '/');
    ClassWriter cw = new ClassWriter(true);
    CodeVisitor cv;
    // special-case: build sub-class of XRDynamicEntityCollection
    if (className.endsWith(COLLECTION_WRAPPER_SUFFIX)) {
      cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, classNameAsSlashes,
        XR_DYNAMIC_ENTITY_COLLECTION_CLASSNAME_SLASHES, null, null);
      cv = cw.visitMethod(ACC_PUBLIC, INIT, "()V", null, null);
      cv.visitVarInsn(ALOAD, 0);
      cv.visitMethodInsn(INVOKESPECIAL, XR_DYNAMIC_ENTITY_COLLECTION_CLASSNAME_SLASHES,
          INIT, "()V");
      cv.visitInsn(RETURN);
      cv.visitMaxs(0, 0);
    }
    else {
            cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, classNameAsSlashes,
                XR_DYNAMIC_ENTITY_CLASSNAME_SLASHES, null, null);
            cw.visitField(ACC_PUBLIC + ACC_STATIC, XR_FIELD_INFO_STATIC,
                "L" + XRFIELDINFO_CLASSNAME_SLASHES + ";", null, null);
            cv = cw.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null);
            cv.visitTypeInsn(NEW, XRFIELDINFO_CLASSNAME_SLASHES);
            cv.visitInsn(DUP);
            cv.visitMethodInsn(INVOKESPECIAL, XRFIELDINFO_CLASSNAME_SLASHES, INIT, "()V");
            cv.visitFieldInsn(PUTSTATIC, classNameAsSlashes, XR_FIELD_INFO_STATIC,
                "L" + XRFIELDINFO_CLASSNAME_SLASHES + ";");
            cv.visitInsn(RETURN);
            cv.visitMaxs(0, 0);
            cv = cw.visitMethod(ACC_PUBLIC, INIT, "()V", null, null);
            cv.visitVarInsn(ALOAD, 0);
            cv.visitMethodInsn(INVOKESPECIAL, XR_DYNAMIC_ENTITY_CLASSNAME_SLASHES, INIT, "()V");
            cv.visitInsn(RETURN);
            cv.visitMaxs(0, 0);
            cv = cw.visitMethod(ACC_PUBLIC, "getFieldInfo",
                "()L" + XRFIELDINFO_CLASSNAME_SLASHES + ";", null, null);
            cv.visitFieldInsn(GETSTATIC, classNameAsSlashes, XR_FIELD_INFO_STATIC,
                "L" + XRFIELDINFO_CLASSNAME_SLASHES + ";");
            cv.visitInsn(ARETURN);
            cv.visitMaxs(0, 0);
    }
    cw.visitEnd();
    return cw.toByteArray();
    }
View Full Code Here

        }
        cw.visitField(Constants.ACC_PUBLIC + Constants.ACC_FINAL + Constants.ACC_STATIC, END_PROPERTY_INDEX, "I", endPropertyIndex, null);
    }

    private void addConstructors(ClassWriter cw) {
        CodeVisitor mv = cw.visitMethod(Constants.ACC_PUBLIC, "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[0]), new String[] { Type.getInternalName(Serializable.class) }, null);
        mv.visitVarInsn(Constants.ALOAD, 0);
        mv.visitMethodInsn(Constants.INVOKESPECIAL, Type.getType(parentClass).getInternalName(), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[0]));
        mv.visitInsn(Constants.RETURN);
        mv.visitMaxs(1, 1);
    }
View Full Code Here

        }       
        addPropertyGetMethodInternal(cw, property, outerGetMethodName, returnType);       
    }
   
    private void addPropertyGetMethodInternal(ClassWriter cw, SDOProperty property, String outerGetMethodName, String returnType){
      CodeVisitor mv;
        String propertyInstanceClassDescriptor;
        if(property.isMany()) {
            propertyInstanceClassDescriptor = Type.getDescriptor(List.class);
        } else if(property.getType().isDataType()) {
            propertyInstanceClassDescriptor = Type.getDescriptor(property.getType().getInstanceClass());
        } else {
            propertyInstanceClassDescriptor = "L" + returnType.replace('.', '/') + ";";
        }
        mv = cw.visitMethod(Constants.ACC_PUBLIC, outerGetMethodName, "()" + propertyInstanceClassDescriptor, null, null);

        mv.visitVarInsn(Constants.ALOAD, 0);
        mv.visitIntInsn(Constants.BIPUSH, startPropertyIndex + property.getIndexInType());

        String builtIn = SDOUtil.getBuiltInType(returnType);
        if(null != builtIn) {
            if(property.getType().isDataType() && !builtIn.equals(LIST)) {
                mv.visitMethodInsn(Constants.INVOKEVIRTUAL, typeImplClassDescriptor, GET + builtIn, "(I)" + propertyInstanceClassDescriptor);
                int iReturnOpcode = Type.getType(property.getType().getInstanceClass()).getOpcode(Constants.IRETURN);
                mv.visitInsn(iReturnOpcode);
            } else {
                mv.visitMethodInsn(Constants.INVOKEVIRTUAL,  typeImplClassDescriptor, GET, "(I)Ljava/lang/Object;");                       
                mv.visitInsn(Constants.ARETURN);
            }
        } else {
            mv.visitMethodInsn(Constants.INVOKEVIRTUAL,  typeImplClassDescriptor, GET, "(I)Ljava/lang/Object;");                       
            mv.visitInsn(Constants.ARETURN);
        }
        mv.visitMaxs(2, 1);
    }
View Full Code Here

    private void addPropertySetMethod(ClassWriter cw, SDOProperty property) {
        String returnType = SDOUtil.getJavaTypeForProperty(property);
        String outerSetMethodName = SDOUtil.setMethodName(property.getName());

        CodeVisitor mv;
        String propertyInstanceClassDescriptor;

        if(property.isMany()) {
            propertyInstanceClassDescriptor = Type.getDescriptor(List.class);
        } else if(property.getType().isDataType()) {
            propertyInstanceClassDescriptor = Type.getDescriptor(property.getType().getInstanceClass());
        } else {
            propertyInstanceClassDescriptor = "L" + returnType.replace('.', '/') + ";";
        }
        mv = cw.visitMethod(Constants.ACC_PUBLIC, outerSetMethodName, "(" + propertyInstanceClassDescriptor + ")V", null, null);

        mv.visitVarInsn(Constants.ALOAD, 0);
        mv.visitIntInsn(Constants.BIPUSH, startPropertyIndex + property.getIndexInType());

        String builtIn = SDOUtil.getBuiltInType(returnType);
        int iLoadOpcode = Constants.ALOAD;
        if(null != builtIn) {
            if(property.getType().isDataType() && !builtIn.equals(LIST)) {
                iLoadOpcode = Type.getType(property.getType().getInstanceClass()).getOpcode(Constants.ILOAD);
                mv.visitVarInsn(iLoadOpcode, 1);
                mv.visitMethodInsn(Constants.INVOKEVIRTUAL, typeImplClassDescriptor, SET + builtIn, "(I" + propertyInstanceClassDescriptor + ")V");
            } else {
                mv.visitVarInsn(iLoadOpcode, 1);
                mv.visitMethodInsn(Constants.INVOKEVIRTUAL,  typeImplClassDescriptor, SET, "(ILjava/lang/Object;)V");                       
            }
        } else {
            mv.visitVarInsn(iLoadOpcode, 1);
            mv.visitMethodInsn(Constants.INVOKEVIRTUAL,  typeImplClassDescriptor, SET, "(ILjava/lang/Object;)V");                       
        }

        mv.visitInsn(Constants.RETURN);
        if(iLoadOpcode == Constants.DLOAD || iLoadOpcode == Constants.LLOAD) {
            mv.visitMaxs(4, 3);
        } else {
            mv.visitMaxs(3, 2);
        }
    }
View Full Code Here

            method = parentClass.getDeclaredMethod(WRITE_REPLACE, new Class[0]);
        } catch (NoSuchMethodException e) {
            return;
        }

        CodeVisitor mv = cw.visitMethod(Constants.ACC_PROTECTED, method.getName(), Type.getMethodDescriptor(method), new String[] { Type.getInternalName(ObjectStreamException.class) }, null);

        mv.visitVarInsn(Constants.ALOAD, 0);
        mv.visitMethodInsn(Constants.INVOKESPECIAL, Type.getInternalName(parentClass), method.getName(), Type.getMethodDescriptor(method));
        mv.visitInsn(Constants.ARETURN);
        mv.visitMaxs(1, 1);
    }
View Full Code Here

        String internalValueName = valueClass.getQualifiedName().replace('.', '/');
       
        Type mapType = Type.getType("L" + mapClass.getRawName().replace('.', '/') + ";");

        ClassWriter cw = new ClassWriter(false);
        CodeVisitor cv;

        cw.visit(Constants.V1_5, Constants.ACC_PUBLIC + Constants.ACC_SUPER, qualifiedInternalClassName, "org/eclipse/persistence/internal/jaxb/many/MapValue", null, "StringEmployeeMap.java");

        // FIELD ATTRIBUTES      
        RuntimeVisibleAnnotations fieldAttrs1 = new RuntimeVisibleAnnotations();

        if (typeMappingInfo != null) {
            java.lang.annotation.Annotation[] annotations = typeMappingInfo.getAnnotations();
            if (annotations != null) {
                for (int i = 0; i < annotations.length; i++) {
                    java.lang.annotation.Annotation nextAnnotation = annotations[i];
                    if (nextAnnotation != null && !(nextAnnotation instanceof XmlElement) && !(nextAnnotation instanceof XmlJavaTypeAdapter)) {                   
                        String annotationClassName = nextAnnotation.annotationType().getName();
                        Annotation fieldAttrs1ann0 = new Annotation("L" + annotationClassName.replace('.', '/') + ";");
                        fieldAttrs1.annotations.add(fieldAttrs1ann0);
                        for(Method next:nextAnnotation.annotationType().getDeclaredMethods()) {
                            try {
                                Object nextValue = next.invoke(nextAnnotation, new Object[]{});
                                if(nextValue instanceof Class) {
                                    Type nextType = Type.getType("L" + ((Class)nextValue).getName().replace('.', '/') + ";");
                                    nextValue = nextType;
                                }
                                fieldAttrs1ann0.add(next.getName(), nextValue);
                            } catch(InvocationTargetException ex) {
                                //ignore the invocation target exception here.
                            } catch(IllegalAccessException ex) {
                               
                            }
                        }
                    }
                }
            }
        }
        // FIELD ATTRIBUTES
        SignatureAttribute fieldAttrs2 = new SignatureAttribute("L" + mapType.getInternalName() + "<L" + internalKeyName + ";L" + internalValueName + ";>;");
        fieldAttrs1.next = fieldAttrs2;
        cw.visitField(Constants.ACC_PUBLIC, "entry", "L" + mapType.getInternalName() + ";", null, fieldAttrs1);

        cv = cw.visitMethod(Constants.ACC_PUBLIC, "<init>", "()V", null, null);
        cv.visitVarInsn(Constants.ALOAD, 0);
        cv.visitMethodInsn(Constants.INVOKESPECIAL, "org/eclipse/persistence/internal/jaxb/many/MapValue", "<init>", "()V");
        cv.visitInsn(Constants.RETURN);
        cv.visitMaxs(1, 1);

        // METHOD ATTRIBUTES
        RuntimeVisibleAnnotations methodAttrs1 = new RuntimeVisibleAnnotations();

        Annotation methodAttrs1ann0 = new Annotation("Ljavax/xml/bind/annotation/XmlTransient;");
        methodAttrs1.annotations.add(methodAttrs1ann0);

        SignatureAttribute methodAttrs2 = new SignatureAttribute("(L" + mapType.getInternalName() + "<L" + internalKeyName + ";L" + internalValueName + ";>;)V");
        methodAttrs1.next = methodAttrs2;
        cv = cw.visitMethod(Constants.ACC_PUBLIC, "setItem", "(L" + mapType.getInternalName() + ";)V", null, methodAttrs1);
        Label l0 = new Label();
        cv.visitLabel(l0);
        cv.visitVarInsn(Constants.ALOAD, 0);
        cv.visitVarInsn(Constants.ALOAD, 1);
        cv.visitFieldInsn(Constants.PUTFIELD, qualifiedInternalClassName, "entry", "L" + mapType.getInternalName() + ";");
        cv.visitInsn(Constants.RETURN);
        Label l1 = new Label();
        cv.visitLabel(l1);
        // CODE ATTRIBUTE

        LocalVariableTypeTableAttribute cvAttr = new LocalVariableTypeTableAttribute();
        cv.visitAttribute(cvAttr);

        cv.visitMaxs(2, 2);

        // METHOD ATTRIBUTES
        methodAttrs1 = new RuntimeVisibleAnnotations();

        methodAttrs1ann0 = new Annotation("Ljavax/xml/bind/annotation/XmlTransient;");
        methodAttrs1.annotations.add(methodAttrs1ann0);

        methodAttrs2 = new SignatureAttribute("()L" + mapType.getInternalName() + "<L" + internalKeyName + ";L" + internalValueName + ";>;");
        methodAttrs1.next = methodAttrs2;
        cv = cw.visitMethod(Constants.ACC_PUBLIC, "getItem", "()L" + mapType.getInternalName() + ";", null, methodAttrs1);
        cv.visitVarInsn(Constants.ALOAD, 0);
        cv.visitFieldInsn(Constants.GETFIELD, qualifiedInternalClassName, "entry", "L" + mapType.getInternalName() + ";");
        cv.visitInsn(Constants.ARETURN);
        cv.visitMaxs(1, 1);

        cv = cw.visitMethod(Constants.ACC_PUBLIC + Constants.ACC_BRIDGE + Constants.ACC_SYNTHETIC, "getItem", "()Ljava/lang/Object;", null, null);
        cv.visitVarInsn(Constants.ALOAD, 0);
        cv.visitMethodInsn(Constants.INVOKEVIRTUAL, qualifiedInternalClassName, "getItem", "()L" + mapType.getInternalName() + ";");
        cv.visitInsn(Constants.ARETURN);
        cv.visitMaxs(1, 1);

        cv = cw.visitMethod(Constants.ACC_PUBLIC + Constants.ACC_BRIDGE + Constants.ACC_SYNTHETIC, "setItem", "(Ljava/lang/Object;)V", null, null);
        cv.visitVarInsn(Constants.ALOAD, 0);
        cv.visitVarInsn(Constants.ALOAD, 1);
        cv.visitTypeInsn(Constants.CHECKCAST, mapType.getInternalName());
        cv.visitMethodInsn(Constants.INVOKEVIRTUAL, qualifiedInternalClassName, "setItem", "(L" + mapType.getInternalName() + ";)V");
        cv.visitInsn(Constants.RETURN);
        cv.visitMaxs(2, 2);

        // CLASS ATTRIBUTE
        RuntimeVisibleAnnotations annotationsAttr = new RuntimeVisibleAnnotations();
       
        Annotation attrann0 = new Annotation("Ljavax/xml/bind/annotation/XmlType;");
View Full Code Here

        for (int index = 0; index < constructor.getParameterTypes().length; index++) {
            types[index] = Type.getType(constructor.getParameterTypes()[index]);
        }

        String consDesc = Type.getMethodDescriptor(Type.VOID_TYPE, types);
        CodeVisitor mv = cw.visitMethod(ACC_PUBLIC, INIT, consDesc, null, null);
        mv.visitVarInsn(ALOAD, 0);

        for (int param = 1; param <= constructor.getParameterTypes().length; param++) {
            mv.visitVarInsn(ALOAD, param);
        }

        mv.visitMethodInsn(INVOKESPECIAL, Type.getType(constructor.getDeclaringClass()).getInternalName(), INIT, consDesc);
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
    }
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.internal.libraries.asm.CodeVisitor

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.