private static StringBuilder createReplacementText(@Nullable PsiExpression expression, StringBuilder out) {
    if (expression instanceof PsiPolyadicExpression polyadicExpression) {
      final PsiElement parent = expression.getParent();
      final boolean parentheses = (parent instanceof PsiConditionalExpression) ||
                                  (parent instanceof PsiInstanceOfExpression) ||
                                  (parent instanceof PsiPolyadicExpression);
      appendText(polyadicExpression, parentheses, out);
    }
    else if (expression instanceof PsiParenthesizedExpression) {
      for (PsiElement child = expression.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child instanceof PsiExpression unwrappedExpression) {
          createReplacementText(unwrappedExpression, out);
        }
        else {
          out.append(child.getText());
        }
      }
    }
    else if (expression instanceof PsiInstanceOfExpression) {
      final PsiElement parent = expression.getParent();
      final boolean parentheses = (parent instanceof PsiPolyadicExpression) || (parent instanceof PsiConditionalExpression);
      appendText(expression, parentheses, out);
    }
    else if (expression instanceof PsiConditionalExpression) {
      final PsiElement parent = expression.getParent();
      final boolean parentheses = (parent instanceof PsiConditionalExpression) || (parent instanceof PsiPolyadicExpression) ||
                                  (parent instanceof PsiInstanceOfExpression);
      appendText(expression, parentheses, out);
    }
    else if (expression instanceof PsiAssignmentExpression assignmentExpression) {
      final PsiElement parent = expression.getParent();
      final boolean parentheses = !isSimpleAssignment(assignmentExpression, parent);
      appendText(assignmentExpression, parentheses, out);
    }
    else if (expression != null) {
      out.append(expression.getText());
    }
    return out;
  }
private static StringBuilder createReplacementText(@Nullable PsiExpression expression, StringBuilder out)