Skip to content

Commit 60c23eb

Browse files
adaussyAxelRICHARD
authored andcommitted
[2034] Fix textual import to be able to annotate relationships
Bug: #2034 Signed-off-by: Arthur Daussy <arthur.daussy@obeo.fr>
1 parent 100ea1c commit 60c23eb

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ For example `ViewUsage` elements are no longer rendered in _parts_ compartments.
4545
- 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.
4646
- https://github.com/eclipse-syson/syson/issues/1998[#1998] [metamodel] Missing implicit TypeFeaturing.
4747
- https://github.com/eclipse-syson/syson/issues/2023[#2023] [diagrans] On diagrams, `ConnectionDefinition` graphical nodes are now correctly labelled as `«connection def»`.
48+
- https://github.com/eclipse-syson/syson/issues/2034[#2034] [import] Fix textual import to be able to annotate `Relationships`.
4849

4950
=== Improvements
5051

backend/application/syson-application/src/test/java/org/eclipse/syson/application/imports/ImportSysMLModelTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import org.eclipse.syson.sysml.LiteralRational;
6262
import org.eclipse.syson.sysml.LiteralString;
6363
import org.eclipse.syson.sysml.Membership;
64+
import org.eclipse.syson.sysml.MembershipExpose;
6465
import org.eclipse.syson.sysml.MetadataAccessExpression;
6566
import org.eclipse.syson.sysml.MetadataDefinition;
6667
import org.eclipse.syson.sysml.MetadataUsage;
@@ -181,6 +182,29 @@ public void unnamedRedefinedReferenceFeature() throws IOException {
181182
}).check(input);
182183
}
183184

185+
@DisplayName("GIVEN an MetadataUsage annotating a ExposeMembership, WHEN importing the model, THEN the Annotation holding the MetadataUsage should be stored in ownedRelationships.")
186+
@Test
187+
public void metadataUsageOnExposeMembership() throws IOException {
188+
var input = """
189+
package Test {
190+
metadata def MyAnnotation;
191+
192+
item def MyItem;
193+
194+
view MyView {
195+
expose MyItem { @MyAnnotation; }
196+
}
197+
198+
item def MyItem2;
199+
}
200+
""";
201+
this.checker.checkImportedModel(resource -> {
202+
List<MembershipExpose> membershipExposes = EMFUtils.allContainedObjectOfType(resource, MembershipExpose.class).toList();
203+
assertThat(membershipExposes).hasSize(1);
204+
assertThat(membershipExposes.get(0).getOwnedRelationship()).hasSize(1);
205+
}).check(input);
206+
}
207+
184208
@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.")
185209
@Test
186210
public void namedRedefinedReferenceFeature() throws IOException {

backend/application/syson-sysml-import/src/main/java/org/eclipse/syson/sysml/parser/translation/EReferenceComputer.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024 Obeo.
2+
* Copyright (c) 2024, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -23,6 +23,7 @@
2323
import org.eclipse.emf.ecore.EClass;
2424
import org.eclipse.emf.ecore.EObject;
2525
import org.eclipse.emf.ecore.EReference;
26+
import org.eclipse.syson.sysml.Relationship;
2627
import org.eclipse.syson.sysml.SysmlPackage;
2728
import org.slf4j.Logger;
2829
import org.slf4j.LoggerFactory;
@@ -73,7 +74,11 @@ public Optional<EReference> getContainmentReference(EObject owner, EClass target
7374
*/
7475

7576
if (references.equals(REL_CONTAINEMTS_REF)) {
76-
if (owner.eContainingFeature() == SysmlPackage.eINSTANCE.getRelationship_OwnedRelatedElement()) {
77+
// Case where the previously described pattern is not correct.
78+
// Here we have a Relationship holding a Relationship in "ownedRelationship"
79+
if (owner instanceof Relationship && SysmlPackage.eINSTANCE.getAnnotation().isSuperTypeOf(targetEClass)) {
80+
ref = Optional.of(SysmlPackage.eINSTANCE.getElement_OwnedRelationship());
81+
} else if (owner.eContainingFeature() == SysmlPackage.eINSTANCE.getRelationship_OwnedRelatedElement()) {
7782
ref = Optional.of(SysmlPackage.eINSTANCE.getElement_OwnedRelationship());
7883
} else {
7984
ref = Optional.of(SysmlPackage.eINSTANCE.getRelationship_OwnedRelatedElement());

doc/content/modules/user-manual/pages/release-notes/2026.3.0.adoc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ part system {
6363
}
6464
```
6565

66+
** Fix the textual import so `Relationships` can be annotated.
67+
Such as in :
68+
69+
```
70+
package Test {
71+
metadata def MyAnnotation;
72+
73+
item def MyItem;
74+
75+
view MyView {
76+
expose MyItem { @MyAnnotation; } // The MembershipExpose is annotated with MyAnnotation
77+
}
78+
79+
item def MyItem2;
80+
}
81+
```
82+
6683
* In _Explorer_ view:
6784

6885
** 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.

0 commit comments

Comments
 (0)