void (@NotNull PsiElement expression) { if (!(expression instanceof PsiExpression)) { return; } if (expression.getParent() instanceof PsiMethodCallExpression) { expression = expression.getParent(); } while (expression.getParent() instanceof PsiPrefixExpression && ((PsiPrefixExpression)expression.getParent()).getOperationTokenType() == JavaTokenType.EXCL) { expression = expression.getParent(); } if (expression instanceof PsiMethodReferenceExpression) { final PsiExpression callExpression = LambdaRefactoringUtil.convertToMethodCallInLambdaBody((PsiMethodReferenceExpression)expression); if (callExpression instanceof PsiCallExpression) { PsiExpression negatedExpression = JavaPsiFacade.getElementFactory(callExpression.getProject()) .createExpressionFromText(BoolUtils.getNegatedExpressionText(callExpression), callExpression); callExpression.replace(negatedExpression); } } else if (!(expression.getParent() instanceof PsiExpressionStatement) || isOperatorAssignment(expression)) { PsiExpression negatedExpression = JavaPsiFacade.getElementFactory(expression.getProject()) .createExpressionFromText(BoolUtils.getNegatedExpressionText((PsiExpression)expression), expression); expression.replace(negatedExpression); } }