Bug 515386: [Compare] Implement workaround to avoid dependency cycle

Originally we wanted to add a bi-directional requirement between
umlrtDiagramChange and umlrtDiagramChange.getSemanticDiff(). However, we
run into dependency cycles that eventually break the diagram.

As a workaround we add a bi-directional dependency between
umlrtDiagramChange and the diff that refines
umlrtDiagramChange.getSemanticDiff().

Change-Id: I8a5c8751257cf275be654242cfede33ca295b54a
Signed-off-by: Philip Langer <planger@eclipsesource.com>
diff --git a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.compare/src/org/eclipse/papyrusrt/umlrt/tooling/compare/internal/UMLRTPostProcessor.java b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.compare/src/org/eclipse/papyrusrt/umlrt/tooling/compare/internal/UMLRTPostProcessor.java
index 3676cec..efb723b 100644
--- a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.compare/src/org/eclipse/papyrusrt/umlrt/tooling/compare/internal/UMLRTPostProcessor.java
+++ b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.compare/src/org/eclipse/papyrusrt/umlrt/tooling/compare/internal/UMLRTPostProcessor.java
@@ -112,7 +112,16 @@
 			while (diagramChangeIterator.hasNext()) {
 				final UMLRTDiagramChange umlrtDiagramChange = diagramChangeIterator.next();
 				if (umlrtDiagramChange.getSemanticDiff() != null) {
-					addBidirectionalRequirement(umlrtDiagramChange, umlrtDiagramChange.getSemanticDiff());
+					// Originally we wanted to add a bi-directional requirement between umlrtDiagramChange and
+					// umlrtDiagramChange.getSemanticDiff(). However, we run into dependency cycles that eventually
+					// break the diagram (see bug 515386).
+					// As a workaround we add a bi-directional dependency between umlrtDiagramChange and the diff that
+					// refines umlrtDiagramChange.getSemanticDiff(), unless there is no refined diff.
+					if (!umlrtDiagramChange.getSemanticDiff().getRefines().isEmpty()) {
+						addBidirectionalRequirement(umlrtDiagramChange, umlrtDiagramChange.getSemanticDiff().getRefines().get(0));
+					} else {
+						addBidirectionalRequirement(umlrtDiagramChange, umlrtDiagramChange.getSemanticDiff());
+					}
 				}
 			}
 		}