static Class<?> determineElementType(Field next) { Class<?> nextElementType = next.getType(); if (List.class.equals(nextElementType)) { nextElementType = ReflectionUtil.getGenericCollectionTypeOfField(next); } else if (Collection.class.isAssignableFrom(nextElementType)) { throw new ConfigurationException("Field '" + next.getName() + "' in type '" + next.getClass().getCanonicalName() + "' is a Collection - Only java.util.List curently supported"); } return nextElementType; }
/** * For a field of type List<Enumeration<Foo>>, returns Foo */ public static Class<?> getGenericCollectionTypeOfFieldWithSecondOrderForList(Field next) { if (!List.class.isAssignableFrom(next.getType())) { return getGenericCollectionTypeOfField(next); } Class<?> type; ParameterizedType collectionType = (ParameterizedType) next.getGenericType(); Type firstArg = collectionType.getActualTypeArguments()[0]; if (ParameterizedType.class.isAssignableFrom(firstArg.getClass())) { ParameterizedType pt = ((ParameterizedType) firstArg); Type pt2 = pt.getActualTypeArguments()[0]; return (Class<?>) pt2; } type = (Class<?>) firstArg; return type; }
static Class<?> determineElementType(Field next) { Class<?> nextElementType = next.getType(); if (List.class.equals(nextElementType)) { nextElementType = ReflectionUtil.getGenericCollectionTypeOfField(next); } else if (Collection.class.isAssignableFrom(nextElementType)) { throw new ConfigurationException("Field '" + next.getName() + "' in type '" + next.getClass().getCanonicalName() + "' is a Collection - Only java.util.List curently supported"); } return nextElementType; }
/** * For a field of type List<Enumeration<Foo>>, returns Foo */ public static Class<?> getGenericCollectionTypeOfFieldWithSecondOrderForList(Field next) { if (!List.class.isAssignableFrom(next.getType())) { return getGenericCollectionTypeOfField(next); } Class<?> type; ParameterizedType collectionType = (ParameterizedType) next.getGenericType(); Type firstArg = collectionType.getActualTypeArguments()[0]; if (ParameterizedType.class.isAssignableFrom(firstArg.getClass())) { ParameterizedType pt = ((ParameterizedType) firstArg); Type pt2 = pt.getActualTypeArguments()[0]; return (Class<?>) pt2; } type = (Class<?>) firstArg; return type; }