Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4a60ba1b32f5dec4351fd7aa0b0a5cc0af2c2a20 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package org.eclipse.emf.edapt.declaration.inheritance;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.edapt.declaration.EdaptConstraint;
import org.eclipse.emf.edapt.declaration.EdaptOperation;
import org.eclipse.emf.edapt.declaration.EdaptParameter;
import org.eclipse.emf.edapt.declaration.OperationImplementation;
import org.eclipse.emf.edapt.internal.common.MetamodelUtils;
import org.eclipse.emf.edapt.spi.migration.Instance;
import org.eclipse.emf.edapt.spi.migration.Metamodel;
import org.eclipse.emf.edapt.spi.migration.Model;

/**
 * {@description}
 *
 * @author herrmama
 * @author $Author$
 * @version $Rev$
 * @levd.rating YELLOW Hash: F68EFAD9047D85BBB05F8215A441EA75
 */
@EdaptOperation(identifier = "inlineSubClass", label = "Inline Sub Class", description = "In the metamodel, the sub class is deleted. In the model, all instances of this sub class are migrated to its super class.")
public class InlineSubClass extends OperationImplementation {

	/** {@description} */
	@EdaptParameter(main = true, description = "The class to be inlined")
	public EClass subClass;

	/** {@description} */
	@EdaptConstraint(restricts = "subClass", description = "The super class must not be abstract")
	public boolean checkSubClass(EClass subClass) {
		return MetamodelUtils.isConcrete(subClass.getESuperTypes().get(0));
	}

	/** {@description} */
	@EdaptConstraint(restricts = "subClass", description = "The sub class must have exactly one super type")
	public boolean checkSubClassSingleSuperType(EClass subClass) {
		return subClass.getESuperTypes().size() == 1;
	}

	/** {@description} */
	@EdaptConstraint(restricts = "subClass", description = "The sub class must not have features")
	public boolean checkSubClassNoFeatures(EClass subClass) {
		return subClass.getEStructuralFeatures().isEmpty();
	}

	/** {@description} */
	@EdaptConstraint(restricts = "subClass", description = "The sub class must not have sub types")
	public boolean checkSubClassNoSubTypes(EClass subClass, Metamodel metamodel) {
		return metamodel.getESubTypes(subClass).isEmpty();
	}

	/** {@inheritDoc} */
	@Override
	public void execute(Metamodel metamodel, Model model) {
		final EClass superClass = subClass.getESuperTypes().get(0);

		// metamodel adaptation
		metamodel.delete(subClass);

		// model migration
		for (final Instance instance : model.getAllInstances(subClass)) {
			instance.migrate(superClass);
		}
	}
}

Back to the top