@TestOnly
 public void prepareForTest() {
   if (!myInitialized) {
     projectOpened();
   }
   setUpdateByTimerEnabled(false);
   waitForTermination();
 }
 @TestOnly
 public void cleanupAfterTest(boolean dispose) {
   if (!myProject.isOpen()) return;
   stopProcess(false);
   if (dispose) {
     projectClosed();
     Disposer.dispose(myStatusBarUpdater);
     myStatusBarUpdater = null;
     Disposer.dispose(myDaemonListeners);
     myDaemonListeners = null;
   }
   setUpdateByTimerEnabled(false);
   waitForTermination();
 }
  @TestOnly
  public List<HighlightInfo> runPasses(
      @NotNull PsiFile file,
      @NotNull Document document,
      @NotNull TextEditor textEditor,
      @NotNull int[] toIgnore,
      boolean canChangeDocument,
      @Nullable Runnable callbackWhileWaiting) {
    assert myInitialized;
    assert !myDisposed;
    Application application = ApplicationManager.getApplication();
    application.assertIsDispatchThread();
    assert !application.isWriteAccessAllowed();

    // pump first so that queued event do not interfere
    UIUtil.dispatchAllInvocationEvents();
    UIUtil.dispatchAllInvocationEvents();

    Project project = file.getProject();
    setUpdateByTimerEnabled(false);
    FileStatusMap fileStatusMap = getFileStatusMap();
    for (int ignoreId : toIgnore) {
      fileStatusMap.markFileUpToDate(document, ignoreId);
    }
    fileStatusMap.allowDirt(canChangeDocument);

    TextEditorBackgroundHighlighter highlighter =
        (TextEditorBackgroundHighlighter) textEditor.getBackgroundHighlighter();
    final List<TextEditorHighlightingPass> passes = highlighter.getPasses(toIgnore);
    HighlightingPass[] array = passes.toArray(new HighlightingPass[passes.size()]);

    final DaemonProgressIndicator progress = createUpdateProgress();
    progress.setDebug(LOG.isDebugEnabled());
    myPassExecutorService.submitPasses(
        Collections.singletonMap((FileEditor) textEditor, array), progress, Job.DEFAULT_PRIORITY);
    try {
      while (progress.isRunning()) {
        try {
          if (progress.isCanceled() && progress.isRunning()) {
            // write action sneaked in the AWT. restart
            waitForTermination();
            Throwable savedException = PassExecutorService.getSavedException(progress);
            if (savedException != null) throw savedException;
            return runPasses(
                file, document, textEditor, toIgnore, canChangeDocument, callbackWhileWaiting);
          }
          if (callbackWhileWaiting != null) {
            callbackWhileWaiting.run();
          }
          progress.waitFor(100);
          UIUtil.dispatchAllInvocationEvents();
          Throwable savedException = PassExecutorService.getSavedException(progress);
          if (savedException != null) throw savedException;
        } catch (RuntimeException e) {
          throw e;
        } catch (Error e) {
          e.printStackTrace();
          throw e;
        } catch (Throwable e) {
          e.printStackTrace();
          throw new RuntimeException(e);
        }
      }
      UIUtil.dispatchAllInvocationEvents();
      UIUtil.dispatchAllInvocationEvents();

      return getHighlights(document, null, project);
    } finally {
      fileStatusMap.allowDirt(true);
      waitForTermination();
    }
  }