Skip to content

Commit 2b03e63

Browse files
adaussyAxelRICHARD
authored andcommitted
[870] Fix an issue while computing the name of VariantMembership
Bug: #870 Signed-off-by: Arthur Daussy <arthur.daussy@obeo.fr>
1 parent 49259f0 commit 2b03e63

File tree

5 files changed

+56
-6
lines changed

5 files changed

+56
-6
lines changed

CHANGELOG.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
=== Bug fixes
1919

20+
- https://github.com/eclipse-syson/syson/issues/870[#870] Fix an issue while computing the name of `VariantMembership`.
21+
2022
=== Improvements
2123

2224
- https://github.com/eclipse-syson/syson/issues/1061[#1061] [general-view] Add ellipsis on `Packages` label, to provide visual feedback on name overflow.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ public void checkScalarValueAttribute() throws IOException {
295295
attribute b : Integer default = 1;
296296
attribute c : Integer = 1;
297297
attribute d : Integer := 3;
298+
attribute e : MyEnum default = enum1;
299+
}
300+
enum def MyEnum {
301+
enum1;
298302
}
299303
}""";
300304
this.checker.check(input, input);

backend/metamodel/syson-sysml-metamodel/src/main/java/org/eclipse/syson/sysml/impl/VariantMembershipImpl.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,16 @@ public Usage getOwnedVariantUsage() {
6969
}
7070

7171
/**
72-
* <!-- begin-user-doc --> <!-- end-user-doc -->
72+
* <!-- begin-user-doc -->The first owned related element which is an Usage.<!-- end-user-doc -->
7373
*
74-
* @generated
74+
* @generated NOT
7575
*/
7676
public Usage basicGetOwnedVariantUsage() {
77-
// TODO: implement this method to return the 'Owned Variant Usage' reference
78-
// -> do not perform proxy resolution
79-
// Ensure that you remove @generated or mark it @generated NOT
80-
return null;
77+
return this.getOwnedRelatedElement().stream()
78+
.filter(Usage.class::isInstance)
79+
.map(Usage.class::cast)
80+
.findFirst()
81+
.orElse(null);
8182
}
8283

8384
/**
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Obeo.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Obeo - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.syson.sysml.impl;
14+
15+
import static org.assertj.core.api.Assertions.assertThat;
16+
17+
import org.eclipse.syson.sysml.EnumerationUsage;
18+
import org.eclipse.syson.sysml.SysmlFactory;
19+
import org.eclipse.syson.sysml.VariantMembership;
20+
import org.junit.jupiter.api.Test;
21+
22+
/**
23+
* Test class for {@link VariantMembershipImpl}.
24+
*
25+
* @author Arthur Daussy
26+
*/
27+
public class VariantMembershipImplTest {
28+
29+
@Test
30+
public void checkBasicGetOwnedVariantUsage() {
31+
VariantMembership variantMembership = SysmlFactory.eINSTANCE.createVariantMembership();
32+
33+
EnumerationUsage enumUsage = SysmlFactory.eINSTANCE.createEnumerationUsage();
34+
enumUsage.setDeclaredName("enum1");
35+
variantMembership.getOwnedRelatedElement().add(enumUsage);
36+
37+
assertThat(variantMembership.getMemberElement()).isEqualTo(enumUsage);
38+
assertThat(variantMembership.getMemberName()).isEqualTo("enum1");
39+
}
40+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ In such cases, delete the `SuccessionUsage` graphical node and recreate it graph
88

99
== Bug fixes
1010

11+
- Fix an issue while computing the name of `VariantMembership`.
12+
This has an impact on name resolution against `Element` contained in `VariantMembership` during the textual import process (e.g. for `EnumerationUsage` literals in `EnumerationDefinition`).
13+
1114
== New features
1215

1316
== Improvements

0 commit comments

Comments
 (0)