Search in sources :

Example 46 with ProcessCanceledException

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);
}
Also used : LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 47 with ProcessCanceledException

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());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) HashSet(java.util.HashSet)

Example 48 with ProcessCanceledException

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);
    }
}
Also used : InboundSemiGraph(com.intellij.util.graph.InboundSemiGraph) THashMap(gnu.trove.THashMap) PsiElement(com.intellij.psi.PsiElement) Element(org.jdom.Element) DFSTBuilder(com.intellij.util.graph.DFSTBuilder) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 49 with ProcessCanceledException

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");
}
Also used : NonNls(org.jetbrains.annotations.NonNls) Project(com.intellij.openapi.project.Project) TextEditor(com.intellij.openapi.fileEditor.TextEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 50 with ProcessCanceledException

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);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TextEditor(com.intellij.openapi.fileEditor.TextEditor) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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