List of utility methods to do Reflection Method Name
Method | getMethod(Class> klass, String methodName, Class> requestClass) Gets method with expected methodName, and with one parameter whose type is requestClass or its super class. Class<?> theRequestClass = requestClass; while (theRequestClass != Object.class) { try { return klass.getMethod(methodName, theRequestClass); } catch (SecurityException e) { } catch (NoSuchMethodException e) { theRequestClass = theRequestClass.getSuperclass(); ... |
Method | getMethod(Class> klass, String methodName, Class>... paramTypes) get Method List<Method> candidates = new ArrayList<Method>(); outer: for (Method method : klass.getMethods()) { if (method.getName().equals(methodName)) { Class<?>[] methodParamTypes = method.getParameterTypes(); if (paramTypes.length == methodParamTypes.length || (method.isVarArgs() && paramTypes.length >= methodParamTypes.length - 1)) { if (method.isVarArgs()) { for (int i = 0; i < methodParamTypes.length - 1; i++) { ... |
Method | getMethod(Class> klass, String name, String name2) get Method Method[] methods = klass.getMethods(); for (int i = 0; i < methods.length; ++i) { if (methods[i].getParameterTypes().length == 0) { if (methods[i].getName().equals(name) || methods[i].getName().equals(name2)) return methods[i]; return null; ... |
Method | getMethod(Class> theClass, String methodName, Class>[] paramTypes) get Method Method method = null; try { method = theClass.getDeclaredMethod(methodName, paramTypes); method.setAccessible(true); } catch (NoSuchMethodException | SecurityException e) { if (method == null) { Class<?> superClasss = theClass.getSuperclass(); ... |
Method | getMethod(Class Get the named method from the class try { return c.getMethod(name, argTypes); } catch (NoSuchMethodException e) { throw new IllegalArgumentException(e); |
Method | getMethod(Class get Method Method[] methods = clazz.getDeclaredMethods(); for (Method m : methods) { if (m.getName().equals(methodName)) { return m; methods = clazz.getSuperclass().getDeclaredMethods(); for (Method m : methods) { ... |
Method | getMethod(Class get Method Method[] testMethods = clazz.getMethods(); outer: for (int i = 0; i < testMethods.length; i++) { if (!testMethods[i].getName().equals(methodName)) { continue outer; Class<?>[] testTypes = testMethods[i].getParameterTypes(); if (testTypes.length != calledTypes.length) { continue; ... |
Method | getMethod(Class get Method if (type != null && methodName != null && methodName.length() > 0) { try { if (params != null && params.length > 0 && params[0] != null) { return type.getMethod(methodName, params); } else { return type.getMethod(methodName); } catch (NoSuchMethodException e) { ... |
Method | getMethod(final Class> atClass, final String name, final Class>[] paramType) get Method try { return atClass.getMethod(name, paramType); } catch (Exception e) { try { return atClass.getDeclaredMethod(name, paramType); } catch (Exception e1) { return null; |
Method | getMethod(final Class> clazz, final String methodName, final boolean factoryMethod, final boolean failIfNotFound) get Method if (methodName == null) return null; final Method method = findMethod(clazz, methodName, failIfNotFound); if (method == null && !failIfNotFound) return null; final int methodModifiers = method.getModifiers(); if (Modifier.isAbstract(methodModifiers)) throw new UnsupportedOperationException("Method '" + methodName + "' cannot be abstract"); ... |