Search in sources :

Example 16 with ProgressManager

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

the class TextFieldWithAutoCompletionListProvider method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull String prefix, @NotNull CompletionResultSet result) {
    Collection<T> items = getItems(prefix, true, parameters);
    addCompletionElements(result, this, items, -10000);
    final ProgressManager progressManager = ProgressManager.getInstance();
    ProgressIndicator mainIndicator = progressManager.getProgressIndicator();
    final ProgressIndicator indicator = mainIndicator != null ? new SensitiveProgressWrapper(mainIndicator) : new EmptyProgressIndicator();
    Future<Collection<T>> future = ApplicationManager.getApplication().executeOnPooledThread(() -> progressManager.runProcess(() -> getItems(prefix, false, parameters), indicator));
    while (true) {
        try {
            Collection<T> tasks = future.get(100, TimeUnit.MILLISECONDS);
            if (tasks != null) {
                addCompletionElements(result, this, tasks, 0);
                return;
            }
        } catch (ProcessCanceledException e) {
            throw e;
        } catch (Exception ignore) {
        }
        ProgressManager.checkCanceled();
    }
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressManager(com.intellij.openapi.progress.ProgressManager) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SensitiveProgressWrapper(com.intellij.concurrency.SensitiveProgressWrapper) Collection(java.util.Collection) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 17 with ProgressManager

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

the class AbstractMissingFilesAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final List<FilePath> files = e.getData(ChangesListView.MISSING_FILES_DATA_KEY);
    if (files == null)
        return;
    final ProgressManager progressManager = ProgressManager.getInstance();
    final Runnable action = new Runnable() {

        public void run() {
            final List<VcsException> allExceptions = new ArrayList<>();
            ChangesUtil.processFilePathsByVcs(project, files, (vcs, items) -> {
                final List<VcsException> exceptions = processFiles(vcs, files);
                if (exceptions != null) {
                    allExceptions.addAll(exceptions);
                }
            });
            for (FilePath file : files) {
                VcsDirtyScopeManager.getInstance(project).fileDirty(file);
            }
            ChangesViewManager.getInstance(project).scheduleRefresh();
            if (allExceptions.size() > 0) {
                AbstractVcsHelper.getInstance(project).showErrors(allExceptions, "VCS Errors");
            }
        }
    };
    if (synchronously()) {
        action.run();
    } else {
        progressManager.runProcessWithProgressSynchronously(action, getName(), true, project);
    }
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) Project(com.intellij.openapi.project.Project) ProgressManager(com.intellij.openapi.progress.ProgressManager) VcsException(com.intellij.openapi.vcs.VcsException) ArrayList(java.util.ArrayList)

Example 18 with ProgressManager

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

the class DeclarationSearchUtils method isTooExpensiveToSearch.

public static boolean isTooExpensiveToSearch(PsiNamedElement element, boolean zeroResult) {
    final String name = element.getName();
    if (name == null) {
        return true;
    }
    final ProgressManager progressManager = ProgressManager.getInstance();
    final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(element.getProject());
    final SearchScope useScope = element.getUseScope();
    if (!(useScope instanceof GlobalSearchScope)) {
        return zeroResult;
    }
    final PsiSearchHelper.SearchCostResult cost = searchHelper.isCheapEnoughToSearch(name, (GlobalSearchScope) useScope, null, progressManager.getProgressIndicator());
    if (cost == PsiSearchHelper.SearchCostResult.ZERO_OCCURRENCES) {
        return zeroResult;
    }
    return cost == PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES;
}
Also used : PsiSearchHelper(com.intellij.psi.search.PsiSearchHelper) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ProgressManager(com.intellij.openapi.progress.ProgressManager) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope)

Example 19 with ProgressManager

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

the class InlineOptionsDialog method initOccurrencesNumber.

