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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/*******************************************************************************
* Copyright (c) 2011, 2012 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.emf.compare.uml2.diff.internal.extension.element;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.compare.diff.metamodel.DiffElement;
import org.eclipse.emf.compare.uml2.diff.UML2DiffEngine;
import org.eclipse.emf.compare.uml2.diff.internal.extension.AbstractDiffExtensionFactory;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.uml2.uml.Element;
/**
* Common factory for UML model element changes.
*
* @see Bug 351593.
* @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
*/
public abstract class AbstractUMLElementChangeFactory extends AbstractDiffExtensionFactory {
/**
* Constructor.
*
* @param engine
* UML2DiffEngine
*/
public AbstractUMLElementChangeFactory(UML2DiffEngine engine) {
super(engine);
}
/**
* Looks for all the stereotype applications inside the given {@link EObject} of the model from the
* specified side. When stereotype applications are found on the child model objects, this returns the
* potential differences, related to these objects, from a given difference type.
*
* @param obj
* The start point to look for child objects on which stereotypes are applied.
* @param crossReferencer
* A cross referencer to look for difference from model objects.
* @param diffSide
* The side from which it is required to look for:
* DiffPackage.Literals.UPDATE_MODEL_ELEMENT__LEFT_ELEMENT or
* DiffPackage.Literals.UPDATE_MODEL_ELEMENT__RIGHT_ELEMENT
* @param expectedDiff
* The type of difference to look for:
* UML2DiffPackage.Literals.UML_STEREOTYPE_APPLICATION_ADDITION or
* UML2DiffPackage.Literals.UML_STEREOTYPE_APPLICATION_REMOVAL
* @return The list of matching differences.
*/
protected List<DiffElement> getEmbeddedStereotypeApplicationDiffs(EObject obj,
EcoreUtil.CrossReferencer crossReferencer, EReference diffSide, EClass expectedDiff) {
final List<DiffElement> result = new ArrayList<DiffElement>();
result.addAll(getStereotypeDifferences(crossReferencer, diffSide, expectedDiff, obj));
final Iterator<EObject> it = obj.eAllContents();
while (it.hasNext()) {
final EObject next = it.next();
result.addAll(getStereotypeDifferences(crossReferencer, diffSide, expectedDiff, next));
}
return result;
}
/**
* Looks for all the stereotype applications on the given {@link EObject} of the model from the specified
* side. When stereotype applications are found, this returns the potential differences, related to this
* model object, from a given difference type.
*
* @param crossReferencer
* A cross referencer to look for difference from model objects.
* @param diffSide
* The side from which it is required to look for:
* DiffPackage.Literals.UPDATE_MODEL_ELEMENT__LEFT_ELEMENT or
* DiffPackage.Literals.UPDATE_MODEL_ELEMENT__RIGHT_ELEMENT
* @param expectedDiff
* The type of difference to look for:
* UML2DiffPackage.Literals.UML_STEREOTYPE_APPLICATION_ADDITION or
* UML2DiffPackage.Literals.UML_STEREOTYPE_APPLICATION_REMOVAL
* @param next
* model object on which stereotypes are applied.
* @return The list of matching differences.
*/
private List<DiffElement> getStereotypeDifferences(EcoreUtil.CrossReferencer crossReferencer,
EReference diffSide, EClass expectedDiff, final EObject next) {
final List<DiffElement> result = new ArrayList<DiffElement>();
if (next instanceof Element && ((Element)next).getStereotypeApplications().size() > 0) {
// Look for the UMLStereotypeApplication Difference
final List<DiffElement> findCrossReferences = findCrossReferences(next, diffSide, crossReferencer);
for (DiffElement diffElement : findCrossReferences) {
if (expectedDiff.isInstance(diffElement)) {
result.add(diffElement);
}
}
}
return result;
}
/**
* Retrieve all the stereotype applied on the given UML element and its children (all descendants).
*
* @param elt
* The UML element.
* @return The list of stereotype applications.
*/
protected List<EObject> getAllStereotypeApplications(Element elt) {
final List<EObject> result = new ArrayList<EObject>();
result.addAll(elt.getStereotypeApplications());
final Iterator<EObject> it = elt.eAllContents();
while (it.hasNext()) {
final EObject obj = it.next();
if (obj instanceof Element) {
result.addAll(((Element)obj).getStereotypeApplications());
}
}
return result;
}
}
|