PsiClass (PsiElement element) { if (element instanceof PsiIdentifier) { final PsiElement parent = element.getParent(); if (parent instanceof PsiClass psiClass) { return isEmptyClass(psiClass) && DirectClassInheritorsSearch.search(psiClass).findFirst() != null ? psiClass : null; } } PsiJavaCodeReferenceElement ref = PsiTreeUtil.getNonStrictParentOfType(element, PsiJavaCodeReferenceElement.class); if (ref == null) return null; final PsiReferenceList referenceList = PsiTreeUtil.getParentOfType(ref, PsiReferenceList.class); if (referenceList == null) return null; final PsiClass psiClass = PsiTreeUtil.getParentOfType(referenceList, PsiClass.class); if (psiClass == null) return null; if (psiClass.getExtendsList() != referenceList && psiClass.getImplementsList() != referenceList) return null; final PsiElement target = ref.resolve(); if (!(target instanceof PsiClass targetClass)) return null; return isEmptyClass(targetClass) ? targetClass : null; }