diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index b092c6791..5c5af1d08 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -45,6 +45,7 @@ For example `ViewUsage` elements are no longer rendered in _parts_ compartments. - https://github.com/eclipse-syson/syson/issues/2026[#2026] [explorer] Fix an issue where creating a new model using the _Create a new model_ action in the _Explorer_ view was not adding the ".sysml" extension to the model name. - https://github.com/eclipse-syson/syson/issues/1998[#1998] [metamodel] Missing implicit TypeFeaturing. - https://github.com/eclipse-syson/syson/issues/2023[#2023] [diagrans] On diagrams, `ConnectionDefinition` graphical nodes are now correctly labelled as `«connection def»`. +- https://github.com/eclipse-syson/syson/issues/2034[#2034] [import] Fix textual import to be able to annotate `Relationships`. === 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 7e5a12a3d..e433fabf2 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 @@ -61,6 +61,7 @@ import org.eclipse.syson.sysml.LiteralRational; import org.eclipse.syson.sysml.LiteralString; import org.eclipse.syson.sysml.Membership; +import org.eclipse.syson.sysml.MembershipExpose; import org.eclipse.syson.sysml.MetadataAccessExpression; import org.eclipse.syson.sysml.MetadataDefinition; import org.eclipse.syson.sysml.MetadataUsage; @@ -181,6 +182,29 @@ public void unnamedRedefinedReferenceFeature() 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.") + @Test + public void metadataUsageOnExposeMembership() throws IOException { + var input = """ + package Test { + metadata def MyAnnotation; + + item def MyItem; + + view MyView { + expose MyItem { @MyAnnotation; } + } + + item def MyItem2; + } + """; + this.checker.checkImportedModel(resource -> { + List membershipExposes = EMFUtils.allContainedObjectOfType(resource, MembershipExpose.class).toList(); + assertThat(membershipExposes).hasSize(1); + assertThat(membershipExposes.get(0).getOwnedRelationship()).hasSize(1); + }).check(input); + } + @DisplayName("GIVEN a redefinition of a part with the same name as the redefined part, WHEN importing the model, THEN the redefintion's redefined feature is correctly resolved.") @Test public void namedRedefinedReferenceFeature() throws IOException { diff --git a/backend/application/syson-sysml-import/src/main/java/org/eclipse/syson/sysml/parser/translation/EReferenceComputer.java b/backend/application/syson-sysml-import/src/main/java/org/eclipse/syson/sysml/parser/translation/EReferenceComputer.java index d3076ce10..ee290c9c9 100644 --- a/backend/application/syson-sysml-import/src/main/java/org/eclipse/syson/sysml/parser/translation/EReferenceComputer.java +++ b/backend/application/syson-sysml-import/src/main/java/org/eclipse/syson/sysml/parser/translation/EReferenceComputer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2024 Obeo. + * Copyright (c) 2024, 2026 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 @@ -23,6 +23,7 @@ import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; +import org.eclipse.syson.sysml.Relationship; import org.eclipse.syson.sysml.SysmlPackage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -73,7 +74,11 @@ public Optional getContainmentReference(EObject owner, EClass target */ if (references.equals(REL_CONTAINEMTS_REF)) { - if (owner.eContainingFeature() == SysmlPackage.eINSTANCE.getRelationship_OwnedRelatedElement()) { + // Case where the previously described pattern is not correct. + // Here we have a Relationship holding a Relationship in "ownedRelationship" + if (owner instanceof Relationship && SysmlPackage.eINSTANCE.getAnnotation().isSuperTypeOf(targetEClass)) { + ref = Optional.of(SysmlPackage.eINSTANCE.getElement_OwnedRelationship()); + } else if (owner.eContainingFeature() == SysmlPackage.eINSTANCE.getRelationship_OwnedRelatedElement()) { ref = Optional.of(SysmlPackage.eINSTANCE.getElement_OwnedRelationship()); } else { ref = Optional.of(SysmlPackage.eINSTANCE.getRelationship_OwnedRelatedElement()); diff --git a/doc/content/modules/user-manual/pages/release-notes/2026.3.0.adoc b/doc/content/modules/user-manual/pages/release-notes/2026.3.0.adoc index 031289401..8eeda3a83 100644 --- a/doc/content/modules/user-manual/pages/release-notes/2026.3.0.adoc +++ b/doc/content/modules/user-manual/pages/release-notes/2026.3.0.adoc @@ -63,6 +63,23 @@ part system { } ``` +** Fix the textual import so `Relationships` can be annotated. +Such as in : + +``` +package Test { + metadata def MyAnnotation; + + item def MyItem; + + view MyView { + expose MyItem { @MyAnnotation; } // The MembershipExpose is annotated with MyAnnotation + } + + item def MyItem2; +} +``` + * In _Explorer_ view: ** Fix an issue where creating a new model using the _Create a new model_ action in the _Explorer_ view was not adding the ".sysml" extension to the model name.