From 1df19fa8da07a8c3b4a76d9894e21cadaf5201f6 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 23 Dec 2016 11:29:10 +0100 Subject: [PATCH] =?UTF-8?q?cleanup=20=E2=80=94=20AppLifecycleListener=20?= =?UTF-8?q?=E2=80=94=20default=20method=20implementation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../daemon/impl/DaemonListeners.java | 2 +- .../intellij/ide/AppLifecycleListener.java | 46 +++++++++---------- .../ide/RecentProjectsManagerBase.java | 2 +- .../com/intellij/ide/SystemHealthMonitor.java | 2 +- ...icationStatisticsPersistenceComponent.java | 2 +- .../application/impl/ApplicationImpl.java | 17 +++---- .../impl/UpdateCheckerComponent.java | 2 +- .../openapi/wm/impl/WindowManagerImpl.java | 2 +- .../platform/PlatformProjectStarter.java | 2 +- .../src/com/intellij/ui/LibNotifyWrapper.java | 2 +- .../ui/MountainLionNotifications.java | 2 +- .../vcs/impl/ProjectLevelVcsManagerImpl.java | 3 +- .../edu/learning/stepic/EduStepicUpdater.java | 2 +- .../edu/PyCharmEduInitialConfigurator.java | 2 +- .../python/PyCharmInitialConfigurator.java | 2 +- 15 files changed, 45 insertions(+), 45 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java index 018e1b4b54db..fb6e89a3263e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java @@ -162,7 +162,7 @@ public class DaemonListeners implements Disposable { if (project.isDefault()) return; MessageBusConnection connection = messageBus.connect(this); - connection.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() { + connection.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() { @Override public void appClosing() { stopDaemon(false, "App closing"); diff --git a/platform/platform-impl/src/com/intellij/ide/AppLifecycleListener.java b/platform/platform-impl/src/com/intellij/ide/AppLifecycleListener.java index 0dbb49745959..e0f7e18d015b 100644 --- a/platform/platform-impl/src/com/intellij/ide/AppLifecycleListener.java +++ b/platform/platform-impl/src/com/intellij/ide/AppLifecycleListener.java @@ -29,49 +29,49 @@ import org.jetbrains.annotations.Nullable; public interface AppLifecycleListener { Topic TOPIC = Topic.create("Application lifecycle notifications", AppLifecycleListener.class); - void appFrameCreated(final String[] commandLineArgs, @NotNull Ref willOpenProject); + default void appFrameCreated(final String[] commandLineArgs, @NotNull Ref willOpenProject) { + } - void appStarting(@Nullable Project projectFromCommandLine); + default void appStarting(@Nullable Project projectFromCommandLine) { + } /** * Called when a project frame is closed. */ - void projectFrameClosed(); + default void projectFrameClosed() { + } /** * Called if the project opening was cancelled or failed because of an error. */ - void projectOpenFailed(); + default void projectOpenFailed() { + } /** * Called when the welcome screen is displayed. */ - void welcomeScreenDisplayed(); + default void welcomeScreenDisplayed() { + } /** * Fired before saving settings and before final 'can exit?' check. App may end up not closing if some of the * {@link com.intellij.openapi.application.ApplicationListener} listeners return false from their {@code canExitApplication} * method. */ - void appClosing(); + default void appClosing() { + } + + /** + * Fired after saving settings and after final 'can exit?' check. + */ + default void appWillBeClosed() { + } + + /** + * @deprecated Please use {@link AppLifecycleListener} directly. + */ + @Deprecated abstract class Adapter implements AppLifecycleListener { - @Override - public void appFrameCreated(String[] commandLineArgs, @NotNull Ref willOpenProject) { } - - @Override - public void appStarting(Project projectFromCommandLine) { } - - @Override - public void projectFrameClosed() { } - - @Override - public void projectOpenFailed() { } - - @Override - public void welcomeScreenDisplayed() { } - - @Override - public void appClosing() { } } } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java b/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java index b1a17e53c5b9..5229187bd4d0 100644 --- a/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java +++ b/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java @@ -635,7 +635,7 @@ public abstract class RecentProjectsManagerBase extends RecentProjectsManager im myState.groups.remove(group); } - private class MyAppLifecycleListener extends AppLifecycleListener.Adapter { + private class MyAppLifecycleListener implements AppLifecycleListener { @Override public void appFrameCreated(final String[] commandLineArgs, @NotNull final Ref willOpenProject) { if (willReopenProjectOnStart()) { diff --git a/platform/platform-impl/src/com/intellij/ide/SystemHealthMonitor.java b/platform/platform-impl/src/com/intellij/ide/SystemHealthMonitor.java index d80290d4a19b..e0a70bb9cddb 100644 --- a/platform/platform-impl/src/com/intellij/ide/SystemHealthMonitor.java +++ b/platform/platform-impl/src/com/intellij/ide/SystemHealthMonitor.java @@ -107,7 +107,7 @@ public class SystemHealthMonitor extends ApplicationComponent.Adapter { final String message = IdeBundle.message(key) + IdeBundle.message("sys.health.acknowledge.link"); final Application app = ApplicationManager.getApplication(); - app.getMessageBus().connect(app).subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() { + app.getMessageBus().connect(app).subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() { @Override public void appFrameCreated(String[] commandLineArgs, @NotNull Ref willOpenProject) { app.invokeLater(() -> { diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java index ed9988296f59..d5f789a646a1 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java @@ -165,7 +165,7 @@ public class ApplicationStatisticsPersistenceComponent extends ApplicationStatis @Override public void initComponent() { - ApplicationManager.getApplication().getMessageBus().connect().subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() { + ApplicationManager.getApplication().getMessageBus().connect().subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() { @Override public void appClosing() { persistOpenedProjects(); diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java index bdc6a3b01f09..696a3070d031 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java @@ -46,8 +46,8 @@ import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.progress.*; import com.intellij.openapi.progress.impl.CoreProgressManager; -import com.intellij.openapi.progress.util.ProgressWindow; import com.intellij.openapi.progress.util.PotemkinProgress; +import com.intellij.openapi.progress.util.ProgressWindow; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.project.ex.ProjectManagerEx; @@ -790,7 +790,8 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App return; } - getMessageBus().syncPublisher(AppLifecycleListener.TOPIC).appClosing(); + AppLifecycleListener lifecycleListener = getMessageBus().syncPublisher(AppLifecycleListener.TOPIC); + lifecycleListener.appClosing(); myDisposeInProgress = true; @@ -799,15 +800,15 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App } saveSettings(); - + lifecycleListener.appWillBeClosed(); boolean success = disposeSelf(!force); - if (!success || isUnitTestMode() || Boolean.getBoolean("idea.test.guimode")) { - if (Boolean.getBoolean("idea.test.guimode")) { - IdeaApplication.getInstance().shutdown(); + if (!success || isUnitTestMode() || Boolean.getBoolean("idea.test.guimode")) { + if (Boolean.getBoolean("idea.test.guimode")) { + IdeaApplication.getInstance().shutdown(); + } + return; } - return; - } int exitCode = 0; if (restart && Restarter.isSupported()) { diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateCheckerComponent.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateCheckerComponent.java index 97838e1434f4..bfdf27b02545 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateCheckerComponent.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateCheckerComponent.java @@ -103,7 +103,7 @@ public class UpdateCheckerComponent implements ApplicationComponent { return; } - app.getMessageBus().connect(app).subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() { + app.getMessageBus().connect(app).subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() { @Override public void appFrameCreated(String[] commandLineArgs, @NotNull Ref willOpenProject) { BuildNumber currentBuild = ApplicationInfo.getInstance().getBuild(); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/WindowManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/WindowManagerImpl.java index f2dd265ac18f..e0864abfaf30 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/WindowManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/WindowManagerImpl.java @@ -155,7 +155,7 @@ public final class WindowManagerImpl extends WindowManagerEx implements NamedCom } }; - bus.connect().subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() { + bus.connect().subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() { @Override public void appClosing() { // save full screen window states diff --git a/platform/platform-impl/src/com/intellij/platform/PlatformProjectStarter.java b/platform/platform-impl/src/com/intellij/platform/PlatformProjectStarter.java index 35d6e4c04087..c892a2a59d75 100644 --- a/platform/platform-impl/src/com/intellij/platform/PlatformProjectStarter.java +++ b/platform/platform-impl/src/com/intellij/platform/PlatformProjectStarter.java @@ -29,7 +29,7 @@ import org.jetbrains.annotations.NotNull; public class PlatformProjectStarter implements ApplicationComponent { public PlatformProjectStarter(MessageBus bus) { - bus.connect().subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() { + bus.connect().subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() { public void appFrameCreated(final String[] commandLineArgs, @NotNull final Ref willOpenProject) { for (String arg : commandLineArgs) { if (!arg.equals(StartupUtil.NO_SPLASH)) { diff --git a/platform/platform-impl/src/com/intellij/ui/LibNotifyWrapper.java b/platform/platform-impl/src/com/intellij/ui/LibNotifyWrapper.java index beb9fe47fbc7..c45f2b1d37af 100644 --- a/platform/platform-impl/src/com/intellij/ui/LibNotifyWrapper.java +++ b/platform/platform-impl/src/com/intellij/ui/LibNotifyWrapper.java @@ -63,7 +63,7 @@ class LibNotifyWrapper implements SystemNotificationsImpl.Notifier { myIcon = icon != null ? icon : "dialog-information"; MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(); - connection.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() { + connection.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() { @Override public void appClosing() { synchronized (myLock) { diff --git a/platform/platform-impl/src/com/intellij/ui/MountainLionNotifications.java b/platform/platform-impl/src/com/intellij/ui/MountainLionNotifications.java index 6b9c3fcc9683..aac282088d0d 100644 --- a/platform/platform-impl/src/com/intellij/ui/MountainLionNotifications.java +++ b/platform/platform-impl/src/com/intellij/ui/MountainLionNotifications.java @@ -49,7 +49,7 @@ class MountainLionNotifications implements SystemNotificationsImpl.Notifier { cleanupDeliveredNotifications(); } }); - connection.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() { + connection.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() { @Override public void appClosing() { cleanupDeliveredNotifications(); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java index 9f61d9b3d7bd..660436c6627c 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java @@ -71,7 +71,6 @@ import com.intellij.util.text.DateFormatUtil; import org.jdom.Attribute; import org.jdom.DataConversionException; import org.jdom.Element; -import org.jetbrains.annotations.CalledInAwt; import org.jetbrains.annotations.*; import javax.swing.*; @@ -151,7 +150,7 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme if (project.isDefault()) { // default project is disposed in write action, so treat it differently MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(); - connection.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() { + connection.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() { @Override public void appClosing() { Disposer.dispose(myInitialization); diff --git a/python/educational-core/student/src/com/jetbrains/edu/learning/stepic/EduStepicUpdater.java b/python/educational-core/student/src/com/jetbrains/edu/learning/stepic/EduStepicUpdater.java index 2fe6b05c28e3..6810a5bad357 100644 --- a/python/educational-core/student/src/com/jetbrains/edu/learning/stepic/EduStepicUpdater.java +++ b/python/educational-core/student/src/com/jetbrains/edu/learning/stepic/EduStepicUpdater.java @@ -29,7 +29,7 @@ public class EduStepicUpdater { if (!checkNeeded()) { return; } - application.getMessageBus().connect(application).subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() { + application.getMessageBus().connect(application).subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() { @Override public void appFrameCreated(String[] commandLineArgs, @NotNull Ref willOpenProject) { diff --git a/python/educational-python/src/com/jetbrains/python/edu/PyCharmEduInitialConfigurator.java b/python/educational-python/src/com/jetbrains/python/edu/PyCharmEduInitialConfigurator.java index b81d4d549890..9e055bc13afc 100644 --- a/python/educational-python/src/com/jetbrains/python/edu/PyCharmEduInitialConfigurator.java +++ b/python/educational-python/src/com/jetbrains/python/edu/PyCharmEduInitialConfigurator.java @@ -187,7 +187,7 @@ public class PyCharmEduInitialConfigurator { if (!propertiesComponent.isValueSet(DISPLAYED_PROPERTY)) { - bus.connect().subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() { + bus.connect().subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() { @Override public void welcomeScreenDisplayed() { diff --git a/python/ide/src/com/jetbrains/python/PyCharmInitialConfigurator.java b/python/ide/src/com/jetbrains/python/PyCharmInitialConfigurator.java index 9a095d6b2121..63e546511215 100644 --- a/python/ide/src/com/jetbrains/python/PyCharmInitialConfigurator.java +++ b/python/ide/src/com/jetbrains/python/PyCharmInitialConfigurator.java @@ -72,7 +72,7 @@ public class PyCharmInitialConfigurator { } if (!propertiesComponent.isValueSet(DISPLAYED_PROPERTY)) { - bus.connect().subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() { + bus.connect().subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() { @Override public void welcomeScreenDisplayed() { ApplicationManager.getApplication().invokeLater(() -> {