Commit a310ca6f authored by Simon Barner's avatar Simon Barner
Browse files

Eliminate org.fortiss.tooling.kernel.utils.MigrationUtils:

- removed deleteAllElementsWithType()
- moved featuresToStrings() to MigrationService
refs 3243
parent 63467a17
......@@ -7,7 +7,7 @@ ElementCompositorService.java feab3d996d7c61e4cb17bd9e990a8d944e52180d GREEN
LibraryPrototypeProvider.java 039d75d5d972e1fd304577e29f82f95e2081255e GREEN
LibraryService.java 9942eb2b7c72f8be705bb979f02de45e55175ba5 GREEN
LoggingService.java ef00b8767f3426ef9568fb5009193034f2967dd4 GREEN
MigrationService.java c542f63a382ab42f36ca82b4d4d32ef6a825aad2 GREEN
MigrationService.java 8734ff320da8055af383bcfd1b51baa67fb121a5 YELLOW
PersistencyService.java 1f06159177e6247083a4ea5baaf8476ea38bc213 GREEN
PrototypeService.java 8f40bc1b1a6d597dbc3ac01c96d9e4fb1e829a58 GREEN
ToolingKernelInternal.java dc4030eadc737ca3c10a8095751f94dab316739c GREEN
......
......@@ -17,13 +17,14 @@ package org.fortiss.tooling.kernel.internal;
import static java.util.Collections.emptyList;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import static org.fortiss.tooling.kernel.utils.MigrationUtils.featuresToStrings;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.FeatureMap;
import org.eclipse.emf.ecore.xml.type.AnyType;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.extension.IMigrationProvider;
......@@ -88,6 +89,19 @@ public class MigrationService extends ObjectAwareServiceBase<IMigrationProvider>
return getProvider(input, unknownFeatures) != null;
}
/** Extracts the list of feature names from a map of features. */
private List<String> featuresToStrings(Map<EObject, AnyType> features) {
List<String> res = new BasicEList<String>();
for(AnyType featuresPerKey : features.values()) {
FeatureMap actualFeatures = featuresPerKey.getMixed();
actualFeatures.addAll(featuresPerKey.getAnyAttribute());
for(FeatureMap.Entry feature : actualFeatures) {
res.add(feature.getEStructuralFeature().getName());
}
}
return res;
}
/** {@inheritDoc} */
@Override
public void migrate(final ITopLevelElement input, final Map<EObject, AnyType> unknownFeatures) {
......
......@@ -8,7 +8,6 @@ IdentifierUtils.java d074a0f40d0ace7c2dd4ec145f0c2d783fbe115d GREEN
JavaUtils.java 88bebee35226100989e118b272c766fa63f3c87c YELLOW
KernelModelElementUtils.java c40d78a15046637061ad84a16c8511376ff3d8ba GREEN
LoggingUtils.java 53c7a8eaa6955112bd1890e0a5ca5437013ccb02 GREEN
MigrationUtils.java e54370b19148ff656d7563e8188baccd947c24d5 GREEN
PrototypesUtils.java 538b5edbab06e95bc32e81309482e36a4bc64d1e GREEN
ResourceUtils.java 8ab06ad3b72fdb2b1925e2ccbedcfea35e36cf24 GREEN
TransformationUtils.java f159b17ac1ce2ce0d94c1a873d74e052ac2dc74b GREEN
......
/*-------------------------------------------------------------------------+
| Copyright 2013 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.kernel.utils;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getChildrenWithType;
import java.util.List;
import java.util.Map;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.FeatureMap;
import org.eclipse.emf.ecore.xml.type.AnyType;
/**
* Utility methods for the migrators.
*
* @author voss
*/
public class MigrationUtils {
/**
* Recursively delete all elements with a certain type from a certain scope.
*
* @param parent
* - the parent containing elements to be deleted
* @param clazz
* - the class of the elements to be deleted
*/
@SuppressWarnings("unchecked")
public static void deleteAllElementsWithType(EObject parent, Class<? extends EObject> clazz) {
EList<EObject> elems = (EList<EObject>)(EList<?>)getChildrenWithType(parent, clazz);
for(EObject obj : elems) {
EcoreUtil.delete(obj);
}
}
/** Extracts the list of feature names from a map of features. */
public static List<String> featuresToStrings(Map<EObject, AnyType> features) {
List<String> res = new BasicEList<String>();
for(AnyType featuresPerKey : features.values()) {
FeatureMap actualFeatures = featuresPerKey.getMixed();
actualFeatures.addAll(featuresPerKey.getAnyAttribute());
for(FeatureMap.Entry feature : actualFeatures) {
res.add(feature.getEStructuralFeature().getName());
}
}
return res;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment