Search in sources :

Example 1 with KeyedLazyInstance

use of com.intellij.util.KeyedLazyInstance in project intellij-community by JetBrains.

the class KeyedExtensionCollector method getPoint.

@Nullable
private ExtensionPoint<KeyedLazyInstance<T>> getPoint() {
    ExtensionPoint<KeyedLazyInstance<T>> point = myPoint;
    if (point == null && Extensions.getRootArea().hasExtensionPoint(myEpName)) {
        ExtensionPointName<KeyedLazyInstance<T>> typesafe = ExtensionPointName.create(myEpName);
        myPoint = point = Extensions.getRootArea().getExtensionPoint(typesafe);
        myListener = new ExtensionPointAndAreaListener<KeyedLazyInstance<T>>() {

            @Override
            public void extensionAdded(@NotNull final KeyedLazyInstance<T> bean, @Nullable final PluginDescriptor pluginDescriptor) {
                synchronized (lock) {
                    if (bean.getKey() == null) {
                        if (pluginDescriptor != null) {
                            throw new PluginException("No key specified for extension of class " + bean.getInstance().getClass(), pluginDescriptor.getPluginId());
                        }
                        LOG.error("No key specified for extension of class " + bean.getInstance().getClass());
                        return;
                    }
                    myCache.remove(bean.getKey());
                    for (ExtensionPointListener<T> listener : myListeners) {
                        listener.extensionAdded(bean.getInstance(), null);
                    }
                }
            }

            @Override
            public void extensionRemoved(@NotNull final KeyedLazyInstance<T> bean, @Nullable final PluginDescriptor pluginDescriptor) {
                synchronized (lock) {
                    myCache.remove(bean.getKey());
                    for (ExtensionPointListener<T> listener : myListeners) {
                        listener.extensionRemoved(bean.getInstance(), null);
                    }
                }
            }

            @Override
            public void areaReplaced(final ExtensionsArea area) {
                resetAreaListener();
            }
        };
        point.addExtensionPointListener(myListener);
    }
    return point;
}
Also used : KeyedLazyInstance(com.intellij.util.KeyedLazyInstance) PluginException(com.intellij.diagnostic.PluginException) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PluginException (com.intellij.diagnostic.PluginException)1 KeyedLazyInstance (com.intellij.util.KeyedLazyInstance)1 Nullable (org.jetbrains.annotations.Nullable)1