| /******************************************************************************* |
| * Copyright (c) 2010, 2019 Willink Transformations and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v2.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v20.html |
| * |
| * Contributors: |
| * E.D.Willink - Initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.ocl.pivot.internal; |
| |
| import java.util.Collection; |
| |
| import org.eclipse.emf.common.notify.Notification; |
| import org.eclipse.emf.common.notify.NotificationChain; |
| import org.eclipse.emf.common.util.Enumerator; |
| import org.eclipse.emf.ecore.EClass; |
| import org.eclipse.emf.ecore.EEnumLiteral; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.ecore.InternalEObject; |
| import org.eclipse.emf.ecore.impl.ENotificationImpl; |
| import org.eclipse.emf.ecore.util.EcoreUtil; |
| import org.eclipse.emf.ecore.util.InternalEList; |
| import org.eclipse.jdt.annotation.NonNull; |
| import org.eclipse.ocl.pivot.Comment; |
| import org.eclipse.ocl.pivot.Element; |
| import org.eclipse.ocl.pivot.ElementExtension; |
| import org.eclipse.ocl.pivot.Enumeration; |
| import org.eclipse.ocl.pivot.EnumerationLiteral; |
| import org.eclipse.ocl.pivot.LanguageExpression; |
| import org.eclipse.ocl.pivot.PivotFactory; |
| import org.eclipse.ocl.pivot.PivotPackage; |
| import org.eclipse.ocl.pivot.Slot; |
| import org.eclipse.ocl.pivot.ids.EnumerationId; |
| import org.eclipse.ocl.pivot.ids.EnumerationLiteralId; |
| import org.eclipse.ocl.pivot.util.Visitor; |
| import org.eclipse.ocl.pivot.utilities.ClassUtil; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * An implementation of the model object '<em><b>Enumeration Literal</b></em>'. |
| * <!-- end-user-doc --> |
| * <p> |
| * The following features are implemented: |
| * </p> |
| * <ul> |
| * <li>{@link org.eclipse.ocl.pivot.internal.EnumerationLiteralImpl#getLiteral <em>Literal</em>}</li> |
| * <li>{@link org.eclipse.ocl.pivot.internal.EnumerationLiteralImpl#getOwningEnumeration <em>Owning Enumeration</em>}</li> |
| * <li>{@link org.eclipse.ocl.pivot.internal.EnumerationLiteralImpl#getValue <em>Value</em>}</li> |
| * </ul> |
| * |
| * @generated |
| */ |
| public class EnumerationLiteralImpl |
| extends InstanceSpecificationImpl |
| implements EnumerationLiteral { |
| |
| /** |
| * The number of structural features of the '<em>Enumeration Literal</em>' class. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| * @ordered |
| */ |
| public static final int ENUMERATION_LITERAL_FEATURE_COUNT = InstanceSpecificationImpl.INSTANCE_SPECIFICATION_FEATURE_COUNT + 3; |
| /** |
| * The number of operations of the '<em>Enumeration Literal</em>' class. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| * @ordered |
| */ |
| public static final int ENUMERATION_LITERAL_OPERATION_COUNT = InstanceSpecificationImpl.INSTANCE_SPECIFICATION_OPERATION_COUNT + 0; |
| /** |
| * The default value of the '{@link #getLiteral() <em>Literal</em>}' attribute. |
| * <!-- begin-user-doc --> |
| * @since 1.4 |
| * <!-- end-user-doc --> |
| * @see #getLiteral() |
| * @generated |
| * @ordered |
| */ |
| protected static final String LITERAL_EDEFAULT = "0"; //$NON-NLS-1$ |
| /** |
| * The cached value of the '{@link #getLiteral() <em>Literal</em>}' attribute. |
| * <!-- begin-user-doc --> |
| * @since 1.4 |
| * <!-- end-user-doc --> |
| * @see #getLiteral() |
| * @generated |
| * @ordered |
| */ |
| protected String literal = LITERAL_EDEFAULT; |
| /** |
| * The default value of the '{@link #getValue() <em>Value</em>}' attribute. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @see #getValue() |
| * @generated |
| * @ordered |
| */ |
| protected static final Number VALUE_EDEFAULT = (Number)PivotFactory.eINSTANCE.createFromString(PivotPackage.eINSTANCE.getInteger(), "0"); //$NON-NLS-1$ |
| /** |
| * The cached value of the '{@link #getValue() <em>Value</em>}' attribute. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @see #getValue() |
| * @generated |
| * @ordered |
| */ |
| protected Number value = VALUE_EDEFAULT; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| protected EnumerationLiteralImpl() { |
| super(); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| protected EClass eStaticClass() { |
| return PivotPackage.Literals.ENUMERATION_LITERAL; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public String getLiteral() |
| { |
| return literal; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public void setLiteral(String newLiteral) |
| { |
| String oldLiteral = literal; |
| literal = newLiteral; |
| if (eNotificationRequired()) |
| eNotify(new ENotificationImpl(this, Notification.SET, 9, oldLiteral, literal)); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public Enumeration getOwningEnumeration() |
| { |
| if (eContainerFeatureID() != (10)) return null; |
| return (Enumeration)eInternalContainer(); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public NotificationChain basicSetOwningEnumeration(Enumeration newOwningEnumeration, NotificationChain msgs) |
| { |
| msgs = eBasicSetContainer((InternalEObject)newOwningEnumeration, 10, msgs); |
| return msgs; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public void setOwningEnumeration(Enumeration newOwningEnumeration) |
| { |
| if (newOwningEnumeration != eInternalContainer() || (eContainerFeatureID() != (10) && newOwningEnumeration != null)) |
| { |
| if (EcoreUtil.isAncestor(this, newOwningEnumeration)) |
| throw new IllegalArgumentException("Recursive containment not allowed for " + toString()); //$NON-NLS-1$ |
| NotificationChain msgs = null; |
| if (eInternalContainer() != null) |
| msgs = eBasicRemoveFromContainer(msgs); |
| if (newOwningEnumeration != null) |
| msgs = ((InternalEObject)newOwningEnumeration).eInverseAdd(this, 23, Enumeration.class, msgs); |
| msgs = basicSetOwningEnumeration(newOwningEnumeration, msgs); |
| if (msgs != null) msgs.dispatch(); |
| } |
| else if (eNotificationRequired()) |
| eNotify(new ENotificationImpl(this, Notification.SET, 10, newOwningEnumeration, newOwningEnumeration)); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public Number getValue() |
| { |
| return value; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public void setValue(Number newValue) |
| { |
| Number oldValue = value; |
| value = newValue; |
| if (eNotificationRequired()) |
| eNotify(new ENotificationImpl(this, Notification.SET, 11, oldValue, value)); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @SuppressWarnings("unchecked") |
| @Override |
| public NotificationChain eInverseAdd(InternalEObject otherEnd, |
| int featureID, NotificationChain msgs) { |
| switch (featureID) |
| { |
| case 0: |
| return ((InternalEList<InternalEObject>)(InternalEList<?>)getAnnotatingComments()).basicAdd(otherEnd, msgs); |
| case 2: |
| return ((InternalEList<InternalEObject>)(InternalEList<?>)getOwnedComments()).basicAdd(otherEnd, msgs); |
| case 3: |
| return ((InternalEList<InternalEObject>)(InternalEList<?>)getOwnedExtensions()).basicAdd(otherEnd, msgs); |
| case 6: |
| return ((InternalEList<InternalEObject>)(InternalEList<?>)getOwnedSlots()).basicAdd(otherEnd, msgs); |
| case 8: |
| if (eInternalContainer() != null) |
| msgs = eBasicRemoveFromContainer(msgs); |
| return basicSetOwningPackage((org.eclipse.ocl.pivot.Package)otherEnd, msgs); |
| case 10: |
| if (eInternalContainer() != null) |
| msgs = eBasicRemoveFromContainer(msgs); |
| return basicSetOwningEnumeration((Enumeration)otherEnd, msgs); |
| } |
| return eDynamicInverseAdd(otherEnd, featureID, msgs); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public NotificationChain eInverseRemove(InternalEObject otherEnd, |
| int featureID, NotificationChain msgs) { |
| switch (featureID) |
| { |
| case 0: |
| return ((InternalEList<?>)getAnnotatingComments()).basicRemove(otherEnd, msgs); |
| case 1: |
| return ((InternalEList<?>)getOwnedAnnotations()).basicRemove(otherEnd, msgs); |
| case 2: |
| return ((InternalEList<?>)getOwnedComments()).basicRemove(otherEnd, msgs); |
| case 3: |
| return ((InternalEList<?>)getOwnedExtensions()).basicRemove(otherEnd, msgs); |
| case 6: |
| return ((InternalEList<?>)getOwnedSlots()).basicRemove(otherEnd, msgs); |
| case 7: |
| return basicSetOwnedSpecification(null, msgs); |
| case 8: |
| return basicSetOwningPackage(null, msgs); |
| case 10: |
| return basicSetOwningEnumeration(null, msgs); |
| } |
| return eDynamicInverseRemove(otherEnd, featureID, msgs); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public NotificationChain eBasicRemoveFromContainerFeature( |
| NotificationChain msgs) { |
| switch (eContainerFeatureID()) |
| { |
| case 8: |
| return eInternalContainer().eInverseRemove(this, 10, org.eclipse.ocl.pivot.Package.class, msgs); |
| case 10: |
| return eInternalContainer().eInverseRemove(this, 23, Enumeration.class, msgs); |
| } |
| return eDynamicBasicRemoveFromContainer(msgs); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public Object eGet(int featureID, boolean resolve, boolean coreType) { |
| switch (featureID) |
| { |
| case 0: |
| return getAnnotatingComments(); |
| case 1: |
| return getOwnedAnnotations(); |
| case 2: |
| return getOwnedComments(); |
| case 3: |
| return getOwnedExtensions(); |
| case 4: |
| return getName(); |
| case 5: |
| return getClasses(); |
| case 6: |
| return getOwnedSlots(); |
| case 7: |
| return getOwnedSpecification(); |
| case 8: |
| return getOwningPackage(); |
| case 9: |
| return getLiteral(); |
| case 10: |
| return getOwningEnumeration(); |
| case 11: |
| return getValue(); |
| } |
| return eDynamicGet(featureID, resolve, coreType); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @SuppressWarnings("unchecked") |
| @Override |
| public void eSet(int featureID, Object newValue) { |
| switch (featureID) |
| { |
| case 0: |
| getAnnotatingComments().clear(); |
| getAnnotatingComments().addAll((Collection<? extends Comment>)newValue); |
| return; |
| case 1: |
| getOwnedAnnotations().clear(); |
| getOwnedAnnotations().addAll((Collection<? extends Element>)newValue); |
| return; |
| case 2: |
| getOwnedComments().clear(); |
| getOwnedComments().addAll((Collection<? extends Comment>)newValue); |
| return; |
| case 3: |
| getOwnedExtensions().clear(); |
| getOwnedExtensions().addAll((Collection<? extends ElementExtension>)newValue); |
| return; |
| case 4: |
| setName((String)newValue); |
| return; |
| case 5: |
| getClasses().clear(); |
| getClasses().addAll((Collection<? extends org.eclipse.ocl.pivot.Class>)newValue); |
| return; |
| case 6: |
| getOwnedSlots().clear(); |
| getOwnedSlots().addAll((Collection<? extends Slot>)newValue); |
| return; |
| case 7: |
| setOwnedSpecification((LanguageExpression)newValue); |
| return; |
| case 8: |
| setOwningPackage((org.eclipse.ocl.pivot.Package)newValue); |
| return; |
| case 9: |
| setLiteral((String)newValue); |
| return; |
| case 10: |
| setOwningEnumeration((Enumeration)newValue); |
| return; |
| case 11: |
| setValue((Number)newValue); |
| return; |
| } |
| eDynamicSet(featureID, newValue); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public void eUnset(int featureID) { |
| switch (featureID) |
| { |
| case 0: |
| getAnnotatingComments().clear(); |
| return; |
| case 1: |
| getOwnedAnnotations().clear(); |
| return; |
| case 2: |
| getOwnedComments().clear(); |
| return; |
| case 3: |
| getOwnedExtensions().clear(); |
| return; |
| case 4: |
| setName(NAME_EDEFAULT); |
| return; |
| case 5: |
| getClasses().clear(); |
| return; |
| case 6: |
| getOwnedSlots().clear(); |
| return; |
| case 7: |
| setOwnedSpecification((LanguageExpression)null); |
| return; |
| case 8: |
| setOwningPackage((org.eclipse.ocl.pivot.Package)null); |
| return; |
| case 9: |
| setLiteral(LITERAL_EDEFAULT); |
| return; |
| case 10: |
| setOwningEnumeration((Enumeration)null); |
| return; |
| case 11: |
| setValue(VALUE_EDEFAULT); |
| return; |
| } |
| eDynamicUnset(featureID); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public boolean eIsSet(int featureID) { |
| switch (featureID) |
| { |
| case 0: |
| return annotatingComments != null && !annotatingComments.isEmpty(); |
| case 1: |
| return ownedAnnotations != null && !ownedAnnotations.isEmpty(); |
| case 2: |
| return ownedComments != null && !ownedComments.isEmpty(); |
| case 3: |
| return ownedExtensions != null && !ownedExtensions.isEmpty(); |
| case 4: |
| return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name); |
| case 5: |
| return classes != null && !classes.isEmpty(); |
| case 6: |
| return ownedSlots != null && !ownedSlots.isEmpty(); |
| case 7: |
| return ownedSpecification != null; |
| case 8: |
| return getOwningPackage() != null; |
| case 9: |
| return LITERAL_EDEFAULT == null ? literal != null : !LITERAL_EDEFAULT.equals(literal); |
| case 10: |
| return getOwningEnumeration() != null; |
| case 11: |
| return VALUE_EDEFAULT == null ? value != null : !VALUE_EDEFAULT.equals(value); |
| } |
| return eDynamicIsSet(featureID); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated NOT |
| */ |
| @Override |
| public String toString() |
| { |
| return super.toString(); |
| } |
| |
| @Override |
| public <R> R accept(@NonNull Visitor<R> visitor) { |
| return visitor.visitEnumerationLiteral(this); |
| } |
| |
| @Override |
| public @NonNull Enumerator getEnumerator() { |
| EObject eTarget = getESObject(); |
| if (eTarget instanceof EEnumLiteral) { |
| return ClassUtil.nonNullEMF(((EEnumLiteral) eTarget).getInstance()); |
| } |
| else { |
| throw new UnsupportedOperationException(); // FIXME |
| } |
| } |
| |
| private /*@LazyNonNull*/ EnumerationLiteralId enumerationLiteralId = null; |
| |
| @Override |
| public @NonNull EnumerationLiteralId getEnumerationLiteralId() { |
| EnumerationLiteralId enumerationLiteralId2 = enumerationLiteralId; |
| if (enumerationLiteralId2 == null) { |
| String name = ClassUtil.nonNullModel(getName()); |
| EnumerationId enumerationId = getOwningEnumeration().getEnumerationId(); |
| enumerationLiteralId = enumerationLiteralId2 = enumerationId.getEnumerationLiteralId(name); |
| } |
| return enumerationLiteralId2; |
| } |
| } //EnumerationLiteralImpl |