diff --git a/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java index c83c3ccdfaab..d16019714a17 100644 --- a/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java @@ -212,19 +212,12 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements public synchronized T registerComponentInstance(@NotNull Class componentKey, @NotNull T componentImplementation) { MutablePicoContainer picoContainer = getPicoContainer(); ComponentAdapter adapter = picoContainer.getComponentAdapter(componentKey); - if (adapter instanceof ComponentConfigComponentAdapter) { - ComponentConfigComponentAdapter componentAdapter = (ComponentConfigComponentAdapter)adapter; - Object oldInstance = componentAdapter.myInitializedComponentInstance; - // we don't update pluginId - method is test only - componentAdapter.myInitializedComponentInstance = componentImplementation; - return (T)oldInstance; - } - else { - // todo it seems, it is unrealistic (illegal) case - component must have our adapter - picoContainer.unregisterComponent(componentKey); - picoContainer.registerComponentInstance(componentKey, componentImplementation); - return null; - } + LOG.assertTrue(adapter instanceof ComponentConfigComponentAdapter); + ComponentConfigComponentAdapter componentAdapter = (ComponentConfigComponentAdapter)adapter; + Object oldInstance = componentAdapter.myInitializedComponentInstance; + // we don't update pluginId - method is test only + componentAdapter.myInitializedComponentInstance = componentImplementation; + return (T)oldInstance; } @Override diff --git a/platform/platform-impl/src/com/intellij/openapi/components/service.kt b/platform/platform-impl/src/com/intellij/openapi/components/service.kt index 247b0cf2d085..f8757e54d1f8 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/service.kt +++ b/platform/platform-impl/src/com/intellij/openapi/components/service.kt @@ -26,4 +26,4 @@ public inline fun Project.service(): T? = ServiceManager.getSer public val ComponentManager.stateStore: IComponentStore get() = getPicoContainer().getComponentInstance(javaClass()) as IComponentStore -public fun ComponentManager.getComponents(baseClass: Class): List = (this as ComponentManagerEx).getComponentInstancesOfType(baseClass) +public fun ComponentManager.getComponents(baseClass: Class): List = (this as ComponentManagerEx).getComponentInstancesOfType(baseClass) \ No newline at end of file diff --git a/platform/testFramework/testSrc/com/intellij/testFramework/util.kt b/platform/testFramework/testSrc/com/intellij/testFramework/util.kt new file mode 100644 index 000000000000..a68c9d3b73ef --- /dev/null +++ b/platform/testFramework/testSrc/com/intellij/testFramework/util.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2015 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. + */ +package com.intellij.testFramework + +import com.intellij.openapi.components.ComponentManager +import org.picocontainer.MutablePicoContainer + +public fun ComponentManager.registerServiceInstance(interfaceClass: Class, instance: T) { + val picoContainer = getPicoContainer() as MutablePicoContainer + val key = interfaceClass.getName() + picoContainer.unregisterComponent(key) + picoContainer.registerComponentInstance(key, instance) +} \ No newline at end of file