Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MinimalModelHelper should tries to initialize unchangeable attributes #65

Open
wilbert-alberts opened this issue Feb 27, 2015 · 0 comments

Comments

@wilbert-alberts
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant