Search in sources :

Example 96 with ProcessCanceledException

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

the class IssueNavigationConfiguration method findIssueLinks.

public List<LinkMatch> findIssueLinks(CharSequence text) {
    final List<LinkMatch> result = new ArrayList<>();
    try {
        for (IssueNavigationLink link : myLinks) {
            Pattern issuePattern = link.getIssuePattern();
            Matcher m = issuePattern.matcher(text);
            while (m.find()) {
                try {
                    String replacement = issuePattern.matcher(m.group(0)).replaceFirst(link.getLinkRegexp());
                    addMatch(result, new TextRange(m.start(), m.end()), replacement);
                } catch (Exception e) {
                    LOG.debug("Malformed regex replacement. IssueLink: " + link + "; text: " + text, e);
                }
            }
        }
        Matcher m = URLUtil.URL_PATTERN.matcher(text);
        while (m.find()) {
            addMatch(result, new TextRange(m.start(), m.end()), m.group());
        }
    } catch (ProcessCanceledException e) {
    //skip too long processing completely
    }
    Collections.sort(result);
    return result;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) TextRange(com.intellij.openapi.util.TextRange) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 97 with ProcessCanceledException

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

the class StubUpdatingIndex method getIndexer.

@NotNull
@Override
public DataIndexer<Integer, SerializedStubTree, FileContent> getIndexer() {
    return new DataIndexer<Integer, SerializedStubTree, FileContent>() {

        @Override
        @NotNull
        public Map<Integer, SerializedStubTree> map(@NotNull final FileContent inputData) {
            final Map<Integer, SerializedStubTree> result = new THashMap<Integer, SerializedStubTree>() {

                StubUpdatingIndexKeys myKeySet;

                @Override
                public Set<Integer> keySet() {
                    if (myKeySet == null) {
                        myKeySet = new StubUpdatingIndexKeys(super.keySet());
                    }
                    return myKeySet;
                }
            };
            ApplicationManager.getApplication().runReadAction(() -> {
                final Stub rootStub = StubTreeBuilder.buildStubTree(inputData);
                if (rootStub == null)
                    return;
                VirtualFile file = inputData.getFile();
                int contentLength;
                if (file.getFileType().isBinary()) {
                    contentLength = -1;
                } else {
                    contentLength = ((FileContentImpl) inputData).getPsiFileForPsiDependentIndex().getTextLength();
                }
                rememberIndexingStamp(file, contentLength);
                final BufferExposingByteArrayOutputStream bytes = new BufferExposingByteArrayOutputStream();
                SerializationManagerEx.getInstanceEx().serialize(rootStub, bytes);
                if (DebugAssertions.DEBUG) {
                    try {
                        Stub deserialized = SerializationManagerEx.getInstanceEx().deserialize(new ByteArrayInputStream(bytes.getInternalBuffer(), 0, bytes.size()));
                        check(deserialized, rootStub);
                    } catch (ProcessCanceledException pce) {
                        throw pce;
                    } catch (Throwable t) {
                        LOG.error("Error indexing:" + file, t);
                    }
                }
                final int key = Math.abs(FileBasedIndex.getFileId(file));
                SerializedStubTree serializedStubTree = new SerializedStubTree(bytes.getInternalBuffer(), bytes.size(), rootStub, file.getLength(), contentLength);
                result.put(key, serializedStubTree);
                try {
                    ((StubUpdatingIndexKeys) result.keySet()).myStubIndicesValueMap = calcStubIndicesValueMap(serializedStubTree, key);
                } catch (StorageException ex) {
                    throw new RuntimeException(ex);
                }
            });
            return result;
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) BufferExposingByteArrayOutputStream(com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream) NotNull(org.jetbrains.annotations.NotNull) THashMap(gnu.trove.THashMap) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 98 with ProcessCanceledException

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

the class BaseRefactoringAction method actionPerformed.

@Override
public final void actionPerformed(@NotNull AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    Project project = e.getProject();
    if (project == null)
        return;
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    final Editor editor = e.getData(CommonDataKeys.EDITOR);
    final PsiElement[] elements = getPsiElementArray(dataContext);
    int eventCount = IdeEventQueue.getInstance().getEventCount();
    RefactoringActionHandler handler;
    try {
        handler = getHandler(dataContext);
    } catch (ProcessCanceledException ignored) {
        return;
    }
    if (handler == null) {
        String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.symbol.to.refactor"));
        CommonRefactoringUtil.showErrorHint(project, editor, message, RefactoringBundle.getCannotRefactorMessage(null), null);
        return;
    }
    InplaceRefactoring activeInplaceRenamer = InplaceRefactoring.getActiveInplaceRenamer(editor);
    if (!InplaceRefactoring.canStartAnotherRefactoring(editor, project, handler, elements) && activeInplaceRenamer != null) {
        InplaceRefactoring.unableToStartWarning(project, editor);
        return;
    }
    if (activeInplaceRenamer == null) {
        final LookupEx lookup = LookupManager.getActiveLookup(editor);
        if (lookup instanceof LookupImpl) {
            Runnable command = () -> ((LookupImpl) lookup).finishLookup(Lookup.NORMAL_SELECT_CHAR);
            Document doc = editor.getDocument();
            DocCommandGroupId group = DocCommandGroupId.noneGroupId(doc);
            CommandProcessor.getInstance().executeCommand(editor.getProject(), command, "Completion", group, UndoConfirmationPolicy.DEFAULT, doc);
        }
    }
    IdeEventQueue.getInstance().setEventCount(eventCount);
    if (editor != null) {
        final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
        if (file == null)
            return;
        DaemonCodeAnalyzer.getInstance(project).autoImportReferenceAtCursor(editor, file);
        handler.invoke(project, editor, file, dataContext);
    } else {
        handler.invoke(project, elements, dataContext);
    }
}
Also used : RefactoringActionHandler(com.intellij.refactoring.RefactoringActionHandler) Document(com.intellij.openapi.editor.Document) Project(com.intellij.openapi.project.Project) LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) DocCommandGroupId(com.intellij.openapi.editor.actionSystem.DocCommandGroupId) Editor(com.intellij.openapi.editor.Editor) LookupEx(com.intellij.codeInsight.lookup.LookupEx) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) InplaceRefactoring(com.intellij.refactoring.rename.inplace.InplaceRefactoring)

