private static boolean replaceWithPrintfExpression(PsiPolyadicExpression expression, String formatString,
                                                     List<PsiExpression> formatParameters) {
    final PsiElement expressionParent = expression.getParent();
    if (!(expressionParent instanceof PsiExpressionList)) {
      return false;
    }
    final PsiElement grandParent = expressionParent.getParent();
    if (!(grandParent instanceof PsiMethodCallExpression methodCallExpression)) {
      return false;
    }
    final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
    final String name = methodExpression.getReferenceName();
    final boolean insertNewline;
    if ("println".equals(name)) {
      insertNewline = true;
    }
    else if ("print".equals(name)) {
      insertNewline = false;
    }
    else {
      return false;
    }
    final PsiMethod method = methodCallExpression.resolveMethod();
    if (method == null) {
      return false;
    }
    final PsiClass containingClass = method.getContainingClass();
    if (containingClass == null) {
      return false;
    }
    final String qualifiedName = containingClass.getQualifiedName();
    if (!"java.io.PrintStream".equals(qualifiedName) &&
        !"java.io.PrintWriter".equals(qualifiedName)) {
      return false;
    }
    CommentTracker commentTracker = new CommentTracker();
    final StringBuilder newExpression = new StringBuilder();
    final PsiExpression qualifier = methodExpression.getQualifierExpression();
    if (qualifier != null) {
      newExpression.append(commentTracker.text(qualifier)).append('.');
    }
    newExpression.append("printf(");
    appendFormatString(expression, formatString, insertNewline, newExpression);
    for (PsiExpression formatParameter : formatParameters) {
      newExpression.append(",").append(commentTracker.text(formatParameter));
    }
    newExpression.append(')');
    PsiReplacementUtil.replaceExpression(methodCallExpression, newExpression.toString(), commentTracker);
    return true;
  }
private static boolean replaceWithPrintfExpression(PsiPolyadicExpression expression, String formatString,
                                                     List<PsiExpression> formatParameters)