예제 #1
0
    def render_object_specification(self, context, object_):
        obj_name = object_.name
        if obj_name is None:
            obj_name = ""
        if is_cclass(object_):
            object_ = object_.class_object

        stereotype_string = ""
        tagged_value_string = ""
        if object_.class_object_class is not None:
            stereotype_string = self.render_stereotypes(
                object_.class_object_class.stereotype_instances)
            tagged_value_string = self.render_tagged_values(
                object_.class_object_class,
                object_.class_object_class.stereotype_instances)
            if len(tagged_value_string) > 0:
                tagged_value_string = tagged_value_string + "\\n"

        cl_name = object_.classifier.name
        if cl_name is None:
            cl_name = ""

        obj_string = " : " + cl_name
        if obj_name != "":
            obj_string = obj_name + obj_string

        if len(stereotype_string) > 0:
            stereotype_string = " " + stereotype_string + " "

        context.add_line("class \"" + tagged_value_string +
                         self.pad_and_break_name(obj_string, None, True) +
                         "\" as " + self.get_node_id(context, object_) +
                         stereotype_string +
                         self.render_attribute_values(context, object_))
예제 #2
0
    def render_classifier_specification(self, context, cl):
        stereotype_string = ""
        tagged_value_string = ""

        if is_cstereotype(cl):
            stereotype_string = self.render_stereotypes_string("stereotype")
        if is_cmetaclass(cl):
            stereotype_string = self.render_stereotypes_string("metaclass")
        if is_cclass(cl):
            stereotype_string = self.render_stereotypes(
                cl.stereotype_instances)
            if context.render_tagged_values:
                tagged_value_string = self.render_tagged_values(
                    cl, cl.stereotype_instances)
                if len(tagged_value_string) > 0:
                    tagged_value_string = tagged_value_string + "\\n"
            if context.render_metaclass_as_stereotype:
                stereotype_string = self.render_stereotypes_string(
                    cl.metaclass.name) + stereotype_string

        if len(stereotype_string) > 0:
            stereotype_string = " " + stereotype_string + " "
        name_label = '"' + tagged_value_string + self.pad_and_break_name(
            cl.name, None, True) + '"'
        context.add_line("class " + name_label + " as " +
                         self.get_node_id(context, cl) + stereotype_string +
                         self.render_attributes(context, cl))
예제 #3
0
 def _get_element_name_string(self):
     if is_cclass(self.element):
         return f"'{self.element.name!s}'"
     elif is_clink(self.element):
         return f"link from '{self.element.source!s}' to '{self.element.target!s}'"
     elif is_cassociation(self.element):
         return f"association from '{self.element.source!s}' to '{self.element.target!s}'"
     raise CException(f"unexpected element type: {self.element!r}")
예제 #4
0
 def render_links(self, context, obj, obj_list):
     for classifier in obj.classifier.class_path:
         for association in classifier.associations:
             links = [l for l in obj.links if l.association == association]
             for link in links:
                 if link in context.excluded_links:
                     continue
                 source = link.source
                 if is_cclass(source):
                     source = source.class_object
                 target = link.target
                 if is_cclass(target):
                     target = target.class_object
                 if source != obj:
                     # only render links outgoing from this object
                     continue
                 if link not in context.visited_links:
                     context.visited_links.add(link)
                     if target in obj_list:
                         self.render_link(context, link)
예제 #5
0
 def render_objects(self, context, objects):
     obj_list = []
     for obj in objects:
         if is_cclass(obj):
             # use class objects and not classes in this renderer
             obj_list.extend([obj.class_object_])
         elif is_cobject(obj):
             obj_list.extend([obj])
         else:
             raise CException(
                 f"'{obj!s}' handed to object renderer is no an object or class'"
             )
     for obj in obj_list:
         self.render_object_specification(context, obj)
     for obj in obj_list:
         self.render_links(context, obj, obj_list)
예제 #6
0
    def get_connected_elements(self, **kwargs):
        """Get all elements this element is connected to.

        Args:
            **kwargs: Configuration parameters for the method

        Returns:
            List[CBundlable]: List of connected elements.

        Per default associations and inheritance relations are included.
        Use the following ``**kwargs`` to specify which connections are included.

        - ``add_bundles`` (bool):
            Default value: False. If set to True, relations to
            bundles are included in the returned list.
        - ``process_bundles`` (bool):
            Default value: False. If set to True, elements in
            connected bundles will be processed and all elements in the bundle will be
            added recursively (i.e. their connections will be processed, too) to the returned list.
        - ``stop_elements_inclusive`` (list of CNamedElements):
            Default value: []. If set, searching will be
            stopped whenever an element on the list in encountered. The stop element will be added to the result.
        - ``stop_elements_exclusive`` (list of CNamedElements):
            Default value: []. If set, searching will be
            stopped whenever an element on the list in encountered. The stop element will not be added to the result.
        - ``add_stereotypes`` (bool):
            Default value: False. If set to True, relations to stereotypes are included
            in the returned list. The option is only applicable on :py:class:`.CMetaclass`,
            :py:class:`.CBundle`, or :py:class:`.CStereotype`.
        - ``process_stereotypes`` (bool):
            Default value: False. If set to True, relations to stereotypes will be
            processed and all elements connected to the stereotype will be added recursively
            (i.e. their connections will be processed, too) to the returned list.
            The option is only applicable on :py:class:`.CMetaclass`,
            :py:class:`.CBundle`, or :py:class:`.CStereotype`.
        - ``add_associations`` (bool):
            Default value: False. If set to True, relations to associations
            (i.e., the association objects) are included
            in the returned list.
            The option is only applicable on :py:class:`.CMetaclass`,
            :py:class:`.CClass`, or :py:class:`.CAssociation`.
        - ``add_links`` (bool):
            Default value: False. If set to True, relations to links
            (i.e., the link objects) are included
            in the returned list. The option is only applicable on :py:class:`.CObject` and  :py:class:`CLink`.
        """
        context = ConnectedElementsContext()

        allowed_keyword_args = [
            "add_bundles", "process_bundles", "stop_elements_inclusive",
            "stop_elements_exclusive"
        ]
        if is_cmetaclass(self) or is_cbundle(self) or is_cstereotype(self):
            allowed_keyword_args = ["add_stereotypes", "process_stereotypes"
                                    ] + allowed_keyword_args
        if is_cmetaclass(self) or is_cclass(self) or is_cassociation(self):
            allowed_keyword_args = ["add_associations"] + allowed_keyword_args
        if is_cobject(self) or is_clink(self):
            allowed_keyword_args = ["add_links"] + allowed_keyword_args

        set_keyword_args(context, allowed_keyword_args, **kwargs)

        if self in context.stop_elements_exclusive:
            return []
        context.elements.append(self)
        self.compute_connected_(context)
        if not context.add_bundles:
            context.elements = [
                elt for elt in context.elements if not is_cbundle(elt)
            ]
        if not context.add_stereotypes:
            context.elements = [
                elt for elt in context.elements if not is_cstereotype(elt)
            ]
        if not context.add_associations:
            context.elements = [
                elt for elt in context.elements if not is_cassociation(elt)
            ]
        if not context.add_links:
            context.elements = [
                elt for elt in context.elements if not is_clink(elt)
            ]
        return context.elements