Search in sources :

Example 86 with XmlFile

use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.

the class AntDomElement method getContextAntProject.

public final AntDomProject getContextAntProject() {
    final AntConfigurationBase antConfig = AntConfigurationBase.getInstance(getManager().getProject());
    final XmlElement xmlElement = getXmlElement();
    if (xmlElement == null) {
        return getAntProject();
    }
    PsiFile containingFile = xmlElement.getContainingFile();
    if (containingFile != null) {
        containingFile = containingFile.getOriginalFile();
    }
    if (!(containingFile instanceof XmlFile)) {
        return getAntProject();
    }
    final XmlFile contextFile = antConfig.getEffectiveContextFile(((XmlFile) containingFile));
    if (contextFile == null) {
        return getAntProject();
    }
    return AntSupport.getAntDomProject(contextFile);
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlElement(com.intellij.psi.xml.XmlElement) PsiFile(com.intellij.psi.PsiFile) AntConfigurationBase(com.intellij.lang.ant.config.AntConfigurationBase)

Example 87 with XmlFile

use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.

the class AntBuildFileImpl method getAntFile.

@Nullable
public XmlFile getAntFile() {
    final PsiFile psiFile = myVFile.isValid() ? PsiManager.getInstance(getProject()).findFile(myVFile) : null;
    if (!(psiFile instanceof XmlFile)) {
        return null;
    }
    final XmlFile xmlFile = (XmlFile) psiFile;
    return AntDomFileDescription.isAntFile(xmlFile) ? xmlFile : null;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Example 88 with XmlFile

use of com.intellij.psi.xml.XmlFile 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 89 with XmlFile

use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.

the class RegistrationCheckerUtil method checkModule.

@Nullable
private static Set<PsiClass> checkModule(Module module, PsiClass psiClass, @Nullable Set<PsiClass> types, boolean includeActions) {
    final XmlFile pluginXml = PluginModuleType.getPluginXml(module);
    if (pluginXml == null)
        return null;
    final DomFileElement<IdeaPlugin> fileElement = DescriptorUtil.getIdeaPlugin(pluginXml);
    if (fileElement == null)
        return null;
    final String qualifiedName = psiClass.getQualifiedName();
    if (qualifiedName != null) {
        final RegistrationTypeFinder finder = new RegistrationTypeFinder(psiClass, types);
        // "main" plugin.xml
        processPluginXml(pluginXml, finder, includeActions);
        // <depends> plugin.xml files
        for (Dependency dependency : fileElement.getRootElement().getDependencies()) {
            final GenericAttributeValue<PathReference> configFileAttribute = dependency.getConfigFile();
            if (!DomUtil.hasXml(configFileAttribute))
                continue;
            final PathReference configFile = configFileAttribute.getValue();
            if (configFile != null) {
                final PsiElement resolve = configFile.resolve();
                if (!(resolve instanceof XmlFile))
                    continue;
                final XmlFile depPluginXml = (XmlFile) resolve;
                if (DescriptorUtil.isPluginXml(depPluginXml)) {
                    processPluginXml(depPluginXml, finder, includeActions);
                }
            }
        }
        types = finder.getTypes();
    }
    return types;
}
Also used : PathReference(com.intellij.openapi.paths.PathReference) XmlFile(com.intellij.psi.xml.XmlFile) IdeaPlugin(org.jetbrains.idea.devkit.dom.IdeaPlugin) Dependency(org.jetbrains.idea.devkit.dom.Dependency) Nullable(org.jetbrains.annotations.Nullable)

Example 90 with XmlFile

use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.

the class AddAntBuildFile method update.

public void update(@NotNull AnActionEvent e) {
    final Presentation presentation = e.getPresentation();
    final Project project = e.getProject();
    if (project != null) {
        final VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
        if (files != null && files.length > 0) {
            for (VirtualFile file : files) {
                final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
                if (!(psiFile instanceof XmlFile)) {
                    continue;
                }
                final XmlFile xmlFile = (XmlFile) psiFile;
                final XmlDocument document = xmlFile.getDocument();
                if (document == null) {
                    continue;
                }
                final XmlTag rootTag = document.getRootTag();
                if (rootTag == null) {
                    continue;
                }
                if (!"project".equals(rootTag.getName())) {
                    continue;
                }
                if (AntConfigurationBase.getInstance(project).getAntBuildFile(psiFile) != null) {
                    continue;
                }
                // found at least one candidate file
                enable(presentation);
                return;
            }
        }
    }
    disable(presentation);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) PsiFile(com.intellij.psi.PsiFile) XmlDocument(com.intellij.psi.xml.XmlDocument) Presentation(com.intellij.openapi.actionSystem.Presentation) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

XmlFile (com.intellij.psi.xml.XmlFile)409 XmlTag (com.intellij.psi.xml.XmlTag)155 PsiFile (com.intellij.psi.PsiFile)121 VirtualFile (com.intellij.openapi.vfs.VirtualFile)102 Nullable (org.jetbrains.annotations.Nullable)74 Project (com.intellij.openapi.project.Project)69 NotNull (org.jetbrains.annotations.NotNull)66 PsiElement (com.intellij.psi.PsiElement)64 XmlAttribute (com.intellij.psi.xml.XmlAttribute)39 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)34 Module (com.intellij.openapi.module.Module)34 XmlDocument (com.intellij.psi.xml.XmlDocument)32 Result (com.intellij.openapi.application.Result)28 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)23 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)22 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)21 ArrayList (java.util.ArrayList)20 Document (com.intellij.openapi.editor.Document)19 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)18 Editor (com.intellij.openapi.editor.Editor)15