Skip to content

Commit ae5c828

Browse files
committed
Polish SynthesizedAnnotationInvocationHandler
1 parent 7e2e9a8 commit ae5c828

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
import java.util.Map;
2525

2626
import org.springframework.util.ObjectUtils;
27-
import org.springframework.util.ReflectionUtils;
2827
import org.springframework.util.StringUtils;
2928

3029
import static org.springframework.core.annotation.AnnotationUtils.*;
30+
import static org.springframework.util.ReflectionUtils.*;
3131

3232
/**
3333
* {@link InvocationHandler} for an {@link Annotation} that Spring has
@@ -67,24 +67,21 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
6767

6868
@Override
6969
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
70-
String methodName = method.getName();
71-
Class<?>[] parameterTypes = method.getParameterTypes();
72-
int parameterCount = parameterTypes.length;
73-
74-
if ("equals".equals(methodName) && (parameterCount == 1) && (parameterTypes[0] == Object.class)) {
70+
if (isEqualsMethod(method)) {
7571
return equals(proxy, args[0]);
7672
}
77-
else if ("toString".equals(methodName) && (parameterCount == 0)) {
73+
if (isToStringMethod(method)) {
7874
return toString(proxy);
7975
}
8076

77+
String methodName = method.getName();
8178
Class<?> returnType = method.getReturnType();
8279
boolean nestedAnnotation = (Annotation[].class.isAssignableFrom(returnType) || Annotation.class.isAssignableFrom(returnType));
8380
String aliasedAttributeName = aliasMap.get(methodName);
8481
boolean aliasPresent = (aliasedAttributeName != null);
8582

86-
ReflectionUtils.makeAccessible(method);
87-
Object value = ReflectionUtils.invokeMethod(method, this.annotation, args);
83+
makeAccessible(method);
84+
Object value = invokeMethod(method, this.annotation, args);
8885

8986
// No custom processing necessary?
9087
if (!aliasPresent && !nestedAnnotation) {
@@ -103,8 +100,8 @@ else if ("toString".equals(methodName) && (parameterCount == 0)) {
103100
throw new AnnotationConfigurationException(msg);
104101
}
105102

106-
ReflectionUtils.makeAccessible(aliasedMethod);
107-
Object aliasedValue = ReflectionUtils.invokeMethod(aliasedMethod, this.annotation, args);
103+
makeAccessible(aliasedMethod);
104+
Object aliasedValue = invokeMethod(aliasedMethod, this.annotation, args);
108105
Object defaultValue = getDefaultValue(this.annotation, methodName);
109106

110107
if (!ObjectUtils.nullSafeEquals(value, aliasedValue) && !ObjectUtils.nullSafeEquals(value, defaultValue)
@@ -149,8 +146,8 @@ private boolean equals(Object proxy, Object other) {
149146
}
150147

151148
for (Method attributeMethod : getAttributeMethods(this.annotationType)) {
152-
Object thisValue = ReflectionUtils.invokeMethod(attributeMethod, proxy);
153-
Object otherValue = ReflectionUtils.invokeMethod(attributeMethod, other);
149+
Object thisValue = invokeMethod(attributeMethod, proxy);
150+
Object otherValue = invokeMethod(attributeMethod, other);
154151
if (!ObjectUtils.nullSafeEquals(thisValue, otherValue)) {
155152
return false;
156153
}
@@ -167,7 +164,7 @@ private String toString(Object proxy) {
167164
Method attributeMethod = iterator.next();
168165
sb.append(attributeMethod.getName());
169166
sb.append('=');
170-
sb.append(valueToString(ReflectionUtils.invokeMethod(attributeMethod, proxy)));
167+
sb.append(valueToString(invokeMethod(attributeMethod, proxy)));
171168
sb.append(iterator.hasNext() ? ", " : "");
172169
}
173170

0 commit comments

Comments
 (0)