[JBoss-user] [Javassist user questions] - Re: reading java 5.0 annotations

2005-02-27 Thread chiba
Yes, the default value is available from AnnotationDefault
attributes.  Thank you for your information.

I added the support of AnnotationDefault attributes to Javassist.
It is available from CVS HEAD or Branch_Javassist_3_0.

Chiba


View the original post : 
http://www.jboss.org/index.html?module=bbop=viewtopicp=3868097#3868097

Reply to the post : 
http://www.jboss.org/index.html?module=bbop=postingmode=replyp=3868097


---
SF email is sponsored by - The IT Product Guide
Read honest  candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595alloc_id=14396op=click
___
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user


[JBoss-user] [Javassist user questions] - Re: reading java 5.0 annotations

2005-02-06 Thread chiba
Maybe that is because the default value is not included in each
class file. (I'm not sure)

public @interface Author {
  | 
  | String name() default me;
  | 
  | int age() default 999;
  | }

Won't you try to read the annotations of the Author interface?

Regards,

Chiba


View the original post : 
http://www.jboss.org/index.html?module=bbop=viewtopicp=3865438#3865438

Reply to the post : 
http://www.jboss.org/index.html?module=bbop=postingmode=replyp=3865438


---
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


[JBoss-user] [Javassist user questions] - Re: reading java 5.0 annotations

2005-02-06 Thread bheal
Thankyou. As soon as I stop using default values, all is well!
So this presumably means that if I want all the effective annotations, I have 
to walk the superclasses to get inherited annotations, and access the 
annotation declaration to get the defaults.

Perhaps the API could include some utility methods that would do this for one. 
There would seem to be two dimensions of generality: inherited annotations from 
superclasses, and 'inherited' data values from default values.

Perhaps something like:
anonymous wrote : 
  |  getDeclaredAnnotations // just the actual annotations with actual data
  | // no inherited ones, no default values
  |  
  | getEffectiveAnnotations // fills in defaults, but no inherited ones
  | 
  | getAllAnnotations // includes inherited annotations, no default values
  | 
  | getAllEffectiveAnnotations // includes inherited annotations , 
  | and fills in default values
  | 
  | 

What do you think?

Benedict

View the original post : 
http://www.jboss.org/index.html?module=bbop=viewtopicp=3865440#3865440

Reply to the post : 
http://www.jboss.org/index.html?module=bbop=postingmode=replyp=3865440


---
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


[JBoss-user] [Javassist user questions] - Re: reading java 5.0 annotations

2005-02-06 Thread bheal
 Maybe that is because the default value is not included in each 
class file. (I'm not sure) 

I've just discovered in 
http://java.sun.com/docs/books/vmspec/2nd-edition/ClassFileFormat.pdf

stuff about an AnnotationDefault attribute which sounds what I need.
It says it contains default values for annottions, but if it did, each class 
would have the defaults bound in at compile time, whereas I had understood that 
recompiling the annotation led to each class getting the latest defaults.

Does it really contain the default values?  If so, is there any way to get at 
it?

Many thanks,

Benedict

View the original post : 
http://www.jboss.org/index.html?module=bbop=viewtopicp=3865486#3865486

Reply to the post : 
http://www.jboss.org/index.html?module=bbop=postingmode=replyp=3865486


---
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


[JBoss-user] [Javassist user questions] - Re: reading java 5.0 annotations

2005-02-05 Thread chiba
Can you replace AnnotationsAttribute.invisibleTag
with AnnotationsAttribute.visibleTag in the above
test code and try again?


View the original post : 
http://www.jboss.org/index.html?module=bbop=viewtopicp=3865395#3865395

Reply to the post : 
http://www.jboss.org/index.html?module=bbop=postingmode=replyp=3865395


---
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


[JBoss-user] [Javassist user questions] - Re: reading java 5.0 annotations

2005-02-05 Thread bheal
Thanks for suggestion.  I did that: I can now get as far as seeing the @Author 
attribute, but cannot
retrieve the name() element. In fact, getMemberNames() always is null.
Benedict

Here's a self-contained test class that shows the problem .
Thanks
Benedict
 
  |  
  | import java.lang.annotation.Retention;
  | import java.lang.annotation.RetentionPolicy;
  | import java.util.Arrays;
  | import java.util.List;
  | import java.util.Set;
  | 
  | import javassist.ClassPool;
  | import javassist.CtClass;
  | import javassist.CtMethod;
  | import javassist.bytecode.AnnotationsAttribute;
  | import javassist.bytecode.AttributeInfo;
  | import javassist.bytecode.ClassFile;
  | import javassist.bytecode.MethodInfo;
  | import javassist.bytecode.SourceFileAttribute;
  | import javassist.bytecode.annotation.Annotation;
  | import javassist.bytecode.annotation.StringMemberValue;
  | import junit.framework.TestCase;
  | import junit.textui.TestRunner;
  | 
  | /**
  |  * This test demonstrates that when I try to access annotations using 
Javassist,
  |  * I can get the annotation per se, but the membernames are always null, so 
I
  |  * can't access the data within the annotation.  
  |  *   p
  |  *   Output is:
  |  * 
  |  * pre
  |  .
  | 
  | -testJavassistMethodAnnotations
  | 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:@ProblemTest$Author
  | Author annotation:@ProblemTest$Author
  | author.getMemberNames is null
  | F.
  | 
  | -testClassAnnotations
  | demoCtClass: [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], ]
  | classfile:  [EMAIL PROTECTED]
  | interfaces: []
  | attributes: [EMAIL PROTECTED], [EMAIL PROTECTED], @ProblemTest$Author]
  | 
  | ---
  | attribute:[EMAIL PROTECTED]
  | an AttributeInfo is of class: class javassist.bytecode.SourceFileAttribute  
- [EMAIL PROTECTED] 
  | 
  | ---
  | attribute:[EMAIL PROTECTED]
  | an AttributeInfo is of class: class 
javassist.bytecode.InnerClassesAttribute  - [EMAIL PROTECTED] 
  | 
  | ---
  | attribute:@ProblemTest$Author
  | annotations: [EMAIL PROTECTED]
  | 
  | ++annotation: @ProblemTest$Author of class class 
javassist.bytecode.annotation.Annotation
  | interfaces: []
  | typename:ProblemTest$Author
  | memberNames: null
  | We have found the Author annotation, but cannot look at the members!
  | memberValue-name: null
  | stringMemberValue: null
  | F
  | Time: 0.141
  | There were 2 failures:
  | 1) 
testJavassistMethodAnnotations(ProblemTest)junit.framework.AssertionFailedError:
 stringmembervalue for name() is null
  | at ProblemTest.testJavassistMethodAnnotations(ProblemTest.java:166)
  | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  | at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  | at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  | at ProblemTest.main(ProblemTest.java:274)
  | 2) testClassAnnotations(ProblemTest)junit.framework.AssertionFailedError: 
On Author annotation, memberNames is null!
  | at ProblemTest.dumpAnnotation(ProblemTest.java:261)
  | at ProblemTest.testClassAnnotations(ProblemTest.java:217)
  | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  | at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  | at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  | at ProblemTest.main(ProblemTest.java:274)
  | 
  | FAILURES!!!
  | Tests run: 2,  Failures: 2,  Errors: 0
  | 
  | 
  |  * /pre
  |  * 
  |  * @author bheal .
  |  */
  | public class ProblemTest extends TestCase {
  | 
  | @Retention(RetentionPolicy.RUNTIME)//
  | public @interface Author {
  | 
  | String name() default me;
  | 
  | int age() default 999;
  | }
  | 
  | @Author//
  | class Thing {
  | 
  | @Author public void methodWithAuthor() {
  | }
  | 
  | public void methodWithoutAuthor() {
  | }
  | }
  | 
  | public void setUp() {
  | echo(\n\n- + getName());
  | }
  | 
  | /**
  |  * * Output is:
  |  * 
  |  * pre
  |  * 
  |  *  
  |  *   
  |  *
  |  * 
  |  *  
  |  *   
  |  *
  |  * 
  |  *  
  |  *   
  |  *   
  |  *  .classname:ProblemTest$Thing
  |  *  .raw [EMAIL PROTECTED] class 

[JBoss-user] [Javassist user questions] - Re: reading java 5.0 annotations

2005-02-01 Thread chiba
The current release 3.0 does not provide high-level API.
So you must use the lower-level API, but using it is not difficult.
For example,


  | import javassist.*;
  | import javassist.bytecode.*;
  | 
  | CtMethod m = ... ;
  | MethodInfo minfo = m.getMethodInfo();
  | AnnotationsAttribute attr = (AnnotationsAttribute)
  | minfo.getAttribute(AnnotationsAttribute.invisibleTag);
  | if (atr != null) {
  | Annotation an = attr.getAnnotation(Author);
  | String s = ((StringMemberValue)a.getMemberValue(name)).getValue();
  | System.out.println(@Author(name= + s + ));
  | }
  | 

This prints the @Author annotation of the method m.



View the original post : 
http://www.jboss.org/index.html?module=bbop=viewtopicp=3864611#3864611

Reply to the post : 
http://www.jboss.org/index.html?module=bbop=postingmode=replyp=3864611


---
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


[JBoss-user] [Javassist user questions] - Re: reading java 5.0 annotations

2005-02-01 Thread bheal
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=bbop=viewtopicp=3864691#3864691

Reply to the post : 
http://www.jboss.org/index.html?module=bbop=postingmode=replyp=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