Skip to main content



      Home
Home » Modeling » M2T (model-to-text transformation) » [xtend] Casting to Subclass in Template
[xtend] Casting to Subclass in Template [message #782282] Mon, 23 January 2012 08:05 Go to next message
Eclipse UserFriend
I have a XText Grammar, which shall be used to fill out a template.

In this Grammar i have a type
VI:
	'{' (vus+=VU)+ '}'
;

VU_unit:
			Ref|Prop
;
Ref: 
	'var' variable=ID 
;

Prop:
	'prop' verif=VD
;


I walk through the given "VU"'s, and can react if something is a Ref or a Prop, but i can't seem to find a way to access the parts variable or respectively verif.

with given p
''' 		
«FOR st:p.VI.VU_unit»
«IF st instanceof Ref»			
WHAT TO DO HERE TO WRITE Ref.variable?

«ENDIF»
«ENDFOR»
'''


I cant find a way how to do it.... Please help. Thanks
Re: [xtend] Casting to Subclass in Template [message #782305 is a reply to message #782282] Mon, 23 January 2012 08:49 Go to previous messageGo to next message
Eclipse UserFriend
Hi you can cast with

myvar as My type

But you should consider to solve this with dispatch methods instead
of doing instance of checks and typecasts. Regards Christian
Re: [xtend] Casting to Subclass in Template [message #782314 is a reply to message #782305] Mon, 23 January 2012 09:17 Go to previous messageGo to next message
Eclipse UserFriend
Thanks. That works for me.

But i still wonder why i couldn't find this...
Re: [xtend] Casting to Subclass in Template [message #784474 is a reply to message #782314] Fri, 27 January 2012 10:29 Go to previous message
Eclipse UserFriend
It's explained here :
http://www.eclipse.org/Xtext/xtend/documentation/index.html#typeCasts

Am 1/23/12 3:17 PM, schrieb Sebastian Burg:
> Thanks. That works for me.
> But i still wonder why i couldn't find this...


--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Previous Topic:Only one file for many classes, here my code.
Next Topic:[acceleo] Extending a module and overriding templates
Goto Forum:
  


Current Time: Tue May 13 11:03:50 EDT 2025

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

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

Back to the top