PsiClass (@Nullable PsiElement element) { PsiClass domainClass = PsiTreeUtil.getParentOfType(element, PsiClass.class); if (domainClass == null) return null; while (true) { PsiClass c = domainClass.getContainingClass(); if (c == null) return domainClass; domainClass = c; } }