Search in sources :

Example 11 with EmptyProgressIndicator

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

the class MockDumbService method queueTask.

@Override
public void queueTask(@NotNull DumbModeTask task) {
    task.performInDumbMode(new EmptyProgressIndicator());
    Disposer.dispose(task);
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator)

Example 12 with EmptyProgressIndicator

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

the class InspectionEngine method runInspectionOnFile.

@NotNull
public static List<ProblemDescriptor> runInspectionOnFile(@NotNull final PsiFile file, @NotNull InspectionToolWrapper toolWrapper, @NotNull final GlobalInspectionContext inspectionContext) {
    final InspectionManager inspectionManager = InspectionManager.getInstance(file.getProject());
    toolWrapper.initialize(inspectionContext);
    RefManagerImpl refManager = (RefManagerImpl) inspectionContext.getRefManager();
    refManager.inspectionReadActionStarted();
    try {
        if (toolWrapper instanceof LocalInspectionToolWrapper) {
            return inspect(Collections.singletonList((LocalInspectionToolWrapper) toolWrapper), file, inspectionManager, new EmptyProgressIndicator());
        }
        if (toolWrapper instanceof GlobalInspectionToolWrapper) {
            final GlobalInspectionTool globalTool = ((GlobalInspectionToolWrapper) toolWrapper).getTool();
            final List<ProblemDescriptor> descriptors = new ArrayList<>();
            if (globalTool instanceof GlobalSimpleInspectionTool) {
                GlobalSimpleInspectionTool simpleTool = (GlobalSimpleInspectionTool) globalTool;
                ProblemsHolder problemsHolder = new ProblemsHolder(inspectionManager, file, false);
                ProblemDescriptionsProcessor collectProcessor = new ProblemDescriptionsProcessor() {

                    @Nullable
                    @Override
                    public CommonProblemDescriptor[] getDescriptions(@NotNull RefEntity refEntity) {
                        return descriptors.toArray(new CommonProblemDescriptor[descriptors.size()]);
                    }

                    @Override
                    public void ignoreElement(@NotNull RefEntity refEntity) {
                        throw new RuntimeException();
                    }

                    @Override
                    public void addProblemElement(@Nullable RefEntity refEntity, @NotNull CommonProblemDescriptor... commonProblemDescriptors) {
                        if (!(refEntity instanceof RefElement))
                            return;
                        PsiElement element = ((RefElement) refEntity).getElement();
                        convertToProblemDescriptors(element, commonProblemDescriptors, descriptors);
                    }

                    @Override
                    public RefEntity getElement(@NotNull CommonProblemDescriptor descriptor) {
                        throw new RuntimeException();
                    }
                };
                simpleTool.checkFile(file, inspectionManager, problemsHolder, inspectionContext, collectProcessor);
                return descriptors;
            }
            RefElement fileRef = refManager.getReference(file);
            final AnalysisScope scope = new AnalysisScope(file);
            assert fileRef != null;
            fileRef.accept(new RefVisitor() {

                @Override
                public void visitElement(@NotNull RefEntity elem) {
                    CommonProblemDescriptor[] elemDescriptors = globalTool.checkElement(elem, scope, inspectionManager, inspectionContext);
                    if (elemDescriptors != null) {
                        convertToProblemDescriptors(file, elemDescriptors, descriptors);
                    }
                    for (RefEntity child : elem.getChildren()) {
                        child.accept(this);
                    }
                }
            });
            return descriptors;
        }
    } finally {
        refManager.inspectionReadActionFinished();
        toolWrapper.cleanup(file.getProject());
        inspectionContext.cleanup();
    }
    return Collections.emptyList();
}
Also used : GlobalInspectionToolWrapper(com.intellij.codeInspection.ex.GlobalInspectionToolWrapper) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) RefManagerImpl(com.intellij.codeInspection.reference.RefManagerImpl) NotNull(org.jetbrains.annotations.NotNull) RefElement(com.intellij.codeInspection.reference.RefElement) AnalysisScope(com.intellij.analysis.AnalysisScope) RefVisitor(com.intellij.codeInspection.reference.RefVisitor) RefEntity(com.intellij.codeInspection.reference.RefEntity) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with EmptyProgressIndicator

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

the class DirDiffTableModel method reloadModel.

public void reloadModel(final boolean userForcedRefresh) {
    myUpdating.set(true);
    myTable.getEmptyText().setText(StatusText.DEFAULT_EMPTY_TEXT);
    final JBLoadingPanel loadingPanel = getLoadingPanel();
    loadingPanel.startLoading();
    final ModalityState modalityState = ModalityState.current();
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        EmptyProgressIndicator indicator = new EmptyProgressIndicator(modalityState);
        ProgressManager.getInstance().executeProcessUnderProgress(() -> {
            try {
                if (myDisposed)
                    return;
                myUpdater = new Updater(loadingPanel, 100);
                myUpdater.start();
                text.set("Loading...");
                myTree = new DTree(null, "", true);
                mySrc.refresh(userForcedRefresh);
                myTrg.refresh(userForcedRefresh);
                scan(mySrc, myTree, true);
                scan(myTrg, myTree, false);
            } catch (final IOException e) {
                LOG.warn(e);
                reportException(VcsBundle.message("refresh.failed.message", StringUtil.decapitalize(e.getLocalizedMessage())));
            } finally {
                if (myTree != null) {
                    myTree.setSource(mySrc);
                    myTree.setTarget(myTrg);
                    myTree.update(mySettings);
                    applySettings();
                }
            }
        }, indicator);
    });
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) JBLoadingPanel(com.intellij.ui.components.JBLoadingPanel) IOException(java.io.IOException)

