Skip to content

Commit 78e36ba

Browse files
committed
ST6RI-944 Invalid TypeAdapter#getFeatureMembership cache when needed
Signed-off-by: Axel RICHARD <axel.richard@obeo.fr>
1 parent 6059ea8 commit 78e36ba

2 files changed

Lines changed: 108 additions & 2 deletions

File tree

org.omg.sysml.logic/src/main/java/org/omg/sysml/delegate/setting/Type_featureMembership_SettingDelegate.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
* SysML 2 Pilot Implementation
33
* Copyright (c) 2022 Siemens AG
44
* Copyright (c) 2022, 2026 Model Driven Solutions, Inc.
5-
*
5+
* Copyright (c) 2026 Obeo
6+
*
67
* This program is free software: you can redistribute it and/or modify
78
* it under the terms of the Eclipse Public License as published by
89
* the Eclipse Foundation, version 2 of the License.
@@ -25,6 +26,7 @@
2526
import org.eclipse.emf.ecore.EStructuralFeature;
2627
import org.eclipse.emf.ecore.InternalEObject;
2728
import org.omg.sysml.lang.sysml.Type;
29+
import org.omg.sysml.util.ElementUtil;
2830
import org.omg.sysml.util.TypeUtil;
2931

3032
public class Type_featureMembership_SettingDelegate extends BasicDerivedListSettingDelegate {
@@ -35,7 +37,8 @@ public Type_featureMembership_SettingDelegate(EStructuralFeature eStructuralFeat
3537

3638
@Override
3739
protected EList<?> basicGet(InternalEObject owner) {
38-
return TypeUtil.getFeatureMembershipOf((Type)owner);
40+
ElementUtil.clearCachesOf((Type) owner);
41+
return TypeUtil.getFeatureMembershipOf((Type) owner);
3942
}
4043

4144
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2026 Obeo
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
22+
package org.omg.sysml.logic;
23+
24+
import static org.junit.Assert.assertEquals;
25+
import static org.junit.Assert.assertSame;
26+
import static org.junit.Assert.assertTrue;
27+
28+
import org.eclipse.emf.common.util.EList;
29+
import org.junit.Test;
30+
import org.omg.sysml.lang.sysml.Feature;
31+
import org.omg.sysml.lang.sysml.FeatureMembership;
32+
import org.omg.sysml.lang.sysml.SysMLFactory;
33+
import org.omg.sysml.lang.sysml.Type;
34+
import org.omg.sysml.util.TypeUtil;
35+
36+
/**
37+
* Verifies that derived feature memberships reflect owned membership mutations that happen after an initial read.
38+
*/
39+
public class TypeFeatureMembershipCacheTest {
40+
41+
/**
42+
* Verifies that a second read of {@link Type#getFeatureMembership()} sees a newly added owned membership after the
43+
* first read has already populated the derived list.
44+
*/
45+
@Test
46+
public void getFeatureMembershipReflectsOwnedMembershipsAddedAfterFirstRead() {
47+
initializeStandalone();
48+
49+
Type type = this.createType("FixtureType");
50+
Feature initialFeature = this.createFeature("initialFeature");
51+
FeatureMembership initialMembership = TypeUtil.addOwnedFeatureTo(type, initialFeature);
52+
53+
EList<FeatureMembership> initialMemberships = type.getFeatureMembership();
54+
55+
assertEquals(1, initialMemberships.size());
56+
assertSame(initialMembership, initialMemberships.get(0));
57+
assertSame(initialFeature, initialMemberships.get(0).getOwnedMemberFeature());
58+
59+
Feature addedFeature = this.createFeature("addedFeature");
60+
FeatureMembership addedMembership = TypeUtil.addOwnedFeatureTo(type, addedFeature);
61+
62+
EList<FeatureMembership> updatedMemberships = type.getFeatureMembership();
63+
64+
assertEquals(2, updatedMemberships.size());
65+
assertTrue(updatedMemberships.contains(initialMembership));
66+
assertTrue(updatedMemberships.contains(addedMembership));
67+
assertSame(addedMembership, updatedMemberships.get(1));
68+
assertSame(addedFeature, updatedMemberships.get(1).getOwnedMemberFeature());
69+
}
70+
71+
/**
72+
* Installs the standalone delegates used by direct EMF logic tests.
73+
*/
74+
private void initializeStandalone() {
75+
SysMLLogicStandaloneSetup.doSetup();
76+
}
77+
78+
/**
79+
* Creates a type with the given declared name.
80+
*
81+
* @param name
82+
* the declared type name used in the test fixture
83+
* @return a new type instance
84+
*/
85+
private Type createType(String name) {
86+
Type type = SysMLFactory.eINSTANCE.createType();
87+
type.setDeclaredName(name);
88+
return type;
89+
}
90+
91+
/**
92+
* Creates a feature with the given declared name.
93+
*
94+
* @param name
95+
* the declared feature name used in the test fixture
96+
* @return a new feature instance
97+
*/
98+
private Feature createFeature(String name) {
99+
Feature feature = SysMLFactory.eINSTANCE.createFeature();
100+
feature.setDeclaredName(name);
101+
return feature;
102+
}
103+
}

0 commit comments

Comments
 (0)