Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 198f5ac6e756ddc29771c668161e92332ce90728 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package org.eclipse.emf.edapt.declaration.inheritance;

import java.util.List;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.EcorePackage;
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.Metamodel;
import org.eclipse.emf.edapt.spi.migration.Model;

/**
 * {@description}
 *
 * @author herrmama
 * @author $Author$
 * @version $Rev$
 * @levd.rating YELLOW Hash: B38C02821017F9D5B8560A3C5C3DD4B5
 */
@EdaptOperation(identifier = "pullOperation", label = "Pull up Operation", description = "In the metamodel, a number of operations are pulled up into a common super class. In the model, nothing needs to be done.")
public class PullOperation extends OperationImplementation {

	/** {@description} */
	@EdaptParameter(main = true, description = "The operations to be pulled up")
	public List<EOperation> operations;

	/** {@description} */
	@EdaptParameter(description = "The super class to which the operations are pulled")
	public EClass targetClass;

	/** {@description} */
	@EdaptConstraint(restricts = "targetClass", description = "The operations' classes must have a common super type")
	public boolean checkTargetClass(EClass targetClass) {
		for (final EOperation operation : operations) {
			if (!operation.getEContainingClass().getESuperTypes().contains(
				targetClass)) {
				return false;
			}
		}
		return true;
	}

	/** {@description} */
	@EdaptConstraint(description = "The operations' multiplicities have to be the same")
	public boolean checkOperationsSameMultiplicity() {
		return hasSameValue(operations, EcorePackage.eINSTANCE
			.getETypedElement_LowerBound())
			&& hasSameValue(operations, EcorePackage.eINSTANCE
				.getETypedElement_UpperBound());
	}

	/** {@description} */
	@EdaptConstraint(description = "The operations' types have to be the same")
	public boolean checkOperationsSameType() {
		return hasSameValue(operations, EcorePackage.eINSTANCE
			.getETypedElement_EType());
	}

	/** {@inheritDoc} */
	@Override
	public void initialize(Metamodel metamodel) {
		if (targetClass == null) {
			final List<EClass> superTypes = operations.get(0).getEContainingClass()
				.getESuperTypes();
			if (!superTypes.isEmpty()) {
				targetClass = superTypes.get(0);
			}
		}
	}

	/** {@inheritDoc} */
	@Override
	public void execute(Metamodel metamodel, Model model) {
		// variables
		final EOperation mainOperation = operations.get(0);

		// metamodel adaptation
		targetClass.getEOperations().add(mainOperation);
		for (final EOperation operation : operations) {
			if (operation != mainOperation) {
				metamodel.delete(operation);
			}
		}
	}
}

Back to the top