Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF] Lower bound 0 vs lower bound 1 of Reference
[EMF] Lower bound 0 vs lower bound 1 of Reference [message #1745049] Tue, 04 October 2016 13:41 Go to next message
Marco Sgura is currently offline Marco SguraFriend
Messages: 5
Registered: September 2016
Junior Member
Hi,

I started recently with EMF and i have a doubt:

If i have class diagram like this:

A -----> B

In the generated code of A i see:

protected B b;


with lower bound = 0 or with lower bound = 1. So in the new Eclipse instance started to populate the model, initial value of property B in an instance of A is not set, then i can set it with a reference to B or return it to initial value. So are there any differences between lower bound = 0 and lower bound = 1 of reference? In the case of lower bound = 1 i was expecting to be able to create an instance of A only then an instance of B to have a consistent value with the lower bound constraint.

Thank you all.
Marco


Re: [EMF] Lower bound 0 vs lower bound 1 of Reference [message #1745052 is a reply to message #1745049] Tue, 04 October 2016 14:04 Go to previous messageGo to next message
Aurélien Mora is currently offline Aurélien MoraFriend
Messages: 38
Registered: July 2014
Member
Hello,

By default, no instance is automatically created for a reference, whether the lower bound is 0 or 1.
The main difference when you change the lower bound, I think, is during the validation of your model : if a lower bound 1 reference is null, you'll have an error.


Now, I suppose your need is to automatically create an instance of B when you create A, isn't it ?
I'm not sure what is the best approach, but you can :
- edit your ModelFactory.createA() (in the model generated code) (no, never do that)
- edit the create command in the edit model (in the edit generated code).

Aurélien.

[Updated on: Tue, 04 October 2016 20:09]

Report message to a moderator

Re: [EMF] Lower bound 0 vs lower bound 1 of Reference [message #1745054 is a reply to message #1745052] Tue, 04 October 2016 14:53 Go to previous messageGo to next message
Marco Sgura is currently offline Marco SguraFriend
Messages: 5
Registered: September 2016
Junior Member
Hello Aurélien,

I don't need to automatically create an instance of B. In my model I have many reference with lower bound set to 1 and i would understand how EMF manages it. I will try to validate my model to see if I get an error.

Thank you.
Marco
Re: [EMF] Lower bound 0 vs lower bound 1 of Reference [message #1745068 is a reply to message #1745054] Tue, 04 October 2016 18:05 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Bound constraints are only checked by the validator, not enforced by the generated code. Only the upper bound has a direct impact on the generated code, i.e., whether the getter returns a single value verses a list of values...

Don't ever change the createAbc methods in the factory to populate features. Many parts of the framework rely on a newly created EObject being in a state were eIsSet will return false for all features. E.g., when you deserialize and when you copy, you should have "bare" objects to start with. Changing the item providers yourpackage.AbcItemProvider.collectNewChildDescriptors(Collection<Object>, Object) is useful for creating populated instances in the editor.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [EMF] Lower bound 0 vs lower bound 1 of Reference [message #1745377 is a reply to message #1745068] Sun, 09 October 2016 10:28 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

As Ed M points out: today, the main difference between [0..1] and [1..1] is that validation will behave differently. This is a modeling activity. You will find that this now affects null-safe navigation warnings in OCL, and may affect the performance and even results of model transformations.

At the Java level the difference is almost irrelevant, since the Java support tends to support transient construction states where mandatory elements may be uninitialized. With the advent of @NonNull annotations, there is case that EMF might evolve to declare @NonNull when getting / setting [1..1] features, perhaps adding a basicGet if you really want the uncertain value. However EMF has such a substantial legacy that such an evolution may be untenable even if funding is provided.

Regards

Ed Willink
Previous Topic:Load model by DOM Node
Next Topic:What is the different between ecore, xcore,xtend,xtext etc
Goto Forum:
  


Current Time: Fri Apr 26 17:10:48 GMT 2024

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

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

Back to the top