PsiElement (PsiClass anonOrLocalClass) { PsiElement parent = anonOrLocalClass.getParent(); while (true) { if (parent instanceof PsiClass && !(parent instanceof PsiAnonymousClass)) { return parent; } if (parent instanceof PsiFile) { return parent; } parent = parent.getParent(); } }