PsiClass (PsiElement element) { PsiClass currentClass; while (true) { currentClass = PsiTreeUtil.getParentOfType(element, PsiClass.class); if (currentClass instanceof PsiAnonymousClass && PsiTreeUtil.isAncestor(((PsiAnonymousClass)currentClass).getArgumentList(), element, false)) { element = currentClass; } else { return currentClass; } } }