Example 14 with EmptyProgressIndicator

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

the class JobUtilTest method testProcessorReturningFalseDoesNotCrashTheOtherThread.

public void testProcessorReturningFalseDoesNotCrashTheOtherThread() {
    final AtomicInteger delay = new AtomicInteger(0);
    final Runnable checkCanceled = ProgressManager::checkCanceled;
    Processor<String> processor = s -> {
        busySleep(delay.incrementAndGet() % 10 + 10, checkCanceled);
        return delay.get() % 100 != 0;
    };
    for (int i = 0; i < 100; i++) {
        ProgressIndicator indicator = new EmptyProgressIndicator();
        boolean result = JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Collections.nCopies(10000, ""), indicator, false, false, processor);
        assertFalse(indicator.isCanceled());
        assertFalse(result);
    }
}
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 15 with EmptyProgressIndicator

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

the class ModuleManagerImpl method loadModules.

protected void loadModules(@NotNull ModuleModelImpl moduleModel) {
    myFailedModulePaths.clear();
    if (myModulePathsToLoad == null || myModulePathsToLoad.isEmpty()) {
        return;
    }
    myFailedModulePaths.addAll(myModulePathsToLoad);
    ProgressIndicator globalIndicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
    ProgressIndicator progressIndicator = myProject.isDefault() || globalIndicator == null ? new EmptyProgressIndicator() : globalIndicator;
    progressIndicator.setText("Loading modules...");
    progressIndicator.setText2("");
    List<Module> modulesWithUnknownTypes = new SmartList<>();
    List<ModuleLoadingErrorDescription> errors = Collections.synchronizedList(new ArrayList<>());
    ModuleGroupInterner groupInterner = new ModuleGroupInterner();
    ExecutorService service = AppExecutorUtil.createBoundedApplicationPoolExecutor("modules loader", JobSchedulerImpl.CORES_COUNT);
    List<Pair<Future<Module>, ModulePath>> tasks = new ArrayList<>();
    Set<String> paths = new THashSet<>();
    boolean parallel = Registry.is("parallel.modules.loading");
    for (ModulePath modulePath : myModulePathsToLoad) {
        if (progressIndicator.isCanceled()) {
            break;
        }
        try {
            String path = modulePath.getPath();
            if (!paths.add(path))
                continue;
            if (!parallel) {
                tasks.add(Pair.create(null, modulePath));
                continue;
            }
            ThrowableComputable<Module, IOException> computable = moduleModel.loadModuleInternal(path);
            Future<Module> future = service.submit(() -> {
                progressIndicator.setFraction(progressIndicator.getFraction() + myProgressStep);
                try {
                    return computable.compute();
                } catch (IOException e) {
                    reportError(errors, modulePath, e);
                } catch (Exception e) {
                    LOG.error(e);
                }
                return null;
            });
            tasks.add(Pair.create(future, modulePath));
        } catch (IOException e) {
            reportError(errors, modulePath, e);
        }
    }
    for (Pair<Future<Module>, ModulePath> task : tasks) {
        if (progressIndicator.isCanceled()) {
            break;
        }
        try {
            Module module;
            if (parallel) {
                module = task.first.get();
            } else {
                module = moduleModel.loadModuleInternal(task.second.getPath()).compute();
                progressIndicator.setFraction(progressIndicator.getFraction() + myProgressStep);
            }
            if (module == null)
                continue;
            if (isUnknownModuleType(module)) {
                modulesWithUnknownTypes.add(module);
            }
            ModulePath modulePath = task.second;
            final String groupPathString = modulePath.getGroup();
            if (groupPathString != null) {
                // model should be updated too
                groupInterner.setModuleGroupPath(moduleModel, module, groupPathString.split(MODULE_GROUP_SEPARATOR));
            }
            myFailedModulePaths.remove(modulePath);
        } catch (IOException e) {
            reportError(errors, task.second, e);
        } catch (Exception e) {
            LOG.error(e);
        }
    }
    service.shutdown();
    progressIndicator.checkCanceled();
    Application app = ApplicationManager.getApplication();
    if (app.isInternal() || app.isEAP() || ApplicationInfo.getInstance().getBuild().isSnapshot()) {
        Map<String, Module> track = new THashMap<>();
        for (Module module : moduleModel.getModules()) {
            for (String url : ModuleRootManager.getInstance(module).getContentRootUrls()) {
                Module oldModule = track.put(url, module);
                if (oldModule != null) {
                    //Map<String, VirtualFilePointer> track1 = ContentEntryImpl.track;
                    //VirtualFilePointer pointer = track1.get(url);
                    LOG.error("duplicated content url: " + url);
                }
            }
        }
    }
    onModuleLoadErrors(moduleModel, errors);
    showUnknownModuleTypeNotification(modulesWithUnknownTypes);
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) THashMap(gnu.trove.THashMap) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) SmartList(com.intellij.util.SmartList) Application(com.intellij.openapi.application.Application)

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