Search in sources :

Example 1 with XmlDocument

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

the class XsltRunConfiguration method initFromFile.

public XsltRunConfiguration initFromFile(@NotNull XmlFile file) {
    assert XsltSupport.isXsltFile(file) : "Not an XSLT file: " + file.getName();
    mySuggestedName = file.getName();
    final VirtualFile virtualFile = file.getVirtualFile();
    assert virtualFile != null : "No VirtualFile for " + file.getName();
    setXsltFile(virtualFile);
    final PsiFile[] associations = FileAssociationsManager.getInstance(file.getProject()).getAssociationsFor(file);
    if (associations.length > 0) {
        final VirtualFile assoc = associations[0].getVirtualFile();
        assert assoc != null;
        setXmlInputFile(assoc);
    }
    final XmlDocument document = file.getDocument();
    assert document != null : "XSLT file without document?";
    final XmlTag rootTag = document.getRootTag();
    assert rootTag != null : "XSLT file without root element?";
    final XmlTag[] params = rootTag.findSubTags("param", XsltSupport.XSLT_NS);
    for (XmlTag param : params) {
        final String name = param.getAttributeValue("name");
        if (name != null) {
            final Pair<String, String> pair = Pair.create(name, null);
            myParameters.add(pair);
        }
    }
    final XmlTag[] outputs = rootTag.findSubTags("output", XsltSupport.XSLT_NS);
    for (XmlTag output : outputs) {
        final String method = output.getAttributeValue("method");
        if ("xml".equals(method)) {
            setFileType(StdFileTypes.XML);
        } else if ("html".equals(method)) {
            setFileType(StdFileTypes.HTML);
        } else if ("text".equals(method)) {
            setFileType(FileTypes.PLAIN_TEXT);
        }
    }
    return this;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlTag(com.intellij.psi.xml.XmlTag)

Example 2 with XmlDocument

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

the class NamespaceCollector method findAllNamespaces.

public static Set<Namespace> findAllNamespaces(final XmlFile psiFile) {
    final NamespaceCollector namespaceCollector = new NamespaceCollector();
    final XmlDocument document = psiFile.getDocument();
    if (document != null) {
        document.accept(namespaceCollector);
    }
    return namespaceCollector.namespaces;
}
Also used : XmlDocument(com.intellij.psi.xml.XmlDocument)

Example 3 with XmlDocument

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

the class NamespaceCollector method findNamespaces.

public static Map<String, String> findNamespaces(final XmlFile psiFile) {
    final NamespaceCollector namespaceCollector = new NamespaceCollector();
    final XmlDocument document = psiFile.getDocument();
    if (document != null) {
        document.accept(namespaceCollector);
    }
    final Set<Namespace> namespaces = namespaceCollector.namespaces;
    return convert(namespaces);
}
Also used : XmlDocument(com.intellij.psi.xml.XmlDocument)

Example 4 with XmlDocument

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

the class ResolvingVisitor method processInclude.

private void processInclude(XmlFile xmlFile, XmlAttribute attribute) {
    final Set<XmlFile> set = myProcessingContext.get(VISITED_KEY);
    if (set.contains(xmlFile)) {
        return;
    }
    set.add(xmlFile);
    final XmlDocument document = xmlFile.getDocument();
    if (document == null)
        return;
    final XmlTag rootTag = document.getRootTag();
    if (rootTag == null)
        return;
    rootTag.processElements(this, attribute);
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlTag(com.intellij.psi.xml.XmlTag)

Example 5 with XmlDocument

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

the class Html5SectionsNodeProvider method provideNodes.

@NotNull
@Override
public Collection<Html5SectionTreeElement> provideNodes(@NotNull final TreeElement node) {
    if (!(node instanceof HtmlFileTreeElement))
        return Collections.emptyList();
    final XmlFile xmlFile = ((HtmlFileTreeElement) node).getElement();
    final XmlDocument document = xmlFile == null ? null : xmlFile.getDocument();
    if (document == null)
        return Collections.emptyList();
    final List<XmlTag> rootTags = new ArrayList<>();
    document.processElements(new FilterElementProcessor(XmlTagFilter.INSTANCE, rootTags), document);
    final Collection<Html5SectionTreeElement> result = new ArrayList<>();
    for (XmlTag tag : rootTags) {
        result.addAll(Html5SectionsProcessor.processAndGetRootSections(tag));
    }
    return result;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) FilterElementProcessor(com.intellij.psi.scope.processor.FilterElementProcessor) ArrayList(java.util.ArrayList) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

XmlDocument (com.intellij.psi.xml.XmlDocument)57 XmlTag (com.intellij.psi.xml.XmlTag)39 XmlFile (com.intellij.psi.xml.XmlFile)32 PsiElement (com.intellij.psi.PsiElement)13 Nullable (org.jetbrains.annotations.Nullable)11 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)9 PsiFile (com.intellij.psi.PsiFile)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 ArrayList (java.util.ArrayList)6 XmlAttribute (com.intellij.psi.xml.XmlAttribute)5 PsiMetaData (com.intellij.psi.meta.PsiMetaData)4 IncorrectOperationException (com.intellij.util.IncorrectOperationException)4 NotNull (org.jetbrains.annotations.NotNull)4 Project (com.intellij.openapi.project.Project)3 XmlText (com.intellij.psi.xml.XmlText)3 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)3 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)2 Editor (com.intellij.openapi.editor.Editor)2 PsiErrorElement (com.intellij.psi.PsiErrorElement)2 FilterElementProcessor (com.intellij.psi.scope.processor.FilterElementProcessor)2