1 | package de.uka.ipd.sdq.pcmbench.tabs.parameters; |
2 | |
3 | import java.util.Iterator; |
4 | import java.util.List; |
5 | |
6 | import org.eclipse.emf.ecore.EObject; |
7 | import org.eclipse.emf.ecore.util.InternalEList; |
8 | import org.eclipse.emf.ecore.util.EcoreUtil.Copier; |
9 | |
10 | import org.eclipse.emf.ecore.EReference; |
11 | |
12 | public class ParameterUtil extends Copier { |
13 | |
14 | /** |
15 | * |
16 | */ |
17 | private static final long serialVersionUID = 3504940555318719080L; |
18 | |
19 | /* |
20 | * (non-Javadoc) |
21 | * |
22 | * @see org.eclipse.emf.ecore.util.EcoreUtil.Copier#copyReference(org.eclipse.emf.ecore.EReference, |
23 | * org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject) |
24 | */ |
25 | @SuppressWarnings("unchecked") |
26 | @Override |
27 | protected void copyReference(EReference eReference, EObject eObject, |
28 | EObject copyEObject) { |
29 | if (eObject.eIsSet(eReference)) { |
30 | if (eReference.isMany()) { |
31 | List source = (List) eObject.eGet(eReference); |
32 | InternalEList<Object> target = (InternalEList<Object>) copyEObject |
33 | .eGet(getTarget(eReference)); |
34 | if (source.isEmpty()) { |
35 | target.clear(); |
36 | } else { |
37 | boolean isBidirectional = eReference.getEOpposite() != null; |
38 | int index = 0; |
39 | for (Iterator k = source.iterator(); k.hasNext();) { |
40 | Object referencedEObject = k.next(); |
41 | Object copyReferencedEObject = get(referencedEObject); |
42 | if (copyReferencedEObject == null) { |
43 | if (!isBidirectional) { |
44 | target.addUnique(index, referencedEObject); |
45 | ++index; |
46 | } |
47 | } else { |
48 | if (isBidirectional) { |
49 | int position = target |
50 | .indexOf(copyReferencedEObject); |
51 | if (position == -1) { |
52 | target.addUnique(index, |
53 | copyReferencedEObject); |
54 | } else if (index != position) { |
55 | target.move(index, copyReferencedEObject); |
56 | } |
57 | } else { |
58 | target.addUnique(index, copyReferencedEObject); |
59 | } |
60 | ++index; |
61 | } |
62 | } |
63 | } |
64 | } else { |
65 | Object referencedEObject = eObject.eGet(eReference); |
66 | if (referencedEObject == null) { |
67 | copyEObject.eSet(getTarget(eReference), null); |
68 | } else { |
69 | Object copyReferencedEObject = get(referencedEObject); |
70 | if (copyReferencedEObject == null) { |
71 | if (eReference.getEOpposite() == null && !eReference.getName().equals("expression")) { |
72 | copyEObject.eSet(getTarget(eReference), |
73 | referencedEObject); |
74 | } |
75 | } else { |
76 | copyEObject.eSet(getTarget(eReference), |
77 | copyReferencedEObject); |
78 | } |
79 | } |
80 | } |
81 | } |
82 | } |
83 | |
84 | } |