Search in sources :

Example 21 with ProcessCanceledException

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

the class IndexCacheManagerImpl method collectVirtualFilesWithWord.

// IMPORTANT!!!
// Since implementation of virtualFileProcessor.process() may call indices directly or indirectly,
// we cannot call it inside FileBasedIndex.processValues() method except in collecting form
// If we do, deadlocks are possible (IDEADEV-42137). Process the files without not holding indices' read lock.
private boolean collectVirtualFilesWithWord(@NotNull final String word, final short occurrenceMask, @NotNull final GlobalSearchScope scope, final boolean caseSensitively, @NotNull final Processor<VirtualFile> fileProcessor) {
    if (myProject.isDefault()) {
        return true;
    }
    try {
        return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {

            @Override
            public Boolean compute() {
                return FileBasedIndex.getInstance().processValues(IdIndex.NAME, new IdIndexEntry(word, caseSensitively), null, new FileBasedIndex.ValueProcessor<Integer>() {

                    final FileIndexFacade index = FileIndexFacade.getInstance(myProject);

                    @Override
                    public boolean process(final VirtualFile file, final Integer value) {
                        ProgressIndicatorProvider.checkCanceled();
                        final int mask = value.intValue();
                        if ((mask & occurrenceMask) != 0 && index.shouldBeFound(scope, file)) {
                            if (!fileProcessor.process(file))
                                return false;
                        }
                        return true;
                    }
                }, scope);
            }
        });
    } catch (IndexNotReadyException e) {
        throw new ProcessCanceledException();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) IdIndexEntry(com.intellij.psi.impl.cache.impl.id.IdIndexEntry) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 22 with ProcessCanceledException

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

the class DaemonCodeAnalyzerImpl method runMainPasses.

