/** * Extracts the class from the given argument, if possible. Null otherwise. */ static Class<?> extractClass(Type type) throws Exception { if (type instanceof Class) { return (Class<?>)type; } else if (type instanceof ParameterizedType) { return extractClass(((ParameterizedType)type).getRawType()); } return null; } }
/** * Extracts the class from the given argument, if possible. Null otherwise. */ static Class<?> extractClass(Type type) throws Exception { if (type instanceof Class) { return (Class<?>)type; } else if (type instanceof ParameterizedType) { return extractClass(((ParameterizedType)type).getRawType()); } return null; } }
/** * Extracts the class from the given argument, if possible. Null otherwise. */ static Class<?> extractClass(Type type) throws Exception { if (type instanceof Class) { return (Class<?>)type; } else if (type instanceof ParameterizedType) { return extractClass(((ParameterizedType)type).getRawType()); } return null; } }
/** * 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; } }