Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b07c372f8fc1095174322df145a48b1ff2bfe91e (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
package org.eclipse.emf.edapt.declaration.simple;

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.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: F1B800B5BE3D5AD4D920562EFA551982
 */
@EdaptOperation(identifier = "makeAbstract", label = "Make Class Abstract", description = "In the metamodel, a class is made abstract. In a model, instances of this class are migrated to a chosen subclass.", breaking = true)
public class MakeAbstract extends OperationImplementation {

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

	/** {@description} */
	@EdaptConstraint(restricts = "eClass", description = "The class is already abstract")
	public boolean checkClassAbstract(EClass eClass) {
		return !eClass.isAbstract();
	}

	/** {@description} */
	@EdaptParameter(description = "The subclass to which instances are migrated")
	public EClass subClass;

	/** {@description} */
	@EdaptConstraint(restricts = "subClass", description = "The class has to be a super type of the sub class")
	public boolean checkSubClass(EClass subClass) {
		return subClass.getEAllSuperTypes().contains(eClass);
	}

	/** {@inheritDoc} */
	@Override
	public void execute(Metamodel metamodel, Model model) {
		// metamodel adaptation
		eClass.setAbstract(true);

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

Back to the top