@Override
@NotNull
public List<HighlightInfo> runMainPasses(@NotNull PsiFile psiFile, @NotNull Document document, @NotNull final ProgressIndicator progress) {
    if (ApplicationManager.getApplication().isDispatchThread()) {
        throw new IllegalStateException("Must not run highlighting from under EDT");
    }
    if (!ApplicationManager.getApplication().isReadAccessAllowed()) {
        throw new IllegalStateException("Must run highlighting from under read action");
    }
    ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    if (!(indicator instanceof DaemonProgressIndicator)) {
        throw new IllegalStateException("Must run highlighting under progress with DaemonProgressIndicator");
    }
    // clear status maps to run passes from scratch so that refCountHolder won't conflict and try to restart itself on partially filled maps
    myFileStatusMap.markAllFilesDirty("prepare to run main passes");
    stopProcess(false, "disable background daemon");
    myPassExecutorService.cancelAll(true);
    final List<HighlightInfo> result;
    try {
        result = new ArrayList<>();
        final VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile != null && !virtualFile.getFileType().isBinary()) {
            List<TextEditorHighlightingPass> passes = TextEditorHighlightingPassRegistrarEx.getInstanceEx(myProject).instantiateMainPasses(psiFile, document, HighlightInfoProcessor.getEmpty());
            Collections.sort(passes, (o1, o2) -> {
                if (o1 instanceof GeneralHighlightingPass)
                    return -1;
                if (o2 instanceof GeneralHighlightingPass)
                    return 1;
                return 0;
            });
            try {
                for (TextEditorHighlightingPass pass : passes) {
                    pass.doCollectInformation(progress);
                    result.addAll(pass.getInfos());
                }
            } catch (ProcessCanceledException e) {
                LOG.debug("Canceled: " + progress);
                throw e;
            }
        }
    } finally {
        stopProcess(true, "re-enable background daemon after main passes run");
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TextEditorHighlightingPass(com.intellij.codeHighlighting.TextEditorHighlightingPass) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with ProcessCanceledException

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

the class LocalInspectionsPass method visitPriorityElementsAndInit.

@NotNull
private List<InspectionContext> visitPriorityElementsAndInit(@NotNull Map<LocalInspectionToolWrapper, Set<String>> toolToSpecifiedLanguageIds, @NotNull final InspectionManager iManager, final boolean isOnTheFly, @NotNull final ProgressIndicator indicator, @NotNull final List<PsiElement> elements, @NotNull final LocalInspectionToolSession session, @NotNull final Set<String> elementDialectIds) {
    final List<InspectionContext> init = new ArrayList<>();
    List<Map.Entry<LocalInspectionToolWrapper, Set<String>>> entries = new ArrayList<>(toolToSpecifiedLanguageIds.entrySet());
    Processor<Map.Entry<LocalInspectionToolWrapper, Set<String>>> processor = pair -> {
        LocalInspectionToolWrapper toolWrapper = pair.getKey();
        Set<String> dialectIdsSpecifiedForTool = pair.getValue();
        runToolOnElements(toolWrapper, dialectIdsSpecifiedForTool, iManager, isOnTheFly, indicator, elements, session, init, elementDialectIds);
        return true;
    };
    boolean result = JobLauncher.getInstance().invokeConcurrentlyUnderProgress(entries, indicator, myFailFastOnAcquireReadAction, processor);
    if (!result)
        throw new ProcessCanceledException();
    return init;
}
Also used : Language(com.intellij.lang.Language) InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) Trinity(com.intellij.openapi.util.Trinity) UIUtil(com.intellij.util.ui.UIUtil) com.intellij.codeInspection.ex(com.intellij.codeInspection.ex) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) Document(com.intellij.openapi.editor.Document) THashSet(gnu.trove.THashSet) Keymap(com.intellij.openapi.keymap.Keymap) THashMap(gnu.trove.THashMap) IdeActions(com.intellij.openapi.actionSystem.IdeActions) ProjectInspectionProfileManager(com.intellij.profile.codeInspection.ProjectInspectionProfileManager) HighlightingLevelManager(com.intellij.codeInsight.daemon.impl.analysis.HighlightingLevelManager) Logger(com.intellij.openapi.diagnostic.Logger) InspectionToolPresentation(com.intellij.codeInspection.ui.InspectionToolPresentation) CommonProcessors(com.intellij.util.CommonProcessors) RangeMarker(com.intellij.openapi.editor.RangeMarker) ProgressManager(com.intellij.openapi.progress.ProgressManager) DocumentWindow(com.intellij.injected.editor.DocumentWindow) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) TextRange(com.intellij.openapi.util.TextRange) KeymapUtil(com.intellij.openapi.keymap.KeymapUtil) Pass(com.intellij.codeHighlighting.Pass) Nullable(org.jetbrains.annotations.Nullable) DaemonBundle(com.intellij.codeInsight.daemon.DaemonBundle) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Processor(com.intellij.util.Processor) SmartHashSet(com.intellij.util.containers.SmartHashSet) ApplicationManager(com.intellij.openapi.application.ApplicationManager) XmlStringUtil(com.intellij.xml.util.XmlStringUtil) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) InspectionProjectProfileManager(com.intellij.profile.codeInspection.InspectionProjectProfileManager) java.util(java.util) KeymapManager(com.intellij.openapi.keymap.KeymapManager) JobLauncher(com.intellij.concurrency.JobLauncher) NonNls(org.jetbrains.annotations.NonNls) TransferToEDTQueue(com.intellij.util.containers.TransferToEDTQueue) QuickFixAction(com.intellij.codeInsight.daemon.impl.quickfix.QuickFixAction) ContainerUtil(com.intellij.util.containers.ContainerUtil) Function(java.util.function.Function) ConcurrentMap(java.util.concurrent.ConcurrentMap) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) EmptyIntentionAction(com.intellij.codeInsight.intention.EmptyIntentionAction) InjectedLanguageUtil(com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil) StringUtil(com.intellij.openapi.util.text.StringUtil) ConcurrencyUtil(com.intellij.util.ConcurrencyUtil) com.intellij.codeInspection(com.intellij.codeInspection) HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) Pair(com.intellij.openapi.util.Pair) Condition(com.intellij.openapi.util.Condition) THashSet(gnu.trove.THashSet) SmartHashSet(com.intellij.util.containers.SmartHashSet) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with ProcessCanceledException

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

