List of utility methods to do Reflection Method Get from Object
T | getMethodConfigByAnnotaton(Object instance, Class> declaringClass, Class extends Annotation> annotationType, Class get Method Config By Annotaton T result = null; List<Method> methods = new ArrayList<>(); methods.addAll(Arrays.asList(declaringClass.getDeclaredMethods())); methods.addAll(Arrays.asList(declaringClass.getMethods())); for (Method method : methods) { Annotation anno = method.getAnnotation(annotationType); if (anno != null) { method.setAccessible(true); ... |
Method | getMethodDescriptor(Object instance, String methodName, Class extends Object> aClass, Class>... parameters) get Method Descriptor notNull(instance, "instance"); Method method = aClass.getDeclaredMethod(methodName, parameters); method.setAccessible(true); return method; |
Class | getMethodFirstParamType(final String methodName, final Object o) get Method First Param Type Class firstParamType = null; Method[] methods = o.getClass().getMethods(); for (Method method : methods) { if (method.getName().equals(methodName)) { firstParamType = getMethodFirstParamType(method); return (firstParamType); ... |
Method | getMethodIfAny(final Object instance, final String name, final Class[] params) get Method If Any if (null != params && params.length > 0) { return getMethodIfAny(instance.getClass(), name, params); } else { return getMethodIfAny(instance.getClass(), name); |
Method | getMethodIgnoreCaseWithNoParams(Object o, String p) get Method Ignore Case With No Params Class cls = o.getClass(); Method[] methods = cls.getMethods(); int point = 0; Method r = null; for (int i = 0; i < methods.length; i++) { Method m = methods[i]; if (m.getName().equalsIgnoreCase(p) && m.getParameterTypes().length == 0) { return m; ... |
T | getMethodInHolder(String methodName, Object holder) get Method In Holder return getMethodInHolder(methodName, holder, null);
|
Object | getMethodInstace(Class> c, Object inst, String name, Class>[] types, boolean access) same as callMethod, but only returns a reference if (c == null) c = inst.getClass(); try { Method method = null; while (method == null) { try { method = c.getDeclaredMethod(name, types); } catch (NoSuchMethodException e) { ... |
String | getMethodName(AccessibleObject method) get Method Name if (method instanceof Method) { return ((Method) method).getName(); } else if (method instanceof Constructor) { return ((Constructor) method).getName(); throw new IllegalArgumentException("Expected method or constructor"); |
Method | getMethodNamed(String methodName, Object holder) get Method Named Method method = null; List<Method> all = Arrays.asList(holder.getClass().getDeclaredMethods()); for (Method m : all) { if (methodName.equalsIgnoreCase(m.getName())) { method = m; break; return method; |
String[] | getMethodNames(Object obj, boolean hasParent) get Method Names Method[] methods = getMethods(obj, hasParent); int len = methods.length; if (len < 1) { return null; String[] names = new String[len]; for (int i = 0; i < len; i++) { Method m = methods[i]; ... |