[Xpand] Access to root element from within DEFINE block [SOLVED] [message #551629] |
Sun, 08 August 2010 13:51 |
jemurphy Messages: 4 Registered: August 2010 |
Junior Member |
|
|
I wish to access the root element of the underlying model from within a DEFINE block that has been defined for the meta-class of a sub-element of the model. Can the root element be referenced directly, by global variable or passed to the DEFINE block with the sub-element? I am expanding the DEFINE block recursively in a manner that does not allow for simply passing the root element alone. If this is possible, could a simple example be provided.
[Updated on: Fri, 13 August 2010 03:44] Report message to a moderator
|
|
|
Re: [Xpand] Access to root element from within DEFINE block [message #551630 is a reply to message #551629] |
Sun, 08 August 2010 13:58 |
|
Hello,
depending on the metamodel you are using (e.g. for emf based ones) you can ask each model element for it's root in the model (eRootContainer )but this may not be what you want if the root is just a semantic one but not the physical root.
But of course you can add parameters to a definition and thereby pass the root.
Here a adapted sample created with the new xpand project wizard
«DEFINE main FOR Model»
«EXPAND javaClass(this) FOREACH entities()»
«ENDDEFINE»
«DEFINE javaClass(Model m) FOR Entity»
«FILE name+".java"»
public class «name» {
«FOREACH features AS f»
private «f.type.name» «f.name»;
public void «f.setter()»(«f.type.name» «f.name») {
this.«f.name» = «f.name»;
}
public «f.type.name» «f.getter()»() {
return «f.name»;
}
«ENDFOREACH»
}
«ENDFILE»
«ENDDEFINE»
i don't see there is a usecase where this should not work.
and you can use globalvar as described in the docs. (std lib doc - part Globalvar extensions)
Regards
Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Sun, 08 August 2010 14:28] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06036 seconds