private synchronized void cancelUpdateProgress(final boolean start, @NonNls String reason) { PassExecutorService.log(myUpdateProgress, null, reason, start); myModificationCount++; if (myUpdateProgress != null) { myUpdateProgress.cancel(); myPassExecutorService.cancelAll(false); myUpdateProgress = null; } }
public List<TextEditorHighlightingPass> getPassesToShowProgressFor(Document document) { List<TextEditorHighlightingPass> allPasses = myPassExecutorService.getAllSubmittedPasses(); List<TextEditorHighlightingPass> result = new ArrayList<TextEditorHighlightingPass>(allPasses.size()); for (TextEditorHighlightingPass pass : allPasses) { if (pass.getDocument() == document || pass.getDocument() == null) { result.add(pass); } } return result; }
static Void cancelAndRestartDaemonLater( ProgressIndicator progress, final Project project, TextEditorHighlightingPass pass) { PassExecutorService.log(progress, pass, "Cancel and restart"); progress.cancel(); ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { try { Thread.sleep(new Random().nextInt(100)); } catch (InterruptedException e) { LOG.error(e); } DaemonCodeAnalyzer.getInstance(project).restart(); } }, project.getDisposed()); throw new ProcessCanceledException(); }
private void waitForTermination() { myPassExecutorService.cancelAll(true); }
@TestOnly public List<HighlightInfo> runPasses( @NotNull PsiFile file, @NotNull Document document, @NotNull TextEditor textEditor, @NotNull int[] toIgnore, boolean canChangeDocument, @Nullable Runnable callbackWhileWaiting) { assert myInitialized; assert !myDisposed; Application application = ApplicationManager.getApplication(); application.assertIsDispatchThread(); assert !application.isWriteAccessAllowed(); // pump first so that queued event do not interfere UIUtil.dispatchAllInvocationEvents(); UIUtil.dispatchAllInvocationEvents(); Project project = file.getProject(); setUpdateByTimerEnabled(false); FileStatusMap fileStatusMap = getFileStatusMap(); for (int ignoreId : toIgnore) { fileStatusMap.markFileUpToDate(document, ignoreId); } fileStatusMap.allowDirt(canChangeDocument); TextEditorBackgroundHighlighter highlighter = (TextEditorBackgroundHighlighter) textEditor.getBackgroundHighlighter(); final List<TextEditorHighlightingPass> passes = highlighter.getPasses(toIgnore); HighlightingPass[] array = passes.toArray(new HighlightingPass[passes.size()]); final DaemonProgressIndicator progress = createUpdateProgress(); progress.setDebug(LOG.isDebugEnabled()); myPassExecutorService.submitPasses( Collections.singletonMap((FileEditor) textEditor, array), progress, Job.DEFAULT_PRIORITY); try { while (progress.isRunning()) { try { if (progress.isCanceled() && progress.isRunning()) { // write action sneaked in the AWT. restart waitForTermination(); Throwable savedException = PassExecutorService.getSavedException(progress); if (savedException != null) throw savedException; return runPasses( file, document, textEditor, toIgnore, canChangeDocument, callbackWhileWaiting); } if (callbackWhileWaiting != null) { callbackWhileWaiting.run(); } progress.waitFor(100); UIUtil.dispatchAllInvocationEvents(); Throwable savedException = PassExecutorService.getSavedException(progress); if (savedException != null) throw savedException; } catch (RuntimeException e) { throw e; } catch (Error e) { e.printStackTrace(); throw e; } catch (Throwable e) { e.printStackTrace(); throw new RuntimeException(e); } } UIUtil.dispatchAllInvocationEvents(); UIUtil.dispatchAllInvocationEvents(); return getHighlights(document, null, project); } finally { fileStatusMap.allowDirt(true); waitForTermination(); } }