Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » XPand et inheritance
XPand et inheritance [message #537063] Tue, 01 June 2010 08:43 Go to next message
jeremie is currently offline jeremieFriend
Messages: 233
Registered: April 2010
Senior Member
Hi,

I have a problem to treat inheritance with XPand,
For example, I have this model :

class A {
   private B : elementB;
}

interface B{}

classe C implements B {}

classe D implements B {}

classe E implements B {}


I will like to do specific treatment for each classes C D and E,

T XPand fille look like this :

«IMPORT model»;


«DEFINE a FOR A»
«EXPAND ... FOR this.elementB»
«ENDDEFINE»



I don't know what I have to write in the EXPAND line because this.elementB can be of type C, D or E..
we can imagine I have a file TreatC.xpt, TreatD.xpt or TreatE.xpt, to make a specific treatment for each type of element.

Thanks.

Jérémie
Re: XPand et inheritance [message #537081 is a reply to message #537063] Tue, 01 June 2010 09:23 Go to previous messageGo to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
Messages: 108
Registered: February 2010
Location: France
Senior Member
Are classe C, classe D, classe E different types from your metamodel ?

If yes, Xpand supports polymorphism, so you just have to define 3 different templates, one for classe C type, one for classe D type, and one for classe E type.


One day I shall master M2T, but that day has yet to come...
Re: XPand et inheritance [message #537086 is a reply to message #537081] Tue, 01 June 2010 09:39 Go to previous messageGo to next message
jeremie is currently offline jeremieFriend
Messages: 233
Registered: April 2010
Senior Member
yes they are different type in my metamodel.
I have make a template for each one,
the problem is that I don"t know how to call this template in the file treatA.xpt.
if there is something equivalent to "instanceof" in XPand it could resole my problem.
I could do something like that :
....
«DEFINE a FOR A»
«IF this.elementB instanceof C»
	«EXPAND TreatC::c FOR this.elementB»
«ENDIF»
«IF this.elementB instanceof D»
	«EXPAND TreatD::d FOR this.elementB»
«ENDIF»
«IF this.elementB instanceof E»
	«EXPAND TreatE::e FOR this.elementB»
«ENDIF»
«ENDDEFINE»


Re: XPand et inheritance [message #537095 is a reply to message #537086] Tue, 01 June 2010 10:18 Go to previous messageGo to next message
jeremie is currently offline jeremieFriend
Messages: 233
Registered: April 2010
Senior Member
Is there in XPand something equivalent to "instanceof"? or an other way to do something like that?

thanks,

Jérémie
Re: XPand et inheritance [message #537100 is a reply to message #537063] Tue, 01 June 2010 10:45 Go to previous messageGo to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
Messages: 108
Registered: February 2010
Location: France
Senior Member
You don't need any "instanceof"

You can just do it that way :


RInteger, RBool, RFloat and RString have RDatatype for ESuper type.
Quote:
«EXPAND tosql FOR RDatatype»

«DEFINE tosql FOR RInteger»INTEGER«ENDDEFINE»
«DEFINE tosql FOR RBool»BOOLEAN«ENDDEFINE»
«DEFINE tosql FOR RFloat»DOUBLE«ENDDEFINE»
«DEFINE tosql FOR RString»VARCHAR(40)«ENDDEFINE»



One day I shall master M2T, but that day has yet to come...
Re: XPand et inheritance [message #537114 is a reply to message #537100] Tue, 01 June 2010 11:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
or you can write C.isInstance(this)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XPand et inheritance [message #537137 is a reply to message #537100] Tue, 01 June 2010 12:45 Go to previous message
jeremie is currently offline jeremieFriend
Messages: 233
Registered: April 2010
Senior Member
Thanks.

It works fine Smile

Jérémie
Previous Topic:[Announce] M2T XPAND 1.0.0RC3 is available
Next Topic:[Xtend] modifying a model
Goto Forum:
  


Current Time: Sat Apr 20 04:19:00 GMT 2024

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

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

Back to the top