Skip to content

Package: AddedDMRToTableDMRMigration

AddedDMRToTableDMRMigration

nameinstructionbranchcomplexitylinemethod
AddedDMRToTableDMRMigration()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getEPackageWithNSPrefix(Metamodel, String)
M: 2 C: 19
90%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 3
75%
M: 0 C: 1
100%
migrateAfter(Model, Metamodel)
M: 0 C: 65
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 15
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Johannes Faltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.table.edapt._140to150;
15:
16: import org.eclipse.emf.common.util.EList;
17: import org.eclipse.emf.ecore.EClass;
18: import org.eclipse.emf.ecore.EPackage;
19: import org.eclipse.emf.ecore.EReference;
20: import org.eclipse.emf.edapt.migration.CustomMigration;
21: import org.eclipse.emf.edapt.migration.MigrationException;
22: import org.eclipse.emf.edapt.spi.migration.Instance;
23: import org.eclipse.emf.edapt.spi.migration.Metamodel;
24: import org.eclipse.emf.edapt.spi.migration.Model;
25:
26: /**
27: * Before 1.5.0 a table domain model reference was simply a subclass of feature path domain model reference. This made
28: * it impossible to use a different dmr to reach the multi reference. Starting with 1.5.0. it is possible to set a
29: * different dmr leading to the multi reference on the table dmr. This migration creates a feature path dmr with the old
30: * values on the table.
31: *
32: * @author jfaltermeier
33: *
34: */
35: public class AddedDMRToTableDMRMigration extends CustomMigration {
36:
37:         @Override
38:         public void migrateAfter(Model model, Metamodel metamodel)
39:                 throws MigrationException {
40:                 final EPackage viewPkg = getEPackageWithNSPrefix(metamodel, "org.eclipse.emf.ecp.view.model"); //$NON-NLS-1$
41:                 final EClass featurePathDMREClass = (EClass) viewPkg.getEClassifier("FeaturePathDomainModelReference"); //$NON-NLS-1$
42:                 final EReference feature = (EReference) featurePathDMREClass.getEStructuralFeature("domainModelEFeature"); //$NON-NLS-1$
43:                 final EReference path = (EReference) featurePathDMREClass.getEStructuralFeature("domainModelEReferencePath"); //$NON-NLS-1$
44:                 final EList<Instance> allTableDMRs = model.getAllInstances("table.TableDomainModelReference"); //$NON-NLS-1$
45:•                for (final Instance tableDMR : allTableDMRs) {
46:•                        if (null == tableDMR.get(feature)) {
47:                                 continue;
48:                         }
49:                         final Instance childDMR = model.newInstance(featurePathDMREClass);
50:                         final Object featureInstance = tableDMR.unset(feature);
51:                         final Object pathInstance = tableDMR.unset(path);
52:                         childDMR.set(feature, featureInstance);
53:                         childDMR.set(path, pathInstance);
54:                         tableDMR.set("domainModelReference", childDMR); //$NON-NLS-1$
55:                 }
56:         }
57:
58:         private EPackage getEPackageWithNSPrefix(Metamodel metamodel, String nsPrefix) {
59:•                for (final EPackage pkg : metamodel.getEPackages()) {
60:•                        if (nsPrefix.equals(pkg.getNsPrefix())) {
61:                                 return pkg;
62:                         }
63:                 }
64:                 return null;
65:         }
66:
67: }