/******************************************************************************* * Copyright (c) 2014 Willink Transformations and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * E.D.Willink - initial API and implementation *******************************************************************************/ package org.eclipse.ocl.examples.xtext2lpg.XBNF.impl; 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.impl.MinimalEObjectImpl; import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList; import org.eclipse.emf.ecore.util.EObjectResolvingEList; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.ecore.util.InternalEList; import org.eclipse.ocl.examples.xtext2lpg.XBNF.Grammar; import org.eclipse.ocl.examples.xtext2lpg.XBNF.Syntax; import org.eclipse.ocl.examples.xtext2lpg.XBNF.TypedRule; import org.eclipse.ocl.examples.xtext2lpg.XBNF.XBNFPackage; /** * <!-- begin-user-doc --> * An implementation of the model object '<em><b>Grammar</b></em>'. * <!-- end-user-doc --> * <p> * The following features are implemented: * <ul> * <li>{@link org.eclipse.ocl.examples.xtext2lpg.XBNF.impl.GrammarImpl#getName <em>Name</em>}</li> * <li>{@link org.eclipse.ocl.examples.xtext2lpg.XBNF.impl.GrammarImpl#getSyntax <em>Syntax</em>}</li> * <li>{@link org.eclipse.ocl.examples.xtext2lpg.XBNF.impl.GrammarImpl#getGoals <em>Goals</em>}</li> * <li>{@link org.eclipse.ocl.examples.xtext2lpg.XBNF.impl.GrammarImpl#getRules <em>Rules</em>}</li> * <li>{@link org.eclipse.ocl.examples.xtext2lpg.XBNF.impl.GrammarImpl#getDebug <em>Debug</em>}</li> * </ul> * </p> * * @generated */ public class GrammarImpl extends MinimalEObjectImpl.Container implements Grammar { /** * 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 #getGoals() <em>Goals</em>}' reference list. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #getGoals() * @generated * @ordered */ protected EList<TypedRule> goals; /** * The cached value of the '{@link #getRules() <em>Rules</em>}' containment reference list. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #getRules() * @generated * @ordered */ protected EList<TypedRule> rules; /** * The default value of the '{@link #getDebug() <em>Debug</em>}' attribute. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #getDebug() * @generated * @ordered */ protected static final String DEBUG_EDEFAULT = null; /** * The cached value of the '{@link #getDebug() <em>Debug</em>}' attribute. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #getDebug() * @generated * @ordered */ protected String debug = DEBUG_EDEFAULT; /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected GrammarImpl() { super(); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override protected EClass eStaticClass() { return XBNFPackage.Literals.GRAMMAR; } /** * <!-- 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, XBNFPackage.GRAMMAR__NAME, oldName, name)); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public Syntax getSyntax() { if (eContainerFeatureID() != XBNFPackage.GRAMMAR__SYNTAX) return null; return (Syntax)eInternalContainer(); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public NotificationChain basicSetSyntax(Syntax newSyntax, NotificationChain msgs) { msgs = eBasicSetContainer((InternalEObject)newSyntax, XBNFPackage.GRAMMAR__SYNTAX, msgs); return msgs; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setSyntax(Syntax newSyntax) { if (newSyntax != eInternalContainer() || (eContainerFeatureID() != XBNFPackage.GRAMMAR__SYNTAX && newSyntax != null)) { if (EcoreUtil.isAncestor(this, newSyntax)) throw new IllegalArgumentException("Recursive containment not allowed for " + toString()); NotificationChain msgs = null; if (eInternalContainer() != null) msgs = eBasicRemoveFromContainer(msgs); if (newSyntax != null) msgs = ((InternalEObject)newSyntax).eInverseAdd(this, XBNFPackage.SYNTAX__GRAMMARS, Syntax.class, msgs); msgs = basicSetSyntax(newSyntax, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, XBNFPackage.GRAMMAR__SYNTAX, newSyntax, newSyntax)); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public EList<TypedRule> getGoals() { if (goals == null) { goals = new EObjectResolvingEList<TypedRule>(TypedRule.class, this, XBNFPackage.GRAMMAR__GOALS); } return goals; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public EList<TypedRule> getRules() { if (rules == null) { rules = new EObjectContainmentWithInverseEList<TypedRule>(TypedRule.class, this, XBNFPackage.GRAMMAR__RULES, XBNFPackage.TYPED_RULE__GRAMMAR); } return rules; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public String getDebug() { return debug; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setDebug(String newDebug) { String oldDebug = debug; debug = newDebug; if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, XBNFPackage.GRAMMAR__DEBUG, oldDebug, debug)); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @SuppressWarnings("unchecked") @Override public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) { switch (featureID) { case XBNFPackage.GRAMMAR__SYNTAX: if (eInternalContainer() != null) msgs = eBasicRemoveFromContainer(msgs); return basicSetSyntax((Syntax)otherEnd, msgs); case XBNFPackage.GRAMMAR__RULES: return ((InternalEList<InternalEObject>)(InternalEList<?>)getRules()).basicAdd(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 XBNFPackage.GRAMMAR__SYNTAX: return basicSetSyntax(null, msgs); case XBNFPackage.GRAMMAR__RULES: return ((InternalEList<?>)getRules()).basicRemove(otherEnd, msgs); } return super.eInverseRemove(otherEnd, featureID, msgs); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) { switch (eContainerFeatureID()) { case XBNFPackage.GRAMMAR__SYNTAX: return eInternalContainer().eInverseRemove(this, XBNFPackage.SYNTAX__GRAMMARS, Syntax.class, msgs); } return super.eBasicRemoveFromContainerFeature(msgs); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public Object eGet(int featureID, boolean resolve, boolean coreType) { switch (featureID) { case XBNFPackage.GRAMMAR__NAME: return getName(); case XBNFPackage.GRAMMAR__SYNTAX: return getSyntax(); case XBNFPackage.GRAMMAR__GOALS: return getGoals(); case XBNFPackage.GRAMMAR__RULES: return getRules(); case XBNFPackage.GRAMMAR__DEBUG: return getDebug(); } 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 XBNFPackage.GRAMMAR__NAME: setName((String)newValue); return; case XBNFPackage.GRAMMAR__SYNTAX: setSyntax((Syntax)newValue); return; case XBNFPackage.GRAMMAR__GOALS: getGoals().clear(); getGoals().addAll((Collection<? extends TypedRule>)newValue); return; case XBNFPackage.GRAMMAR__RULES: getRules().clear(); getRules().addAll((Collection<? extends TypedRule>)newValue); return; case XBNFPackage.GRAMMAR__DEBUG: setDebug((String)newValue); return; } super.eSet(featureID, newValue); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case XBNFPackage.GRAMMAR__NAME: setName(NAME_EDEFAULT); return; case XBNFPackage.GRAMMAR__SYNTAX: setSyntax((Syntax)null); return; case XBNFPackage.GRAMMAR__GOALS: getGoals().clear(); return; case XBNFPackage.GRAMMAR__RULES: getRules().clear(); return; case XBNFPackage.GRAMMAR__DEBUG: setDebug(DEBUG_EDEFAULT); return; } super.eUnset(featureID); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public boolean eIsSet(int featureID) { switch (featureID) { case XBNFPackage.GRAMMAR__NAME: return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name); case XBNFPackage.GRAMMAR__SYNTAX: return getSyntax() != null; case XBNFPackage.GRAMMAR__GOALS: return goals != null && !goals.isEmpty(); case XBNFPackage.GRAMMAR__RULES: return rules != null && !rules.isEmpty(); case XBNFPackage.GRAMMAR__DEBUG: return DEBUG_EDEFAULT == null ? debug != null : !DEBUG_EDEFAULT.equals(debug); } 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(", debug: "); result.append(debug); result.append(')'); return result.toString(); } } //GrammarImpl