Search in sources :

Example 1 with CachingConstructorInjectionComponentAdapter

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

the class ActionManagerImpl method processGroupElement.

private AnAction processGroupElement(Element element, final ClassLoader loader, PluginId pluginId) {
    final IdeaPluginDescriptor plugin = PluginManager.getPlugin(pluginId);
    ResourceBundle bundle = getActionsResourceBundle(loader, plugin);
    if (!GROUP_ELEMENT_NAME.equals(element.getName())) {
        reportActionError(pluginId, "unexpected name of element \"" + element.getName() + "\"");
        return null;
    }
    String className = element.getAttributeValue(CLASS_ATTR_NAME);
    if (className == null) {
        // use default group if class isn't specified
        if ("true".equals(element.getAttributeValue(COMPACT_ATTR_NAME))) {
            className = DefaultCompactActionGroup.class.getName();
        } else {
            className = DefaultActionGroup.class.getName();
        }
    }
    try {
        ActionGroup group;
        if (DefaultActionGroup.class.getName().equals(className)) {
            group = new DefaultActionGroup();
        } else if (DefaultCompactActionGroup.class.getName().equals(className)) {
            group = new DefaultCompactActionGroup();
        } else {
            Class aClass = Class.forName(className, true, loader);
            Object obj = new CachingConstructorInjectionComponentAdapter(className, aClass).getComponentInstance(ApplicationManager.getApplication().getPicoContainer());
            if (!(obj instanceof ActionGroup)) {
                reportActionError(pluginId, "class with name \"" + className + "\" should be instance of " + ActionGroup.class.getName());
                return null;
            }
            if (element.getChildren().size() != element.getChildren(ADD_TO_GROUP_ELEMENT_NAME).size()) {
                //
                if (!(obj instanceof DefaultActionGroup)) {
                    reportActionError(pluginId, "class with name \"" + className + "\" should be instance of " + DefaultActionGroup.class.getName() + " because there are children specified");
                    return null;
                }
            }
            group = (ActionGroup) obj;
        }
        // read ID and register loaded group
        String id = element.getAttributeValue(ID_ATTR_NAME);
        if (id != null && id.isEmpty()) {
            reportActionError(pluginId, "ID of the group cannot be an empty string");
            return null;
        }
        if (Boolean.valueOf(element.getAttributeValue(INTERNAL_ATTR_NAME)).booleanValue() && !ApplicationManagerEx.getApplicationEx().isInternal()) {
            myNotRegisteredInternalActionIds.add(id);
            return null;
        }
        if (id != null) {
            registerOrReplaceActionInner(element, id, group, pluginId);
        }
        Presentation presentation = group.getTemplatePresentation();
        // text
        String text = loadTextForElement(element, bundle, id, GROUP_ELEMENT_NAME);
        // don't override value which was set in API with empty value from xml descriptor
        if (!StringUtil.isEmpty(text) || presentation.getText() == null) {
            presentation.setText(text);
        }
        // description
        String description = loadDescriptionForElement(element, bundle, id, GROUP_ELEMENT_NAME);
        // don't override value which was set in API with empty value from xml descriptor
        if (!StringUtil.isEmpty(description) || presentation.getDescription() == null) {
            presentation.setDescription(description);
        }
        // icon
        setIcon(element.getAttributeValue(ICON_ATTR_NAME), className, loader, presentation, pluginId);
        // popup
        String popup = element.getAttributeValue(POPUP_ATTR_NAME);
        if (popup != null) {
            group.setPopup(Boolean.valueOf(popup).booleanValue());
        }
        // process all group's children. There are other groups, actions, references and links
        for (final Object o : element.getChildren()) {
            Element child = (Element) o;
            String name = child.getName();
            if (ACTION_ELEMENT_NAME.equals(name)) {
                AnAction action = processActionElement(child, loader, pluginId);
                if (action != null) {
                    assertActionIsGroupOrStub(action);
                    addToGroupInner(group, action, Constraints.LAST, isSecondary(child));
                }
            } else if (SEPARATOR_ELEMENT_NAME.equals(name)) {
                processSeparatorNode((DefaultActionGroup) group, child, pluginId);
            } else if (GROUP_ELEMENT_NAME.equals(name)) {
                AnAction action = processGroupElement(child, loader, pluginId);
                if (action != null) {
                    addToGroupInner(group, action, Constraints.LAST, false);
                }
            } else if (ADD_TO_GROUP_ELEMENT_NAME.equals(name)) {
                processAddToGroupNode(group, child, pluginId, isSecondary(child));
            } else if (REFERENCE_ELEMENT_NAME.equals(name)) {
                AnAction action = processReferenceElement(child, pluginId);
                if (action != null) {
                    addToGroupInner(group, action, Constraints.LAST, isSecondary(child));
                }
            } else {
                reportActionError(pluginId, "unexpected name of element \"" + name + "\n");
                return null;
            }
        }
        return group;
    } catch (ClassNotFoundException e) {
        reportActionError(pluginId, "class with name \"" + className + "\" not found");
        return null;
    } catch (NoClassDefFoundError e) {
        reportActionError(pluginId, "class with name \"" + e.getMessage() + "\" not found");
        return null;
    } catch (UnsupportedClassVersionError e) {
        reportActionError(pluginId, "unsupported class version for " + className);
        return null;
    } catch (Exception e) {
        final String message = "cannot create class \"" + className + "\"";
        if (pluginId == null) {
            LOG.error(message, e);
        } else {
            LOG.error(new PluginException(message, e, pluginId));
        }
        return null;
    }
}
Also used : Element(org.jdom.Element) PluginException(com.intellij.diagnostic.PluginException) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginException(com.intellij.diagnostic.PluginException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) CachingConstructorInjectionComponentAdapter(com.intellij.util.pico.CachingConstructorInjectionComponentAdapter)

