[508556] Type source/target/xxView variables in
ReconnectEdgeDescription.precondition

Add the code and supporting test case so that the source/target/xxView
variables
which is available in ReconnectEdgeDescription have a more specific type
based on the mappings which are referenced by the tool.

Bug : 508556
Change-Id: Ibb0e30a6595e9a19a8a2ad11aed11de07664421c
Signed-off-by: jmallet <jessy.mallet@obeo.fr>
diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/description/DiagramInterpretedExpressionQuery.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/description/DiagramInterpretedExpressionQuery.java
index 31554b4..615344e 100644
--- a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/description/DiagramInterpretedExpressionQuery.java
+++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/description/DiagramInterpretedExpressionQuery.java
@@ -16,6 +16,7 @@
 import java.util.Map.Entry;
 import java.util.Set;
 
+import org.eclipse.emf.common.util.EList;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.EPackage;
 import org.eclipse.emf.ecore.EStructuralFeature;
@@ -265,9 +266,7 @@
             refineVariableType(availableVariables, SELF, possibleSemanticTypes);
         }
         if (target instanceof ReconnectEdgeDescription && this.feature == ToolPackage.Literals.ABSTRACT_TOOL_DESCRIPTION__PRECONDITION) {
-            Collection<String> possibleContainerTypes = Sets.newLinkedHashSet();
-            collectPotentialContainerTypes(possibleContainerTypes, Sets.<String> newLinkedHashSet(), ((ReconnectEdgeDescription) target).getMappings());
-            availableVariables.put(IInterpreterSiriusVariables.CONTAINER, VariableType.fromStrings(possibleContainerTypes));
+            collectReconnectEdgeDescriptionVariableTypes(availableVariables);
         }
         if (target instanceof RepresentationCreationDescription) {
             typeVariablesForDiagramCreationRepresentation((RepresentationCreationDescription) target, availableVariables);
@@ -631,6 +630,31 @@
         }
     }
 
+    private void collectReconnectEdgeDescriptionVariableTypes(Map<String, VariableType> availableVariables) {
+        Collection<String> possibleContainerTypes = Sets.newLinkedHashSet();
+        EList<EdgeMapping> mappings = ((ReconnectEdgeDescription) target).getMappings();
+        collectPotentialContainerTypes(possibleContainerTypes, Sets.<String> newLinkedHashSet(), mappings);
+        availableVariables.put(IInterpreterSiriusVariables.CONTAINER, VariableType.fromStrings(possibleContainerTypes));
+
+        Set<String> sourceSemanticType = Sets.newLinkedHashSet();
+        Set<String> sourceViewType = Sets.newLinkedHashSet();
+        Set<String> targetSemanticType = Sets.newLinkedHashSet();
+        Set<String> targetViewType = Sets.newLinkedHashSet();
+        for (EdgeMapping edgeMapping : mappings) {
+            for (DiagramElementMapping m : edgeMapping.getSourceMapping()) {
+                collectTypes(sourceSemanticType, sourceViewType, m);
+            }
+            for (DiagramElementMapping m : edgeMapping.getTargetMapping()) {
+                collectTypes(targetSemanticType, targetViewType, m);
+            }
+        }
+        availableVariables.put(IInterpreterSiriusVariables.SOURCE, VariableType.fromStrings(sourceSemanticType));
+        availableVariables.put(IInterpreterSiriusVariables.SOURCE_VIEW, VariableType.fromStrings(sourceViewType));
+        availableVariables.put(IInterpreterSiriusVariables.TARGET, VariableType.fromStrings(targetSemanticType));
+        availableVariables.put(IInterpreterSiriusVariables.TARGET_VIEW, VariableType.fromStrings(targetViewType));
+        availableVariables.put(IInterpreterSiriusVariables.DIAGRAM, VariableType.fromString(DIAGRAM_D_SEMANTIC_DIAGRAM));
+    }
+
     /**
      * An {@link IInterpretedExpressionTargetSwitch} that delegates to the defaultSwitch or the diagram specific switch,
      * according to the package of the considered element.
diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/validateVariableTypes.odesign b/plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/validateVariableTypes.odesign
index eff50a7..68d7054 100644
--- a/plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/validateVariableTypes.odesign
+++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/validateVariableTypes.odesign
@@ -519,7 +519,7 @@
               </firstModelOperations>
             </initialOperation>
           </ownedTools>
-          <ownedTools xsi:type="tool_1:ReconnectEdgeDescription" name="Reconnect participantnode to interaction node" precondition="aql:container.ownedInteractions->size() > 0" reconnectionKind="RECONNECT_BOTH">
+          <ownedTools xsi:type="tool_1:ReconnectEdgeDescription" name="Reconnect participantnode to interaction node" precondition="aql:container.ownedInteractions->size() > 0 and source.type &lt;> null and target.messages->size() > 0 and diagram&lt;>null and sourceView &lt;>null and targetView&lt;>null " reconnectionKind="RECONNECT_BOTH">
             <source name="source"/>
             <target name="target"/>
             <sourceView name="sourceView"/>