Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Upcasting and Downcasting in XPand?(Check if element of model is of some subtype in xpand template?)
Upcasting and Downcasting in XPand? [message #645789] Mon, 20 December 2010 15:28 Go to next message
Stefan Mijatov is currently offline Stefan MijatovFriend
Messages: 59
Registered: March 2010
Location: Vienna, Austria
Member
I have the following code in my xpand template file:

«IMPORT ejb3»
«IMPORT java»
«DEFINE packageTemplate FOR JavaPackage»
«FOREACH eClassifiers AS c»
«EXPAND entityTemplate FOR c»
«ENDFOREACH»
«ENDDEFINE»
«DEFINE entityTemplate FOR EntityBean»
«FILE name + ".java" »
import java.io.Serializable;
//@Entity
class «name» implements Serializable{
	
	private static final long serialVersionUID = 1L;
	«FOREACH fields AS f»
	«f.javaVisibility.toString().toLowerCase()» «IF f.eType.name != null»«f.eType.name»«ELSE»String«ENDIF» «f.name»;
	«ENDFOREACH»
	«FOREACH fields AS f»
	public void set«((String)f.name).toFirstUpper()»(«IF f.eType.name != null»«f.eType.name»«ELSE»String«ENDIF» value){
		this.«f.name» = value;
	}
	public «IF f.eType.name != null»«f.eType.name»«ELSE»String«ENDIF» get«((String)f.name).toFirstUpper()»(){
		return this.«f.name»;
	}
	«ENDFOREACH»
}
«ENDFILE»
«ENDDEFINE»


Is it possible to somehow check for the subtype of element f in foreach loop, as I would do in QVT like this:

f.oclIsTypeOf(ManyToOne);


Please help Sad
Re: Upcasting and Downcasting in XPand? [message #645817 is a reply to message #645789] Mon, 20 December 2010 16:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hello Stefan,

on a list you can use
mylist.typeSelect(MyType)


a normal properties you can use
MyTypel.isInstance(myprop)


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Upcasting and Downcasting in XPand? [message #645821 is a reply to message #645817] Mon, 20 December 2010 17:01 Go to previous message
Stefan Mijatov is currently offline Stefan MijatovFriend
Messages: 59
Registered: March 2010
Location: Vienna, Austria
Member
I did it, and it works. Thanks!
Previous Topic:[Xpand] : runing workflows with ant or Maven
Next Topic:Code autocompletion in xpt files
Goto Forum:
  


Current Time: Sat Apr 20 00:52:26 GMT 2024

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

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

Back to the top