private static void convertCallExpToRefExpr(PyCallExpression callExpression) {
    PyExpression callee = callExpression.getCallee();
    if (callee == null) {
      throw new PsiInvalidElementAccessException(callExpression);
    }

    String newReferenceExpressionText = callee.getText();

    PyExpression newExpression = PyElementGenerator.getInstance(callExpression.getProject())
      .createExpressionFromText(LanguageLevel.forElement(callExpression), newReferenceExpressionText);

    if (newExpression instanceof PyReferenceExpression referenceExpression) {
      callExpression.replace(referenceExpression);
    }
    else {
      throw new IllegalStateException(
        "Failed to create reference expression from call expression with text: \"" + callExpression.getText() + "\"");
    }
  }
private static void convertCallExpToRefExpr(PyCallExpression callExpression)