-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from HammerMaximilian/development
development --> master 2.0.0
- Loading branch information
Showing
366 changed files
with
100,074 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
fUML-CSharp/fuml/src/fuml/extensions/structuredclassifiers/UMLConformingDispatchStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using fuml.semantics.structuredclassifiers; | ||
using uml.classification; | ||
using uml.commonstructure; | ||
|
||
namespace fuml.extensions.structuredclassifiers | ||
{ | ||
public class UMLConformingDispatchStrategy : RedefinitionBasedDispatchStrategy | ||
{ | ||
public override bool OperationsMatch( | ||
Operation ownedOperation, | ||
Operation baseOperation) | ||
{ | ||
// Check if the owned operation is equal to or overrides the base operation. | ||
// In this context, an owned operation overrides a base operation if: | ||
// - base operation is directly or indirectly redefined by owned operation | ||
// - the class that owns base operation is equal to or a base class of the class that owns owned operation | ||
// - they have the same number of owned parameters and for each parameter the following holds: | ||
// - direction, ordering and uniqueness are the same | ||
// - the corresponding types are covariant, contravariant or invariant | ||
// - the multiplicities are compatible depending on the parameter direction | ||
|
||
bool matches = base.OperationsMatch(ownedOperation, baseOperation); | ||
if (matches) | ||
{ | ||
matches = IsConsistentWith(ownedOperation, baseOperation); | ||
} | ||
|
||
return matches; | ||
} // operationsMatch | ||
|
||
public bool IsConsistentWith( | ||
Operation ownedOperation, | ||
Operation baseOperation) | ||
{ | ||
bool isConsistentWith; | ||
|
||
isConsistentWith = ConformsTo(ownedOperation.class_!, baseOperation.class_!); | ||
|
||
List<Parameter> ownedOperationParameters = ownedOperation.ownedParameter; | ||
List<Parameter> baseOperationParameters = baseOperation.ownedParameter; | ||
|
||
isConsistentWith = isConsistentWith && (baseOperationParameters.Count == ownedOperationParameters.Count); | ||
|
||
for (int i = 0; isConsistentWith == true && i < ownedOperationParameters.Count; i++) | ||
{ | ||
Parameter redefiningParameter = ownedOperationParameters.ElementAt(i); | ||
Parameter redefinedParameter = baseOperationParameters.ElementAt(i); | ||
|
||
isConsistentWith = isConsistentWith && (redefiningParameter.multiplicityElement.isUnique == redefinedParameter.multiplicityElement.isUnique); | ||
isConsistentWith = isConsistentWith && (redefiningParameter.multiplicityElement.isOrdered == redefinedParameter.multiplicityElement.isOrdered); | ||
isConsistentWith = isConsistentWith && (redefiningParameter.direction == redefinedParameter.direction); | ||
|
||
Classifier redefiningParameterType = (Classifier)redefiningParameter.type!; | ||
Classifier redefinedParameterType = (Classifier)redefinedParameter.type!; | ||
isConsistentWith = isConsistentWith && (ConformsTo(redefiningParameterType, redefinedParameterType) || ConformsTo(redefinedParameterType, redefiningParameterType)); | ||
|
||
if (redefinedParameter.direction == ParameterDirectionKind.inout) | ||
{ | ||
isConsistentWith = isConsistentWith && | ||
( | ||
CompatibleWith(redefiningParameter.multiplicityElement, redefinedParameter.multiplicityElement) && | ||
CompatibleWith(redefinedParameter.multiplicityElement, redefiningParameter.multiplicityElement) | ||
); | ||
} | ||
else if (redefinedParameter.direction == ParameterDirectionKind.in_) | ||
{ | ||
isConsistentWith = isConsistentWith && CompatibleWith(redefinedParameter.multiplicityElement, redefiningParameter.multiplicityElement); | ||
} | ||
else // i.e. if((redefinedParameter.direction == ParameterDirectionKind.out_) || (redefinedParameter.direction == ParameterDirectionKind.return_)) | ||
{ | ||
isConsistentWith = isConsistentWith && CompatibleWith(redefiningParameter.multiplicityElement, redefinedParameter.multiplicityElement); | ||
} | ||
} | ||
|
||
return isConsistentWith; | ||
} | ||
|
||
public bool ConformsTo(Classifier type, Classifier otherType) | ||
{ | ||
bool conformsTo = false; | ||
|
||
if (type == otherType) | ||
{ | ||
conformsTo = true; | ||
} | ||
else | ||
{ | ||
int i = 1; | ||
while (conformsTo is false && i <= type.general.Count) | ||
{ | ||
Classifier general = type.general.ElementAt(i); | ||
conformsTo = ConformsTo(general, otherType); | ||
} | ||
} | ||
|
||
return conformsTo; | ||
} | ||
|
||
public bool CompatibleWith(MultiplicityElement self, MultiplicityElement other) | ||
{ | ||
bool compatibleWith = (other.lower <= self.lower) && ((other.upper.naturalValue == -1) || (self.upper.naturalValue <= other.upper.naturalValue)); | ||
|
||
return compatibleWith; | ||
} | ||
} // UMLConformingDispatchStrategy | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.