/** * Collects the parameterized type declarations for a given field. */ public static Class<?>[] getParameterizedTypes(Field f) { try { return collectParameterizedTypes(f.getGenericType(), f.getType()); } catch (Exception e) { return EMPTY_CLASSES; } }
/** * Collects the parameterized return type declarations for a given method. */ public static Class<?>[] getParameterizedTypes(Method meth) { try { return collectParameterizedTypes(meth.getGenericReturnType(), meth.getReturnType()); } catch (Exception e) { return EMPTY_CLASSES; } }
/** * Collects the parameterized type declarations for a given field. */ public static Class<?>[] getParameterizedTypes(Field f) { try { return collectParameterizedTypes(f.getGenericType(), f.getType()); } catch (Exception e) { return EMPTY_CLASSES; } }
/** * Collects the parameterized return type declarations for a given method. */ public static Class<?>[] getParameterizedTypes(Method meth) { try { return collectParameterizedTypes(meth.getGenericReturnType(), meth.getReturnType()); } catch (Exception e) { return EMPTY_CLASSES; } }
/** * Collects the parameterized type declarations for a given field. */ public static Class<?>[] getParameterizedTypes(Field f) { try { return collectParameterizedTypes(f.getGenericType(), f.getType()); } catch (Exception e) { return EMPTY_CLASSES; } }
/** * Collects the parameterized return type declarations for a given method. */ public static Class<?>[] getParameterizedTypes(Method meth) { try { return collectParameterizedTypes(meth.getGenericReturnType(), meth.getReturnType()); } catch (Exception e) { return EMPTY_CLASSES; } }
/** * Collects the parameterized type declarations for a given field. */ public static Class[] getParameterizedTypes(Field f) { if (f == null) return null; if (VERSION < 5) return EMPTY_CLASSES; try { Object type = Field.class.getMethod("getGenericType", (Class[]) null).invoke(f, (Object[]) null); return collectParameterizedTypes(type); } catch (Exception e) { return EMPTY_CLASSES; } }
/** * Collects the parameterized return type declarations for a given method. */ public static Class[] getParameterizedTypes(Method meth) { if (meth == null) return null; if (VERSION < 5) return EMPTY_CLASSES; try { Object type = Method.class.getMethod("getGenericReturnType", (Class[]) null).invoke(meth, (Object[]) null); return collectParameterizedTypes(type); } catch (Exception e) { return EMPTY_CLASSES; } }
/** * Return all parameterized classes for the given type. */ private static Class<?>[] collectParameterizedTypes(Type type, Class<?> cls) throws Exception { if (type instanceof ParameterizedType) { Type[] args = ((ParameterizedType)type).getActualTypeArguments(); Class<?>[] clss = new Class[args.length]; for (int i = 0; i < args.length; i++) { Class<?> c = extractClass(args[i]); if (c == null) { return EMPTY_CLASSES; } clss[i] = c; } return clss; } else if (cls.getSuperclass() != Object.class) { return collectParameterizedTypes(cls.getGenericSuperclass(), cls.getSuperclass()); } else { return EMPTY_CLASSES; } }
/** * Return all parameterized classes for the given type. */ private static Class<?>[] collectParameterizedTypes(Type type, Class<?> cls) throws Exception { if (type instanceof ParameterizedType) { Type[] args = ((ParameterizedType)type).getActualTypeArguments(); Class<?>[] clss = new Class[args.length]; for (int i = 0; i < args.length; i++) { Class<?> c = extractClass(args[i]); if (c == null) { return EMPTY_CLASSES; } clss[i] = c; } return clss; } else if (cls.getSuperclass() != Object.class) { return collectParameterizedTypes(cls.getGenericSuperclass(), cls.getSuperclass()); } else { return EMPTY_CLASSES; } }
/** * Return all parameterized classes for the given type. */ private static Class<?>[] collectParameterizedTypes(Type type, Class<?> cls) throws Exception { if (type instanceof ParameterizedType) { Type[] args = ((ParameterizedType)type).getActualTypeArguments(); Class<?>[] clss = new Class[args.length]; for (int i = 0; i < args.length; i++) { Class<?> c = extractClass(args[i]); if (c == null) { return EMPTY_CLASSES; } clss[i] = c; } return clss; } else if (cls.getSuperclass() != Object.class) { return collectParameterizedTypes(cls.getGenericSuperclass(), cls.getSuperclass()); } else { return EMPTY_CLASSES; } }