Search in sources :

Example 31 with EmptyProgressIndicator

use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.

the class BackgroundTaskUtil method executeAndTryWait.

@NotNull
@CalledInAwt
public static ProgressIndicator executeAndTryWait(@NotNull Function<ProgressIndicator, /*@NotNull*/
Runnable> backgroundTask, @Nullable Runnable onSlowAction, long waitMillis, boolean forceEDT) {
    ModalityState modality = ModalityState.current();
    if (forceEDT) {
        ProgressIndicator indicator = new EmptyProgressIndicator(modality);
        try {
            Runnable callback = backgroundTask.fun(indicator);
            finish(callback, indicator);
        } catch (ProcessCanceledException ignore) {
        } catch (Throwable t) {
            LOG.error(t);
        }
        return indicator;
    } else {
        Pair<Runnable, ProgressIndicator> pair = computeInBackgroundAndTryWait(backgroundTask, (callback, indicator) -> {
            ApplicationManager.getApplication().invokeLater(() -> {
                finish(callback, indicator);
            }, modality);
        }, modality, waitMillis);
        Runnable callback = pair.first;
        ProgressIndicator indicator = pair.second;
        if (callback != null) {
            finish(callback, indicator);
        } else {
            if (onSlowAction != null)
                onSlowAction.run();
        }
        return indicator;
    }
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ModalityState(com.intellij.openapi.application.ModalityState) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) CalledInAwt(org.jetbrains.annotations.CalledInAwt) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with EmptyProgressIndicator

use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.

the class ParsingTestCase method ensureCorrectReparse.

public static void ensureCorrectReparse(@NotNull final PsiFile file) {
    final String psiToStringDefault = DebugUtil.psiToString(file, false, false);
    final String fileText = file.getText();
    final DiffLog diffLog = new BlockSupportImpl(file.getProject()).reparseRange(file, file.getNode(), TextRange.allOf(fileText), fileText, new EmptyProgressIndicator(), fileText);
    diffLog.performActualPsiChange(file);
    TestCase.assertEquals(psiToStringDefault, DebugUtil.psiToString(file, false, false));
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) BlockSupportImpl(com.intellij.psi.impl.source.text.BlockSupportImpl) DiffLog(com.intellij.psi.impl.source.text.DiffLog)

Example 33 with EmptyProgressIndicator

use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.

the class JobUtilTest method testTasksRunEvenWhenReadActionIsHardToGet_Performance.

public void testTasksRunEvenWhenReadActionIsHardToGet_Performance() throws ExecutionException, InterruptedException {
    AtomicInteger processorCalled = new AtomicInteger();
    final Processor<String> processor = s -> {
        busySleep(1);
        processorCalled.incrementAndGet();
        return true;
    };
    for (int i = 0; i < 10; /*0*/
    i++) {
        System.out.println("i = " + i);
        processorCalled.set(0);
        final ProgressIndicator indicator = new EmptyProgressIndicator();
        int N = 10000;
        Future<?> future = ApplicationManager.getApplication().executeOnPooledThread(() -> {
            JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Collections.nCopies(N, ""), indicator, true, false, processor);
            assertFalse(indicator.isCanceled());
        });
        for (int k = 0; k < 10000; k++) {
            ApplicationManager.getApplication().runWriteAction(() -> {
                busySleep(1);
            });
        }
        future.get();
        assertEquals(N, processorCalled.get());
    }
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) UIUtil(com.intellij.util.ui.UIUtil) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) java.util(java.util) PlatformTestUtil(com.intellij.testFramework.PlatformTestUtil) PlatformTestCase(com.intellij.testFramework.PlatformTestCase) java.util.concurrent(java.util.concurrent) AbstractProgressIndicatorBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorBase) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) ThreadDumper(com.intellij.diagnostic.ThreadDumper) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) BigDecimal(java.math.BigDecimal) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TimeoutUtil(com.intellij.util.TimeoutUtil) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) javax.swing(javax.swing) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)

