From 7a8aa7205b1b32e58132884fa9b29edbbefa0598 Mon Sep 17 00:00:00 2001
From: Sebastian Krings <sebastian@krin.gs>
Date: Wed, 16 Jan 2013 14:06:53 +0100
Subject: [PATCH] copy over attributes on machines

---
 .../units/sc/MachineAttributeProcessor.java   | 37 ++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/de.prob.units/src/de/prob/units/sc/MachineAttributeProcessor.java b/de.prob.units/src/de/prob/units/sc/MachineAttributeProcessor.java
index 41ea2406..c6d81b40 100644
--- a/de.prob.units/src/de/prob/units/sc/MachineAttributeProcessor.java
+++ b/de.prob.units/src/de/prob/units/sc/MachineAttributeProcessor.java
@@ -2,14 +2,20 @@ package de.prob.units.sc;
 
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eventb.core.IMachineRoot;
+import org.eventb.core.ISCVariable;
+import org.eventb.core.IVariable;
+import org.eventb.core.basis.SCMachineRoot;
 import org.eventb.core.sc.SCCore;
 import org.eventb.core.sc.SCProcessorModule;
 import org.eventb.core.sc.state.ISCStateRepository;
 import org.eventb.core.tool.IModuleType;
 import org.rodinp.core.IInternalElement;
 import org.rodinp.core.IRodinElement;
+import org.rodinp.core.IRodinFile;
 
 import de.prob.units.Activator;
+import de.prob.units.pragmas.UnitPragmaAttribute;
 
 public class MachineAttributeProcessor extends SCProcessorModule {
 	public static final IModuleType<MachineAttributeProcessor> MODULE_TYPE = SCCore
@@ -19,7 +25,36 @@ public class MachineAttributeProcessor extends SCProcessorModule {
 	public void process(IRodinElement element, IInternalElement target,
 			ISCStateRepository repository, IProgressMonitor monitor)
 			throws CoreException {
-		System.out.println("blah");
+		assert (element instanceof IRodinFile);
+		assert (target instanceof SCMachineRoot);
+
+		// get all variables and copy over the attributes
+		IRodinFile machineFile = (IRodinFile) element;
+		IMachineRoot machineRoot = (IMachineRoot) machineFile.getRoot();
+
+		SCMachineRoot scMachineRoot = (SCMachineRoot) target;
+
+		IVariable[] variables = machineRoot.getVariables();
+
+		if (variables.length == 0)
+			return;
+
+		for (IVariable var : variables) {
+			ISCVariable scVar = scMachineRoot.getSCVariable(var
+					.getIdentifierString());
+
+			// might have been filtered out by previous modules
+			if (scVar != null) {
+				// original might not contain the attribute
+				if (var.hasAttribute(UnitPragmaAttribute.ATTRIBUTE)) {
+					String attribute = var
+							.getAttributeValue(UnitPragmaAttribute.ATTRIBUTE);
+
+					scVar.setAttributeValue(UnitPragmaAttribute.ATTRIBUTE,
+							attribute, monitor);
+				}
+			}
+		}
 
 	}
 
-- 
GitLab