boolean (@NotNull final PsiElement element, @NotNull final Editor editor, @NotNull PsiFile file, @NotNull DataContext context) { final PsiElement targetElement = file.findElementAt(editor.getCaretModel().getOffset()); if (PsiTreeUtil.getParentOfType(targetElement, PsiAnonymousClass.class) != null) { return true; } if (PsiTreeUtil.getParentOfType(element, PsiAnonymousClass.class) != null) { return true; } final PsiNewExpression newExpression = PsiTreeUtil.getParentOfType(element, PsiNewExpression.class); return newExpression != null && newExpression.getAnonymousClass() != null; }