1
1
/*
2
- * Copyright 2002-2014 the original author or authors.
2
+ * Copyright 2002-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -59,6 +59,7 @@ public static Method findBridgedMethod(Method bridgeMethod) {
59
59
if (bridgeMethod == null || !bridgeMethod .isBridge ()) {
60
60
return bridgeMethod ;
61
61
}
62
+
62
63
// Gather all methods with matching name and parameter size.
63
64
List <Method > candidateMethods = new ArrayList <Method >();
64
65
Method [] methods = ReflectionUtils .getAllDeclaredMethods (bridgeMethod .getDeclaringClass ());
@@ -67,10 +68,12 @@ public static Method findBridgedMethod(Method bridgeMethod) {
67
68
candidateMethods .add (candidateMethod );
68
69
}
69
70
}
71
+
70
72
// Now perform simple quick check.
71
73
if (candidateMethods .size () == 1 ) {
72
74
return candidateMethods .get (0 );
73
75
}
76
+
74
77
// Search for candidate match.
75
78
Method bridgedMethod = searchCandidates (candidateMethods , bridgeMethod );
76
79
if (bridgedMethod != null ) {
@@ -133,42 +136,13 @@ static boolean isBridgeMethodFor(Method bridgeMethod, Method candidateMethod, Cl
133
136
return (method != null && isResolvedTypeMatch (method , candidateMethod , declaringClass ));
134
137
}
135
138
136
- /**
137
- * Searches for the generic {@link Method} declaration whose erased signature
138
- * matches that of the supplied bridge method.
139
- * @throws IllegalStateException if the generic declaration cannot be found
140
- */
141
- private static Method findGenericDeclaration (Method bridgeMethod ) {
142
- // Search parent types for method that has same signature as bridge.
143
- Class <?> superclass = bridgeMethod .getDeclaringClass ().getSuperclass ();
144
- while (superclass != null && Object .class != superclass ) {
145
- Method method = searchForMatch (superclass , bridgeMethod );
146
- if (method != null && !method .isBridge ()) {
147
- return method ;
148
- }
149
- superclass = superclass .getSuperclass ();
150
- }
151
-
152
- // Search interfaces.
153
- Class <?>[] interfaces = ClassUtils .getAllInterfacesForClass (bridgeMethod .getDeclaringClass ());
154
- for (Class <?> ifc : interfaces ) {
155
- Method method = searchForMatch (ifc , bridgeMethod );
156
- if (method != null && !method .isBridge ()) {
157
- return method ;
158
- }
159
- }
160
-
161
- return null ;
162
- }
163
-
164
139
/**
165
140
* Returns {@code true} if the {@link Type} signature of both the supplied
166
141
* {@link Method#getGenericParameterTypes() generic Method} and concrete {@link Method}
167
142
* are equal after resolving all types against the declaringType, otherwise
168
143
* returns {@code false}.
169
144
*/
170
- private static boolean isResolvedTypeMatch (
171
- Method genericMethod , Method candidateMethod , Class <?> declaringClass ) {
145
+ private static boolean isResolvedTypeMatch (Method genericMethod , Method candidateMethod , Class <?> declaringClass ) {
172
146
Type [] genericParameters = genericMethod .getGenericParameterTypes ();
173
147
Class <?>[] candidateParameters = candidateMethod .getParameterTypes ();
174
148
if (genericParameters .length != candidateParameters .length ) {
@@ -191,13 +165,51 @@ private static boolean isResolvedTypeMatch(
191
165
return true ;
192
166
}
193
167
168
+ /**
169
+ * Searches for the generic {@link Method} declaration whose erased signature
170
+ * matches that of the supplied bridge method.
171
+ * @throws IllegalStateException if the generic declaration cannot be found
172
+ */
173
+ private static Method findGenericDeclaration (Method bridgeMethod ) {
174
+ // Search parent types for method that has same signature as bridge.
175
+ Class <?> superclass = bridgeMethod .getDeclaringClass ().getSuperclass ();
176
+ while (superclass != null && Object .class != superclass ) {
177
+ Method method = searchForMatch (superclass , bridgeMethod );
178
+ if (method != null && !method .isBridge ()) {
179
+ return method ;
180
+ }
181
+ superclass = superclass .getSuperclass ();
182
+ }
183
+
184
+ Class <?>[] interfaces = ClassUtils .getAllInterfacesForClass (bridgeMethod .getDeclaringClass ());
185
+ return searchInterfaces (interfaces , bridgeMethod );
186
+ }
187
+
188
+ private static Method searchInterfaces (Class <?>[] interfaces , Method bridgeMethod ) {
189
+ for (Class <?> ifc : interfaces ) {
190
+ Method method = searchForMatch (ifc , bridgeMethod );
191
+ if (method != null && !method .isBridge ()) {
192
+ return method ;
193
+ }
194
+ else {
195
+ return searchInterfaces (ifc .getInterfaces (), bridgeMethod );
196
+ }
197
+ }
198
+ return null ;
199
+ }
200
+
194
201
/**
195
202
* If the supplied {@link Class} has a declared {@link Method} whose signature matches
196
203
* that of the supplied {@link Method}, then this matching {@link Method} is returned,
197
204
* otherwise {@code null} is returned.
198
205
*/
199
206
private static Method searchForMatch (Class <?> type , Method bridgeMethod ) {
200
- return ReflectionUtils .findMethod (type , bridgeMethod .getName (), bridgeMethod .getParameterTypes ());
207
+ try {
208
+ return type .getDeclaredMethod (bridgeMethod .getName (), bridgeMethod .getParameterTypes ());
209
+ }
210
+ catch (NoSuchMethodException ex ) {
211
+ return null ;
212
+ }
201
213
}
202
214
203
215
/**
0 commit comments