Search in sources :

Example 1 with StringInterner

use of com.intellij.util.containers.StringInterner in project intellij-community by JetBrains.

the class IdeaPluginDescriptorImpl method readExternal.

public void readExternal(@NotNull Document document, @NotNull URL url, boolean ignoreMissingInclude, @NotNull JDOMXIncluder.PathResolver pathResolver) throws InvalidDataException, FileNotFoundException {
    document = JDOMXIncluder.resolve(document, url.toExternalForm(), ignoreMissingInclude, pathResolver);
    Element rootElement = document.getRootElement();
    JDOMUtil.internElement(rootElement, new StringInterner());
    readExternal(document.getRootElement());
}
Also used : StringInterner(com.intellij.util.containers.StringInterner) Element(org.jdom.Element)

Example 2 with StringInterner

use of com.intellij.util.containers.StringInterner in project intellij-community by JetBrains.

the class DirectoryStorageUtil method loadFrom.

@NotNull
public static Map<String, Element> loadFrom(@Nullable VirtualFile dir, @Nullable PathMacroSubstitutor pathMacroSubstitutor) {
    if (dir == null || !dir.exists()) {
        return Collections.emptyMap();
    }
    StringInterner interner = new StringInterner();
    Map<String, Element> fileToState = new THashMap<>();
    for (VirtualFile file : dir.getChildren()) {
        // ignore system files like .DS_Store on Mac
        if (!StringUtilRt.endsWithIgnoreCase(file.getNameSequence(), FileStorageCoreUtil.DEFAULT_EXT)) {
            continue;
        }
        try {
            if (file.getLength() == 0) {
                LOG.warn("Ignore empty file " + file.getPath());
                continue;
            }
            Element element = JDOMUtil.load(file.getInputStream());
            String componentName = FileStorageCoreUtil.getComponentNameIfValid(element);
            if (componentName == null) {
                continue;
            }
            if (!element.getName().equals(FileStorageCoreUtil.COMPONENT)) {
                LOG.error("Incorrect root tag name (" + element.getName() + ") in " + file.getPresentableUrl());
                continue;
            }
            List<Element> elementChildren = element.getChildren();
            if (elementChildren.isEmpty()) {
                continue;
            }
            Element state = (Element) elementChildren.get(0).detach();
            if (JDOMUtil.isEmpty(state)) {
                continue;
            }
            JDOMUtil.internElement(state, interner);
            if (pathMacroSubstitutor != null) {
                pathMacroSubstitutor.expandPaths(state);
                if (pathMacroSubstitutor instanceof TrackingPathMacroSubstitutor) {
                    ((TrackingPathMacroSubstitutor) pathMacroSubstitutor).addUnknownMacros(componentName, PathMacrosCollector.getMacroNames(state));
                }
            }
            fileToState.put(file.getName(), state);
        } catch (Throwable e) {
            LOG.warn("Unable to load state", e);
        }
    }
    return fileToState;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StringInterner(com.intellij.util.containers.StringInterner) THashMap(gnu.trove.THashMap) Element(org.jdom.Element) TrackingPathMacroSubstitutor(com.intellij.openapi.components.TrackingPathMacroSubstitutor) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with StringInterner

use of com.intellij.util.containers.StringInterner 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)

Example 4 with StringInterner

use of com.intellij.util.containers.StringInterner in project intellij-community by JetBrains.

the class IdeaPluginDescriptorImpl method readExternal.

