Semprini / pyMDG

UML Model Driven Generation of schema, code, data and documentation.
Other
21 stars 10 forks source link

Sparx local DBs can have the same id for packages as classes #44

Closed Semprini closed 2 years ago

Semprini commented 2 years ago
    def find_by_id(self, id: Union[int, str], find_type: Optional[str]=None):
        """ Finds UMLPackage, UMLClass, UMLEnumeration or UMLInstance object with specified Id
        Looks for classes part of this package and all sub-packages
        """
        if str(self.id) == str(id) and find_type in (None, "package"):
            return self

        for cls in self.classes:
            if str(cls.id) == str(id) and find_type in (None, "class"):
                return cls

        for ins in self.instances:
            if str(ins.id) == str(id) and find_type in (None, "instance"):
                return ins

        for enum in self.enumerations:
            if str(enum.id) == str(id) and find_type in (None, "enumeration"):
                return enum

        for child in self.children:
            res = child.find_by_id(id, find_type)
            if res is not None:
                return res