use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.
the class EditorHighlighterFactoryImpl method createEditorHighlighter.
@NotNull
@Override
public EditorHighlighter createEditorHighlighter(@NotNull VirtualFile vFile, @NotNull EditorColorsScheme settings, @Nullable Project project) {
FileType fileType = vFile.getFileType();
if (fileType instanceof LanguageFileType) {
LanguageFileType substFileType = substituteFileType(((LanguageFileType) fileType).getLanguage(), vFile, project);
if (substFileType != null) {
EditorHighlighterProvider provider = FileTypeEditorHighlighterProviders.INSTANCE.forFileType(substFileType);
EditorHighlighter editorHighlighter = provider.getEditorHighlighter(project, substFileType, vFile, settings);
boolean isPlain = editorHighlighter.getClass() == LexerEditorHighlighter.class && ((LexerEditorHighlighter) editorHighlighter).isPlain();
if (!isPlain) {
return editorHighlighter;
}
}
try {
return FileTypeEditorHighlighterProviders.INSTANCE.forFileType(fileType).getEditorHighlighter(project, fileType, vFile, settings);
} catch (ProcessCanceledException e) {
throw e;
} catch (Exception e) {
LOG.error(e);
}
}
SyntaxHighlighter highlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, project, vFile);
return createEditorHighlighter(highlighter, settings);
}
use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.
the class ForwardDependenciesBuilder method visit.
private void visit(final PsiFile file, final ProjectFileIndex fileIndex, final PsiManager psiManager, int depth) {
final FileViewProvider viewProvider = file.getViewProvider();
if (viewProvider.getBaseLanguage() != file.getLanguage())
return;
if (getScopeOfInterest() != null && !getScopeOfInterest().contains(file))
return;
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
final VirtualFile virtualFile = file.getVirtualFile();
if (indicator != null) {
if (indicator.isCanceled()) {
throw new ProcessCanceledException();
}
indicator.setText(AnalysisScopeBundle.message("package.dependencies.progress.text"));
if (virtualFile != null) {
indicator.setText2(getRelativeToProjectPath(virtualFile));
}
if (myTotalFileCount > 0) {
indicator.setFraction(((double) ++myFileCount) / myTotalFileCount);
}
}
final boolean isInLibrary = virtualFile == null || fileIndex.isInLibrarySource(virtualFile) || fileIndex.isInLibraryClasses(virtualFile);
final Set<PsiFile> collectedDeps = new HashSet<>();
final HashSet<PsiFile> processed = new HashSet<>();
collectedDeps.add(file);
do {
if (depth++ > getTransitiveBorder())
return;
for (PsiFile psiFile : new HashSet<>(collectedDeps)) {
final VirtualFile vFile = psiFile.getVirtualFile();
if (vFile != null) {
if (indicator != null) {
indicator.setText2(getRelativeToProjectPath(vFile));
}
if (!isInLibrary && (fileIndex.isInLibraryClasses(vFile) || fileIndex.isInLibrarySource(vFile))) {
processed.add(psiFile);
}
}
final Set<PsiFile> found = new HashSet<>();
if (!processed.contains(psiFile)) {
processed.add(psiFile);
analyzeFileDependencies(psiFile, new DependencyProcessor() {
@Override
public void process(PsiElement place, PsiElement dependency) {
PsiFile dependencyFile = dependency.getContainingFile();
if (dependencyFile != null) {
if (viewProvider == dependencyFile.getViewProvider())
return;
if (dependencyFile.isPhysical()) {
final VirtualFile virtualFile = dependencyFile.getVirtualFile();
if (virtualFile != null && (fileIndex.isInContent(virtualFile) || fileIndex.isInLibraryClasses(virtualFile) || fileIndex.isInLibrarySource(virtualFile))) {
final PsiElement navigationElement = dependencyFile.getNavigationElement();
found.add(navigationElement instanceof PsiFile ? (PsiFile) navigationElement : dependencyFile);
}
}
}
}
});
Set<PsiFile> deps = getDependencies().get(file);
if (deps == null) {
deps = new HashSet<>();
getDependencies().put(file, deps);
}
deps.addAll(found);
getDirectDependencies().put(psiFile, new HashSet<>(found));
collectedDeps.addAll(found);
psiManager.dropResolveCaches();
InjectedLanguageManager.getInstance(file.getProject()).dropFileCaches(file);
}
}
collectedDeps.removeAll(processed);
} while (isTransitive() && !collectedDeps.isEmpty());
}
use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.
the class InspectionProfileImpl method initialize.
@Override
protected void initialize(@Nullable Project project) {
SchemeDataHolder<? super InspectionProfileImpl> dataHolder = myDataHolder;
if (dataHolder != null) {
myDataHolder = null;
Element element = dataHolder.read();
if (element.getName().equals("component")) {
element = element.getChild("profile");
}
assert element != null;
readExternal(element);
}
if (myBaseProfile != null) {
myBaseProfile.initInspectionTools(project);
}
final List<InspectionToolWrapper> tools;
try {
tools = createTools(project);
} catch (ProcessCanceledException ignored) {
return;
}
final Map<String, List<String>> dependencies = new THashMap<>();
for (InspectionToolWrapper toolWrapper : tools) {
addTool(project, toolWrapper, dependencies);
}
DFSTBuilder<String> builder = new DFSTBuilder<>(GraphGenerator.generate(new InboundSemiGraph<String>() {
@Override
public Collection<String> getNodes() {
return dependencies.keySet();
}
@Override
public Iterator<String> getIn(String n) {
return dependencies.get(n).iterator();
}
}));
if (builder.isAcyclic()) {
myScopesOrder = ArrayUtil.toStringArray(builder.getSortedNodes());
}
copyToolsConfigurations(project);
initialized = true;
if (dataHolder != null) {
// should be only after set myInitialized
dataHolder.updateDigest(this);
}
}
use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method testInterruptOnTyping.
public void testInterruptOnTyping() throws Throwable {
@NonNls String filePath = "/psi/resolve/Thinlet.java";
configureByFile(filePath);
highlightErrors();
final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(getProject());
codeAnalyzer.restart();
try {
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
PsiFile file = getFile();
Editor editor = getEditor();
Project project = file.getProject();
CodeInsightTestFixtureImpl.ensureIndexesUpToDate(project);
TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(editor);
codeAnalyzer.runPasses(file, editor.getDocument(), textEditor, ArrayUtil.EMPTY_INT_ARRAY, true, () -> type(' '));
} catch (ProcessCanceledException ignored) {
return;
}
fail("PCE must have been thrown");
}
use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method checkDaemonReaction.
private void checkDaemonReaction(boolean mustCancelItself, @NotNull final Runnable action) {
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
highlightErrors();
myDaemonCodeAnalyzer.waitForTermination();
TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(getEditor());
final AtomicBoolean run = new AtomicBoolean();
Disposable disposable = Disposer.newDisposable();
final AtomicReference<RuntimeException> stopDaemonReason = new AtomicReference<>();
StorageUtilKt.setDEBUG_LOG("");
getProject().getMessageBus().connect(disposable).subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, new DaemonCodeAnalyzer.DaemonListenerAdapter() {
@Override
public void daemonCancelEventOccurred(@NotNull String reason) {
RuntimeException e = new RuntimeException("Some bastard's restarted daemon: " + reason + "\nStorage write log: ----------\n" + StorageUtilKt.getDEBUG_LOG() + "\n--------------");
stopDaemonReason.compareAndSet(null, e);
}
});
try {
while (true) {
try {
myDaemonCodeAnalyzer.runPasses(getFile(), getDocument(getFile()), textEditor, new int[0], true, () -> {
if (!run.getAndSet(true)) {
action.run();
}
});
break;
} catch (ProcessCanceledException ignored) {
}
}
if (mustCancelItself) {
assertNotNull(stopDaemonReason.get());
} else {
if (stopDaemonReason.get() != null)
throw stopDaemonReason.get();
}
} finally {
StorageUtilKt.setDEBUG_LOG(null);
Disposer.dispose(disposable);
}
}
Aggregations