Skip to content

Commit

Permalink
[17] Support EAnnotation.contents feature in JsonResource
Browse files Browse the repository at this point in the history
Bug: eclipse-sirius#17
Signed-off-by: Laurent Fasani <[email protected]>
  • Loading branch information
lfasani authored and sbegaudeau committed Jan 19, 2023
1 parent 0df7244 commit 9faf027
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2022 Obeo.
* Copyright (c) 2020, 2023 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -642,6 +642,13 @@ private JsonElement serializeEAnnotation(EAnnotation eAnnotation) {
object.add(IGsonConstants.REFERENCES, array);
}

// EAnnotation contents
EList<EObject> contents = eAnnotation.getContents();
if (contents != null && contents.size() > 0) {
JsonElement jsonElement = this.serializeEReference(eAnnotation, EcorePackage.eINSTANCE.getEAnnotation_Contents());
object.add(IGsonConstants.CONTENTS, jsonElement);
}

// EAnnotation details
JsonArray jsonArray = new JsonArray();
EMap<String, String> annotationDetails = eAnnotation.getDetails();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020 Obeo.
* Copyright (c) 2020, 2023 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -73,6 +73,11 @@ public interface IGsonConstants {
*/
String REFERENCES = "references"; //$NON-NLS-1$

/**
* The EAnnotation Contents attribute.
*/
String CONTENTS = "contents"; //$NON-NLS-1$

/**
* The key details EAnnotation value.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020 Obeo.
* Copyright (c) 2020, 2023 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -113,4 +113,12 @@ public void testEAnnotationsDeserializationOnLiteral() {
this.testLoad("TestLiteralAnnotation.ecore"); //$NON-NLS-1$
}

/**
* Test the EAnnotations deserialization on Literal.
*/
@Test
public void testEAnnotationsWithDataDeserialization() {
this.testLoad("TestClassAnnotationWithData.ecore"); //$NON-NLS-1$
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020 Obeo.
* Copyright (c) 2020, 2023 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -112,4 +112,12 @@ public void testEAnnotationsSerializationOnEnumeration() {
public void testEAnnotationsSerializationOnLiteral() {
this.testSave("TestLiteralAnnotation.ecore"); //$NON-NLS-1$
}

/**
* Test the EAnnotations serialization on Literal.
*/
@Test
public void testEAnnotationsWithDataSerialization() {
this.testSave("TestClassAnnotationWithData.ecore"); //$NON-NLS-1$
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="ecore" nsURI="http://www.eclipse.org/emf/2002/Ecore" nsPrefix="ecore">
<eClassifiers xsi:type="ecore:EClass" name="EClass">
<eAnnotations source="http://www.eclipse.org/uml2/2.0.0/UML">
<contents xsi:type="ecore:EPackage" name="testProfile" nsURI="http:///schemas/testProfile/_lxpeIJWqEe2_Wav1ork0Rw/2"
nsPrefix="testProfile">
<eAnnotations source="ProductVersion" references="#//EClass">
<details key="Version" value="1.0.0"/>
<details key="Comment" value=""/>
</eAnnotations>
</contents>
</eAnnotations>
</eClassifiers>
</ecore:EPackage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"json": {
"version": "1.0",
"encoding": "utf-8"
},
"ns": {
"ecore": "http://www.eclipse.org/emf/2002/Ecore"
},
"content": [
{
"eClass": "ecore:EPackage",
"data": {
"name": "ecore",
"nsURI": "http://www.eclipse.org/emf/2002/Ecore",
"nsPrefix": "ecore",
"eClassifiers": [
{
"eClass": "ecore:EClass",
"data": {
"eAnnotations": [
{
"source": "http://www.eclipse.org/uml2/2.0.0/UML",
"contents": [
{
"eClass": "ecore:EPackage",
"data": {
"eAnnotations": [
{
"source": "ProductVersion",
"references": [
"//EClass"
],
"details": [
{
"key": "Version",
"value": "1.0.0"
},
{
"key": "Comment",
"value": ""
}
]
}
],
"name": "testProfile",
"nsURI": "http:///schemas/testProfile/_lxpeIJWqEe2_Wav1ork0Rw/2",
"nsPrefix": "testProfile"
}
}
]
}
],
"name": "EClass"
}
}
]
}
}
]
}

0 comments on commit 9faf027

Please sign in to comment.