- remove applied stereotype when extension is removed

This commit is contained in:
wrobell 2010-02-03 22:57:11 +00:00
parent be8c0fa0d6
commit 12c766d4f9
2 changed files with 38 additions and 2 deletions

View File

@ -34,8 +34,8 @@ class StereotypesAttributesTestCase(TestCase):
attr.name = 'st2_attr_1'
st2.ownedAttribute = attr
UML.model.extend_with_stereotype(factory, cls, st1)
UML.model.extend_with_stereotype(factory, cls, st2)
self.ext1 = UML.model.extend_with_stereotype(factory, cls, st1)
self.ext2 = UML.model.extend_with_stereotype(factory, cls, st2)
def tearDown(self):
del self.st1
@ -112,6 +112,27 @@ class StereotypesAttributesTestCase(TestCase):
self.assertEquals(0, len(c._compartments))
def test_deleting_extension(self):
"""Test if stereotype is removed when extension is deleteded
"""
factory = self.element_factory
c = self.create(ComponentItem, UML.Component)
c.show_stereotypes_attrs = True
st1 = self.st1
ext1 = self.ext1
UML.model.apply_stereotype(factory, c.subject, st1)
# test precondition
assert len(c._compartments) == 1
assert len(c.subject.appliedStereotype) == 1
ext1.unlink()
self.assertEquals(0, len(c.subject.appliedStereotype))
self.assertEquals(0, len(c._compartments))
def test_deleting_stereotype(self):
"""Test if stereotype is removed when stereotype is deleteded
"""

View File

@ -28,12 +28,14 @@ class SanitizerService(object):
app.register_handler(self._unlink_on_presentation_delete)
app.register_handler(self._unlink_on_stereotype_attribute_delete)
app.register_handler(self._unlink_on_stereotype_delete)
app.register_handler(self._unlink_on_extension_delete)
def shutdown(self):
self._app.unregister_handler(self._unlink_on_presentation_delete)
self._app.unregister_handler(self._unlink_on_stereotype_attribute_delete)
self._app.unregister_handler(self._unlink_on_stereotype_delete)
self._app.unregister_handler(self._unlink_on_extension_delete)
@component.adapter(UML.Presentation, IElementDeleteEvent)
@ -50,6 +52,19 @@ class SanitizerService(object):
subject.unlink()
@component.adapter(UML.Extension, IElementDeleteEvent)
def _unlink_on_extension_delete(self, ext, event):
"""
Remove applied stereotypes when extension is deleted.
"""
for end in ext.memberEnd:
st = end.type
if isinstance(st, UML.Stereotype):
instances = UML.model.find_instances(self.element_factory, st)
for obj in list(instances):
UML.model.remove_stereotype(obj.extended[0], obj.classifier[0])
@component.adapter(UML.Stereotype, IElementDeleteEvent)
def _unlink_on_stereotype_delete(self, st, event):
"""