Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [XPAND] Casting possibilities
[XPAND] Casting possibilities [message #776520] Sun, 08 January 2012 17:08 Go to next message
Verena Himmelbauer is currently offline Verena HimmelbauerFriend
Messages: 3
Registered: January 2012
Junior Member
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 17:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [XPAND] Casting possibilities [message #776581 is a reply to message #776528] Sun, 08 January 2012 20:55 Go to previous messageGo to next message
Verena Himmelbauer is currently offline Verena HimmelbauerFriend
Messages: 3
Registered: January 2012
Junior Member
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 21:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi,

can you post your sample code. you did never mention what you wanted to do when
talking about «HERE THE TYPE»


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [XPAND] Casting possibilities [message #776588 is a reply to message #776586] Sun, 08 January 2012 21:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
and what is the error message you get?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [XPAND] Casting possibilities [message #776805 is a reply to message #776588] Mon, 09 January 2012 09:51 Go to previous message
Verena Himmelbauer is currently offline Verena HimmelbauerFriend
Messages: 3
Registered: January 2012
Junior Member
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: Fri Apr 19 22:38:09 GMT 2024

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

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

Back to the top