Skip to content

Commit 49259f0

Browse files
adaussyAxelRICHARD
authored andcommitted
[1080] Improve import and resolution of ConjugatedPort
Bug: #1080 Signed-off-by: Arthur Daussy <arthur.daussy@obeo.fr>
1 parent a014eb8 commit 49259f0

File tree

6 files changed

+89
-1
lines changed

6 files changed

+89
-1
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ A new dra & drop tool is available on the diagram, allowing moving `Satisfy Requ
3232
- https://github.com/eclipse-syson/syson/issues/1030[#1030] [metamodel] `ConnectorAsUsage.getSourceFeature` and `ConnectorAsUsage.getTargetFeature` should redefine `Relationship.source` and `Relationship.target` features
3333
- https://github.com/eclipse-syson/syson/issues/1042[#1042] [import] Improve textual import of `SuccessionAsUsage` which define a new target action directly after the 'then' keyword.
3434
- https://github.com/eclipse-syson/syson/issues/1045[#1045] [export] Improve textual export by properly handle named `SuccessionAsUsage`.
35+
- https://github.com/eclipse-syson/syson/issues/1080[#1080] [import] Improve textual import and resolution against `ConjugatedPorts`.
3536

3637
=== New features
3738

backend/application/syson-application/src/test/java/org/eclipse/syson/application/export/ImportExportTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,26 @@ public void setUp() {
5555
this.checker = new SysmlImportExportChecker(this.sysmlLoader, this.editingDomainFactory, this.exporter, this.sysMLEditingContextProcessor);
5656
}
5757

58+
@Test
59+
@DisplayName("Given a model with a PortDefinition, when importing/exporting the file, then check that the conjugated port reference is kept during the process.")
60+
public void checkConjugatedPortUse() throws IOException {
61+
var input = """
62+
package Conjugated {
63+
attribute def Temp;
64+
port def TempPort {
65+
attribute temperature : Temp;
66+
}
67+
part def TempPortClassic {
68+
port tempPortClassic : TempPort;
69+
}
70+
part def TempPortConj {
71+
port tempPortConj : ~TempPort;
72+
}
73+
}""";
74+
75+
this.checker.check(input, input);
76+
}
77+
5878
@Test
5979
@DisplayName("Given a named SuccessionAsUsage, when importing and exporting the model, then the exported text file should be the same as the imported one.")
6080
public void checkNamedSuccessionAsUsageInActionDefinitionTest() throws IOException {

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
import org.eclipse.syson.AbstractIntegrationTests;
2525
import org.eclipse.syson.application.configuration.SysMLEditingContextProcessor;
2626
import org.eclipse.syson.services.UtilService;
27+
import org.eclipse.syson.sysml.ConjugatedPortDefinition;
2728
import org.eclipse.syson.sysml.Feature;
2829
import org.eclipse.syson.sysml.Membership;
30+
import org.eclipse.syson.sysml.PortDefinition;
31+
import org.eclipse.syson.sysml.PortUsage;
2932
import org.eclipse.syson.sysml.ReferenceUsage;
3033
import org.eclipse.syson.sysml.SuccessionAsUsage;
3134
import org.eclipse.syson.sysml.helper.EMFUtils;
@@ -62,6 +65,41 @@ public void setUp() {
6265
this.checker = new SysMLv2SemanticImportChecker(this.sysmlResourceLoader, this.editingDomainFactory, this.sysMLEditingContextProcessor);
6366
}
6467

68+
@Test
69+
@DisplayName("Given a model with PortDefinitions, when importing the model, then a conjugated port is create for each conjugated ports")
70+
public void checkConjugatedPortCreation() throws IOException {
71+
var input = """
72+
package Conjugated {
73+
attribute def Temp;
74+
port def TempPort {
75+
attribute temperature : Temp;
76+
}
77+
part def TempPortClassic {
78+
port tempPortClassic : TempPort;
79+
}
80+
part def TempPortConj {
81+
port tempPortConj : ~TempPort;
82+
}
83+
}""";
84+
85+
86+
this.checker.checkImportedModel(resource -> {
87+
PortDefinition tempPort = EMFUtils.allContainedObjectOfType(resource, PortDefinition.class)
88+
.filter(pod -> "TempPort".equals(pod.getDeclaredName()))
89+
.findFirst().get();
90+
91+
ConjugatedPortDefinition conjugatedPortDefinition = tempPort.getConjugatedPortDefinition();
92+
assertThat(conjugatedPortDefinition).isNotNull();
93+
94+
PortUsage tempPortConj = EMFUtils.allContainedObjectOfType(resource, PortUsage.class)
95+
.filter(pou -> "tempPortConj".equals(pou.getDeclaredName()))
96+
.findFirst().get();
97+
98+
assertThat(tempPortConj.getType()).hasSize(1).allMatch(e -> e == conjugatedPortDefinition);
99+
100+
}).check(input);
101+
}
102+
65103
@Test
66104
@DisplayName("Given a SuccessionAsUsage using the syntax that create a new target action, when importing and exporting the model, then the source and target should be correctly computed.")
67105
public void checkSuccessionToDefinedActionSourceTest() throws IOException {

backend/application/syson-sysml-import/src/main/java/org/eclipse/syson/sysml/ASTTransformer.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public Resource convertResource(final InputStream input, final ResourceSet resou
9191
private void preResolvingFixingPhase(List<EObject> rootSysmlObjects) {
9292
for (EObject root : rootSysmlObjects) {
9393
this.fixSuccessionUsageImplicitSource(root);
94+
this.fixConjugatedPorts(root);
9495
}
9596
}
9697

@@ -107,6 +108,31 @@ private void fixSuccessionUsageImplicitSource(EObject root) {
107108
this.fixImplicitTarget(succesionAsUsage);
108109
}
109110

111+
/**
112+
* Add all missing conjugate ports on PortDefinitions.
113+
*
114+
* @param root
115+
* a root element
116+
*/
117+
private void fixConjugatedPorts(EObject root) {
118+
List<PortDefinition> portDefinitions = EMFUtils.allContainedObjectOfType(root, PortDefinition.class).toList();
119+
120+
for (PortDefinition portDef : portDefinitions) {
121+
if (portDef.getConjugatedPortDefinition() == null) {
122+
OwningMembership owningMembership = SysmlFactory.eINSTANCE.createOwningMembership();
123+
portDef.getOwnedRelationship().add(owningMembership);
124+
// No need to set the declaredName for the ConjugatedPortDefinition here, it is always the same than its
125+
// originalPortDefinition and computed elsewhere
126+
ConjugatedPortDefinition conjugatedPortDefinition = SysmlFactory.eINSTANCE.createConjugatedPortDefinition();
127+
owningMembership.getOwnedRelatedElement().add(conjugatedPortDefinition);
128+
PortConjugation portConjugation = SysmlFactory.eINSTANCE.createPortConjugation();
129+
conjugatedPortDefinition.getOwnedRelationship().add(portConjugation);
130+
portConjugation.setConjugatedType(conjugatedPortDefinition);
131+
portConjugation.setOriginalPortDefinition(portDef);
132+
}
133+
}
134+
}
135+
110136
/**
111137
* Try to fix all {@link SuccessionAsUsage} elements contained in the given root to workaround
112138
* https://github.com/eclipse-syson/syson/issues/1042 and https://github.com/sensmetry/sysml-2ls/issues/13.

backend/application/syson-sysml-import/src/test/java/org/eclipse/syson/sysml/ASTTransformerTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,13 @@ void convertFeatureTypingTest() {
293293
PortDefinition typedPortDefinition = (PortDefinition) portDefinition;
294294
assertEquals("portDefinition", typedPortDefinition.getDeclaredName());
295295

296-
assertEquals(1, typedPortDefinition.getOwnedMember().size());
296+
assertEquals(2, typedPortDefinition.getOwnedMember().size());
297297
EObject referenceUsage = typedPortDefinition.getOwnedMember().get(0);
298298
assertInstanceOf(ReferenceUsage.class, referenceUsage);
299299
ReferenceUsage typedReferenceUsage = (ReferenceUsage) referenceUsage;
300300
assertEquals("referenceUsage", typedReferenceUsage.getDeclaredName());
301+
EObject conjugatedPortDefinition = typedPortDefinition.getOwnedMember().get(1);
302+
assertInstanceOf(ConjugatedPortDefinition.class, conjugatedPortDefinition);
301303

302304
assertEquals(1, typedReferenceUsage.getOwnedTyping().size());
303305
FeatureTyping featureTyping = typedReferenceUsage.getOwnedTyping().get(0);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ action def ActionDef1 {
7070
succession s1 first a1 then a2;
7171
}
7272
```
73+
- Improve `PortDefinition` textual import by creating the required `ConjugatedPort` during the import process.
7374

7475
== Dependency update
7576

0 commit comments

Comments
 (0)