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

Fix PrintUtil for multi-valued attributes #277

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

vhemery
Copy link
Contributor

@vhemery vhemery commented Jan 9, 2025

Displays multi-valued attributes correctly.

The example plugin does not have tests, and registered models do not have mutivalued attributes.
Adding a new test module may not be relevant.
However, one can simply test this fix by executing :

package org.eclipse.emfcloud.modelserver.example.util;

import java.util.List;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.util.EcoreUtil;

public class PrintUtilTest {

   public static void main(final String[] args) {
      var ep = EcoreFactory.eINSTANCE.createEPackage();
      ep.setName("testModel");
      var ec = EcoreFactory.eINSTANCE.createEClass();
      ec.setName("TestManyAttribute");
      var att = EcoreFactory.eINSTANCE.createEAttribute();
      att.setName("values");
      att.setEType(EcorePackage.Literals.ESTRING);
      att.setUpperBound(-1);
      ec.getEStructuralFeatures().add(att);
      ep.getEClassifiers().add(ec);

      var obj = EcoreUtil.create(ec);
      EList<String> values = (EList<String>) obj.eGet(att);
      values.addAll(List.of("1", "2", "3"));
      // displays value successfully as "values: [1, 2, 3]"
      System.out.println(PrintUtil.toPrettyString(obj));
   }

}

Fixes #276

@vhemery vhemery requested a review from ndoschek January 9, 2025 10:18
@vhemery
Copy link
Contributor Author

vhemery commented Jan 9, 2025

Needs rebase after #280

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

Successfully merging this pull request may close these issues.

PrintUtil fails with multi-valued attributes
1 participant