LANG-1518 - fix searchSupers for generic classes (#494)
* fix searchSupers for generic classes * fix checkstyle
This commit is contained in:
parent
eb8d069089
commit
f4c2ed4995
|
@ -974,17 +974,13 @@ public class MethodUtils {
|
|||
final Class<?> mcls = method.getDeclaringClass();
|
||||
final List<Class<?>> classes = getAllSuperclassesAndInterfaces(mcls);
|
||||
for (final Class<?> acls : classes) {
|
||||
Method equivalentMethod;
|
||||
try {
|
||||
equivalentMethod = (ignoreAccess ? acls.getDeclaredMethod(method.getName(), method.getParameterTypes())
|
||||
: acls.getMethod(method.getName(), method.getParameterTypes()));
|
||||
} catch (final NoSuchMethodException e) {
|
||||
// if not found, just keep searching
|
||||
continue;
|
||||
}
|
||||
annotation = equivalentMethod.getAnnotation(annotationCls);
|
||||
if (annotation != null) {
|
||||
break;
|
||||
Method equivalentMethod = (ignoreAccess ? MethodUtils.getMatchingMethod(acls, method.getName(), method.getParameterTypes())
|
||||
: MethodUtils.getMatchingAccessibleMethod(acls, method.getName(), method.getParameterTypes()));
|
||||
if (equivalentMethod != null) {
|
||||
annotation = equivalentMethod.getAnnotation(annotationCls);
|
||||
if (annotation != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -799,6 +799,15 @@ public class MethodUtilsTest {
|
|||
Annotated.class, true, true));
|
||||
assertNotNull(MethodUtils.getAnnotation(PublicChild.class.getMethod("publicAnnotatedMethod"),
|
||||
Annotated.class, true, true));
|
||||
|
||||
assertNull(MethodUtils.getAnnotation(StringParameterizedChild.class.getMethod("parentNotAnnotatedMethod", String.class),
|
||||
Annotated.class, true, true));
|
||||
assertNotNull(MethodUtils.getAnnotation(StringParameterizedChild.class.getMethod("parentProtectedAnnotatedMethod", String.class),
|
||||
Annotated.class, true, true));
|
||||
assertNotNull(MethodUtils.getAnnotation(StringParameterizedChild.class.getDeclaredMethod("privateAnnotatedMethod", String.class),
|
||||
Annotated.class, true, true));
|
||||
assertNotNull(MethodUtils.getAnnotation(StringParameterizedChild.class.getMethod("publicAnnotatedMethod", String.class),
|
||||
Annotated.class, true, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -827,6 +836,15 @@ public class MethodUtilsTest {
|
|||
Annotated.class, true, false));
|
||||
assertNotNull(MethodUtils.getAnnotation(PublicChild.class.getMethod("publicAnnotatedMethod"),
|
||||
Annotated.class, true, false));
|
||||
|
||||
assertNull(MethodUtils.getAnnotation(StringParameterizedChild.class.getMethod("parentNotAnnotatedMethod", String.class),
|
||||
Annotated.class, true, false));
|
||||
assertNull(MethodUtils.getAnnotation(StringParameterizedChild.class.getMethod("parentProtectedAnnotatedMethod", String.class),
|
||||
Annotated.class, true, false));
|
||||
assertNull(MethodUtils.getAnnotation(StringParameterizedChild.class.getDeclaredMethod("privateAnnotatedMethod", String.class),
|
||||
Annotated.class, true, false));
|
||||
assertNotNull(MethodUtils.getAnnotation(StringParameterizedChild.class.getMethod("publicAnnotatedMethod", String.class),
|
||||
Annotated.class, true, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -25,4 +25,10 @@ public class GenericParent<T> implements GenericConsumer<T> {
|
|||
public void consume(final T t) {
|
||||
}
|
||||
|
||||
@Annotated
|
||||
protected void parentProtectedAnnotatedMethod(final T t) {
|
||||
}
|
||||
|
||||
public void parentNotAnnotatedMethod(final T t) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,4 +24,19 @@ public class StringParameterizedChild extends GenericParent<String> {
|
|||
public void consume(final String t) {
|
||||
super.consume(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parentProtectedAnnotatedMethod(final String t) {
|
||||
}
|
||||
|
||||
public void parentNotAnnotatedMethod(final String t) {
|
||||
}
|
||||
|
||||
@Annotated
|
||||
private void privateAnnotatedMethod(final String t) {
|
||||
}
|
||||
|
||||
@Annotated
|
||||
public void publicAnnotatedMethod(final String t) {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue