From ab8711920d40435127953629dcd558ec0047717a Mon Sep 17 00:00:00 2001 From: Axel RICHARD Date: Thu, 13 Aug 2026 13:13:11 +0200 Subject: [PATCH] [2226] Fix imported relationship annotations Bug: https://github.com/eclipse-syson/syson/issues/2226 Signed-off-by: Axel RICHARD --- CHANGELOG.adoc | 1 + .../imports/ImportSysMLModelTest.java | 6 +++++- .../parser/ContainmentReferenceHandler.java | 17 ++++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 0dddf725a5..82ed3590f9 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -46,6 +46,7 @@ It is now _Become nested Concern_ instead of _Become nested Requirement_. - https://github.com/eclipse-syson/syson/issues/2397[#2397] [metamodel] Fix the resolution of the ends of a connector so the ends declared with the `end` keyword inside a connection body are taken into account. Following KerML, where `endFeature` is defined as the owned features having `isEnd = true`, the ends owned through a plain `FeatureMembership` are now collected as well, and not only those owned through an `EndFeatureMembership`. This also fixes `relatedFeature`, `sourceFeature` and `targetFeature`, which were all empty for such connections. +- https://github.com/eclipse-syson/syson/issues/2226[#2226] [import] Fix textual import of annotations on relationships so their `annotatedElement` is set and they are returned by `Element#getOwnedAnnotation()`. === Improvements diff --git a/backend/application/syson-application/src/test/java/org/eclipse/syson/application/imports/ImportSysMLModelTest.java b/backend/application/syson-application/src/test/java/org/eclipse/syson/application/imports/ImportSysMLModelTest.java index c258edee13..082c626f92 100644 --- a/backend/application/syson-application/src/test/java/org/eclipse/syson/application/imports/ImportSysMLModelTest.java +++ b/backend/application/syson-application/src/test/java/org/eclipse/syson/application/imports/ImportSysMLModelTest.java @@ -45,6 +45,7 @@ import org.eclipse.syson.services.UtilService; import org.eclipse.syson.sysml.ActionDefinition; import org.eclipse.syson.sysml.ActionUsage; +import org.eclipse.syson.sysml.Annotation; import org.eclipse.syson.sysml.AttributeUsage; import org.eclipse.syson.sysml.BindingConnectorAsUsage; import org.eclipse.syson.sysml.ConjugatedPortDefinition; @@ -208,7 +209,7 @@ public void removeExtraBacklash() throws IOException { }).check(input); } - @DisplayName("GIVEN an MetadataUsage annotating a ExposeMembership, WHEN importing the model, THEN the Annotation holding the MetadataUsage should be stored in ownedRelationships.") + @DisplayName("GIVEN a MetadataUsage annotating an ExposeMembership, WHEN importing the model, THEN the Annotation targets and is owned by the ExposeMembership.") @Test public void metadataUsageOnExposeMembership() throws IOException { var input = """ @@ -228,6 +229,9 @@ public void metadataUsageOnExposeMembership() throws IOException { List membershipExposes = EMFUtils.allContainedObjectOfType(resource, MembershipExpose.class).toList(); assertThat(membershipExposes).hasSize(1); assertThat(membershipExposes.get(0).getOwnedRelationship()).hasSize(1); + Annotation annotation = (Annotation) membershipExposes.get(0).getOwnedRelationship().get(0); + assertThat(annotation.getAnnotatedElement()).isEqualTo(membershipExposes.get(0)); + assertThat(membershipExposes.get(0).getOwnedAnnotation()).containsExactly(annotation); }).check(input); } diff --git a/backend/application/syson-sysml-import/src/main/java/org/eclipse/syson/sysml/parser/ContainmentReferenceHandler.java b/backend/application/syson-sysml-import/src/main/java/org/eclipse/syson/sysml/parser/ContainmentReferenceHandler.java index efd05db4ad..e85b75c225 100644 --- a/backend/application/syson-sysml-import/src/main/java/org/eclipse/syson/sysml/parser/ContainmentReferenceHandler.java +++ b/backend/application/syson-sysml-import/src/main/java/org/eclipse/syson/sysml/parser/ContainmentReferenceHandler.java @@ -19,6 +19,8 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; +import org.eclipse.syson.sysml.Annotation; +import org.eclipse.syson.sysml.Element; import org.eclipse.syson.sysml.Expression; import org.eclipse.syson.sysml.Feature; import org.eclipse.syson.sysml.FeatureDirectionKind; @@ -99,6 +101,17 @@ private void setValue(final EObject eObject, EReference ref, EObject value) { } } + /** + * Adds a parsed object to its containing reference and completes containment-derived relationships. + * + * @param owner + * the object that contains the parsed object + * @param owned + * the parsed object to add + * @param referenceName + * the AST containment reference name + * @return {@code true} when the containment has been handled + */ private boolean addChildIn(final EObject owner, final EObject owned, String referenceName) { if ("operands".equals(referenceName) && owned instanceof Expression ownedExpression && owner instanceof InvocationExpression invocationExpression) { @@ -115,10 +128,12 @@ private boolean addChildIn(final EObject owner, final EObject owned, String refe featureValue.getOwnedRelatedElement().add(ownedExpression); invocationExpression.getOwnedRelationship().add(paramMembership); } else { - Optional optContainementReference = this.referenceTranslator.getContainmentReference(owner, owned.eClass(), referenceName); if (optContainementReference.isPresent()) { this.setValue(owner, optContainementReference.get(), owned); + if (owned instanceof Annotation annotation && owner instanceof Element element) { + annotation.setAnnotatedElement(element); + } } }