Search in sources :

Example 1 with CompositePathMacroFilter

use of com.intellij.openapi.components.CompositePathMacroFilter in project intellij-community by JetBrains.

the class FileStorageCoreUtil method load.

@NotNull
public static TreeMap<String, Element> load(@NotNull Element rootElement, @Nullable PathMacroSubstitutor pathMacroSubstitutor, boolean intern) {
    if (pathMacroSubstitutor != null) {
        pathMacroSubstitutor.expandPaths(rootElement);
    }
    StringInterner interner = intern ? new StringInterner() : null;
    List<Element> children = rootElement.getChildren(COMPONENT);
    if (children.isEmpty() && rootElement.getName().equals(COMPONENT) && rootElement.getAttributeValue(NAME) != null) {
        // exclusive component data
        // singleton must be not used here - later we modify list
        children = new SmartList<>(rootElement);
    }
    CompositePathMacroFilter filter = null;
    TreeMap<String, Element> map = new TreeMap<>();
    for (Iterator<Element> iterator = children.iterator(); iterator.hasNext(); ) {
        Element element = iterator.next();
        String name = getComponentNameIfValid(element);
        if (name == null || !(element.getAttributes().size() > 1 || !element.getChildren().isEmpty())) {
            continue;
        }
        // so, PathMacroFilter can easily find component name (null parent)
        iterator.remove();
        if (interner != null) {
            JDOMUtil.internElement(element, interner);
        }
        map.put(name, element);
        if (pathMacroSubstitutor instanceof TrackingPathMacroSubstitutor) {
            if (filter == null) {
                filter = new CompositePathMacroFilter(PathMacrosCollector.MACRO_FILTER_EXTENSION_POINT_NAME.getExtensions());
            }
            ((TrackingPathMacroSubstitutor) pathMacroSubstitutor).addUnknownMacros(name, PathMacrosCollector.getMacroNames(element, filter, PathMacros.getInstance()));
        }
        // remove only after "getMacroNames" - some PathMacroFilter requires element name attribute
        element.removeAttribute(NAME);
    }
    return map;
}
Also used : StringInterner(com.intellij.util.containers.StringInterner) Element(org.jdom.Element) TrackingPathMacroSubstitutor(com.intellij.openapi.components.TrackingPathMacroSubstitutor) TreeMap(java.util.TreeMap) CompositePathMacroFilter(com.intellij.openapi.components.CompositePathMacroFilter) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

CompositePathMacroFilter (com.intellij.openapi.components.CompositePathMacroFilter)1 TrackingPathMacroSubstitutor (com.intellij.openapi.components.TrackingPathMacroSubstitutor)1 StringInterner (com.intellij.util.containers.StringInterner)1 TreeMap (java.util.TreeMap)1 Element (org.jdom.Element)1 NotNull (org.jetbrains.annotations.NotNull)1