Explorar el Código

Implement check for childfirst / parentfirst (#1563)

Rene Beckmann hace 8 años
padre
commit
f0c443e791

+ 10 - 0
plugins/org.yakindu.sct.model.stext.lib/src/org/yakindu/sct/model/stext/lib/StatechartAnnotations.java

@@ -21,6 +21,8 @@ public class StatechartAnnotations {
 
 	public static final String CYCLE_BASED_ANNOTATION = "CycleBased";
 	public static final String EVENT_DRIVEN_ANNOTATION = "EventDriven";
+	public static final String PARENT_FIRST_ANNOTATION = "ParentFirstExecution";
+	public static final String CHILD_FIRST_ANNOTATION = "ChildFirstExecution";
 
 	public boolean isCycleBased(Statechart statechart) {
 		return statechart.getAnnotationOfType(EVENT_DRIVEN_ANNOTATION) == null;
@@ -29,4 +31,12 @@ public class StatechartAnnotations {
 	public boolean isEventDriven(Statechart statechart) {
 		return statechart.getAnnotationOfType(EVENT_DRIVEN_ANNOTATION) != null;
 	}
+	
+	public boolean isParentFirstExecution(Statechart statechart) {
+		return statechart.getAnnotationOfType(PARENT_FIRST_ANNOTATION) != null;
+	}
+	
+	public boolean isChildFirstExecution(Statechart statechart) {
+		return statechart.getAnnotationOfType(CHILD_FIRST_ANNOTATION) != null;
+	}
 }

+ 13 - 0
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/validation/STextJavaValidator.java

@@ -13,6 +13,8 @@ package org.yakindu.sct.model.stext.validation;
 
 import static org.yakindu.sct.model.stext.lib.StatechartAnnotations.EVENT_DRIVEN_ANNOTATION;
 import static org.yakindu.sct.model.stext.lib.StatechartAnnotations.CYCLE_BASED_ANNOTATION;
+import static org.yakindu.sct.model.stext.lib.StatechartAnnotations.CHILD_FIRST_ANNOTATION;
+import static org.yakindu.sct.model.stext.lib.StatechartAnnotations.PARENT_FIRST_ANNOTATION;
 
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -437,12 +439,23 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements ST
 	public void checkAnnotations(final Statechart statechart) {
 		Annotation eventDriven = statechart.getAnnotationOfType(EVENT_DRIVEN_ANNOTATION);
 		Annotation cycleBased = statechart.getAnnotationOfType(CYCLE_BASED_ANNOTATION);
+		
 		if(eventDriven != null && cycleBased != null) {
 			String errorMsg = String.format(CONTRADICTORY_ANNOTATIONS, String.join(
 					", ", eventDriven.getType().toString(), cycleBased.getType().toString()
 					));
 			error(errorMsg, cycleBased, null, -1);
 		}
+		
+		Annotation parentFirst = statechart.getAnnotationOfType(PARENT_FIRST_ANNOTATION);
+		Annotation childFirst = statechart.getAnnotationOfType(CHILD_FIRST_ANNOTATION);
+		
+		if(parentFirst != null && childFirst != null) {
+			String errorMsg = String.format(CONTRADICTORY_ANNOTATIONS, String.join(
+					", ", parentFirst.getType().toString(), childFirst.getType().toString()
+					));
+			error(errorMsg, parentFirst, null, -1);
+		}
 	}
 
 	@Check(CheckType.NORMAL)

+ 22 - 0
test-plugins/org.yakindu.sct.model.stext.test/src/org/yakindu/sct/model/stext/test/validation/STextJavaValidatorTest.java

@@ -327,6 +327,28 @@ public class STextJavaValidatorTest extends AbstractSTextValidationTest implemen
 		statechart.getAnnotations().addAll(model.getAnnotations());
 		validationResult = tester.validate(statechart);
 		validationResult.assertErrorContains(CONTRADICTORY_ANNOTATIONS.split("%s")[0]);
+
+		scope = "@ParentFirstExecution";
+		model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
+		statechart.getAnnotations().clear();
+		statechart.getAnnotations().addAll(model.getAnnotations());
+		validationResult = tester.validate(statechart);
+		validationResult.assertOK();
+		
+		scope = "@ChildFirstExecution";
+		model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
+		statechart.getAnnotations().clear();
+		statechart.getAnnotations().addAll(model.getAnnotations());
+		validationResult = tester.validate(statechart);
+		validationResult.assertOK();
+		
+		scope = "@ParentFirstExecution\n"
+				+ "@ChildFirstExecution";
+		model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
+		statechart.getAnnotations().clear();
+		statechart.getAnnotations().addAll(model.getAnnotations());
+		validationResult = tester.validate(statechart);
+		validationResult.assertErrorContains(CONTRADICTORY_ANNOTATIONS.split("%s")[0]);
 	}
 
 	/**