Package javassist.bytecode.annotation

Examples of javassist.bytecode.annotation.Annotation


      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)));
    } catch (Exception e) {
View Full Code Here


/* 529 */       this.allAnno = array;
/* 530 */       return pos;
/*     */     }
/*     */
/*     */     int annotation(int pos, int type, int numPairs) throws Exception {
/* 534 */       this.currentAnno = new Annotation(type, this.pool);
/* 535 */       return super.annotation(pos, type, numPairs);
/*     */     }
View Full Code Here

/* 592 */       this.currentMember = new ClassMemberValue(index, this.pool);
/* 593 */       super.classMemberValue(index);
/*     */     }
/*     */
/*     */     int annotationMemberValue(int pos) throws Exception {
/* 597 */       Annotation anno = this.currentAnno;
/* 598 */       pos = super.annotationMemberValue(pos);
/* 599 */       this.currentMember = new AnnotationMemberValue(this.currentAnno, this.pool);
/* 600 */       this.currentAnno = anno;
/* 601 */       return pos;
/*     */     }
View Full Code Here

        ConstPool cp = theClass.getClassFile().getConstPool();
        AnnotationsAttribute attr = new AnnotationsAttribute(cp, AnnotationsAttribute.visibleTag);

        for (Object obj : annotationsAttribute.getAnnotations()) {

          Annotation a = (Annotation) obj;

          Annotation theAnnotation = new Annotation(a.getTypeName(), cp);

          if (a.getMemberNames() != null) {
            for (Object aName : a.getMemberNames()) {
              theAnnotation.addMemberValue(aName.toString(), a.getMemberValue(aName.toString()));
            }
          }

          attr.setAnnotation(theAnnotation);
        }
View Full Code Here

            String idType = play.modules.morphia.utils.IdGenerator.getIdTypeName();
            CtField idField = new CtField(classPool.get(idType), "_id", ctClass);
            idField.setModifiers(Modifier.PRIVATE);
            AnnotationsAttribute aa = new AnnotationsAttribute(ctClass.getClassFile().getConstPool(),
                    AnnotationsAttribute.visibleTag);
            Annotation idAnn = new Annotation(Id.class.getName(), ctClass.getClassFile().getConstPool());
            aa.addAnnotation(idAnn);
            idField.getFieldInfo().addAttribute(aa);
            ctClass.addField(idField);
            Logger.trace("ID field added to entity[%2$s]: %1$s", idField.getSignature(), ctClass.getName());
            // id()
            CtMethod getId = CtMethod.make("public Object getId() { return _id;}", ctClass);
            ctClass.addMethod(getId);
            // setId
            CtMethod setId = CtMethod.make("protected void setId_(Object id) { _id = (" + idType + ")play.modules.morphia.utils.IdGenerator.processId(id);}", ctClass);
            ctClass.addMethod(setId);
        } else {
            Logger.trace("adding id methods to user defined id entity: %1$s", ctClass.getName());
            // a general id() method for user marked Id field
            boolean hasGetId = false;
            for (CtMethod cm: ctClass.getDeclaredMethods()) {
                if ("getId".equals(cm.getName()) && cm.getDeclaringClass().equals(ctClass)) {
                    // user has defined getId already
                    hasGetId = true;
                    break;
                }
            }
            if (!hasGetId) {
                CtMethod getId = CtMethod.make("public Object getId() { return mf.keyValue(this);}", ctClass);
                ctClass.addMethod(getId);
            }
            // setId - for user marked Id entity, setId method needs to be override

            CtMethod isUserDefinedId = CtMethod.make("protected boolean isUserDefinedId_() {return super.isUserDefinedId_();}", ctClass);
            ctClass.addMethod(isUserDefinedId);
        }

        // create timestamp?
        if (autoTS) {
            ClassFile classFile = ctClass.getClassFile();
            ConstPool cp = classFile.getConstPool();
            AnnotationsAttribute attribute = new AnnotationsAttribute(cp, AnnotationsAttribute.visibleTag);
            Annotation indexAnnotation = new Annotation(cp, ClassPool.getDefault().get("com.google.code.morphia.annotations.Indexed"));
            EnumMemberValue val = new EnumMemberValue(cp);
            val.setType(IndexDirection.class.getName());
            val.setValue(IndexDirection.DESC.name());
            indexAnnotation.addMemberValue("value", val);
            attribute.addAnnotation(indexAnnotation);

          Logger.trace("create timestamp fields automatically");
          CtField createdField = new CtField(CtClass.longType, "_created", ctClass);
          createdField.getFieldInfo().addAttribute(attribute);
          createdField.setModifiers(Modifier.PRIVATE);
          ctClass.addField(createdField);

          CtField modifiedField = new CtField(CtClass.longType, "_modified", ctClass);
          modifiedField.getFieldInfo().addAttribute(attribute);
          modifiedField.setModifiers(Modifier.PRIVATE);
          ctClass.addField(modifiedField);

          CtMethod persistTs = CtMethod.make("void _updateTimestamp() { long now = System.currentTimeMillis(); if (0 == _created) {_created = now;} ;_modified = now;}", ctClass);
            AnnotationsAttribute aa = new AnnotationsAttribute(ctClass.getClassFile().getConstPool(),
                    AnnotationsAttribute.visibleTag);
            Annotation prePersistAnn = new Annotation(PrePersist.class.getName(), ctClass.getClassFile().getConstPool());
            aa.addAnnotation(prePersistAnn);
            persistTs.getMethodInfo().addAttribute(aa);
            ctClass.addMethod(persistTs);

            CtMethod getCreated = CtMethod.make("public long _getCreated() { return _created; }", ctClass);
View Full Code Here

            }

            if (Modifier.isStatic(cf.getModifiers())) continue;
            AnnotationsAttribute attr = getAnnotations(cf);
            Annotation[] aa = attr.getAnnotations();
            Annotation colA = null;
            Annotation propA = null;
            for (Annotation a: aa) {
                if (a.getTypeName().equals(Column.class.getName())) {
                    colA = a;
                } else if (a.getTypeName().equals(Property.class.getName())) {
                    propA = a;
                }
            }
            if (null == propA && null != colA) {
                MemberValue value = colA.getMemberValue("value");
                MemberValue concreteClass = colA.getMemberValue("concreteClass");
                if (null == value && null == concreteClass) continue;
                propA = new Annotation(Property.class.getName(), ctClass.getClassFile().getConstPool());
                if (null != value) propA.addMemberValue("value", value);
                if (null != concreteClass) propA.addMemberValue("concreteClass", concreteClass);
                attr.addAnnotation(propA);
            }
        }
        return blobs;
    }
View Full Code Here

  
   public void visitAnnotationMemberValue(AnnotationMemberValue node)
   {
      try
      {
         Annotation ann = node.getValue();
         value = AnnotationProxy.createProxy(ann);
      }
      catch (Exception e)
      {
         throw new RuntimeException(e);
View Full Code Here

            if ( !(attributeInfo instanceof AnnotationsAttribute)) {
                return;
            }
            AnnotationsAttribute annotationAttribute = (AnnotationsAttribute)attributeInfo;
            for (int i = 0; i < annotationAttribute.getAnnotations().length; i++) {
                Annotation annotation = annotationAttribute.getAnnotations()[i];
                // TODO: stuff is hard coded here - dump it with AW 2.0
                // TODO: when Javassist support primitive type array, then do not use BASE64
                if (annotation.getTypeName().equals(CUSTOM_ATTRIBUTE_CLASSNAME)) {
                    String value = ((StringMemberValue)annotation.getMemberValue(VALUE)).getValue();
                    byte[] bytes = Base64.decode(value);
                    listToPutAttributesIn.add(CustomAttributeHelper.extractCustomAnnotation(bytes));
                }
            }
        }
View Full Code Here

  
   public void visitAnnotationMemberValue(AnnotationMemberValue node)
   {
      try
      {
         Annotation ann = node.getValue();
         value = AnnotationProxy.createProxy(ann);
      }
      catch (Exception e)
      {
         throw new RuntimeException(e);
View Full Code Here

TOP

Related Classes of javassist.bytecode.annotation.Annotation

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.