| /******************************************************************************* |
| * Copyright (c) 2004, 2005 IBM Corporation 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: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.jem.internal.instantiation.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.EStructuralFeature; |
| 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.eclipse.jem.internal.instantiation.*; |
| import org.eclipse.jem.internal.instantiation.PTArrayAccess; |
| import org.eclipse.jem.internal.instantiation.PTExpression; |
| import org.eclipse.jem.internal.instantiation.InstantiationPackage; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * An implementation of the model object '<em><b>Array Access</b></em>'. |
| * <!-- end-user-doc --> |
| * <p> |
| * The following features are implemented: |
| * <ul> |
| * <li>{@link org.eclipse.jem.internal.instantiation.impl.PTArrayAccessImpl#getArray <em>Array</em>}</li> |
| * <li>{@link org.eclipse.jem.internal.instantiation.impl.PTArrayAccessImpl#getIndexes <em>Indexes</em>}</li> |
| * </ul> |
| * </p> |
| * |
| * @generated |
| */ |
| public class PTArrayAccessImpl extends PTExpressionImpl implements PTArrayAccess { |
| /** |
| * The cached value of the '{@link #getArray() <em>Array</em>}' containment reference. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @see #getArray() |
| * @generated |
| * @ordered |
| */ |
| protected PTExpression array = null; |
| |
| /** |
| * The cached value of the '{@link #getIndexes() <em>Indexes</em>}' containment reference list. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @see #getIndexes() |
| * @generated |
| * @ordered |
| */ |
| protected EList indexes = null; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| protected PTArrayAccessImpl() { |
| super(); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| protected EClass eStaticClass() { |
| return InstantiationPackage.eINSTANCE.getPTArrayAccess(); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public PTExpression getArray() { |
| return array; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public NotificationChain basicSetArray(PTExpression newArray, NotificationChain msgs) { |
| PTExpression oldArray = array; |
| array = newArray; |
| if (eNotificationRequired()) { |
| ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, InstantiationPackage.PT_ARRAY_ACCESS__ARRAY, oldArray, newArray); |
| if (msgs == null) msgs = notification; else msgs.add(notification); |
| } |
| return msgs; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public void setArray(PTExpression newArray) { |
| if (newArray != array) { |
| NotificationChain msgs = null; |
| if (array != null) |
| msgs = ((InternalEObject)array).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - InstantiationPackage.PT_ARRAY_ACCESS__ARRAY, null, msgs); |
| if (newArray != null) |
| msgs = ((InternalEObject)newArray).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - InstantiationPackage.PT_ARRAY_ACCESS__ARRAY, null, msgs); |
| msgs = basicSetArray(newArray, msgs); |
| if (msgs != null) msgs.dispatch(); |
| } |
| else if (eNotificationRequired()) |
| eNotify(new ENotificationImpl(this, Notification.SET, InstantiationPackage.PT_ARRAY_ACCESS__ARRAY, newArray, newArray)); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public EList getIndexes() { |
| if (indexes == null) { |
| indexes = new EObjectContainmentEList(PTExpression.class, this, InstantiationPackage.PT_ARRAY_ACCESS__INDEXES); |
| } |
| return indexes; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) { |
| if (featureID >= 0) { |
| switch (eDerivedStructuralFeatureID(featureID, baseClass)) { |
| case InstantiationPackage.PT_ARRAY_ACCESS__ARRAY: |
| return basicSetArray(null, msgs); |
| case InstantiationPackage.PT_ARRAY_ACCESS__INDEXES: |
| return ((InternalEList)getIndexes()).basicRemove(otherEnd, msgs); |
| default: |
| return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs); |
| } |
| } |
| return eBasicSetContainer(null, featureID, msgs); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public Object eGet(EStructuralFeature eFeature, boolean resolve) { |
| switch (eDerivedStructuralFeatureID(eFeature)) { |
| case InstantiationPackage.PT_ARRAY_ACCESS__ARRAY: |
| return getArray(); |
| case InstantiationPackage.PT_ARRAY_ACCESS__INDEXES: |
| return getIndexes(); |
| } |
| return eDynamicGet(eFeature, resolve); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public void eSet(EStructuralFeature eFeature, Object newValue) { |
| switch (eDerivedStructuralFeatureID(eFeature)) { |
| case InstantiationPackage.PT_ARRAY_ACCESS__ARRAY: |
| setArray((PTExpression)newValue); |
| return; |
| case InstantiationPackage.PT_ARRAY_ACCESS__INDEXES: |
| getIndexes().clear(); |
| getIndexes().addAll((Collection)newValue); |
| return; |
| } |
| eDynamicSet(eFeature, newValue); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public void eUnset(EStructuralFeature eFeature) { |
| switch (eDerivedStructuralFeatureID(eFeature)) { |
| case InstantiationPackage.PT_ARRAY_ACCESS__ARRAY: |
| setArray((PTExpression)null); |
| return; |
| case InstantiationPackage.PT_ARRAY_ACCESS__INDEXES: |
| getIndexes().clear(); |
| return; |
| } |
| eDynamicUnset(eFeature); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public boolean eIsSet(EStructuralFeature eFeature) { |
| switch (eDerivedStructuralFeatureID(eFeature)) { |
| case InstantiationPackage.PT_ARRAY_ACCESS__ARRAY: |
| return array != null; |
| case InstantiationPackage.PT_ARRAY_ACCESS__INDEXES: |
| return indexes != null && !indexes.isEmpty(); |
| } |
| return eDynamicIsSet(eFeature); |
| } |
| |
| /* |
| * (non-Javadoc) |
| * @see org.eclipse.jem.internal.instantiation.impl.ExpressionImpl#accept0(org.eclipse.jem.internal.instantiation.ParseVisitor) |
| */ |
| protected void accept0(ParseVisitor visitor) { |
| boolean visitChildren = visitor.visit(this); |
| if (visitChildren) { |
| // visit children in normal left to right reading order |
| acceptChild(visitor, getArray()); |
| if (indexes != null) |
| acceptChildren(visitor, indexes); |
| } |
| visitor.endVisit(this); |
| } |
| |
| } //ArrayAccessImpl |