Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Extending the generated model
Extending the generated model [message #673714] Tue, 24 May 2011 10:27 Go to next message
Eclipse UserFriend
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 14:35 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Extending the generated model [message #673849 is a reply to message #673714] Tue, 24 May 2011 19:25 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Extending the generated model [message #673850 is a reply to message #673714] Tue, 24 May 2011 19:29 Go to previous messageGo to next message
Eclipse UserFriend
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 05:29 Go to previous message
Eclipse UserFriend
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: Tue Jul 08 19:45:23 EDT 2025

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

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

Back to the top