Skip to content

Commit 680d163

Browse files
225: Enum values are not properly initialized when creating a new
element - Use Enumerator instead of EEnumLiteral - Add missing return statement Fixes #225 Contributed on behalf of STMicroelectronics. Signed-off-by: Camille Letavernier <cletavernier@eclipsesource.com>
1 parent 7c6d2e8 commit 680d163

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

bundles/org.eclipse.emfcloud.modelserver.common/src/org/eclipse/emfcloud/modelserver/common/patch/AbstractJsonPatchHelper.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
import org.apache.logging.log4j.Logger;
3232
import org.eclipse.emf.common.command.Command;
3333
import org.eclipse.emf.common.command.IdentityCommand;
34+
import org.eclipse.emf.common.util.Enumerator;
3435
import org.eclipse.emf.common.util.URI;
3536
import org.eclipse.emf.ecore.EAttribute;
3637
import org.eclipse.emf.ecore.EClass;
3738
import org.eclipse.emf.ecore.EClassifier;
3839
import org.eclipse.emf.ecore.EDataType;
3940
import org.eclipse.emf.ecore.EEnum;
40-
import org.eclipse.emf.ecore.EEnumLiteral;
4141
import org.eclipse.emf.ecore.EFactory;
4242
import org.eclipse.emf.ecore.EObject;
4343
import org.eclipse.emf.ecore.EReference;
@@ -392,28 +392,25 @@ protected Object getEMFValue(final String modelURI, final ResourceSet resourceSe
392392
if (feature instanceof EAttribute) {
393393
// Attributes
394394
if (feature.getEType() instanceof EEnum) {
395-
getEMFEnumValue((EEnum) feature.getEType(), value);
396-
} else {
397-
return getPrimitiveEMFValue((EAttribute) feature, value);
398-
}
399-
} else {
400-
// References
401-
JsonNode refNode = value.get(JsonConstants.REF_ATTR);
402-
JsonNode idNode = value.get(JsonConstants.ID_ATTR);
403-
if (refNode == null && idNode == null) {
404-
throw new JsonPatchException("Reference values should include a $ref or an $id attribute");
395+
return getEMFEnumValue((EEnum) feature.getEType(), value);
405396
}
406-
String objectId = refNode == null ? idNode.asText() : refNode.asText();
407-
return getEObject(modelURI, URI.createURI(objectId));
397+
return getPrimitiveEMFValue((EAttribute) feature, value);
398+
}
399+
// References
400+
JsonNode refNode = value.get(JsonConstants.REF_ATTR);
401+
JsonNode idNode = value.get(JsonConstants.ID_ATTR);
402+
if (refNode == null && idNode == null) {
403+
throw new JsonPatchException("Reference values should include a $ref or an $id attribute");
408404
}
405+
String objectId = refNode == null ? idNode.asText() : refNode.asText();
406+
return getEObject(modelURI, URI.createURI(objectId));
409407
// TODO Support custom datatypes & array-values. See
410408
// https://github.com/eclipse-emfcloud/emfcloud-modelserver/issues/162
411-
return null;
412409
}
413410

414-
protected EEnumLiteral getEMFEnumValue(final EEnum enumType, final JsonNode value) throws JsonPatchException {
411+
protected Enumerator getEMFEnumValue(final EEnum enumType, final JsonNode value) throws JsonPatchException {
415412
if (value.isTextual()) {
416-
EEnumLiteral literal = enumType.getEEnumLiteral(value.asText());
413+
Enumerator literal = enumType.getEEnumLiteral(value.asText()).getInstance();
417414
if (literal != null) {
418415
return literal;
419416
}

0 commit comments

Comments
 (0)