void (Condition<? super PsiTypeParameter> filter, Set<PsiTypeParameter> used) { Stack<PsiTypeParameter> toProcess = new com.intellij.util.containers.Stack<>(); toProcess.addAll(used); while (!toProcess.isEmpty()) { PsiTypeParameter parameter = toProcess.pop(); HashSet<PsiTypeParameter> dependencies = new HashSet<>(); collectTypeParameters(dependencies, parameter, param -> filter.value(param) && !used.contains(param)); used.addAll(dependencies); toProcess.addAll(dependencies); } }