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

PrintUtil fails with multi-valued attributes #276

Open
sdybiec opened this issue May 11, 2024 · 1 comment · May be fixed by #277
Open

PrintUtil fails with multi-valued attributes #276

sdybiec opened this issue May 11, 2024 · 1 comment · May be fixed by #277
Labels
bug Something isn't working modelserver EMF.cloud Model Server

Comments

@sdybiec
Copy link

sdybiec commented May 11, 2024

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;
  }`
@sdybiec sdybiec added bug Something isn't working modelserver EMF.cloud Model Server labels May 11, 2024
@ndoschek
Copy link
Contributor

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

@vhemery vhemery linked a pull request Jan 9, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working modelserver EMF.cloud Model Server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants