private String getTemporaryBuffer( IjFile file ) { final VirtualFile virtualFile = file.getVirtualFile(); // we're getting the cached documents since getDocument() forces PSI creating which will cause deadlock !!! if( virtualFile != null && !virtualFile.getFileType().isBinary() ) { final Document document = FileDocumentManager.getInstance().getCachedDocument( virtualFile ); final String[] result = new String[1]; if( document != null ) { if( ApplicationManagerEx.getApplicationEx().tryRunReadAction( () -> result[0] = document.getText() ) ) { return result[0]; } else { return document.getCharsSequence().toString(); } } } return null; }
public void startup() { if (myProjectPath == null || myOutPath == null) { GenerateAntMain.printHelp(); } SwingUtilities.invokeLater(new Runnable() { public void run() { ApplicationEx application = ApplicationManagerEx.getApplicationEx(); try { logMessage(0, "Starting app... "); application.doNotSave(); application.load(); logMessageLn(0, "done"); GenerateAntApplication.this.run(); } catch (Exception e) { GenerateAntApplication.LOG.error(e); } finally { application.exit(true, true); } } }); }
private void wrapInReadActionAndIndicator(@NotNull final Runnable process) { Runnable toRun = runInReadAction ? new Runnable() { @Override public void run() { if (!ApplicationManagerEx.getApplicationEx().tryRunReadAction(process)) { failedSubTasks = new ArrayList<ApplierCompleter<T>>(); failedSubTasks.add(ApplierCompleter.this); doComplete(throwable); } } } : process; ProgressIndicator existing = ProgressManager.getInstance().getProgressIndicator(); if (existing == progressIndicator) { toRun.run(); } else { ProgressManager.getInstance().executeProcessUnderProgress(toRun, progressIndicator); } }
static void setupCloseAction(final JFrame frame) { frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); frame.addWindowListener( new WindowAdapter() { public void windowClosing(final WindowEvent e) { frame.dispose(); final Application app = ApplicationManager.getApplication(); app.invokeLater(new DumbAwareRunnable() { public void run() { if (app.isDisposed()) { ApplicationManagerEx.getApplicationEx().exit(); return; } final Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); if (openProjects.length == 0) { ApplicationManagerEx.getApplicationEx().exit(); } } }, ModalityState.NON_MODAL); } } ); }
public void actionPerformed(@NotNull AnActionEvent e) { Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); if (project == null) { project = ProjectManager.getInstance().getDefaultProject(); } final long startTime = System.nanoTime(); SwingUtilities.invokeLater(new Runnable() { public void run() { final long endTime = System.nanoTime(); if (ApplicationManagerEx.getApplicationEx().isInternal()) { System.out.println("Displaying settings dialog took " + ((endTime - startTime) / 1000000) + " ms"); } } }); ShowSettingsUtil.getInstance().showSettingsDialog(project, ShowSettingsUtilImpl.getConfigurableGroups(project, true)); }
@Override public void apply() throws ConfigurationException { final String applyMessage = myPluginManagerMain.apply(); if (applyMessage != null) { throw new ConfigurationException(applyMessage); } if (myPluginManagerMain.isRequireShutdown()) { if (showRestartDialog() == Messages.YES) { ApplicationManagerEx.getApplicationEx().restart(true); } else { myPluginManagerMain.ignoreChanges(); } } }
public boolean canHandle(IdeaLoggingEvent event) { if (ourLoggerBroken) return false; try { UpdateChecker.checkForUpdate(event); boolean notificationEnabled = !DISABLED_VALUE.equals(System.getProperty(FATAL_ERROR_NOTIFICATION_PROPERTY, ENABLED_VALUE)); ErrorReportSubmitter submitter = IdeErrorsDialog.getSubmitter(event.getThrowable()); boolean showPluginError = !(submitter instanceof ITNReporter) || ((ITNReporter)submitter).showErrorInRelease(event); //noinspection ThrowableResultOfMethodCallIgnored return notificationEnabled || showPluginError || ApplicationManagerEx.getApplicationEx().isInternal() || isOOMError(event.getThrowable()) || event.getThrowable() instanceof MappingFailedException; } catch (LinkageError e) { if (e.getMessage().contains("Could not initialize class com.intellij.diagnostic.IdeErrorsDialog")) { //noinspection AssignmentToStaticFieldFromInstanceMethod ourLoggerBroken = true; } throw e; } }
public IdeErrorsDialog(MessagePool messagePool, @Nullable LogMessage defaultMessage) { super(JOptionPane.getRootFrame(), false); myMessagePool = messagePool; ApplicationEx app = ApplicationManagerEx.getApplicationEx(); myInternalMode = app != null && app.isInternal(); setTitle(DiagnosticBundle.message("error.list.title")); init(); rebuildHeaders(); if (defaultMessage == null || !moveSelectionToMessage(defaultMessage)) { moveSelectionToEarliestMessage(); } setCancelButtonText(CommonBundle.message("close.action.name")); setModal(false); if (myInternalMode) { if (ourDevelopersList.isEmpty()) { loadDevelopersAsynchronously(); } else { myDetailsTabForm.setDevelopers(ourDevelopersList); } } }
@Override public void releaseFoldings(@NotNull Editor editor) { ApplicationManagerEx.getApplicationEx().assertIsDispatchThread(); final Project project = editor.getProject(); if (project != null && (!project.equals(myProject) || !project.isOpen())) return; Document document = editor.getDocument(); PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(document); if (file == null || !file.getViewProvider().isPhysical() || !file.isValid()) return; PsiDocumentManager.getInstance(myProject).commitDocument(document); Editor[] otherEditors = EditorFactory.getInstance().getEditors(document, myProject); if (otherEditors.length == 0 && !editor.isDisposed()) { getDocumentFoldingInfo(document).loadFromEditor(editor); } EditorFoldingInfo.get(editor).dispose(); }
@Override public void invokeDslErrorPopup(Throwable e, final Project project, @NotNull VirtualFile vfile) { if (!GroovyDslFileIndex.isActivated(vfile)) { return; } final String exceptionText = ExceptionUtil.getThrowableText(e); LOG.info(exceptionText); GroovyDslFileIndex.disableFile(vfile, DslActivationStatus.Status.ERROR, exceptionText); if (!ApplicationManagerEx.getApplicationEx().isInternal() && !ProjectRootManager.getInstance(project).getFileIndex().isInContent(vfile)) { return; } String content = "<p>" + e.getMessage() + "</p><p><a href=\"\">Click here to investigate.</a></p>"; NOTIFICATION_GROUP.createNotification("DSL script execution error", content, NotificationType.ERROR, new NotificationListener() { @Override public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { InvestigateFix.analyzeStackTrace(project, exceptionText); notification.expire(); } }).notify(project); }
public void startup() { if (myProjectPath == null || myOutPath == null) { GenerateAntMain.printHelp(); } SwingUtilities.invokeLater(new Runnable() { public void run() { ApplicationEx application = ApplicationManagerEx.getApplicationEx(); try { logMessage(0, "Starting app... "); application.doNotSave(); application.load(PathManager.getOptionsPath()); logMessageLn(0, "done"); GenerateAntApplication.this.run(); } catch (Exception e) { GenerateAntApplication.LOG.error(e); } finally { application.exit(true); } } }); }
private void setupCloseAction() { setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); addWindowListener( new WindowAdapter() { public void windowClosing(final WindowEvent e) { dispose(); final Application app = ApplicationManager.getApplication(); app.invokeLater(new DumbAwareRunnable() { public void run() { if (app.isDisposed()) { ApplicationManagerEx.getApplicationEx().exit(); return; } final Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); if (openProjects.length == 0) { ApplicationManagerEx.getApplicationEx().exit(); } } }, ModalityState.NON_MODAL); } } ); }
public void saveProjectsAndDocuments() { if (LOG.isDebugEnabled()) { LOG.debug("enter: save()"); } if (ApplicationManager.getApplication().isDisposed()) return; if (myBlockSaveOnFrameDeactivationCount.get() == 0 && GeneralSettings.getInstance().isSaveOnFrameDeactivation()) { FileDocumentManager.getInstance().saveAllDocuments(); Project[] openProjects = ProjectManagerEx.getInstanceEx().getOpenProjects(); for (Project project : openProjects) { if (LOG.isDebugEnabled()) { LOG.debug("save project: " + project); } project.save(); } if (LOG.isDebugEnabled()) { LOG.debug("save application settings"); } ApplicationManagerEx.getApplicationEx().saveSettings(); if (LOG.isDebugEnabled()) { LOG.debug("exit: save()"); } } }
public void actionPerformed(AnActionEvent e) { Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); if (project == null) { project = ProjectManager.getInstance().getDefaultProject(); } final long startTime = System.nanoTime(); SwingUtilities.invokeLater(new Runnable() { public void run() { final long endTime = System.nanoTime(); if (ApplicationManagerEx.getApplicationEx().isInternal()) { System.out.println("Displaying settings dialog took " + ((endTime - startTime) / 1000000) + " ms"); } } }); ShowSettingsUtil.getInstance().showSettingsDialog(project, new ProjectConfigurablesGroup(project), new IdeConfigurablesGroup()); }
public void apply() throws ConfigurationException { final String applyMessage = myPluginManagerMain.apply(); if (applyMessage != null) { throw new ConfigurationException(applyMessage); } if (myPluginManagerMain.isRequireShutdown()) { final ApplicationEx app = ApplicationManagerEx.getApplicationEx(); int response = app.isRestartCapable() ? showRestartIDEADialog() : showShutDownIDEADialog(); if (response == 0) { app.restart(true); } else { myPluginManagerMain.ignoreChanges(); } } }
private static void notifyPluginsWereInstalled(@Nullable String pluginName) { final ApplicationEx app = ApplicationManagerEx.getApplicationEx(); final boolean restartCapable = app.isRestartCapable(); String message = restartCapable ? IdeBundle.message("message.idea.restart.required", ApplicationNamesInfo.getInstance().getFullProductName()) : IdeBundle.message("message.idea.shutdown.required", ApplicationNamesInfo.getInstance().getFullProductName()); message += "<br><a href="; message += restartCapable ? "\"restart\">Restart now" : "\"shutdown\">Shutdown"; message += "</a>"; Notifications.Bus.notify(new Notification("Plugins Lifecycle Group", pluginName != null ? "Plugin \'" + pluginName + "\' was successfully installed" : "Plugins were installed", XmlStringUtil.wrapInHtml(message), NotificationType.INFORMATION, new NotificationListener() { @Override public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { notification.expire(); if (restartCapable) { app.restart(true); } else { app.exit(true); } } })); }
public boolean canHandle(IdeaLoggingEvent event) { if (ourLoggerBroken) return false; try { boolean notificationEnabled = !DISABLED_VALUE.equals(System.getProperty(FATAL_ERROR_NOTIFICATION_PROPERTY, ENABLED_VALUE)); ErrorReportSubmitter submitter = IdeErrorsDialog.getSubmitter(event.getThrowable()); boolean showPluginError = !(submitter instanceof ITNReporter) || ((ITNReporter)submitter).showErrorInRelease(event); //noinspection ThrowableResultOfMethodCallIgnored return notificationEnabled || showPluginError || ApplicationManagerEx.getApplicationEx().isInternal() || isOOMError(event.getThrowable()) || event.getThrowable() instanceof MappingFailedException; } catch (LinkageError e) { if (e.getMessage().contains("Could not initialize class com.intellij.diagnostic.IdeErrorsDialog")) { //noinspection AssignmentToStaticFieldFromInstanceMethod ourLoggerBroken = true; } throw e; } }
static void invokeDslErrorPopup(Throwable e, final Project project, @NotNull VirtualFile vfile) { if (!isActivated(vfile)) { return; } final String exceptionText = ExceptionUtil.getThrowableText(e); LOG.info(exceptionText); disableFile(vfile, exceptionText); if (!ApplicationManagerEx.getApplicationEx().isInternal() && !ProjectRootManager.getInstance(project).getFileIndex().isInContent(vfile)) { return; } String content = "<p>" + e.getMessage() + "</p><p><a href=\"\">Click here to investigate.</a></p>"; NOTIFICATION_GROUP.createNotification("DSL script execution error", content, NotificationType.ERROR, new NotificationListener() { @Override public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { GroovyDslAnnotator.analyzeStackTrace(project, exceptionText); notification.expire(); } }).notify(project); }
private void wrapInReadActionAndIndicator(@Nonnull final Runnable process) { Runnable toRun = runInReadAction ? () -> { if (!ApplicationManagerEx.getApplicationEx().tryRunReadAction(process)) { failedSubTasks.add(this); doComplete(throwable); } } : process; ProgressIndicator existing = ProgressManager.getInstance().getProgressIndicator(); if (existing == progressIndicator) { // we are already wrapped in an indicator - most probably because we came here from helper which steals children tasks toRun.run(); } else { ProgressManager.getInstance().executeProcessUnderProgress(toRun, progressIndicator); } }
private boolean tryToReloadApplication() { if (ApplicationManager.getApplication().isDisposed()) { return false; } if (myChangedApplicationFiles.isEmpty()) { return true; } Set<StateStorage> causes = new THashSet<>(myChangedApplicationFiles); myChangedApplicationFiles.clear(); ReloadComponentStoreStatus status = ComponentStoreImpl.reloadStore(causes, ((ApplicationImpl)ApplicationManager.getApplication()).getStateStore()); if (status == ReloadComponentStoreStatus.RESTART_AGREED) { ApplicationManagerEx.getApplicationEx().restart(true); return false; } else { return status == ReloadComponentStoreStatus.SUCCESS || status == ReloadComponentStoreStatus.RESTART_CANCELLED; } }
private void setupCloseAction() { setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); addWindowListener( new WindowAdapter() { @Override public void windowClosing(@Nonnull final WindowEvent e) { if (isTemporaryDisposed()) return; final Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); if (openProjects.length > 1 || openProjects.length == 1 && SystemInfo.isMacSystemMenu) { if (myProject != null && myProject.isOpen()) { ProjectUtil.closeAndDispose(myProject); } ApplicationManager.getApplication().getMessageBus().syncPublisher(AppLifecycleListener.TOPIC).projectFrameClosed(); WelcomeFrame.showIfNoProjectOpened(); } else { ApplicationManagerEx.getApplicationEx().exit(); } } } ); }
public void run(boolean newConfigFolder) { try { ApplicationEx app = ApplicationManagerEx.getApplicationEx(); app.load(PathManager.getOptionsPath()); if (myPostStarter.needStartInTransaction()) { ((TransactionGuardImpl)TransactionGuard.getInstance()).performUserActivity(() -> myPostStarter.main(newConfigFolder, myArgs)); } else { myPostStarter.main(newConfigFolder, myArgs); } myPostStarter = null; ourLoaded = true; } catch (Exception e) { throw new RuntimeException(e); } }
public void actionPerformed(AnActionEvent e) { Project project = e.getData(CommonDataKeys.PROJECT); if (project == null) { project = ProjectManager.getInstance().getDefaultProject(); } final long startTime = System.nanoTime(); SwingUtilities.invokeLater(new Runnable() { public void run() { final long endTime = System.nanoTime(); if (ApplicationManagerEx.getApplicationEx().isInternal()) { System.out.println("Displaying settings dialog took " + ((endTime - startTime) / 1000000) + " ms"); } } }); ShowSettingsUtil.getInstance().showSettingsDialog(project); }
@Override public void apply() throws ConfigurationException { final String applyMessage = myPluginManagerMain.apply(); if (applyMessage != null) { throw new ConfigurationException(applyMessage); } if (myPluginManagerMain.isRequireShutdown()) { final ApplicationEx app = ApplicationManagerEx.getApplicationEx(); int response = app.isRestartCapable() ? showRestartIDEADialog() : showShutDownIDEADialog(); if (response == Messages.YES) { app.restart(true); } else { myPluginManagerMain.ignoreChanges(); } } }
public static void notifyPluginsWereUpdated(final String title, final Project project) { final ApplicationEx app = ApplicationManagerEx.getApplicationEx(); final boolean restartCapable = app.isRestartCapable(); String message = restartCapable ? IdeBundle.message("message.idea.restart.required", ApplicationNamesInfo.getInstance().getFullProductName()) : IdeBundle.message("message.idea.shutdown.required", ApplicationNamesInfo.getInstance().getFullProductName()); message += "<br><a href="; message += restartCapable ? "\"restart\">Restart now" : "\"shutdown\">Shutdown"; message += "</a>"; new NotificationGroup("Plugins Lifecycle Group", NotificationDisplayType.STICKY_BALLOON, true) .createNotification(title, XmlStringUtil.wrapInHtml(message), NotificationType.INFORMATION, new NotificationListener() { @Override public void hyperlinkUpdate(@Nonnull Notification notification, @Nonnull HyperlinkEvent event) { notification.expire(); if (restartCapable) { app.restart(true); } else { app.exit(true, true); } } }).notify(project); }
private void updateConnection() { final ApplicationEx app = ApplicationManagerEx.getApplicationEx(); boolean value = PropertiesComponent.getInstance().getBoolean(KEY); if(value) { myConnection = app.getMessageBus().connect(); myConnection.subscribe(ApplicationActivationListener.TOPIC, myListener); } else { if(myConnection != null) { myConnection.disconnect(); } } }
public static <T> T runInReadActionWithWriteActionPriorityWithRetries(@NotNull Computable<T> action) { if(ApplicationManagerEx.getApplicationEx().holdsReadLock()) { return action.compute(); } Ref<T> res = Ref.create(); while(true) { if(ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(() -> res.set(action.compute()))) { return res.get(); } ProgressIndicatorUtils.yieldToPendingWriteActions(); } }
public static void enableExternalCompiler() { ApplicationManagerEx.getApplicationEx().doNotSave(false); final JavaAwareProjectJdkTableImpl table = JavaAwareProjectJdkTableImpl.getInstanceEx(); new WriteAction() { @Override protected void run(@NotNull final Result result) { table.addJdk(table.getInternalJdk()); } }.execute(); }
public static void saveProject(Project project) { ApplicationEx application = ApplicationManagerEx.getApplicationEx(); boolean oldValue = application.isDoNotSave(); try { application.doNotSave(false); project.save(); } finally { application.doNotSave(oldValue); } }
public static synchronized IdeaTestApplication getInstance(@Nullable final String configPath) { if (ourInstance == null) { PlatformTestCase.doAutodetectPlatformPrefix(); new IdeaTestApplication(); PluginManagerCore.getPlugins(); ApplicationManagerEx.getApplicationEx().load(configPath); } return (IdeaTestApplication)ourInstance; }
private static <T> Boolean processImmediatelyIfTooFew(@NotNull final List<T> things, final ProgressIndicator progress, boolean runInReadAction, @NotNull final Processor<? super T> thingProcessor) { // commit can be invoked from within write action //if (runInReadAction && ApplicationManager.getApplication().isWriteAccessAllowed()) { // throw new RuntimeException("Must not run invokeConcurrentlyUnderProgress() from under write action because of imminent deadlock"); //} if (things.isEmpty()) return true; if (things.size() <= 1 || JobSchedulerImpl.CORES_COUNT <= CORES_FORK_THRESHOLD) { final AtomicBoolean result = new AtomicBoolean(true); Runnable runnable = new Runnable() { @Override public void run() { ProgressManager.getInstance().executeProcessUnderProgress(new Runnable() { @Override public void run() { //noinspection ForLoopReplaceableByForEach for (int i = 0; i < things.size(); i++) { T thing = things.get(i); if (!thingProcessor.process(thing)) { result.set(false); break; } } } }, progress); } }; if (runInReadAction) { if (!ApplicationManagerEx.getApplicationEx().tryRunReadAction(runnable)) return false; } else { runnable.run(); } return result.get(); } return null; }
@Override public void save() { if (ApplicationManagerEx.getApplicationEx().isDoNotSave()) { // no need to save return; } if (!mySavingInProgress.compareAndSet(false, true)) { return; } try { if (isToSaveProjectName()) { try { String basePath = getStateStore().getProjectBasePath(); File baseDir = basePath == null ? null : new File(basePath); if (baseDir != null && baseDir.exists()) { File ideaDir = new File(baseDir, DIRECTORY_STORE_FOLDER); if (ideaDir.exists() && ideaDir.isDirectory()) { FileUtil.writeToFile(new File(ideaDir, NAME_FILE), getName()); myOldName = null; RecentProjectsManager.getInstance().clearNameCache(); } } } catch (Throwable e) { LOG.error("Unable to store project name", e); } } StoreUtil.save(ServiceKt.getStateStore(this), this); } finally { mySavingInProgress.set(false); ApplicationManager.getApplication().getMessageBus().syncPublisher(ProjectSaved.TOPIC).saved(this); } }
private void setupCloseAction() { setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); addWindowListener( new WindowAdapter() { public void windowClosing(@NotNull final WindowEvent e) { if (isTemporaryDisposed()) return; final Application app = ApplicationManager.getApplication(); app.invokeLater(new DumbAwareRunnable() { public void run() { if (app.isDisposed()) { ApplicationManagerEx.getApplicationEx().exit(); return; } final Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); if (openProjects.length > 1 || (openProjects.length == 1 && SystemInfo.isMacSystemMenu)) { if (myProject != null && myProject.isOpen()) { ProjectUtil.closeAndDispose(myProject); } app.getMessageBus().syncPublisher(AppLifecycleListener.TOPIC).projectFrameClosed(); WelcomeFrame.showIfNoProjectOpened(); } else { ApplicationManagerEx.getApplicationEx().exit(); } } }, ModalityState.NON_MODAL); } } ); }
protected void restart() { final ApplicationEx app = ApplicationManagerEx.getApplicationEx(); // do not stack several modal dialogs (native & swing) app.invokeLater(new Runnable() { @Override public void run() { app.restart(true); } }); }
@NotNull @Override public ListPopup createConfirmation(String title, final String yesText, String noText, final Runnable onYes, final Runnable onNo, int defaultOptionIndex) { final BaseListPopupStep<String> step = new BaseListPopupStep<String>(title, new String[]{yesText, noText}) { @Override public PopupStep onChosen(String selectedValue, final boolean finalChoice) { if (selectedValue.equals(yesText)) { onYes.run(); } else { onNo.run(); } return FINAL_CHOICE; } @Override public void canceled() { onNo.run(); } @Override public boolean isMnemonicsNavigationEnabled() { return true; } }; step.setDefaultOptionIndex(defaultOptionIndex); final ApplicationEx app = ApplicationManagerEx.getApplicationEx(); return app == null || !app.isUnitTestMode() ? new ListPopupImpl(step) : new MockConfirmation(step, yesText); }
public void run() { try { ApplicationManagerEx.getApplicationEx().load(); myLoaded = true; myStarter.main(myArgs); myStarter = null; //GC it } catch (Exception e) { throw new RuntimeException(e); } }
public void startup() { if (myProjectPath == null) { logError("Project to inspect is not defined"); printHelp(); } if (myProfileName == null && myProfilePath == null && myStubProfile == null) { logError("Profile to inspect with is not defined"); printHelp(); } final ApplicationEx application = ApplicationManagerEx.getApplicationEx(); application.runReadAction(new Runnable() { @Override public void run() { try { final ApplicationInfoEx applicationInfo = (ApplicationInfoEx)ApplicationInfo.getInstance(); logMessage(1, InspectionsBundle.message("inspection.application.starting.up", applicationInfo.getFullApplicationName())); application.doNotSave(); logMessageLn(1, InspectionsBundle.message("inspection.done")); InspectionApplication.this.run(); } catch (Exception e) { LOG.error(e); } finally { if (myErrorCodeRequired) application.exit(true, true); } } }); }
@Override protected void applyInformationWithProgress() { final long modificationStampBefore = myDocument.getModificationStamp(); Update update = new Update(myFile) { @Override public void setRejected() { super.setRejected(); doFinish(getHighlights(), modificationStampBefore); } @Override public void run() { if (documentChanged(modificationStampBefore) || myProject.isDisposed()) { return; } doAnnotate(); ApplicationManagerEx.getApplicationEx().tryRunReadAction(new Runnable() { @Override public void run() { if (documentChanged(modificationStampBefore) || myProject.isDisposed()) { return; } applyRelevant(); doFinish(getHighlights(), modificationStampBefore); } }); } }; myExternalToolPassFactory.scheduleExternalActivity(update); }
@Nullable @Override public CodeFoldingState buildInitialFoldings(@NotNull final Document document) { if (myProject.isDisposed()) { return null; } ApplicationManager.getApplication().assertReadAccessAllowed(); PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(myProject); if (psiDocumentManager.isUncommited(document)) { // skip building foldings for uncommitted document, CodeFoldingPass invoked by daemon will do it later return null; } //Do not save/restore folding for code fragments final PsiFile file = psiDocumentManager.getPsiFile(document); if (file == null || !file.isValid() || !file.getViewProvider().isPhysical() && !ApplicationManager.getApplication().isUnitTestMode()) { return null; } final FoldingUpdate.FoldingMap foldingMap = FoldingUpdate.getFoldingsFor(file, document, true); return new CodeFoldingState() { @Override public void setToEditor(@NotNull final Editor editor) { ApplicationManagerEx.getApplicationEx().assertIsDispatchThread(); if (myProject.isDisposed() || editor.isDisposed()) return; final FoldingModelEx foldingModel = (FoldingModelEx)editor.getFoldingModel(); if (!foldingModel.isFoldingEnabled()) return; if (isFoldingsInitializedInEditor(editor)) return; if (DumbService.isDumb(myProject) && !FoldingUpdate.supportsDumbModeFolding(editor)) return; foldingModel.runBatchFoldingOperationDoNotCollapseCaret(new UpdateFoldRegionsOperation(myProject, editor, file, foldingMap, YES, false)); initFolding(editor); } }; }