use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.
the class PsiSearchHelperImpl method isCheapEnoughToSearch.
@NotNull
@Override
public SearchCostResult isCheapEnoughToSearch(@NotNull String name, @NotNull final GlobalSearchScope scope, @Nullable final PsiFile fileToIgnoreOccurrencesIn, @Nullable final ProgressIndicator progress) {
final AtomicInteger count = new AtomicInteger();
final ProgressIndicator indicator = progress == null ? new EmptyProgressIndicator() : progress;
final Processor<VirtualFile> processor = new Processor<VirtualFile>() {
private final VirtualFile virtualFileToIgnoreOccurrencesIn = fileToIgnoreOccurrencesIn == null ? null : fileToIgnoreOccurrencesIn.getVirtualFile();
@Override
public boolean process(VirtualFile file) {
indicator.checkCanceled();
if (Comparing.equal(file, virtualFileToIgnoreOccurrencesIn))
return true;
final int value = count.incrementAndGet();
return value < 10;
}
};
List<IdIndexEntry> keys = getWordEntries(name, true);
boolean cheap = keys.isEmpty() || processFilesContainingAllKeys(myManager.getProject(), scope, null, keys, processor);
if (!cheap) {
return SearchCostResult.TOO_MANY_OCCURRENCES;
}
return count.get() == 0 ? SearchCostResult.ZERO_OCCURRENCES : SearchCostResult.FEW_OCCURRENCES;
}
use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.
the class LineMarkersPass method queryLineMarkers.
@NotNull
public static Collection<LineMarkerInfo> queryLineMarkers(@NotNull PsiFile file, @NotNull Document document) {
if (file.getNode() == null) {
// binary file? see IDEADEV-2809
return Collections.emptyList();
}
LineMarkersPass pass = new LineMarkersPass(file.getProject(), file, document, file.getTextRange(), file.getTextRange());
pass.doCollectInformation(new EmptyProgressIndicator());
return pass.myMarkers;
}
use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.
the class CleanupInspectionIntention method invoke.
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
final List<ProblemDescriptor> descriptions = ProgressManager.getInstance().runProcess(() -> {
InspectionManager inspectionManager = InspectionManager.getInstance(project);
return InspectionEngine.runInspectionOnFile(file, myToolWrapper, inspectionManager.createNewGlobalContext(false));
}, new EmptyProgressIndicator());
if (!descriptions.isEmpty() && !FileModificationService.getInstance().preparePsiElementForWrite(file))
return;
final AbstractPerformFixesTask fixesTask = applyFixes(project, "Apply Fixes", descriptions, myQuickfixClass);
if (!fixesTask.isApplicableFixFound()) {
HintManager.getInstance().showErrorHint(editor, "Unfortunately '" + myText + "' is currently not available for batch mode\n User interaction is required for each problem found");
}
}
use of com.intellij.openapi.progress.EmptyProgressIndicator 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.EmptyProgressIndicator in project intellij-community by JetBrains.
the class FileDownloaderImpl method download.
@NotNull
@Override
public List<Pair<File, DownloadableFileDescription>> download(@NotNull final File targetDir) throws IOException {
List<Pair<File, DownloadableFileDescription>> downloadedFiles = Collections.synchronizedList(new ArrayList<>());
List<Pair<File, DownloadableFileDescription>> existingFiles = Collections.synchronizedList(new ArrayList<>());
ProgressIndicator parentIndicator = ProgressManager.getInstance().getProgressIndicator();
if (parentIndicator == null) {
parentIndicator = new EmptyProgressIndicator();
}
try {
final ConcurrentTasksProgressManager progressManager = new ConcurrentTasksProgressManager(parentIndicator, myFileDescriptions.size());
parentIndicator.setText(IdeBundle.message("progress.downloading.0.files.text", myFileDescriptions.size()));
int maxParallelDownloads = Runtime.getRuntime().availableProcessors();
LOG.debug("Downloading " + myFileDescriptions.size() + " files using " + maxParallelDownloads + " threads");
long start = System.currentTimeMillis();
ExecutorService executor = AppExecutorUtil.createBoundedApplicationPoolExecutor("FileDownloaderImpl pool", maxParallelDownloads);
List<Future<Void>> results = new ArrayList<>();
final AtomicLong totalSize = new AtomicLong();
for (final DownloadableFileDescription description : myFileDescriptions) {
results.add(executor.submit(() -> {
SubTaskProgressIndicator indicator = progressManager.createSubTaskIndicator();
indicator.checkCanceled();
final File existing = new File(targetDir, description.getDefaultFileName());
final String url = description.getDownloadUrl();
if (url.startsWith(LIB_SCHEMA)) {
final String path = FileUtil.toSystemDependentName(StringUtil.trimStart(url, LIB_SCHEMA));
final File file = PathManager.findFileInLibDirectory(path);
existingFiles.add(Pair.create(file, description));
} else if (url.startsWith(LocalFileSystem.PROTOCOL_PREFIX)) {
String path = FileUtil.toSystemDependentName(StringUtil.trimStart(url, LocalFileSystem.PROTOCOL_PREFIX));
File file = new File(path);
if (file.exists()) {
existingFiles.add(Pair.create(file, description));
}
} else {
File downloaded;
try {
downloaded = downloadFile(description, existing, indicator);
} catch (IOException e) {
throw new IOException(IdeBundle.message("error.file.download.failed", description.getDownloadUrl(), e.getMessage()), e);
}
if (FileUtil.filesEqual(downloaded, existing)) {
existingFiles.add(Pair.create(existing, description));
} else {
totalSize.addAndGet(downloaded.length());
downloadedFiles.add(Pair.create(downloaded, description));
}
}
indicator.finished();
return null;
}));
}
for (Future<Void> result : results) {
try {
result.get();
} catch (InterruptedException e) {
throw new ProcessCanceledException();
} catch (ExecutionException e) {
Throwables.propagateIfInstanceOf(e.getCause(), IOException.class);
Throwables.propagateIfInstanceOf(e.getCause(), ProcessCanceledException.class);
LOG.error(e);
}
}
long duration = System.currentTimeMillis() - start;
LOG.debug("Downloaded " + StringUtil.formatFileSize(totalSize.get()) + " in " + StringUtil.formatDuration(duration) + "(" + duration + "ms)");
List<Pair<File, DownloadableFileDescription>> localFiles = new ArrayList<>();
localFiles.addAll(moveToDir(downloadedFiles, targetDir));
localFiles.addAll(existingFiles);
return localFiles;
} catch (ProcessCanceledException | IOException e) {
deleteFiles(downloadedFiles);
throw e;
}
}
Aggregations