/**
 * Copyright (c) 2016 committers of YAKINDU and others.
 * 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:
 * 	committers of YAKINDU - initial API and implementation
 * 
 */
package org.yakindu.base.types;

import org.eclipse.emf.ecore.EObject;
import org.yakindu.base.base.BasePackage;
import org.yakindu.base.base.NamedElement;

/**
 * @author Thomas Kutz - Initial contribution and API
 */
public class TypesUtil {

	public static final String ID_SEPARATOR = ".";

	public static String computeQID(NamedElement element) {
		if (element.getName() == null) {
			return null;
		}

		StringBuilder id = new StringBuilder();
		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);
				}
			}
			container = container.eContainer();
		}
		return id.toString();
	}
	
}

@@ -443,21 +443,117 @@
 emf.
-ecore.EObject
+common.util.BasicEList;%0Aimport org.eclipse.emf.ecore.EObject;%0Aimport org.eclipse.emf.ecore.EStructuralFeature
 ;%0Aim
@@ -1034,16 +1034,17 @@
 null) %7B%0A
+%0A
 %09%09%09if (c
@@ -1145,16 +1145,280 @@
 E)) %7B%0A%09%09
+%09%09prependNamedElementName(id, container);%0A%09%09%09%7D else %7B%0A%09%09%09%09prependContainingFeatureName(id, container);%0A%09%09%09%7D%0A%09%09%09container = container.eContainer();%0A%09%09%7D%0A%09%09return id.toString();%0A%09%7D%0A%09%0A%09private static void prependNamedElementName(StringBuilder id, EObject container) %7B%0A
 %09%09String
@@ -1492,18 +1492,16 @@
 _NAME);%0A
-%09%09
 %09%09if (na
@@ -1513,26 +1513,24 @@
  null) %7B%0A%09%09%09
-%09%09
 id.insert(0,
@@ -1548,18 +1548,16 @@
 OR);%0A%09%09%09
-%09%09
 id.inser
@@ -1572,89 +1572,608 @@
 e);%0A
-%09%09
 %09%09%7D%0A%09
-%09%09%7D%0A%09%09%09container = container.eContainer();%0A%09%09%7D%0A%09%09return id.toString(
+%7D%0A%0A%09private static void prependContainingFeatureName(StringBuilder id, EObject container) %7B%0A%09%09EStructuralFeature feature = container.eContainingFeature();%0A%09%09if (feature != null) %7B%0A%09%09%09String name;%0A%09%09%09if (feature.isMany()) %7B%0A%09%09%09%09Object elements = container.eContainer().eGet(feature);%0A%09%09%09%09int index = 0;%0A%09%09%09%09if (elements instanceof BasicEList) %7B%0A%09%09%09%09%09BasicEList elementList = (BasicEList) elements;%0A%09%09%09%09%09index = elementList.indexOf(container);%0A%09%09%09%09%7D%0A%09%09%09%09name = feature.getName() + index;%0A%09%09%09%7D else %7B%0A%09%09%09%09name = feature.getName();%0A%09%09%09%7D%0A%09%09%09id.insert(0, ID_SEPARATOR);%0A%09%09%09id.insert(0, name
 );%0A
+%09
 %09%7D%0A%09
+%7D%0A%0A%0A
 %0A%7D%0A

Extend ID creation to take non-named containers into account (#1500) (#1601)