Search in sources :

Example 1 with PicoContainer

use of org.picocontainer.PicoContainer in project intellij-community by JetBrains.

the class ServiceManager method doGetService.

@Nullable
private static <T> T doGetService(ComponentManager componentManager, @NotNull Class<T> serviceClass) {
    PicoContainer picoContainer = componentManager.getPicoContainer();
    @SuppressWarnings("unchecked") T instance = (T) picoContainer.getComponentInstance(serviceClass.getName());
    if (instance == null) {
        instance = componentManager.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 " + (componentManager == app ? "ApplicationManager.getApplication().getComponent()" : "project.getComponent()");
            if (app.isUnitTestMode()) {
                LOG.error(message);
            } else {
                LOG.warn(message);
            }
        }
    }
    return instance;
}
Also used : PicoContainer(org.picocontainer.PicoContainer) Application(com.intellij.openapi.application.Application) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with PicoContainer

use of org.picocontainer.PicoContainer in project intellij-community by JetBrains.

the class ThreadLocalAnnotatorMap method cloneTemplates.

@SuppressWarnings("unchecked")
@NotNull
private List<V> cloneTemplates(@NotNull Collection<V> templates) {
    List<V> result = new ArrayList<>(templates.size());
    PicoContainer container = ApplicationManager.getApplication().getPicoContainer();
    for (V template : templates) {
        Class<? extends V> aClass = (Class<? extends V>) template.getClass();
        V clone = (V) new CachingConstructorInjectionComponentAdapter(aClass.getName(), aClass).getComponentInstance(container);
        result.add(clone);
    }
    return result;
}
Also used : PicoContainer(org.picocontainer.PicoContainer) ArrayList(java.util.ArrayList) CachingConstructorInjectionComponentAdapter(com.intellij.util.pico.CachingConstructorInjectionComponentAdapter) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PicoContainer (org.picocontainer.PicoContainer)2 Application (com.intellij.openapi.application.Application)1 CachingConstructorInjectionComponentAdapter (com.intellij.util.pico.CachingConstructorInjectionComponentAdapter)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1