Skip to content

Commit

Permalink
[459] Correct text imported in documentation
Browse files Browse the repository at this point in the history
Bug: eclipse-syson#459
Signed-off-by: Guillaume Escande <guillaume.escande@obeosoft.fr>
  • Loading branch information
GuillaumeEscande authored and AxelRICHARD committed Jul 5, 2024
1 parent a0685dc commit 6dd0296
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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":
Expand All @@ -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";
}
Expand All @@ -119,8 +121,7 @@ public EObject createObject(final JsonNode astJson) {
if (type.equals("MembershipReference")) {
type = "Membership";
}



if (type.equals("NamespaceReference")) {
type = "Namespace";
}
Expand All @@ -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 {
Expand All @@ -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;
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 6dd0296

Please sign in to comment.