blob: 71617c3568a21ffcaa272f5dc3f1b5f1332f074d [file] [log] [blame]
/**
* <copyright>
* Copyright (c) 2013 Willink Transformations, University of York, 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
* Adolfo Sanchez-Barbudo (University of York) - Bug397429
* </copyright>
*/
package org.eclipse.qvto.examples.pivot.qvtoperational.impl;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.ocl.examples.domain.values.IntegerValue;
import org.eclipse.ocl.examples.domain.values.UnlimitedValue;
import org.eclipse.ocl.examples.pivot.CollectionType;
import org.eclipse.ocl.examples.pivot.Operation;
import org.eclipse.ocl.examples.pivot.Parameter;
import org.eclipse.ocl.examples.pivot.PivotPackage;
import org.eclipse.ocl.examples.pivot.Type;
import org.eclipse.ocl.examples.pivot.TypedMultiplicityElement;
import org.eclipse.ocl.examples.pivot.ValueSpecification;
import org.eclipse.ocl.examples.pivot.internal.impl.VariableImpl;
import org.eclipse.ocl.examples.pivot.util.Visitor;
import org.eclipse.qvto.examples.pivot.qvtoperational.DirectionKind;
import org.eclipse.qvto.examples.pivot.qvtoperational.ImperativeOperation;
import org.eclipse.qvto.examples.pivot.qvtoperational.QVTOperationalPackage;
import org.eclipse.qvto.examples.pivot.qvtoperational.VarParameter;
import org.eclipse.qvto.examples.pivot.qvtoperational.util.QVTOperationalVisitor;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Var Parameter</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* <ul>
* <li>{@link org.eclipse.qvto.examples.pivot.qvtoperational.impl.VarParameterImpl#getOperation <em>Operation</em>}</li>
* <li>{@link org.eclipse.qvto.examples.pivot.qvtoperational.impl.VarParameterImpl#getCtxOwner <em>Ctx Owner</em>}</li>
* <li>{@link org.eclipse.qvto.examples.pivot.qvtoperational.impl.VarParameterImpl#getKind <em>Kind</em>}</li>
* <li>{@link org.eclipse.qvto.examples.pivot.qvtoperational.impl.VarParameterImpl#getResOwner <em>Res Owner</em>}</li>
* </ul>
* </p>
*
* @generated
*/
public class VarParameterImpl extends VariableImpl implements VarParameter {
/**
* The default value of the '{@link #getKind() <em>Kind</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getKind()
* @generated
* @ordered
*/
protected static final DirectionKind KIND_EDEFAULT = DirectionKind.IN;
/**
* The cached value of the '{@link #getKind() <em>Kind</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getKind()
* @generated
* @ordered
*/
protected DirectionKind kind = KIND_EDEFAULT;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected VarParameterImpl() {
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return QVTOperationalPackage.Literals.VAR_PARAMETER;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Operation getOperation() {
if (eContainerFeatureID() != QVTOperationalPackage.VAR_PARAMETER__OPERATION) return null;
return (Operation)eInternalContainer();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetOperation(Operation newOperation, NotificationChain msgs) {
msgs = eBasicSetContainer((InternalEObject)newOperation, QVTOperationalPackage.VAR_PARAMETER__OPERATION, msgs);
return msgs;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setOperation(Operation newOperation) {
if (newOperation != eInternalContainer() || (eContainerFeatureID() != QVTOperationalPackage.VAR_PARAMETER__OPERATION && newOperation != null)) {
if (EcoreUtil.isAncestor(this, (EObject)newOperation))
throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
NotificationChain msgs = null;
if (eInternalContainer() != null)
msgs = eBasicRemoveFromContainer(msgs);
if (newOperation != null)
msgs = ((InternalEObject)newOperation).eInverseAdd(this, PivotPackage.OPERATION__OWNED_PARAMETER, Operation.class, msgs);
msgs = basicSetOperation(newOperation, msgs);
if (msgs != null) msgs.dispatch();
}
else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, QVTOperationalPackage.VAR_PARAMETER__OPERATION, newOperation, newOperation));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public ImperativeOperation getCtxOwner() {
if (eContainerFeatureID() != QVTOperationalPackage.VAR_PARAMETER__CTX_OWNER) return null;
return (ImperativeOperation)eInternalContainer();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetCtxOwner(ImperativeOperation newCtxOwner, NotificationChain msgs) {
msgs = eBasicSetContainer((InternalEObject)newCtxOwner, QVTOperationalPackage.VAR_PARAMETER__CTX_OWNER, msgs);
return msgs;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setCtxOwner(ImperativeOperation newCtxOwner) {
if (newCtxOwner != eInternalContainer() || (eContainerFeatureID() != QVTOperationalPackage.VAR_PARAMETER__CTX_OWNER && newCtxOwner != null)) {
if (EcoreUtil.isAncestor(this, newCtxOwner))
throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
NotificationChain msgs = null;
if (eInternalContainer() != null)
msgs = eBasicRemoveFromContainer(msgs);
if (newCtxOwner != null)
msgs = ((InternalEObject)newCtxOwner).eInverseAdd(this, QVTOperationalPackage.IMPERATIVE_OPERATION__CONTEXT, ImperativeOperation.class, msgs);
msgs = basicSetCtxOwner(newCtxOwner, msgs);
if (msgs != null) msgs.dispatch();
}
else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, QVTOperationalPackage.VAR_PARAMETER__CTX_OWNER, newCtxOwner, newCtxOwner));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public DirectionKind getKind() {
return kind;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setKind(DirectionKind newKind) {
DirectionKind oldKind = kind;
kind = newKind == null ? KIND_EDEFAULT : newKind;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, QVTOperationalPackage.VAR_PARAMETER__KIND, oldKind, kind));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public ImperativeOperation getResOwner() {
if (eContainerFeatureID() != QVTOperationalPackage.VAR_PARAMETER__RES_OWNER) return null;
return (ImperativeOperation)eInternalContainer();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetResOwner(ImperativeOperation newResOwner, NotificationChain msgs) {
msgs = eBasicSetContainer((InternalEObject)newResOwner, QVTOperationalPackage.VAR_PARAMETER__RES_OWNER, msgs);
return msgs;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setResOwner(ImperativeOperation newResOwner) {
if (newResOwner != eInternalContainer() || (eContainerFeatureID() != QVTOperationalPackage.VAR_PARAMETER__RES_OWNER && newResOwner != null)) {
if (EcoreUtil.isAncestor(this, newResOwner))
throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
NotificationChain msgs = null;
if (eInternalContainer() != null)
msgs = eBasicRemoveFromContainer(msgs);
if (newResOwner != null)
msgs = ((InternalEObject)newResOwner).eInverseAdd(this, QVTOperationalPackage.IMPERATIVE_OPERATION__RESULT, ImperativeOperation.class, msgs);
msgs = basicSetResOwner(newResOwner, msgs);
if (msgs != null) msgs.dispatch();
}
else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, QVTOperationalPackage.VAR_PARAMETER__RES_OWNER, newResOwner, newResOwner));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public <R> R accept(final QVTOperationalVisitor<R> v) {
return v.visitVarParameter(this);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public <R> R accept(final Visitor<R> v) {
return ((QVTOperationalVisitor<R>)v).visitVarParameter(this);
}
/**
* The cached invocation delegate for the '{@link #CompatibleBody(org.eclipse.ocl.examples.pivot.ValueSpecification) <em>Compatible Body</em>}' operation.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #CompatibleBody(org.eclipse.ocl.examples.pivot.ValueSpecification)
* @generated
* @ordered
*/
protected static final EOperation.Internal.InvocationDelegate COMPATIBLE_BODY_VALUE_SPECIFICATION__EINVOCATION_DELEGATE = ((EOperation.Internal)PivotPackage.Literals.TYPED_MULTIPLICITY_ELEMENT___COMPATIBLE_BODY__VALUESPECIFICATION).getInvocationDelegate();
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public boolean CompatibleBody(ValueSpecification bodySpecification) {
try {
return (Boolean)COMPATIBLE_BODY_VALUE_SPECIFICATION__EINVOCATION_DELEGATE.dynamicInvoke(this, new BasicEList.UnmodifiableEList<Object>(1, new Object[]{bodySpecification}));
}
catch (InvocationTargetException ite) {
throw new WrappedException(ite);
}
}
/**
* The cached invocation delegate for the '{@link #makeParameter() <em>Make Parameter</em>}' operation.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #makeParameter()
* @generated
* @ordered
*/
protected static final EOperation.Internal.InvocationDelegate MAKE_PARAMETER__EINVOCATION_DELEGATE = ((EOperation.Internal)PivotPackage.Literals.TYPED_MULTIPLICITY_ELEMENT___MAKE_PARAMETER).getInvocationDelegate();
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Parameter makeParameter() {
try {
return (Parameter)MAKE_PARAMETER__EINVOCATION_DELEGATE.dynamicInvoke(this, null);
}
catch (InvocationTargetException ite) {
throw new WrappedException(ite);
}
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
switch (featureID) {
case QVTOperationalPackage.VAR_PARAMETER__OPERATION:
if (eInternalContainer() != null)
msgs = eBasicRemoveFromContainer(msgs);
return basicSetOperation((Operation)otherEnd, msgs);
case QVTOperationalPackage.VAR_PARAMETER__CTX_OWNER:
if (eInternalContainer() != null)
msgs = eBasicRemoveFromContainer(msgs);
return basicSetCtxOwner((ImperativeOperation)otherEnd, msgs);
case QVTOperationalPackage.VAR_PARAMETER__RES_OWNER:
if (eInternalContainer() != null)
msgs = eBasicRemoveFromContainer(msgs);
return basicSetResOwner((ImperativeOperation)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 QVTOperationalPackage.VAR_PARAMETER__OPERATION:
return basicSetOperation(null, msgs);
case QVTOperationalPackage.VAR_PARAMETER__CTX_OWNER:
return basicSetCtxOwner(null, msgs);
case QVTOperationalPackage.VAR_PARAMETER__RES_OWNER:
return basicSetResOwner(null, msgs);
}
return super.eInverseRemove(otherEnd, featureID, msgs);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
switch (eContainerFeatureID()) {
case QVTOperationalPackage.VAR_PARAMETER__OPERATION:
return eInternalContainer().eInverseRemove(this, PivotPackage.OPERATION__OWNED_PARAMETER, Operation.class, msgs);
case QVTOperationalPackage.VAR_PARAMETER__CTX_OWNER:
return eInternalContainer().eInverseRemove(this, QVTOperationalPackage.IMPERATIVE_OPERATION__CONTEXT, ImperativeOperation.class, msgs);
case QVTOperationalPackage.VAR_PARAMETER__RES_OWNER:
return eInternalContainer().eInverseRemove(this, QVTOperationalPackage.IMPERATIVE_OPERATION__RESULT, ImperativeOperation.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 QVTOperationalPackage.VAR_PARAMETER__OPERATION:
return getOperation();
case QVTOperationalPackage.VAR_PARAMETER__CTX_OWNER:
return getCtxOwner();
case QVTOperationalPackage.VAR_PARAMETER__KIND:
return getKind();
case QVTOperationalPackage.VAR_PARAMETER__RES_OWNER:
return getResOwner();
}
return super.eGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case QVTOperationalPackage.VAR_PARAMETER__OPERATION:
setOperation((Operation)newValue);
return;
case QVTOperationalPackage.VAR_PARAMETER__CTX_OWNER:
setCtxOwner((ImperativeOperation)newValue);
return;
case QVTOperationalPackage.VAR_PARAMETER__KIND:
setKind((DirectionKind)newValue);
return;
case QVTOperationalPackage.VAR_PARAMETER__RES_OWNER:
setResOwner((ImperativeOperation)newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case QVTOperationalPackage.VAR_PARAMETER__OPERATION:
setOperation((Operation)null);
return;
case QVTOperationalPackage.VAR_PARAMETER__CTX_OWNER:
setCtxOwner((ImperativeOperation)null);
return;
case QVTOperationalPackage.VAR_PARAMETER__KIND:
setKind(KIND_EDEFAULT);
return;
case QVTOperationalPackage.VAR_PARAMETER__RES_OWNER:
setResOwner((ImperativeOperation)null);
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case QVTOperationalPackage.VAR_PARAMETER__OPERATION:
return getOperation() != null;
case QVTOperationalPackage.VAR_PARAMETER__CTX_OWNER:
return getCtxOwner() != null;
case QVTOperationalPackage.VAR_PARAMETER__KIND:
return kind != KIND_EDEFAULT;
case QVTOperationalPackage.VAR_PARAMETER__RES_OWNER:
return getResOwner() != null;
}
return super.eIsSet(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass) {
if (baseClass == TypedMultiplicityElement.class) {
switch (derivedFeatureID) {
default: return -1;
}
}
if (baseClass == Parameter.class) {
switch (derivedFeatureID) {
case QVTOperationalPackage.VAR_PARAMETER__OPERATION: return PivotPackage.PARAMETER__OPERATION;
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 == TypedMultiplicityElement.class) {
switch (baseFeatureID) {
default: return -1;
}
}
if (baseClass == Parameter.class) {
switch (baseFeatureID) {
case PivotPackage.PARAMETER__OPERATION: return QVTOperationalPackage.VAR_PARAMETER__OPERATION;
default: return -1;
}
}
return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public int eDerivedOperationID(int baseOperationID, Class<?> baseClass) {
if (baseClass == TypedMultiplicityElement.class) {
switch (baseOperationID) {
case PivotPackage.TYPED_MULTIPLICITY_ELEMENT___COMPATIBLE_BODY__VALUESPECIFICATION: return QVTOperationalPackage.VAR_PARAMETER___COMPATIBLE_BODY__VALUESPECIFICATION;
case PivotPackage.TYPED_MULTIPLICITY_ELEMENT___MAKE_PARAMETER: return QVTOperationalPackage.VAR_PARAMETER___MAKE_PARAMETER;
default: return -1;
}
}
if (baseClass == Parameter.class) {
switch (baseOperationID) {
default: return -1;
}
}
return super.eDerivedOperationID(baseOperationID, baseClass);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
@SuppressWarnings({"rawtypes", "unchecked" })
public Object eInvoke(int operationID, EList<?> arguments) throws InvocationTargetException {
switch (operationID) {
case QVTOperationalPackage.VAR_PARAMETER___ACCEPT__QVTOPERATIONALVISITOR:
return accept((QVTOperationalVisitor)arguments.get(0));
case QVTOperationalPackage.VAR_PARAMETER___ACCEPT__VISITOR:
return accept((Visitor)arguments.get(0));
case QVTOperationalPackage.VAR_PARAMETER___COMPATIBLE_BODY__VALUESPECIFICATION:
return CompatibleBody((ValueSpecification)arguments.get(0));
case QVTOperationalPackage.VAR_PARAMETER___MAKE_PARAMETER:
return makeParameter();
}
return super.eInvoke(operationID, arguments);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public String toString() {
if (eIsProxy()) return super.toString();
StringBuffer result = new StringBuffer(super.toString());
result.append(" (kind: ");
result.append(kind);
result.append(')');
return result.toString();
}
// FIXME copied from TypedMultiplicityElementImpl. See bug 409268
public boolean isMany() {
Type type = getType();
if (type instanceof CollectionType) {
CollectionType collectionType = (CollectionType)type;
IntegerValue upperValue = collectionType.getUpperValue();
return !(upperValue instanceof UnlimitedValue) && (upperValue.intValue() > 1);
}
return false;
}
} //VarParameterImpl