public static Type resolveVariableInHierarchy(@NotNull TypeVariable variable, @NotNull Class aClass) { Type type; Class current = aClass; while ((type = resolveVariable(variable, current, false)) == null) { current = current.getSuperclass(); if (current == null) { return null; } } if (type instanceof TypeVariable) { return resolveVariableInHierarchy((TypeVariable)type, aClass); } return type; }
@Nullable public static Type resolveVariable(@NotNull TypeVariable variable, @NotNull Class classType) { return resolveVariable(variable, classType, true); }
@Nullable public static Class<?> substituteGenericType(@NotNull Type genericType, @NotNull Type classType) { if (genericType instanceof TypeVariable) { final Class<?> aClass = getRawType(classType); final Type type = resolveVariable((TypeVariable)genericType, aClass); if (type instanceof Class) { return (Class)type; } if (type instanceof ParameterizedType) { return (Class<?>)((ParameterizedType)type).getRawType(); } if (type instanceof TypeVariable && classType instanceof ParameterizedType) { final int index = ArrayUtilRt.find(aClass.getTypeParameters(), type); if (index >= 0) { return getRawType(getActualTypeArguments((ParameterizedType)classType)[index]); } } } else { return getRawType(genericType); } return null; }
final Type resolved = resolveVariable(variable, anInterface); if (resolved instanceof Class || resolved instanceof ParameterizedType) { return resolved;