[
https://issues.jboss.org/browse/JASSIST-256?page=com.atlassian.jira.plugi...
]
Rui C. updated JASSIST-256:
---------------------------
Description:
{code:java}
ClassPool pool = ClassPool.getDefault();
CtClass superclass = pool.getCtClass(AbstractEntity.class.getName());
CtClass cc = pool.makeClass("com.rapid.develop.entity.Ponit", superclass);
ClassFile ccFile = cc.getClassFile();
ConstPool constpool = ccFile.getConstPool();
AnnotationsAttribute attr = new AnnotationsAttribute(constpool,
AnnotationsAttribute.visibleTag);
Annotation entityAnno = new Annotation("Entity", constpool);
Annotation tableAnno = new Annotation("Table", constpool);
tableAnno.addMemberValue("name", new StringMemberValue("test",
ccFile.getConstPool()));
attr.addAnnotation(entityAnno);
attr.addAnnotation(tableAnno);
ccFile.addAttribute(attr);
Class clazz = cc.toClass();
Object o = clazz.newInstance();
assertTrue(o.getClass().getName().equals("com.rapid.develop.entity.Ponit"));
// annotations length = zero
java.lang.annotation.Annotation[] annotations = clazz.getDeclaredAnnotations();
assertEquals(2, annotations.length);
{code}
I used javassist to add annotation for class, I saw these annotations were added to class
file.
But I can't get them using java API clazz.getDeclaredAnnotations() and
clazz.getAnnotations()
was:
{code:java}
ClassPool pool = ClassPool.getDefault();
CtClass superclass = pool.getCtClass(AbstractEntity.class.getName());
CtClass cc = pool.makeClass("com.rapid.develop.entity.Ponit",
superclass);
ClassFile ccFile = cc.getClassFile();
ConstPool constpool = ccFile.getConstPool();
AnnotationsAttribute attr = new AnnotationsAttribute(constpool,
AnnotationsAttribute.visibleTag);
Annotation entityAnno = new Annotation("Entity", constpool);
Annotation tableAnno = new Annotation("Table", constpool);
tableAnno.addMemberValue("name", new
StringMemberValue("test", ccFile.getConstPool()));
attr.addAnnotation(entityAnno);
attr.addAnnotation(tableAnno);
ccFile.addAttribute(attr);
Class clazz = cc.toClass();
Object o = clazz.newInstance();
assertTrue(o.getClass().getName().equals("com.rapid.develop.entity.Ponit"));
// annotations length = zero
java.lang.annotation.Annotation[] annotations =
clazz.getDeclaredAnnotations();
assertEquals(2, annotations.length);
{code}
I used javassist to add annotation for class, I saw these annotations were added to class
file.
But I can't get them using java API clazz.getDeclaredAnnotations() and
clazz.getAnnotations()
Javassist - add annotation to class doesn't work on reflections
---------------------------------------------------------------
Key: JASSIST-256
URL:
https://issues.jboss.org/browse/JASSIST-256
Project: Javassist
Issue Type: Bug
Affects Versions: 3.20.0-GA
Environment: JDK1.7, IDEA
Reporter: Rui C.
Assignee: Shigeru Chiba
Priority: Minor
{code:java}
ClassPool pool = ClassPool.getDefault();
CtClass superclass = pool.getCtClass(AbstractEntity.class.getName());
CtClass cc = pool.makeClass("com.rapid.develop.entity.Ponit", superclass);
ClassFile ccFile = cc.getClassFile();
ConstPool constpool = ccFile.getConstPool();
AnnotationsAttribute attr = new AnnotationsAttribute(constpool,
AnnotationsAttribute.visibleTag);
Annotation entityAnno = new Annotation("Entity", constpool);
Annotation tableAnno = new Annotation("Table", constpool);
tableAnno.addMemberValue("name", new StringMemberValue("test",
ccFile.getConstPool()));
attr.addAnnotation(entityAnno);
attr.addAnnotation(tableAnno);
ccFile.addAttribute(attr);
Class clazz = cc.toClass();
Object o = clazz.newInstance();
assertTrue(o.getClass().getName().equals("com.rapid.develop.entity.Ponit"));
// annotations length = zero
java.lang.annotation.Annotation[] annotations = clazz.getDeclaredAnnotations();
assertEquals(2, annotations.length);
{code}
I used javassist to add annotation for class, I saw these annotations were added to class
file.
But I can't get them using java API clazz.getDeclaredAnnotations() and
clazz.getAnnotations()
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)