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();
}
}
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);
}
}
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;
}
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;
}
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);
}
Aggregations