Re: annotations

Niels Boldt <[email protected]>
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <[email protected]>
H,

Sorry for my previous message, somehow hitted send before it as ready

I'm using version 1.5.3

I'm quite new to asm and are currently wrestling with generation of
annotations on my classes, It goes quite well with annotations like

@Entity( name="AdGamer" )

that pretty much resmembles the example at
http://asm.ow2.org/doc/tutorial-annotations.html, however when I try to
create annotation that contains enums, like

    @ManyToOne( optional = false , cascade=CascadeType.PERSIST )

 I get an error message like

java.lang.IllegalArgumentException: value SINGLE_TABLE
    at org.objectweb.asm.ClassWriter.newConstItem(Unknown Source)
    at org.objectweb.asm.ClassWriter.newConst(Unknown Source)
    at org.objectweb.asm.attrs.Annotation.writeValue(Unknown Source)

...

I generate the annotations with the following code that run for each
annotation of the class and then iterate through all methods of the
java.reflect.Annotation

                org.objectweb.asm.attrs.Annotation attr = new
org.objectweb.asm.attrs.Annotation("L" +
annotation.annotationType().getName().replace(".", "/") + ";");
                ........
                //get all the methods
                try {
                    if( !"hashCode".equals( m.getName() ) &&
!"equals".equals( m.getName() ) && !"toString".equals( m.getName() ) &&
!"annotationType".equals( m.getName() ) ){
                        Object o = m.invoke( annotation , null );
                        attr.add( m.getName() , o );
                    }
                }
                catch( Exception exc ){
                    throw new RuntimeException( exc );
                }

My error is probably related to the way I use attr.add, but the problem is
that I don't understand this method or the way annotations are structured.
The ASMifierClassVisitor does not help me as it ignores complex attributes,
in other case it has been a great help.

If anyone could point me in the right direction, or provide a link to an
example etc I would be most thankful

Best Regards
Niels
-- 
BinaryConstructors ApS
Vestergade 10a, 4th
1456 Kbh K
Denmark
phone: +4528138757
web: http://www.binaryconstructors.dk
mail: [email protected]
skype: nielsboldt
message-footer.txt (text/plain, 238 B)
-- 
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.