Skip to content

Commit

Permalink
Add support for .eContents (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
agarciadom committed Oct 9, 2022
1 parent 9101397 commit d4a53f2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
*******************************************************************************/
package org.eclipse.epsilon.emc.magicdraw.remote;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.epsilon.emc.magicdraw.modelapi.GetFeatureValueRequest;
import org.eclipse.epsilon.emc.magicdraw.modelapi.ModelElement;
import org.eclipse.epsilon.emc.magicdraw.modelapi.Value;
import org.eclipse.epsilon.emc.magicdraw.modelapi.Value.ValueCase;
import org.eclipse.epsilon.eol.exceptions.EolRuntimeException;
Expand Down Expand Up @@ -64,10 +68,18 @@ protected Object decodeValue(Value response) {
case SHORTVALUES:
case BYTEVALUES:
case STRINGVALUES:
case REFERENCEVALUES:
case ENUMERATIONVALUES:
throw new IllegalArgumentException("Server should only send proxy lists for many-valued features");

case REFERENCEVALUES: {
// NOTE: should be used solely for .eContents and read-only lists - modifiable many-valued features should use proxy lists
List<MDModelElement> elems = new ArrayList<>(response.getReferenceValues().getValuesCount());
for (ModelElement e : response.getReferenceValues().getValuesList()) {
elems.add(new MDModelElement(model, e));
}
return elems;
}

case PROXYLIST: return new MDProxyList(model, response.getProxyList());

case NOTDEFINED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ public void getFeatureValue(GetFeatureValueRequest request, StreamObserver<Value
}
break;
}
case "eContents": {
ModelElementCollection.Builder coll = ModelElementCollection.newBuilder();
for (EObject child : mdObject.eContents()) {
coll.addValues(encoder.encode(child));
}
vBuilder.setReferenceValues(coll);
break;
}
default:
vBuilder.setNotDefined(true);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,14 @@ public void cannotSetNameOfFeature() throws Exception {
assertThrows(EolInternalException.class, () -> module.execute());
}

@Test
public void eContents() throws Exception {
EolModule module = createEOLModule();

module.parse("return Class.all.selectOne(c|c.name = 'Animal').eContents.size;");
assertEquals("The size of the contents of the Animal class should be 5", 5, module.execute());
}

private void assumeTypeExists(String typeName) {
try {
m.getAllOfKind(typeName);
Expand Down

0 comments on commit d4a53f2

Please sign in to comment.