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