Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Set-accessor Body?(Set-accessor Body?)
Set-accessor Body? [message #1850562] Tue, 08 March 2022 14:16 Go to next message
Antonio Garmendia is currently offline Antonio GarmendiaFriend
Messages: 93
Registered: May 2014
Member
Hi all,

Currently, I am working with derived references. When I click on my derived reference in the genmodel, I can see in the properties view the text-field for the Get-accessor Body, so I can insert my code there.

However, I cannot see a Set-Accessor Body. I notice that the setter method is generated but of course, it is left empty. My problem is that I want to generate the genmodel from another application, set the bodies for the setter and getter, and then, generate the model code.

Is there a way to manage the setter the same way as the getter? Or should I create a setter EOperation?

Thanks in advance!

Kind regards,
Antonio
Re: Set-accessor Body? [message #1850572 is a reply to message #1850562] Tue, 08 March 2022 17:00 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The regular way to specify Java bodies for EMF functionality is through an "http://www.eclipse.org/emf/2002/GenModel" EAnnotation, with "body", "get", "set" keys in the Ecore model.

I was not aware of the genmodel capability. It would seem that this friendly alternative has hidden the general solution from you.

The EMF Generator capability is powerful and extensible. You might find the approach taken by the OCL2Java code generator helpful. See the org.eclipse.ocl.examples.codegen plugin. The OCL Generator registers a pre and post generator. The pre-generator synthesizes the required Java code from OCL EAnnotations and embeds it as Java EAnnotations that are the used by the regular generator. The post generator undoes the changes in case anyone else is interested in the resulting models. This approach avoids cluttering the *.ecore model.

Regards

Ed Willink
Re: Set-accessor Body? [message #1850597 is a reply to message #1850572] Wed, 09 March 2022 14:05 Go to previous messageGo to next message
Antonio Garmendia is currently offline Antonio GarmendiaFriend
Messages: 93
Registered: May 2014
Member
Hi Ed,

Thanks for your prompt reply.

Indeed, this feature in GenModel exists and in our case, it is very useful.

We tried your approach but it does not seem to work for the "set" case. It only recognizes the key "get".

Find attached the screenshot (set-example.png) of the minimal example that we are testing. What are we missing?

Thanks for your help.

Kind regards,
Antonio
Re: Set-accessor Body? [message #1850605 is a reply to message #1850597] Wed, 09 March 2022 17:49 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The relevant line in Class.javaJet looks to be
<%=setAccessorOperation.getBody(genModel.getIndentation(stringBuffer))%>
so you probably should use "body" rather than "set".

Regards

Ed Willink

[Updated on: Wed, 09 March 2022 19:35]

Report message to a moderator

Re: Set-accessor Body? [message #1850608 is a reply to message #1850605] Wed, 09 March 2022 20:12 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Note that originally I'm seeing advice for annotations for a feature but now I'm seeing advice for annotations for an operation. For features only org.eclipse.emf.codegen.ecore.genmodel.GenFeature.getGetterBody(String) is supported so yes, you'd need to use an operation if you want to override set's behavior.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Set-accessor Body? [message #1850617 is a reply to message #1850608] Thu, 10 March 2022 10:40 Go to previous message
Antonio Garmendia is currently offline Antonio GarmendiaFriend
Messages: 93
Registered: May 2014
Member
Hi,

Thank you both for your answers.

Indeed, I will implement the set EOperation and in the derived feature, the Changeable property must equal to false.

Kind regards,
Antonio
Previous Topic:Optimizing AuditListTableMappingWithRages.moveUp/Down
Next Topic:Generating updated feature description
Goto Forum:
  


Current Time: Sat Apr 27 02:55:22 GMT 2024

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

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

Back to the top