Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » proper way to enrich model
proper way to enrich model [message #1385797] Wed, 11 June 2014 09:29 Go to next message
Yoel Pinhas is currently offline Yoel PinhasFriend
Messages: 17
Registered: October 2013
Junior Member
Hi,

I have a grammar that accepts something that looks like this:

entity A {
 int i = 1
 int j
}

entity B extends A {
 int j = 2
}

entity C extends B {
 int k = 3
}



When I generate code from 'entity C' it actually have 3 fields: i, j and k, and, the values are: 1, 2, 3 correspondingly.

However, the emf model only contain k

What is the 'proper' way of handling this?
- sure, it's easy to evaluate the values - but i want to do this only once

I can think of several solutions:
1) Effect the creation of the emf model somehow (how?) and manually add the missing i and j to C (and j to B) while xtext is creating the model
2) 'piggyback' the extra fields on the resource/emf model while in doGenerate (am i allowed to do that?)
3) Use cache to cache fields references and values once calculated/deduced
4) Create my own model (bahh!)

Option 4 - is my least favorite.
Option 3 - looks nicer, but I don't think it's elegant
Option 2 - I don't know if I'm allowed to do that at all?
Option 1 - Sounds promising, I think that a good starting point is this: xtextcasts.org/episodes/18-model-optimization

So, what is the 'proper' xtext way to do this? is there a proper way? Smile

Any comment will be warmly accepted Smile
Yoel.

Re: proper way to enrich model [message #1385807 is a reply to message #1385797] Wed, 11 June 2014 10:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13313
Registered: July 2009
Senior Member
Hi,

what about simple traverse the model (ask entity for its parent, the parent for its attributes???)


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: proper way to enrich model [message #1385808 is a reply to message #1385807] Wed, 11 June 2014 10:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13313
Registered: July 2009
Senior Member
P.S: you may create simple extensions (helper functions) in xtend that do all the collection

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: proper way to enrich model [message #1385835 is a reply to message #1385808] Wed, 11 June 2014 14:14 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 248
Registered: June 2013
Senior Member
Hi Yoel,
in the book "Implementing Domain-Specific Languages with Xtext and Xtend" from Lorenzo Bettini
there is a chapter "Scope for inheritance and member visibility" where he gives on page 246 an example:

@Inject extension SmallJavaTypeProvider
def scope_SJMember(SJMemberSelection sel, EReference r) {
var parentScope = IScope::NULLSCOPE
val type = sel.receiver.typeFor
if (type == null || type.isPrimitive)
return parentScope
for (c : type.classHierarchy.reverseView) {
parentScope = Scopes::scopeFor(c.members, parentScope)
}
Scopes::scopeFor(type.members, parentScope)
}

Hope it helps, Uli
Re: proper way to enrich model [message #1385902 is a reply to message #1385835] Thu, 12 June 2014 08:20 Go to previous message
Yoel Pinhas is currently offline Yoel PinhasFriend
Messages: 17
Registered: October 2013
Junior Member
Christian:
Thank you for your reply. Yes, I'm traversing the model using extension methods. this covers some of my problem.

Uli:
Thank you very much, yes! your snippet is helping me with the scoping aspect
I will order Lorenzo's book, it seems like a very good book Smile

Consider the following example (a little more complex)

entity Doll {
 int height
 Cuteness cutenessLevel
 Color eyeColor
 Color hairColor
 Gender gender 
}

Entity BlondDoll extends Doll {
 Color hairColor = Color.BLONDE
}

Entity VeryCuteDoll extends {
 Cuteness cutenessLevel = Cuteness.VERY_CUTE
}

Entity MaleDoll extends Doll {
 Gender gender = Gender.MALE
}

Entity VeryCuteBlondeDoll extends VeryCuteDoll, BlondDoll {
}

Entity DollHouse {
 MaleDoll veryCuteBlondeMaleDoll42 = new VeryCuteBlondeDoll(height=42)
}




When I evaluate 'veryCuteBlondeMaleDoll42' I have to find the assignment for all of its values (height, cutenessLevel, eyeColor, hairColor and gender)
they come from different places, some stem from weird inheritance (blond) some from C'tor (height) and some from the value type (male)
This example sheds some more light on the grammar and the correct phrases in it.

Furthermore, things in real world scenario are a little more complicated than this.

Finding the assignment for each value of Doll is not hard.
But it does take some time and effort. And when I have of large number of values which are referenced from pre-compiled parts I want to use that.

My question is how to 'store' the data once I found it, once I traced its origin?

Can I store data in the EMF? should I?
Perhaps cache is answer?

Thanks again, Yoel

p.s.
Perhaps I'm going on a limb here, but I'm new to Xtext. I presume that there is a standard approach that is best practice in compilation of structures of this sort - I could be all wrong :0)

[Updated on: Thu, 12 June 2014 11:22]

Report message to a moderator

Previous Topic:ScopeProvider with imported Xcore
Next Topic:Need to change the return type of a Terminal
Goto Forum:
  


Current Time: Sun Jan 19 21:00:44 GMT 2020

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

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

Back to the top