Skip to content

Commit c39ed52

Browse files
committed
Add since tag to hasMethod(Class, Method)
See gh-24282
1 parent 8e5cad2 commit c39ed52

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

spring-core/src/main/java/org/springframework/util/ClassUtils.java

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -533,7 +533,7 @@ public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz) {
533533
* @param lhsType the target type
534534
* @param rhsType the value type that should be assigned to the target type
535535
* @return if the target type is assignable from the value type
536-
* @see TypeUtils#isAssignable
536+
* @see TypeUtils#isAssignable(java.lang.reflect.Type, java.lang.reflect.Type)
537537
*/
538538
public static boolean isAssignable(Class<?> lhsType, Class<?> rhsType) {
539539
Assert.notNull(lhsType, "Left-hand side type must not be null");
@@ -1088,25 +1088,12 @@ public static <T> Constructor<T> getConstructorIfAvailable(Class<T> clazz, Class
10881088
}
10891089
}
10901090

1091-
/**
1092-
* Determine whether the given class has a public method with the given signature.
1093-
* <p>Essentially translates {@code NoSuchMethodException} to "false".
1094-
* @param clazz the clazz to analyze
1095-
* @param methodName the name of the method
1096-
* @param paramTypes the parameter types of the method
1097-
* @return whether the class has a corresponding method
1098-
* @see Class#getMethod
1099-
*/
1100-
public static boolean hasMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) {
1101-
return (getMethodIfAvailable(clazz, methodName, paramTypes) != null);
1102-
}
1103-
11041091
/**
11051092
* Determine whether the given class has a public method with the given signature.
11061093
* @param clazz the clazz to analyze
1107-
* @param method checked method
1094+
* @param method the method to look for
11081095
* @return whether the class has a corresponding method
1109-
* @see Method#getDeclaringClass
1096+
* @since 5.2.3
11101097
*/
11111098
public static boolean hasMethod(Class<?> clazz, Method method) {
11121099
Assert.notNull(clazz, "Class must not be null");
@@ -1119,6 +1106,19 @@ public static boolean hasMethod(Class<?> clazz, Method method) {
11191106
return getMethodOrNull(clazz, methodName, paramTypes) != null;
11201107
}
11211108

1109+
/**
1110+
* Determine whether the given class has a public method with the given signature.
1111+
* <p>Essentially translates {@code NoSuchMethodException} to "false".
1112+
* @param clazz the clazz to analyze
1113+
* @param methodName the name of the method
1114+
* @param paramTypes the parameter types of the method
1115+
* @return whether the class has a corresponding method
1116+
* @see Class#getMethod
1117+
*/
1118+
public static boolean hasMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) {
1119+
return (getMethodIfAvailable(clazz, methodName, paramTypes) != null);
1120+
}
1121+
11221122
/**
11231123
* Determine whether the given class has a public method with the given signature,
11241124
* and return it if available (else throws an {@code IllegalStateException}).
@@ -1373,6 +1373,17 @@ public static Method getStaticMethod(Class<?> clazz, String methodName, Class<?>
13731373
}
13741374
}
13751375

1376+
1377+
@Nullable
1378+
private static Method getMethodOrNull(Class<?> clazz, String methodName, Class<?>[] paramTypes) {
1379+
try {
1380+
return clazz.getMethod(methodName, paramTypes);
1381+
}
1382+
catch (NoSuchMethodException ex) {
1383+
return null;
1384+
}
1385+
}
1386+
13761387
private static Set<Method> findMethodCandidatesByName(Class<?> clazz, String methodName) {
13771388
Set<Method> candidates = new HashSet<>(1);
13781389
Method[] methods = clazz.getMethods();
@@ -1384,12 +1395,4 @@ private static Set<Method> findMethodCandidatesByName(Class<?> clazz, String met
13841395
return candidates;
13851396
}
13861397

1387-
@Nullable
1388-
private static Method getMethodOrNull(Class<?> clazz, String methodName, Class<?>[] paramTypes) {
1389-
try {
1390-
return clazz.getMethod(methodName, paramTypes);
1391-
} catch (NoSuchMethodException ex) {
1392-
return null;
1393-
}
1394-
}
13951398
}

0 commit comments

Comments
 (0)