Java 类com.intellij.openapi.project.DumbServiceImpl 实例源码

项目:intellij-ce-playground    文件:RefreshSessionImpl.java   
public RefreshSessionImpl(boolean async, boolean recursive, @Nullable Runnable finishRunnable, @NotNull ModalityState modalityState) {
  myIsAsync = async;
  myIsRecursive = recursive;
  myFinishRunnable = finishRunnable;
  myModalityState = modalityState;
  LOG.assertTrue(modalityState == ModalityState.NON_MODAL || modalityState != ModalityState.any(), "Refresh session should have a specific modality");

  if (modalityState == ModalityState.NON_MODAL) {
    myDumbModePermission = null;
    myStartTrace = null;
  }
  else {
    myDumbModePermission = DumbServiceImpl.getExplicitPermission(modalityState);
    myStartTrace = new Throwable(); // please report exceptions here to peter
  }
}
项目:intellij-ce-playground    文件:ToggleDumbModeAction.java   
public void actionPerformed(final AnActionEvent e) {
  if (myDumb) {
    myDumb = false;
  }
  else {
    myDumb = true;
    final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
    if (project == null) return;

    DumbServiceImpl.getInstance(project).queueTask(new DumbModeTask() {
      @Override
      public void performInDumbMode(@NotNull ProgressIndicator indicator) {
        while (myDumb) {
          indicator.checkCanceled();
          TimeoutUtil.sleep(100);
        }
      }
    });
  }
}
项目:intellij-ce-playground    文件:FileEditorManagerTest.java   
public void testOpenInDumbMode() throws Exception {
  PlatformTestUtil.registerExtension(FileEditorProvider.EP_FILE_EDITOR_PROVIDER, new MyFileEditorProvider(), getTestRootDisposable());
  PlatformTestUtil.registerExtension(FileEditorProvider.EP_FILE_EDITOR_PROVIDER, new DumbAwareProvider(), getTestRootDisposable());
  try {
    DumbServiceImpl.getInstance(getProject()).setDumb(true);
    VirtualFile file = getFile("/src/foo.bar");
    assertEquals(1, myManager.openFile(file, false).length);
    DumbServiceImpl.getInstance(getProject()).setDumb(false);
    UIUtil.dispatchAllInvocationEvents();
    assertEquals(2, myManager.getAllEditors(file).length);
    //assertFalse(FileEditorManagerImpl.isDumbAware(editors[0]));
  }
  finally {
    DumbServiceImpl.getInstance(getProject()).setDumb(false);
  }
}
项目:consulo    文件:ToggleDumbModeAction.java   
@Override
public void actionPerformed(final AnActionEvent e) {
  if (myDumb) {
    myDumb = false;
  }
  else {
    myDumb = true;
    final Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null) return;

    DumbServiceImpl.getInstance(project).queueTask(new DumbModeTask() {
      @Override
      public void performInDumbMode(@Nonnull ProgressIndicator indicator) {
        while (myDumb) {
          indicator.checkCanceled();
          TimeoutUtil.sleep(100);
        }
      }
    });
  }
}
项目:intellij-ce-playground    文件:FindManagerTest.java   
public void testSearchInDumbMode() throws Exception {
  createFile("a.java", "foo bar foo true");
  FindModel findModel = FindManagerTestUtils.configureFindModel("true");
  findModel.setWholeWordsOnly(true);
  DumbServiceImpl.getInstance(getProject()).setDumb(true);
  try {
    assertSize(1, findUsages(findModel));
  }
  finally {
    DumbServiceImpl.getInstance(getProject()).setDumb(false);
  }
}
项目:intellij-ce-playground    文件:RefreshSessionImpl.java   
public void fireEvents(final boolean hasWriteAction) {
  AccessToken token = myStartTrace == null ? null : DumbServiceImpl.forceDumbModeStartTrace(myStartTrace);
  try {
    if (!iHaveEventsToFire || ApplicationManager.getApplication().isDisposed()) return;

    Runnable runnable = new Runnable() {
      public void run() {
        if (hasWriteAction) {
          fireEventsInWriteAction();
        }
        else {
          ApplicationManager.getApplication().runWriteAction(new Runnable() {
            @Override
            public void run() {
              fireEventsInWriteAction();
            }
          });
        }
      }
    };

    if (myDumbModePermission != null) {
      DumbService.allowStartingDumbModeInside(myDumbModePermission, runnable);
    } else {
      runnable.run();
    }
  }
  finally {
    if (token != null) {
      token.finish();
    }
    mySemaphore.up();
  }
}
项目:intellij-ce-playground    文件:ToggleDumbModeAction.java   
@Override
public void update(final AnActionEvent e) {
  final Presentation presentation = e.getPresentation();
  final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
  presentation.setEnabled(project != null && myDumb == DumbServiceImpl.getInstance(project).isDumb());
  if (myDumb) {
    presentation.setText("Exit Dumb Mode");
  }
  else {
    presentation.setText("Enter Dumb Mode");
  }
}
项目:intellij-ce-playground    文件:ProjectRootManagerComponent.java   
private void doUpdateOnRefresh() {
  if (ApplicationManager.getApplication().isUnitTestMode() && (!myStartupActivityPerformed || myProject.isDisposed())) {
    return; // in test mode suppress addition to a queue unless project is properly initialized
  }
  if (myProject.isDefault()) {
    return;
  }

  if (myDoLogCachesUpdate) LOG.info("refresh");
  DumbServiceImpl dumbService = DumbServiceImpl.getInstance(myProject);
  DumbModeTask task = FileBasedIndexProjectHandler.createChangedFilesIndexingTask(myProject);
  if (task != null) {
    dumbService.queueTask(task);
  }
}
项目:intellij-ce-playground    文件:ProjectRootManagerComponent.java   
@Override
protected void doSynchronizeRoots() {
  if (!myStartupActivityPerformed) return;

  if (myDoLogCachesUpdate) LOG.info(new Throwable("sync roots"));
  else LOG.info("project roots have changed");

  DumbServiceImpl dumbService = DumbServiceImpl.getInstance(myProject);
  if (FileBasedIndex.getInstance() instanceof FileBasedIndexImpl) {
    dumbService.queueTask(new UnindexedFilesUpdater(myProject, false));
  }
}
项目:intellij-ce-playground    文件:PyStubsTest.java   
public void testStubIndexMismatch() {
  VirtualFile vFile = myFixture.getTempDirFixture().createFile("foo.py");
  final Project project = myFixture.getProject();
  PsiFileImpl fooPyFile = (PsiFileImpl) PsiManager.getInstance(project).findFile(vFile);
  final Document fooDocument = fooPyFile.getViewProvider().getDocument();
  Collection<PyClass> classes = PyClassNameIndex.find("Foo", project, GlobalSearchScope.allScope(project));
  assertEquals(classes.size(), 0);
  new WriteCommandAction.Simple(project, fooPyFile) {
    public void run() {
      fooDocument.setText("class Foo: pass");
    }
  }.execute();
  PsiDocumentManager.getInstance(project).commitDocument(fooDocument);
  fooPyFile.setTreeElementPointer(null);
  //classes = PyClassNameIndex.find("Foo", project, GlobalSearchScope.allScope(project));
  //fooPyFile.unloadContent();
  DumbServiceImpl.getInstance(project).setDumb(true);
  try {
    assertEquals(1, ((PyFile) fooPyFile).getTopLevelClasses().size());
    assertFalse(fooPyFile.isContentsLoaded());
  }
  finally {
    DumbServiceImpl.getInstance(project).setDumb(false);
  }
  classes = PyClassNameIndex.find("Foo", project, GlobalSearchScope.allScope(project));
  assertEquals(classes.size(), 1);
}
项目:intellij-pants-plugin    文件:PantsMetrics.java   
/**
 * This starts the indexing timer when certain conditions are met,
 * because the factor to determine whether indexing has started is
 * different in unit test and in GUI mode.
 *
 * @param myProject current Project.
 */
public static void prepareTimeIndexing(Project myProject) {
  if (!isMetricsEnabled()) {
    return;
  }
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    markIndexStart();
    return;
  }

  /**
   * This portion only applies in manual testing.
   */
  handle = indexThreadPool.scheduleWithFixedDelay(new Runnable() {
    @Override
    public void run() {
      // Start counting now in unit test mode, because dumb mode is never set.
      if (!DumbServiceImpl.getInstance(myProject).isDumb()) {
        return;
      }
      // Still in smart mode, meaning indexing hasn't started yet.
      counter++;
      if (counter > 10) {
        handle.cancel(false);
        counter = 0;
      }
      markIndexStart();
      DumbServiceImpl.getInstance(myProject).runWhenSmart(new Runnable() {
        @Override
        public void run() {
          markIndexEnd();
          report();
        }
      });
      handle.cancel(false);
    }
  }, 0, 1, TimeUnit.SECONDS);
}
项目:tools-idea    文件:ToggleDumbModeAction.java   
public void actionPerformed(final AnActionEvent e) {
  if (myDumb) {
    myDumb = false;
  }
  else {
    myDumb = true;
    final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
    if (project == null) return;

    CacheUpdater updater = new CacheUpdater() {
      public int getNumberOfPendingUpdateJobs() {
        return 0;
      }

      public VirtualFile[] queryNeededFiles(ProgressIndicator indicator) {
        while (myDumb) {
          TimeoutUtil.sleep(100);
        }
        return VirtualFile.EMPTY_ARRAY;
      }

      public void processFile(FileContent fileContent) {
      }

      public void updatingDone() {
      }

      public void canceled() {
      }
    };
    DumbServiceImpl.getInstance(project).queueCacheUpdateInDumbMode(Arrays.asList(updater));
  }
}
项目:tools-idea    文件:ToggleDumbModeAction.java   
@Override
public void update(final AnActionEvent e) {
  final Presentation presentation = e.getPresentation();
  final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
  presentation.setEnabled(project != null && myDumb == DumbServiceImpl.getInstance(project).isDumb());
  if (myDumb) {
    presentation.setText("Exit dumb mode");
  }
  else {
    presentation.setText("Enter dumb mode");
  }
}
项目:consulo    文件:ToggleLaggingModeAction.java   
@Override
public void update(final AnActionEvent e) {
  final Presentation presentation = e.getPresentation();
  final Project project = e.getData(CommonDataKeys.PROJECT);
  presentation.setEnabled(project != null && myLagging == DumbServiceImpl.getInstance(project).isDumb());
  if (myLagging) {
    presentation.setText("Exit lagging mode");
  }
  else {
    presentation.setText("Enter lagging mode");
  }
}
项目:consulo    文件:ToggleDumbModeAction.java   
@Override
public void update(final AnActionEvent e) {
  final Presentation presentation = e.getPresentation();
  final Project project = e.getData(CommonDataKeys.PROJECT);
  presentation.setEnabled(project != null && myDumb == DumbServiceImpl.getInstance(project).isDumb());
  if (myDumb) {
    presentation.setText("Exit Dumb Mode");
  }
  else {
    presentation.setText("Enter Dumb Mode");
  }
}
项目:consulo    文件:ProjectRootManagerComponent.java   
private void doUpdateOnRefresh() {
  if (ApplicationManager.getApplication().isUnitTestMode() && (!myStartupActivityPerformed || myProject.isDisposed())) {
    return; // in test mode suppress addition to a queue unless project is properly initialized
  }
  if (myProject.isDefault()) {
    return;
  }

  if (myDoLogCachesUpdate) LOG.debug("refresh");
  DumbServiceImpl dumbService = DumbServiceImpl.getInstance(myProject);
  DumbModeTask task = FileBasedIndexProjectHandler.createChangedFilesIndexingTask(myProject);
  if (task != null) {
    dumbService.queueTask(task);
  }
}
项目:consulo    文件:ProjectRootManagerComponent.java   
@Override
protected void doSynchronizeRoots() {
  if (!myStartupActivityPerformed) return;

  if (myDoLogCachesUpdate) {
    LOG.debug(new Throwable("sync roots"));
  }
  else if (!ApplicationManager.getApplication().isUnitTestMode()) LOG.info("project roots have changed");

  DumbServiceImpl dumbService = DumbServiceImpl.getInstance(myProject);
  if (FileBasedIndex.getInstance() instanceof FileBasedIndexImpl) {
    dumbService.queueTask(new UnindexedFilesUpdater(myProject));
  }
}
项目:intellij-ce-playground    文件:FindInProjectUtil.java   
public static void setDirectoryName(@NotNull FindModel model, @NotNull DataContext dataContext) {
  PsiElement psiElement = null;
  Project project = CommonDataKeys.PROJECT.getData(dataContext);

  if (project != null && !DumbServiceImpl.getInstance(project).isDumb()) {
    try {
      psiElement = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
    }
    catch (IndexNotReadyException ignore) {}
  }

  String directoryName = null;

  if (psiElement instanceof PsiDirectory) {
    directoryName = ((PsiDirectory)psiElement).getVirtualFile().getPresentableUrl();
  }

  if (directoryName == null && psiElement instanceof PsiDirectoryContainer) {
    final PsiDirectory[] directories = ((PsiDirectoryContainer)psiElement).getDirectories();
    directoryName = directories.length == 1 ? directories[0].getVirtualFile().getPresentableUrl():null;
  }

  Module module = LangDataKeys.MODULE_CONTEXT.getData(dataContext);
  if (module != null) {
    model.setModuleName(module.getName());
  }

  Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
  if (model.getModuleName() == null || editor == null) {
    model.setDirectoryName(directoryName);
    model.setProjectScope(directoryName == null && module == null && !model.isCustomScope() || editor != null);
    if (directoryName != null) {
      model.setCustomScope(false); // to select "Directory: " radio button
    }

    // for convenience set directory name to directory of current file, note that we doesn't change default projectScope
    if (directoryName == null) {
      VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
      if (virtualFile != null && !virtualFile.isDirectory()) virtualFile = virtualFile.getParent();
      if (virtualFile != null) model.setDirectoryName(virtualFile.getPresentableUrl());
    }
  }
}
项目:intellij-pants-plugin    文件:PantsExternalMetricsListenerExtensionTest.java   
public void testDurationIndexing() throws Throwable {
  class DurationMetricsTestListener extends EmptyMetricsTestListener {
    private long duration = -1;

    @Override
    public void logIndexingDuration(long milliSeconds) throws Throwable {
      duration = milliSeconds;
    }
  }

  DurationMetricsTestListener listener = new DurationMetricsTestListener();
  Extensions.getRootArea().getExtensionPoint(PantsExternalMetricsListener.EP_NAME).registerExtension(listener);

  // Set DumbService manually to explicitly trigger the StopWatch for indexing.
  // The goal is to test the whether `logIndexingDuration` works.
  DumbServiceImpl.getInstance(myProject).setDumb(true);

  // Set dumb mode multiple times to test the semaphore behavior.
  DumbServiceImpl.getInstance(myProject).setDumb(true);

  long sleepTimeMilliSeconds = 500;
  Thread.sleep(sleepTimeMilliSeconds);

  // Unset dumb service to signify indexing has ended.
  DumbServiceImpl.getInstance(myProject).setDumb(false);
  DumbServiceImpl.getInstance(myProject).setDumb(false);

  assertTrue(
    String.format("Indexing duration should be greater than %s, but is %s.", sleepTimeMilliSeconds, listener.duration),
    listener.duration >= sleepTimeMilliSeconds
  );

  // reset
  listener.duration = -1;

  // 2nd wave of indexing.
  DumbServiceImpl.getInstance(myProject).setDumb(true);

  long secondSleepTimeMilliSeconds = 1000;
  Thread.sleep(secondSleepTimeMilliSeconds);

  // Unset dumb service to signify indexing has ended.
  DumbServiceImpl.getInstance(myProject).setDumb(false);

  assertTrue(
    String.format("Indexing duration should be greater than %s, but is %s.", secondSleepTimeMilliSeconds, listener.duration),
    listener.duration >= secondSleepTimeMilliSeconds
  );
}
项目:tools-idea    文件:ProjectRootManagerComponent.java   
private void doUpdateOnRefresh() {
  if (ApplicationManager.getApplication().isUnitTestMode() && (!myStartupActivityPerformed || myProject.isDisposed())) {
    return; // in test mode suppress addition to a queue unless project is properly initialized
  }
  DumbServiceImpl.getInstance(myProject).queueCacheUpdate(myRefreshCacheUpdaters);
}
项目:tools-idea    文件:ProjectRootManagerComponent.java   
@Override
protected void doSynchronizeRoots() {
  if (!myStartupActivityPerformed) return;
  DumbServiceImpl.getInstance(myProject).queueCacheUpdate(myRootsChangeUpdaters);
}
项目:consulo    文件:FindInProjectUtil.java   
public static void setDirectoryName(@Nonnull FindModel model, @Nonnull DataContext dataContext) {
  PsiElement psiElement = null;
  Project project = dataContext.getData(CommonDataKeys.PROJECT);

  if (project != null && !DumbServiceImpl.getInstance(project).isDumb()) {
    try {
      psiElement = dataContext.getData(CommonDataKeys.PSI_ELEMENT);
    }
    catch (IndexNotReadyException ignore) {
    }
  }

  String directoryName = null;

  if (psiElement instanceof PsiDirectory) {
    directoryName = ((PsiDirectory)psiElement).getVirtualFile().getPresentableUrl();
  }

  if (directoryName == null && psiElement instanceof PsiDirectoryContainer) {
    final PsiDirectory[] directories = ((PsiDirectoryContainer)psiElement).getDirectories();
    directoryName = directories.length == 1 ? directories[0].getVirtualFile().getPresentableUrl() : null;
  }

  if (directoryName == null) {
    VirtualFile virtualFile = dataContext.getData(CommonDataKeys.VIRTUAL_FILE);
    if (virtualFile != null && virtualFile.isDirectory()) directoryName = virtualFile.getPresentableUrl();
  }

  Module module = dataContext.getData(LangDataKeys.MODULE_CONTEXT);
  if (module != null) {
    model.setModuleName(module.getName());
  }

  // model contains previous find in path settings
  // apply explicit settings from context
  if (module != null) {
    model.setModuleName(module.getName());
  }

  Editor editor = dataContext.getData(CommonDataKeys.EDITOR);
  if (model.getModuleName() == null || editor == null) {
    if (directoryName != null) {
      model.setDirectoryName(directoryName);
      model.setCustomScope(false); // to select "Directory: " radio button
    }
  }

  // set project scope if we have no other settings
  model.setProjectScope(model.getDirectoryName() == null && model.getModuleName() == null && !model.isCustomScope());
}