1 17 package org.eclipse.emf.codegen.ecore.genmodel.impl; 18 19 20 import org.eclipse.emf.codegen.ecore.genmodel.GenEnum; 21 import org.eclipse.emf.codegen.ecore.genmodel.GenEnumLiteral; 22 import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage; 23 import org.eclipse.emf.codegen.ecore.genmodel.GenPackage; 24 import org.eclipse.emf.common.notify.Notification; 25 import org.eclipse.emf.common.notify.NotificationChain; 26 import org.eclipse.emf.ecore.EClass; 27 import org.eclipse.emf.ecore.EEnumLiteral; 28 import org.eclipse.emf.ecore.EModelElement; 29 import org.eclipse.emf.ecore.EStructuralFeature; 30 import org.eclipse.emf.ecore.InternalEObject; 31 import org.eclipse.emf.ecore.impl.ENotificationImpl; 32 import org.eclipse.emf.ecore.util.EcoreUtil; 33 34 35 49 public class GenEnumLiteralImpl extends GenBaseImpl implements GenEnumLiteral 50 { 51 59 protected EEnumLiteral ecoreEnumLiteral = null; 60 61 66 protected GenEnumLiteralImpl() 67 { 68 super(); 69 } 70 71 76 protected EClass eStaticClass() 77 { 78 return GenModelPackage.eINSTANCE.getGenEnumLiteral(); 79 } 80 81 86 public GenEnum getGenEnum() 87 { 88 if (eContainerFeatureID != GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM) return null; 89 return (GenEnum)eContainer; 90 } 91 92 97 public void setGenEnum(GenEnum newGenEnum) 98 { 99 if (newGenEnum != eContainer || (eContainerFeatureID != GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM && newGenEnum != null)) 100 { 101 if (EcoreUtil.isAncestor(this, newGenEnum)) 102 throw new IllegalArgumentException ("Recursive containment not allowed for " + toString()); 103 NotificationChain msgs = null; 104 if (eContainer != null) 105 msgs = eBasicRemoveFromContainer(msgs); 106 if (newGenEnum != null) 107 msgs = ((InternalEObject)newGenEnum).eInverseAdd(this, GenModelPackage.GEN_ENUM__GEN_ENUM_LITERALS, GenEnum.class, msgs); 108 msgs = eBasicSetContainer((InternalEObject)newGenEnum, GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM, msgs); 109 if (msgs != null) msgs.dispatch(); 110 } 111 else if (eNotificationRequired()) 112 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM, newGenEnum, newGenEnum)); 113 } 114 115 public EModelElement getEcoreModelElement() 116 { 117 return getEcoreEnumLiteral(); 118 } 119 120 125 public EEnumLiteral getEcoreEnumLiteral() 126 { 127 if (ecoreEnumLiteral != null && ecoreEnumLiteral.eIsProxy()) 128 { 129 EEnumLiteral oldEcoreEnumLiteral = ecoreEnumLiteral; 130 ecoreEnumLiteral = (EEnumLiteral)eResolveProxy((InternalEObject)ecoreEnumLiteral); 131 if (ecoreEnumLiteral != oldEcoreEnumLiteral) 132 { 133 if (eNotificationRequired()) 134 eNotify(new ENotificationImpl(this, Notification.RESOLVE, GenModelPackage.GEN_ENUM_LITERAL__ECORE_ENUM_LITERAL, oldEcoreEnumLiteral, ecoreEnumLiteral)); 135 } 136 } 137 return ecoreEnumLiteral; 138 } 139 140 145 public EEnumLiteral basicGetEcoreEnumLiteral() 146 { 147 return ecoreEnumLiteral; 148 } 149 150 155 public void setEcoreEnumLiteral(EEnumLiteral newEcoreEnumLiteral) 156 { 157 EEnumLiteral oldEcoreEnumLiteral = ecoreEnumLiteral; 158 ecoreEnumLiteral = newEcoreEnumLiteral; 159 if (eNotificationRequired()) 160 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_ENUM_LITERAL__ECORE_ENUM_LITERAL, oldEcoreEnumLiteral, ecoreEnumLiteral)); 161 } 162 163 168 public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 169 { 170 if (featureID >= 0) 171 { 172 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 173 { 174 case GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM: 175 if (eContainer != null) 176 msgs = eBasicRemoveFromContainer(msgs); 177 return eBasicSetContainer(otherEnd, GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM, msgs); 178 default: 179 return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs); 180 } 181 } 182 if (eContainer != null) 183 msgs = eBasicRemoveFromContainer(msgs); 184 return eBasicSetContainer(otherEnd, featureID, msgs); 185 } 186 187 192 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 193 { 194 if (featureID >= 0) 195 { 196 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 197 { 198 case GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM: 199 return eBasicSetContainer(null, GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM, msgs); 200 default: 201 return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs); 202 } 203 } 204 return eBasicSetContainer(null, featureID, msgs); 205 } 206 207 212 public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs) 213 { 214 if (eContainerFeatureID >= 0) 215 { 216 switch (eContainerFeatureID) 217 { 218 case GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM: 219 return eContainer.eInverseRemove(this, GenModelPackage.GEN_ENUM__GEN_ENUM_LITERALS, GenEnum.class, msgs); 220 default: 221 return eDynamicBasicRemoveFromContainer(msgs); 222 } 223 } 224 return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs); 225 } 226 227 232 public Object eGet(EStructuralFeature eFeature, boolean resolve) 233 { 234 switch (eDerivedStructuralFeatureID(eFeature)) 235 { 236 case GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM: 237 return getGenEnum(); 238 case GenModelPackage.GEN_ENUM_LITERAL__ECORE_ENUM_LITERAL: 239 if (resolve) return getEcoreEnumLiteral(); 240 return basicGetEcoreEnumLiteral(); 241 } 242 return eDynamicGet(eFeature, resolve); 243 } 244 245 250 public boolean eIsSet(EStructuralFeature eFeature) 251 { 252 switch (eDerivedStructuralFeatureID(eFeature)) 253 { 254 case GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM: 255 return getGenEnum() != null; 256 case GenModelPackage.GEN_ENUM_LITERAL__ECORE_ENUM_LITERAL: 257 return ecoreEnumLiteral != null; 258 } 259 return eDynamicIsSet(eFeature); 260 } 261 262 267 public void eSet(EStructuralFeature eFeature, Object newValue) 268 { 269 switch (eDerivedStructuralFeatureID(eFeature)) 270 { 271 case GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM: 272 setGenEnum((GenEnum)newValue); 273 return; 274 case GenModelPackage.GEN_ENUM_LITERAL__ECORE_ENUM_LITERAL: 275 setEcoreEnumLiteral((EEnumLiteral)newValue); 276 return; 277 } 278 eDynamicSet(eFeature, newValue); 279 } 280 281 286 public void eUnset(EStructuralFeature eFeature) 287 { 288 switch (eDerivedStructuralFeatureID(eFeature)) 289 { 290 case GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM: 291 setGenEnum((GenEnum)null); 292 return; 293 case GenModelPackage.GEN_ENUM_LITERAL__ECORE_ENUM_LITERAL: 294 setEcoreEnumLiteral((EEnumLiteral)null); 295 return; 296 } 297 eDynamicUnset(eFeature); 298 } 299 300 public String getName() 301 { 302 return getEcoreEnumLiteral().getName(); 303 } 304 305 public String getCapName() 306 { 307 return capName(getName()); 308 } 309 310 public String getFormattedName() 311 { 312 return format(getCapName(), ' ', null, false); 313 } 314 315 public int getValue() 316 { 317 return getEcoreEnumLiteral().getValue(); 318 } 319 320 public String getEnumLiteralID() 321 { 322 return format(getName(), '_', null, false).toUpperCase(); 323 } 324 325 public GenPackage getGenPackage() 326 { 327 return getGenEnum().getGenPackage(); 328 } 329 330 public String getEnumLiteralAccessorName() 331 { 332 return getGenEnum().getName() + "_" + getCapName(); 333 } 334 335 public void initialize(EEnumLiteral eEnumLiteral) 336 { 337 setEcoreEnumLiteral(eEnumLiteral); 338 } 339 340 public String getModelInfo() 341 { 342 StringBuffer result = new StringBuffer (); 343 if (!getEnumLiteralID().equals(getName())) 344 { 345 result.append("name=\""); 346 result.append(getName()); 347 result.append('"'); 348 } 349 350 appendAnnotationInfo(result, getEcoreEnumLiteral()); 351 352 return result.toString(); 353 } 354 355 public boolean reconcile(GenEnumLiteral oldGenEnumLiteralVersion) 356 { 357 if (getEcoreEnumLiteral().getName().equals(oldGenEnumLiteralVersion.getEcoreEnumLiteral().getName())) 358 { 359 reconcileSettings(oldGenEnumLiteralVersion); 360 return true; 361 } 362 else 363 { 364 return false; 365 } 366 } 367 368 protected void reconcileSettings(GenEnumLiteral oldGenEnumLiteralVersion) 369 { 370 } 371 372 public boolean reconcile() 373 { 374 EEnumLiteral eEnumLiteral = getEcoreEnumLiteral(); 375 if (eEnumLiteral == null || eEnumLiteral.eIsProxy() || eEnumLiteral.eResource() == null) 376 { 377 return false; 378 } 379 else 380 { 381 return true; 382 } 383 } 384 } 385 | Popular Tags |