Search in sources :

Example 16 with ProcessCanceledException

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

the class CompilerTask method run.

@Override
public void run(@NotNull final ProgressIndicator indicator) {
    myIndicator = indicator;
    final ProjectManager projectManager = ProjectManager.getInstance();
    projectManager.addProjectManagerListener(myProject, myCloseListener = new CloseListener());
    final Semaphore semaphore = ((CompilerManagerImpl) CompilerManager.getInstance(myProject)).getCompilationSemaphore();
    boolean acquired = false;
    try {
        try {
            while (!acquired) {
                acquired = semaphore.tryAcquire(300, TimeUnit.MILLISECONDS);
                if (!acquired && !myWaitForPreviousSession) {
                    return;
                }
                if (indicator.isCanceled()) {
                    // let compile work begin in order to stop gracefuly on cancel event
                    break;
                }
            }
        } catch (InterruptedException ignored) {
        }
        if (!isHeadless()) {
            addIndicatorDelegate();
        }
        myCompileWork.run();
    } catch (ProcessCanceledException ignored) {
    } finally {
        try {
            indicator.stop();
            projectManager.removeProjectManagerListener(myProject, myCloseListener);
        } finally {
            if (acquired) {
                semaphore.release();
            }
        }
    }
}
Also used : CompilerManagerImpl(com.intellij.compiler.CompilerManagerImpl) Semaphore(java.util.concurrent.Semaphore) ProjectManager(com.intellij.openapi.project.ProjectManager) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 17 with ProcessCanceledException

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

the class CompilerReferenceServiceImpl method getHierarchyInfo.

@Nullable
private CompilerHierarchyInfoImpl getHierarchyInfo(@NotNull PsiNamedElement aClass, @NotNull GlobalSearchScope useScope, @NotNull GlobalSearchScope searchScope, @NotNull FileType searchFileType, @NotNull CompilerHierarchySearchType searchType) {
    if (!isServiceEnabledFor(aClass) || searchScope == LibraryScopeCache.getInstance(myProject).getLibrariesOnlyScope())
        return null;
    try {
        Map<VirtualFile, Object[]> candidatesPerFile = ReadAction.compute(() -> {
            if (myProject.isDisposed())
                throw new ProcessCanceledException();
            return CachedValuesManager.getCachedValue(aClass, () -> CachedValueProvider.Result.create(new ConcurrentFactoryMap<HierarchySearchKey, Map<VirtualFile, Object[]>>() {

                @Nullable
                @Override
                protected Map<VirtualFile, Object[]> create(HierarchySearchKey key) {
                    return calculateDirectInheritors(aClass, useScope, key.mySearchFileType, key.mySearchType);
                }
            }, PsiModificationTracker.MODIFICATION_COUNT, this)).get(new HierarchySearchKey(searchType, searchFileType));
        });
        if (candidatesPerFile == null)
            return null;
        GlobalSearchScope dirtyScope = myDirtyScopeHolder.getDirtyScope();
        if (ElementPlace.LIB == ReadAction.compute(() -> ElementPlace.get(aClass.getContainingFile().getVirtualFile(), myProjectFileIndex))) {
            dirtyScope = dirtyScope.union(LibraryScopeCache.getInstance(myProject).getLibrariesOnlyScope());
        }
        return new CompilerHierarchyInfoImpl(candidatesPerFile, aClass, dirtyScope, searchScope, myProject, searchFileType, searchType);
    } catch (ProcessCanceledException e) {
        throw e;
    } catch (RuntimeException e) {
        return onException(e, "hierarchy");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ConcurrentFactoryMap(com.intellij.util.containers.ConcurrentFactoryMap) Nullable(org.jetbrains.annotations.Nullable) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with ProcessCanceledException

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

the class KotlinBytecodeToolWindow method getBytecodeForFile.

// public for tests
@NotNull
public static String getBytecodeForFile(@NotNull KtFile ktFile, @NotNull CompilerConfiguration configuration) {
    GenerationState state;
    try {
        state = compileSingleFile(ktFile, configuration);
    } catch (ProcessCanceledException e) {
        throw e;
    } catch (Exception e) {
        return printStackTraceToString(e);
    }
    StringBuilder answer = new StringBuilder();
    Collection<Diagnostic> diagnostics = state.getCollectedExtraJvmDiagnostics().all();
    if (!diagnostics.isEmpty()) {
        answer.append("// Backend Errors: \n");
        answer.append("// ================\n");
        for (Diagnostic diagnostic : diagnostics) {
            answer.append("// Error at ").append(diagnostic.getPsiFile().getName()).append(StringsKt.join(diagnostic.getTextRanges(), ",")).append(": ").append(DefaultErrorMessages.render(diagnostic)).append("\n");
        }
        answer.append("// ================\n\n");
    }
    OutputFileCollection outputFiles = state.getFactory();
    for (OutputFile outputFile : outputFiles.asList()) {
        answer.append("// ================");
        answer.append(outputFile.getRelativePath());
        answer.append(" =================\n");
        answer.append(outputFile.asText()).append("\n\n");
    }
    return answer.toString();
}
Also used : OutputFile(org.jetbrains.kotlin.backend.common.output.OutputFile) OutputFileCollection(org.jetbrains.kotlin.backend.common.output.OutputFileCollection) Diagnostic(org.jetbrains.kotlin.diagnostics.Diagnostic) GenerationState(org.jetbrains.kotlin.codegen.state.GenerationState) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with ProcessCanceledException

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

the class DebugInfoAnnotator method annotate.

@Override
public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) {
    if (!isDebugInfoEnabled() || !ProjectRootsUtil.isInProjectOrLibSource(element)) {
        return;
    }
    if (element instanceof KtFile && !(element instanceof KtCodeFragment)) {
        KtFile file = (KtFile) element;
        try {
            BindingContext bindingContext = ResolutionUtils.analyzeFully(file);
            DebugInfoUtil.markDebugAnnotations(file, bindingContext, new DebugInfoUtil.DebugInfoReporter() {

                @Override
                public void reportElementWithErrorType(@NotNull KtReferenceExpression expression) {
                    holder.createErrorAnnotation(expression, "[DEBUG] Resolved to error element").setTextAttributes(KotlinHighlightingColors.RESOLVED_TO_ERROR);
                }

                @Override
                public void reportMissingUnresolved(@NotNull KtReferenceExpression expression) {
                    holder.createErrorAnnotation(expression, "[DEBUG] Reference is not resolved to anything, but is not marked unresolved").setTextAttributes(KotlinHighlightingColors.DEBUG_INFO);
                }

                @Override
                public void reportUnresolvedWithTarget(@NotNull KtReferenceExpression expression, @NotNull String target) {
                    holder.createErrorAnnotation(expression, "[DEBUG] Reference marked as unresolved is actually resolved to " + target).setTextAttributes(KotlinHighlightingColors.DEBUG_INFO);
                }
            });
        } catch (ProcessCanceledException e) {
            throw e;
        } catch (Throwable e) {
            // TODO
            holder.createErrorAnnotation(element, e.getClass().getCanonicalName() + ": " + e.getMessage());
            e.printStackTrace();
        }
    }
}
Also used : KtReferenceExpression(org.jetbrains.kotlin.psi.KtReferenceExpression) KtCodeFragment(org.jetbrains.kotlin.psi.KtCodeFragment) KtFile(org.jetbrains.kotlin.psi.KtFile) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) DebugInfoUtil(org.jetbrains.kotlin.checkers.DebugInfoUtil) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 20 with ProcessCanceledException

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

