Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » eIsSet prevents copying (setting) of attribute when default is set
icon3.gif  eIsSet prevents copying (setting) of attribute when default is set [message #1742486] Fri, 02 September 2016 11:37 Go to next message
Andreas Weinberger is currently offline Andreas WeinbergerFriend
Messages: 2
Registered: September 2016
Junior Member
Hey guys,

while using the EcoreUtil.Copier in our project we encountered an issue. The scenario is the
following:
When a dialog is opened a model instance is copied to use it as edit clone. After 'apply' the
instance is copied back to the original. When using a default value for a boolean attribute
in this model instance a problem came up that it would only be possible to set the non-default
value to this attribute. When setting it to the default value and 'applying' the changes and opening
the dialog again, it showed the old value.
After debugging it got clear that the problem was the copying of the model instance. The Copier skips
values where eIsSet is false. It turns out that this returns false because the new value is equals the
default. So when copying something to an instance that has the non-default value set, this value
is not changed by the Copier (because eIsSet doesn't check the target but the source).


Attachment notes:

  1. xcore model class example
  2. Compiled code snippet of example
  3. Custom copier
  4. EcoreUtil$Copier

class A {
  Boolean value = 'false'
}

private static class EditableCopier extends EcoreUtil.Copier {
  ...
  for (int i = 0, size = eClass.getFeatureCount(); i < size; ++i) {
    copyAttribute((EAttribute) eStructuralFeature, source, target);
  }
  ...
}

protected void copyAttribute(EAttribute eAttribute, EObject eObject, EObject copyEObject) {
  if (eObject.eIsSet(eAttribute)) {...}
}

public boolean eIsSet(int featureID) {
  ...
  return VALUE_EDEFAULT == null ? value != null : !VALUE_EDEFAULT.equals(value);
  ...
}


My question is, if someone could explain to me why it works this way? I'm currently using version
2.10. Maybe this behaviour was changed already? Maybe there is a reason to have it this way? Shouldn't it
work different because it is a copy method?
I solved the issue by overwriting the copy method and using eUnset. Now I'm just interested in the background
of this.

I hope you could understand me and can shed some light in this issue :)
Re: eIsSet prevents copying (setting) of attribute when default is set [message #1742523 is a reply to message #1742486] Fri, 02 September 2016 17:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Andreas,

The copier assumes it's the one doing the copying and that the targets are the ones that it created, all in their default initial ground state. So it would normally be expected that the targets have eIsSet false for all attributes and that all containments and references are empty and are being populated by the copying process. Also, with unsettable features, it's important to preserve the unset state, so no feature that has eIsSet false should generally be processed.

Your use case might be bettered handled by a change recorder that can undo all the changes you made. E.g., you might attach it when you start a dialog and if the user hits cancel, undo all the changes. Or you might record what's changed to the copy, and apply those to the original...


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: eIsSet prevents copying (setting) of attribute when default is set [message #1742559 is a reply to message #1742523] Mon, 05 September 2016 07:09 Go to previous message
Andreas Weinberger is currently offline Andreas WeinbergerFriend
Messages: 2
Registered: September 2016
Junior Member
Hi Ed,

thank you very much for your quick reply! I think it answers my questions!
Previous Topic:news.eclipse.org is shutting down.
Next Topic:[CDO] Cross model references
Goto Forum:
  


Current Time: Tue Apr 16 22:19:35 GMT 2024

Powered by FUDForum. Page generated in 6.73467 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top