the class LookupCellRenderer method getListCellRendererComponent.

@Override
public Component getListCellRendererComponent(final JList list, Object value, int index, boolean isSelected, boolean hasFocus) {
    boolean nonFocusedSelection = isSelected && myLookup.getFocusDegree() == LookupImpl.FocusDegree.SEMI_FOCUSED;
    if (!myLookup.isFocused()) {
        isSelected = false;
    }
    myIsSelected = isSelected;
    final LookupElement item = (LookupElement) value;
    final Color foreground = getForegroundColor(isSelected);
    final Color background = nonFocusedSelection ? SELECTED_NON_FOCUSED_BACKGROUND_COLOR : isSelected ? SELECTED_BACKGROUND_COLOR : BACKGROUND_COLOR;
    int allowedWidth = list.getWidth() - calcSpacing(myNameComponent, myEmptyIcon) - calcSpacing(myTailComponent, null) - calcSpacing(myTypeLabel, null);
    FontMetrics normalMetrics = getRealFontMetrics(item, false);
    FontMetrics boldMetrics = getRealFontMetrics(item, true);
    final LookupElementPresentation presentation = new RealLookupElementPresentation(isSelected ? getMaxWidth() : allowedWidth, normalMetrics, boldMetrics, myLookup);
    AccessToken token = ReadAction.start();
    try {
        if (item.isValid()) {
            try {
                item.renderElement(presentation);
            } catch (ProcessCanceledException e) {
                LOG.info(e);
                presentation.setItemTextForeground(JBColor.RED);
                presentation.setItemText("Error occurred, see the log in Help | Show Log");
            } catch (Exception | Error e) {
                LOG.error(e);
            }
        } else {
            presentation.setItemTextForeground(JBColor.RED);
            presentation.setItemText("Invalid");
        }
    } finally {
        token.finish();
    }
    myNameComponent.clear();
    myNameComponent.setBackground(background);
    allowedWidth -= setItemTextLabel(item, new JBColor(isSelected ? SELECTED_FOREGROUND_COLOR : presentation.getItemTextForeground(), presentation.getItemTextForeground()), isSelected, presentation, allowedWidth);
    Font font = myLookup.getCustomFont(item, false);
    if (font == null) {
        font = myNormalFont;
    }
    myTailComponent.setFont(font);
    myTypeLabel.setFont(font);
    myNameComponent.setIcon(augmentIcon(myLookup.getEditor(), presentation.getIcon(), myEmptyIcon));
    myTypeLabel.clear();
    if (allowedWidth > 0) {
        allowedWidth -= setTypeTextLabel(item, background, foreground, presentation, isSelected ? getMaxWidth() : allowedWidth, isSelected, nonFocusedSelection, normalMetrics);
    }
    myTailComponent.clear();
    myTailComponent.setBackground(background);
    if (isSelected || allowedWidth >= 0) {
        setTailTextLabel(isSelected, presentation, foreground, isSelected ? getMaxWidth() : allowedWidth, nonFocusedSelection, normalMetrics);
    }
    if (mySelected.containsKey(index)) {
        if (!isSelected && mySelected.get(index)) {
            myPanel.setUpdateExtender(true);
        }
    }
    mySelected.put(index, isSelected);
    final double w = myNameComponent.getPreferredSize().getWidth() + myTailComponent.getPreferredSize().getWidth() + myTypeLabel.getPreferredSize().getWidth();
    boolean useBoxLayout = isSelected && w > list.getWidth() && ((JBList) list).getExpandableItemsHandler().isEnabled();
    if (useBoxLayout != myPanel.getLayout() instanceof BoxLayout) {
        myPanel.removeAll();
        if (useBoxLayout) {
            myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.X_AXIS));
            myPanel.add(myNameComponent);
            myPanel.add(myTailComponent);
            myPanel.add(myTypeLabel);
        } else {
            myPanel.setLayout(new BorderLayout());
            myPanel.add(myNameComponent, BorderLayout.WEST);
            myPanel.add(myTailComponent, BorderLayout.CENTER);
            myPanel.add(myTypeLabel, BorderLayout.EAST);
        }
    }
    AccessibleContextUtil.setCombinedName(myPanel, myNameComponent, "", myTailComponent, " - ", myTypeLabel);
    AccessibleContextUtil.setCombinedDescription(myPanel, myNameComponent, "", myTailComponent, " - ", myTypeLabel);
    return myPanel;
}
Also used : LookupElement(com.intellij.codeInsight.lookup.LookupElement) LookupValueWithUIHint(com.intellij.codeInsight.lookup.LookupValueWithUIHint) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) RealLookupElementPresentation(com.intellij.codeInsight.lookup.RealLookupElementPresentation) LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation) AccessToken(com.intellij.openapi.application.AccessToken) JBList(com.intellij.ui.components.JBList) RealLookupElementPresentation(com.intellij.codeInsight.lookup.RealLookupElementPresentation) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 25 with ProcessCanceledException

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