Example 34 with EmptyProgressIndicator

use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.

the class HgUpdateTest method updateThroughPlugin.

private List<VcsException> updateThroughPlugin() throws VcsException {
    HgRegularUpdater updater = new HgRegularUpdater(myProject, projectRepoVirtualFile, new HgUpdateConfigurationSettings());
    UpdatedFiles updatedFiles = UpdatedFiles.create();
    EmptyProgressIndicator indicator = new EmptyProgressIndicator();
    ArrayList<VcsException> nonFatalWarnings = new ArrayList<>();
    updater.update(updatedFiles, indicator, nonFatalWarnings);
    return nonFatalWarnings;
}
Also used : HgUpdateConfigurationSettings(org.zmlx.hg4idea.provider.update.HgUpdateConfigurationSettings) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) HgRegularUpdater(org.zmlx.hg4idea.provider.update.HgRegularUpdater) VcsException(com.intellij.openapi.vcs.VcsException) ArrayList(java.util.ArrayList) UpdatedFiles(com.intellij.openapi.vcs.update.UpdatedFiles)

Example 35 with EmptyProgressIndicator

use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.

the class PatternEditorContextMembersProvider method calcDevPatternClassNames.

private static Set<String> calcDevPatternClassNames(@NotNull final Project project) {
    final List<String> roots = ContainerUtil.createLockFreeCopyOnWriteList();
    JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
    PsiClass beanClass = psiFacade.findClass(PatternClassBean.class.getName(), GlobalSearchScope.allScope(project));
    if (beanClass != null) {
        GlobalSearchScope scope = GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), StdFileTypes.XML);
        final TextOccurenceProcessor occurenceProcessor = new TextOccurenceProcessor() {

            @Override
            public boolean execute(@NotNull PsiElement element, int offsetInElement) {
                XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
                String className = tag == null ? null : tag.getAttributeValue("className");
                if (StringUtil.isNotEmpty(className) && tag.getLocalName().endsWith("patternClass")) {
                    roots.add(className);
                }
                return true;
            }
        };
        final StringSearcher searcher = new StringSearcher("patternClass", true, true);
        CacheManager.SERVICE.getInstance(beanClass.getProject()).processFilesWithWord(psiFile -> {
            LowLevelSearchUtil.processElementsContainingWordInElement(occurenceProcessor, psiFile, searcher, true, new EmptyProgressIndicator());
            return true;
        }, searcher.getPattern(), UsageSearchContext.IN_FOREIGN_LANGUAGES, scope, searcher.isCaseSensitive());
    }
    return ContainerUtil.newHashSet(roots);
}
Also used : PatternClassBean(com.intellij.patterns.compiler.PatternClassBean) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) NotNull(org.jetbrains.annotations.NotNull) TextOccurenceProcessor(com.intellij.psi.search.TextOccurenceProcessor) XmlTag(com.intellij.psi.xml.XmlTag) StringSearcher(com.intellij.util.text.StringSearcher)

Aggregations

EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)46 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)14 NotNull (org.jetbrains.annotations.NotNull)14 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 IOException (java.io.IOException)6 ProgressManager (com.intellij.openapi.progress.ProgressManager)5 Test (org.junit.Test)5 StudioProgressIndicatorAdapter (com.android.tools.idea.sdk.progress.StudioProgressIndicatorAdapter)4 Processor (com.intellij.util.Processor)4 File (java.io.File)4 UpdatedFiles (com.intellij.openapi.vcs.update.UpdatedFiles)3 DiffLog (com.intellij.psi.impl.source.text.DiffLog)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Future (java.util.concurrent.Future)3 Nullable (org.jetbrains.annotations.Nullable)3 Disposable (com.intellij.openapi.Disposable)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 Logger (com.intellij.openapi.diagnostic.Logger)2 PluginId (com.intellij.openapi.extensions.PluginId)2