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

io.pelle.mango.dsl.query.functions.FunctionEReferenceTypeSelect Maven / Gradle / Ivy

package io.pelle.mango.dsl.query.functions;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;

import com.google.common.base.Function;

public class FunctionEReferenceTypeSelect implements Function
{
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static  FunctionEReferenceTypeSelect create(EReference eReference, Class clazz)
	{
		return new FunctionEReferenceTypeSelect(eReference, clazz);
	}

	private Class clazz;
	private EReference eReference;

	private FunctionEReferenceTypeSelect(EReference eReference, Class clazz)
	{
		super();
		this.eReference = eReference;
		this.clazz = clazz;
	}

	@SuppressWarnings("unchecked")
	@Override
	public T apply(EObject eObject)
	{
		if (eObject.eIsSet(eReference))
		{
			Object o = eObject.eGet(eReference, true);

			if (o != null && clazz.isAssignableFrom(o.getClass()))
			{
				return (T) o;
			}
		}

		return null;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy