Skip to main content



      Home
Home » Modeling » M2T (model-to-text transformation) » XPand et inheritance
XPand et inheritance [message #537063] Tue, 01 June 2010 04:43 Go to next message
Eclipse UserFriend
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 05:23 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: XPand et inheritance [message #537086 is a reply to message #537081] Tue, 01 June 2010 05:39 Go to previous messageGo to next message
Eclipse UserFriend
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 06:18 Go to previous messageGo to next message
Eclipse UserFriend
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 06:45 Go to previous messageGo to next message
Eclipse UserFriend
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»

Re: XPand et inheritance [message #537114 is a reply to message #537100] Tue, 01 June 2010 07:32 Go to previous messageGo to next message
Eclipse UserFriend
or you can write C.isInstance(this)
Re: XPand et inheritance [message #537137 is a reply to message #537100] Tue, 01 June 2010 08:45 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 08:18:44 EDT 2025

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

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

Back to the top