eIsSet prevents copying (setting) of attribute when default is set [message #1742486] |
Fri, 02 September 2016 11:37 |
|
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:
- xcore model class example
- Compiled code snippet of example
- Custom copier
- 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 :)
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02698 seconds