Package javassist.bytecode

Examples of javassist.bytecode.AnnotationsAttribute


      cf.setVersionToJava5();
      cf.setInterfaces(new String[]{WebAppBootstrap.class.getName()});

      // add @Generated
      ConstPool cp = cf.getConstPool();
      AnnotationsAttribute attr = new AnnotationsAttribute(cp, AnnotationsAttribute.visibleTag);
      attr.setAnnotation(new Annotation(Generated.class.getName(), cp));
      cf.addAttribute(attr);

      // write the file
      cf.write(new DataOutputStream(new FileOutputStream(filename)));
View Full Code Here


    private Object[] getAnnotations(boolean ignoreNotFound)
        throws ClassNotFoundException
    {
        ClassFile cf = getClassFile2();
        AnnotationsAttribute ainfo = (AnnotationsAttribute)
                cf.getAttribute(AnnotationsAttribute.invisibleTag)
        AnnotationsAttribute ainfo2 = (AnnotationsAttribute)
                cf.getAttribute(AnnotationsAttribute.visibleTag)
        return toAnnotationType(ignoreNotFound, getClassPool(), ainfo, ainfo2);
    }
View Full Code Here

    }

    protected void scanClass(ClassFile cf)
    {
        String className = cf.getName();
        AnnotationsAttribute visible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.visibleTag);
        AnnotationsAttribute invisible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.invisibleTag);

        if (visible != null)
        {
            populate(visible.getAnnotations(), className);
        }

        if (invisible != null)
        {
            populate(invisible.getAnnotations(), className);
        }
    }
View Full Code Here

        for (Object obj : methods)
        {
            MethodInfo method = (MethodInfo) obj;
            if (scanMethodAnnotations)
            {
                AnnotationsAttribute visible = (AnnotationsAttribute) method.getAttribute(AnnotationsAttribute.visibleTag);
                AnnotationsAttribute invisible = (AnnotationsAttribute) method.getAttribute(AnnotationsAttribute.invisibleTag);

                if (visible != null)
                {
                    populate(visible.getAnnotations(), cf.getName());
                }
                if (invisible != null)
                {
                    populate(invisible.getAnnotations(), cf.getName());
                }
            }
            if (scanParameterAnnotations)
            {
                ParameterAnnotationsAttribute paramsVisible = (ParameterAnnotationsAttribute) method.getAttribute(ParameterAnnotationsAttribute.visibleTag);
View Full Code Here

        }

        for (Object obj : fields)
        {
            FieldInfo field = (FieldInfo) obj;
            AnnotationsAttribute visible = (AnnotationsAttribute) field.getAttribute(AnnotationsAttribute.visibleTag);
            AnnotationsAttribute invisible = (AnnotationsAttribute) field.getAttribute(AnnotationsAttribute.invisibleTag);

            if (visible != null)
            {
                populate(visible.getAnnotations(), cf.getName());
            }
            if (invisible != null)
            {
                populate(invisible.getAnnotations(), cf.getName());
            }
        }


    }
View Full Code Here

  private boolean isAnnotatedWithCustomRunner(CtClass classReference) {
    return isAnnotatedWithGivenAnnotation(classReference, RunWith.class);
  }

  private boolean isAnnotatedWithGivenAnnotation(CtClass classReference, Class<?> givenAnnotation) {
    AnnotationsAttribute annotations = getAnnotationsOfType(visibleTag, classReference);
    if (annotations != null) {
      for (Annotation annotation : annotations.getAnnotations()) {
        if (annotation.getTypeName().equals(givenAnnotation.getName())) {
          return true;
        }
      }
    }
View Full Code Here

  private boolean isTestNGTestMethod(CtMethod ctMethod) {
    MethodInfo methodInfo = ctMethod.getMethodInfo2();
    List<?> attributes = methodInfo.getAttributes();
    for (Object attribute : attributes) {
      if (attribute instanceof AnnotationsAttribute) {
        AnnotationsAttribute annotations = (AnnotationsAttribute) attribute;
        for (Annotation each : annotations.getAnnotations()) {
          if (org.testng.annotations.Test.class.getName().equals(each.getTypeName())) {
            return true;
          }
        }
      }
View Full Code Here

  private boolean isJUnit4TestMethod(CtMethod ctMethod) {
    MethodInfo methodInfo = ctMethod.getMethodInfo2();
    List<?> attributes = methodInfo.getAttributes();
    for (Object attribute : attributes) {
      if (attribute instanceof AnnotationsAttribute) {
        AnnotationsAttribute annotations = (AnnotationsAttribute) attribute;
        for (Annotation each : annotations.getAnnotations()) {
          if (Test.class.getName().equals(each.getTypeName())) {
            return true;
          }
        }
      }
View Full Code Here

   
    ClassFile ccFile = cc.getClassFile();
    ConstPool constpool = ccFile.getConstPool();
    // 1.2.1] Create an annotation for the class
   
    AnnotationsAttribute attrClass = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag);
   
    // 1.2.1.1] Entity
    Annotation annotEntity = new Annotation("javax.persistence.Entity", constpool);
    attrClass.addAnnotation(annotEntity);
   
    // 1.2.1.2] Table info
    Annotation annotTable = new Annotation("javax.persistence.Table", constpool);
    annotTable.addMemberValue("name", new StringMemberValue("TEST_CLASS", ccFile.getConstPool()));
    annotTable.addMemberValue("schema", new StringMemberValue("KunderaTest@mongoPU", ccFile.getConstPool()));   
    attrClass.addAnnotation(annotTable);
   
    // 1.2.1.3] Attach the annotation to the class
   
    ccFile.addAttribute(attrClass);
   
    // 1.2.2] Create an annotation for the field    
   
    // 1.2.2.1] Annotation Id
    AnnotationsAttribute attrIdField = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag);
   
    Annotation annotId = new Annotation("javax.persistence.Id", constpool);
    attrIdField.addAnnotation(annotId);
    idField.getFieldInfo().addAttribute(attrIdField);
   
    // 1.2.2.2] Annotation Column (name="testField")
    AnnotationsAttribute attrTestField = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag);
   
    Annotation annotCol = new Annotation("javax.persistence.Column", constpool);
    annotCol.addMemberValue("name", new StringMemberValue("TEST_FIELD", ccFile.getConstPool()));
    attrTestField.addAnnotation(annotCol);
    testField.getFieldInfo().addAttribute(attrTestField);
   
    if (null != testField2) {
      AnnotationsAttribute attrTestField2 = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag);
     
      Annotation annotCol2 = new Annotation("javax.persistence.Column", constpool);
      annotCol.addMemberValue("name", new StringMemberValue("TEST_FIELD2", ccFile.getConstPool()));
      attrTestField2.addAnnotation(annotCol2);
      testField2.getFieldInfo().addAttribute(attrTestField2);
    }
   
    // 1.3] Add methods
View Full Code Here

                    List<Boolean> renames = new ArrayList<Boolean>();
                    check: {
                        while(itr.hasNext()) {
                            Object object = itr.next();
                            if (AnnotationsAttribute.class.isAssignableFrom(object.getClass())) {
                                AnnotationsAttribute attr = (AnnotationsAttribute) object;
                                Annotation[] items = attr.getAnnotations();
                                for (Annotation annotation : items) {
                                    String typeName = annotation.getTypeName();
                                    if (typeName.equals(DirectCopyTransform.class.getName())) {
                                        ArrayMemberValue arrayMember = (ArrayMemberValue) annotation.getMemberValue("value");
                                        for (MemberValue arrayMemberValue : arrayMember.getValue()) {
View Full Code Here

TOP

Related Classes of javassist.bytecode.AnnotationsAttribute

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.