/** * Considers the parent's type variable map before invoking the super class method. * * @return */ @SuppressWarnings("rawtypes") protected Map<TypeVariable, Type> getTypeVariableMap() { return parent == null ? super.getTypeVariableMap() : parent.getTypeVariableMap(); }
/** * Creates a new {@link GenericArrayTypeInformation} for the given {@link GenericArrayTypeInformation} and * {@link TypeDiscoverer}. * * @param type * @param parent */ protected GenericArrayTypeInformation(GenericArrayType type, TypeDiscoverer<?> parent) { super(type, parent, parent.getTypeVariableMap()); this.type = type; }
/** * Creates a new {@link ParentTypeAwareTypeInformation}. * * @param type must not be {@literal null}. * @param parent must not be {@literal null}. */ protected ParentTypeAwareTypeInformation(Type type, TypeDiscoverer<?> parent) { this(type, parent, parent.getTypeVariableMap()); }
/** * Resolves the given type into a plain {@link Class}. * * @param type * @return */ @SuppressWarnings("unchecked") protected Class<S> resolveType(Type type) { return (Class<S>) GenericTypeResolver.resolveType(type, getTypeVariableMap()); }
/** * Resolves the given type into a plain {@link Class}. * * @param type * @return */ @SuppressWarnings({ "unchecked", "rawtypes" }) protected Class<S> resolveType(Type type) { Map<TypeVariable, Type> map = new HashMap<>(); map.putAll(getTypeVariableMap()); return (Class<S>) GenericTypeResolver.resolveType(type, map); }
/** * Resolves the type variables to be used. Uses the parent's type variable map but overwrites variables locally * declared. * * @param type must not be {@literal null}. * @param parent must not be {@literal null}. * @return will never be {@literal null}. */ private static Map<TypeVariable<?>, Type> calculateTypeVariables(ParameterizedType type, TypeDiscoverer<?> parent) { Class<?> resolvedType = parent.resolveType(type); TypeVariable<?>[] typeParameters = resolvedType.getTypeParameters(); Type[] arguments = type.getActualTypeArguments(); Map<TypeVariable<?>, Type> localTypeVariables = new HashMap<>(parent.getTypeVariableMap()); IntStream.range(0, typeParameters.length) // .mapToObj(it -> Pair.of(typeParameters[it], flattenTypeVariable(arguments[it], localTypeVariables))) // .forEach(it -> localTypeVariables.put(it.getFirst(), it.getSecond())); return localTypeVariables; }