/** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * See the NOTICE file distributed with this work for additional * information regarding copyright ownership. */ package org.sintef.thingml.impl; import java.util.ArrayList; import java.util.Collection; import java.util.List; 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 org.sintef.thingml.Action; import org.sintef.thingml.Expression; import org.sintef.thingml.Function; import org.sintef.thingml.HasParameters; import org.sintef.thingml.Parameter; import org.sintef.thingml.ThingmlPackage; import org.sintef.thingml.Type; import org.sintef.thingml.TypedElement; /** * <!-- begin-user-doc --> * An implementation of the model object '<em><b>Function</b></em>'. * <!-- end-user-doc --> * <p> * The following features are implemented: * </p> * <ul> * <li>{@link org.sintef.thingml.impl.FunctionImpl#getType <em>Type</em>}</li> * <li>{@link org.sintef.thingml.impl.FunctionImpl#getCardinality <em>Cardinality</em>}</li> * <li>{@link org.sintef.thingml.impl.FunctionImpl#isIsArray <em>Is Array</em>}</li> * <li>{@link org.sintef.thingml.impl.FunctionImpl#getParameters <em>Parameters</em>}</li> * <li>{@link org.sintef.thingml.impl.FunctionImpl#getBody <em>Body</em>}</li> * </ul> * * @generated */ public class FunctionImpl extends AnnotatedElementImpl implements Function { /** * The cached value of the '{@link #getType() <em>Type</em>}' reference. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #getType() * @generated * @ordered */ protected Type type; /** * The cached value of the '{@link #getCardinality() <em>Cardinality</em>}' containment reference. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #getCardinality() * @generated * @ordered */ protected Expression cardinality; /** * The default value of the '{@link #isIsArray() <em>Is Array</em>}' attribute. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #isIsArray() * @generated * @ordered */ protected static final boolean IS_ARRAY_EDEFAULT = true; /** * The cached value of the '{@link #isIsArray() <em>Is Array</em>}' attribute. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #isIsArray() * @generated * @ordered */ protected boolean isArray = IS_ARRAY_EDEFAULT; /** * The cached value of the '{@link #getParameters() <em>Parameters</em>}' containment reference list. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #getParameters() * @generated * @ordered */ protected EList<Parameter> parameters; /** * The cached value of the '{@link #getBody() <em>Body</em>}' containment reference. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #getBody() * @generated * @ordered */ protected Action body; /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected FunctionImpl() { super(); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override protected EClass eStaticClass() { return ThingmlPackage.Literals.FUNCTION; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public Type getType() { if (type != null && type.eIsProxy()) { InternalEObject oldType = (InternalEObject)type; type = (Type)eResolveProxy(oldType); if (type != oldType) { if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.RESOLVE, ThingmlPackage.FUNCTION__TYPE, oldType, type)); } } return type; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public Type basicGetType() { return type; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setType(Type newType) { Type oldType = type; type = newType; if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, ThingmlPackage.FUNCTION__TYPE, oldType, type)); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public Expression getCardinality() { return cardinality; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public NotificationChain basicSetCardinality(Expression newCardinality, NotificationChain msgs) { Expression oldCardinality = cardinality; cardinality = newCardinality; if (eNotificationRequired()) { ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ThingmlPackage.FUNCTION__CARDINALITY, oldCardinality, newCardinality); if (msgs == null) msgs = notification; else msgs.add(notification); } return msgs; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setCardinality(Expression newCardinality) { if (newCardinality != cardinality) { NotificationChain msgs = null; if (cardinality != null) msgs = ((InternalEObject)cardinality).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ThingmlPackage.FUNCTION__CARDINALITY, null, msgs); if (newCardinality != null) msgs = ((InternalEObject)newCardinality).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ThingmlPackage.FUNCTION__CARDINALITY, null, msgs); msgs = basicSetCardinality(newCardinality, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, ThingmlPackage.FUNCTION__CARDINALITY, newCardinality, newCardinality)); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public boolean isIsArray() { return isArray; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setIsArray(boolean newIsArray) { boolean oldIsArray = isArray; isArray = newIsArray; if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, ThingmlPackage.FUNCTION__IS_ARRAY, oldIsArray, isArray)); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public EList<Parameter> getParameters() { if (parameters == null) { parameters = new EObjectContainmentEList<Parameter>(Parameter.class, this, ThingmlPackage.FUNCTION__PARAMETERS); } return parameters; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public Action getBody() { return body; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public NotificationChain basicSetBody(Action newBody, NotificationChain msgs) { Action oldBody = body; body = newBody; if (eNotificationRequired()) { ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ThingmlPackage.FUNCTION__BODY, oldBody, newBody); if (msgs == null) msgs = notification; else msgs.add(notification); } return msgs; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setBody(Action newBody) { if (newBody != body) { NotificationChain msgs = null; if (body != null) msgs = ((InternalEObject)body).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ThingmlPackage.FUNCTION__BODY, null, msgs); if (newBody != null) msgs = ((InternalEObject)newBody).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ThingmlPackage.FUNCTION__BODY, null, msgs); msgs = basicSetBody(newBody, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, ThingmlPackage.FUNCTION__BODY, newBody, newBody)); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { switch (featureID) { case ThingmlPackage.FUNCTION__CARDINALITY: return basicSetCardinality(null, msgs); case ThingmlPackage.FUNCTION__PARAMETERS: return ((InternalEList<?>)getParameters()).basicRemove(otherEnd, msgs); case ThingmlPackage.FUNCTION__BODY: return basicSetBody(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 ThingmlPackage.FUNCTION__TYPE: if (resolve) return getType(); return basicGetType(); case ThingmlPackage.FUNCTION__CARDINALITY: return getCardinality(); case ThingmlPackage.FUNCTION__IS_ARRAY: return isIsArray(); case ThingmlPackage.FUNCTION__PARAMETERS: return getParameters(); case ThingmlPackage.FUNCTION__BODY: return getBody(); } 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 ThingmlPackage.FUNCTION__TYPE: setType((Type)newValue); return; case ThingmlPackage.FUNCTION__CARDINALITY: setCardinality((Expression)newValue); return; case ThingmlPackage.FUNCTION__IS_ARRAY: setIsArray((Boolean)newValue); return; case ThingmlPackage.FUNCTION__PARAMETERS: getParameters().clear(); getParameters().addAll((Collection<? extends Parameter>)newValue); return; case ThingmlPackage.FUNCTION__BODY: setBody((Action)newValue); return; } super.eSet(featureID, newValue); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case ThingmlPackage.FUNCTION__TYPE: setType((Type)null); return; case ThingmlPackage.FUNCTION__CARDINALITY: setCardinality((Expression)null); return; case ThingmlPackage.FUNCTION__IS_ARRAY: setIsArray(IS_ARRAY_EDEFAULT); return; case ThingmlPackage.FUNCTION__PARAMETERS: getParameters().clear(); return; case ThingmlPackage.FUNCTION__BODY: setBody((Action)null); return; } super.eUnset(featureID); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public boolean eIsSet(int featureID) { switch (featureID) { case ThingmlPackage.FUNCTION__TYPE: return type != null; case ThingmlPackage.FUNCTION__CARDINALITY: return cardinality != null; case ThingmlPackage.FUNCTION__IS_ARRAY: return isArray != IS_ARRAY_EDEFAULT; case ThingmlPackage.FUNCTION__PARAMETERS: return parameters != null && !parameters.isEmpty(); case ThingmlPackage.FUNCTION__BODY: return body != null; } return super.eIsSet(featureID); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass) { if (baseClass == TypedElement.class) { switch (derivedFeatureID) { case ThingmlPackage.FUNCTION__TYPE: return ThingmlPackage.TYPED_ELEMENT__TYPE; case ThingmlPackage.FUNCTION__CARDINALITY: return ThingmlPackage.TYPED_ELEMENT__CARDINALITY; case ThingmlPackage.FUNCTION__IS_ARRAY: return ThingmlPackage.TYPED_ELEMENT__IS_ARRAY; default: return -1; } } if (baseClass == HasParameters.class) { switch (derivedFeatureID) { case ThingmlPackage.FUNCTION__PARAMETERS: return ThingmlPackage.HAS_PARAMETERS__PARAMETERS; default: return -1; } } return super.eBaseStructuralFeatureID(derivedFeatureID, baseClass); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public int eDerivedStructuralFeatureID(int baseFeatureID, Class<?> baseClass) { if (baseClass == TypedElement.class) { switch (baseFeatureID) { case ThingmlPackage.TYPED_ELEMENT__TYPE: return ThingmlPackage.FUNCTION__TYPE; case ThingmlPackage.TYPED_ELEMENT__CARDINALITY: return ThingmlPackage.FUNCTION__CARDINALITY; case ThingmlPackage.TYPED_ELEMENT__IS_ARRAY: return ThingmlPackage.FUNCTION__IS_ARRAY; default: return -1; } } if (baseClass == HasParameters.class) { switch (baseFeatureID) { case ThingmlPackage.HAS_PARAMETERS__PARAMETERS: return ThingmlPackage.FUNCTION__PARAMETERS; default: return -1; } } return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public String toString() { if (eIsProxy()) return super.toString(); StringBuffer result = new StringBuffer(super.toString()); result.append(" (isArray: "); result.append(isArray); result.append(')'); return result.toString(); } } //FunctionImpl