<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Adding a Method Annotation not working as expected...
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/apinke">Amit P</a> in <i>Javassist</i> - <a href="http://community.jboss.org/message/629947#629947">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi All, </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I have a few classes ( in a supplied jar) in which I am trying to mark certain specifc methods as "Deprecated" .</p><p>I am able to use javassist and add the annotation to the method (code attached to the end of this mail) but Eclipse refuses to identify that as a "Deprecated" method at compile time.</p><p>I decompiled and verified that there is a "@Deprecated" annotation on the method. I also used ASM compare between a class in which I added a @Deprecated and this class in which javassist&#160; added the annotation and notice one strange thing : the access flags are different</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>"normal" method :</p><p>// DEPRECATED</p><p>&#160; // access flags 0x20001</p><p>&#160; public getName()Ljava/lang/String;</p><p>&#160; @Ljava/lang/Deprecated;()</p><p>&#160;&#160; L0</p><p>&#160;&#160;&#160; LINENUMBER 7 L0</p><p><span style="color: #3f7f5f; font-size: 10pt;">&#160; </span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>javassist annotated method :</p><p>&#160;&#160; // access flags 0x1</p><p>&#160; public getName()Ljava/lang/String;</p><p>&#160; @Ljava/lang/Deprecated;()</p><p>&#160;&#160; L0</p><p>&#160;&#160;&#160; LINENUMBER 7 L0</p><p align="left"><span style="font-size: 10pt;">&#160; </span></p><p><span style="font-size: 10pt;"><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left">Questions :</p><p align="left">1) is there a problem in the way the Annotation is being added ?</p><p align="left">2) Cant I add a java.lang.Deprecated annotation to a method ? is there some special modifier or instruction to be used to add the inbuilt java Annotations ?</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left">Any help or pointer is appreciated !! </p><p align="left"><span style="font-size: 10pt;">I tried to make it a "invisibleTag" ,&#160; specify it as "Deprecated" , "@Deprecated" but the IDE refuses to treat that as a Deprecated API.</span></p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left">thanks</p><p align="left">Pat</p><p align="left">----</p><p align="left">code snippet :</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p></span></p><p align="left"><span style="font-size: 10pt;"><span id="mce_marker"></span></span> CtMethod[] methods = cc.getMethods();<br/>&#160; for (int k = 0; k &lt; methods.length; k++) {<br/>&#160;&#160; CtMethod met = methods[k];<br/>&#160;&#160;&#160; System.out.println("Found Method --&gt; " + met.getName());<br/>&#160;&#160;&#160; try{<br/>&#160;&#160;&#160;&#160; ClassFile ccFile = cc.getClassFile(); <br/>&#160;&#160;&#160;&#160; ConstPool constpool = ccFile.getConstPool(); <br/>&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160; AnnotationsAttribute attr = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag); <br/>&#160;&#160;&#160;&#160; Annotation annot = new Annotation("java.lang.Deprecated", constpool);<br/>&#160;&#160;&#160;&#160; attr.addAnnotation(annot); <br/>&#160;&#160;&#160;&#160; met.getMethodInfo().addAttribute(attr);&#160; <br/>&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160; }catch(Exception e){<br/>&#160;&#160;&#160;&#160; System.out.println("Skipping method:--&gt;" + met.getName() +"Reason:" + e.getMessage() );<br/>&#160;&#160;&#160; }<br/>&#160; }</p><p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p></p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/629947#629947">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in Javassist at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2062">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>