From 6cec315ce2fb5aa69630161eca821b56814cb552 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 7 Jan 2022 17:57:09 +0100 Subject: [PATCH] Optimization: check for setting before initiating background action and checking if Lombok library exists GitOrigin-RevId: 7338ae8b498eb527b1e305597080f753258136c2 --- .../LombokProjectValidatorActivity.java | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/plugins/lombok/src/main/java/de/plushnikov/intellij/plugin/activity/LombokProjectValidatorActivity.java b/plugins/lombok/src/main/java/de/plushnikov/intellij/plugin/activity/LombokProjectValidatorActivity.java index b11c0b22971a..b844400e77be 100644 --- a/plugins/lombok/src/main/java/de/plushnikov/intellij/plugin/activity/LombokProjectValidatorActivity.java +++ b/plugins/lombok/src/main/java/de/plushnikov/intellij/plugin/activity/LombokProjectValidatorActivity.java @@ -32,31 +32,33 @@ public class LombokProjectValidatorActivity implements StartupActivity.DumbAware final MessageBusConnection connection = project.getMessageBus().connect(); connection.subscribe(BuildManagerListener.TOPIC, new LombokBuildManagerListener()); - ReadAction.nonBlocking(() -> { - if (project.isDisposed()) return null; + if (ProjectSettings.isEnabled(project, ProjectSettings.IS_LOMBOK_VERSION_CHECK_ENABLED, false)) { + ReadAction.nonBlocking(() -> { + if (project.isDisposed()) return null; - final boolean hasLombokLibrary = LombokLibraryUtil.hasLombokLibrary(project); + final boolean hasLombokLibrary = LombokLibraryUtil.hasLombokLibrary(project); - // If dependency is present and out of date notification setting is enabled (defaults to disabled) - if (hasLombokLibrary && ProjectSettings.isEnabled(project, ProjectSettings.IS_LOMBOK_VERSION_CHECK_ENABLED, false)) { - String lombokVersion = LombokLibraryUtil.getLombokVersionCached(project); + // If dependency is present and out of date notification setting is enabled (defaults to disabled) + if (hasLombokLibrary) { + String lombokVersion = LombokLibraryUtil.getLombokVersionCached(project); - if (StringUtil.isNotEmpty(lombokVersion) && Version.isLessThan(lombokVersion, Version.LAST_LOMBOK_VERSION)) { - return getNotificationGroup().createNotification( - LombokBundle.message("config.warn.dependency.outdated.title"), - LombokBundle.message("config.warn.dependency.outdated.message", project.getName(), lombokVersion, Version.LAST_LOMBOK_VERSION), - NotificationType.WARNING); + if (StringUtil.isNotEmpty(lombokVersion) && Version.isLessThan(lombokVersion, Version.LAST_LOMBOK_VERSION)) { + return getNotificationGroup().createNotification( + LombokBundle.message("config.warn.dependency.outdated.title"), + LombokBundle.message("config.warn.dependency.outdated.message", project.getName(), lombokVersion, Version.LAST_LOMBOK_VERSION), + NotificationType.WARNING); + } } - } - return null; - }).expireWith(LombokPluginDisposable.getInstance(project)) - .coalesceBy(project, LombokProjectValidatorActivity.class) - .finishOnUiThread(ModalityState.NON_MODAL, notification -> { - if (notification != null) { - notification.setListener(NotificationListener.URL_OPENING_LISTENER).notify(project); - Disposer.register(LombokPluginDisposable.getInstance(project), notification::expire); - } - }).submit(AppExecutorUtil.getAppExecutorService()); + return null; + }).expireWith(LombokPluginDisposable.getInstance(project)) + .coalesceBy(project, LombokProjectValidatorActivity.class) + .finishOnUiThread(ModalityState.NON_MODAL, notification -> { + if (notification != null) { + notification.setListener(NotificationListener.URL_OPENING_LISTENER).notify(project); + Disposer.register(LombokPluginDisposable.getInstance(project), notification::expire); + } + }).submit(AppExecutorUtil.getAppExecutorService()); + } } @NotNull