/** * Little helper to allow us to create a generified map, actually just to satisfy the compiler. * * @param type must not be {@literal null}. * @return */ private static Map<TypeVariable<?>, Type> getTypeVariableMap(Class<?> type) { return getTypeVariableMap(type, new HashSet<>()); }
/** * Creates {@link ClassTypeInformation} for the given type. * * @param type */ ClassTypeInformation(Class<S> type) { super(ProxyUtils.getUserClass(type), getTypeVariableMap(type)); this.type = type; }
private static Map<TypeVariable<?>, Type> getTypeVariableMap(Class<?> type, Collection<Type> visited) { if (visited.contains(type)) { return Collections.emptyMap(); } else { visited.add(type); } Map<TypeVariable, Type> source = GenericTypeResolver.getTypeVariableMap(type); Map<TypeVariable<?>, Type> map = new HashMap<>(source.size()); for (Entry<TypeVariable, Type> entry : source.entrySet()) { Type value = entry.getValue(); map.put(entry.getKey(), entry.getValue()); if (value instanceof Class) { for (Entry<TypeVariable<?>, Type> nestedEntry : getTypeVariableMap((Class<?>) value, visited).entrySet()) { if (!map.containsKey(nestedEntry.getKey())) { map.put(nestedEntry.getKey(), nestedEntry.getValue()); } } } } return map; }