[5536124] Do not propagate special imports to the Query Legacy
interpreter

Complete initial fix to also handle late interpreter creation: the
special imports might have been declared before the add of the Query
Legacy interpreter to the loadedInterpreter list.

Bug: 526124
Change-Id: I919e08c5cfb28b89841c50f82ef5377b0db75772
Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr>
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/interpreter/SessionInterpreter.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/interpreter/SessionInterpreter.java
index 989ea15..f71d953 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/interpreter/SessionInterpreter.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/interpreter/SessionInterpreter.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2017 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2010, 2018 THALES GLOBAL SERVICES and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -118,18 +118,23 @@
         if (this.dependencies.add(dependency)) {
             for (final IInterpreter interpreter : this.loadedInterpreters.values()) {
                 if (interpreter != null) {
-                    // Is the class imported from one of the white-listed plug-ins (which are not in the normal search path of interpreters)?
-                    boolean isSpecialImport = dependency != null && (dependency.startsWith("org.eclipse.sirius.properties.") || dependency.startsWith("org.eclipse.sirius.common.")); //$NON-NLS-1$ //$NON-NLS-2$
-                    // Is the target interpreter the legacy one, which does not support the plug-ins white list?
-                    boolean isTargetLegacyInterpreter = interpreter.getClass().getName().startsWith("org.eclipse.sirius.query.legacy."); //$NON-NLS-1$
-                    if (!isSpecialImport || !isTargetLegacyInterpreter) {
-                        interpreter.addImport(dependency);
-                    }
+                    safeAddImport(interpreter, dependency);
                 }
             }
         }
     }
 
+    private void safeAddImport(final IInterpreter interpreter, final String dependency) {
+        // Is the class imported from one of the white-listed plug-ins (which are not in the normal search path of
+        // interpreters)?
+        boolean isSpecialImport = dependency != null && (dependency.startsWith("org.eclipse.sirius.properties.") || dependency.startsWith("org.eclipse.sirius.common.")); //$NON-NLS-1$ //$NON-NLS-2$
+        // Is the target interpreter the legacy one, which does not support the plug-ins white list?
+        boolean isTargetLegacyInterpreter = interpreter.getClass().getName().startsWith("org.eclipse.sirius.query.legacy."); //$NON-NLS-1$
+        if (!isSpecialImport || !isTargetLegacyInterpreter) {
+            interpreter.addImport(dependency);
+        }
+    }
+
     @Override
     public void clearImports() {
         this.dependencies.clear();
@@ -329,7 +334,7 @@
                 result.clearImports();
             }
             for (final String dependency : this.dependencies) {
-                result.addImport(dependency);
+                safeAddImport(result, dependency);
             }
             result.activateMetamodels(additionalMetamodels);
             this.variables.setVariables(result);