Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Dynamic model with a list that may contain more instances of the same object?
Dynamic model with a list that may contain more instances of the same object? [message #688256] Fri, 24 June 2011 09:26 Go to next message
Ulrich  is currently offline Ulrich Friend
Messages: 2
Registered: February 2011
Junior Member
Hi,

i have troubles to create a dynamic model with a list that may contain one or more instances of the same object:



public static <T> EList<T> createList() {
   EcoreFactory theCoreFactory = EcoreFactory.eINSTANCE;

  EPackage emfTabelPackage = theCoreFactory.createEPackage();
  emfTabelPackage.setName("emftable");
  emfTabelPackage.setNsPrefix("emftable");
  emfTabelPackage.setNsURI("emftable");

  EClass listOwnerClass = theCoreFactory.createEClass();
  listOwnerClass.setName("ListOwner");
  EReference list = theCoreFactory.createEReference();
  list.setName("elements");
  list.setEType(EcorePackage.eINSTANCE.getEObject());
  list.setUpperBound(EStructuralFeature.UNBOUNDED_MULTIPLICITY);

  list.setContainment(false);
  list.setUnique(false); // <- doesn't work? 

  listOwnerClass.getEStructuralFeatures().add(list); 
  emfTabelPackage.getEClassifiers().add(listOwnerClass);
  EFactory emfTableFactoryInstance = emfTabelPackage.getEFactoryInstance();

  EObject eObject = emfTableFactoryInstance.create(listOwnerClass);
  EList<T> ret = (EList<T>) eObject.eGet(list);
  return ret;
}




public static void main(String[] args) {
   EList<EObject> list = EmfTable.createList();
   EObject createEObject = EcoreFactory.eINSTANCE.createEObject();
   list.add(createEObject);
   list.add(createEObject);
  
   System.err.println(list.size()); // Should be two, but is one
}





The list always contains only one element.


What went wrong?


Cheers
Ulrich
Re: Dynamic model with a list that may contain more instances of the same object? [message #688273 is a reply to message #688256] Fri, 24 June 2011 10:05 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13124
Registered: July 2009
Senior Member
Hi Ulrich,

seems to be an instance of this bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=89325
see http://www.eclipse.org/forums/index.php?t=msg&th=136463 too

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 24 June 2011 10:07]

Report message to a moderator

Re: Dynamic model with a list that may contain more instances of the same object? [message #688316 is a reply to message #688273] Fri, 24 June 2011 12:23 Go to previous message
Ulrich  is currently offline Ulrich Friend
Messages: 2
Registered: February 2011
Junior Member
Thxs, Christian.
Previous Topic:(no subject)
Next Topic:(no subject)
Goto Forum:
  


Current Time: Fri Sep 20 03:29:19 GMT 2019

Powered by FUDForum. Page generated in 0.02085 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top