the class FrameworkDetectionProcessor method collectSuitableFiles.

private void collectSuitableFiles(@NotNull VirtualFile file) {
    try {
        VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {

            @Override
            public boolean visitFile(@NotNull VirtualFile file) {
                // Since this code is invoked from New Project Wizard it's very possible that VFS isn't loaded to memory yet, so we need to do it
                // manually, otherwise refresh will do nothing
                myProgressIndicator.checkCanceled();
                return true;
            }
        });
        file.refresh(false, true);
        VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {

            @Override
            public boolean visitFile(@NotNull VirtualFile file) {
                myProgressIndicator.checkCanceled();
                if (!myProcessedFiles.add(file)) {
                    return false;
                }
                if (!file.isDirectory()) {
                    final FileType fileType = file.getFileType();
                    if (myDetectorsByFileType.containsKey(fileType)) {
                        myProgressIndicator.setText2(file.getPresentableUrl());
                        try {
                            final FileContent fileContent = new FileContentImpl(file, file.contentsToByteArray(false));
                            for (FrameworkDetectorData detector : myDetectorsByFileType.get(fileType)) {
                                if (detector.myFilePattern.accepts(fileContent)) {
                                    detector.mySuitableFiles.add(file);
                                }
                            }
                        } catch (IOException e) {
                            LOG.info(e);
                        }
                    }
                }
                return true;
            }
        });
    } catch (ProcessCanceledException ignored) {
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileContent(com.intellij.util.indexing.FileContent) FileType(com.intellij.openapi.fileTypes.FileType) FileContentImpl(com.intellij.util.indexing.FileContentImpl) IOException(java.io.IOException) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Aggregations

ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)175 NotNull (org.jetbrains.annotations.NotNull)45 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)41 VirtualFile (com.intellij.openapi.vfs.VirtualFile)38 Project (com.intellij.openapi.project.Project)28 Nullable (org.jetbrains.annotations.Nullable)23 IOException (java.io.IOException)20 Task (com.intellij.openapi.progress.Task)16 File (java.io.File)16 Document (com.intellij.openapi.editor.Document)14 Ref (com.intellij.openapi.util.Ref)13 PsiFile (com.intellij.psi.PsiFile)12 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)11 Logger (com.intellij.openapi.diagnostic.Logger)10 StringUtil (com.intellij.openapi.util.text.StringUtil)9 ContainerUtil (com.intellij.util.containers.ContainerUtil)9 ArrayList (java.util.ArrayList)9 NonNls (org.jetbrains.annotations.NonNls)9 ProgressManager (com.intellij.openapi.progress.ProgressManager)8 java.util (java.util)8