Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 13:05 Go to next message
Sebastian Burg is currently offline Sebastian BurgFriend
Messages: 9
Registered: November 2011
Junior Member
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 13:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6499
Registered: July 2009
Senior Member
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 14:17 Go to previous messageGo to next message
Sebastian Burg is currently offline Sebastian BurgFriend
Messages: 9
Registered: November 2011
Junior Member
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 15:29 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1771
Registered: July 2009
Senior Member
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


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : 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: Fri Nov 28 15:11:30 GMT 2014

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

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