Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -155,23 +155,25 @@ 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());
usage.getFeature();
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());
}

/**
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down