Pārlūkot izejas kodu

moved entry target test from transition to region validation

Axel Terfloth 7 gadi atpakaļ
vecāks
revīzija
1940907508

+ 29 - 0
plugins/org.yakindu.sct.model.sgraph/src/org/yakindu/sct/model/sgraph/validation/RegionValidator.java

@@ -14,6 +14,8 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
 
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
 import org.eclipse.xtext.validation.Check;
 import org.eclipse.xtext.validation.CheckType;
 import org.yakindu.sct.model.sgraph.CompositeElement;
@@ -117,4 +119,31 @@ public class RegionValidator extends AbstractSGraphValidator {
 		}
 	}
 
+	
+	
+	private static final String REGION_ENTRY_TARGET_MUST_BE_CHILD_MSG  = "Entry target must be child of the region.";
+	public static final String  REGION_ENTRY_TARGET_MUST_BE_CHILD_CODE = "region.EntryTargetMustBeChild";
+
+	/**
+	 * TODO: check region instead of transition.
+	 * @param t
+	 */
+	@Check(CheckType.FAST)
+	public void checkRegionEntryTargetMustBeChild(Transition t) {
+		if (t.getSource() instanceof Entry && !isChildOrSibling(t.getSource(), t.getTarget())) {
+			error(REGION_ENTRY_TARGET_MUST_BE_CHILD_MSG, t, null, -1,
+					REGION_ENTRY_TARGET_MUST_BE_CHILD_CODE);
+		}
+	}
+
+	protected boolean isChildOrSibling(Vertex source, Vertex target) {
+		TreeIterator<EObject> iter = source.getParentRegion().eAllContents();
+		while (iter.hasNext()) {
+			if (target == iter.next()) {
+				return true;
+			}
+		}
+		return false;
+	}
+
 }

+ 0 - 24
plugins/org.yakindu.sct.model.sgraph/src/org/yakindu/sct/model/sgraph/validation/TransitionValidator.java

@@ -47,28 +47,4 @@ public class TransitionValidator extends AbstractSGraphValidator {
 
 
 	
-	private static final String REGION_ENTRY_TARGET_MUST_BE_CHILD_MSG  = "Entry target must be child of the region.";
-	public static final String  REGION_ENTRY_TARGET_MUST_BE_CHILD_CODE = "region.EntryTargetMustBeChild";
-
-	/**
-	 * TODO: check region instead of transition.
-	 * @param t
-	 */
-	@Check(CheckType.FAST)
-	public void checkRegionEntryTargetMustBeChild(Transition t) {
-		if (t.getSource() instanceof Entry && !isChildOrSibling(t.getSource(), t.getTarget())) {
-			error(REGION_ENTRY_TARGET_MUST_BE_CHILD_MSG, t, null, -1,
-					REGION_ENTRY_TARGET_MUST_BE_CHILD_CODE);
-		}
-	}
-
-	protected boolean isChildOrSibling(Vertex source, Vertex target) {
-		TreeIterator<EObject> iter = source.getParentRegion().eAllContents();
-		while (iter.hasNext()) {
-			if (target == iter.next()) {
-				return true;
-			}
-		}
-		return false;
-	}
 }

+ 8 - 0
test-plugins/org.yakindu.sct.model.sgraph.test/src/org/yakindu/sct/model/sgraph/test/validation/RegionValidatorTest.java

@@ -84,6 +84,14 @@ public class RegionValidatorTest extends AbstractSGraphValidatorTest {
 	}
 
 	
+	@Test
+	public void initialEntryWithTransitionToContainer() {
+		Statechart statechart = loadStatechart("EntryTransitionToParentState.sct");
+		tester.validate(statechart).assertError(REGION_ENTRY_TARGET_MUST_BE_CHILD_CODE);
+	}
+
+
+	
 	@Override
 	protected Statechart loadStatechart(String path) {
 		return super.loadStatechart("region/" + path);

+ 0 - 7
test-plugins/org.yakindu.sct.model.sgraph.test/src/org/yakindu/sct/model/sgraph/test/validation/TransitionValidatorTest.java

@@ -10,7 +10,6 @@
  */
 package org.yakindu.sct.model.sgraph.test.validation;
 
-import static org.yakindu.sct.model.sgraph.validation.TransitionValidator.REGION_ENTRY_TARGET_MUST_BE_CHILD_CODE;
 import static org.yakindu.sct.model.sgraph.validation.TransitionValidator.TRANSITION_SOURCE_NOT_ORTHOGONAL_TO_TARGET_CODE;
 
 import org.junit.Test;
@@ -30,12 +29,6 @@ public class TransitionValidatorTest extends AbstractSGraphValidatorTest {
 	@Inject
 	protected SGraphJavaValidatorTester<TransitionValidator> tester;
 
-	@Test
-	public void initialEntryWithTransitionToContainer() {
-		Statechart statechart = loadStatechart("EntryTransitionToParentState.sct");
-		tester.validate(statechart).assertError(REGION_ENTRY_TARGET_MUST_BE_CHILD_CODE);
-	}
-
 	@Test
 	public void orthogonalTransition_BetweenTopLevelRegions() {
 		Statechart statechart = loadStatechart("OrthogonalTransition01.sct");

test-plugins/org.yakindu.sct.model.sgraph.test/testmodels/transition/EntryTransitionToParentState.sct → test-plugins/org.yakindu.sct.model.sgraph.test/testmodels/region/EntryTransitionToParentState.sct