Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =import java.lang.reflect.Method;
- import javassist.ClassPool;
- import javassist.CtClass;
- import javassist.CtMethod;
- import javassist.bytecode.AnnotationsAttribute;
- import javassist.bytecode.ClassFile;
- import javassist.bytecode.ConstPool;
- import javassist.bytecode.annotation.Annotation;
- import javassist.bytecode.annotation.StringMemberValue;
- public class SelfDeprecation
- {
- static boolean dep = false;
- public static void deprecateMethod(String className, String methodName) throws Exception
- {
- ClassPool pool = ClassPool.getDefault();
- CtClass cc = pool.getCtClass(className);
- CtMethod descriptor = cc.getDeclaredMethod(methodName);
- 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);
- descriptor.getMethodInfo().addAttribute(attr);
- if(!dep)
- {
- deprecateMethod("SelfDeperecation", "deprecateMethod");
- dep = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment