如下实例:
@Test
public void aetTestCaseAtrributes() throws NotFoundException {
ClassPool pool = ClassPool.getDefault();
// 获取需要修改的类
CtClass ct = pool.get("com.XXX.XXX.XXX.XXXX");
// 获取类里的所有方法
CtMethod[] cms = ct.getDeclaredMethods();
for (CtMethod cm : cms) {
System.out.println("方法名称====" + cm.getName());
MethodInfo methodInfo = cm.getMethodInfo();
AnnotationsAttribute attribute = (AnnotationsAttribute) methodInfo
.getAttribute(AnnotationsAttribute.visibleTag);
System.out.println(attribute);
ConstPool cPool = methodInfo.getConstPool();
AnnotationsAttribute attribute2 = new AnnotationsAttribute(cPool, AnnotationsAttribute.visibleTag);
Annotation[] anns= attribute2.getAnnotations();
for(Annotation ann:anns){
System.out.println(ann.getTypeName());
}
Annotation annotation = new Annotation("org.testn