private void applyFix(@NotNull PsiExpression expression, @NotNull PsiStatement @NotNull [] sideEffects) {
    if (sideEffects.length > 0) {
      CodeBlockSurrounder surrounder = Objects.requireNonNull(CodeBlockSurrounder.forExpression(expression));
      CodeBlockSurrounder.SurroundResult result = surrounder.surround();
      expression = result.getExpression();
      BlockUtils.addBefore(result.getAnchor(), sideEffects);
    }
    PsiMethodCallExpression call = expression.getParent() instanceof PsiExpressionList list &&
                                   list.getParent() instanceof PsiMethodCallExpression grandParent ? grandParent : null;
    PsiMethod targetMethod = null;
    PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;
    if (call != null) {
      JavaResolveResult result = call.resolveMethodGenerics();
      substitutor = result.getSubstitutor();
      targetMethod = ObjectUtils.tryCast(result.getElement(), PsiMethod.class);
    }

    new CommentTracker().replaceAndRestoreComments(expression, myReplacementText);

    if (targetMethod != null) {
      ExtractMethodUtil.addCastsToEnsureResolveTarget(targetMethod, substitutor, call);
    }
  }
private void applyFix(@NotNull PsiExpression expression, @NotNull PsiStatement @NotNull [] sideEffects)