List of utility methods to do Reflection Method Parameter
Method | getMethod(final Field visitee, final String methodName, final Class>... parameterTypes) Gets the method specified by methodName for the optionally specified parameterTypes from the specified visitee 's declaring class. Method result = null; try { result = visitee.getDeclaringClass().getMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { throw new RuntimeException("Unable to access method " + methodName + " for field:" + visitee.toString(), e); return result; ... |
Method | getMethod(String classFullName, String methodName, Class>... parameterTypes) get Method Class<?> cls = getClass(classFullName); if (cls == null || "".equals(methodName)) { return null; Method method = null; try { method = cls.getDeclaredMethod(methodName, parameterTypes); } catch (SecurityException | NoSuchMethodException e) { ... |
Method | getMethod0(Class c, String name, Class... parameterTypes) Invokes private Class.getMethod0() without throwing NoSuchMethodException .
try { return (Method) _getMethod0.invoke(c, name, parameterTypes); } catch (Exception ignore) { return null; |
Method | getMethod0(Class> target, String name, Class>[] parameterTypes) get Method try { Method method = target.getDeclaredMethod(name, parameterTypes); method.setAccessible(true); return method; } catch (NoSuchMethodException ignored) { Class<?> superclass = target.getSuperclass(); if (superclass != null) { ... |
Annotation[] | getMethodAnnotations(String className, String methodName, Class>[] parameterTypes) Returns all annotations on the given method try { Class<?> cls = Class.forName(className); if ("<init>".equals(methodName)) { Constructor<?> c = cls.getDeclaredConstructor(parameterTypes); c.setAccessible(true); return c.getAnnotations(); } else { try { ... |
Method | getMethodByName(Class> clazz, String name, Class>... parameterTypes) get Method By Name return getMethodByName(clazz, null, name, parameterTypes);
|
Method | getMethodByParametersWithAnnotation(final Class> source, final Class>[] params, final Class extends Annotation> annotation) get Method By Parameters With Annotation for (final Method e : source.getDeclaredMethods()) { if (Arrays.deepEquals(e.getParameterTypes(), params)) { if (e.isAnnotationPresent(annotation)) { return e; return null; ... |
Method | getMethodFromClass(String className, String methodName, Class>... parameterTypes) get Method From Class Class<?> c = Class.forName(className);
return c.getMethod(methodName, parameterTypes);
|
Method | getMethodFromClassName(String classAndMethodName, Class>... parameterTypes) Returns a method from the class and method name string. int lastIdx = classAndMethodName.lastIndexOf('.'); if (lastIdx == -1) { throw new IllegalArgumentException("classAndMethodName must be in form of <class>.<method>"); String className = classAndMethodName.substring(0, lastIdx); String methodName = classAndMethodName.substring(lastIdx + 1); Class<?> clazz = Class.forName(className); return clazz.getMethod(methodName, parameterTypes); ... |
String | getMethodFullName(Method m, boolean includeClassPackage, boolean includeParametersType, boolean includeTypesPackage) get Method Full Name String str; str = includeClassPackage ? m.getClass().getName() : m.getClass().getSimpleName() + "." + m.getName() + "("; if (!(m.getParameterTypes().length == 0) && includeParametersType) { for (int i = 0; i < m.getParameterTypes().length; i++) { str = str + (includeTypesPackage ? m.getParameterTypes()[i].getName() : m.getParameterTypes()[i].getSimpleName()); if (!(i == m.getParameterTypes().length - 1)) str = str + ", "; ... |