Hi All,
I have a few classes ( in a supplied jar) in which I am trying to mark certain specifc methods as "Deprecated" .
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.
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 added the annotation and notice one strange thing : the access flags are different
"normal" method :
// DEPRECATED
// access flags 0x20001
public getName()Ljava/lang/String;
@Ljava/lang/Deprecated;()
L0
LINENUMBER 7 L0
javassist annotated method :
// access flags 0x1
public getName()Ljava/lang/String;
@Ljava/lang/Deprecated;()
L0
LINENUMBER 7 L0
Questions : 1) is there a problem in the way the Annotation is being added ? 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 ? Any help or pointer is appreciated !! I tried to make it a "invisibleTag" , specify it as "Deprecated" , "@Deprecated" but the IDE refuses to treat that as a Deprecated API. thanks Pat ---- code snippet :
CtMethod[] methods = cc.getMethods();
for (int k = 0; k < methods.length; k++) {
CtMethod met = methods[k];
System.out.println("Found Method --> " + met.getName());
try{
ClassFile ccFile = cc.getClassFile();
ConstPool constpool = ccFile.getConstPool();
AnnotationsAttribute attr = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag);
Annotation annot = new Annotation("java.lang.Deprecated", constpool);
attr.addAnnotation(annot);
met.getMethodInfo().addAttribute(attr);
}catch(Exception e){
System.out.println("Skipping method:-->" + met.getName() +"Reason:" + e.getMessage() );
}
}