private static CachedValueProvider.Result<Runnable> getUpdateResult(@NotNull PsiFile file,
                                                                      @NotNull Document document,
                                                                      boolean quick,
                                                                      Project project,
                                                                      Editor editor,
                                                                      boolean applyDefaultState) {
    PsiUtilCore.ensureValid(file);
    List<RegionInfo> elementsToFold = getFoldingsFor(file, quick);
    UpdateFoldRegionsOperation operation = new UpdateFoldRegionsOperation(project, editor, file, elementsToFold,
                                                                                applyDefaultStateMode(applyDefaultState),
                                                                                !applyDefaultState, false);
    int documentLength = document.getTextLength();
    AtomicBoolean alreadyExecuted = new AtomicBoolean();
    Runnable runnable = () -> {
      if (alreadyExecuted.compareAndSet(false, true)) {
        if (documentLength != document.getTextLength() || !PsiDocumentManager.getInstance(project).isCommitted(document)) {
          reportUnexpectedDocumentChange(file, document, documentLength);
        }
        editor.getFoldingModel().runBatchFoldingOperationDoNotCollapseCaret(operation);
      }
    };
    Set<Object> dependencies = new HashSet<>();
    dependencies.add(file);
    dependencies.add(editor.getFoldingModel());
    for (RegionInfo info : elementsToFold) {
      dependencies.addAll(info.descriptor.getDependencies());
    }
    return CachedValueProvider.Result.create(runnable, ArrayUtil.toObjectArray(dependencies));
  }
private static CachedValueProvider.Result<Runnable> getUpdateResult(@NotNull PsiFile file,
                                                                      @NotNull Document document,
                                                                      boolean quick,
                                                                      Project project,
                                                                      Editor editor,
                                                                      boolean applyDefaultState)