From 1b5d425fd03bd7ffe606565cd4a56241f57c1cc8 Mon Sep 17 00:00:00 2001
From: Simon Barner <barner@fortiss.org>
Date: Fri, 9 Mar 2018 15:58:29 +0000
Subject: [PATCH] - Register MemoryPerNode and PowerConsumption only for  *
 org.fortiss.af3.platform.model.generic.GenericExecutionUnit (changed - from
 ExecutionUnit)  * org.fortiss.af3.platform.pikeos.model.Core (as before)

- Add migrators that remove annotation from model elements other than the two mentioned above

- Move registration of MemoryPerNode, PowerConsumption, HardwareCost from af3.exploration.smt to af3.platform
refs 2658
---
 .../trunk/META-INF/MANIFEST.MF                |  1 +
 .../fortiss/tooling/base/migration/.ratings   |  2 +-
 ...edAnnotationInstanceMigrationProvider.java | 78 +++++++++++++++++++
 3 files changed, 80 insertions(+), 1 deletion(-)
 create mode 100644 org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/migration/RemoveOutdatedAnnotationInstanceMigrationProvider.java

diff --git a/org.fortiss.tooling.base/trunk/META-INF/MANIFEST.MF b/org.fortiss.tooling.base/trunk/META-INF/MANIFEST.MF
index 98e348de8..932de64c7 100644
--- a/org.fortiss.tooling.base/trunk/META-INF/MANIFEST.MF
+++ b/org.fortiss.tooling.base/trunk/META-INF/MANIFEST.MF
@@ -18,6 +18,7 @@ Export-Package: org.fortiss.tooling.base,
  org.fortiss.tooling.base.dnd,
  org.fortiss.tooling.base.layout,
  org.fortiss.tooling.base.library,
+ org.fortiss.tooling.base.migration,
  org.fortiss.tooling.base.model.base,
  org.fortiss.tooling.base.model.base.impl,
  org.fortiss.tooling.base.model.base.util,
diff --git a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/migration/.ratings b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/migration/.ratings
index b0e4cd495..2744e02d5 100644
--- a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/migration/.ratings
+++ b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/migration/.ratings
@@ -1,3 +1,3 @@
-
 IDMigrationProvider.java 38c9d2df4d810a2875d0e7d56c239af4b72b384c GREEN
 RemoveDuplicatedAnnotationsMigrationProvider.java 0af6b49eaea213ee603000f61687405daf020d88 GREEN
+RemoveOutdatedAnnotationInstanceMigrationProvider.java f7c31a9c3f2af7178434a8dd3bd56c0b4db820ad YELLOW
diff --git a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/migration/RemoveOutdatedAnnotationInstanceMigrationProvider.java b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/migration/RemoveOutdatedAnnotationInstanceMigrationProvider.java
new file mode 100644
index 000000000..29c29f2bb
--- /dev/null
+++ b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/migration/RemoveOutdatedAnnotationInstanceMigrationProvider.java
@@ -0,0 +1,78 @@
+/*-------------------------------------------------------------------------+
+| Copyright 2018 fortiss GmbH                                              |
+|                                                                          |
+| Licensed under the Apache License, Version 2.0 (the "License");          |
+| you may not use this file except in compliance with the License.         |
+| You may obtain a copy of the License at                                  |
+|                                                                          |
+|    http://www.apache.org/licenses/LICENSE-2.0                            |
+|                                                                          |
+| Unless required by applicable law or agreed to in writing, software      |
+| distributed under the License is distributed on an "AS IS" BASIS,        |
+| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+| See the License for the specific language governing permissions and      |
+| limitations under the License.                                           |
++--------------------------------------------------------------------------*/
+package org.fortiss.tooling.base.migration;
+
+import static org.eclipse.emf.ecore.util.EcoreUtil.delete;
+import static org.fortiss.tooling.common.util.LambdaUtils.isAssignableFromAny;
+import static org.fortiss.tooling.kernel.utils.EcoreUtils.getChildrenWithType;
+
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.xml.type.AnyType;
+import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
+import org.fortiss.tooling.base.model.element.IModelElement;
+import org.fortiss.tooling.kernel.extension.IMigrationProvider;
+import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
+
+/**
+ * {@link IMigrationProvider} that ensures that the annotation of the given {@code annotationType}
+ * is only kept for the {@link IModelElement} specializations of the given. From all other
+ * {@link IModelElement} specializations, the annotation instance is removed.
+ * 
+ * @author barner
+ */
+public abstract class RemoveOutdatedAnnotationInstanceMigrationProvider<T extends IAnnotatedSpecification>
+		implements IMigrationProvider {
+	/** Annotation type for which outdated instances should be removed. */
+	private Class<T> annotationType;
+
+	/** List of {@link IModelElement} types for which annotation should be kept. */
+	private List<Class<?>> modelElementTypes;
+
+	/** Constructor. */
+	protected RemoveOutdatedAnnotationInstanceMigrationProvider(Class<T> annotationType,
+			List<Class<?>> modelElementTypes) {
+		this.annotationType = annotationType;
+		this.modelElementTypes = modelElementTypes;
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public boolean needMigration(ITopLevelElement modelElement,
+			Map<EObject, AnyType> unknownFeatures) {
+
+		EObject rootModelElement = modelElement.getRootModelElement();
+		for(T annotation : getChildrenWithType(rootModelElement, annotationType)) {
+			if(!isAssignableFromAny(modelElementTypes, annotation.getSpecificationOf())) {
+				return true;
+			}
+		}
+		return false;
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public void migrate(ITopLevelElement modelElement, Map<EObject, AnyType> unknownFeatures) {
+		EObject rootModelElement = modelElement.getRootModelElement();
+		for(T annotation : getChildrenWithType(rootModelElement, annotationType)) {
+			if(!isAssignableFromAny(modelElementTypes, annotation.getSpecificationOf())) {
+				delete(annotation);
+			}
+		}
+	}
+}
-- 
GitLab