Skip to content

MinimalModelHelper should tries to initialize unchangeable attributes #65

@wilbert-alberts

Description

@wilbert-alberts

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions