diff --git a/capellambse/model/common/element.py b/capellambse/model/common/element.py index 9a415074d..2f32713b3 100644 --- a/capellambse/model/common/element.py +++ b/capellambse/model/common/element.py @@ -401,6 +401,43 @@ def _wrap_short_html(self, content: str) -> markupsafe.Markup: def _repr_html_(self) -> str: return self.__html__() + def get_children(self) -> MixedElementList: + """Return all model elements that are children of this one. + + .... seealso:: + + :meth:`iter_children` + """ + return MixedElementList( + self._model, [ele._element for ele in self.iter_children()] + ) + + def has_children(self) -> bool: + return next(self.iter_children(), None) is not None + + def iter_children(self) -> t.Iterator[GenericElement]: + """Yield model elements that are children of this one. + + The elements yielded from this generator are the direct + descendants of this element, with regard to the XML hierarchy + (usually referred to as "owned objects" in the metamodel). + """ + for attr in dir(self): + if attr.startswith("_"): + continue + acc = getattr(type(self), attr, None) + if ( + # pylint: disable-next=unidiomatic-typecheck + type(acc) is accessors.DirectProxyAccessor + and not acc.rootelem + or isinstance(acc, accessors.RoleTagAccessor) + ): + if acc.aslist is None: + if getattr(self, attr) is not None: + yield getattr(self, attr) + else: + yield from getattr(self, attr) + if t.TYPE_CHECKING: def __getattr__(self, attr: str) -> t.Any: @@ -756,7 +793,7 @@ def __html__(self) -> markupsafe.Markup: return markupsafe.Markup("

(Empty list)

") fragments = ['
    '] - for i in self: + for i in [i for i in self if i is not None]: fragments.append(f"
  1. {i._short_html_()}
  2. ") fragments.append("
") return markupsafe.Markup("".join(fragments)) diff --git a/capellambse/model/crosslayer/information/datavalue.py b/capellambse/model/crosslayer/information/datavalue.py index 61eaf1f8e..4d9ead795 100644 --- a/capellambse/model/crosslayer/information/datavalue.py +++ b/capellambse/model/crosslayer/information/datavalue.py @@ -67,6 +67,5 @@ def __eq__(self, other: object) -> bool: @c.xtype_handler(None) class EnumerationReference(c.GenericElement): - name = c.AttributeProperty("name", returntype=str) type = c.AttrProxyAccessor(c.GenericElement, "abstractType") value = c.AttrProxyAccessor(c.GenericElement, "referencedValue")