Package javassist.bytecode.annotation

Examples of javassist.bytecode.annotation.Annotation


                            }
                        }
                        itr.remove();
                    }
                }
                Annotation inheritance = new Annotation(Inheritance.class.getName(), constantPool);
                ClassPool pool = ClassPool.getDefault();
                pool.importPackage("javax.persistence");
                pool.importPackage("java.lang");
                EnumMemberValue strategy = (EnumMemberValue) Annotation.createMemberValue(constantPool, pool.makeClass("InheritanceType"));
                strategy.setType(InheritanceType.class.getName());
                strategy.setValue(InheritanceType.SINGLE_TABLE.name());
                inheritance.addMemberValue("strategy", strategy);
                annotationsAttribute.addAnnotation(inheritance);
                if (myInfo.getDiscriminatorName() != null) {
                    Annotation discriminator = new Annotation(DiscriminatorColumn.class.getName(), constantPool);
                    StringMemberValue name = new StringMemberValue(constantPool);
                    name.setValue(myInfo.getDiscriminatorName());
                    discriminator.addMemberValue("name", name);
                    EnumMemberValue discriminatorType = (EnumMemberValue) Annotation.createMemberValue(constantPool, pool.makeClass("DiscriminatorType"));
                    discriminatorType.setType(DiscriminatorType.class.getName());
                    discriminatorType.setValue(myInfo.getDiscriminatorType().name());
                    discriminator.addMemberValue("discriminatorType", discriminatorType);
                    IntegerMemberValue length = new IntegerMemberValue(constantPool);
                    length.setValue(myInfo.getDiscriminatorLength());
                    discriminator.addMemberValue("length", length);
                   
                    annotationsAttribute.addAnnotation(discriminator);
                }
                classFile.addAttribute(annotationsAttribute);
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
View Full Code Here


         boolean changed = false;
         for (int i = 0; i < annotations.length; i++)
         {
            if (annotations[i].getTypeName().equals(Inherited.class.getName()))
            {
               annotations[i] = new Annotation("org/jboss/lang/annotation/Inherited", file.getConstPool());
               changed = true;
            }
         }
         if (changed)
         {
View Full Code Here

         boolean changed = false;
         for (int i = 0; i < annotations.length; i++)
         {
            if (annotations[i].getTypeName().equals(Inherited.class.getName()))
            {
               annotations[i] = new Annotation("org/jboss/lang/annotation/Inherited", file.getConstPool());
               changed = true;
            }
         }
         if (changed)
         {
View Full Code Here

*/
public class AnnotationBuilder {

    public static javassist.bytecode.annotation.Annotation createJavassistAnnotation(java.lang.annotation.Annotation annotation, ConstPool cp) {
        try {
            javassist.bytecode.annotation.Annotation a = new Annotation(annotation.annotationType().getName(), cp);
            for (Method m : annotation.annotationType().getDeclaredMethods()) {
                Object val = m.invoke(annotation);
                a.addMemberValue(m.getName(), createMemberValue(m.getReturnType(), val, cp));
            }
            return a;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
View Full Code Here

                AnnotationsAttribute at = (AnnotationsAttribute) m.getAttribute(AnnotationsAttribute.visibleTag);
                if (at == null) {
                    at = new AnnotationsAttribute(file.getConstPool(), AnnotationsAttribute.visibleTag);
                    m.addAttribute(at);
                }
                at.addAnnotation(new Annotation(ModifiedMethod.class.getName(), file.getConstPool()));
                m.addAttribute(new AttributeInfo(file.getConstPool(), Constants.FINAL_METHOD_ATTRIBUTE, new byte[0]));
                modified = true;
            }
        }
        return modified;
View Full Code Here

      theField.setModifiers( theField.getModifiers() | Modifier.TRANSIENT );
    }
    theField.setModifiers( Modifier.setPrivate( theField.getModifiers() ) );

    final AnnotationsAttribute annotationsAttribute = getVisibleAnnotations( theField.getFieldInfo() );
    annotationsAttribute.addAnnotation( new Annotation( Transient.class.getName(), constPool ) );
    return theField;
  }
View Full Code Here

                for (Field field : entity.getDeclaredFields()) {
                    AnnotationsAttribute annotAttr = null;
                    // Add Hibernate's @Type to each entity String field annotated with @Lob
                    if (field.isAnnotationPresent(Lob.class)) {
                        Annotation typeAnnot = new Annotation("org.hibernate.annotations.Type", constPool);
                        if (String.class.equals(field.getType())) {
                            typeAnnot.addMemberValue("type",
                                    new StringMemberValue("org.hibernate.type.StringClobType", constPool));
                        } else if (field.getType().isArray()) {
                            typeAnnot.addMemberValue("type",
                                    new StringMemberValue("org.hibernate.type.ByteArrayBlobType", constPool));
                        }

                        annotAttr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
                        annotAttr.addAnnotation(typeAnnot);
                    }

                    // Workaround for https://hibernate.onjira.com/browse/EJB-346
                    if (field.isAnnotationPresent(OneToMany.class) && field.getType().isAssignableFrom(List.class)
                            && FetchType.EAGER == field.getAnnotation(OneToMany.class).fetch()) {

                        Annotation fetchAnnot = new Annotation("org.hibernate.annotations.Fetch", constPool);
                        EnumMemberValue emb = new EnumMemberValue(constPool);
                        emb.setType("org.hibernate.annotations.FetchMode");
                        emb.setValue("SUBSELECT");
                        fetchAnnot.addMemberValue("value", emb);

                        annotAttr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
                        annotAttr.addAnnotation(fetchAnnot);
                    }
View Full Code Here

    if (annoAttr == null) {
      annoAttr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
    }

    // Create annotation if it does not exist
    Annotation a = new Annotation(EnhancedClassFile.class.getName(), constPool);

    // Replace annotation
    annoAttr.addAnnotation(a);

    // Replace annotation attribute
View Full Code Here

    if (annoAttr == null) {
      annoAttr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
    }

    // Create annotation if it does not exist
    Annotation a = annoAttr.getAnnotation(ResourceMetaData.class.getName());
    if (a == null) {
      a = new Annotation(ResourceMetaData.class.getName(), constPool);
      // Add a name, otherwise there will be none in the generated descriptor.
      a.addMemberValue("name", new StringMemberValue(
              ResourceMetaDataFactory.getDefaultName(aClazz), constPool));
    }

    // Update description from JavaDoc
    String doc = Util.getComponentDocumentation(aAST, aClazz.getName());
View Full Code Here

    if ( makeTransient ) {
      theField.setModifiers( theField.getModifiers() | Modifier.TRANSIENT );
    }
    theField.setModifiers( Modifier.setPrivate( theField.getModifiers() ) );
    AnnotationsAttribute annotationsAttribute = getVisibleAnnotations( theField.getFieldInfo() );
    annotationsAttribute.addAnnotation( new Annotation( Transient.class.getName(), constPool ) );
    return theField;
  }
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.