Skip to content

Commit 1e5763f

Browse files
committed
ST6RI-897 Implemented a setting delegate for Feature::isNonunique.
- Updated CustomUML2EcoreConverter to add SysML EAnnotation to the Feature::isNonunique EAttribute, when it adds that to the Ecore metamodel.
1 parent 158e32e commit 1e5763f

7 files changed

Lines changed: 146 additions & 56 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//*
2+
XPECT_SETUP org.omg.kerml.xpect.tests.validation.KerMLValidationTest
3+
ResourceSet {
4+
ThisFile {}
5+
File {from ="/library/Base.kerml"}
6+
}
7+
Workspace {
8+
JavaProject {
9+
SrcFolder {
10+
ThisFile {}
11+
File {from ="/library/Base.kerml"}
12+
}
13+
}
14+
}
15+
END_SETUP
16+
*/
17+
package Feature_nonunique_invalid {
18+
classifier A {
19+
feature x; // "unique" by default
20+
}
21+
classifier B specializes A {
22+
// XPECT errors --> "Subsetting/redefining feature cannot be nonunique if subsetted/redefined feature is unique" at "x"
23+
feature x1 nonunique subsets x;
24+
}
25+
classifier C specializes A {
26+
// XPECT errors --> "Subsetting/redefining feature cannot be nonunique if subsetted/redefined feature is unique" at "x"
27+
feature x2 nonunique redefines x;
28+
}
29+
}

org.omg.sysml.uml.ecore.importer/src/org/omg/sysml/uml/ecore/importer/CustomUML2EcoreConverter.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import org.eclipse.emf.common.util.DiagnosticChain;
88
import org.eclipse.emf.ecore.EAnnotation;
9+
import org.eclipse.emf.ecore.EAttribute;
910
import org.eclipse.emf.ecore.EClass;
1011
import org.eclipse.emf.ecore.EClassifier;
1112
import org.eclipse.emf.ecore.EModelElement;
@@ -45,16 +46,15 @@ private void customConvert(DiagnosticChain diagnostics) {
4546
if (element instanceof Property && ((Property)element).isDerived() && !((Property)element).isDerivedUnion() && modelElement instanceof EStructuralFeature ||
4647
element instanceof Operation && modelElement instanceof EOperation) {
4748
String qualifiedName = ((NamedElement)element).getQualifiedName();
48-
System.out.println("Add annotation: " + qualifiedName.substring(qualifiedName.indexOf("::") + 2));
49-
EAnnotation annotation = EcoreFactory.eINSTANCE.createEAnnotation();
50-
annotation.setSource(ANNOTATION_SYSML);
51-
modelElement.getEAnnotations().add(annotation);
49+
addSysMLAnnotation(qualifiedName.substring(qualifiedName.indexOf("::") + 2), modelElement);
5250
} else if (element instanceof org.eclipse.uml2.uml.Class && modelElement instanceof EClass) {
5351
String name = ((org.eclipse.uml2.uml.Class)element).getName();
5452
EClass eClass = (EClass)modelElement;
5553
if ("Feature".equals(name)) {
5654
EClassifier booleanType = eClass.getEStructuralFeature("isUnique").getEType();
57-
addStructuralFeature(eClass, EcoreFactory.eINSTANCE.createEAttribute(), "isNonunique", booleanType, 1, 1, "false", false);
55+
EAttribute isNonUniqueAttribute = EcoreFactory.eINSTANCE.createEAttribute();
56+
addStructuralFeature(eClass, isNonUniqueAttribute, "isNonunique", booleanType, 1, 1, "false", false);
57+
addSysMLAnnotation("Feature::isNonUnique", isNonUniqueAttribute);
5858
} else if ("InvocationExpression".equals(name)) {
5959
EClassifier expressionClass = eClass.getEStructuralFeature("argument").getEType();
6060
addStructuralFeature(eClass, EcoreFactory.eINSTANCE.createEReference(), "operand", expressionClass, 0, -1, null, true);
@@ -63,6 +63,13 @@ private void customConvert(DiagnosticChain diagnostics) {
6363
}
6464
}
6565

66+
private void addSysMLAnnotation(String qualifiedName, EModelElement modelElement) {
67+
System.out.println("Add annotation: " + qualifiedName);
68+
EAnnotation annotation = EcoreFactory.eINSTANCE.createEAnnotation();
69+
annotation.setSource(ANNOTATION_SYSML);
70+
modelElement.getEAnnotations().add(annotation);
71+
}
72+
6673
private void addStructuralFeature(EClass eClass, EStructuralFeature feature, String name, EClassifier type, int lower, int upper, String defaultValue, boolean isContainment) {
6774
System.out.println("Add feature: " + eClass.getName() + "::" + name + ": " + (type == null? "<null>": type.getName()));
6875
feature.setName(name);

org.omg.sysml/model/SysML.ecore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,9 @@
443443
</eStructuralFeatures>
444444
<eStructuralFeatures xsi:type="ecore:EAttribute" name="isNonunique" ordered="false"
445445
lowerBound="1" eType="ecore:EDataType types.ecore#//Boolean" volatile="true"
446-
transient="true" defaultValueLiteral="false" derived="true"/>
446+
transient="true" defaultValueLiteral="false" derived="true">
447+
<eAnnotations source="http://www.omg.org/spec/SysML"/>
448+
</eStructuralFeatures>
447449
</eClassifiers>
448450
<eClassifiers xsi:type="ecore:EClass" name="Type" eSuperTypes="#//Namespace">
449451
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2026 Model Driven Solutions, Inc.
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.delegate.setting;
23+
24+
import org.eclipse.emf.ecore.EStructuralFeature;
25+
import org.eclipse.emf.ecore.InternalEObject;
26+
import org.omg.sysml.lang.sysml.Feature;
27+
28+
public class Feature_isNonunique_SettingDelegate extends BasicDerivedPropertySettingDelegate {
29+
30+
public Feature_isNonunique_SettingDelegate(EStructuralFeature eStructuralFeature) {
31+
super(eStructuralFeature);
32+
}
33+
34+
@Override
35+
protected Boolean basicGet(InternalEObject owner) {
36+
Feature feature = (Feature)owner;
37+
return !feature.isUnique();
38+
}
39+
40+
@Override
41+
protected void set(InternalEObject owner, Object newValue) {
42+
Feature feature = (Feature)owner;
43+
feature.setIsUnique(!(Boolean)newValue);
44+
}
45+
46+
}

org.omg.sysml/syntax-gen/org/omg/sysml/lang/sysml/Feature.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,7 @@ public interface Feature extends Type {
994994
* @see #setIsNonunique(boolean)
995995
* @see org.omg.sysml.lang.sysml.SysMLPackage#getFeature_IsNonunique()
996996
* @model default="false" dataType="org.omg.sysml.lang.types.Boolean" required="true" transient="true" volatile="true" derived="true" ordered="false"
997+
* annotation="http://www.omg.org/spec/SysML"
997998
* @generated
998999
*/
9991000
boolean isNonunique();

0 commit comments

Comments
 (0)