get rid of ModuleServiceManager

GitOrigin-RevId: 91f39625139a964430a3d14829216d3c5f49a220
This commit is contained in:
Vladimir Krivosheev
2020-03-15 09:01:41 +01:00
committed by intellij-monorepo-bot
parent a0e55eb2a0
commit 324e3b3d2c
20 changed files with 36 additions and 124 deletions

View File

@@ -1,25 +1,10 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// 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.openapi.roots;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleServiceManager;
public abstract class ModulePackageIndex extends PackageIndex {
public static ModulePackageIndex getInstance(Module module) {
return ModuleServiceManager.getService(module, ModulePackageIndex.class);
return module.getService(ModulePackageIndex.class);
}
}

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 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.configurationStore
import com.intellij.ide.highlighter.ProjectFileType
@@ -8,7 +8,6 @@ import com.intellij.openapi.components.impl.stores.IProjectStore
import com.intellij.openapi.diagnostic.runAndLogException
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.module.ModuleServiceManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ex.ProjectEx
import com.intellij.openapi.project.ex.ProjectNameProvider
@@ -166,7 +165,7 @@ open class ProjectWithModulesStoreImpl(project: Project) : ProjectStoreImpl(proj
val saveSessions: MutableList<SaveSession> = SmartList()
// commit components
for (module in modules) {
val moduleStore = ModuleServiceManager.getService(module, IComponentStore::class.java) as? ComponentStoreImpl ?: continue
val moduleStore = module.getService(IComponentStore::class.java) as? ComponentStoreImpl ?: continue
// collectSaveSessions is very cheap, so, do it in EDT
val saveManager = moduleStore.createSaveSessionProducerManager()
commitModuleComponents(moduleStore, saveManager, projectSaveSessionManager, isForceSavingAllSettings, errors)

View File

@@ -1,50 +1,19 @@
// 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.openapi.module;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Provide a module service if you need to can be used to store data associated with a module. Its implementation should be registered in plugin.xml:
* <pre>
* &lt;extensions defaultExtensionNs="com.intellij"&gt;
* &lt;moduleService serviceInterface="qualified-interface-class-name"
serviceImplementation="qualified-implementation-class-name"/&gt;
* &lt;/extensions&gt;
* </pre>
* Class is loaded and its instance is created lazily when {@link #getService(Module, Class)} method is called for the first time.
* <p/>
* If the service implementation class implements {@link com.intellij.openapi.components.PersistentStateComponent} interface its state will
* be persisted in the module configuration file.
* @deprecated Do not use module services.
*
* @author yole
* See https://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_services.html
*/
public final class ModuleServiceManager {
private static final Logger LOG = Logger.getInstance(ModuleServiceManager.class);
private ModuleServiceManager() {
}
@Nullable
public static <T> T getService(@NotNull Module module, @NotNull Class<T> serviceClass) {
//noinspection unchecked
T instance = (T)module.getPicoContainer().getComponentInstance(serviceClass.getName());
if (instance == null) {
instance = module.getComponent(serviceClass);
if (instance != null) {
Application app = ApplicationManager.getApplication();
String message = serviceClass.getName() + " requested as a service, but it is a component - convert it to a service or change call to module.getComponent()";
if (app.isUnitTestMode()) {
LOG.error(message);
}
else {
LOG.warn(message);
}
}
}
return instance;
public static @Nullable <T> T getService(@NotNull Module module, @NotNull Class<T> serviceClass) {
return module.getService(serviceClass);
}
}

View File

@@ -11,7 +11,6 @@ import com.intellij.openapi.components.State;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.ModuleServiceManager;
import com.intellij.openapi.project.ModuleListener;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
@@ -62,7 +61,7 @@ public final class ModuleRunConfigurationManager implements PersistentStateCompo
if (!project.isDefault()) {
for (Module module : ModuleManager.getInstance(project).getModules()) {
if (!module.isDisposed()) {
ModuleServiceManager.getService(module, ModuleRunConfigurationManager.class);
module.getService(ModuleRunConfigurationManager.class);
}
}
}

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2017 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.openapi.externalSystem
import com.intellij.openapi.components.PersistentStateComponent
@@ -7,7 +7,6 @@ import com.intellij.openapi.externalSystem.model.ProjectSystemId
import com.intellij.openapi.externalSystem.model.project.ModuleData
import com.intellij.openapi.externalSystem.model.project.ProjectData
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleServiceManager
import com.intellij.openapi.project.isExternalStorageEnabled
import com.intellij.openapi.roots.ExternalProjectSystemRegistry
import com.intellij.openapi.roots.ProjectModelElement
@@ -34,7 +33,7 @@ class ExternalSystemModulePropertyManager(private val module: Module) : Persiste
companion object {
@JvmStatic
fun getInstance(module: Module): ExternalSystemModulePropertyManager = ModuleServiceManager.getService(module, ExternalSystemModulePropertyManager::class.java)!!
fun getInstance(module: Module): ExternalSystemModulePropertyManager = module.getService(ExternalSystemModulePropertyManager::class.java)!!
}
@Suppress("DEPRECATION")

View File

@@ -1,24 +1,9 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// 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.facet;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleServiceManager;
import com.intellij.openapi.util.ModificationTracker;
import com.intellij.openapi.util.ModificationTrackerListener;
import org.jetbrains.annotations.ApiStatus;
@@ -28,11 +13,11 @@ import org.jetbrains.annotations.NotNull;
public abstract class FacetModificationTrackingService {
public static FacetModificationTrackingService getInstance(@NotNull Module module) {
return ModuleServiceManager.getService(module, FacetModificationTrackingService.class);
return module.getService(FacetModificationTrackingService.class);
}
public static FacetModificationTrackingService getInstance(@NotNull Facet<?> facet) {
return ModuleServiceManager.getService(facet.getModule(), FacetModificationTrackingService.class);
return facet.getModule().getService(FacetModificationTrackingService.class);
}
@NotNull

View File

@@ -16,7 +16,6 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleComponent;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.ModuleServiceManager;
import com.intellij.openapi.module.impl.scopes.ModuleScopeProviderImpl;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
@@ -264,7 +263,7 @@ public class ModuleImpl extends ComponentManagerImpl implements ModuleEx {
@NotNull
private DeprecatedModuleOptionManager getOptionManager() {
//noinspection ConstantConditions
return ModuleServiceManager.getService(this, DeprecatedModuleOptionManager.class);
return ((Module)this).getService(DeprecatedModuleOptionManager.class);
}
@Override

View File

@@ -1,22 +1,7 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// 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.openapi.roots;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleServiceManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -31,7 +16,7 @@ import org.jetbrains.annotations.Nullable;
*/
public abstract class TestModuleProperties {
public static TestModuleProperties getInstance(@NotNull Module module) {
return ModuleServiceManager.getService(module, TestModuleProperties.class);
return module.getService(TestModuleProperties.class);
}
@Nullable

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 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.openapi.roots.impl;
import com.intellij.openapi.Disposable;
@@ -9,7 +9,6 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.ModifiableModuleModel;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.ModuleServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.*;
@@ -64,7 +63,7 @@ public class ModuleRootManagerImpl extends ModuleRootManagerEx implements Dispos
@Override
@NotNull
public ModuleFileIndex getFileIndex() {
return ModuleServiceManager.getService(myModule, ModuleFileIndex.class);
return myModule.getService(ModuleFileIndex.class);
}
@Override

View File

@@ -1,8 +1,8 @@
// 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.workspace.legacyBridge.intellij
import com.intellij.openapi.components.service
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleServiceManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.pointers.VirtualFilePointer
import com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer
@@ -25,7 +25,7 @@ interface LegacyBridgeFilePointerProvider {
@JvmStatic
fun getInstance(module: Module): LegacyBridgeFilePointerProvider =
ModuleServiceManager.getService(module, LegacyBridgeFilePointerProvider::class.java)!!
module.getService(LegacyBridgeFilePointerProvider::class.java)!!
}
}

View File

@@ -1,8 +1,8 @@
// 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.workspace.legacyBridge.intellij
import com.intellij.openapi.Disposable
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleServiceManager
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.roots.*
import com.intellij.openapi.roots.impl.ModuleLibraryTable
@@ -102,7 +102,7 @@ class LegacyBridgeModuleRootComponent(
override fun getExternalSource(): ProjectModelExternalSource? =
ExternalProjectSystemRegistry.getInstance().getExternalSource(module)
override fun getFileIndex(): ModuleFileIndex = ModuleServiceManager.getService(currentModule, ModuleFileIndex::class.java)!!
override fun getFileIndex(): ModuleFileIndex = currentModule.getService(ModuleFileIndex::class.java)!!
override fun getModifiableModel(): ModifiableRootModel = getModifiableModel(RootConfigurationAccessor())
override fun getModifiableModel(accessor: RootConfigurationAccessor): ModifiableRootModel = LegacyBridgeModifiableRootModel(

View File

@@ -10,6 +10,6 @@ public class ${NAME} {
}
public static ${NAME} getInstance(@NotNull Module module) {
return ModuleServiceManager.getService(module, ${NAME}.class);
return module.getService(${NAME}.class);
}
}

View File

@@ -7,6 +7,6 @@ import org.jetbrains.annotations.NotNull;
#parse("File Header.java")
public interface ${NAME} {
static ${NAME} getInstance(@NotNull Module module) {
return ModuleServiceManager.getService(module, ${NAME}.class);
return module.getService(${NAME}.class);
}
}

View File

@@ -6,7 +6,6 @@ import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleServiceManager;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Disposer;
@@ -52,7 +51,7 @@ public class PluginBuildConfiguration implements PersistentStateComponent<Plugin
@Nullable
public static PluginBuildConfiguration getInstance(@NotNull Module module) {
return ModuleType.is(module, PluginModuleType.getInstance()) ? ModuleServiceManager.getService(module, PluginBuildConfiguration.class) : null;
return ModuleType.is(module, PluginModuleType.getInstance()) ? module.getService(PluginBuildConfiguration.class) : null;
}
static class State {

View File

@@ -1,10 +1,9 @@
// Copyright 2000-2019 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 org.jetbrains.idea.eclipse.config;
import com.intellij.openapi.components.*;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleServiceManager;
import com.intellij.openapi.roots.impl.storage.ClassPathStorageUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ArrayUtilRt;
@@ -52,7 +51,7 @@ public class EclipseModuleManagerImpl implements EclipseModuleManager, Persisten
}
public static EclipseModuleManagerImpl getInstance(Module module) {
return ModuleServiceManager.getService(module, EclipseModuleManagerImpl.class);
return module.getService(EclipseModuleManagerImpl.class);
}
public static boolean isEclipseStorage(@NotNull Module module) {

View File

@@ -1,10 +1,9 @@
// 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 org.jetbrains.idea.maven.importing;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleServiceManager;
import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -21,7 +20,7 @@ public class MavenAnnotationProcessorsModuleService implements PersistentStateCo
private final MavenAnnotationProcessorsModel myState = new MavenAnnotationProcessorsModel();
public static MavenAnnotationProcessorsModuleService getInstance(Module module) {
return ModuleServiceManager.getService(module, MavenAnnotationProcessorsModuleService.class);
return module.getService(MavenAnnotationProcessorsModuleService.class);
}
public List<String> getAnnotationProcessorModules() {

View File

@@ -1,10 +1,9 @@
// Copyright 2000-2019 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 org.jetbrains.idea.maven.importing;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleServiceManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -13,7 +12,7 @@ public class MavenPomPathModuleService implements PersistentStateComponent<Maven
private MavenPomPathState myState = new MavenPomPathState();
public static MavenPomPathModuleService getInstance(final Module module) {
return ModuleServiceManager.getService(module, MavenPomPathModuleService.class);
return module.getService(MavenPomPathModuleService.class);
}
public String getPomFileUrl() {

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 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.uiDesigner;
@@ -7,7 +7,6 @@ import com.intellij.lang.properties.IProperty;
import com.intellij.lang.properties.PropertiesUtilBase;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleServiceManager;
import com.intellij.openapi.roots.ModuleRootEvent;
import com.intellij.openapi.roots.ModuleRootListener;
import com.intellij.openapi.util.Pair;
@@ -41,7 +40,7 @@ public class StringDescriptorManager {
}
public static StringDescriptorManager getInstance(Module module) {
StringDescriptorManager service = ModuleServiceManager.getService(module, StringDescriptorManager.class);
StringDescriptorManager service = module.getService(StringDescriptorManager.class);
if (service != null) {
service.myModule = module;
}

View File

@@ -3,7 +3,6 @@ package com.jetbrains.python.defaultProjectAwareService;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleServiceManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -39,7 +38,7 @@ public final class PyDefaultProjectAwareServiceClasses<
}
public MODULE_SERVICE getModuleService(@NotNull Module module) {
return ModuleServiceManager.getService(module, myModuleServiceClass);
return module.getService(myModuleServiceClass);
}
void copyFromAppToModule(@NotNull Module module) {

View File

@@ -4,7 +4,6 @@ package com.jetbrains.python.psi.resolve;
import com.intellij.ProjectTopics;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleServiceManager;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ModuleRootEvent;
import com.intellij.openapi.roots.ModuleRootListener;
@@ -19,7 +18,7 @@ import org.jetbrains.annotations.NotNull;
*/
public class PythonModulePathCache extends PythonPathCache implements Disposable {
public static PythonPathCache getInstance(Module module) {
return ModuleServiceManager.getService(module, PythonPathCache.class);
return module.getService(PythonPathCache.class);
}
@SuppressWarnings({"UnusedDeclaration"})