1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2020 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.
@@ -533,7 +533,7 @@ public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz) {
533
533
* @param lhsType the target type
534
534
* @param rhsType the value type that should be assigned to the target type
535
535
* @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)
537
537
*/
538
538
public static boolean isAssignable (Class <?> lhsType , Class <?> rhsType ) {
539
539
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
1088
1088
}
1089
1089
}
1090
1090
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
-
1104
1091
/**
1105
1092
* Determine whether the given class has a public method with the given signature.
1106
1093
* @param clazz the clazz to analyze
1107
- * @param method checked method
1094
+ * @param method the method to look for
1108
1095
* @return whether the class has a corresponding method
1109
- * @see Method#getDeclaringClass
1096
+ * @since 5.2.3
1110
1097
*/
1111
1098
public static boolean hasMethod (Class <?> clazz , Method method ) {
1112
1099
Assert .notNull (clazz , "Class must not be null" );
@@ -1119,6 +1106,19 @@ public static boolean hasMethod(Class<?> clazz, Method method) {
1119
1106
return getMethodOrNull (clazz , methodName , paramTypes ) != null ;
1120
1107
}
1121
1108
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
+
1122
1122
/**
1123
1123
* Determine whether the given class has a public method with the given signature,
1124
1124
* and return it if available (else throws an {@code IllegalStateException}).
@@ -1373,6 +1373,17 @@ public static Method getStaticMethod(Class<?> clazz, String methodName, Class<?>
1373
1373
}
1374
1374
}
1375
1375
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
+
1376
1387
private static Set <Method > findMethodCandidatesByName (Class <?> clazz , String methodName ) {
1377
1388
Set <Method > candidates = new HashSet <>(1 );
1378
1389
Method [] methods = clazz .getMethods ();
@@ -1384,12 +1395,4 @@ private static Set<Method> findMethodCandidatesByName(Class<?> clazz, String met
1384
1395
return candidates ;
1385
1396
}
1386
1397
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
- }
1395
1398
}
0 commit comments