Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 331209

Summary: feature with unique=false implemented by unique list
Product: [Modeling] EMF Reporter: Nicolas Bros <nicolas.bros>
Component: CoreAssignee: Ed Merks <Ed.Merks>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3    
Version: 2.7.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Nicolas Bros CLA 2010-11-26 09:48:34 EST
I have a metamodel with a feature on which "unique" is false :

<eStructuralFeatures xsi:type="ecore:EReference" name="naryReference_notUnique" unique="false" upperBound="-1" eType="#//Class2"/>

EMF Generates this implementation for this feature's getter:

public EList<Class2> getNaryReference_notUnique() {
  if (naryReference_notUnique == null) {
    naryReference_notUnique = new EObjectResolvingEList<Class2>(Class2.class, this, SamplemmPackage.CLASS1__NARY_REFERENCE_NOT_UNIQUE);
  }
  return naryReference_notUnique;
}

On EObjectResolvingEList, the method isUnique() (inherited from EObjectEList) returns true.
Comment 1 Ed Merks CLA 2010-11-26 09:54:03 EST

*** This bug has been marked as a duplicate of bug 89325 ***
Comment 2 Nicolas Bros CLA 2010-11-26 10:10:51 EST
For future reference, a workaround is to override isUnique on the returned list (and mark the method @generated NOT):

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
public EList<Class2> getNaryReference_notUnique() {
  if (this.naryReference_notUnique == null) {
    this.naryReference_notUnique = new EObjectResolvingEList<Class2>(Class2.class, this, SamplemmPackage.CLASS1__NARY_REFERENCE_NOT_UNIQUE) {
      @Override
      protected boolean isUnique() {
        return false;
      }
    };
  }
  return this.naryReference_notUnique;
}