PsiClass[] (final PsiClass aClass, final PsiClass bClass) { if (InheritanceUtil.isInheritorOrSelf(aClass, bClass, true)) { return new PsiClass[]{aClass}; } if (InheritanceUtil.isInheritorOrSelf(bClass, aClass, true)) { return new PsiClass[]{bClass}; } final Set<PsiClass> descendants = new LinkedHashSet<>(); new Object() { public void getGreatestLowerClasses(final PsiClass aClass, final PsiClass bClass, final Set<? super PsiClass> descendants) { if (bClass.hasModifierProperty(PsiModifier.FINAL)) return; if (aClass.isInheritor(bClass, true)) { descendants.add(aClass); } else { for (PsiClass bInheritor : ClassInheritorsSearch.search(bClass, false)) { getGreatestLowerClasses(bInheritor, aClass, descendants); } } } }.getGreatestLowerClasses(aClass, bClass, descendants); return descendants.toArray(PsiClass.EMPTY_ARRAY); }