Search in sources :

Example 26 with EmptyProgressIndicator

use of com.intellij.openapi.progress.EmptyProgressIndicator in project smali by JesusFreke.

the class SmaliClassReferenceSearcher method processQuery.

@Override
public void processQuery(final SearchParameters queryParameters, final Processor<PsiReference> consumer) {
    final PsiElement element = queryParameters.getElementToSearch();
    if (!(element instanceof PsiClass)) {
        return;
    }
    String smaliType = ApplicationManager.getApplication().runReadAction(new Computable<String>() {

        @Override
        public String compute() {
            String qualifiedName = ((PsiClass) element).getQualifiedName();
            if (qualifiedName != null) {
                return NameUtils.javaToSmaliType((PsiClass) element);
            }
            return null;
        }
    });
    if (smaliType == null) {
        return;
    }
    final StringSearcher stringSearcher = new StringSearcher(smaliType, true, true, false, false);
    final SingleTargetRequestResultProcessor processor = new SingleTargetRequestResultProcessor(element);
    SearchScope querySearchScope = ApplicationManager.getApplication().runReadAction(new Computable<SearchScope>() {

        @Override
        public SearchScope compute() {
            return queryParameters.getEffectiveSearchScope();
        }
    });
    if (querySearchScope instanceof LocalSearchScope) {
        for (final PsiElement scopeElement : ((LocalSearchScope) querySearchScope).getScope()) {
            ApplicationManager.getApplication().runReadAction(new Runnable() {

                @Override
                public void run() {
                    LowLevelSearchUtil.processElementsContainingWordInElement(new TextOccurenceProcessor() {

                        @Override
                        public boolean execute(@NotNull PsiElement element, int offsetInElement) {
                            return processor.processTextOccurrence(element, offsetInElement, consumer);
                        }
                    }, scopeElement, stringSearcher, true, new EmptyProgressIndicator());
                }
            });
        }
    } else if (querySearchScope instanceof GlobalSearchScope) {
        PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(element.getProject());
        // TODO: limit search scope to only smali files. See, e.g. AnnotatedPackagesSearcher.PackageInfoFilesOnly
        helper.processAllFilesWithWord(smaliType, (GlobalSearchScope) querySearchScope, new Processor<PsiFile>() {

            @Override
            public boolean process(PsiFile file) {
                LowLevelSearchUtil.processElementsContainingWordInElement(new TextOccurenceProcessor() {

                    @Override
                    public boolean execute(@NotNull PsiElement element, int offsetInElement) {
                        return processor.processTextOccurrence(element, offsetInElement, consumer);
                    }
                }, file, stringSearcher, true, new EmptyProgressIndicator());
                return true;
            }
        }, true);
    } else {
        assert false;
        return;
    }
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) Processor(com.intellij.util.Processor) PsiClass(com.intellij.psi.PsiClass) NotNull(org.jetbrains.annotations.NotNull) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) StringSearcher(com.intellij.util.text.StringSearcher)

Example 27 with EmptyProgressIndicator

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

the class PsiBuilderImpl method merge.

@NotNull
private DiffLog merge(@NotNull final ASTNode oldRoot, @NotNull StartMarker newRoot, @NotNull CharSequence lastCommittedText) {
    DiffLog diffLog = new DiffLog();
    DiffTreeChangeBuilder<ASTNode, LighterASTNode> builder = new ConvertFromTokensToASTBuilder(newRoot, diffLog);
    MyTreeStructure treeStructure = new MyTreeStructure(newRoot, null);
    ShallowNodeComparator<ASTNode, LighterASTNode> comparator = new MyComparator(getUserDataUnprotected(CUSTOM_COMPARATOR), treeStructure);
    ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
    BlockSupportImpl.diffTrees(oldRoot, builder, comparator, treeStructure, indicator == null ? new EmptyProgressIndicator() : indicator, lastCommittedText);
    return diffLog;
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DiffLog(com.intellij.psi.impl.source.text.DiffLog) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with EmptyProgressIndicator

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

the class PomModelImpl method reparseFile.

@Nullable
private Runnable reparseFile(@NotNull final PsiFile file, @NotNull FileElement treeElement, @NotNull CharSequence newText) {
    TextRange changedPsiRange = DocumentCommitThread.getChangedPsiRange(file, treeElement, newText);
    if (changedPsiRange == null)
        return null;
    Runnable reparseLeaf = tryReparseOneLeaf(treeElement, newText, changedPsiRange);
    if (reparseLeaf != null)
        return reparseLeaf;
    final DiffLog log = BlockSupport.getInstance(myProject).reparseRange(file, treeElement, changedPsiRange, newText, new EmptyProgressIndicator(), treeElement.getText());
    return () -> runTransaction(new PomTransactionBase(file, getModelAspect(TreeAspect.class)) {

        @Nullable
        @Override
        public PomModelEvent runInner() throws IncorrectOperationException {
            return new TreeAspectEvent(PomModelImpl.this, log.performActualPsiChange(file));
        }
    });
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ThrowableRunnable(com.intellij.util.ThrowableRunnable) TextRange(com.intellij.openapi.util.TextRange) PomTransactionBase(com.intellij.pom.impl.PomTransactionBase) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PomModelEvent(com.intellij.pom.event.PomModelEvent) TreeAspectEvent(com.intellij.pom.tree.TreeAspectEvent) DiffLog(com.intellij.psi.impl.source.text.DiffLog) Nullable(org.jetbrains.annotations.Nullable) Nullable(org.jetbrains.annotations.Nullable)

Example 29 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 30 with EmptyProgressIndicator

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

the class BackgroundTaskUtil method computeInBackgroundAndTryWait.

/**
   * Compute value in background and try wait for its completion.
   * <ul>
   * <li> If the computation is fast, return computed value synchronously. Callback will not be called in this case.
   * <li> If the computation is slow, return <tt>null</tt>. When the computation is completed, pass the value to the callback.
   * </ul>
   * Callback will be executed on the same thread as the background task.
   */
@NotNull
@CalledInAny
public static <T> Pair<T, ProgressIndicator> computeInBackgroundAndTryWait(@NotNull Function<ProgressIndicator, T> task, @NotNull PairConsumer<T, ProgressIndicator> asyncCallback, @NotNull ModalityState modality, long waitMillis) {
    ProgressIndicator indicator = new EmptyProgressIndicator(modality);
    Helper<T> helper = new Helper<>();
    indicator.start();
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        ProgressManager.getInstance().executeProcessUnderProgress(() -> {
            try {
                T result = task.fun(indicator);
                if (!helper.setResult(result)) {
                    asyncCallback.consume(result, indicator);
                }
            } finally {
                indicator.stop();
            }
        }, indicator);
    });
    T result = null;
    if (helper.await(waitMillis)) {
        result = helper.getResult();
    }
    return Pair.create(result, indicator);
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) CalledInAny(org.jetbrains.annotations.CalledInAny) NotNull(org.jetbrains.annotations.NotNull)

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