mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
don't use registerComponentInstance to register service (test-only)
This commit is contained in:
+6
-13
@@ -212,19 +212,12 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements
|
||||
public synchronized <T> T registerComponentInstance(@NotNull Class<T> 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
|
||||
|
||||
@@ -26,4 +26,4 @@ public inline fun <reified T: Any> Project.service(): T? = ServiceManager.getSer
|
||||
public val ComponentManager.stateStore: IComponentStore
|
||||
get() = getPicoContainer().getComponentInstance(javaClass<IComponentStore>()) as IComponentStore
|
||||
|
||||
public fun <T> ComponentManager.getComponents(baseClass: Class<T>): List<T> = (this as ComponentManagerEx).getComponentInstancesOfType(baseClass)
|
||||
public fun <T> ComponentManager.getComponents(baseClass: Class<T>): List<T> = (this as ComponentManagerEx).getComponentInstancesOfType(baseClass)
|
||||
@@ -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 <T> ComponentManager.registerServiceInstance(interfaceClass: Class<T>, instance: T) {
|
||||
val picoContainer = getPicoContainer() as MutablePicoContainer
|
||||
val key = interfaceClass.getName()
|
||||
picoContainer.unregisterComponent(key)
|
||||
picoContainer.registerComponentInstance(key, instance)
|
||||
}
|
||||
Reference in New Issue
Block a user