/*******************************************************************************
 * Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the LGPL 3.0
 * which accompanies this distribution, and is available at
 * https://www.gnu.org/licenses/lgpl-3.0-standalone.html
 *
 * Contributors:
 *     Faiez Zalila - initial API and implementation and/or initial documentation
 *******************************************************************************/
/**
 */
package com.irtsaintexupery.fiacre.instance.fiacreinstance.impl;

import fr.irit.fiacre.xtext.fiacre.ValueExpression;
import fr.irit.fiacre.xtext.fiacre.VariableDeclaration;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;

import com.irtsaintexupery.fiacre.instance.fiacreinstance.FiacreinstancePackage;
import com.irtsaintexupery.fiacre.instance.fiacreinstance.VariableDeclarationInstance;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Variable Declaration Instance</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link com.irtsaintexupery.fiacre.instance.fiacreinstance.impl.VariableDeclarationInstanceImpl#getVariableDeclaration <em>Variable Declaration</em>}</li>
 *   <li>{@link com.irtsaintexupery.fiacre.instance.fiacreinstance.impl.VariableDeclarationInstanceImpl#getCurrentValue <em>Current Value</em>}</li>
 * </ul>
 *
 * @generated
 */
public class VariableDeclarationInstanceImpl extends MinimalEObjectImpl.Container implements VariableDeclarationInstance {
	/**
	 * The cached value of the '{@link #getVariableDeclaration() <em>Variable Declaration</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getVariableDeclaration()
	 * @generated
	 * @ordered
	 */
	protected VariableDeclaration variableDeclaration;

	/**
	 * The cached value of the '{@link #getCurrentValue() <em>Current Value</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCurrentValue()
	 * @generated
	 * @ordered
	 */
	protected ValueExpression currentValue;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected VariableDeclarationInstanceImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return FiacreinstancePackage.Literals.VARIABLE_DECLARATION_INSTANCE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public VariableDeclaration getVariableDeclaration() {
		if (variableDeclaration != null && variableDeclaration.eIsProxy()) {
			InternalEObject oldVariableDeclaration = (InternalEObject)variableDeclaration;
			variableDeclaration = (VariableDeclaration)eResolveProxy(oldVariableDeclaration);
			if (variableDeclaration != oldVariableDeclaration) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, FiacreinstancePackage.VARIABLE_DECLARATION_INSTANCE__VARIABLE_DECLARATION, oldVariableDeclaration, variableDeclaration));
			}
		}
		return variableDeclaration;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public VariableDeclaration basicGetVariableDeclaration() {
		return variableDeclaration;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setVariableDeclaration(VariableDeclaration newVariableDeclaration) {
		VariableDeclaration oldVariableDeclaration = variableDeclaration;
		variableDeclaration = newVariableDeclaration;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, FiacreinstancePackage.VARIABLE_DECLARATION_INSTANCE__VARIABLE_DECLARATION, oldVariableDeclaration, variableDeclaration));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ValueExpression getCurrentValue() {
		return currentValue;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetCurrentValue(ValueExpression newCurrentValue, NotificationChain msgs) {
		ValueExpression oldCurrentValue = currentValue;
		currentValue = newCurrentValue;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, FiacreinstancePackage.VARIABLE_DECLARATION_INSTANCE__CURRENT_VALUE, oldCurrentValue, newCurrentValue);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCurrentValue(ValueExpression newCurrentValue) {
		if (newCurrentValue != currentValue) {
			NotificationChain msgs = null;
			if (currentValue != null)
				msgs = ((InternalEObject)currentValue).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - FiacreinstancePackage.VARIABLE_DECLARATION_INSTANCE__CURRENT_VALUE, null, msgs);
			if (newCurrentValue != null)
				msgs = ((InternalEObject)newCurrentValue).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - FiacreinstancePackage.VARIABLE_DECLARATION_INSTANCE__CURRENT_VALUE, null, msgs);
			msgs = basicSetCurrentValue(newCurrentValue, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, FiacreinstancePackage.VARIABLE_DECLARATION_INSTANCE__CURRENT_VALUE, newCurrentValue, newCurrentValue));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case FiacreinstancePackage.VARIABLE_DECLARATION_INSTANCE__CURRENT_VALUE:
				return basicSetCurrentValue(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case FiacreinstancePackage.VARIABLE_DECLARATION_INSTANCE__VARIABLE_DECLARATION:
				if (resolve) return getVariableDeclaration();
				return basicGetVariableDeclaration();
			case FiacreinstancePackage.VARIABLE_DECLARATION_INSTANCE__CURRENT_VALUE:
				return getCurrentValue();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case FiacreinstancePackage.VARIABLE_DECLARATION_INSTANCE__VARIABLE_DECLARATION:
				setVariableDeclaration((VariableDeclaration)newValue);
				return;
			case FiacreinstancePackage.VARIABLE_DECLARATION_INSTANCE__CURRENT_VALUE:
				setCurrentValue((ValueExpression)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case FiacreinstancePackage.VARIABLE_DECLARATION_INSTANCE__VARIABLE_DECLARATION:
				setVariableDeclaration((VariableDeclaration)null);
				return;
			case FiacreinstancePackage.VARIABLE_DECLARATION_INSTANCE__CURRENT_VALUE:
				setCurrentValue((ValueExpression)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case FiacreinstancePackage.VARIABLE_DECLARATION_INSTANCE__VARIABLE_DECLARATION:
				return variableDeclaration != null;
			case FiacreinstancePackage.VARIABLE_DECLARATION_INSTANCE__CURRENT_VALUE:
				return currentValue != null;
		}
		return super.eIsSet(featureID);
	}

} //VariableDeclarationInstanceImpl
