Jelajahi Sumber

Added validation for detecting othogonality of synchronized transitions.

Axel Terfloth 10 tahun lalu
induk
melakukan
8daedde4ef

+ 62 - 24
plugins/org.yakindu.sct.model.sgraph/src/org/yakindu/sct/model/sgraph/validation/SGraphJavaValidator.java

@@ -298,8 +298,7 @@ public class SGraphJavaValidator extends AbstractDeclarativeValidator {
 
 	}
 
-	@Check(CheckType.FAST)
-	public void orthogonalTransition(Transition transition) {
+	@Check public void orthogonalTransition(Transition transition) {
 		
 		Vertex source = transition.getSource();
 		Vertex target = transition.getTarget();
@@ -315,6 +314,67 @@ public class SGraphJavaValidator extends AbstractDeclarativeValidator {
 	}
 	
 	
+	@Check public void orthogonalSourceStates(Synchronization sync) {
+		
+		List<Vertex> sourceVertices = sources(sync.getIncomingTransitions());
+		
+		if ( ! areOrthogonal(sourceVertices) ) {
+			error(ISSUE_SYNCHRONIZATION_SOURCE_STATES_NOT_ORTHOGONAL, sync, null, -1);
+		}
+	}
+
+	
+
+	@Check public void orthogonalTargetStates(Synchronization sync) {
+		
+		List<Vertex> sourceVertices = targets(sync.getOutgoingTransitions());
+		
+		if ( ! areOrthogonal(sourceVertices) ) {
+			error(ISSUE_SYNCHRONIZATION_TARGET_STATES_NOT_ORTHOGONAL, sync, null, -1);
+		}
+	}
+
+	
+
+	@Check public void orthogonalSynchronizedTransition(Synchronization sync) {
+		
+		List<Transition> incoming = sync.getIncomingTransitions();		
+		List<List<EObject>> inAncestorsList = new ArrayList<List<EObject>>();
+		for (Transition trans : incoming) { inAncestorsList.add(collectAncestors(trans.getSource(), new ArrayList<EObject>())); }
+
+		List<Transition> outgoing = sync.getOutgoingTransitions();
+		List<List<EObject>> outAncestorsList = new ArrayList<List<EObject>>(); 
+		for (Transition trans : outgoing) { outAncestorsList.add(collectAncestors(trans.getTarget(), new ArrayList<EObject>())); }
+				
+		
+		Set<Transition> inOrthogonal = new HashSet<Transition>(incoming);
+		Set<Transition> outOrthogonal = new HashSet<Transition>(outgoing);
+		
+		for ( int i=0; i<incoming.size(); i++) {
+			for ( int j=0; j<outgoing.size(); j++ ) {
+				
+				EObject commonAncestor = findCommonAncestor(inAncestorsList.get(i), outAncestorsList.get(j));
+
+				if ( commonAncestor instanceof Region ) {					
+					inOrthogonal.remove(incoming.get(i));
+					outOrthogonal.remove(outgoing.get(j));
+				}
+			}
+		}
+
+		for ( Transition trans : inOrthogonal ) {
+			error(ISSUE_SYNCHRONIZATION_SOURCE_STATES_NOT_WITHIN_SAME_PARENTSTATE, trans, null, -1);				
+		}
+		
+		for ( Transition trans : outOrthogonal ) {
+			error(ISSUE_SYNCHRONIZATION_TARGET_STATES_NOT_WITHIN_SAME_PARENTSTATE, trans, null, -1);				
+		}
+		
+	}
+	
+	
+	
+	
 	/**
 	 * Calculates the common ancestor of to EObjects. The calculation first calculates the ancestors for both objects and compares the lists starting from the root. 
 	 * The last same element is the common ancestor.
@@ -369,28 +429,6 @@ public class SGraphJavaValidator extends AbstractDeclarativeValidator {
 	}
 	
 
-	@Check(CheckType.FAST)
-	public void orthogonalSourceStates(Synchronization sync) {
-		
-		List<Vertex> sourceVertices = sources(sync.getIncomingTransitions());
-		
-		if ( ! areOrthogonal(sourceVertices) ) {
-			error(ISSUE_SYNCHRONIZATION_SOURCE_STATES_NOT_ORTHOGONAL + "_new_", sync, null, -1);
-		}
-	}
-
-	
-	@Check(CheckType.FAST)
-	public void orthogonalTargetStates(Synchronization sync) {
-		
-		List<Vertex> sourceVertices = targets(sync.getOutgoingTransitions());
-		
-		if ( ! areOrthogonal(sourceVertices) ) {
-			error(ISSUE_SYNCHRONIZATION_TARGET_STATES_NOT_ORTHOGONAL + "_new_", sync, null, -1);
-		}
-	}
-
-	
 	protected boolean areOrthogonal(List<Vertex> vertices) {
 		
 		if (vertices == null || vertices.isEmpty()) return true;

+ 9 - 8
test-plugins/org.yakindu.sct.model.sgraph.test/src/org/yakindu/sct/model/sgraph/test/SGraphJavaValidationTest.java

@@ -579,8 +579,7 @@ public class SGraphJavaValidationTest {
 		assertWarning(diagnostics, ISSUE_SYNCHRONIZATION_TRANSITION_COUNT);
 	}
 
-	@Test
-	public void orthogonalStates() {
+	@Test public void orthogonalStates() {
 		statechart = AbstractTestModelsUtil
 				.loadStatechart(VALIDATION_TESTMODEL_DIR
 						+ "NotOrthogonalRegion01.sct");
@@ -598,12 +597,13 @@ public class SGraphJavaValidationTest {
 				ISSUE_SYNCHRONIZATION_SOURCE_STATES_NOT_ORTHOGONAL);
 		assertError(diagnostics,
 				ISSUE_SYNCHRONIZATION_TARGET_STATES_NOT_ORTHOGONAL);
+	}
 
-		diagnostics = new BasicDiagnostic();
+	@Test public void orthogonalState_2() {
 		statechart = AbstractTestModelsUtil
 				.loadStatechart(VALIDATION_TESTMODEL_DIR
 						+ "NotOrthogonalRegion02.sct");
-		iter = statechart.eAllContents();
+		Iterator<EObject> iter = statechart.eAllContents();
 		while (iter.hasNext()) {
 			EObject element = iter.next();
 			if (element instanceof Synchronization) {
@@ -614,15 +614,16 @@ public class SGraphJavaValidationTest {
 
 		assertIssueCount(diagnostics, 2);
 		assertError(diagnostics,
-				ISSUE_SYNCHRONIZATION_SOURCE_STATES_NOT_WITHIN_SAME_PARENTSTATE);
+				ISSUE_SYNCHRONIZATION_SOURCE_STATES_NOT_ORTHOGONAL);
 		assertError(diagnostics,
-				ISSUE_SYNCHRONIZATION_TARGET_STATES_NOT_WITHIN_SAME_PARENTSTATE);
+				ISSUE_SYNCHRONIZATION_TARGET_STATES_NOT_ORTHOGONAL);
+	}
 
-		diagnostics = new BasicDiagnostic();
+	@Test public void orthogonalState_3() {
 		statechart = AbstractTestModelsUtil
 				.loadStatechart(VALIDATION_TESTMODEL_DIR
 						+ "NotOrthogonalRegion03.sct");
-		iter = statechart.eAllContents();
+		Iterator<EObject> iter = statechart.eAllContents();
 		while (iter.hasNext()) {
 			EObject element = iter.next();
 			if (element instanceof Synchronization) {