diff --git a/platform/core-api/src/com/intellij/openapi/components/ServiceManager.java b/platform/core-api/src/com/intellij/openapi/components/ServiceManager.java index b8daeed13cee..61fdbcbb36c2 100644 --- a/platform/core-api/src/com/intellij/openapi/components/ServiceManager.java +++ b/platform/core-api/src/com/intellij/openapi/components/ServiceManager.java @@ -24,13 +24,19 @@ public final class ServiceManager { return project.getService(serviceClass); } - @Nullable - public static T getServiceIfCreated(@NotNull Project project, @NotNull Class serviceClass) { + /** + * @deprecated Use {@link ComponentManager#getServiceIfCreated(Class)}. + */ + @Deprecated + public static @Nullable T getServiceIfCreated(@NotNull Project project, @NotNull Class serviceClass) { return project.getServiceIfCreated(serviceClass); } - @Nullable - public static T getServiceIfCreated(@NotNull Class serviceClass) { + /** + * @deprecated Use {@link ComponentManager#getServiceIfCreated(Class)}. + */ + @Deprecated + public static @Nullable T getServiceIfCreated(@NotNull Class serviceClass) { return ApplicationManager.getApplication().getServiceIfCreated(serviceClass); } @@ -41,8 +47,7 @@ public final class ServiceManager { * @param Service class type. * @return Key instance. */ - @NotNull - public static NotNullLazyKey createLazyKey(@NotNull final Class serviceClass) { + public static @NotNull NotNullLazyKey createLazyKey(final @NotNull Class serviceClass) { return NotNullLazyKey.create("Service: " + serviceClass.getName(), project -> project.getService(serviceClass)); } } diff --git a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnAction.java b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnAction.java index e1a7a1eb643c..9e97d1afec1e 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnAction.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnAction.java @@ -3,7 +3,7 @@ package com.intellij.openapi.actionSystem; import com.intellij.diagnostic.LoadingState; import com.intellij.openapi.Disposable; -import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.PossiblyDumbAware; import com.intellij.openapi.project.Project; @@ -13,7 +13,6 @@ import com.intellij.ui.ComponentUtil; import com.intellij.util.SmartFMap; import com.intellij.util.SmartList; import org.intellij.lang.annotations.JdkConstants; -import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -326,7 +325,7 @@ public abstract class AnAction implements PossiblyDumbAware { if (myShortcutSet != shortcutSet && myShortcutSet != CustomShortcutSet.EMPTY && LoadingState.PROJECT_OPENED.isOccurred()) { - ActionManager actionManager = ServiceManager.getServiceIfCreated(ActionManager.class); + ActionManager actionManager = ApplicationManager.getApplication().getServiceIfCreated(ActionManager.class); if (actionManager != null && actionManager.getId(this) != null) { LOG.warn("ShortcutSet of global AnActions should not be changed outside of KeymapManager.\n" + "This is likely not what you wanted to do. Consider setting shortcut in keymap defaults, inheriting from other action " + diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java index 2ca88a23846c..afbf4d4b16a5 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java @@ -24,7 +24,6 @@ import com.intellij.openapi.actionSystem.IdeActions; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.command.WriteCommandAction; -import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Document; @@ -527,7 +526,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement @TestOnly public static void cleanupForNextTest() { - CompletionService completionService = ServiceManager.getServiceIfCreated(CompletionService.class); + CompletionService completionService = ApplicationManager.getApplication().getServiceIfCreated(CompletionService.class); if (!(completionService instanceof CompletionServiceImpl)) { return; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupManager.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupManager.java index fb42c16dbfdb..5ca489c4a68f 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupManager.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupManager.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.lookup; @@ -50,7 +50,7 @@ public abstract class LookupManager { public abstract void hideActiveLookup(); public static void hideActiveLookup(@NotNull Project project) { - LookupManager lookupManager = ServiceManager.getServiceIfCreated(project, LookupManager.class); + LookupManager lookupManager = project.getServiceIfCreated(LookupManager.class); if (lookupManager != null) { lookupManager.hideActiveLookup(); } diff --git a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java index b3d51ec59a47..f8d3e6a188d9 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java @@ -1514,7 +1514,7 @@ public final class IdeEventQueue extends EventQueue { return false; } - ActionManager actionManager = ServiceManager.getServiceIfCreated(ActionManager.class); + ActionManager actionManager = ApplicationManager.getApplication().getServiceIfCreated(ActionManager.class); return actionManager instanceof ActionManagerImpl && !((ActionManagerImpl)actionManager).isActionPopupStackEmpty() && !((ActionManagerImpl)actionManager).isToolWindowContextMenuVisible(); diff --git a/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomActionsSchema.java b/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomActionsSchema.java index 920f0f917dcc..22d4b411149d 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomActionsSchema.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomActionsSchema.java @@ -27,24 +27,20 @@ import com.intellij.openapi.wm.impl.ProjectFrameHelper; import com.intellij.util.ImageLoader; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.JBImageIcon; -import java.awt.Image; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; -import javax.swing.Icon; -import javax.swing.tree.DefaultMutableTreeNode; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.swing.*; +import javax.swing.tree.DefaultMutableTreeNode; +import java.awt.*; +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + @State(name = "com.intellij.ide.ui.customization.CustomActionsSchema", storages = @Storage("customization.xml")) public final class CustomActionsSchema implements PersistentStateComponent { private static final Logger LOG = Logger.getInstance(CustomActionsSchema.class); @@ -99,7 +95,7 @@ public final class CustomActionsSchema implements PersistentStateComponent { val metricEvents = mutableSetOf() if (!Registry.`is`("vcs.log.index.git")) { @@ -40,7 +36,7 @@ class VcsLogIndexApplicationStatisticsCollector : ApplicationUsagesCollector() { return metricEvents } - private fun getBigRepositoriesList() = getServiceIfCreated(VcsLogBigRepositoriesList::class.java) + private fun getBigRepositoriesList() = serviceIfCreated() override fun getGroupId(): String = "vcs.log.index.application" @@ -65,9 +61,9 @@ class VcsLogIndexProjectStatisticsCollector : ProjectUsagesCollector() { return usages } - private fun getSharedSettings(project: Project) = getServiceIfCreated(project, VcsLogSharedSettings::class.java) + private fun getSharedSettings(project: Project) = project.serviceIfCreated() - private fun getIndexCollector(project: Project) = getServiceIfCreated(project, VcsLogIndexCollector::class.java) + private fun getIndexCollector(project: Project) = project.serviceIfCreated() override fun getGroupId(): String = "vcs.log.index.project"