/*******************************************************************************
 * 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.ComponentInstance;

import java.util.Collection;

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

import org.eclipse.emf.common.util.EList;

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

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

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import com.irtsaintexupery.fiacre.instance.fiacreinstance.DeclarationInstance;
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>Declaration Instance</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link com.irtsaintexupery.fiacre.instance.fiacreinstance.impl.DeclarationInstanceImpl#getVariableDeclarationInstances <em>Variable Declaration Instances</em>}</li>
 *   <li>{@link com.irtsaintexupery.fiacre.instance.fiacreinstance.impl.DeclarationInstanceImpl#getName <em>Name</em>}</li>
 *   <li>{@link com.irtsaintexupery.fiacre.instance.fiacreinstance.impl.DeclarationInstanceImpl#getInstance <em>Instance</em>}</li>
 *   <li>{@link com.irtsaintexupery.fiacre.instance.fiacreinstance.impl.DeclarationInstanceImpl#getFlatname <em>Flatname</em>}</li>
 * </ul>
 *
 * @generated
 */
public abstract class DeclarationInstanceImpl extends BlockInstanceImpl implements DeclarationInstance {
	/**
	 * The cached value of the '{@link #getVariableDeclarationInstances() <em>Variable Declaration Instances</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getVariableDeclarationInstances()
	 * @generated
	 * @ordered
	 */
	protected EList<VariableDeclarationInstance> variableDeclarationInstances;

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getInstance() <em>Instance</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInstance()
	 * @generated
	 * @ordered
	 */
	protected ComponentInstance instance;

	/**
	 * The default value of the '{@link #getFlatname() <em>Flatname</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFlatname()
	 * @generated
	 * @ordered
	 */
	protected static final String FLATNAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getFlatname() <em>Flatname</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFlatname()
	 * @generated
	 * @ordered
	 */
	protected String flatname = FLATNAME_EDEFAULT;

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<VariableDeclarationInstance> getVariableDeclarationInstances() {
		if (variableDeclarationInstances == null) {
			variableDeclarationInstances = new EObjectContainmentEList<VariableDeclarationInstance>(VariableDeclarationInstance.class, this, FiacreinstancePackage.DECLARATION_INSTANCE__VARIABLE_DECLARATION_INSTANCES);
		}
		return variableDeclarationInstances;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, FiacreinstancePackage.DECLARATION_INSTANCE__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ComponentInstance getInstance() {
		if (instance != null && instance.eIsProxy()) {
			InternalEObject oldInstance = (InternalEObject)instance;
			instance = (ComponentInstance)eResolveProxy(oldInstance);
			if (instance != oldInstance) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, FiacreinstancePackage.DECLARATION_INSTANCE__INSTANCE, oldInstance, instance));
			}
		}
		return instance;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ComponentInstance basicGetInstance() {
		return instance;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setInstance(ComponentInstance newInstance) {
		ComponentInstance oldInstance = instance;
		instance = newInstance;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, FiacreinstancePackage.DECLARATION_INSTANCE__INSTANCE, oldInstance, instance));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getFlatname() {
		return flatname;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setFlatname(String newFlatname) {
		String oldFlatname = flatname;
		flatname = newFlatname;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, FiacreinstancePackage.DECLARATION_INSTANCE__FLATNAME, oldFlatname, flatname));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case FiacreinstancePackage.DECLARATION_INSTANCE__VARIABLE_DECLARATION_INSTANCES:
				return ((InternalEList<?>)getVariableDeclarationInstances()).basicRemove(otherEnd, 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.DECLARATION_INSTANCE__VARIABLE_DECLARATION_INSTANCES:
				return getVariableDeclarationInstances();
			case FiacreinstancePackage.DECLARATION_INSTANCE__NAME:
				return getName();
			case FiacreinstancePackage.DECLARATION_INSTANCE__INSTANCE:
				if (resolve) return getInstance();
				return basicGetInstance();
			case FiacreinstancePackage.DECLARATION_INSTANCE__FLATNAME:
				return getFlatname();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case FiacreinstancePackage.DECLARATION_INSTANCE__VARIABLE_DECLARATION_INSTANCES:
				getVariableDeclarationInstances().clear();
				getVariableDeclarationInstances().addAll((Collection<? extends VariableDeclarationInstance>)newValue);
				return;
			case FiacreinstancePackage.DECLARATION_INSTANCE__NAME:
				setName((String)newValue);
				return;
			case FiacreinstancePackage.DECLARATION_INSTANCE__INSTANCE:
				setInstance((ComponentInstance)newValue);
				return;
			case FiacreinstancePackage.DECLARATION_INSTANCE__FLATNAME:
				setFlatname((String)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case FiacreinstancePackage.DECLARATION_INSTANCE__VARIABLE_DECLARATION_INSTANCES:
				getVariableDeclarationInstances().clear();
				return;
			case FiacreinstancePackage.DECLARATION_INSTANCE__NAME:
				setName(NAME_EDEFAULT);
				return;
			case FiacreinstancePackage.DECLARATION_INSTANCE__INSTANCE:
				setInstance((ComponentInstance)null);
				return;
			case FiacreinstancePackage.DECLARATION_INSTANCE__FLATNAME:
				setFlatname(FLATNAME_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case FiacreinstancePackage.DECLARATION_INSTANCE__VARIABLE_DECLARATION_INSTANCES:
				return variableDeclarationInstances != null && !variableDeclarationInstances.isEmpty();
			case FiacreinstancePackage.DECLARATION_INSTANCE__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case FiacreinstancePackage.DECLARATION_INSTANCE__INSTANCE:
				return instance != null;
			case FiacreinstancePackage.DECLARATION_INSTANCE__FLATNAME:
				return FLATNAME_EDEFAULT == null ? flatname != null : !FLATNAME_EDEFAULT.equals(flatname);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(", flatname: ");
		result.append(flatname);
		result.append(')');
		return result.toString();
	}

} //DeclarationInstanceImpl
