Ejemplo n.º 1
0
    def delete(self):
        """Deletes this association. Removes the association from all classifiers and links. Removes it from
        all stereotypes, too.  Calls ``delete()`` on superclass.

        Returns:
            None.

        """
        if self.is_deleted:
            return
        if is_cmetaclass(self.source):
            all_instances = self.source.all_classes
        elif is_cstereotype(self.source):
            all_instances = self.source.all_extended_instances
        else:
            all_instances = self.source.all_objects
        for instance in all_instances:
            for link in instance.links:
                link.delete()
        self.source.associations_.remove(self)
        if self.source != self.target:
            self.target.associations_.remove(self)
        for s in self.stereotypes_holder.stereotypes:
            s.extended_.remove(self)
        self.stereotypes_holder.stereotypes_ = []
        super().delete()
Ejemplo n.º 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))
 def render_classifier_specification(self, context, cl):
     stereotype_string = ""
     if is_cstereotype(cl):
         stereotype_string = self.render_stereotypes_string("stereotype")
     if is_cmetaclass(cl):
         stereotype_string = self.render_stereotypes_string("metaclass")
     if len(stereotype_string) > 0:
         stereotype_string = " " + stereotype_string + " "
     name_label = '"' + 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))
 def render_extended_relations(self, context, stereotype, class_list):
     if not context.render_extended_relations:
         return
     for extended in stereotype.extended:
         if is_cmetaclass(extended):
             if context.included_extended_classes:
                 if extended not in context.included_extended_classes:
                     continue
             if extended in context.excluded_extended_classes:
                 continue
             if extended in class_list:
                 context.add_line(
                     self.get_node_id(context, stereotype) + " --> " +
                     self.get_node_id(context, extended) + ': "' +
                     self.render_stereotypes_string("extended") + '"')
Ejemplo n.º 5
0
    def delete(self):
        """Deletes this association. Removes the association from all classifiers, links, and derived associations.
        Removes it from all stereotypes, too. Removes it from associations it is derived from.
        Calls ``delete()`` on superclass.

        Returns:
            None.

        """
        if self.is_deleted:
            return
        if is_cmetaclass(self.source):
            all_instances = self.source.all_classes
        elif is_cstereotype(self.source):
            all_instances = self.source.all_extended_instances
        else:
            all_instances = self.source.all_objects
        for instance in all_instances:
            for link in instance.links:
                link.delete()
        self.source.associations_.remove(self)
        if self.source != self.target:
            self.target.associations_.remove(self)
        for s in self.stereotypes_holder.stereotypes:
            s.extended_.remove(self)
        self.stereotypes_holder.stereotypes_ = []
        for si in self.stereotype_instances:
            si.extended_instances_.remove(self)
        self.stereotype_instances_holder.stereotypes_ = []
        if self.derived_from_ is not None:
            self.derived_from_.derived_associations_.remove(self)
            self.derived_from_ = None
        if self.derived_associations_:
            for a in self.derived_associations_:
                a.derived_from_ = None
            self.derived_associations_ = []
        super().delete()
Ejemplo n.º 6
0
 def is_metaclass_association_(self):
     if is_cmetaclass(self.source):
         return True
     return False
Ejemplo n.º 7
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