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;
}
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;
}
};
}
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);
}
}
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);
}
}
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;
}
Aggregations