protected void runInspections(@NotNull Project project,
                                @NotNull AnalysisScope scope) {
    int runId = ++myRunId;
    scope.setSearchInLibraries(false);
    FileDocumentManager.getInstance().saveAllDocuments();

    InspectionProfileImpl externalProfile = myExternalProfile;
    final GlobalInspectionContextImpl inspectionContext = getGlobalInspectionContext(project);
    inspectionContext.setRerunAction(() -> DumbService.getInstance(project).smartInvokeLater(() -> {
      //someone called the runInspections before us, we cannot restore the state
      if (runId != myRunId) return;
      if (project.isDisposed()) return;
      if (!scope.isValid()) return;

      //restore current state
      myExternalProfile = externalProfile;
      myGlobalInspectionContext = inspectionContext;

      FileDocumentManager.getInstance().saveAllDocuments();
      analyze(project, scope);
    }));

    inspectionContext.setExternalProfile(externalProfile);
    inspectionContext.setCurrentScope(scope);
    inspectionContext.doInspections(scope);
  }
protected void runInspections(@NotNull Project project,
                                @NotNull AnalysisScope scope)