示例#1
0
    def update(self, symbols: "SymbolMap") -> None:
        """
		Register multiple symbols.
		"""
        for fqn, element in symbols.map.items():

            # Ignore private entries
            if FQN.isPrivate(fqn):
                continue
            existingElement = self._get(fqn=fqn)
            if existingElement is not None and element["p"] != existingElement[
                    "p"]:
                SymbolMap.errorSymbolConflict_(
                    SymbolMap.metaToElement(element),
                    SymbolMap.metaToElement(existingElement))
            self.map[fqn] = element
示例#2
0
    def close(self) -> None:
        """
		Close the map to prevent any further editing.
		"""

        # Create serialized blobs for elements present in the entities map.
        removeFQNs: typing.Set[str] = set()
        for fqn, entity in self.entities.items():

            # Ignore builtins
            if fqn in self.builtins:
                continue

            entity.assertTrue(
                condition=fqn in self.map,
                message=
                "Entry '{}' was not properly created before being added to the entities map."
                .format(fqn))
            element = entity.element

            # Remove nested element and change them to references.
            if any([
                    element.isNestedSequence(category)
                    for category in CATEGORIES
            ]):

                preparedElement = element.copy(ignoreNested=CATEGORIES)
                for category in CATEGORIES:
                    nested = element.getNestedSequence(category)
                    if nested is not None:
                        sequence = SequenceBuilder()
                        for nestedElement in nested:
                            if nestedElement.isAttr("fqn"):
                                fqnNested = nestedElement.getAttr("fqn").value
                                # Remove private FQNs and keep them nested.
                                # This is needed because when merging nested structure, some config
                                # for example have unamed elements and need to be copied with the rest.
                                if FQN.isPrivate(fqnNested):
                                    removeFQNs.add(fqnNested)
                                    ElementBuilder.cast(
                                        nestedElement,
                                        ElementBuilder).removeAttr("fqn")
                                    sequence.pushBackElement(nestedElement)
                                else:
                                    sequence.pushBackElement(
                                        self.makeReference(fqnNested))
                            else:
                                sequence.pushBackElement(nestedElement)
                        if sequence:
                            preparedElement.setNestedSequence(
                                category, sequence)
                element = preparedElement

            # Serialize the element to the map.
            self.map[fqn]["e"] = element.serialize()

        # Remove some of the FQNs that have been copied.
        for fqn in removeFQNs:
            del self.map[fqn]

        # Sanity check to ensure that all entries in the map are valid.
        for fqn, entry in self.map.items():
            assert "e" in entry and entry[
                "e"], "Invalid element in the map: {}.".format(entry)
            assert "c" in entry and entry[
                "c"], "Invalid category in the map: {}.".format(entry)
            assert "p" in entry, "Missing path in the map: {}.".format(entry)

        # Mark as closed.
        self.isClosed = True