|
@@ -10,7 +10,9 @@
|
|
|
*/
|
|
|
package org.yakindu.base.types;
|
|
|
|
|
|
+import org.eclipse.emf.common.util.BasicEList;
|
|
|
import org.eclipse.emf.ecore.EObject;
|
|
|
+import org.eclipse.emf.ecore.EStructuralFeature;
|
|
|
import org.yakindu.base.base.BasePackage;
|
|
|
import org.yakindu.base.base.NamedElement;
|
|
|
|
|
@@ -30,16 +32,45 @@ public class TypesUtil {
|
|
|
id.append(element.getName());
|
|
|
EObject container = element.eContainer();
|
|
|
while (container != null) {
|
|
|
+
|
|
|
if (container.eClass().getEAllStructuralFeatures().contains(BasePackage.Literals.NAMED_ELEMENT__NAME)) {
|
|
|
- String name = (String) container.eGet(BasePackage.Literals.NAMED_ELEMENT__NAME);
|
|
|
- if (name != null) {
|
|
|
- id.insert(0, ID_SEPARATOR);
|
|
|
- id.insert(0, name);
|
|
|
- }
|
|
|
+ prependNamedElementName(id, container);
|
|
|
+ } else {
|
|
|
+ prependContainingFeatureName(id, container);
|
|
|
}
|
|
|
container = container.eContainer();
|
|
|
}
|
|
|
return id.toString();
|
|
|
}
|
|
|
|
|
|
+ private static void prependNamedElementName(StringBuilder id, EObject container) {
|
|
|
+ String name = (String) container.eGet(BasePackage.Literals.NAMED_ELEMENT__NAME);
|
|
|
+ if (name != null) {
|
|
|
+ id.insert(0, ID_SEPARATOR);
|
|
|
+ id.insert(0, name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void prependContainingFeatureName(StringBuilder id, EObject container) {
|
|
|
+ EStructuralFeature feature = container.eContainingFeature();
|
|
|
+ if (feature != null) {
|
|
|
+ String name;
|
|
|
+ if (feature.isMany()) {
|
|
|
+ Object elements = container.eContainer().eGet(feature);
|
|
|
+ int index = 0;
|
|
|
+ if (elements instanceof BasicEList) {
|
|
|
+ BasicEList elementList = (BasicEList) elements;
|
|
|
+ index = elementList.indexOf(container);
|
|
|
+ }
|
|
|
+ name = feature.getName() + index;
|
|
|
+ } else {
|
|
|
+ name = feature.getName();
|
|
|
+ }
|
|
|
+ id.insert(0, ID_SEPARATOR);
|
|
|
+ id.insert(0, name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|