Search in sources :

Example 11 with Label

use of org.eclipse.persistence.internal.libraries.asm.Label in project eclipselink by eclipse-ee4j.

the class CollectionProxyClassWriter method writeClass.

/**
 *  public class Proxy extends SuperType implements CollectionProxy {
 *      private List<LinkV2> links;
 *
 *      public CollectionProxy(Collection c) {
 *          super();
 *          this.addAll(c);
 *      }
 *
 *      @Override
 *      public List<LinkV2> getLinks() {
 *          return links;
 *      }
 *
 *      @Override
 *      public void setLinks(List<LinkV2> links) {
 *          this.links = links;
 *      }
 *  }
 */
@Override
public byte[] writeClass(DynamicClassLoader loader, String className) {
    final EclipseLinkASMClassWriter cw = new EclipseLinkASMClassWriter(0);
    MethodVisitor mv;
    // public class Proxy extends SuperType implements CollectionProxy
    cw.visit(ACC_PUBLIC + ACC_SUPER, getASMClassName(), null, getASMParentClassName(), new String[] { INTERFACE });
    // private List<LinkV2> links;
    final FieldVisitor fv = cw.visitField(ACC_PRIVATE, "links", "Ljava/util/List;", "Ljava/util/List<Lorg/eclipse/persistence/internal/jpa/rs/metadata/model/LinkV2;>;", null);
    fv.visitEnd();
    // public CollectionProxy(Collection c) {
    // super();
    // this.addAll(c);
    // }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "(Ljava/util/Collection;)V", null, null);
        mv.visitCode();
        Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(15, l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, getASMParentClassName(), "<init>", "()V", false);
        Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLineNumber(16, l1);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKEVIRTUAL, getASMClassName(), "addAll", "(Ljava/util/Collection;)Z", false);
        mv.visitInsn(POP);
        Label l2 = new Label();
        mv.visitLabel(l2);
        mv.visitLineNumber(17, l2);
        mv.visitInsn(RETURN);
        Label l3 = new Label();
        mv.visitLabel(l3);
        mv.visitLocalVariable("this", "L" + getASMClassName() + ";", null, l0, l3, 0);
        mv.visitLocalVariable("c", "Ljava/util/Collection;", null, l0, l3, 1);
        mv.visitMaxs(2, 2);
        mv.visitEnd();
    }
    // @Override
    // public List<LinkV2> getLinks() {
    // return links;
    // }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "getLinks", "()Ljava/util/List;", "()Ljava/util/List<Lorg/eclipse/persistence/internal/jpa/rs/metadata/model/LinkV2;>;", null);
        mv.visitCode();
        Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(21, l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, getASMClassName(), "links", "Ljava/util/List;");
        mv.visitInsn(ARETURN);
        Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLocalVariable("this", "L" + getASMClassName() + ";", null, l0, l1, 0);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
    }
    // @Override
    // public void setLinks(List<LinkV2> links) {
    // this.links = links;
    // }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "setLinks", "(Ljava/util/List;)V", "(Ljava/util/List<Lorg/eclipse/persistence/internal/jpa/rs/metadata/model/LinkV2;>;)V", null);
        mv.visitCode();
        Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(26, l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitFieldInsn(PUTFIELD, getASMClassName(), "links", "Ljava/util/List;");
        Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLineNumber(27, l1);
        mv.visitInsn(RETURN);
        Label l2 = new Label();
        mv.visitLabel(l2);
        mv.visitLocalVariable("this", "L" + getASMClassName() + ";", null, l0, l2, 0);
        mv.visitLocalVariable("links", "Ljava/util/List;", "Ljava/util/List<Lorg/eclipse/persistence/internal/jpa/rs/metadata/model/LinkV2;>;", l0, l2, 1);
        mv.visitMaxs(2, 2);
        mv.visitEnd();
    }
    return cw.toByteArray();
}
Also used : Label(org.eclipse.persistence.internal.libraries.asm.Label) EclipseLinkASMClassWriter(org.eclipse.persistence.internal.libraries.asm.EclipseLinkASMClassWriter) FieldVisitor(org.eclipse.persistence.internal.libraries.asm.FieldVisitor) MethodVisitor(org.eclipse.persistence.internal.libraries.asm.MethodVisitor)

Aggregations

Label (org.eclipse.persistence.internal.libraries.asm.Label)11 MethodVisitor (org.eclipse.persistence.internal.libraries.asm.MethodVisitor)10 XmlElement (jakarta.xml.bind.annotation.XmlElement)2 XmlJavaTypeAdapter (jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter)2 Annotation (java.lang.annotation.Annotation)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 AnnotationVisitor (org.eclipse.persistence.internal.libraries.asm.AnnotationVisitor)2 EclipseLinkASMClassWriter (org.eclipse.persistence.internal.libraries.asm.EclipseLinkASMClassWriter)2 FieldVisitor (org.eclipse.persistence.internal.libraries.asm.FieldVisitor)2 Type (org.eclipse.persistence.internal.libraries.asm.Type)2 JavaAnnotation (org.eclipse.persistence.jaxb.javamodel.JavaAnnotation)2 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)2 JavaMethod (org.eclipse.persistence.jaxb.javamodel.JavaMethod)2 XmlAccessorType (jakarta.xml.bind.annotation.XmlAccessorType)1 XmlList (jakarta.xml.bind.annotation.XmlList)1 XmlMimeType (jakarta.xml.bind.annotation.XmlMimeType)1 XmlSchemaType (jakarta.xml.bind.annotation.XmlSchemaType)1 XmlType (jakarta.xml.bind.annotation.XmlType)1 ParameterizedType (java.lang.reflect.ParameterizedType)1