-
Notifications
You must be signed in to change notification settings - Fork 0
#683 Add activity constraints #684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
12cb8f6
58705a8
6fe4ef6
212a07b
3bb41f9
0fa177a
a468205
19fa69f
6b5dc4d
8a1f8c1
ee430c6
3127da1
5aa521f
ab173a0
549e163
8cd8aac
f689a77
686be24
281f185
1c52cc8
49a6a8e
3312f5d
e623614
0487e95
2f63429
f0ba3f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ | |
| import org.eclipse.uml2.uml.NamedElement; | ||
| import org.eclipse.uml2.uml.OpaqueExpression; | ||
| import org.eclipse.uml2.uml.Package; | ||
| import org.eclipse.uml2.uml.PrimitiveType; | ||
| import org.eclipse.uml2.uml.Profile; | ||
| import org.eclipse.uml2.uml.Property; | ||
| import org.eclipse.uml2.uml.RedefinableElement; | ||
|
|
@@ -82,7 +83,7 @@ public class PokaYokeUmlProfileUtil { | |
|
|
||
| private static final String ST_FORMAL_CONSTRAINT = SynthMLPackage.Literals.FORMAL_CONSTRAINT.getName(); | ||
|
|
||
| public static final String ST_CLASS_REQUIREMENT = SynthMLPackage.Literals.REQUIREMENT.getName(); | ||
| public static final String ST_REQUIREMENT = SynthMLPackage.Literals.REQUIREMENT.getName(); | ||
|
|
||
| public static final String ST_SYNTHESIS_PRECONDITION = SynthMLPackage.Literals.SYNTHESIS_PRECONDITION.getName(); | ||
|
|
||
|
|
@@ -112,8 +113,7 @@ public class PokaYokeUmlProfileUtil { | |
| + ST_FORMAL_CONSTRAINT; | ||
|
|
||
| /** Qualified name for the {@link Requirement} stereotype. */ | ||
| public static final String REQUIREMENT_STEREOTYPE = POKA_YOKE_PROFILE + NamedElement.SEPARATOR | ||
| + ST_CLASS_REQUIREMENT; | ||
| public static final String REQUIREMENT_STEREOTYPE = POKA_YOKE_PROFILE + NamedElement.SEPARATOR + ST_REQUIREMENT; | ||
|
|
||
| /** Qualified name for the {@link SynthesisPrecondition} stereotype. */ | ||
| public static final String SYNTHESIS_PRECONDITION_STEREOTYPE = POKA_YOKE_PROFILE + NamedElement.SEPARATOR | ||
|
|
@@ -523,13 +523,13 @@ public static Stereotype getConstraintFirstStereotype(Constraint constraint) { | |
| * @return A list of supported stereotypes for the given constraint. | ||
| */ | ||
| public static List<Stereotype> getSupportedConstraintStereotypes(Constraint constraint) { | ||
| if (isPreconditionConstraint(constraint)) { | ||
| if (isContainedAsActivityPrecondition(constraint)) { | ||
| return List.of(getStereotype(constraint, ST_SYNTHESIS_PRECONDITION), | ||
| getStereotype(constraint, ST_USAGE_PRECONDITION)); | ||
| } else if (isPostconditionConstraint(constraint)) { | ||
| } else if (isContainedAsActivityPostcondition(constraint)) { | ||
| return List.of(getStereotype(constraint, ST_POSTCONDITION)); | ||
| } else if (isClassRequirement(constraint)) { | ||
| return List.of(getStereotype(constraint, ST_CLASS_REQUIREMENT)); | ||
| } else if (isContainedAsClassOrActivityOwnedRule(constraint)) { | ||
| return List.of(getStereotype(constraint, ST_REQUIREMENT)); | ||
| } else { | ||
| return List.of(); | ||
| } | ||
|
|
@@ -539,12 +539,30 @@ private static Stereotype getStereotype(Constraint constraint, String stereotype | |
| return getPokaYokeProfile(constraint).getOwnedStereotype(stereotypeName); | ||
| } | ||
|
|
||
| private static boolean isPreconditionConstraint(Constraint constraint) { | ||
| public static boolean isContainedAsActivityPrecondition(Constraint constraint) { | ||
| return (constraint.eContainer() instanceof Activity activity) | ||
| && activity.getPreconditions().contains(constraint); | ||
| } | ||
|
|
||
| public static boolean isSynthesisPrecondition(Constraint constraint) { | ||
| public static boolean isContainedAsActivityPostcondition(Constraint constraint) { | ||
| return (constraint.eContainer() instanceof Activity activity) | ||
| && activity.getPostconditions().contains(constraint); | ||
| } | ||
|
|
||
| public static boolean isContainedAsClassOrActivityOwnedRule(Constraint constraint) { | ||
| // Activity is a sub-type of Classifier. | ||
| return constraint.eContainer() instanceof Classifier clazz && clazz.getOwnedRules().contains(constraint); | ||
| } | ||
|
|
||
| public static boolean isContainedAsActivityOccurrenceConstraint(Constraint constraint) { | ||
| return constraint.getContext() instanceof Activity && constraint instanceof IntervalConstraint; | ||
| } | ||
|
|
||
| public static boolean isPrimitiveTypeConstraint(Constraint constraint) { | ||
| return constraint.getContext() instanceof PrimitiveType; | ||
| } | ||
|
|
||
| public static boolean isSynthesisPreconditionConstraint(Constraint constraint) { | ||
| List<Stereotype> appliedStereotypes = constraint.getAppliedStereotypes(); | ||
|
|
||
| if (appliedStereotypes.isEmpty()) { | ||
|
|
@@ -554,7 +572,7 @@ public static boolean isSynthesisPrecondition(Constraint constraint) { | |
| return appliedStereotypes.get(0).getName().equals(ST_SYNTHESIS_PRECONDITION); | ||
| } | ||
|
|
||
| public static boolean isUsagePrecondition(Constraint constraint) { | ||
| public static boolean isUsagePreconditionConstraint(Constraint constraint) { | ||
| List<Stereotype> appliedStereotypes = constraint.getAppliedStereotypes(); | ||
|
|
||
| if (appliedStereotypes.isEmpty()) { | ||
|
|
@@ -564,13 +582,14 @@ public static boolean isUsagePrecondition(Constraint constraint) { | |
| return appliedStereotypes.get(0).getName().equals(ST_USAGE_PRECONDITION); | ||
| } | ||
|
|
||
| private static boolean isPostconditionConstraint(Constraint constraint) { | ||
| return (constraint.eContainer() instanceof Activity activity) | ||
| && activity.getPostconditions().contains(constraint); | ||
| } | ||
| public static boolean isRequirementConstraint(Constraint constraint) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe move
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are three methods for 'where' the constraint is (precondition/postcondition of activity, rule of a class/activity), and three methods about what kind (synthesis pre, usage pre, requirement).
|
||
| List<Stereotype> appliedStereotypes = constraint.getAppliedStereotypes(); | ||
|
|
||
| if (appliedStereotypes.isEmpty()) { | ||
| return false; | ||
| } | ||
|
|
||
| private static boolean isClassRequirement(Constraint constraint) { | ||
| return (constraint.eContainer() instanceof Classifier clazz) && clazz.getOwnedRules().contains(constraint); | ||
| return appliedStereotypes.get(0).getName().equals(ST_REQUIREMENT); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -592,7 +611,7 @@ public static void setConstraintStereotype(Constraint constraint, Stereotype ste | |
| } | ||
|
|
||
| private static String getQualifiedStereotypeName(String stereotypeName) { | ||
| if (ST_CLASS_REQUIREMENT.equals(stereotypeName)) { | ||
| if (ST_REQUIREMENT.equals(stereotypeName)) { | ||
| return REQUIREMENT_STEREOTYPE; | ||
| } else if (ST_SYNTHESIS_PRECONDITION.equals(stereotypeName)) { | ||
| return SYNTHESIS_PRECONDITION_STEREOTYPE; | ||
|
|
@@ -616,7 +635,7 @@ public static void setConstraintExpression(Constraint constraint, String newValu | |
|
|
||
| public static String getStereotypeName(Stereotype st) { | ||
| // Returns a slightly better formatted name for the preconditions. | ||
| if (st.getName().equals(ST_CLASS_REQUIREMENT)) { | ||
| if (st.getName().equals(ST_REQUIREMENT)) { | ||
| return "Requirement"; | ||
| } else if (st.getName().equals(ST_SYNTHESIS_PRECONDITION)) { | ||
| return "Synthesis precondition"; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it sufficient to translate the requirements like this? Should we also include all requirements of other activities that we call, etc? (all other 'relevant' activities)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this to be consistent with the occurrence constraints: these are considered only during the activity synthesis, not when an activity is called. Better to have a conversation offline about this.