Search in sources :

Example 1 with XmlRecursiveElementWalkingVisitor

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

the class HtmlUtil method getIncludedPathsElements.

public static List<XmlAttributeValue> getIncludedPathsElements(@NotNull final XmlFile file) {
    final List<XmlAttributeValue> result = new ArrayList<>();
    file.acceptChildren(new XmlRecursiveElementWalkingVisitor() {

        @Override
        public void visitXmlTag(XmlTag tag) {
            XmlAttribute attribute = null;
            if ("link".equalsIgnoreCase(tag.getName())) {
                attribute = tag.getAttribute("href");
            } else if ("script".equalsIgnoreCase(tag.getName()) || "img".equalsIgnoreCase(tag.getName())) {
                attribute = tag.getAttribute("src");
            }
            if (attribute != null)
                result.add(attribute.getValueElement());
            super.visitXmlTag(tag);
        }

        @Override
        public void visitElement(PsiElement element) {
            if (element.getLanguage() instanceof XMLLanguage) {
                super.visitElement(element);
            }
        }
    });
    return result.isEmpty() ? Collections.emptyList() : result;
}
Also used : XMLLanguage(com.intellij.lang.xml.XMLLanguage) XmlRecursiveElementWalkingVisitor(com.intellij.psi.XmlRecursiveElementWalkingVisitor) PsiElement(com.intellij.psi.PsiElement)

Example 2 with XmlRecursiveElementWalkingVisitor

use of com.intellij.psi.XmlRecursiveElementWalkingVisitor in project intellij-plugins by JetBrains.

the class AngularAttributeIndexer method map.

@NotNull
@Override
public Map<String, AngularNamedItemDefinition> map(@NotNull FileContent inputData) {
    final Map<String, AngularNamedItemDefinition> map = new HashMap<>();
    final PsiFile file = inputData.getPsiFile();
    if (file instanceof XmlFile) {
        file.accept(new XmlRecursiveElementWalkingVisitor() {

            @Override
            public void visitXmlAttribute(XmlAttribute attribute) {
                if (myAttributeName.equals(DirectiveUtil.normalizeAttributeName(attribute.getName()))) {
                    final XmlAttributeValue element = attribute.getValueElement();
                    if (element == null) {
                        map.put("", new AngularNamedItemDefinition("", attribute.getTextRange().getStartOffset()));
                    } else {
                        final String name = StringUtil.unquoteString(element.getText());
                        map.put(name, new AngularNamedItemDefinition(name, element.getTextRange().getStartOffset()));
                    }
                }
            }
        });
    }
    return map;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) HashMap(java.util.HashMap) PsiFile(com.intellij.psi.PsiFile) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XmlRecursiveElementWalkingVisitor(com.intellij.psi.XmlRecursiveElementWalkingVisitor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

XmlRecursiveElementWalkingVisitor (com.intellij.psi.XmlRecursiveElementWalkingVisitor)2 XMLLanguage (com.intellij.lang.xml.XMLLanguage)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)1 XmlFile (com.intellij.psi.xml.XmlFile)1 HashMap (java.util.HashMap)1 NotNull (org.jetbrains.annotations.NotNull)1