Example 2 with CachingConstructorInjectionComponentAdapter

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

the class ProjectImpl method bootstrapPicoContainer.

@Override
protected void bootstrapPicoContainer(@NotNull String name) {
    Extensions.instantiateArea(ExtensionAreas.IDEA_PROJECT, this, null);
    super.bootstrapPicoContainer(name);
    final MutablePicoContainer picoContainer = getPicoContainer();
    final ProjectStoreClassProvider projectStoreClassProvider = (ProjectStoreClassProvider) picoContainer.getComponentInstanceOfType(ProjectStoreClassProvider.class);
    picoContainer.registerComponentImplementation(PathMacroManager.class, ProjectPathMacroManager.class);
    picoContainer.registerComponent(new ComponentAdapter() {

        private ComponentAdapter myDelegate;

        @NotNull
        private ComponentAdapter getDelegate() {
            if (myDelegate == null) {
                Class storeClass = projectStoreClassProvider.getProjectStoreClass(isDefault());
                myDelegate = new CachingConstructorInjectionComponentAdapter(storeClass, storeClass, null, true);
            }
            return myDelegate;
        }

        @Override
        public Object getComponentKey() {
            return IComponentStore.class;
        }

        @Override
        public Class getComponentImplementation() {
            return getDelegate().getComponentImplementation();
        }

        @Override
        public Object getComponentInstance(final PicoContainer container) throws PicoInitializationException, PicoIntrospectionException {
            return getDelegate().getComponentInstance(container);
        }

        @Override
        public void verify(final PicoContainer container) throws PicoIntrospectionException {
            getDelegate().verify(container);
        }

        @Override
        public void accept(final PicoVisitor visitor) {
            visitor.visitComponentAdapter(this);
            getDelegate().accept(visitor);
        }
    });
}
Also used : CachingConstructorInjectionComponentAdapter(com.intellij.util.pico.CachingConstructorInjectionComponentAdapter) NotNull(org.jetbrains.annotations.NotNull) CachingConstructorInjectionComponentAdapter(com.intellij.util.pico.CachingConstructorInjectionComponentAdapter)

Example 3 with CachingConstructorInjectionComponentAdapter

use of com.intellij.util.pico.CachingConstructorInjectionComponentAdapter 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)

Example 4 with CachingConstructorInjectionComponentAdapter

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

the class HeavyTestFixtureBuilderImpl method createModuleBuilder.

private <M extends ModuleFixtureBuilder> M createModuleBuilder(Class<M> key) {
    Class<? extends ModuleFixtureBuilder> implClass = myProviders.get(key);
    Assert.assertNotNull(key.toString(), implClass);
    final CachingConstructorInjectionComponentAdapter adapter = new CachingConstructorInjectionComponentAdapter(implClass, implClass, null, true);
    return (M) adapter.getComponentInstance(myContainer);
}
Also used : CachingConstructorInjectionComponentAdapter(com.intellij.util.pico.CachingConstructorInjectionComponentAdapter)

Example 5 with CachingConstructorInjectionComponentAdapter

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

the class ExtensionComponentAdapter method getDelegate.

private synchronized ComponentAdapter getDelegate() {
    if (myDelegate == null) {
        Class impl = loadImplementationClass();
        myDelegate = new CachingConstructorInjectionComponentAdapter(getComponentKey(), impl, null, true);
    }
    return myDelegate;
}
Also used : CachingConstructorInjectionComponentAdapter(com.intellij.util.pico.CachingConstructorInjectionComponentAdapter)

Aggregations

CachingConstructorInjectionComponentAdapter (com.intellij.util.pico.CachingConstructorInjectionComponentAdapter)5 NotNull (org.jetbrains.annotations.NotNull)2 PluginException (com.intellij.diagnostic.PluginException)1 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ArrayList (java.util.ArrayList)1 Element (org.jdom.Element)1 PicoContainer (org.picocontainer.PicoContainer)1