Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
notifyChanged = lambda x: assert_wrap(x.kind is Kind.ADD
and x.new is a1
and x.feature.name == 'namedElements'
and x.notifier is root)
observer = EObserver(root, notifyChanged=notifyChanged)
def test_notification_add_onecall():
root = EPackage(name='test')
A = EClass('A')
o1 = ObserverCounter(root)
o2 = ObserverCounter(A)
root.eClassifiers.append(A)
assert o1.calls == 1
assert o1.kind == Kind.ADD
assert o1.feature is EPackage.eClassifiers
assert o2.calls == 1
assert o2.kind == Kind.SET
assert o2.feature is EClassifier.ePackage
def notifyChanged(self, notif):
if notif.feature is EEnum.eLiterals:
if notif.kind is Kind.ADD:
literal = notif.new
self.__setattr__(literal.name, literal)
elif notif.kind is Kind.REMOVE:
literal = notif.old
del self.__dict__[literal.name]
feature=self.feature,
kind=Kind.REMOVE_MANY))
elif sliced_elements:
self.owner.notify(Notification(old=sliced_elements[0],
feature=self.feature,
kind=Kind.REMOVE))
else:
self.check(y)
if self.is_ref:
self._update_container(y)
self._update_opposite(y, self.owner)
super().__setitem__(i, y)
kind = Kind.ADD
if is_collection and len(y) > 1:
kind = Kind.ADD_MANY
elif is_collection:
y = y[0] if y else y
self.owner.notify(Notification(new=y,
feature=self.feature,
kind=kind))
self.owner._isset.add(self.feature)
def notifyChanged(self, notif):
# We do not update in case of static metamodel (could be changed)
if getattr(self.python_class, '_staticEClass', False):
return
if notif.feature is EClass.eSuperTypes:
new_supers = self.__compute_supertypes()
self.python_class.__bases__ = new_supers
elif notif.feature is EClass.eOperations:
if notif.kind is Kind.ADD:
self.__create_fun(notif.new)
elif notif.kind is Kind.REMOVE:
delattr(self.python_class, notif.old.name)
elif notif.feature is EClass.eStructuralFeatures:
if notif.kind is Kind.ADD:
setattr(self.python_class, notif.new.name, notif.new)
elif notif.kind is Kind.ADD_MANY:
for x in notif.new:
setattr(self.python_class, x.name, x)
elif notif.kind is Kind.REMOVE:
delattr(self.python_class, notif.old.name)
elif notif.feature is EClass.name and notif.kind is Kind.SET:
self.python_class.__name__ = notif.new
self.__name__ = notif.new
def notifyChanged(self, notification):
kind = notification.kind
if notification.feature is EPackage.eClassifiers:
if kind == Kind.ADD:
new = notification.new
setattr(self, new.name, new)
elif kind == Kind.ADD_MANY:
for new in notification.new:
setattr(self, new.name, new)
elif kind == Kind.REMOVE and notification.old.eResource is None:
delattr(self, notification.old.name)
# elif kind == Kind.REMOVE_MANY:
def _set(self, value, update_opposite=True):
self.check(value)
previous_value = self._value
self._value = value
owner = self.owner
efeature = self.feature
notif = Notification(old=previous_value,
new=value,
feature=efeature,
kind=Kind.UNSET if value is None else Kind.SET)
owner.notify(notif)
owner._isset.add(efeature)
if not self.is_ref:
return
self._update_container(value, previous_value)
if not update_opposite:
return
# if there is no opposite, we set inverse relation and return
if not efeature.eOpposite:
couple = (owner, efeature)
if hasattr(value, '_inverse_rels'):
if hasattr(previous_value, '_inverse_rels'):
previous_value._inverse_rels.remove(couple)
value._inverse_rels.add(couple)
def add(self, value, update_opposite=True):
self.check(value)
if self.is_ref:
self._update_container(value)
if update_opposite:
self._update_opposite(value, self.owner)
super().add(value)
self.owner.notify(Notification(new=value,
feature=self.feature,
kind=Kind.ADD))
self.owner._isset.add(self.feature)
def notifyChanged(self, notification):
kind = notification.kind
if notification.feature is EPackage.eClassifiers:
if kind == Kind.ADD:
new = notification.new
setattr(self, new.name, new)
elif kind == Kind.ADD_MANY:
for new in notification.new:
setattr(self, new.name, new)
elif kind == Kind.REMOVE and notification.old.eResource is None:
delattr(self, notification.old.name)
# elif kind == Kind.REMOVE_MANY: