Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Extending the generated model
Extending the generated model [message #673714] Tue, 24 May 2011 14:27 Go to next message
Vlad Dumitrescu is currently offline Vlad DumitrescuFriend
Messages: 431
Registered: July 2009
Location: Gothenburg
Senior Member
Hi,

I don't find anything concrete about this question, please someone point me out in the right direction.

How can I extend the model generated from the grammar, for example to add more operations to classes?

One example is that at the top level I have different kinds of Forms, in no particular order. I want to be able to say model.getFormsOfKind(kind) and get a filtered list. This is more readable than Util.filterFormsByKind(model.getForms(), kind) or similar approaches.

Thanks in advance!
best regards,
Vlad
Re: Extending the generated model [message #673790 is a reply to message #673714] Tue, 24 May 2011 18:35 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

you can of course use an imported meta model rather than generate one. Within that meta model, you are free to do what you want. Keeping grammar and meta model in sync is some effort, of course (during language evolution).
It is also possible to do meta model post processing (briefly covered in the documentation and the Xtext FAQ). This might be another option.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Extending the generated model [message #673849 is a reply to message #673714] Tue, 24 May 2011 23:25 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
If you want EOperations in your model, I'd recommend to switch from a
generated metamodel to an imported one (see docs).

Jan

Am 24.05.11 16:27, schrieb Vlad Dumitrescu:
> Hi,
>
> I don't find anything concrete about this question, please someone point
> me out in the right direction.
>
> How can I extend the model generated from the grammar, for example to
> add more operations to classes?
> One example is that at the top level I have different kinds of Forms, in
> no particular order. I want to be able to say model.getFormsOfKind(kind)
> and get a filtered list. This is more readable than
> Util.filterFormsByKind(model.getForms(), kind) or similar approaches.
>
> Thanks in advance!
> best regards,
> Vlad
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: Extending the generated model [message #673850 is a reply to message #673714] Tue, 24 May 2011 23:29 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
You solve this by not generating the model and instead use an external
model. You can start by making a copy of the generated model to a
separate project as a starting point.

I can however recommend to keep the model anemic and do as much
processing as possible outside of the actual model. It is simply much
easier to adapt, maintain and test. I started adding quite a few methods
to the semantic objects in my first xtext project and had to refactor
them (that was painful).

By use of guice injection and good naming it is easy to make the code
readable (as well as testable/maintainable) - say something like:

@Inject
FormsByKindFilter formsByKindFilter;
formsByKindFilter.filter(model, kind)

Then combine that with polymorphic dispatching and google collections
(iterators, filters and functions).

Just my 2c.
Regards
- henrik



On 5/24/11 4:27 PM, Vlad Dumitrescu wrote:
> Hi,
>
> I don't find anything concrete about this question, please someone point
> me out in the right direction.
>
> How can I extend the model generated from the grammar, for example to
> add more operations to classes?
> One example is that at the top level I have different kinds of Forms, in
> no particular order. I want to be able to say model.getFormsOfKind(kind)
> and get a filtered list. This is more readable than
> Util.filterFormsByKind(model.getForms(), kind) or similar approaches.
>
> Thanks in advance!
> best regards,
> Vlad
>
Re: Extending the generated model [message #674534 is a reply to message #673850] Fri, 27 May 2011 09:29 Go to previous message
Vlad Dumitrescu is currently offline Vlad DumitrescuFriend
Messages: 431
Registered: July 2009
Location: Gothenburg
Senior Member
Thanks to everyone for the suggestions. The advantage of using the xtext grammar is that I don't have to dig too deep into the ecore modeling stuff, but if I must to, then I must! Smile

regards,
Vlad
Previous Topic:Grammar documentation
Next Topic:Using first rule for code generation
Goto Forum:
  


Current Time: Fri Apr 26 19:36:19 GMT 2024

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

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

Back to the top