Skip to content

Commit 3866507

Browse files
committed
Merge pull request #821 from Systems-Modeling/ST6RI-947
ST6RI-947 (supplemental) Remove model mutation in adapters for default multiplicity
2 parents fdba9c4 + ec8cd2f commit 3866507

3 files changed

Lines changed: 24 additions & 9 deletions

File tree

‎org.omg.sysml.interactive.tests/src/org/omg/sysml/interactive/tests/MultiplicityPreparationTest.java‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,23 +155,25 @@ public void explicitSpecializationsReceiveDefaultMultiplicity() throws Exception
155155
attribute plainValues;
156156
}
157157
""");
158-
for (String name : List.of("redefinedValues", "subsetValues", "chainValues", "packageValues")) {
158+
for (String name : List.of("plainValues", "subsetValues", "chainValues", "packageValues")) {
159159
Usage usage = findByName(resource, name, Usage.class);
160-
// ST6RI-774 allows the default even when the target has [0..*].
160+
// Allows the default even when the target has [0..*].
161+
// TODO: Update as necessary after final resolution of SYSML21-185.
161162
assertEquals(name, 1, TypeUtil.getOwnedMultiplicitiesOf(usage).size());
162163
Multiplicity multiplicity = TypeUtil.getOwnedMultiplicitiesOf(usage).get(0);
163164
assertEquals(SysMLPackage.Literals.MULTIPLICITY, multiplicity.eClass());
164165
usage.getFeature();
165166
SysMLParserPostProcessorFactory.getPostProcessor(usage).postProcess();
166167
assertEquals(name, 1, TypeUtil.getOwnedMultiplicitiesOf(usage).size());
167168
}
168-
assertEquals(1, TypeUtil.getOwnedMultiplicitiesOf(findByName(resource, "plainValues", Usage.class)).size());
169+
assertTrue("redefinedValues", TypeUtil.getOwnedMultiplicitiesOf(findByName(resource, "redefinedValues", Usage.class)).isEmpty());
169170

170171
// Explicit transformation must retain the same multiplicity choices.
171172
ElementUtil.transformAll(resource, true);
172-
for (String name : List.of("redefinedValues", "subsetValues", "chainValues", "packageValues")) {
173+
for (String name : List.of("plainValues", "subsetValues", "chainValues", "packageValues")) {
173174
assertEquals(name, 1, TypeUtil.getOwnedMultiplicitiesOf(findByName(resource, name, Usage.class)).size());
174175
}
176+
assertTrue("redefinedValues", TypeUtil.getOwnedMultiplicitiesOf(findByName(resource, "redefinedValues", Usage.class)).isEmpty());
175177
}
176178

177179
/**
Binary file not shown.

‎org.omg.sysml.xtext/src/org/omg/sysml/xtext/postprocessing/UsageParserPostProcessor.java‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.omg.kerml.xtext.postprocessing.FeatureParserPostProcessor;
1919
import org.omg.sysml.lang.sysml.AttributeDefinition;
2020
import org.omg.sysml.lang.sysml.AttributeUsage;
21+
import org.omg.sysml.lang.sysml.Redefinition;
2122
import org.omg.sysml.lang.sysml.SysMLPackage;
2223
import org.omg.sysml.lang.sysml.Type;
2324
import org.omg.sysml.lang.sysml.Usage;
@@ -82,16 +83,28 @@ protected void setIsVariableIfConstant() {
8283
}
8384

8485
/**
85-
* Checks the owning type for eligible attribute, item and port usages.
86-
* Subsettings and redefinitions do not restrict this default (ST6RI-774);
87-
* their targets are not consulted. End usages always receive the default.
86+
* Check whether a default multiplicity should be added.
87+
* For use by attribute, item and port post-processor subclasses.
88+
* Usages with explicit owned redefinitions do not get a default,
89+
* except that end usages always receive the default.
90+
*
91+
* TODO: Update as necessary after final resolution of SYSML21-185.
8892
*/
8993
protected boolean isAddDefaultMultiplicity() {
9094
Usage target = getTarget();
91-
return target.isEnd() || target.getOwningType() != null;
95+
return target.isEnd() ||
96+
target.getOwningType() != null &&
97+
target.getOwnedRelationship().stream().
98+
filter(rel->!rel.isImplied()).
99+
noneMatch(Redefinition.class::isInstance);
92100
}
93101

94-
// Multiplicity of 1..1 is always the default for an end usage.
102+
/**
103+
* Check if a default multiplicity must be added to the usage.
104+
* Multiplicity of 1..1 is always the default for an end usage.
105+
* This method is overridden to call isAddDefaultMultiplicity in
106+
* the post-processors for kinds of usages that have defaults.
107+
*/
95108
protected boolean isAddMultiplicity() {
96109
return getTarget().isEnd();
97110
}

0 commit comments

Comments
 (0)