|
Lines 109-134
Link Here
|
| 109 |
/** |
109 |
/** |
| 110 |
* Relocate stereotype applications for the nested elements of the selection in the controlled resource |
110 |
* Relocate stereotype applications for the nested elements of the selection in the controlled resource |
| 111 |
* |
111 |
* |
| 112 |
* @param pack |
112 |
* @param root |
| 113 |
* the package for which stereotype application must be relocated |
113 |
* the root element for which stereotype applications must be relocated |
| 114 |
* @param target |
114 |
* @param target |
| 115 |
* the target controlled resource |
115 |
* the target controlled resource |
| 116 |
*/ |
116 |
*/ |
| 117 |
public static void relocateStereotypeApplications(Package pack, Resource target) { |
117 |
public static void relocateStereotypeApplications(Element root, Resource target) { |
| 118 |
for(Iterator<EObject> i = EcoreUtil.getAllProperContents(pack, false); i.hasNext();) { |
118 |
// Relocate stereotype applications of the root element itself. |
|
|
119 |
for(EObject stereotypeApplication : root.getStereotypeApplications()) { |
| 120 |
relocateStereotypeApplication(root, stereotypeApplication); |
| 121 |
} |
| 122 |
// Relocate stereotype applications of the root's child elements. |
| 123 |
for(Iterator<EObject> i = EcoreUtil.getAllProperContents(root, false); i.hasNext();) { |
| 119 |
EObject current = i.next(); |
124 |
EObject current = i.next(); |
| 120 |
if(current instanceof Element) { |
125 |
if(current instanceof Element) { |
| 121 |
Element element = (Element)current; |
126 |
Element element = (Element)current; |
| 122 |
EList<EObject> stereotypeApplications = element.getStereotypeApplications(); |
127 |
for(EObject stereotypeApplication : element.getStereotypeApplications()) { |
| 123 |
if(!stereotypeApplications.isEmpty()) { |
128 |
relocateStereotypeApplication(element, stereotypeApplication); |
| 124 |
for(EObject e : stereotypeApplications) { |
|
|
| 125 |
int size = target.getContents().size(); |
| 126 |
target.getContents().add(size, e); |
| 127 |
} |
| 128 |
} |
129 |
} |
| 129 |
} |
130 |
} |
| 130 |
} |
131 |
} |
| 131 |
} |
132 |
} |
|
|
133 |
|
| 134 |
/** |
| 135 |
* Relocate one stereotype application of the given element. |
| 136 |
* |
| 137 |
* @param element |
| 138 |
* the element holding the stereotype application to be relocated |
| 139 |
* @param stereotypeApplication |
| 140 |
* the stereotype application to be relocated |
| 141 |
*/ |
| 142 |
public static void relocateStereotypeApplication(Element element, EObject stereotypeApplication) { |
| 143 |
// Too bad that StereotypeApplicationHelper.getContainmentList is not public, it would have allowed a completely generic heuristic. |
| 144 |
EList<EObject> containmentList; // = StereotypeApplicationHelper.INSTANCE.getContainmentList(element, stereotypeApplication.eClass()); |
| 145 |
Resource resource = element.eResource(); |
| 146 |
containmentList = resource != null ? resource.getContents() : null; // Default heuristic of StereotypeApplicationHelper. |
| 147 |
if (containmentList != null) { |
| 148 |
containmentList.add(stereotypeApplication); |
| 149 |
} |
| 150 |
} |
| 132 |
|
151 |
|
| 133 |
/** |
152 |
/** |
| 134 |
* Check if the profile application is a duplicated one |
153 |
* Check if the profile application is a duplicated one |