Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to customize generated eclass from a grammar?
How to customize generated eclass from a grammar? [message #1856330] Sun, 04 December 2022 09:05 Go to next message
jo ber is currently offline jo berFriend
Messages: 88
Registered: August 2018
Member
Hello

I would like to customize the classes generated from an xtext grammar with my own methods. I don't know how to do that technically.
I thought:
- create my own ecore model with my customized methods,
- when the classes from the xtext grammar are generated, my customized methods should be picked and included by inheritance (but how, and how to tell what should be inherited for which class?)

Or should it be the other way around (i.e. customizing by inheriting from the generated classes) but in this case, the grammar infrastructure would continue to use the original generated classes and not the customized ones (how to solve this)

Any hints appreciated. Kind regards
Re: How to customize generated eclass from a grammar? [message #1856331 is a reply to message #1856330] Sun, 04 December 2022 09:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14434
Registered: July 2009
Senior Member
Hi, can you please be more specific about your EXACT usecase.

the ususal way is to switch to a manually maintained metamodel at some point. but without exact problem description it is hard to tell.


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to customize generated eclass from a grammar? [message #1856332 is a reply to message #1856331] Sun, 04 December 2022 14:03 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7564
Registered: July 2009
Senior Member
Hi

If you use a manual rather than auto-generated Ecore metamodel you are in full control and have more flexibility. (Personally I strongly recommend manual.)

However migrating from auto-generated to manual is slightly awkward; I think that the menu action wizard remains an enhancement.

You should study the differing layouts of manual and auto-generated before migrating. If you cannot find any examples of manual, then use the Xtext or OCL grammars.

Regards

Ed Willink
Re: How to customize generated eclass from a grammar? [message #1856342 is a reply to message #1856332] Mon, 05 December 2022 08:11 Go to previous messageGo to next message
Rubén Porras Campo is currently offline Rubén Porras CampoFriend
Messages: 64
Registered: July 2009
Member
Hi,

I think that if you only need to extend a bunch of classes, the best you can do is to follow the pattern of ImplCustom classes, that is, you still use the auto-generated Ecore metamodel and for the classes you would like to extend, you create a ImplCustom (e.g. AImplCustom extens AImpl) class with the additional methods. The generator should pick them up

Regrads
Re: How to customize generated eclass from a grammar? [message #1856352 is a reply to message #1856342] Mon, 05 December 2022 20:27 Go to previous message
jo ber is currently offline jo berFriend
Messages: 88
Registered: August 2018
Member
Thank you for your answers.
I think there is tradeoff in all scenarios. I believe for my use case, it is kind of acceptable to switch from a generated ecore to a manually maintained one when the dsl is stable. In case something must be changed in dsl the amount of manual work to migrate the methods could be ok.

kind regards,
Previous Topic:Error creating PDA for syntactic sequencer (2.29.0)
Next Topic:Dependency injection of ResourceDescriptionsProvider failed
Goto Forum:
  


Current Time: Sat Feb 04 15:58:29 GMT 2023

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

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

Back to the top