PsiClass (@NotNull PsiClass superClass, PsiClass upperBound, PsiElement context) { final Query<PsiClass> search = DirectClassInheritorsSearch.search(superClass, context.getResolveScope()); final Project project = superClass.getProject(); for (PsiClass aClass : search) { ProgressManager.checkCanceled(); if (aClass.isInheritor(superClass, true) && upperBound.isInheritor(aClass, true)) { if (PsiUtil.isAccessible(project, aClass, context, null)) { return aClass; } else { return getVisibleInheritor(aClass, upperBound, context); } } } return null; }