eclipse-emfcloud / emfcloud-modelserver

Modelserver component
Other
40 stars 21 forks source link

PrintUtil fails with multi-valued attributes #276

Open sdybiec opened 1 month ago

sdybiec commented 1 month ago

In class 'org.eclipse.emfcloud.modelserver.example.util.PrintUtil.java', the default case in the switch statement needs to account for the case of multi-valued attributes. The current code assumes all attributes are single-valued and fails with a ClassCastException when it encounters a multi-valued attribute. Here's the updated method that I used to fix the problem:

`@Override public StringBuilder defaultCase(final EObject object) { beginObject(object.eClass().getName() + " {");

     for (EAttribute attr : object.eClass().getEAllAttributes()) {
        Object value = object.eGet(attr);
        if (value instanceof List) {
           List<?> list = (List<?>) value;
           if (!list.isEmpty()) {
              for (Object oneValue : list) {
                 print(String.format("%s: %s", attr.getName(),
                    EcoreUtil.convertToString(attr.getEAttributeType(), oneValue)));
              }
           }
        } else {
           print(String.format("%s: %s", attr.getName(),
              EcoreUtil.convertToString(attr.getEAttributeType(), object.eGet(attr))));
        }

     }

     recurse(object);

     endObject("}");

     return result;
  }`
ndoschek commented 1 month ago

Hi @sdybiec,

Thank you for pointing out the issue in the Model Server's PrintUtil and sharing your solution. We appreciate your effort and encourage you to open a pull request with your fix so it can be reviewed and integrated into the project.

Thanks again!

All my best, Nina