/**
* Processes a method invocation request to this annotation instance.
* Recognizes the methods declared in the
* {@link java.lang.annotation.Annotation java.lang.annotation.Annotation}
* interface, and member-defining methods of the implemented annotation type.
* @throws IllegalArgumentException If the specified method is none of the above
* @return the invocation result
*/
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
String name = method.getName();
Class[] params = method.getParameterTypes();
if (params.length == 0) {
if ("annotationType".equals(name)) {
return klazz;
} else if ("toString".equals(name)) {
return toString();
} else if ("hashCode".equals(name)) {
return hashCode();
}
// this must be element value request
AnnotationMember element = null;
for (AnnotationMember el : elements) {
if (name.equals(el.name)) {
element = el;
break;
}
}
if (element == null || !method.equals(element.definingMethod)) {
throw new IllegalArgumentException(method.toString());
} else {
Object value = element.validateValue();
if (value == null) {
throw new IncompleteAnnotationException(klazz, name);
}
return value;
}
} else if (params.length == 1 && params[0] == Object.class && "equals".equals(name)){
return Boolean.valueOf(equals(args[0]));
}
throw new IllegalArgumentException(
"Invalid method for annotation type: " + method);
}
AnnotationFactory.java 文件源码
java
阅读 32
收藏 0
点赞 0
评论 0
项目:cn1
作者:
评论列表
文章目录