Search in sources :

Example 6 with EmptyProgressIndicator

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ReadActionProcessor(com.intellij.openapi.application.ReadActionProcessor) Processor(com.intellij.util.Processor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) IdIndexEntry(com.intellij.psi.impl.cache.impl.id.IdIndexEntry) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with EmptyProgressIndicator

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;
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with EmptyProgressIndicator

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");
    }
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator)

Example 9 with EmptyProgressIndicator

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();
    }
}
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 10 with EmptyProgressIndicator

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;
    }
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AtomicLong(java.util.concurrent.atomic.AtomicLong) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DownloadableFileDescription(com.intellij.util.download.DownloadableFileDescription) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) File(java.io.File) Pair(com.intellij.openapi.util.Pair) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) 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