Many thanks for prompt reply. However when I do that, I find that 'attr' is 
always null! Here's part of a test of annotating methods.

When I annotate a class, I can get the annotation for the class, but then find 
memberNames() always returns null, so cannot get members from within the 
annotion.

I have been using the latest .jar from the site, but I also got the CVS source 
and rebuilt that, but the effect is the same.

Sorry to appear so slow.
Benedict
-------------------------------------------------------------------- 

anonymous wrote : 
  | 
  |    @Retention(RetentionPolicy.RUNTIME)//
  |     public @interface Author {
  | 
  |         String name() default "me";
  | 
  |         int age() default 999;
  |     }
  | 
  |     @Author//
  |     class Thing {
  | 
  |         @Author public void methodWithAuthor() {
  |         }
  | 
  |         public void methodWithoutAuthor() {
  |         }
  |     }
  | 
  |     /**
  |      * * Output is:
  |      * 
  |      * 
  |      * 
  |      *  
  |      *  
  |      *     .classname:ProblemTest$Thing
  |      *     .raw [EMAIL PROTECTED] class ProblemTest$Thing 
fields=ProblemTest$Thing.this$0:LProblemTest;,  [EMAIL PROTECTED] 
ProblemTest$Thing (LProblemTest;)V],  [EMAIL PROTECTED] methodWithAuthor ()V], 
[EMAIL PROTECTED] methodWithoutAuthor ()V], ]
  |      *     CtMethod: [EMAIL PROTECTED] methodWithAuthor ()V]
  |      *     attr:null
  |      *     CtMethod: [EMAIL PROTECTED] methodWithoutAuthor ()V]
  |      *     attr:null
  |      *  
  |      *   
  |      *  
  |      * 
  |      */
  |     public void testJavassistMethodAnnotations() throws Exception {
  | 
  |         ClassPool pool = ClassPool.getDefault();
  | 
  |         String demoClassName = "ProblemTest$Thing";
  | 
  |         CtClass demoClass = pool.get(demoClassName);
  |         echo("raw demoClass=" + demoClass);
  | 
  |         CtMethod[] thingMethods = demoClass.getDeclaredMethods();
  | 
  |         for (CtMethod ctMethod : thingMethods) {
  |             echo("CtMethod: " + ctMethod);
  | 
  |             MethodInfo mInfo = ctMethod.getMethodInfo();
  | 
  |             AnnotationsAttribute attr = (AnnotationsAttribute) mInfo
  |                     .getAttribute(AnnotationsAttribute.invisibleTag);
  | 
  |             System.out.println("attr:" + attr);
  | 
  |             if (attr != null) {
  |                 // we never get here!
  |                 Annotation author = attr.getAnnotation("Author");
  |                 echo("Author annotation:" + author);
  |                 String s = ((StringMemberValue) 
author.getMemberValue("name")).getValue();
  |                 System.out.println("@Author(name=" + s + ")");
  |             }
  |         }
  |     }

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3864691#3864691

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3864691


-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to