the class PsiSearchHelperImpl method processVirtualFile.

private void processVirtualFile(@NotNull final VirtualFile vfile, @NotNull final ProgressIndicator progress, @NotNull final Processor<? super PsiFile> localProcessor, @NotNull final AtomicBoolean canceled) throws ApplicationUtil.CannotRunReadActionException {
    final PsiFile file = ApplicationUtil.tryRunReadAction(() -> vfile.isValid() ? myManager.findFile(vfile) : null);
    if (file != null && !(file instanceof PsiBinaryFile)) {
        // load contents outside read action
        if (FileDocumentManager.getInstance().getCachedDocument(vfile) == null) {
            // cache bytes in vfs
            try {
                vfile.contentsToByteArray();
            } catch (IOException ignored) {
            }
        }
        ApplicationUtil.tryRunReadAction(() -> {
            final Project project = myManager.getProject();
            if (project.isDisposed())
                throw new ProcessCanceledException();
            if (DumbService.isDumb(project))
                throw new ApplicationUtil.CannotRunReadActionException();
            List<PsiFile> psiRoots = file.getViewProvider().getAllFiles();
            Set<PsiFile> processed = new THashSet<>(psiRoots.size() * 2, (float) 0.5);
            for (final PsiFile psiRoot : psiRoots) {
                progress.checkCanceled();
                assert psiRoot != null : "One of the roots of file " + file + " is null. All roots: " + psiRoots + "; ViewProvider: " + file.getViewProvider() + "; Virtual file: " + file.getViewProvider().getVirtualFile();
                if (!processed.add(psiRoot))
                    continue;
                if (!psiRoot.isValid()) {
                    continue;
                }
                if (!localProcessor.process(psiRoot)) {
                    canceled.set(true);
                    break;
                }
            }
        });
    }
}
Also used : Project(com.intellij.openapi.project.Project) ApplicationUtil(com.intellij.openapi.application.ex.ApplicationUtil) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) 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