// used in upsource
protected void readExternal(@NotNull Element element) {
    final PluginBean pluginBean = XmlSerializer.deserialize(element, PluginBean.class);
    url = pluginBean.url;
    myName = pluginBean.name;
    String idString = pluginBean.id;
    if (idString == null || idString.isEmpty()) {
        idString = myName;
    }
    myId = idString == null ? null : PluginId.getId(idString);
    String internalVersionString = pluginBean.formatVersion;
    if (internalVersionString != null) {
        try {
            //noinspection ResultOfMethodCallIgnored
            Integer.parseInt(internalVersionString);
        } catch (NumberFormatException e) {
            LOG.error(new PluginException("Invalid value in plugin.xml format version: '" + internalVersionString + "'", e, myId));
        }
    }
    myUseIdeaClassLoader = pluginBean.useIdeaClassLoader;
    myAllowBundledUpdate = pluginBean.allowBundledUpdate;
    if (pluginBean.ideaVersion != null) {
        mySinceBuild = pluginBean.ideaVersion.sinceBuild;
        myUntilBuild = convertExplicitBigNumberInUntilBuildToStar(pluginBean.ideaVersion.untilBuild);
    }
    myResourceBundleBaseName = pluginBean.resourceBundle;
    myDescriptionChildText = pluginBean.description;
    myChangeNotes = pluginBean.changeNotes;
    myVersion = pluginBean.pluginVersion;
    if (myVersion == null) {
        myVersion = PluginManagerCore.getBuildNumber().asStringWithoutProductCode();
    }
    myCategory = pluginBean.category;
    if (pluginBean.vendor != null) {
        myVendor = pluginBean.vendor.name;
        myVendorEmail = pluginBean.vendor.email;
        myVendorUrl = pluginBean.vendor.url;
        myVendorLogoPath = pluginBean.vendor.logo;
    }
    // preserve items order as specified in xml (filterBadPlugins will not fail if module comes first)
    Set<PluginId> dependentPlugins = new LinkedHashSet<>();
    Set<PluginId> optionalDependentPlugins = new LinkedHashSet<>();
    if (pluginBean.dependencies != null) {
        myOptionalConfigs = new THashMap<>();
        for (PluginDependency dependency : pluginBean.dependencies) {
            String text = dependency.pluginId;
            if (!StringUtil.isEmpty(text)) {
                PluginId id = PluginId.getId(text);
                dependentPlugins.add(id);
                if (dependency.optional) {
                    optionalDependentPlugins.add(id);
                    if (!StringUtil.isEmpty(dependency.configFile)) {
                        myOptionalConfigs.put(id, dependency.configFile);
                    }
                }
            }
        }
    }
    myDependencies = dependentPlugins.isEmpty() ? PluginId.EMPTY_ARRAY : dependentPlugins.toArray(new PluginId[dependentPlugins.size()]);
    myOptionalDependencies = optionalDependentPlugins.isEmpty() ? PluginId.EMPTY_ARRAY : optionalDependentPlugins.toArray(new PluginId[optionalDependentPlugins.size()]);
    if (pluginBean.helpSets == null || pluginBean.helpSets.length == 0) {
        myHelpSets = HelpSetPath.EMPTY;
    } else {
        myHelpSets = new HelpSetPath[pluginBean.helpSets.length];
        PluginHelpSet[] sets = pluginBean.helpSets;
        for (int i = 0, n = sets.length; i < n; i++) {
            PluginHelpSet pluginHelpSet = sets[i];
            myHelpSets[i] = new HelpSetPath(pluginHelpSet.file, pluginHelpSet.path);
        }
    }
    myAppComponents = pluginBean.applicationComponents;
    myProjectComponents = pluginBean.projectComponents;
    myModuleComponents = pluginBean.moduleComponents;
    if (myAppComponents == null)
        myAppComponents = ComponentConfig.EMPTY_ARRAY;
    if (myProjectComponents == null)
        myProjectComponents = ComponentConfig.EMPTY_ARRAY;
    if (myModuleComponents == null)
        myModuleComponents = ComponentConfig.EMPTY_ARRAY;
    StringInterner interner = new StringInterner();
    List<Element> extensions = copyElements(pluginBean.extensions, interner);
    if (extensions != null) {
        myExtensions = MultiMap.createSmart();
        for (Element extension : extensions) {
            myExtensions.putValue(ExtensionsAreaImpl.extractEPName(extension), extension);
        }
    }
    List<Element> extensionPoints = copyElements(pluginBean.extensionPoints, interner);
    if (extensionPoints != null) {
        myExtensionsPoints = MultiMap.createSmart();
        for (Element extensionPoint : extensionPoints) {
            myExtensionsPoints.putValue(StringUtil.notNullize(extensionPoint.getAttributeValue(ExtensionsAreaImpl.ATTRIBUTE_AREA)), extensionPoint);
        }
    }
    myActionsElements = copyElements(pluginBean.actions, interner);
    if (pluginBean.modules != null && !pluginBean.modules.isEmpty()) {
        myModules = pluginBean.modules;
    }
}
Also used : PluginException(com.intellij.diagnostic.PluginException) Element(org.jdom.Element) PluginId(com.intellij.openapi.extensions.PluginId) StringInterner(com.intellij.util.containers.StringInterner)

Example 5 with StringInterner

use of com.intellij.util.containers.StringInterner in project intellij-community by JetBrains.

the class GeneratedStructureModel method getInterner.

// we keep a shared string interner across all currently running xslt debugger instances. it should go away once
// all instances (and their toolwindow contents) are gone. This should minimize the memory usage of the generated
// structure tree.
private static StringInterner getInterner() {
    StringInterner interner = SoftReference.dereference(ourSharedInterner);
    if (interner == null) {
        interner = new StringInterner();
        ourSharedInterner = new WeakReference<>(interner);
    }
    return interner;
}
Also used : StringInterner(com.intellij.util.containers.StringInterner)

Aggregations

StringInterner (com.intellij.util.containers.StringInterner)6 Element (org.jdom.Element)4 TrackingPathMacroSubstitutor (com.intellij.openapi.components.TrackingPathMacroSubstitutor)2 NotNull (org.jetbrains.annotations.NotNull)2 PluginException (com.intellij.diagnostic.PluginException)1 CompositePathMacroFilter (com.intellij.openapi.components.CompositePathMacroFilter)1 PluginId (com.intellij.openapi.extensions.PluginId)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 XmlBuilder (com.intellij.psi.impl.source.parsing.xml.XmlBuilder)1 XmlBuilderDriver (com.intellij.psi.impl.source.parsing.xml.XmlBuilderDriver)1 THashMap (gnu.trove.THashMap)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1