Search in sources :

Example 1 with FilterElementProcessor

use of com.intellij.psi.scope.processor.FilterElementProcessor 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)

Example 2 with FilterElementProcessor

use of com.intellij.psi.scope.processor.FilterElementProcessor in project intellij-community by JetBrains.

the class HtmlFileTreeElement method getChildrenBase.

@Override
@NotNull
public Collection<StructureViewTreeElement> getChildrenBase() {
    if (isHtml5SectionsMode()) {
        // Html5SectionsNodeProvider will return its structure
        return Collections.emptyList();
    }
    final XmlFile xmlFile = getElement();
    final XmlDocument document = xmlFile == null ? null : xmlFile.getDocument();
    if (document == null) {
        return Collections.emptyList();
    }
    final List<XmlTag> rootTags = new SmartList<>();
    document.processElements(new FilterElementProcessor(XmlTagFilter.INSTANCE, rootTags), document);
    if (rootTags.isEmpty()) {
        return Collections.emptyList();
    } else if (rootTags.size() == 1) {
        final XmlTag rootTag = rootTags.get(0);
        if ("html".equalsIgnoreCase(rootTag.getLocalName())) {
            final XmlTag[] subTags = rootTag.getSubTags();
            if (subTags.length == 1 && ("head".equalsIgnoreCase(subTags[0].getLocalName()) || "body".equalsIgnoreCase(subTags[0].getLocalName()))) {
                return new HtmlTagTreeElement(subTags[0]).getChildrenBase();
            }
            return new HtmlTagTreeElement(rootTag).getChildrenBase();
        }
        return Collections.<StructureViewTreeElement>singletonList(new HtmlTagTreeElement(rootTag));
    } else {
        final Collection<StructureViewTreeElement> result = new ArrayList<>(rootTags.size());
        for (XmlTag tag : rootTags) {
            result.add(new HtmlTagTreeElement(tag));
        }
        return result;
    }
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) FilterElementProcessor(com.intellij.psi.scope.processor.FilterElementProcessor) Collection(java.util.Collection) XmlDocument(com.intellij.psi.xml.XmlDocument) SmartList(com.intellij.util.SmartList) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with FilterElementProcessor

use of com.intellij.psi.scope.processor.FilterElementProcessor in project intellij-community by JetBrains.

the class XmlElementDescriptorImpl method doCollectAttlistDeclarations.

private static XmlAttlistDecl[] doCollectAttlistDeclarations(XmlElement xmlElement) {
    final List<XmlAttlistDecl> result = new ArrayList<>();
    XmlUtil.processXmlElements(xmlElement, new FilterElementProcessor(new ClassFilter(XmlAttlistDecl.class), result), false, false, XmlUtil.getContainingFile(xmlElement));
    return result.toArray(new XmlAttlistDecl[result.size()]);
}
Also used : FilterElementProcessor(com.intellij.psi.scope.processor.FilterElementProcessor) ClassFilter(com.intellij.psi.filters.ClassFilter) ArrayList(java.util.ArrayList)

Example 4 with FilterElementProcessor

use of com.intellij.psi.scope.processor.FilterElementProcessor in project intellij-community by JetBrains.

the class XmlNSDescriptorImpl method doBuildDeclarationMap.

// Read-only calculation
private CachedValue<Map<String, XmlElementDescriptor>> doBuildDeclarationMap() {
    return CachedValuesManager.getManager(myElement.getProject()).createCachedValue(() -> {
        final List<XmlElementDecl> result = new ArrayList<>();
        myElement.processElements(new FilterElementProcessor(new ClassFilter(XmlElementDecl.class), result), getDeclaration());
        final Map<String, XmlElementDescriptor> ret = new LinkedHashMap<>((int) (result.size() * 1.5));
        Set<PsiFile> dependencies = new THashSet<>(1);
        dependencies.add(myDescriptorFile);
        for (final XmlElementDecl xmlElementDecl : result) {
            final String name = xmlElementDecl.getName();
            if (name != null) {
                if (!ret.containsKey(name)) {
                    ret.put(name, new XmlElementDescriptorImpl(xmlElementDecl));
                    // if element descriptor was produced from entity reference use proper dependency
                    PsiElement dependingElement = xmlElementDecl.getUserData(XmlElement.DEPENDING_ELEMENT);
                    if (dependingElement != null) {
                        PsiFile dependingElementContainingFile = dependingElement.getContainingFile();
                        if (dependingElementContainingFile != null)
                            dependencies.add(dependingElementContainingFile);
                    }
                }
            }
        }
        return new CachedValueProvider.Result<>(ret, dependencies.toArray());
    }, false);
}
Also used : THashSet(gnu.trove.THashSet) FilterElementProcessor(com.intellij.psi.scope.processor.FilterElementProcessor) ClassFilter(com.intellij.psi.filters.ClassFilter) PsiFile(com.intellij.psi.PsiFile) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) PsiElement(com.intellij.psi.PsiElement)

Example 5 with FilterElementProcessor

use of com.intellij.psi.scope.processor.FilterElementProcessor in project intellij-community by JetBrains.

the class XmlEnumeratedTypeImpl method getEnumeratedValues.

@Override
public XmlElement[] getEnumeratedValues() {
    final List<XmlElement> result = new ArrayList<>();
    processElements(new FilterElementProcessor(new XmlTokenTypeFilter(XmlTokenType.XML_NAME), result), this);
    return result.toArray(new XmlElement[result.size()]);
}
Also used : FilterElementProcessor(com.intellij.psi.scope.processor.FilterElementProcessor) XmlTokenTypeFilter(com.intellij.psi.filters.position.XmlTokenTypeFilter) ArrayList(java.util.ArrayList) XmlElement(com.intellij.psi.xml.XmlElement)

Aggregations

FilterElementProcessor (com.intellij.psi.scope.processor.FilterElementProcessor)7 ArrayList (java.util.ArrayList)4 ClassFilter (com.intellij.psi.filters.ClassFilter)3 PsiElement (com.intellij.psi.PsiElement)2 XmlDocument (com.intellij.psi.xml.XmlDocument)2 XmlFile (com.intellij.psi.xml.XmlFile)2 XmlTag (com.intellij.psi.xml.XmlTag)2 NotNull (org.jetbrains.annotations.NotNull)2 PsiFile (com.intellij.psi.PsiFile)1 XmlTokenTypeFilter (com.intellij.psi.filters.position.XmlTokenTypeFilter)1 XmlElement (com.intellij.psi.xml.XmlElement)1 SmartList (com.intellij.util.SmartList)1 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)1 THashSet (gnu.trove.THashSet)1 Collection (java.util.Collection)1