[jboss-user] [Javassist user questions] - Re: Help on class anotation
theyurinator
do-not-reply at jboss.com
Wed Aug 13 13:28:26 EDT 2008
To be a little more specific, this is the exact code I have
public static void main(String[] args) {
| ClassPool pool = ClassPool.getDefault();
| CtClass cc = pool.makeClass("sample");
| ClassFile cf = cc.getClassFile();
| ConstPool cp = cf.getConstPool();
|
| AnnotationsAttribute attr = new AnnotationsAttribute(cp, AnnotationsAttribute.visibleTag);
| Annotation a = new Annotation("Author", cp);
| a.addMemberValue("name", new StringMemberValue("Chiba", cp));
| attr.setAnnotation(a);
| cf.addAttribute(attr);
| cf.setVersionToJava5();
|
| try {
| cc.writeFile();
| } catch (NotFoundException e) {
| // TODO Auto-generated catch block
| e.printStackTrace();
| } catch (IOException e) {
| // TODO Auto-generated catch block
| e.printStackTrace();
| } catch (CannotCompileException e) {
| // TODO Auto-generated catch block
| e.printStackTrace();
| }
| }
and this is what I see with javap as a result.
public class sample extends java.lang.Object{
| public sample();
| }
|
I don't really understand what I am doing wrong? If I step through with the debugger, I do see the AnnotationsAttribute added to the ClassFile object, and the Annotation object is added to the AnnotationsAttribute object.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4170387#4170387
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4170387
More information about the jboss-user
mailing list