Skip to content

Commit 5bcbcb3

Browse files
committed
Simplify SynthesizedMergedAnnotationInvocationHandler.invoke()
1 parent fe7355d commit 5bcbcb3

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,29 +73,23 @@ private SynthesizedMergedAnnotationInvocationHandler(MergedAnnotation<A> annotat
7373

7474
@Override
7575
public Object invoke(Object proxy, Method method, Object[] args) {
76-
if (ReflectionUtils.isEqualsMethod(method)) {
77-
return annotationEquals(args[0]);
78-
}
79-
if (ReflectionUtils.isHashCodeMethod(method)) {
80-
return annotationHashCode();
81-
}
82-
if (ReflectionUtils.isToStringMethod(method)) {
83-
return annotationToString();
84-
}
85-
if (isAnnotationTypeMethod(method)) {
86-
return this.type;
87-
}
8876
if (this.attributes.indexOf(method.getName()) != -1) {
8977
return getAttributeValue(method);
9078
}
79+
if (method.getParameterCount() == 0) {
80+
switch (method.getName()) {
81+
case "annotationType": return this.type;
82+
case "hashCode": return annotationHashCode();
83+
case "toString": return annotationToString();
84+
}
85+
}
86+
if (ReflectionUtils.isEqualsMethod(method)) {
87+
return annotationEquals(args[0]);
88+
}
9189
throw new AnnotationConfigurationException(String.format(
9290
"Method [%s] is unsupported for synthesized annotation type [%s]", method, this.type));
9391
}
9492

95-
private boolean isAnnotationTypeMethod(Method method) {
96-
return (method.getName().equals("annotationType") && method.getParameterCount() == 0);
97-
}
98-
9993
/**
10094
* See {@link Annotation#equals(Object)} for a definition of the required algorithm.
10195
* @param other the other object to compare against

0 commit comments

Comments
 (0)