Search in sources :

Example 1 with XmlElementDecl

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

the class AdvancedDtdOptions method prepareNamespaceMap.

public static Map<String, ?> prepareNamespaceMap(Project project, VirtualFile firstFile) {
    final PsiFile file = PsiManager.getInstance(project).findFile(firstFile);
    if (file == null) {
        return Collections.emptyMap();
    }
    final HashMap<String, Object> map = new LinkedHashMap<>();
    file.accept(new PsiRecursiveElementVisitor() {

        @Override
        public void visitElement(PsiElement element) {
            if (element instanceof XmlElementDecl) {
                final String s = ((XmlElementDecl) element).getName();
                if (s != null) {
                    final String[] parts = s.split(":");
                    if (parts.length > 1) {
                        map.put(XMLNS + ":" + parts[0], null);
                    }
                }
            } else if (element instanceof XmlAttributeDecl) {
                final String s = ((XmlAttributeDecl) element).getName();
                if (s != null) {
                    final String[] parts = s.split(":");
                    if (parts.length > 1) {
                        map.put(XMLNS + ":" + parts[0], null);
                    }
                }
            }
            super.visitElement(element);
        }
    });
    return map;
}
Also used : PsiRecursiveElementVisitor(com.intellij.psi.PsiRecursiveElementVisitor) XmlAttributeDecl(com.intellij.psi.xml.XmlAttributeDecl) XmlElementDecl(com.intellij.psi.xml.XmlElementDecl) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 PsiRecursiveElementVisitor (com.intellij.psi.PsiRecursiveElementVisitor)1 XmlAttributeDecl (com.intellij.psi.xml.XmlAttributeDecl)1 XmlElementDecl (com.intellij.psi.xml.XmlElementDecl)1