Skip to content

Commit b82d93d

Browse files
adaussyAxelRICHARD
authored andcommitted
[1003] Fix Feature labels using a default FeatureValue relationship
Bug: #1003 Signed-off-by: Arthur Daussy <arthur.daussy@obeo.fr>
1 parent cfb999d commit b82d93d

File tree

8 files changed

+50
-22
lines changed

8 files changed

+50
-22
lines changed

CHANGELOG.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ 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.
30+
- https://github.com/eclipse-syson/syson/issues/1002[#1002] Invalid label for `Usages` (e.g.: `Attribute Usage`) when their `Feature Value` aims to define "initial" value.
31+
- https://github.com/eclipse-syson/syson/issues/1003[#1003] Invalid label for `Usages` (e.g.: `Attribute Usage`) when their `Feature Value` aims to define "default" value.
3132

3233
=== Improvements
3334

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public class ImportExportTests extends AbstractIntegrationTests {
4848
@Autowired
4949
private SysMLEditingContextProcessor sysMLEditingContextProcessor;
5050

51-
5251
private SysmlImportExportChecker checker;
5352

5453
@BeforeEach
@@ -172,13 +171,13 @@ public void checkImportPort() throws IOException {
172171
public void checkScalarValueAttribute() throws IOException {
173172
var input = """
174173
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-
}
174+
private import ScalarValues::*;
175+
occurrence def Occurrence1 {
176+
attribute a : Integer;
177+
attribute b : Integer default = 1;
178+
attribute c : Integer = 1;
179+
attribute d : Integer := 3;
180+
}
182181
}""";
183182
this.checker.check(input, input);
184183
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ public class SysmlImportExportChecker {
5050

5151
private final SysMLEditingContextProcessor sysMLEditingContextProcessor;
5252

53-
54-
5553
public SysmlImportExportChecker(SysMLExternalResourceLoaderService sysmlLoader, IEditingDomainFactory editingDomainFactory, SysMLv2DocumentExporter exporter, SysMLEditingContextProcessor sysMLEditingContextProcessor) {
5654
super();
5755
this.sysMLEditingContextProcessor = Objects.requireNonNull(sysMLEditingContextProcessor);

backend/application/syson-sysml-export/src/main/java/org/eclipse/syson/sysml/export/SysMLElementSerializer.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,16 +1206,13 @@ private void appendValuePart(Appender builder, Usage usage) {
12061206

12071207
for (FeatureValue feature : ownedRelationship) {
12081208
builder.appendSpaceIfNeeded();
1209+
if (feature.isIsDefault()) {
1210+
builder.appendWithSpaceIfNeeded(LabelConstants.DEFAULT);
1211+
}
12091212
if (feature.isIsInitial()) {
1210-
builder.append(":=");
1211-
} else if (feature.isIsDefault()) {
1212-
builder.append("default");
1213-
if (feature.isIsInitial()) {
1214-
builder.append(":");
1215-
}
1216-
builder.append("=");
1213+
builder.appendWithSpaceIfNeeded(":=");
12171214
} else {
1218-
builder.append("=");
1215+
builder.appendWithSpaceIfNeeded(LabelConstants.EQUAL);
12191216
}
12201217
this.appendOwnedExpression(builder, feature.getValue());
12211218
}

backend/metamodel/syson-sysml-metamodel/src/main/java/org/eclipse/syson/sysml/helper/LabelConstants.java

Lines changed: 3 additions & 1 deletion
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
@@ -78,4 +78,6 @@ public class LabelConstants {
7878
public static final String VARIANT = "variant";
7979

8080
public static final String VARIATION = "variation";
81+
82+
public static final String DEFAULT = "default";
8183
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,15 @@ protected String getValueLabel(Usage usage) {
553553
if (expression != null) {
554554
valueAsString = this.getValue(expression);
555555
}
556+
557+
if (featureValue.get().isIsDefault()) {
558+
label
559+
.append(LabelConstants.SPACE)
560+
.append(LabelConstants.DEFAULT);
561+
}
556562
label
557563
.append(LabelConstants.SPACE)
558-
.append(getFeatureValueRelationshipSymbol(featureValue.get()))
564+
.append(this.getFeatureValueRelationshipSymbol(featureValue.get()))
559565
.append(LabelConstants.SPACE)
560566
.append(valueAsString);
561567
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,30 @@ public void testInitalFeatureValueSymboleLabel() {
104104

105105
}
106106

107+
@DisplayName("Given a FeatureValue to an attribute, when it is a default FeatureValue relationship, then the label should use the symbole ':=' instead of '='")
108+
@Test
109+
public void testDefaultFeatureValueSymboleLabel() {
110+
AttributeUsage attributeUsage = SysmlFactory.eINSTANCE.createAttributeUsage();
111+
attributeUsage.setDeclaredName(ATTRIBUTE_USAGE_NAME);
112+
113+
LiteralInteger literal = SysmlFactory.eINSTANCE.createLiteralInteger();
114+
literal.setValue(1);
115+
FeatureValue featureValue = SysmlFactory.eINSTANCE.createFeatureValue();
116+
featureValue.getOwnedRelatedElement().add(literal);
117+
attributeUsage.getOwnedRelationship().add(featureValue);
118+
119+
assertEquals("myAttributeUsage = 1", this.viewLabelService.getCompartmentItemLabel(attributeUsage));
120+
121+
featureValue.setIsDefault(true);
122+
123+
assertEquals("myAttributeUsage default = 1", this.viewLabelService.getCompartmentItemLabel(attributeUsage));
124+
125+
featureValue.setIsInitial(true);
126+
127+
assertEquals("myAttributeUsage default := 1", this.viewLabelService.getCompartmentItemLabel(attributeUsage));
128+
129+
}
130+
107131
@DisplayName("Check Attribute Usage item label with no name")
108132
@Test
109133
void testItemCompartmentLabelWithoutName() {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ 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 "=".
36+
- In diagrams, labels of `Usages` (e.g.: `Attribute Usages`) with a `Feature Value` relationship having the _initial_ property set to true now use the ":=" symbol instead of "=".
37+
- In diagrams, labels of `Usages` (e.g.: `Attribute Usages`) with a `Feature Value` relationship having the _default_ property set to true now display the _default_ keyword.
3738

3839
== New features
3940

0 commit comments

Comments
 (0)