boolean (@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { if (startElement instanceof PsiNewExpression) { final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project); String startElementText = startElement.getText(); try { PsiNewExpression newExpression = (PsiNewExpression)elementFactory.createExpressionFromText(startElementText + "{}", startElement); if (newExpression.getAnonymousClass() == null) { try { newExpression = (PsiNewExpression)elementFactory.createExpressionFromText(startElementText + "){}", startElement); } catch (IncorrectOperationException e) { return false; } if (newExpression.getAnonymousClass() == null) return false; } } catch (IncorrectOperationException e) { return false; } return true; } return false; }