24
24
import java .util .Map ;
25
25
26
26
import org .springframework .util .ObjectUtils ;
27
- import org .springframework .util .ReflectionUtils ;
28
27
import org .springframework .util .StringUtils ;
29
28
30
29
import static org .springframework .core .annotation .AnnotationUtils .*;
30
+ import static org .springframework .util .ReflectionUtils .*;
31
31
32
32
/**
33
33
* {@link InvocationHandler} for an {@link Annotation} that Spring has
@@ -67,24 +67,21 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
67
67
68
68
@ Override
69
69
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 )) {
75
71
return equals (proxy , args [0 ]);
76
72
}
77
- else if ("toString" . equals ( methodName ) && ( parameterCount == 0 )) {
73
+ if (isToStringMethod ( method )) {
78
74
return toString (proxy );
79
75
}
80
76
77
+ String methodName = method .getName ();
81
78
Class <?> returnType = method .getReturnType ();
82
79
boolean nestedAnnotation = (Annotation [].class .isAssignableFrom (returnType ) || Annotation .class .isAssignableFrom (returnType ));
83
80
String aliasedAttributeName = aliasMap .get (methodName );
84
81
boolean aliasPresent = (aliasedAttributeName != null );
85
82
86
- ReflectionUtils . makeAccessible (method );
87
- Object value = ReflectionUtils . invokeMethod (method , this .annotation , args );
83
+ makeAccessible (method );
84
+ Object value = invokeMethod (method , this .annotation , args );
88
85
89
86
// No custom processing necessary?
90
87
if (!aliasPresent && !nestedAnnotation ) {
@@ -103,8 +100,8 @@ else if ("toString".equals(methodName) && (parameterCount == 0)) {
103
100
throw new AnnotationConfigurationException (msg );
104
101
}
105
102
106
- ReflectionUtils . makeAccessible (aliasedMethod );
107
- Object aliasedValue = ReflectionUtils . invokeMethod (aliasedMethod , this .annotation , args );
103
+ makeAccessible (aliasedMethod );
104
+ Object aliasedValue = invokeMethod (aliasedMethod , this .annotation , args );
108
105
Object defaultValue = getDefaultValue (this .annotation , methodName );
109
106
110
107
if (!ObjectUtils .nullSafeEquals (value , aliasedValue ) && !ObjectUtils .nullSafeEquals (value , defaultValue )
@@ -149,8 +146,8 @@ private boolean equals(Object proxy, Object other) {
149
146
}
150
147
151
148
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 );
154
151
if (!ObjectUtils .nullSafeEquals (thisValue , otherValue )) {
155
152
return false ;
156
153
}
@@ -167,7 +164,7 @@ private String toString(Object proxy) {
167
164
Method attributeMethod = iterator .next ();
168
165
sb .append (attributeMethod .getName ());
169
166
sb .append ('=' );
170
- sb .append (valueToString (ReflectionUtils . invokeMethod (attributeMethod , proxy )));
167
+ sb .append (valueToString (invokeMethod (attributeMethod , proxy )));
171
168
sb .append (iterator .hasNext () ? ", " : "" );
172
169
}
173
170
0 commit comments