private void handleDocument(final @NotNull Document document) {
    VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
    if (virtualFile == null) return;
    Project project = guessProject(virtualFile);
    while(true) {
      if (project != null && project.isDisposed()) break;
      int nRequests = addNumberOfRequestedRedetects(document, 0);
      Charset charset = LoadTextUtil.charsetFromContentOrNull(project, virtualFile, document.getImmutableCharSequence());
      Charset oldCached = getCachedCharsetFromContent(document);
      if (!Comparing.equal(charset, oldCached)) {
        setCachedCharsetFromContent(charset, oldCached, document);
      }
      if (addNumberOfRequestedRedetects(document, -nRequests) == 0) break;
    }
  }
private void handleDocument(final @NotNull Document document)