List of utility methods to do Reflection Method Parameter
List | getMethodGenericParameterTypes(Method method, int index) get Method Generic Parameter Types List<Class> results = new ArrayList<Class>(); Type[] genericParameterTypes = method.getGenericParameterTypes(); if (index >= genericParameterTypes.length || index < 0) { throw new IllegalArgumentException("index " + (index < 0 ? " must > 0 " : " over total arguments")); Type genericParameterType = genericParameterTypes[index]; if (genericParameterType instanceof ParameterizedType) { ParameterizedType aType = (ParameterizedType) genericParameterType; ... |
MethodHandle | getMethodHandle(final Lookup lookup, final Class get Method Handle return unreflect(lookup, getMethod(receiver, methodName, parameterTypes));
|
String | getMethodName(Method method, Class>[] parameterClasses, String rightCode) get Method Name if (method.getParameterTypes().length > parameterClasses.length) { Class<?>[] types = method.getParameterTypes(); StringBuilder buf = new StringBuilder(rightCode); for (int i = parameterClasses.length; i < types.length; i++) { if (buf.length() > 0) { buf.append(","); Class<?> type = types[i]; ... |
List | getMethodParameterAnnotations(Method method, int index, Class annotationClass) Get Annotation s of the provided class associated to the the provided method parameter. Annotation[][] parametersAnnotations = method.getParameterAnnotations(); Annotation[] parameterAnnotations = parametersAnnotations[index]; List<A> foundAnnotations = new ArrayList<A>(); for (Annotation annotation : parameterAnnotations) { if (annotationClass.isInstance(annotation)) { foundAnnotations.add((A) annotation); return foundAnnotations; |
Map | getMethodParameterIndexes(final Method m) Try to determine the names of the method parameters. if ((GETPARAMETERS == null) || (m == null)) { return Collections.emptyMap(); Map<String, Integer> paramNames = new HashMap<String, Integer>(); try { Object[] params = (Object[]) GETPARAMETERS.invoke(m); if (params.length == 0) { return Collections.emptyMap(); ... |
List | getMethodParameters(final Method method, final Map Resolve generics in method parameters. final List<Class<?>> params = new ArrayList<Class<?>>(); for (Type type : method.getGenericParameterTypes()) { params.add(resolveClass(type, generics)); return params; |
Class>[] | getMethodParametersType(Class> clazz, String methodName) Get the method parameter type array for (Method method : clazz.getMethods()) { if (method.getName().equals(methodName)) { return method.getParameterTypes(); throw new NoSuchMethodException( "No such method is paresent in " + clazz.getName() + " of name " + methodName); |
Class[] | getMethodParameterTypes(final Method method) Get the list of parameter types for a given method. return method.getParameterTypes();
|
Method | getMethodQuietly(Class> clazz, String methodName, Class>... parameterTypes) get Method Quietly try { return clazz.getMethod(methodName, parameterTypes); } catch (NoSuchMethodException ex) { return null; |
Method | getMethodRecursive(final Class> clazz, final String methodName, final Class>... parameterTypes) get Method Recursive final Method m = getMethod(clazz, methodName, parameterTypes); if (m != null) return m; final Class<?> superclazz = clazz.getSuperclass(); if (superclazz == null) return null; return getMethodRecursive(superclazz, methodName, parameterTypes); |