PsiClass (@NotNull PsiClass fromIncl, @NotNull PsiClass toIncl, @NotNull Collection<String> stopClasses) { for (PsiClass superClass : InheritanceUtil.getSuperClasses(fromIncl)) { if (!superClass.isInheritor(toIncl, true)) continue; if (stopClasses.contains(getClassName(superClass))) { return superClass; } } return toIncl; }