Skip to main content



      Home
Home » Modeling » M2T (model-to-text transformation) » [XPAND] Casting possibilities
[XPAND] Casting possibilities [message #776520] Sun, 08 January 2012 12:08 Go to next message
Eclipse UserFriend
hi, i´m trying to transform some ecore model to java code.
my current problem are method parameters as i have to decide wether they are simple or complex.

«DEFINE methodBuilder FOR myModel::Method»
public void «name»(«FOREACH parameters AS param SEPARATOR ','» «HERE THE TYPE»
«param.name»
«ENDFOREACH»)

«HERE THE TYPE» is the part where i´m experiencing problems.
as far as i found out i can use the typeSelect only on the parameters List, but then i have as param only simple OR complex left.
if i make one FOREACH for simple and one for complex i´m missing commas:

«DEFINE methodBuilder FOR myModel::Method»
public void «name»((
«FOREACH parameters.typeSelect(myModel::SimpleParameter) AS param SEPARATOR ','» «HERE THE TYPE»
«FOREACH parameters.typeSelect(myModel::ComplexParameter) AS param SEPARATOR ','» «HERE THE TYPE»
«param.name»
«ENDFOREACH»)

Could anyone give me a hint how to do this?

thx Asa
Re: [XPAND] Casting possibilities [message #776528 is a reply to message #776520] Sun, 08 January 2012 12:27 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

(from the docs)

Casting
The expression language is statically type checked. Although there are many concepts that help the programmer to have really good static type information, sometimes. One knows more about the real type than the system. To explicitly give the system such an information casts are available. Casts are 100% static, so you do not need them, if you never statically typecheck your expressions!

The syntax for casts is very Java-like:

((String)unTypedList.get(0)).toUpperCase()


// results to true, if the result of someExpression is of type MyType or its subtypes
MyType.isInstance(someExpression)

// results to true, if the result of someExpression is exactly of type MyType
someExpression.metaType == MyType


~Christian
Re: [XPAND] Casting possibilities [message #776581 is a reply to message #776528] Sun, 08 January 2012 15:55 Go to previous messageGo to next message
Eclipse UserFriend
thx for answering.
i forgot to add that i tried this but it´s always marked as wrong code.
could somebody provide me another example so maybe i could figure out my mistake?
Re: [XPAND] Casting possibilities [message #776586 is a reply to message #776581] Sun, 08 January 2012 16:12 Go to previous messageGo to next message
Eclipse UserFriend
hi,

can you post your sample code. you did never mention what you wanted to do when
talking about «HERE THE TYPE»
Re: [XPAND] Casting possibilities [message #776588 is a reply to message #776586] Sun, 08 January 2012 16:13 Go to previous messageGo to next message
Eclipse UserFriend
and what is the error message you get?
Re: [XPAND] Casting possibilities [message #776805 is a reply to message #776588] Mon, 09 January 2012 04:51 Go to previous message
Eclipse UserFriend
thank you for yout answers.
when trying to reproduce my error i found a way to make it work. iwas irritated because the autocompletion did not work and it seems that when i tried to manually code it i made a typing mistake, because the autocompletion still does not work but when expanding the type at another position and copying it to the cast position it works now:

public void «name»(«FOREACH parameters AS param SEPARATOR ','-»«IF param.type=="myModel::Simple"»«((myModel::Simple)param).type» «ELSEIF param.type=="myModel::Complex"»«((myModel::Complex)param).classType.name»«ENDIF» «param.name»«ENDFOREACH-») {
Previous Topic:[Acceleo] *.emtl files missing when building updatesite
Next Topic:[acceleo] binary/XMI format & java application
Goto Forum:
  


Current Time: Wed Jul 09 08:34:45 EDT 2025

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

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

Back to the top