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