Gets a method by its name and parameter types, accounts for cases where the given class might not be the exact same type as the parameter the method requires, but is a subclass. @param clazz The class to get the method in @param name The name of the method @param argTypes The class types for
(Class<?> clazz, String name, Class<?>[] argTypes)
| 106 | * @return The method in the class, or null if none was found |
| 107 | */ |
| 108 | public static Method getMethod(Class<?> clazz, String name, Class<?>[] argTypes) { |
| 109 | Method[] methods = clazz.getMethods(); |
| 110 | methods: |
| 111 | for (Method method : methods) { |
| 112 | if (!method.getName().equals(name) || method.getParameterCount() != argTypes.length) { |
| 113 | continue; |
| 114 | } |
| 115 | Parameter[] params = method.getParameters(); |
| 116 | for (int i = 0; i < params.length; i++) { |
| 117 | if (!params[i].getType().isAssignableFrom(argTypes[i])) { |
| 118 | continue methods; |
| 119 | } |
| 120 | } |
| 121 | return method; |
| 122 | } |
| 123 | return null; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Gets a constructor by its parameter types, accounts for cases where the given class might not be the |
no test coverage detected