All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.pelle.mango.dsl.emf.EmfModelQuery Maven / Gradle / Ivy

package io.pelle.mango.dsl.emf;

import org.eclipse.emf.ecore.EObject;

import com.google.common.base.Optional;

public class EmfModelQuery {

	public static  EObjectQuery createEObjectQuery(T eObject) {
		return new EObjectQuery(eObject);
	}

	@SuppressWarnings("unchecked")
	public static  Optional getParentEObject(EObject eObject, Class eObjectClass) {

		EObject currentEObject = eObject;

		int count = 0;

		while (currentEObject != null && !eObjectClass.isAssignableFrom(currentEObject.getClass())) {
			// see EcoreUtil.getRootContainer(EObject)
			if (++count > 100000) {
				break;
			}
			currentEObject = currentEObject.eContainer();
		}

		return Optional.fromNullable((T) currentEObject);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy