-
Notifications
You must be signed in to change notification settings - Fork 12
Description
I have created a metamodel having a root that contains a derived, volatile, unchangeable, transient attribute.
Based on that metamodel, a concrete syntax has been defined and the corresponding parser en ui projects have been generated.
Whenever I try to create a new instance using the generated wizard, it fails due to the fact that the wizard tries to set the value of the derived attribute.
Debugging the generated code leads to this section (from the generated MinimalModelHelper):
public EObject getMinimalModel(EClass eClass, EClass[] allAvailableClasses, String name) {
if (!contains(allAvailableClasses, eClass)) {
return null;
}
EPackage ePackage = eClass.getEPackage();
if (ePackage == null) {
return null;
}
EObject root = ePackage.getEFactoryInstance().create(eClass);
List<EStructuralFeature> features = eClass.getEAllStructuralFeatures();
for (EStructuralFeature feature : features) {
if (feature instanceof EReference) {
EReference reference = (EReference) feature;
if (reference.isUnsettable()) {
continue;
}
if (!reference.isChangeable()) {
continue;
}< rest omitted >
In the highlighted iteration any reference that is unchangeable is prevented from being initialized. However, no attempt is made to prevent initialization of unchangeable attributes. This can be seen in:
} else if (feature instanceof EAttribute) {
EAttribute attribute = (EAttribute) feature;
if ("EString".equals(attribute.getEType().getName())) {
String initialValue;
if (attribute.getName().equals("name") && name != null) {
initialValue = name;
}
else {
initialValue = "some" + dca.resource.hdca.util.HdcaStringUtil.capitalize(attribute.getName());
}
Object value = root.eGet(attribute);
if (value instanceof List<?>) {
List<String> list = dca.resource.hdca.util.HdcaListUtil.castListUnchecked(value);
list.add(initialValue);
} else {
root.eSet(attribute, initialValue);
}
}
}So probably some additional guarding against initializing unchangeable is due.