Search in sources :

Example 11 with DumbService

use of com.intellij.openapi.project.DumbService in project android by JetBrains.

the class AndroidProjectComponent method createAlarmForAutogeneration.

private void createAlarmForAutogeneration() {
    DumbService service = DumbService.getInstance(myProject);
    final Alarm alarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, myDisposable);
    alarm.addRequest(new Runnable() {

        @Override
        public void run() {
            Map<AndroidFacet, Collection<AndroidAutogeneratorMode>> facetsToProcess = service.runReadActionInSmartMode(() -> checkGenerate());
            if (facetsToProcess.size() > 0) {
                generate(facetsToProcess);
            }
            if (!alarm.isDisposed()) {
                alarm.addRequest(this, 2000);
            }
        }
    }, 2000);
}
Also used : AndroidAutogeneratorMode(org.jetbrains.android.compiler.AndroidAutogeneratorMode) Alarm(com.intellij.util.Alarm) DumbService(com.intellij.openapi.project.DumbService) HashMap(com.intellij.util.containers.HashMap)

Example 12 with DumbService

use of com.intellij.openapi.project.DumbService in project intellij-plugins by JetBrains.

the class ModuleInfoUtil method collectLocalStyle.

public static List<LocalStyleHolder> collectLocalStyle(final ModuleInfo moduleInfo, final String flexSdkVersion, final StringWriter stringWriter, final ProblemsHolder problemsHolder, ProjectComponentReferenceCounter projectComponentReferenceCounter, AssetCounter assetCounter) {
    Project project = moduleInfo.getModule().getProject();
    DumbService dumbService = DumbService.getInstance(project);
    if (dumbService.isDumb()) {
        dumbService.waitForSmartMode();
    }
    final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
    if (psiDocumentManager.hasUncommitedDocuments()) {
        final Semaphore semaphore = new Semaphore();
        semaphore.down();
        Application application = ApplicationManager.getApplication();
        LogMessageUtil.LOG.assertTrue(!application.isReadAccessAllowed());
        application.invokeLater(() -> psiDocumentManager.performWhenAllCommitted(() -> semaphore.up()));
        semaphore.waitFor();
    }
    final AccessToken token = ReadAction.start();
    try {
        if (moduleInfo.isApp()) {
            return collectApplicationLocalStyle(moduleInfo.getModule(), flexSdkVersion, problemsHolder, stringWriter, projectComponentReferenceCounter, assetCounter);
        } else {
            return collectLibraryLocalStyle(moduleInfo.getModule(), stringWriter, problemsHolder, projectComponentReferenceCounter, assetCounter);
        }
    } finally {
        token.finish();
    }
}
Also used : Project(com.intellij.openapi.project.Project) AccessToken(com.intellij.openapi.application.AccessToken) Semaphore(com.intellij.util.concurrency.Semaphore) DumbService(com.intellij.openapi.project.DumbService) Application(com.intellij.openapi.application.Application)

Aggregations

DumbService (com.intellij.openapi.project.DumbService)12 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 Project (com.intellij.openapi.project.Project)2 PsiElement (com.intellij.psi.PsiElement)2 HashMap (com.intellij.util.containers.HashMap)2 ArrayList (java.util.ArrayList)2 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)1 AccessToken (com.intellij.openapi.application.AccessToken)1 Application (com.intellij.openapi.application.Application)1 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiClass (com.intellij.psi.PsiClass)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiFile (com.intellij.psi.PsiFile)1 CodeStyleManager (com.intellij.psi.codeStyle.CodeStyleManager)1