Search in sources :

Example 1 with Extensions

use of org.jetbrains.idea.devkit.dom.Extensions in project intellij-community by JetBrains.

the class PrepareToDeployAction method collectJpsPluginModules.

@NotNull
private static Map<Module, String> collectJpsPluginModules(@NotNull Module module) {
    XmlFile pluginXml = PluginModuleType.getPluginXml(module);
    if (pluginXml == null)
        return Collections.emptyMap();
    DomFileElement<IdeaPlugin> fileElement = DomManager.getDomManager(module.getProject()).getFileElement(pluginXml, IdeaPlugin.class);
    if (fileElement == null)
        return Collections.emptyMap();
    Map<Module, String> jpsPluginToOutputPath = new HashMap<>();
    IdeaPlugin plugin = fileElement.getRootElement();
    List<Extensions> extensions = plugin.getExtensions();
    for (Extensions extensionGroup : extensions) {
        XmlTag extensionsTag = extensionGroup.getXmlTag();
        String defaultExtensionNs = extensionsTag.getAttributeValue("defaultExtensionNs");
        for (XmlTag tag : extensionsTag.getSubTags()) {
            String name = tag.getLocalName();
            String qualifiedName = defaultExtensionNs != null ? defaultExtensionNs + "." + name : name;
            if (CompileServerPlugin.EP_NAME.getName().equals(qualifiedName)) {
                String classpath = tag.getAttributeValue("classpath");
                if (classpath != null) {
                    for (String path : StringUtil.split(classpath, ";")) {
                        String moduleName = FileUtil.getNameWithoutExtension(PathUtil.getFileName(path));
                        Module jpsModule = ModuleManager.getInstance(module.getProject()).findModuleByName(moduleName);
                        if (jpsModule != null) {
                            jpsPluginToOutputPath.put(jpsModule, path);
                        }
                    }
                }
            }
        }
    }
    return jpsPluginToOutputPath;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) IdeaPlugin(org.jetbrains.idea.devkit.dom.IdeaPlugin) Module(com.intellij.openapi.module.Module) Extensions(org.jetbrains.idea.devkit.dom.Extensions) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Extensions

use of org.jetbrains.idea.devkit.dom.Extensions in project intellij-community by JetBrains.

the class PluginDescriptorChooser method findOrCreateExtensionsForEP.

@NotNull
public static Extensions findOrCreateExtensionsForEP(DomFileElement<IdeaPlugin> domFileElement, String epName) {
    final IdeaPlugin ideaPlugin = domFileElement.getRootElement();
    final List<Extensions> extensionsList = ideaPlugin.getExtensions();
    for (Extensions extensions : extensionsList) {
        if (extensions.getXmlTag() instanceof IncludedXmlTag) {
            continue;
        }
        String s = extensions.getDefaultExtensionNs().getStringValue();
        if (s != null && epName.startsWith(s)) {
            return extensions;
        }
    }
    Extensions extensions = ideaPlugin.addExtensions();
    final String epPrefix = StringUtil.getPackageName(epName);
    extensions.getDefaultExtensionNs().setStringValue(epPrefix);
    return extensions;
}
Also used : IdeaPlugin(org.jetbrains.idea.devkit.dom.IdeaPlugin) IncludedXmlTag(com.intellij.xml.util.IncludedXmlTag) Extensions(org.jetbrains.idea.devkit.dom.Extensions) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with Extensions

use of org.jetbrains.idea.devkit.dom.Extensions in project intellij-community by JetBrains.

the class RegisterExtensionFix method registerExtension.

private void registerExtension(final DomFileElement<IdeaPlugin> selectedValue, final ExtensionPointCandidate candidate) {
    PsiElement navTarget = new WriteCommandAction<PsiElement>(selectedValue.getFile().getProject(), selectedValue.getFile()) {

        @Override
        protected void run(@NotNull Result<PsiElement> result) throws Throwable {
            Extensions extensions = PluginDescriptorChooser.findOrCreateExtensionsForEP(selectedValue, candidate.epName);
            Extension extension = extensions.addExtension(candidate.epName);
            XmlTag tag = extension.getXmlTag();
            PsiElement navTarget = null;
            String keyAttrName = KEY_MAP.get(candidate.beanClassName);
            if (keyAttrName != null) {
                XmlAttribute attr = tag.setAttribute(keyAttrName, "");
                navTarget = attr.getValueElement();
            }
            if (candidate.attributeName != null) {
                tag.setAttribute(candidate.attributeName, myExtensionClass.getQualifiedName());
            } else {
                XmlTag subTag = tag.createChildTag(candidate.tagName, null, myExtensionClass.getQualifiedName(), false);
                tag.addSubTag(subTag, false);
            }
            result.setResult(navTarget != null ? navTarget : extension.getXmlTag());
        }
    }.execute().throwException().getResultObject();
    PsiNavigateUtil.navigate(navTarget);
}
Also used : Extension(org.jetbrains.idea.devkit.dom.Extension) XmlAttribute(com.intellij.psi.xml.XmlAttribute) Extensions(org.jetbrains.idea.devkit.dom.Extensions) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 4 with Extensions

use of org.jetbrains.idea.devkit.dom.Extensions in project intellij-community by JetBrains.

the class RegisterInspectionFix method doFix.

private void doFix(final DomFileElement<IdeaPlugin> selectedValue, final Project project, final PsiFile file) {
    Extension extension = new WriteCommandAction<Extension>(project, file) {

        @Override
        protected void run(@NotNull Result<Extension> result) throws Throwable {
            final Extensions extensions = PluginDescriptorChooser.findOrCreateExtensionsForEP(selectedValue, myEp.getName());
            Extension extension = extensions.addExtension(myEp.getName());
            XmlTag tag = extension.getXmlTag();
            tag.setAttribute("implementationClass", myPsiClass.getQualifiedName());
            result.setResult(extension);
        }
    }.execute().throwException().getResultObject();
    PsiNavigateUtil.navigate(extension.getXmlTag());
}
Also used : Extension(org.jetbrains.idea.devkit.dom.Extension) Extensions(org.jetbrains.idea.devkit.dom.Extensions) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

Extensions (org.jetbrains.idea.devkit.dom.Extensions)4 XmlTag (com.intellij.psi.xml.XmlTag)3 NotNull (org.jetbrains.annotations.NotNull)2 Extension (org.jetbrains.idea.devkit.dom.Extension)2 IdeaPlugin (org.jetbrains.idea.devkit.dom.IdeaPlugin)2 Module (com.intellij.openapi.module.Module)1 PsiElement (com.intellij.psi.PsiElement)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlFile (com.intellij.psi.xml.XmlFile)1 IncludedXmlTag (com.intellij.xml.util.IncludedXmlTag)1