add mathod

This commit is contained in:
Looly 2020-11-25 23:29:26 +08:00
parent eb38b6b3ff
commit c11e2a935f
2 changed files with 9 additions and 14 deletions

View File

@ -3,7 +3,7 @@
-------------------------------------------------------------------------------------------------------------
# 5.5.2 (2020-11-20)
# 5.5.2 (2020-11-25)
### 新特性
* 【crypto 】 KeyUtil增加重载AES构造增加重载issue#I25NNZ@Gitee
@ -12,6 +12,7 @@
* 【extra 】 新增Rhino表达式执行引擎pr#1229@Github
* 【crypto 】 增加判空issue#1230@Github
* 【core 】 xml.setXmlStandalone(true)格式优化pr#1234@Github
* 【core 】 AnnotationUtil增加setValue方法pr#1250@Github
### Bug修复
* 【cron 】 修复CronTimer可能死循环的问题issue#1224@Github

View File

@ -12,8 +12,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.HashMap;
@ -205,20 +203,16 @@ public class AnnotationUtil {
}
/**
* 刷新注解的属性值
* 设置新的注解的属性字段
*
* @param annotation 注解对象
* @param annotationField 注解属性名称
* @param annotationField 注解属性字段名称
* @param value 要更新的属性值
* @throws Exception 可能出现的异常(一般情况下不会发生)
* @since 5.5.2
*/
public static void refreshAnnotationValue(Annotation annotation, String annotationField, Object value) throws Exception {
InvocationHandler invocationHandler = Proxy.getInvocationHandler(annotation);
Field field = invocationHandler.getClass().getDeclaredField("memberValues");
boolean accessible = field.isAccessible();
field.setAccessible(true);
@SuppressWarnings("unchecked")
Map<Object, Object> memberValues = (Map<Object, Object>) field.get(invocationHandler);
@SuppressWarnings({"rawtypes", "unchecked"})
public static void setValue(Annotation annotation, String annotationField, Object value) {
final Map memberValues = (Map) ReflectUtil.getFieldValue(Proxy.getInvocationHandler(annotation), "memberValues");
memberValues.put(annotationField, value);
field.setAccessible(accessible);
}
}