This content has been marked as final. 
    
Show                 4 replies
    
- 
        1. Re: annotation bug?chiba Sep 6, 2005 10:17 PM (in response to slobo)Thank you for a bug report. 
 I have fixed this bug. Please download
 the latest snapshot from CVS.
- 
        2. Re: annotation bug?safarje Oct 13, 2005 4:57 AM (in response to slobo)Hi, 
 Along the same lines, I am trying to create a class and Annotations on the fly to it. When I finally ask the Class descriptor to give me the annotations it does not find it. Am I doing something wrong here?CtClass c = pool.makeClass("NewClass"); ClassFile cf = c.getClassFile(); ConstPool cp = cf.getConstPool(); AnnotationsAttribute attr = new AnnotationsAttribute(cp, AnnotationsAttribute.visibleTag); javassist.bytecode.annotation.Annotation a = new javassist.bytecode.annotation.Annotation("MyAnnotation", cp); a.addMemberValue("name", new StringMemberValue("Chiba", cp)); a.addMemberValue("version", new StringMemberValue("Chiba", cp)); a.addMemberValue("description", new StringMemberValue("Chiba", cp)); a.addMemberValue("interfaceName", new StringMemberValue("Chiba", cp)); attr.setAnnotation(a); System.out.println(attr); cf.addAttribute(attr); Object [] ans = c.getAnnotations() ; System.out.println("Num Annotation : " +ans.length); Class newclass = c.toClass(); Annotation[] anns = newclass.getAnnotations(); System.out.println("Num NewClass Annotation : " +anns.length);
 
- 
        3. Re: annotation bug?safarje Oct 13, 2005 5:00 AM (in response to slobo)"safarje" wrote: 
 Hi, (sorry for the repost but the original got truncated...)
 Along the same lines, I am trying to create a class and Annotations on the fly to it. When I finally ask the Class descriptor to give me the annotations it does not find it. Am I doing something wrong here?
 <p>The result is:
 @MyAnnotation(description="Chiba", interfaceName="Chiba", name="Chiba", version="Chiba")
 Num Annotation : 1
 Num NewClass Annotation : 0
 <p>
 <p>Is it possible to define annotations on the fly like I did? (I am using javassist 3.1).
 Best Regards
 JeanCtClass c = pool.makeClass("NewClass"); ClassFile cf = c.getClassFile(); ConstPool cp = cf.getConstPool(); AnnotationsAttribute attr = new AnnotationsAttribute(cp, AnnotationsAttribute.visibleTag); javassist.bytecode.annotation.Annotation a = new javassist.bytecode.annotation.Annotation("MyAnnotation", cp); a.addMemberValue("name", new StringMemberValue("Chiba", cp)); a.addMemberValue("version", new StringMemberValue("Chiba", cp)); a.addMemberValue("description", new StringMemberValue("Chiba", cp)); a.addMemberValue("interfaceName", new StringMemberValue("Chiba", cp)); attr.setAnnotation(a); System.out.println(attr); cf.addAttribute(attr); Object [] ans = c.getAnnotations() ; System.out.println("Num Annotation : " +ans.length); Class newclass = c.toClass(); Annotation[] anns = newclass.getAnnotations(); System.out.println("Num NewClass Annotation : " +anns.length);
- 
        4. Re: annotation bug?chiba Nov 9, 2005 3:23 AM (in response to slobo)Oh, you must insert the following code before calling c.toClass(): cf.setMajorVersion(49); cf.setMinorVersion(0); 
 I will add this info to the javadoc comment... Thanks.
 
     
    