public static PsiElement replaceExpression(PsiExpression expression,
                                             final Project project,
                                             Object conversion,
                                             TypeEvaluator typeEvaluator) {
    if (conversion instanceof TypeConversionDescriptorBase) {
      try {
        return ((TypeConversionDescriptorBase)conversion).replace(expression, typeEvaluator);
      } catch (IncorrectOperationException e) {
        LOG.error(e);
      }
    } else if (conversion instanceof String replacement) {
      try {
        return expression.replace(
            JavaPsiFacade.getElementFactory(project).createExpressionFromText(replacement, expression));
      }
      catch (IncorrectOperationException e) {
        LOG.error(e);
      }
    }
    else if (expression instanceof PsiReferenceExpression reference) {
      final PsiElement resolved = reference.resolve();
      final PsiMember replacer = ((PsiMember)conversion);
      final String method = ((PsiMember)resolved).getName();
      final String ref = expression.getText();
      final String newref = ref.substring(0, ref.lastIndexOf(method)) + replacer.getName();

      if (conversion instanceof PsiMethod) {
        if (resolved instanceof PsiMethod) {
          try {
            return expression.replace(
                JavaPsiFacade.getElementFactory(project).createExpressionFromText(newref, expression));
          }
          catch (IncorrectOperationException e) {
            LOG.error(e);
          }
        }
        else {
          try {
            return expression.replace(JavaPsiFacade.getElementFactory(project).createExpressionFromText(
                newref + "()", expression));
          }
          catch (IncorrectOperationException e) {
            LOG.error(e);
          }
        }
      }
      else if (conversion instanceof PsiField) {
        if (resolved instanceof PsiField) {
          try {
            return expression.replace(
                JavaPsiFacade.getElementFactory(project).createExpressionFromText(newref, expression));
          }
          catch (IncorrectOperationException e) {
            LOG.error(e);
          }
        }
        else {
          final PsiElement parent = Util.getEssentialParent(expression);

          if (parent instanceof PsiMethodCallExpression) {
            try {
              return parent.replace(
                  JavaPsiFacade.getElementFactory(project).createExpressionFromText(newref, expression));
            }
            catch (IncorrectOperationException e) {
              LOG.error(e);
            }
          }
        }
      }
    }
    return expression;
  }
public static PsiElement replaceExpression(PsiExpression expression,
                                             final Project project,
                                             Object conversion,
                                             TypeEvaluator typeEvaluator)