Example 99 with ProcessCanceledException

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

the class BaseRefactoringProcessor method doRun.

protected void doRun() {
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    final Ref<UsageInfo[]> refUsages = new Ref<>();
    final Ref<Language> refErrorLanguage = new Ref<>();
    final Ref<Boolean> refProcessCanceled = new Ref<>();
    final Ref<Boolean> anyException = new Ref<>();
    final Runnable findUsagesRunnable = new Runnable() {

        @Override
        public void run() {
            try {
                refUsages.set(DumbService.getInstance(myProject).runReadActionInSmartMode(new Computable<UsageInfo[]>() {

                    @Override
                    public UsageInfo[] compute() {
                        return findUsages();
                    }
                }));
            } catch (UnknownReferenceTypeException e) {
                refErrorLanguage.set(e.getElementLanguage());
            } catch (ProcessCanceledException e) {
                refProcessCanceled.set(Boolean.TRUE);
            } catch (Throwable e) {
                anyException.set(Boolean.TRUE);
                LOG.error(e);
            }
        }
    };
    if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(findUsagesRunnable, RefactoringBundle.message("progress.text"), true, myProject)) {
        return;
    }
    if (!refErrorLanguage.isNull()) {
        Messages.showErrorDialog(myProject, RefactoringBundle.message("unsupported.refs.found", refErrorLanguage.get().getDisplayName()), RefactoringBundle.message("error.title"));
        return;
    }
    if (DumbService.isDumb(myProject)) {
        DumbService.getInstance(myProject).showDumbModeNotification("Refactoring is not available until indices are ready");
        return;
    }
    if (!refProcessCanceled.isNull()) {
        Messages.showErrorDialog(myProject, "Index corruption detected. Please retry the refactoring - indexes will be rebuilt automatically", RefactoringBundle.message("error.title"));
        return;
    }
    if (!anyException.isNull()) {
        //do not proceed if find usages fails
        return;
    }
    assert !refUsages.isNull() : "Null usages from processor " + this;
    if (!preprocessUsages(refUsages))
        return;
    final UsageInfo[] usages = refUsages.get();
    assert usages != null;
    UsageViewDescriptor descriptor = createUsageViewDescriptor(usages);
    boolean isPreview = isPreviewUsages(usages);
    if (!isPreview) {
        isPreview = !ensureElementsWritable(usages, descriptor) || UsageViewUtil.hasReadOnlyUsages(usages);
        if (isPreview) {
            StatusBarUtil.setStatusBarInfo(myProject, RefactoringBundle.message("readonly.occurences.found"));
        }
    }
    if (isPreview) {
        for (UsageInfo usage : usages) {
            LOG.assertTrue(usage != null, getClass());
        }
        previewRefactoring(usages);
    } else {
        execute(usages);
    }
}
Also used : UsageViewDescriptor(com.intellij.usageView.UsageViewDescriptor) Ref(com.intellij.openapi.util.Ref) Language(com.intellij.lang.Language) ThrowableRunnable(com.intellij.util.ThrowableRunnable) EmptyRunnable(com.intellij.openapi.util.EmptyRunnable) Computable(com.intellij.openapi.util.Computable) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo) UsageInfo(com.intellij.usageView.UsageInfo) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 100 with ProcessCanceledException

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

the class CallerChooserBase method createTree.

private Tree createTree() {
    final Runnable cancelCallback = () -> {
        if (myInitDone) {
            close(CANCEL_EXIT_CODE);
        } else {
            throw new ProcessCanceledException();
        }
    };
    final CheckedTreeNode root = createTreeNode(null, new HashSet<>(), cancelCallback);
    myRoot = createTreeNode(myMethod, new HashSet<>(), cancelCallback);
    root.add(myRoot);
    final CheckboxTree.CheckboxTreeCellRenderer cellRenderer = new CheckboxTree.CheckboxTreeCellRenderer(true, false) {

        @Override
        public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            if (value instanceof MethodNodeBase) {
                ((MethodNodeBase) value).customizeRenderer(getTextRenderer());
            }
        }
    };
    Tree tree = new CheckboxTree(cellRenderer, root, new CheckboxTreeBase.CheckPolicy(false, true, true, false));
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.getSelectionModel().setSelectionPath(new TreePath(myRoot.getPath()));
    return tree;
}
Also used : TreePath(javax.swing.tree.TreePath) Tree(com.intellij.ui.treeStructure.Tree) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) HashSet(com.intellij.util.containers.HashSet)

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