[578030] Fix import / this domain references
diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvts2qvti/QVTs2QVTi.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvts2qvti/QVTs2QVTi.java
index 528d518..cdefb76 100644
--- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvts2qvti/QVTs2QVTi.java
+++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvts2qvti/QVTs2QVTi.java
@@ -31,6 +31,7 @@
 import org.eclipse.ocl.pivot.Package;
 import org.eclipse.ocl.pivot.Property;
 import org.eclipse.ocl.pivot.PropertyCallExp;
+import org.eclipse.ocl.pivot.internal.manager.Orphanage;
 import org.eclipse.ocl.pivot.utilities.ClassUtil;
 import org.eclipse.ocl.pivot.utilities.NameUtil;
 import org.eclipse.ocl.pivot.utilities.PivotUtil;
@@ -208,16 +209,18 @@
 		Collections.sort(sortedImportedNamespaces, NameUtil.NAMEABLE_COMPARATOR);
 		List<Import> ownedImports = model.getOwnedImports();
 		for (@NonNull Namespace importedNamespace : sortedImportedNamespaces) {
-			SymbolNameBuilder s = new SymbolNameBuilder();
-			s.appendString("mm_");
-			//			for (@NonNull String partialName : partialNames) {
-			//				s.appendString("_");
-			//				s.appendName(partialName);
-			//			}
-			s.appendName(importedNamespace.getName());
-			s.appendName("MM");
-			String name = model.reserveSymbolName(s, importedNamespace);
-			ownedImports.add(createImport(name, importedNamespace));	// FIXME BUG 530025 bad aliases
+			if (!(importedNamespace instanceof org.eclipse.ocl.pivot.Package) || !Orphanage.isTypeOrphanage((org.eclipse.ocl.pivot.Package)importedNamespace)) {
+				SymbolNameBuilder s = new SymbolNameBuilder();
+				s.appendString("mm_");
+				//			for (@NonNull String partialName : partialNames) {
+				//				s.appendString("_");
+				//				s.appendName(partialName);
+				//			}
+				s.appendName(importedNamespace.getName());
+				s.appendName("MM");
+				String name = model.reserveSymbolName(s, importedNamespace);
+				ownedImports.add(createImport(name, importedNamespace));	// FIXME BUG 530025 bad aliases
+			}
 		}
 	}
 
diff --git a/plugins/org.eclipse.qvtd.pivot.qvtrelation/src/org/eclipse/qvtd/pivot/qvtrelation/utilities/QVTrelationUtil.java b/plugins/org.eclipse.qvtd.pivot.qvtrelation/src/org/eclipse/qvtd/pivot/qvtrelation/utilities/QVTrelationUtil.java
index 4e3acd9..b439dbd 100644
--- a/plugins/org.eclipse.qvtd.pivot.qvtrelation/src/org/eclipse/qvtd/pivot/qvtrelation/utilities/QVTrelationUtil.java
+++ b/plugins/org.eclipse.qvtd.pivot.qvtrelation/src/org/eclipse/qvtd/pivot/qvtrelation/utilities/QVTrelationUtil.java
@@ -440,7 +440,7 @@
 	}
 
 	/**
-	 * Rewrite asResource to replace ensure that each RelationalTransformation has a $trace$ TypedModel and each
+	 * Rewrite asResource to ensure that each RelationalTransformation has $primitove&, $this$, $trace$ TypedModel and each
 	 * Relation has a $trace$ SharedVariable..
 	 */
 	public static boolean rewriteMissingTraceArtefacts(@NonNull EnvironmentFactory environmentFactory, @NonNull Resource asResource) {
@@ -465,6 +465,13 @@
 					}
 					modelParameters.add(0, helper.createPrimitiveTypedModel());
 				}
+				TypedModel thisTypedModel = QVTbaseUtil.basicGetThisTypedModel(modelParameters);
+				if (thisTypedModel == null) {
+					if (helper == null) {
+						helper = new QVTrelationHelper(environmentFactory);
+					}
+					modelParameters.add(1, helper.createThisTypedModel());
+				}
 			}
 			if (eObject instanceof Relation) {
 				VariableDeclaration traceClassVariable = null;
@@ -488,6 +495,6 @@
 				}
 			}
 		}
-		return helper != null;
+		return false; //helper != null;
 	}
 }
\ No newline at end of file