private static String addTerminalOperation(CommentTracker ct,
                                             String methodName,
                                             @NotNull PsiElement contextElement,
                                             @NotNull TerminalBlock tb) {
    String origStream = tb.generate(ct);
    PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(contextElement.getProject());
    PsiMethodCallExpression stream = (PsiMethodCallExpression)elementFactory.createExpressionFromText(origStream, contextElement);
    PsiElement nameElement = stream.getMethodExpression().getReferenceNameElement();
    if (nameElement != null && nameElement.getText().equals("filter")) {
      if (methodName.equals("noneMatch")) {
        // Try to reduce noneMatch(x -> !(condition)) to allMatch(x -> condition)
        PsiExpression[] expressions = stream.getArgumentList().getExpressions();
        if (expressions.length == 1 && expressions[0] instanceof PsiLambdaExpression lambda) {
          PsiElement lambdaBody = lambda.getBody();
          if (lambdaBody instanceof PsiExpression && BoolUtils.isNegation((PsiExpression)lambdaBody)) {
            PsiExpression negated = BoolUtils.getNegated((PsiExpression)lambdaBody);
            LOG.assertTrue(negated != null, lambdaBody.getText());
            lambdaBody.replace(negated);
            methodName = "allMatch";
          }
        }
      }
      nameElement.replace(elementFactory.createIdentifier(methodName));
      return stream.getText();
    }
    return origStream + "." + methodName + "(" + tb.getVariable().getName() + " -> true)";
  }
private static String addTerminalOperation(CommentTracker ct,
                                             String methodName,
                                             @NotNull PsiElement contextElement,
                                             @NotNull TerminalBlock tb)