From 6dd02963874c5361892a1e89e00d7512d0401bb8 Mon Sep 17 00:00:00 2001 From: Escande Guillaume Date: Mon, 1 Jul 2024 11:47:49 +0200 Subject: [PATCH] [459] Correct text imported in documentation Bug: https://github.com/eclipse-syson/syson/issues/459 Signed-off-by: Guillaume Escande --- CHANGELOG.adoc | 1 + .../syson/sysml/parser/AstObjectParser.java | 26 ++++++------- .../syson/sysml/ASTTransformerTest.java | 38 +++++++++++++++++++ 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 3e1d79c07..121c4052a 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -60,6 +60,7 @@ A reset of the database is needed. - https://github.com/eclipse-syson/syson/issues/364[#364] [export] Fix names used during export in FeatureChainExpression - https://github.com/eclipse-syson/syson/issues/363[#363] [export] Fix the first part of the InvocationExpression during export - https://github.com/eclipse-syson/syson/issues/341[#341] [export] Fix missing element names in the expressions during export +- https://github.com/eclipse-syson/syson/issues/459[#459] [import] Fix documentation import to remove /* */ around texts === Improvements diff --git a/backend/application/syson-sysml-import/src/main/java/org/eclipse/syson/sysml/parser/AstObjectParser.java b/backend/application/syson-sysml-import/src/main/java/org/eclipse/syson/sysml/parser/AstObjectParser.java index 85877e28b..ddf6c5abd 100644 --- a/backend/application/syson-sysml-import/src/main/java/org/eclipse/syson/sysml/parser/AstObjectParser.java +++ b/backend/application/syson-sysml-import/src/main/java/org/eclipse/syson/sysml/parser/AstObjectParser.java @@ -38,7 +38,7 @@ public class AstObjectParser { private static final Logger LOGGER = LoggerFactory.getLogger(AstObjectParser.class); - + public void setObjectAttribute(final EObject eObject, final JsonNode astJson) { for (final EAttribute attribute : eObject.eClass().getEAllAttributes()) { if (attribute.isDerived() || attribute.isUnsettable()) { @@ -72,9 +72,12 @@ public void setObjectAttribute(final EObject eObject, final JsonNode astJson) { eObject.eSet(attribute, astJson.get(mappedName).asBoolean()); break; case "EString": - final String name = AstConstant.asCleanedText(astJson.get(mappedName)); - if (!name.equals("null")) { - eObject.eSet(attribute, name); + String textContent = AstConstant.asCleanedText(astJson.get(mappedName)); + if (attribute.equals(SysmlPackage.eINSTANCE.getComment_Body())) { + textContent = textContent.replaceFirst("^/\\*", "").replaceFirst("\\*/", "").trim(); + } + if (!textContent.equals("null")) { + eObject.eSet(attribute, textContent); } break; case "FeatureDirectionKind": @@ -93,8 +96,7 @@ public void setObjectAttribute(final EObject eObject, final JsonNode astJson) { public EObject createObject(final JsonNode astJson) { String type = astJson.findValue(AstConstant.TYPE_CONST).textValue(); - - + if (type.equals("MembershipReference")) { type = "Membership"; } @@ -119,8 +121,7 @@ public EObject createObject(final JsonNode astJson) { if (type.equals("MembershipReference")) { type = "Membership"; } - - + if (type.equals("NamespaceReference")) { type = "Namespace"; } @@ -136,11 +137,10 @@ public EObject createObject(final JsonNode astJson) { } } } - - + final EClassifier classif = SysmlPackage.eINSTANCE.getEClassifier(type); final EClassImpl eclassImpl = (EClassImpl) classif; - + if (classif == null) { return null; } else { @@ -152,9 +152,7 @@ private String computeAttribute(final EObject eObject, final String attributeNam String computedAttributeName = attributeName; if (eObject instanceof LiteralInteger && "value".equals(attributeName)) { computedAttributeName = "literal"; - } + } return computedAttributeName; } } - - diff --git a/backend/application/syson-sysml-import/src/test/java/org/eclipse/syson/sysml/ASTTransformerTest.java b/backend/application/syson-sysml-import/src/test/java/org/eclipse/syson/sysml/ASTTransformerTest.java index b62e03ea4..f8f207e5a 100644 --- a/backend/application/syson-sysml-import/src/test/java/org/eclipse/syson/sysml/ASTTransformerTest.java +++ b/backend/application/syson-sysml-import/src/test/java/org/eclipse/syson/sysml/ASTTransformerTest.java @@ -454,6 +454,44 @@ void convertImportTest() { assertEquals(p12, p211.getOwnedSubclassification().get(0).getSuperclassifier()); } + /** + * Test Containement reference + */ + @Test + void convertDocumentationTest() { + ASTTransformer transformer = new ASTTransformer(); + String fileContent = """ + { + "$type": "Namespace", + "children": [ + { + "$type": "OwningMembership", + "target": { + "$type": "Documentation", + "body": "/* TEST */" + } + } + ] + } + """; + Resource result = transformer.convertResource(new ByteArrayInputStream(fileContent.getBytes()), new ResourceSetImpl()); + + var content = result.getContents(); + assertEquals(1, content.size()); + EObject object = content.get(0); + assertInstanceOf(Namespace.class, object); + + Namespace namespace = (Namespace) object; + assertEquals(1, namespace.getOwnedElement().size()); + assertNotNull(namespace.getOwnedRelationship().get(0).getOwnedElement()); + assertEquals(1, namespace.getMember().size()); + EObject documentationObject = namespace.getMember().get(0); + assertInstanceOf(Documentation.class, documentationObject); + + assertEquals("TEST", ((Documentation) documentationObject).getBody()); + } + + /** * Test convertAssignmentTEst */