[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.emf] Re: Default Value of an inherited EAttribute or EReference

Guys,

Comments below.

Michael Mühlberg wrote:
Hello John,

I would suggest to change the constructor of the generated impl class for B 
and set the value there. Take into account that the attribute can be 
unsettable. In this case you also have to change the generated change 
tracking variable from which I currently don't know the name :)
  
No, don't ever populate instance in the constructor.  You must start values in their ground state because things like deserialization and the copier expect that.
As far as I know there is no generator include template foreseen for 
changing the generation of constructor code. Taking the original templates 
and modifying them is problematic because in this case you have to merge all 
future changes therein.
  
Yes, though the templates don't change much these days.
I didn't find any way to overwrite defaults only via modeling, one has to 
modify the generated code or the generation templates :(
  
Reference defaults are problematic.
Ciao, Michael



"John T.E. Timm" <johntimm@xxxxxxxxxx> wrote in message 
news:9af675507e16f9247052dde7c18e7de5$1@xxxxxxxxxxxxxxx...
  
I have two classes A and B. B is a subclass of A. B inherits an attribute 
    
>from A and I want to default the value of this attribute when B is 
  
constructed.

A : EClass
 attr : EAttribute

B -> A : EClass
 attr := 'someDefaultValue' : EAttribute

What is the best way to set the default value of an inherited EAttribute 
or EReference?
References don't support defaults at all.
 My guess is that I need to extend code generation to pick 
up an annotation attached to an EClass and generate some initialization 
code in the constructor.
It's a bad idea though because such a thing will not behave like a proper default.  It will appear to be eIsSet true and will be serialized.
 Does such an annotation already exist? Is there a 
more automated way of accomplishing this?
    
Best avoid it entirely... Or have just an operation on A with a name that is overloaded by the attribute in B...
Thanks,

JT