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