Skip to content

Commit 60bb466

Browse files
authored
Merge pull request #448 from Systems-Modeling/ST6RI-636
ST6RI-636 Update multiplicity derivation
2 parents 37dd1ca + 918162d commit 60bb466

5 files changed

Lines changed: 30 additions & 21 deletions

File tree

org.omg.sysml.plantuml/src/org/omg/sysml/plantuml/Visitor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*****************************************************************************
22
* SysML 2 Pilot Implementation, PlantUML Visualization
33
* Copyright (c) 2020-2022 Mgnite Inc.
4+
* Copyright (c) 2023 Model Driven Solutions, Inc.
45
*
56
* This program is free software: you can redistribute it and/or modify
67
* it under the terms of the GNU Lesser General Public License as published by
@@ -19,6 +20,7 @@
1920
*
2021
* Contributors:
2122
* Hisashi Miyashita, Mgnite Inc.
23+
* Ed Seidewitz, MDS
2224
*
2325
*****************************************************************************/
2426

@@ -347,7 +349,7 @@ protected PRelation addPRelation(Element src, Element dest, Element rel) {
347349
private MultiplicityRange getEffectiveMultiplicityRange(Element e) {
348350
if (!(e instanceof Type)) return null;
349351
Type typ = (Type) e;
350-
Multiplicity m = typ.getMultiplicity();
352+
Multiplicity m = FeatureUtil.getMultiplicityOf(typ);
351353
return FeatureUtil.getMultiplicityRangeOf(m);
352354
}
353355

org.omg.sysml/src/org/omg/sysml/delegate/Type_multiplicity_SettingDelegate.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
* SysML 2 Pilot Implementation
3-
* Copyright (c) 2022 Model Driven Solutions, Inc.
3+
* Copyright (c) 2022, 2023 Model Driven Solutions, Inc.
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Lesser General Public License as published by
@@ -22,16 +22,13 @@
2222
package org.omg.sysml.delegate;
2323

2424
import java.util.HashSet;
25-
import java.util.List;
2625
import java.util.Set;
2726

2827
import org.eclipse.emf.ecore.EStructuralFeature;
2928
import org.eclipse.emf.ecore.InternalEObject;
3029
import org.omg.sysml.lang.sysml.Membership;
3130
import org.omg.sysml.lang.sysml.Multiplicity;
3231
import org.omg.sysml.lang.sysml.Type;
33-
import org.omg.sysml.lang.sysml.impl.TypeImpl;
34-
import org.omg.sysml.util.TypeUtil;
3532

3633
public class Type_multiplicity_SettingDelegate extends BasicDerivedObjectSettingDelegate {
3734

@@ -45,21 +42,10 @@ protected Multiplicity basicGet(InternalEObject owner) {
4542
}
4643

4744
protected static Multiplicity getMultiplicityOf(Type type, Set<Type> visited) {
48-
Multiplicity multiplicity = (Multiplicity)type.getOwnedMembership().stream().
45+
return (Multiplicity)type.getOwnedMembership().stream().
4946
map(Membership::getMemberElement).
5047
filter(Multiplicity.class::isInstance).
5148
findFirst().orElse(null);
52-
if (multiplicity == null) {
53-
visited.add(type);
54-
List<Type> superTypes = TypeUtil.getSupertypesOf(type);
55-
if (!superTypes.isEmpty()) {
56-
Type general = TypeUtil.getSupertypesOf(type).get(0);
57-
if (general != null && !visited.contains(general)) {
58-
multiplicity = getMultiplicityOf((TypeImpl)general, visited);
59-
}
60-
}
61-
}
62-
return multiplicity;
6349
}
6450

6551
}

org.omg.sysml/src/org/omg/sysml/util/FeatureUtil.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public static List<Feature> getAllSubsettingFeaturesIn(Type type, Feature subset
229229
collect(Collectors.toList());
230230
}
231231

232-
// Feature values
232+
// Feature values
233233

234234
public static FeatureValue getValuationFor(Feature feature) {
235235
return (FeatureValue)feature.getOwnedMembership().stream().
@@ -395,4 +395,23 @@ public static void addMultiplicityTo(Type type) {
395395
}
396396
}
397397

398+
public static Multiplicity getMultiplicityOf(Type type) {
399+
return getMultiplicityOf(type, new HashSet<>());
400+
}
401+
402+
public static Multiplicity getMultiplicityOf(Type type, Set<Type> visited) {
403+
Multiplicity multiplicity = type.getMultiplicity();
404+
if (multiplicity == null) {
405+
visited.add(type);
406+
for (Type general: TypeUtil.getGeneralTypesOf(type)){
407+
if (general != null && !visited.contains(general)) {
408+
multiplicity = getMultiplicityOf(general, visited);
409+
if (multiplicity != null) {
410+
break;
411+
}
412+
}
413+
}
414+
}
415+
return multiplicity;
416+
}
398417
}

sysml.library/Kernel Libraries/Kernel Semantic Library/Base.kerml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ standard library package Base {
3131
feature self: DataValue redefines Anything::self;
3232
}
3333

34-
abstract feature things: Anything [0..*] nonunique {
34+
abstract feature things: Anything [1..*] nonunique {
3535
doc
3636
/*
3737
* things is the top-level feature in the language.
@@ -87,7 +87,7 @@ standard library package Base {
8787
multiplicity zeroToMany [0..*] {
8888
doc
8989
/*
90-
* oneToMany is a multiplicity range allowing any cardinality of ozero or more
90+
* zeroToMany is a multiplicity range allowing any cardinality of zero or more
9191
* (that is, no restriction).
9292
*/
9393
}

sysml/src/examples/Simple Tests/PartTest.sysml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ package PartTest {
1111
}
1212

1313
abstract part def <xx> B {
14-
public abstract part a: A;
14+
public abstract part a: A[1..2];
15+
public abstract part b subsets a;
16+
public abstract part c[0..1] subsets a;
1517
port x: ~C;
1618
package P { }
1719

0 commit comments

Comments
 (0)