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

项目:intellij-spring-assistant    文件:MavenProcessorTask.java   
@Override
public void perform(Project project, MavenEmbeddersManager mavenEmbeddersManager,
    MavenConsole mavenConsole, MavenProgressIndicator mavenProgressIndicator) {
  debug(() -> log.debug(
      "Project imported successfully, will trigger indexing via dumbservice for project "
          + project.getName()));
  DumbService.getInstance(project).smartInvokeLater(() -> {
    log.debug("Will attempt to trigger indexing for project " + project.getName());

    try {
      SuggestionIndexService service =
          ServiceManager.getService(project, SuggestionIndexService.class);

      if (!service.canProvideSuggestions(project, module)) {
        service.reindex(project, module);
      } else {
        debug(() -> log.debug(
            "Index is already built, no point in rebuilding index for project " + project
                .getName()));
      }
    } catch (Throwable e) {
      log.error("Error occurred while indexing project " + project.getName(), e);
    }
  });
}
项目:idea-php-typo3-plugin    文件:LegacyClassesForIdeQuickFix.java   
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {

    PsiElement psiElement = descriptor.getPsiElement();
    if (DumbService.isDumb(project)) {
        showIsInDumpModeMessage(project, psiElement);
        return;
    }

    if (psiElement instanceof ClassReference) {
        ClassReference classReference = (ClassReference) psiElement;
        String fqn = classReference.getFQN();
        if (fqn != null) {
            String replacementFQN = LegacyClassesForIDEIndex.findReplacementClass(project, fqn);
            if (replacementFQN != null) {
                try {
                    classReference.replace(PhpPsiElementFactory.createClassReference(project, replacementFQN));
                } catch (IncorrectOperationException e) {
                    showErrorMessage(project, "Could not replace class reference", psiElement);
                }
            }
        }
    }
}
项目:idea-php-typo3-plugin    文件:ObjectManagerTypeProvider.java   
@Nullable
@Override
public PhpType getType(PsiElement psiElement) {
    if (DumbService.getInstance(psiElement.getProject()).isDumb()) {
        return null;
    }

    if (!(psiElement instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(psiElement, "get")) {
        return null;
    }

    MethodReference methodReference = (MethodReference) psiElement;
    if (methodReference.getParameters().length == 0) {
        return null;
    }

    PsiElement firstParam = methodReference.getParameters()[0];
    if (firstParam instanceof PhpReference) {
        PhpReference ref = (PhpReference) firstParam;
        if (ref.getText().toLowerCase().contains("::class")) {
            return new PhpType().add("#" + this.getKey() + ref.getSignature());
        }
    }

    return null;
}
项目:intellij-plugin    文件:NavigatorUtil.java   
public static void smartInvokeAndWait(final Project p, final ModalityState state, final Runnable r) {
    if (isNoBackgroundMode() || ApplicationManager.getApplication().isDispatchThread()) {
        r.run();
    } else {
        final Semaphore semaphore = new Semaphore();
        semaphore.down();
        DumbService.getInstance(p).smartInvokeLater(() -> {
            try {
                r.run();
            } finally {
                semaphore.up();
            }
        }, state);
        semaphore.waitFor();
    }
}
项目:processing-idea    文件:ProcessingImportBuilder.java   
@Nullable
@Override
public List<Module> commit(Project project,
                           ModifiableModuleModel modifiableModuleModel,
                           ModulesProvider modulesProvider,
                           ModifiableArtifactModel modifiableArtifactModel) {

    logger.debug("Initializing module builder instance.");
    ProcessingModuleBuilder processingModuleBuilder = new ProcessingModuleBuilder();
    processingModuleBuilder.setGenerateTemplateSketchClass(false);

    logger.debug("Creating modules for project '" + project + "' at path '" + getParameters().projectCreationRoot + "'.");

    List<Module> modules = processingModuleBuilder.commit(project, modifiableModuleModel, modulesProvider);

    Collection<VirtualFile> importablePdeFiles = new LinkedList<>(getParameters().importablePdeFiles);

    logger.info("Identified a total of " + importablePdeFiles.size() + " PDE files for import from '" + getParameters().root + "'.");

    ImportSketchClasses importSketchClasses = new ImportSketchClasses(this, project, modules, importablePdeFiles);
    DumbService.getInstance(project).smartInvokeLater(importSketchClasses);

    return modules;
}
项目:CodeGen    文件:SQLGeneratorAction.java   
@Override
public void actionPerformed(AnActionEvent anActionEvent) {

    Project project = PsiUtil.getProject(anActionEvent);
    DumbService dumbService = DumbService.getInstance(project);
    if (dumbService.isDumb()) {
        dumbService.showDumbModeNotification(CodeGenBundle.message("codegen.plugin.is.not.available.during.indexing"));
        return;
    }

    JFrame frame = new JFrame();
    frame.setTitle("CodeGen-SQL");
    frame.setContentPane(new SqlEditorPanel(new IdeaContext(project)).getRootComponent());
    frame.setSize(600, 400);
    frame.setResizable(false);
    frame.setAlwaysOnTop(true);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
项目:manifold-ij    文件:FileModificationManager.java   
public void after( final List<? extends VFileEvent> events )
{
  if( _project.isDisposed() )
  {
    return;
  }

  DumbService dumb = DumbService.getInstance( _project );
  if( dumb.isDumb() )
  {
    dumb.smartInvokeLater( () -> _after( events ) );
  }
  else
  {
    ApplicationManager.getApplication().invokeLater( () ->_after( events ) );
  }
}
项目:manifold-ij    文件:ExtensionClassAnnotator.java   
@Override
public void annotate( PsiElement element, AnnotationHolder holder )
{
  if( DumbService.getInstance( element.getProject() ).isDumb() )
  {
    // skip processing during index rebuild
    return;
  }

  PsiClass psiExtensionClass = findExtensionClass( element );

  if( psiExtensionClass != null )
  {
    // The enclosing class a @Extension class, verify usage of @This etc.

    verifyPackage( element, holder );
    verifyExtensionInterfaces( element, holder );
    verifyExtensionMethods( element, holder );
  }
  else
  {
    // The enclosing class is *not* an extension class; usage of @This or @Extension on methods are errors

    errrantThisOrExtension( element, holder );
  }
}
项目:manifold-ij    文件:ManTypeFinder.java   
@Override
public PsiClass[] findClasses( String fqn, GlobalSearchScope globalSearchScope )
{
  //System.out.println( "PsiClass[] findClasses() : " + fqn + " : " + globalSearchScope );

  if( DumbService.getInstance( globalSearchScope.getProject() ).isDumb() )
  {
    // skip processing during index rebuild
    return PsiClass.EMPTY_ARRAY;
  }

  List<PsiClass> psiClasses = new ArrayList<>();
  List<ManModule> modules = findModules( globalSearchScope );
  for( ManModule m : modules )
  {
    PsiClass psiClass = ManifoldPsiClassCache.instance().getPsiClass( globalSearchScope, m, fqn );
    if( psiClass != null )
    {
      psiClasses.add( psiClass );
    }
  }
  return psiClasses.toArray( new PsiClass[psiClasses.size()] );
}
项目:manifold-ij    文件:ManTypeFinder.java   
@Override
public PsiClass findClass( String fqn, GlobalSearchScope globalSearchScope )
{
  //System.out.println( "findClass() : " + fqn + " : " + globalSearchScope );

  if( DumbService.getInstance( globalSearchScope.getProject() ).isDumb() )
  {
    // skip processing during index rebuild
    return null;
  }

  List<ManModule> modules = findModules( globalSearchScope );

  for( ManModule m : modules )
  {
    PsiClass psiClass = ManifoldPsiClassCache.instance().getPsiClass( globalSearchScope, m, fqn );
    if( psiClass != null )
    {
      return psiClass;
    }
  }
  return null;
}
项目:MultiHighlight    文件:MultiHighlightAction.java   
@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
    final PsiFile psiFile = e.getRequiredData(CommonDataKeys.PSI_FILE);

    CommandProcessor.getInstance().executeCommand(project, () -> {
        try {
            MultiHighlightHandler.invoke(project, editor, psiFile);
        } catch (IndexNotReadyException ex) {
            DumbService.getInstance(project)
                    .showDumbModeNotification("MultiHighlight requires indices "
                            + "and cannot be performed until they are built");
        }
    }, "MultiHighlight", null);
}
项目:mule-intellij-plugins    文件:MuleSdk.java   
@Nullable
private static String getMuleHome(@NotNull Module module) {
    if (!DumbService.isDumb(module.getProject())) {
        final OrderEnumerator enumerator = ModuleRootManager.getInstance(module)
                .orderEntries().recursively().librariesOnly().exportedOnly();
        final String[] home = new String[1];
        enumerator.forEachLibrary(library -> {
            if (MuleLibraryKind.MULE_LIBRARY_KIND.equals(((LibraryEx) library).getKind()) &&
                    library.getFiles(OrderRootType.CLASSES) != null &&
                    library.getFiles(OrderRootType.CLASSES).length > 0) {
                home[0] = getMuleHome(library.getFiles(OrderRootType.CLASSES)[0]);
                return false;
            } else {
                return true;
            }
        });

        return home[0];
    }
    return null;
}
项目:catberry-idea-plugin    文件:CatberryProjectConfigurationManager.java   
@NotNull
public PsiDirectory[] getComponentsDirectories() {
  if (DumbService.isDumb(project))
    return new PsiDirectory[0];

  final NotNullLazyValue<ModificationTracker> tracker = getCatberryTracker();
  ComponentsDirectoriesProvider provider = new ComponentsDirectoriesProvider(project, tracker);
  String[] res = CachedValuesManager.getManager(project).getCachedValue(project, provider);

  List<PsiDirectory> result = new ArrayList<PsiDirectory>(res.length);
  for(String path : res) {
    VirtualFile virtualFile = project.getBaseDir().findFileByRelativePath(path);
    if(virtualFile == null)
      continue;
    PsiManager manager = PsiManager.getInstance(project);
    PsiDirectory dir = manager.findDirectory(virtualFile);
    if(dir != null)
      result.add(dir);
  }
  return result.toArray(new PsiDirectory[result.size()]);
}
项目:intellij-ce-playground    文件:RenameDialog.java   
public void performRename(final String newName) {
  final RenamePsiElementProcessor elementProcessor = RenamePsiElementProcessor.forElement(myPsiElement);
  elementProcessor.setToSearchInComments(myPsiElement, isSearchInComments());
  if (myCbSearchTextOccurences.isEnabled()) {
    elementProcessor.setToSearchForTextOccurrences(myPsiElement, isSearchInNonJavaFiles());
  }
  if (mySuggestedNameInfo != null) {
    mySuggestedNameInfo.nameChosen(newName);
  }

  final RenameProcessor processor = createRenameProcessor(newName);

  for(Map.Entry<AutomaticRenamerFactory, JCheckBox> e: myAutomaticRenamers.entrySet()) {
    e.getKey().setEnabled(e.getValue().isSelected());
    if (e.getValue().isSelected()) {
      processor.addRenamerFactory(e.getKey());
    }
  }

  DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_MODAL, new Runnable() {
    @Override
    public void run() {
      invokeRefactoring(processor);
    }
  });
}
项目:intellij-ce-playground    文件:EditorGutterComponentImpl.java   
@SuppressWarnings("unchecked")
public EditorGutterComponentImpl(EditorImpl editor) {
  myEditor = editor;
  myLineNumberConvertor = ID;
  if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
    installDnD();
  }
  setOpaque(true);
  myAnchorsDisplayStrategy = new FoldingAnchorsOverlayStrategy(editor);

  Project project = myEditor.getProject();
  if (project != null) {
    project.getMessageBus().connect(myEditor.getDisposable()).subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() {
      @Override
      public void enteredDumbMode() {
      }

      @Override
      public void exitDumbMode() {
        updateSize();
      }
    });
  }
}
项目:intellij-ce-playground    文件:BaseRefactoringProcessor.java   
@Override
public final void run() {
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    doRun();
    UIUtil.dispatchAllInvocationEvents();
    UIUtil.dispatchAllInvocationEvents();
    return;
  }
  if (ApplicationManager.getApplication().isWriteAccessAllowed()) {
    LOG.info(new Exception());
    DumbService.getInstance(myProject).smartInvokeLater(new Runnable() {
      @Override
      public void run() {
        doRun();
      }
    });
  }
  else {
    doRun();
  }
}
项目:intellij-ce-playground    文件:ClsFieldImpl.java   
@Override
@NotNull
public PsiElement getNavigationElement() {
  if (DumbService.isDumb(getProject())) return this;

  for (ClsCustomNavigationPolicy customNavigationPolicy : Extensions.getExtensions(ClsCustomNavigationPolicy.EP_NAME)) {
    PsiElement navigationElement = customNavigationPolicy.getNavigationElement(this);
    if (navigationElement != null) {
      return navigationElement;
    }
  }

  PsiClass sourceClassMirror = ((ClsClassImpl)getParent()).getSourceMirrorClass();
  PsiElement sourceFieldMirror = sourceClassMirror != null ? sourceClassMirror.findFieldByName(getName(), false) : null;
  return sourceFieldMirror != null ? sourceFieldMirror.getNavigationElement() : this;
}
项目:intellij-ce-playground    文件:PsiPackageImpl.java   
@NotNull
private PsiClass[] getCachedClassesByName(@NotNull String name, GlobalSearchScope scope) {
  if (DumbService.getInstance(getProject()).isDumb()) {
    return getCachedClassInDumbMode(name, scope);
  }

  Map<String, PsiClass[]> map = SoftReference.dereference(myClassCache);
  if (map == null) {
    myClassCache = new SoftReference<Map<String, PsiClass[]>>(map = ContainerUtil.createConcurrentSoftValueMap());
  }
  PsiClass[] classes = map.get(name);
  if (classes != null) {
    return classes;
  }

  final String qName = getQualifiedName();
  final String classQName = !qName.isEmpty() ? qName + "." + name : name;
  map.put(name, classes = getFacade().findClasses(classQName, new EverythingGlobalScope(getProject())));
  return classes;
}
项目:intellij-ce-playground    文件:RearrangeBeforeCheckinHandler.java   
@Override
public void runCheckinHandlers(@NotNull final Runnable finishAction) {
  final Runnable performCheckoutAction = new Runnable() {
    @Override
    public void run() {
      FileDocumentManager.getInstance().saveAllDocuments();
      finishAction.run();
    }
  };

  if (VcsConfiguration.getInstance(myProject).REARRANGE_BEFORE_PROJECT_COMMIT && !DumbService.isDumb(myProject)) {
    new RearrangeCodeProcessor(
      myProject, CheckinHandlerUtil.getPsiFiles(myProject, myPanel.getVirtualFiles()), COMMAND_NAME, performCheckoutAction
    ).run();
  }
  else {
    performCheckoutAction.run();
  }
}
项目:intellij-ce-playground    文件:ExecutionManagerImpl.java   
protected void doRun(@NotNull final ExecutionEnvironment environment, @NotNull final Runnable startRunnable) {
  Boolean allowSkipRun = environment.getUserData(EXECUTION_SKIP_RUN);
  if (allowSkipRun != null && allowSkipRun) {
    environment.getProject().getMessageBus().syncPublisher(EXECUTION_TOPIC).processNotStarted(environment.getExecutor().getId(),
                                                                                              environment);
  }
  else {
    // important! Do not use DumbService.smartInvokeLater here because it depends on modality state
    // and execution of startRunnable could be skipped if modality state check fails
    //noinspection SSBasedInspection
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        if (!myProject.isDisposed()) {
          DumbService.getInstance(myProject).runWhenSmart(startRunnable);
        }
      }
    });
  }
}
项目:intellij-ce-playground    文件:AddImportAction.java   
private void addImport(final PsiReference ref, final PsiClass targetClass) {
  StatisticsManager.getInstance().incUseCount(JavaStatisticsManager.createInfo(null, targetClass));
  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    @Override
    public void run() {
      ApplicationManager.getApplication().runWriteAction(new Runnable() {
        @Override
        public void run() {
          DumbService.getInstance(myProject).withAlternativeResolveEnabled(new Runnable() {
            @Override
            public void run() {
              _addImport(ref, targetClass);
            }
          });
        }
      });
    }
  }, QuickFixBundle.message("add.import"), null);
}
项目:intellij-ce-playground    文件:XmlSchemaProvider.java   
@Nullable
public static XmlFile findSchema(@NotNull @NonNls String namespace, @Nullable Module module, @NotNull PsiFile file) {
  if (file.getProject().isDefault()) return null;
  final boolean dumb = DumbService.getInstance(file.getProject()).isDumb();
  for (XmlSchemaProvider provider: Extensions.getExtensions(EP_NAME)) {
    if (dumb && !DumbService.isDumbAware(provider)) {
      continue;
    }

    if (file instanceof XmlFile && !provider.isAvailable((XmlFile)file)) {
      continue;
    }
    final XmlFile schema = provider.getSchema(namespace, module, file);
    if (schema != null) {
      return schema;
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:CompositeFilter.java   
@Override
public String getUpdateMessage() {
  final boolean dumb = myDumbService.isDumb();
  List<Filter> filters = myFilters;
  final List<String> updateMessage = new ArrayList<String>();
  int count = filters.size();

  for (int i = 0; i < count; i++) {
    Filter filter = filters.get(i);

    if (!(filter instanceof FilterMixin) || !((FilterMixin)filter).shouldRunHeavy()) continue;
    if (!dumb || DumbService.isDumbAware(filter)) {
      updateMessage.add(((FilterMixin)filter).getUpdateMessage());
    }
  }
  return updateMessage.size() == 1 ? updateMessage.get(0) : "Updating...";
}
项目:intellij-ce-playground    文件:PsiClassFavoriteNodeProvider.java   
@Override
public Object[] createPathFromUrl(final Project project, final String url, final String moduleName) {
  if (DumbService.isDumb(project)) {
    return null;
  }

  GlobalSearchScope scope = null;
  if (moduleName != null) {
    final Module module = ModuleManager.getInstance(project).findModuleByName(moduleName);
    if (module != null) {
      scope = GlobalSearchScope.moduleScope(module);
    }
  }
  if (scope == null) {
    scope = GlobalSearchScope.allScope(project);
  }
  final PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(url, scope);
  if (aClass == null) return null;
  return new Object[]{aClass};
}
项目:intellij-ce-playground    文件:LibrariesUtil.java   
@Nullable
public static String getGroovyHomePath(@NotNull Module module) {
  if (!DumbService.isDumb(module.getProject())) {
    final VirtualFile local = findJarWithClass(module, SOME_GROOVY_CLASS);
    if (local != null) {
      final VirtualFile parent = local.getParent();
      if (parent != null) {
        if (("lib".equals(parent.getName()) || "embeddable".equals(parent.getName())) && parent.getParent() != null) {
          return parent.getParent().getPath();
        }
        return parent.getPath();
      }
    }
  }

  final String home = getGroovyLibraryHome(OrderEnumerator.orderEntries(module).getAllLibrariesAndSdkClassesRoots());
  return StringUtil.isEmpty(home) ? null : home;
}
项目:intellij-ce-playground    文件:AddCustomLibraryDialog.java   
@Override
protected void doOKAction() {
  final LibraryCompositionSettings settings = myPanel.apply();
  DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, new Runnable() {
    @Override
    public void run() {
      if (settings != null && settings.downloadFiles(myPanel.getMainPanel())) {
        if (myModifiableRootModel == null) {
          final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
          new WriteAction() {
            @Override
            protected void run(@NotNull final Result result) {
              addLibraries(model, settings);
              model.commit();
            }
          }.execute();
        }
        else {
          addLibraries(myModifiableRootModel, settings);
        }

      }
      AddCustomLibraryDialog.super.doOKAction();
    }
  });
}
项目:intellij-ce-playground    文件:AddFrameworkSupportDialog.java   
protected void doOKAction() {
  if (myAddSupportPanel.hasSelectedFrameworks()) {
    if (!myAddSupportPanel.downloadLibraries()) {
      int answer = Messages.showYesNoDialog(myAddSupportPanel.getMainPanel(),
                                            ProjectBundle.message("warning.message.some.required.libraries.wasn.t.downloaded"),
                                            CommonBundle.getWarningTitle(), Messages.getWarningIcon());
      if (answer != Messages.YES) {
        return;
      }
    }

    DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, new Runnable() {
      @Override
      public void run() {
        new WriteAction() {
          protected void run(@NotNull final Result result) {
            ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
            myAddSupportPanel.addSupport(myModule, model);
            model.commit();
          }
        }.execute();
      }
    });
  }
  super.doOKAction();
}
项目:intellij-ce-playground    文件:AddSupportForFrameworksPanel.java   
public boolean downloadLibraries() {
  final Ref<Boolean> result = Ref.create(true);
  DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, new Runnable() {
    @Override
    public void run() {
      applyLibraryOptionsForSelected();
      List<LibraryCompositionSettings> list = getLibrariesCompositionSettingsList();
      for (LibraryCompositionSettings compositionSettings : list) {
        if (!compositionSettings.downloadFiles(myMainPanel)) {
          result.set(false);
          return;
        }
      }
    }
  });
  return result.get();
}
项目:intellij-ce-playground    文件:PsiModificationTrackerImpl.java   
public PsiModificationTrackerImpl(Project project) {
  final MessageBus bus = project.getMessageBus();
  myPublisher = bus.syncPublisher(TOPIC);
  bus.connect().subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() {
    private void doIncCounter() {
      ApplicationManager.getApplication().runWriteAction(new Runnable() {
        @Override
        public void run() {
          incCounter();
        }
      });
    }

    @Override
    public void enteredDumbMode() {
      doIncCounter();
    }

    @Override
    public void exitDumbMode() {
      doIncCounter();
    }
  });
}
项目:intellij-ce-playground    文件:UsageNodeTreeBuilder.java   
@Nullable
UsageNode appendUsage(@NotNull Usage usage, @NotNull Consumer<Runnable> edtQueue) {
  if (!isVisible(usage)) return null;

  final boolean dumb = DumbService.isDumb(myProject);

  GroupNode lastGroupNode = myRoot;
  for (int i = 0; i < myGroupingRules.length; i++) {
    final UsageGroupingRule rule = myGroupingRules[i];
    if (dumb && !DumbService.isDumbAware(rule)) continue;

    final UsageGroup group;
    if (rule instanceof UsageGroupingRuleEx) {
      group = ((UsageGroupingRuleEx) rule).groupUsage(usage, myTargets);
    }
    else {
      group = rule.groupUsage(usage);
    }
    if (group != null) {
      lastGroupNode = lastGroupNode.addGroup(group, i, edtQueue);
    }
  }

  return lastGroupNode.addUsage(usage, edtQueue);
}
项目:intellij-ce-playground    文件:ReformatCodeAction.java   
private static void reformatModule(@NotNull Project project,
                                   @Nullable Module moduleContext,
                                   @NotNull ReformatFilesOptions selectedFlags)
{
  boolean shouldOptimizeImports = selectedFlags.isOptimizeImports() && !DumbService.getInstance(project).isDumb();
  boolean processOnlyChangedText = selectedFlags.getTextRangeType() == TextRangeType.VCS_CHANGED_TEXT;

  AbstractLayoutCodeProcessor processor;
  if (moduleContext != null)
    processor = new ReformatCodeProcessor(project, moduleContext, processOnlyChangedText);
  else
    processor = new ReformatCodeProcessor(project, processOnlyChangedText);

  registerScopeFilter(processor, selectedFlags.getSearchScope());
  registerFileMaskFilter(processor, selectedFlags.getFileTypeMask());

  if (shouldOptimizeImports) {
    processor = new OptimizeImportsProcessor(processor);
  }

  if (selectedFlags.isRearrangeCode()) {
    processor = new RearrangeCodeProcessor(processor);
  }

  processor.run();
}
项目:intellij-ce-playground    文件:GeneralHighlightingPass.java   
@NotNull
private HighlightVisitor[] filterVisitors(@NotNull HighlightVisitor[] highlightVisitors, @NotNull PsiFile psiFile) {
  final List<HighlightVisitor> visitors = new ArrayList<HighlightVisitor>(highlightVisitors.length);
  List<HighlightVisitor> list = Arrays.asList(highlightVisitors);
  for (HighlightVisitor visitor : DumbService.getInstance(myProject).filterByDumbAwareness(list)) {
    if (visitor.suitableForFile(psiFile)) {
      visitors.add(visitor);
    }
  }
  if (visitors.isEmpty()) {
    LOG.error("No visitors registered. list=" +
              list +
              "; all visitors are:" +
              Arrays.asList(Extensions.getExtensions(HighlightVisitor.EP_HIGHLIGHT_VISITOR, myProject)));
  }

  return visitors.toArray(new HighlightVisitor[visitors.size()]);
}
项目:intellij-ce-playground    文件:TodoTreeBuilder.java   
@Override
protected final AbstractTreeUpdater createUpdater() {
  return new AbstractTreeUpdater(this) {
    @Override
    protected ActionCallback beforeUpdate(final TreeUpdatePass pass) {
      if (!myDirtyFileSet.isEmpty()) { // suppress redundant cache validations
        final AsyncResult callback = new AsyncResult();
        DumbService.getInstance(myProject).runWhenSmart(new Runnable() {
          @Override
          public void run() {
            try {
              validateCache();
              getTodoTreeStructure().validateCache();
            }
            finally {
              callback.setDone();
            }
          }
        });
        return callback;
      }

      return ActionCallback.DONE;
    }
  };
}
项目:intellij-ce-playground    文件:CreateResourceActionBase.java   
protected boolean isAvailable(final DataContext dataContext) {
  final Project project = CommonDataKeys.PROJECT.getData(dataContext);
  if (project == null) {
    return false;
  }

  if (DumbService.getInstance(project).isDumb() && !isDumbAware()) {
    return false;
  }

  final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
  if (view == null || view.getDirectories().length == 0) {
    return false;
  }

  return true;
}
项目:intellij-ce-playground    文件:ResourceEditor.java   
protected void showDialog() {
  Module module = RadModelBuilder.getModule(myRootComponent);
  if (module == null) {
    if (myBooleanResourceValue != null) {
      fireEditingCancelled();
    }
    return;
  }
  if (DumbService.isDumb(module.getProject())) {
    DumbService.getInstance(module.getProject()).showDumbModeNotification("Resources are not available during indexing");
    return;
  }

  ResourceDialog dialog = new ResourceDialog(module, myTypes, (String)getValue(), (RadViewComponent)myComponent);
  if (dialog.showAndGet()) {
    setValue(dialog.getResourceName());
  }
  else {
    if (myBooleanResourceValue != null) {
      fireEditingCancelled();
    }
  }
}
项目:intellij-ce-playground    文件:MavenUtil.java   
public static void smartInvokeAndWait(final Project p, final ModalityState state, final Runnable r) {
  if (isNoBackgroundMode() || ApplicationManager.getApplication().isDispatchThread()) {
    r.run();
  }
  else {
    final Semaphore semaphore = new Semaphore();
    semaphore.down();
    DumbService.getInstance(p).smartInvokeLater(new Runnable() {
      @Override
      public void run() {
        try {
          r.run();
        }
        finally {
          semaphore.up();
        }
      }
    }, state);
    semaphore.waitFor();
  }
}
项目:intellij-ce-playground    文件:PythonSdkType.java   
public void setupSdkPaths(@NotNull final Sdk sdk) {
  final Project project;
  final WeakReference<Component> ownerComponentRef = sdk.getUserData(SDK_CREATOR_COMPONENT_KEY);
  final Component ownerComponent = SoftReference.dereference(ownerComponentRef);
  if (ownerComponent != null) {
    project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(ownerComponent));
  }
  else {
    project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext());
  }

  DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, new Runnable() {
    @Override
    public void run() {
      setupSdkPaths(sdk, project, ownerComponent);
    }
  });
}
项目:intellij    文件:BlazeNewProjectWizard.java   
@Override
protected final void doOKAction() {
  final Ref<Boolean> result = Ref.create(false);
  DumbService.allowStartingDumbModeInside(
      DumbModePermission.MAY_START_BACKGROUND,
      new Runnable() {
        @Override
        public void run() {
          result.set(doFinishAction());
        }
      });
  if (!result.get()) {
    return;
  }
  super.doOKAction();
}
项目:intellij-ce-playground    文件:SMTestProxy.java   
protected Location getLocation(@NotNull Project project, @NotNull GlobalSearchScope searchScope, String locationUrl) {
  if (locationUrl != null && myLocator != null) {
    String protocolId = VirtualFileManager.extractProtocol(locationUrl);
    if (protocolId != null) {
      String path = VirtualFileManager.extractPath(locationUrl);
      if (!DumbService.isDumb(project) || DumbService.isDumbAware(myLocator)) {
        List<Location> locations = myLocator.getLocation(protocolId, path, project, searchScope);
        if (!locations.isEmpty()) {
          return locations.get(0);
        }
      }
    }
  }

  return null;
}
项目:intellij-ce-playground    文件:EditorComposite.java   
private JComponent createEditorComponent(final FileEditor editor) {
  JPanel component = new JPanel(new BorderLayout());
  JComponent comp = editor.getComponent();
  if (!FileEditorManagerImpl.isDumbAware(editor)) {
    comp = DumbService.getInstance(myFileEditorManager.getProject()).wrapGently(comp, editor);
  }

  component.add(comp, BorderLayout.CENTER);

  JPanel topPanel = new TopBottomPanel();
  myTopComponents.put(editor, topPanel);
  component.add(topPanel, BorderLayout.NORTH);

  final JPanel bottomPanel = new TopBottomPanel();
  myBottomComponents.put(editor, bottomPanel);
  component.add(bottomPanel, BorderLayout.SOUTH);

  return component;
}