static List<ResolvedType> collectReplaceables(ResolvedType replacingType, ResolvedType wildcardType) {
return breadthFirstSearch(replacingType, wildcardType);
}
private static List<ResolvedType> breadthFirstSearch(ResolvedType replacingType, ResolvedType wildcardType) {
TypeBindings wildcardTypeBindings = wildcardType.getTypeBindings();
TypeBindings bindingsToMatch = replacingType.getTypeBindings();
Preconditions.checkArgument(typeBindingsAreOfSameSize(wildcardType, replacingType));
List<ResolvedType> bindings = newArrayList();
for (int index = 0; index < bindingsToMatch.size(); index++) {
if (WildcardType.class.equals(wildcardTypeBindings.getBoundType(index).getErasedType())) {
bindings.add(bindingsToMatch.getBoundType(index));
} else {
bindings.addAll(breadthFirstSearch(bindingsToMatch.getBoundType(index),
wildcardTypeBindings.getBoundType(index)));
}
}
return bindings;
}