protected static int initOccurrencesNumber(PsiNameIdentifierOwner nameIdentifierOwner) {
    final ProgressManager progressManager = ProgressManager.getInstance();
    final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(nameIdentifierOwner.getProject());
    final GlobalSearchScope scope = GlobalSearchScope.projectScope(nameIdentifierOwner.getProject());
    final String name = nameIdentifierOwner.getName();
    final boolean isCheapToSearch = name != null && searchHelper.isCheapEnoughToSearch(name, scope, null, progressManager.getProgressIndicator()) != PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES;
    return isCheapToSearch ? ReferencesSearch.search(nameIdentifierOwner, scope).findAll().size() : -1;
}
Also used : PsiSearchHelper(com.intellij.psi.search.PsiSearchHelper) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ProgressManager(com.intellij.openapi.progress.ProgressManager)

Example 20 with ProgressManager

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

the class InferNullityAnnotationsAction method analyze.

@Override
protected void analyze(@NotNull final Project project, @NotNull final AnalysisScope scope) {
    PropertiesComponent.getInstance().setValue(ANNOTATE_LOCAL_VARIABLES, myAnnotateLocalVariablesCb.isSelected());
    final ProgressManager progressManager = ProgressManager.getInstance();
    final Set<Module> modulesWithoutAnnotations = new HashSet<>();
    final Set<Module> modulesWithLL = new HashSet<>();
    final JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
    final String defaultNullable = NullableNotNullManager.getInstance(project).getDefaultNullable();
    final int[] fileCount = new int[] { 0 };
    if (!progressManager.runProcessWithProgressSynchronously(() -> scope.accept(new PsiElementVisitor() {

        private final Set<Module> processed = new HashSet<>();

        @Override
        public void visitFile(PsiFile file) {
            fileCount[0]++;
            final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
            if (progressIndicator != null) {
                final VirtualFile virtualFile = file.getVirtualFile();
                if (virtualFile != null) {
                    progressIndicator.setText2(ProjectUtil.calcRelativeToProjectPath(virtualFile, project));
                }
                progressIndicator.setText(AnalysisScopeBundle.message("scanning.scope.progress.title"));
            }
            if (!(file instanceof PsiJavaFile))
                return;
            final Module module = ModuleUtilCore.findModuleForPsiElement(file);
            if (module != null && processed.add(module)) {
                if (PsiUtil.getLanguageLevel(file).compareTo(LanguageLevel.JDK_1_5) < 0) {
                    modulesWithLL.add(module);
                } else if (javaPsiFacade.findClass(defaultNullable, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module)) == null) {
                    modulesWithoutAnnotations.add(module);
                }
            }
        }
    }), "Check Applicability...", true, project)) {
        return;
    }
    if (!modulesWithLL.isEmpty()) {
        Messages.showErrorDialog(project, "Infer Nullity Annotations requires the project language level be set to 1.5 or greater.", INFER_NULLITY_ANNOTATIONS);
        return;
    }
    if (!modulesWithoutAnnotations.isEmpty()) {
        if (addAnnotationsDependency(project, modulesWithoutAnnotations, defaultNullable, INFER_NULLITY_ANNOTATIONS)) {
            restartAnalysis(project, scope);
        }
        return;
    }
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    final UsageInfo[] usageInfos = findUsages(project, scope, fileCount[0]);
    if (usageInfos == null)
        return;
    processUsages(project, scope, usageInfos);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProgressManager(com.intellij.openapi.progress.ProgressManager) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Module(com.intellij.openapi.module.Module) UsageInfo(com.intellij.usageView.UsageInfo)

Aggregations

ProgressManager (com.intellij.openapi.progress.ProgressManager)24 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)13 Task (com.intellij.openapi.progress.Task)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 Project (com.intellij.openapi.project.Project)4 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)3 VcsException (com.intellij.openapi.vcs.VcsException)3 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)2 IdeFrame (com.intellij.openapi.wm.IdeFrame)2 IdeFrameImpl (com.intellij.openapi.wm.impl.IdeFrameImpl)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 PsiSearchHelper (com.intellij.psi.search.PsiSearchHelper)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Robot (org.fest.swing.core.Robot)2 WindowFinder.findFrame (org.fest.swing.finder.WindowFinder.findFrame)2 Condition (org.fest.swing.timing.Condition)2 DaemonProgressIndicator (com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)1 SensitiveProgressWrapper (com.intellij.concurrency.SensitiveProgressWrapper)1 ThreadDumper (com.intellij.diagnostic.ThreadDumper)1