1 17 package org.eclipse.emf.ecore.impl; 18 19 20 import java.util.Collection ; 21 22 import org.eclipse.emf.common.notify.Notification; 23 import org.eclipse.emf.common.notify.NotificationChain; 24 import org.eclipse.emf.common.util.Enumerator; 25 import org.eclipse.emf.ecore.EClass; 26 import org.eclipse.emf.ecore.EEnum; 27 import org.eclipse.emf.ecore.EEnumLiteral; 28 import org.eclipse.emf.ecore.EStructuralFeature; 29 import org.eclipse.emf.ecore.EcorePackage; 30 import org.eclipse.emf.ecore.InternalEObject; 31 import org.eclipse.emf.ecore.util.InternalEList; 32 33 34 49 public class EEnumLiteralImpl extends ENamedElementImpl implements EEnumLiteral 50 { 51 59 protected static final int VALUE_EDEFAULT = 0; 60 61 69 protected int value = VALUE_EDEFAULT; 70 71 79 protected static final Enumerator INSTANCE_EDEFAULT = null; 80 81 89 protected Enumerator instance = INSTANCE_EDEFAULT; 90 91 96 protected EEnumLiteralImpl() 97 { 98 super(); 99 instance = this; 100 } 101 102 107 protected EClass eStaticClass() 108 { 109 return EcorePackage.eINSTANCE.getEEnumLiteral(); 110 } 111 112 117 public int getValue() 118 { 119 return value; 120 } 121 122 127 public void setValue(int newValue) 128 { 129 int oldValue = value; 130 value = newValue; 131 if (eNotificationRequired()) 132 eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EENUM_LITERAL__VALUE, oldValue, value)); 133 } 134 135 140 public Enumerator getInstance() 141 { 142 return instance; 143 } 144 145 150 public void setInstanceGen(Enumerator newInstance) 151 { 152 Enumerator oldInstance = instance; 153 instance = newInstance; 154 if (eNotificationRequired()) 155 eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EENUM_LITERAL__INSTANCE, oldInstance, instance)); 156 } 157 158 public void setInstance(Enumerator newInstance) 159 { 160 setInstanceGen(newInstance); 161 if (newInstance == null) 162 { 163 setName(null); 164 setValue(0); 165 } 166 else if (newInstance != this) 167 { 168 setName(newInstance.getName()); 169 setValue(newInstance.getValue()); 170 } 171 } 172 173 178 public EEnum getEEnum() 179 { 180 return (eContainerFeatureID == EcorePackage.EENUM_LITERAL__EENUM) ? (EEnum)eContainer : null; 181 } 182 183 188 public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 189 { 190 if (featureID >= 0) 191 { 192 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 193 { 194 case EcorePackage.EENUM_LITERAL__EANNOTATIONS: 195 return ((InternalEList)getEAnnotations()).basicAdd(otherEnd, msgs); 196 case EcorePackage.EENUM_LITERAL__EENUM: 197 if (eContainer != null) 198 msgs = eBasicRemoveFromContainer(msgs); 199 return eBasicSetContainer(otherEnd, EcorePackage.EENUM_LITERAL__EENUM, msgs); 200 default: 201 return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs); 202 } 203 } 204 if (eContainer != null) 205 msgs = eBasicRemoveFromContainer(msgs); 206 return eBasicSetContainer(otherEnd, featureID, msgs); 207 } 208 209 214 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 215 { 216 if (featureID >= 0) 217 { 218 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 219 { 220 case EcorePackage.EENUM_LITERAL__EANNOTATIONS: 221 return ((InternalEList)getEAnnotations()).basicRemove(otherEnd, msgs); 222 case EcorePackage.EENUM_LITERAL__EENUM: 223 return eBasicSetContainer(null, EcorePackage.EENUM_LITERAL__EENUM, msgs); 224 default: 225 return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs); 226 } 227 } 228 return eBasicSetContainer(null, featureID, msgs); 229 } 230 231 236 public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs) 237 { 238 if (eContainerFeatureID >= 0) 239 { 240 switch (eContainerFeatureID) 241 { 242 case EcorePackage.EENUM_LITERAL__EENUM: 243 return eContainer.eInverseRemove(this, EcorePackage.EENUM__ELITERALS, EEnum.class, msgs); 244 default: 245 return eDynamicBasicRemoveFromContainer(msgs); 246 } 247 } 248 return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs); 249 } 250 251 256 public Object eGet(EStructuralFeature eFeature, boolean resolve) 257 { 258 switch (eDerivedStructuralFeatureID(eFeature)) 259 { 260 case EcorePackage.EENUM_LITERAL__EANNOTATIONS: 261 return getEAnnotations(); 262 case EcorePackage.EENUM_LITERAL__NAME: 263 return getName(); 264 case EcorePackage.EENUM_LITERAL__VALUE: 265 return new Integer (getValue()); 266 case EcorePackage.EENUM_LITERAL__INSTANCE: 267 return getInstance(); 268 case EcorePackage.EENUM_LITERAL__EENUM: 269 return getEEnum(); 270 } 271 return eDynamicGet(eFeature, resolve); 272 } 273 274 279 public boolean eIsSet(EStructuralFeature eFeature) 280 { 281 switch (eDerivedStructuralFeatureID(eFeature)) 282 { 283 case EcorePackage.EENUM_LITERAL__EANNOTATIONS: 284 return eAnnotations != null && !eAnnotations.isEmpty(); 285 case EcorePackage.EENUM_LITERAL__NAME: 286 return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name); 287 case EcorePackage.EENUM_LITERAL__VALUE: 288 return value != VALUE_EDEFAULT; 289 case EcorePackage.EENUM_LITERAL__INSTANCE: 290 return INSTANCE_EDEFAULT == null ? instance != null : !INSTANCE_EDEFAULT.equals(instance); 291 case EcorePackage.EENUM_LITERAL__EENUM: 292 return getEEnum() != null; 293 } 294 return eDynamicIsSet(eFeature); 295 } 296 297 302 public void eSet(EStructuralFeature eFeature, Object newValue) 303 { 304 switch (eDerivedStructuralFeatureID(eFeature)) 305 { 306 case EcorePackage.EENUM_LITERAL__EANNOTATIONS: 307 getEAnnotations().clear(); 308 getEAnnotations().addAll((Collection )newValue); 309 return; 310 case EcorePackage.EENUM_LITERAL__NAME: 311 setName((String )newValue); 312 return; 313 case EcorePackage.EENUM_LITERAL__VALUE: 314 setValue(((Integer )newValue).intValue()); 315 return; 316 case EcorePackage.EENUM_LITERAL__INSTANCE: 317 setInstance((Enumerator)newValue); 318 return; 319 } 320 eDynamicSet(eFeature, newValue); 321 } 322 323 328 public void eUnset(EStructuralFeature eFeature) 329 { 330 switch (eDerivedStructuralFeatureID(eFeature)) 331 { 332 case EcorePackage.EENUM_LITERAL__EANNOTATIONS: 333 getEAnnotations().clear(); 334 return; 335 case EcorePackage.EENUM_LITERAL__NAME: 336 setName(NAME_EDEFAULT); 337 return; 338 case EcorePackage.EENUM_LITERAL__VALUE: 339 setValue(VALUE_EDEFAULT); 340 return; 341 case EcorePackage.EENUM_LITERAL__INSTANCE: 342 setInstance(INSTANCE_EDEFAULT); 343 return; 344 } 345 eDynamicUnset(eFeature); 346 } 347 348 public String toString() 349 { 350 return getName(); 351 } 352 353 358 public String toStringGen() 359 { 360 if (eIsProxy()) return super.toString(); 361 362 StringBuffer result = new StringBuffer (super.toString()); 363 result.append(" (value: "); 364 result.append(value); 365 result.append(", instance: "); 366 result.append(instance); 367 result.append(')'); 368 return result.toString(); 369 } 370 371 } 372 | Popular Tags |