PsiClass (@NotNull PsiClass containingClass, @Nullable PsiReferenceList referenceList) { if (referenceList != null) { for (PsiJavaCodeReferenceElement referenceElement : referenceList.getReferenceElements()) { if (!referenceElement.isQualified()) { final PsiElement superClass = referenceElement.resolve(); if (superClass instanceof PsiClass) { final PsiClass superContainingClass = ((PsiClass)superClass).getContainingClass(); if (superContainingClass != null && InheritanceUtil.isInheritorOrSelf(containingClass, superContainingClass, true) && !PsiTreeUtil.isAncestor(superContainingClass, containingClass, true)) { return (PsiClass)superClass; } } } } } return null; }