Package org.objectweb.asm

Examples of org.objectweb.asm.AnnotationVisitor


        verify(annotationVisitor).visitEnum("withDefaultOverridden", desc, "IN");
    }

    public void testArrayValuesPlayback() throws Exception {

        AnnotationVisitor arrayOfString = mock(AnnotationVisitor.class);
        AnnotationVisitor arrayOfEnum = mock(AnnotationVisitor.class);
        AnnotationVisitor arrayOfClass = mock(AnnotationVisitor.class);
        AnnotationVisitor arrayOfAnnotation = mock(AnnotationVisitor.class);
        AnnotationVisitor emptyArray = mock(AnnotationVisitor.class);

        when(visitor.visitAnnotation(anyString(), anyBoolean())).thenReturn(annotationVisitor);
        when(annotationVisitor.visitArray("arrayOfString")).thenReturn(arrayOfString);
        when(annotationVisitor.visitArray("arrayOfEnum")).thenReturn(arrayOfEnum);
        when(annotationVisitor.visitArray("arrayOfClass")).thenReturn(arrayOfClass);


    public void testVisitAnnotationRecord() throws Exception {

        when(visitor.visitAnnotation("name", "type-desc")).thenReturn(visitor);

        AnnotationRecorder recorder = new AnnotationRecorder();
        AnnotationVisitor sub = recorder.visitAnnotation("name", "type-desc");
        sub.visit("name2", "value2");
        recorder.accept(visitor);

        verify(visitor).visitAnnotation("name", "type-desc");
        verify(visitor).visit("name2", "value2");
    }

    public void testVisitArrayRecord() throws Exception {

        when(visitor.visitArray("name")).thenReturn(visitor);

        AnnotationRecorder recorder = new AnnotationRecorder();
        AnnotationVisitor sub = recorder.visitArray("name");
        sub.visit("name2", "value2");
        recorder.accept(visitor);

        verify(visitor).visitArray("name");
        verify(visitor).visit("name2", "value2");
    }

  }

  private void add_module_annotation(ClassVisitor cv) {

    AnnotationVisitor av = cv.visitAnnotation(
        MODULE_ANN_TYPE.getDescriptor(), true);
    av.visit("value", getModuleName());

    av.visitEnd();
  }

      ExtFun f = ent.getValue();

      FieldVisitor fv = cv.visitField(ACC_STATIC, ent.getKey(), "L"
          + EFUN_NAME + f.arity + ";", null, null);
      EFunCG.ensure(f.arity);
      AnnotationVisitor av = fv.visitAnnotation(
          IMPORT_ANN_TYPE.getDescriptor(), true);
      av.visit("module", f.mod.getName());
      av.visit("fun", f.fun.getName());
      av.visit("arity", f.arity);
      av.visitEnd();
      fv.visitEnd();
    }
   
    generate_on_load();

      mv.visitMaxs(20, scratch_reg + 3);

      // mark this function to be called "on load"
      if (funInfo.call_on_load) {
        AnnotationVisitor an = mv.visitAnnotation(
            ONLOAD_ANN_TYPE.getDescriptor(), true);
        an.visitEnd();
      }

      mv.visitEnd();

      int arity_plus = arity;
      Lambda lambda = get_lambda_freevars(fun_name, arity_plus);
      final int freevars = lambda == null ? 0 : lambda.freevars;

      int real_arity = arity_plus - freevars;

      String mname = EUtil.getJavaName(fun_name, real_arity);
      String outer_name = self_type.getInternalName();
      String inner_name = "FN_" + mname;
      String full_inner_name = outer_name + "$" + inner_name;

      boolean make_fun = false;
      boolean is_exported = isExported(fun_name, arity);
      if (lambda != null) {
        CompilerVisitor.this.module_md5 = lambda.uniq;
        make_fun = true;
      } else {

        String fun_type;
        if (uses_on_load) {
          fun_type = EFUN_NAME + arity;
        } else {
          fun_type = full_inner_name;
        }
       
        if (!Boolean.getBoolean("erjang.inline_calls")
            && funInfo.is_called_locally_in_nontail_position)
          generate_invoke_call_self();

        if (funInfo.is_called_locally_in_tail_position)
          generate_tail_call_self(fun_type);

        if (funInfo.mustHaveFun() || uses_on_load) {
          FieldVisitor fv = cv.visitField(ACC_STATIC | (uses_on_load ? 0 : ACC_FINAL),
              mname, "L" + fun_type + ";", null, null);
          EFunCG.ensure(arity);

          if (is_exported) {
            if (ModuleAnalyzer.log.isLoggable(Level.FINE))
              ModuleAnalyzer.log.fine("export " + module_name
                  + ":" + fun_name + "/" + arity);
            AnnotationVisitor an = fv.visitAnnotation(
                EXPORT_ANN_TYPE.getDescriptor(), true);
            an.visit("module", module_name.getName());
            an.visit("fun", fun_name.getName());
            an.visit("arity", new Integer(arity));
            an.visitEnd();
          } else if (uses_on_load) {
            AnnotationVisitor an = fv.visitAnnotation(
                INTERNAL_ANN_TYPE.getDescriptor(), true);
            an.visit("module", module_name.getName());
            an.visit("fun", fun_name.getName());
            an.visit("arity", new Integer(arity));
            an.visitEnd();
          }

          fv.visitEnd();

          funs.put(mname, full_inner_name);

        }
        String classFileName = periodToSlashes(className);
        cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, classFileName, null,
                 "java/lang/Object", null);

        AnnotationVisitor av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlRootElement;", true);
        av0.visit("name", wrapperElement.getLocalPart());
        av0.visit("namespace", wrapperElement.getNamespaceURI());
        av0.visitEnd();

        av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlAccessorType;", true);
        av0.visitEnum("value", "Ljavax/xml/bind/annotation/XmlAccessType;", "FIELD");
        av0.visitEnd();

        av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlType;", true);
        if (!anonymous) {
            av0.visit("name", wrapperElement.getLocalPart());
            av0.visit("namespace", wrapperElement.getNamespaceURI());
        } else {
            av0.visit("name", "");           
        }
        av0.visitEnd();

        // add constructor
        MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        Label lbegin = new Label();

        boolean q = qualified;
        SchemaInfo si = interfaceInfo.getService().getSchema(ns);
        if (si != null) {
            q = si.isElementFormQualified();
        }
        AnnotationVisitor av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlSchema;", true);
        av0.visit("namespace", ns);
        av0.visitEnum("elementFormDefault",
                      getClassCode(XmlNsForm.class),
                      q ? "QUALIFIED" : "UNQUALIFIED");
        av0.visitEnd();
        cw.visitEnd();

        loadClass(className, clz, cw.toByteArray());
    }

                                        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();

        mv.visitEnd();

    }
    
    private void addJAXBAnnotations(FieldVisitor fv, List<Annotation> jaxbAnnos) {
        AnnotationVisitor av0;
        for (Annotation ann : jaxbAnnos) {
            if (ann instanceof XmlMimeType) {
                av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlMimeType;", true);
                av0.visit("value", ((XmlMimeType)ann).value());
                av0.visitEnd();
            } else if (ann instanceof XmlJavaTypeAdapter) {
                av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/adapters/XmlJavaTypeAdapter;", true);
                XmlJavaTypeAdapter adapter = (XmlJavaTypeAdapter)ann;
                if (adapter.value() != null) {
                    av0.visit("value", org.objectweb.asm.Type.getType(getClassCode(adapter.value())));
                }
                if (adapter.type() != javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter.DEFAULT.class) {
                    av0.visit("type", org.objectweb.asm.Type.getType(getClassCode(adapter.type())));
                }
                av0.visitEnd();
            } else if (ann instanceof XmlAttachmentRef) {
                av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlAttachmentRef;", true);
                av0.visitEnd();
            } else if (ann instanceof XmlList) {
                av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlList;", true);
                av0.visitEnd();
            }
        }
    }

TOP

Related Classes of org.objectweb.asm.AnnotationVisitor

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.