Skip to content

Commit cfb999d

Browse files
adaussyAxelRICHARD
authored andcommitted
[1002] Fix Feature labels using an initial FeatureValue relationship
Bug: #1002 Signed-off-by: Arthur Daussy <arthur.daussy@obeo.fr>
1 parent 439a4d6 commit cfb999d

File tree

6 files changed

+75
-6
lines changed

6 files changed

+75
-6
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ New default names now includes a number, this number corresponding to the count
2727
They are now properly downloaded.
2828
Export to textual SysMLv2 is not fully implemented yet so there are still unhandled cases.
2929
- https://github.com/eclipse-syson/syson/issues/998[#998] Fix `Port Usage` labels in diagrams.
30+
- https://github.com/eclipse-syson/syson/issues/1002[#1002] Invalid label for Feature (e.g.: `Attribute Usage`) when the `Feature Value` aims to define "initial" value.
3031

3132
=== Improvements
3233

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import org.eclipse.sirius.web.application.editingcontext.services.api.IEditingDomainFactory;
1818
import org.eclipse.syson.AbstractIntegrationTests;
19+
import org.eclipse.syson.application.configuration.SysMLEditingContextProcessor;
1920
import org.eclipse.syson.application.export.checker.SysmlImportExportChecker;
2021
import org.eclipse.syson.sysml.export.SysMLv2DocumentExporter;
2122
import org.eclipse.syson.sysml.upload.SysMLExternalResourceLoaderService;
@@ -44,11 +45,15 @@ public class ImportExportTests extends AbstractIntegrationTests {
4445
@Autowired
4546
private SysMLv2DocumentExporter exporter;
4647

48+
@Autowired
49+
private SysMLEditingContextProcessor sysMLEditingContextProcessor;
50+
51+
4752
private SysmlImportExportChecker checker;
4853

4954
@BeforeEach
5055
public void setUp() {
51-
this.checker = new SysmlImportExportChecker(this.sysmlLoader, this.editingDomainFactory, this.exporter);
56+
this.checker = new SysmlImportExportChecker(this.sysmlLoader, this.editingDomainFactory, this.exporter, this.sysMLEditingContextProcessor);
5257
}
5358

5459
/**
@@ -157,6 +162,27 @@ public void checkImportPort() throws IOException {
157162
this.checker.check(input, input);
158163
}
159164

165+
/**
166+
* Test import/export of AttributeUsages with FeatureValue with different combination of default or initial value.
167+
*
168+
* @throws IOException
169+
*/
170+
@DisplayName("Given a model with AttributeUsages with default and initial value, when importing and exporting the model, then the exported text file should be the same as the imported one.")
171+
@Test
172+
public void checkScalarValueAttribute() throws IOException {
173+
var input = """
174+
package Occurrences {
175+
private import ScalarValues::*;
176+
occurrence def Occurrence1 {
177+
attribute a : Integer;
178+
attribute b : Integer default = 1;
179+
attribute c : Integer = 1;
180+
attribute d : Integer := 3;
181+
}
182+
}""";
183+
this.checker.check(input, input);
184+
}
185+
160186
/**
161187
* Test import/export on test file ImportTest.sysml.
162188
*

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

Lines changed: 12 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, 2025 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
@@ -18,6 +18,7 @@
1818
import java.io.ByteArrayInputStream;
1919
import java.io.IOException;
2020
import java.util.List;
21+
import java.util.Map;
2122
import java.util.Objects;
2223
import java.util.Optional;
2324
import java.util.UUID;
@@ -26,8 +27,10 @@
2627
import org.eclipse.emf.ecore.resource.Resource;
2728
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
2829
import org.eclipse.sirius.components.events.ICause;
30+
import org.eclipse.sirius.web.application.editingcontext.EditingContext;
2931
import org.eclipse.sirius.web.application.editingcontext.services.api.IEditingDomainFactory;
3032
import org.eclipse.sirius.web.domain.boundedcontexts.project.Project;
33+
import org.eclipse.syson.application.configuration.SysMLEditingContextProcessor;
3134
import org.eclipse.syson.sysml.export.SysMLv2DocumentExporter;
3235
import org.eclipse.syson.sysml.upload.SysMLExternalResourceLoaderService;
3336
import org.springframework.http.MediaType;
@@ -45,8 +48,13 @@ public class SysmlImportExportChecker {
4548

4649
private final SysMLv2DocumentExporter exporter;
4750

48-
public SysmlImportExportChecker(SysMLExternalResourceLoaderService sysmlLoader, IEditingDomainFactory editingDomainFactory, SysMLv2DocumentExporter exporter) {
51+
private final SysMLEditingContextProcessor sysMLEditingContextProcessor;
52+
53+
54+
55+
public SysmlImportExportChecker(SysMLExternalResourceLoaderService sysmlLoader, IEditingDomainFactory editingDomainFactory, SysMLv2DocumentExporter exporter, SysMLEditingContextProcessor sysMLEditingContextProcessor) {
4956
super();
57+
this.sysMLEditingContextProcessor = Objects.requireNonNull(sysMLEditingContextProcessor);
5058
this.sysmlLoader = Objects.requireNonNull(sysmlLoader);
5159
this.editingDomainFactory = editingDomainFactory;
5260
this.exporter = exporter;
@@ -56,6 +64,8 @@ public void check(String importedText, String expectedResult) throws IOException
5664

5765
UUID uuid = UUID.randomUUID();
5866
AdapterFactoryEditingDomain editingDomain = this.editingDomainFactory.createEditingDomain(this.createFakeProject(uuid));
67+
EditingContext editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain, Map.of(), List.of());
68+
this.sysMLEditingContextProcessor.preProcess(editingContext);
5969

6070
try (var inputStream = new ByteArrayInputStream(importedText.getBytes())) {
6171
Optional<Resource> optLoadedResources = this.sysmlLoader.getResource(inputStream, this.createFakeURI(uuid), editingDomain.getResourceSet(), false);

backend/services/syson-services/src/main/java/org/eclipse/syson/services/LabelService.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023, 2024 Obeo.
2+
* Copyright (c) 2023, 2025 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
@@ -555,13 +555,24 @@ protected String getValueLabel(Usage usage) {
555555
}
556556
label
557557
.append(LabelConstants.SPACE)
558-
.append(LabelConstants.EQUAL)
558+
.append(getFeatureValueRelationshipSymbol(featureValue.get()))
559559
.append(LabelConstants.SPACE)
560560
.append(valueAsString);
561561
}
562562
return label.toString();
563563
}
564564

565+
private String getFeatureValueRelationshipSymbol(FeatureValue featureValueMembership) {
566+
final String affectationSymbole;
567+
568+
if (featureValueMembership.isIsInitial()) {
569+
affectationSymbole = ":=";
570+
} else {
571+
affectationSymbole = LabelConstants.EQUAL;
572+
}
573+
return affectationSymbole;
574+
}
575+
565576
/**
566577
* Get the value of the given {@link Expression} as a string.
567578
*

backend/views/syson-diagram-common-view/src/test/java/org/eclipse/syson/diagram/common/view/services/ViewLabelServiceTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024 Obeo.
2+
* Copyright (c) 2024, 2025 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
@@ -84,6 +84,26 @@ void testItemCompartmentLabelWithNameAndShortName() {
8484
this.viewLabelService.getCompartmentItemLabel(attributeUsage));
8585
}
8686

87+
@DisplayName("Given a FeatureValue to an attribute, when it is an initial FeatureValue relationship, then the label should use the symbole ':=' instead of '='")
88+
@Test
89+
public void testInitalFeatureValueSymboleLabel() {
90+
AttributeUsage attributeUsage = SysmlFactory.eINSTANCE.createAttributeUsage();
91+
attributeUsage.setDeclaredName(ATTRIBUTE_USAGE_NAME);
92+
93+
LiteralInteger literal = SysmlFactory.eINSTANCE.createLiteralInteger();
94+
literal.setValue(1);
95+
FeatureValue featureValue = SysmlFactory.eINSTANCE.createFeatureValue();
96+
featureValue.getOwnedRelatedElement().add(literal);
97+
attributeUsage.getOwnedRelationship().add(featureValue);
98+
99+
assertEquals("myAttributeUsage = 1", this.viewLabelService.getCompartmentItemLabel(attributeUsage));
100+
101+
featureValue.setIsInitial(true);
102+
103+
assertEquals("myAttributeUsage := 1", this.viewLabelService.getCompartmentItemLabel(attributeUsage));
104+
105+
}
106+
87107
@DisplayName("Check Attribute Usage item label with no name")
88108
@Test
89109
void testItemCompartmentLabelWithoutName() {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ For example, if a `PartDefinition` already defines 5 parts, then a new `Part` cr
3333
They are now properly downloaded.
3434
Export to textual SysMLv2 is not fully implemented yet so there are still unhandled cases.
3535
- Fix `Port Usage` labels in diagrams (feature typing was incorrectly duplicated).
36+
- In diagrams, labels of `Usages` (e.g.: `Attribute Usages`) with a `FeatureValue` relationship having an _initial_ property set to true now use the ":=" symbole instead of "=".
3637

3738
== New features
3839

0 commit comments

Comments
 (0)