Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* SysML 2 Pilot Implementation
* Copyright (c) 2022 Siemens AG
* Copyright (c) 2022, 2026 Model Driven Solutions, Inc.
*
* Copyright (c) 2026 Obeo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Eclipse Public License as published by
* the Eclipse Foundation, version 2 of the License.
Expand All @@ -25,6 +26,7 @@
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.InternalEObject;
import org.omg.sysml.lang.sysml.Type;
import org.omg.sysml.util.ElementUtil;
import org.omg.sysml.util.TypeUtil;

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

@Override
protected EList<?> basicGet(InternalEObject owner) {
return TypeUtil.getFeatureMembershipOf((Type)owner);
ElementUtil.clearCachesOf((Type) owner);
return TypeUtil.getFeatureMembershipOf((Type) owner);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*******************************************************************************
* SysML 2 Pilot Implementation
* Copyright (c) 2022 Siemens AG
* Copyright (c) 2022 Model Driven Solutions, Inc.
* Copyright (c) 2022, 2026 Model Driven Solutions, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Eclipse Public License as published by
Expand All @@ -28,6 +28,7 @@
import org.omg.sysml.lang.sysml.FeatureMembership;
import org.omg.sysml.lang.sysml.Type;
import org.omg.sysml.util.NonNotifyingEObjectEList;
import org.omg.sysml.util.TypeUtil;

public class Type_feature_SettingDelegate extends BasicDerivedListSettingDelegate {

Expand All @@ -38,7 +39,7 @@ public Type_feature_SettingDelegate(EStructuralFeature eStructuralFeature) {
@Override
protected EList<?> basicGet(InternalEObject owner) {
EList<Feature> features = new NonNotifyingEObjectEList<>(Feature.class, owner, eStructuralFeature.getFeatureID());
((Type) owner).getFeatureMembership().stream().
TypeUtil.getFeatureMembershipOf((Type) owner).stream().
map(FeatureMembership::getOwnedMemberFeature).
filter(f->f != null).
forEachOrdered(features::add);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public static <M extends Membership, T> Stream<T> getInheritedMembersByMembershi
}

public static <T extends Membership> Stream<Feature> getFeaturesByMembershipIn(Type type, Class<T> kind) {
return type.getFeatureMembership().stream().
return getFeatureMembershipOf(type).stream().
filter(kind::isInstance).
map(FeatureMembership::getOwnedMemberFeature);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*******************************************************************************
* SysML 2 Pilot Implementation
* Copyright (c) 2026 Obeo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
*
*******************************************************************************/

package org.omg.sysml.logic;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import org.eclipse.emf.common.util.EList;
import org.junit.Test;
import org.omg.sysml.lang.sysml.Feature;
import org.omg.sysml.lang.sysml.FeatureMembership;
import org.omg.sysml.lang.sysml.SysMLFactory;
import org.omg.sysml.lang.sysml.Type;
import org.omg.sysml.util.TypeUtil;

/**
* Verifies that derived feature memberships reflect owned membership mutations that happen after an initial read.
*/
public class TypeFeatureMembershipCacheTest {

/**
* Verifies that a second read of {@link Type#getFeatureMembership()} sees a newly added owned membership after the
* first read has already populated the derived list.
*/
@Test
public void getFeatureMembershipReflectsOwnedMembershipsAddedAfterFirstRead() {
initializeStandalone();

Type type = this.createType("FixtureType");
Feature initialFeature = this.createFeature("initialFeature");
FeatureMembership initialMembership = TypeUtil.addOwnedFeatureTo(type, initialFeature);

EList<FeatureMembership> initialMemberships = type.getFeatureMembership();

assertEquals(1, initialMemberships.size());
assertSame(initialMembership, initialMemberships.get(0));
assertSame(initialFeature, initialMemberships.get(0).getOwnedMemberFeature());

Feature addedFeature = this.createFeature("addedFeature");
FeatureMembership addedMembership = TypeUtil.addOwnedFeatureTo(type, addedFeature);

EList<FeatureMembership> updatedMemberships = type.getFeatureMembership();

assertEquals(2, updatedMemberships.size());
assertTrue(updatedMemberships.contains(initialMembership));
assertTrue(updatedMemberships.contains(addedMembership));
assertSame(addedMembership, updatedMemberships.get(1));
assertSame(addedFeature, updatedMemberships.get(1).getOwnedMemberFeature());
}

/**
* Installs the standalone delegates used by direct EMF logic tests.
*/
private void initializeStandalone() {
SysMLLogicStandaloneSetup.doSetup();
}

/**
* Creates a type with the given declared name.
*
* @param name
* the declared type name used in the test fixture
* @return a new type instance
*/
private Type createType(String name) {
Type type = SysMLFactory.eINSTANCE.createType();
type.setDeclaredName(name);
return type;
}

/**
* Creates a feature with the given declared name.
*
* @param name
* the declared feature name used in the test fixture
* @return a new feature instance
*/
private Feature createFeature(String name) {
Feature feature = SysMLFactory.eINSTANCE.createFeature();
feature.setDeclaredName(name);
return feature;
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ import org.omg.sysml.util.SysMLLibraryUtil
import org.omg.sysml.util.FeatureUtil
import org.omg.sysml.util.UsageUtil
import org.omg.sysml.lang.sysml.MetadataFeature
import org.omg.sysml.util.TypeUtil

/**
* This class contains custom validation rules.
Expand Down Expand Up @@ -907,7 +908,7 @@ class SysMLValidator extends KerMLValidator {
}

// validateSendActionUsagePayloadArgument
val featureMembership = usg.featureMembership
val featureMembership = TypeUtil.getFeatureMembershipOf(usg)
if ((featureMembership instanceof StateSubactionMembership ||
featureMembership instanceof TransitionFeatureMembership) &&
usg.payloadArgument === null) {
Expand Down Expand Up @@ -1374,7 +1375,7 @@ class SysMLValidator extends KerMLValidator {
}

protected def boolean checkAtMostOneFeature(Type featuringType, Class<? extends FeatureMembership> kind, String msg, String eId) {
var mems = featuringType.featureMembership.filter[m | kind.isInstance(m)]
var mems = TypeUtil.getFeatureMembershipOf(featuringType).filter[m | kind.isInstance(m)]
checkAtMostOneRelationship(featuringType, mems, msg, eId)
}

Expand Down
Loading