/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package fr.femtost.disc.eclipse.vhdlamsmetamodel.vhdlams.impl;

import fr.femtost.disc.eclipse.vhdlamsmetamodel.vhdlams.ElseStatement;
import fr.femtost.disc.eclipse.vhdlamsmetamodel.vhdlams.IfThenStatement;
import fr.femtost.disc.eclipse.vhdlamsmetamodel.vhdlams.VhdlamsPackage;

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;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>If Then Statement</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link fr.femtost.disc.eclipse.vhdlamsmetamodel.vhdlams.impl.IfThenStatementImpl#getBooleanExpression <em>Boolean Expression</em>}</li>
 *   <li>{@link fr.femtost.disc.eclipse.vhdlamsmetamodel.vhdlams.impl.IfThenStatementImpl#getElse <em>Else</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class IfThenStatementImpl extends SequentialStatementImpl implements IfThenStatement {
	/**
	 * The default value of the '{@link #getBooleanExpression() <em>Boolean Expression</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBooleanExpression()
	 * @generated
	 * @ordered
	 */
	protected static final String BOOLEAN_EXPRESSION_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getBooleanExpression() <em>Boolean Expression</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBooleanExpression()
	 * @generated
	 * @ordered
	 */
	protected String booleanExpression = BOOLEAN_EXPRESSION_EDEFAULT;

	/**
	 * The cached value of the '{@link #getElse() <em>Else</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getElse()
	 * @generated
	 * @ordered
	 */
	protected ElseStatement else_;

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

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setBooleanExpression(String newBooleanExpression) {
		String oldBooleanExpression = booleanExpression;
		booleanExpression = newBooleanExpression;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, VhdlamsPackage.IF_THEN_STATEMENT__BOOLEAN_EXPRESSION, oldBooleanExpression, booleanExpression));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ElseStatement getElse() {
		if (else_ != null && else_.eIsProxy()) {
			InternalEObject oldElse = (InternalEObject)else_;
			else_ = (ElseStatement)eResolveProxy(oldElse);
			if (else_ != oldElse) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, VhdlamsPackage.IF_THEN_STATEMENT__ELSE, oldElse, else_));
			}
		}
		return else_;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ElseStatement basicGetElse() {
		return else_;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetElse(ElseStatement newElse, NotificationChain msgs) {
		ElseStatement oldElse = else_;
		else_ = newElse;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, VhdlamsPackage.IF_THEN_STATEMENT__ELSE, oldElse, newElse);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setElse(ElseStatement newElse) {
		if (newElse != else_) {
			NotificationChain msgs = null;
			if (else_ != null)
				msgs = ((InternalEObject)else_).eInverseRemove(this, VhdlamsPackage.ELSE_STATEMENT__IF, ElseStatement.class, msgs);
			if (newElse != null)
				msgs = ((InternalEObject)newElse).eInverseAdd(this, VhdlamsPackage.ELSE_STATEMENT__IF, ElseStatement.class, msgs);
			msgs = basicSetElse(newElse, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, VhdlamsPackage.IF_THEN_STATEMENT__ELSE, newElse, newElse));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case VhdlamsPackage.IF_THEN_STATEMENT__ELSE:
				if (else_ != null)
					msgs = ((InternalEObject)else_).eInverseRemove(this, VhdlamsPackage.ELSE_STATEMENT__IF, ElseStatement.class, msgs);
				return basicSetElse((ElseStatement)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case VhdlamsPackage.IF_THEN_STATEMENT__ELSE:
				return basicSetElse(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 VhdlamsPackage.IF_THEN_STATEMENT__BOOLEAN_EXPRESSION:
				return getBooleanExpression();
			case VhdlamsPackage.IF_THEN_STATEMENT__ELSE:
				if (resolve) return getElse();
				return basicGetElse();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case VhdlamsPackage.IF_THEN_STATEMENT__BOOLEAN_EXPRESSION:
				setBooleanExpression((String)newValue);
				return;
			case VhdlamsPackage.IF_THEN_STATEMENT__ELSE:
				setElse((ElseStatement)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case VhdlamsPackage.IF_THEN_STATEMENT__BOOLEAN_EXPRESSION:
				setBooleanExpression(BOOLEAN_EXPRESSION_EDEFAULT);
				return;
			case VhdlamsPackage.IF_THEN_STATEMENT__ELSE:
				setElse((ElseStatement)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case VhdlamsPackage.IF_THEN_STATEMENT__BOOLEAN_EXPRESSION:
				return BOOLEAN_EXPRESSION_EDEFAULT == null ? booleanExpression != null : !BOOLEAN_EXPRESSION_EDEFAULT.equals(booleanExpression);
			case VhdlamsPackage.IF_THEN_STATEMENT__ELSE:
				return else_ != null;
		}
		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(" (booleanExpression: ");
		result.append(booleanExpression);
		result.append(')');
		return result.toString();
	}

} //IfThenStatementImpl
