Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to implement generalization in XText ?
How to implement generalization in XText ? [message #1722454] Thu, 04 February 2016 22:51 Go to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 210
Registered: February 2014
Senior Member
Hi,

Given the meta model attached below, which way of implementation is correct for the Message class.

1)
Concept:
message=Message |
attribuConc= AttributedConcept
...

OR:

2)
Concept:
name or whatever attribute

Message returns Concept:

...

So, the difference is using "return" keyword which is used for subtyping or using message inside concept. Using (1), the generated Java code creates a class concept which HAS message attribute. but using return statement (2) generate a class Message that extends Concept.

Thanks.
Parsa
index.php/fa/24902/0/
Re: How to implement generalization in XText ? [message #1722460 is a reply to message #1722454] Fri, 05 February 2016 04:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14081
Registered: July 2009
Senior Member
Concept: Message | AttributedConcept;

Message: ...;

AttributedConcept: ....;


or

Message returns Concept:
{Message} .....


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 implement generalization in XText ? [message #1722576 is a reply to message #1722460] Sat, 06 February 2016 02:04 Go to previous messageGo to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 210
Registered: February 2014
Senior Member
Thanks a lot Christian for your quick reply and help.

Do you know if we have an attribute (let's say name) in Concept, and Message also inherits this "name" attribute form Concept, then from what I can see we need to declare name in the Message and not in Concept. Because concept here is just a transient element, right ? I tried having name for both Concept and for Message. In the generated ecore file it adds name attribute for both elements. However, since it is a inheritance, only Concept should have it and inherited Message can have name attribute by inheritance... What do you suggest ?

I want to end yup with generating an ecore file like below:

Concept
-name: EString

Message->Concept
-a1
-a2


So, Message still has name attribute by the definition of inheritance. Not sure, how to do in XText.

Thanks,
Bests,
Parsa
Re: How to implement generalization in XText ? [message #1722588 is a reply to message #1722576] Sat, 06 February 2016 09:27 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14081
Registered: July 2009
Senior Member
Hi have a look in the docs. It describes how ecore is inferred. At a
certain point switching to a handwritten meta model might be better

Having the name at the parent level makes only sense if you have 2 child's.

If you have

Parent:A|B

And

A:name=ID

And

B:name=ID

Then

Parent will get the name from the inferrer


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
Previous Topic:importing from java in custom expressions
Next Topic:New symbols for literals
Goto Forum:
  


Current Time: Wed Oct 27 07:37:13 GMT 2021

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

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

Back to the top