diff --git a/org.omg.sysml.interactive.tests/src/org/omg/sysml/interactive/tests/MultiplicityPreparationTest.java b/org.omg.sysml.interactive.tests/src/org/omg/sysml/interactive/tests/MultiplicityPreparationTest.java index 6452238e8..39c50a0a9 100644 --- a/org.omg.sysml.interactive.tests/src/org/omg/sysml/interactive/tests/MultiplicityPreparationTest.java +++ b/org.omg.sysml.interactive.tests/src/org/omg/sysml/interactive/tests/MultiplicityPreparationTest.java @@ -155,9 +155,10 @@ public void explicitSpecializationsReceiveDefaultMultiplicity() throws Exception attribute plainValues; } """); - for (String name : List.of("redefinedValues", "subsetValues", "chainValues", "packageValues")) { + for (String name : List.of("plainValues", "subsetValues", "chainValues", "packageValues")) { Usage usage = findByName(resource, name, Usage.class); - // ST6RI-774 allows the default even when the target has [0..*]. + // Allows the default even when the target has [0..*]. + // TODO: Update as necessary after final resolution of SYSML21-185. assertEquals(name, 1, TypeUtil.getOwnedMultiplicitiesOf(usage).size()); Multiplicity multiplicity = TypeUtil.getOwnedMultiplicitiesOf(usage).get(0); assertEquals(SysMLPackage.Literals.MULTIPLICITY, multiplicity.eClass()); @@ -165,13 +166,14 @@ public void explicitSpecializationsReceiveDefaultMultiplicity() throws Exception SysMLParserPostProcessorFactory.getPostProcessor(usage).postProcess(); assertEquals(name, 1, TypeUtil.getOwnedMultiplicitiesOf(usage).size()); } - assertEquals(1, TypeUtil.getOwnedMultiplicitiesOf(findByName(resource, "plainValues", Usage.class)).size()); + assertTrue("redefinedValues", TypeUtil.getOwnedMultiplicitiesOf(findByName(resource, "redefinedValues", Usage.class)).isEmpty()); // Explicit transformation must retain the same multiplicity choices. ElementUtil.transformAll(resource, true); - for (String name : List.of("redefinedValues", "subsetValues", "chainValues", "packageValues")) { + for (String name : List.of("plainValues", "subsetValues", "chainValues", "packageValues")) { assertEquals(name, 1, TypeUtil.getOwnedMultiplicitiesOf(findByName(resource, name, Usage.class)).size()); } + assertTrue("redefinedValues", TypeUtil.getOwnedMultiplicitiesOf(findByName(resource, "redefinedValues", Usage.class)).isEmpty()); } /** diff --git a/org.omg.sysml.logic.bundle/lib/org.omg.sysml.logic-0.63.0-SNAPSHOT.jar b/org.omg.sysml.logic.bundle/lib/org.omg.sysml.logic-0.63.0-SNAPSHOT.jar index 9f62f5b33..d8b0f57c9 100644 Binary files a/org.omg.sysml.logic.bundle/lib/org.omg.sysml.logic-0.63.0-SNAPSHOT.jar and b/org.omg.sysml.logic.bundle/lib/org.omg.sysml.logic-0.63.0-SNAPSHOT.jar differ diff --git a/org.omg.sysml.xtext/src/org/omg/sysml/xtext/postprocessing/UsageParserPostProcessor.java b/org.omg.sysml.xtext/src/org/omg/sysml/xtext/postprocessing/UsageParserPostProcessor.java index eb64fc35d..5117e8da6 100644 --- a/org.omg.sysml.xtext/src/org/omg/sysml/xtext/postprocessing/UsageParserPostProcessor.java +++ b/org.omg.sysml.xtext/src/org/omg/sysml/xtext/postprocessing/UsageParserPostProcessor.java @@ -18,6 +18,7 @@ import org.omg.kerml.xtext.postprocessing.FeatureParserPostProcessor; import org.omg.sysml.lang.sysml.AttributeDefinition; import org.omg.sysml.lang.sysml.AttributeUsage; +import org.omg.sysml.lang.sysml.Redefinition; import org.omg.sysml.lang.sysml.SysMLPackage; import org.omg.sysml.lang.sysml.Type; import org.omg.sysml.lang.sysml.Usage; @@ -82,16 +83,28 @@ protected void setIsVariableIfConstant() { } /** - * Checks the owning type for eligible attribute, item and port usages. - * Subsettings and redefinitions do not restrict this default (ST6RI-774); - * their targets are not consulted. End usages always receive the default. + * Check whether a default multiplicity should be added. + * For use by attribute, item and port post-processor subclasses. + * Usages with explicit owned redefinitions do not get a default, + * except that end usages always receive the default. + * + * TODO: Update as necessary after final resolution of SYSML21-185. */ protected boolean isAddDefaultMultiplicity() { Usage target = getTarget(); - return target.isEnd() || target.getOwningType() != null; + return target.isEnd() || + target.getOwningType() != null && + target.getOwnedRelationship().stream(). + filter(rel->!rel.isImplied()). + noneMatch(Redefinition.class::isInstance); } - // Multiplicity of 1..1 is always the default for an end usage. + /** + * Check if a default multiplicity must be added to the usage. + * Multiplicity of 1..1 is always the default for an end usage. + * This method is overridden to call isAddDefaultMultiplicity in + * the post-processors for kinds of usages that have defaults. + */ protected boolean isAddMultiplicity() { return getTarget().isEnd(); }