[XPAND] Convert real to integer [message #836192] |
Wed, 04 April 2012 07:27  |
Eclipse User |
|
|
|
Hi,
I do some researsch in the forum but i don't find an answer to my problem. I'm sure my problem can be solve quickly...
I'm working in a xpand model. I make a calculation with some arguments, and in last i found a REAL number (ex : 79,99456). I would like to convert this real number in an integer, to obtain for example the number 79.
I try to convert my real to string, and convert it in integer but it still dont work.
Example of my program :
«(EcuConfiguration.microPerCycle.first()/2778.0)»,
Result :
71.99424046076314,
Thank you in advance,
Best regards,
|
|
|
|
Re: [XPAND] Convert real to integer [message #836267 is a reply to message #836202] |
Wed, 04 April 2012 09:48   |
Eclipse User |
|
|
|
Hi,
And thanks for you reply.
How i can call the function "toInteger"? Because when i try to use an expression, i can only use "toString" and the expression toInteger don't appear in the expression list...
|
|
|
|
|
|
Re: [XPAND] Convert real to integer [message #836291 is a reply to message #836284] |
Wed, 04 April 2012 10:11   |
Eclipse User |
|
|
|
For the metamodel, i use an .XSD file. And when i execute the template, it donrt work. It say the following error :
3756 ERROR AbstractExpressionsUsingWorkflowComponent - Error in Component of type org.openarchitectureware.xpand2.Generator:
EvaluationException : Couldn't find operation 'toInteger()' for Real.
template.xpt[5797,59] on line 99 'EcuConfiguration.microPerCycle.first()./(2778.0).toInteger()'
[23,43] on line 1 'EXPAND template::GenerationCode FOR Autosar'
3757 ERROR WorkflowRunner - Workflow interrupted. Reason: EvaluationException : Couldn't find operation 'toInteger()' for Real.
template.xpt[5797,59] on line 99 'EcuConfiguration.microPerCycle.first()./(2778.0).toInteger()'
[23,43] on line 1 'EXPAND template::GenerationCode FOR Autosar'
3757 ERROR WorkflowRunner - ERROR in Component of type org.openarchitectureware.xpand2.Generator
Couldn't find operation 'toInteger()' for Real. [EcuConfiguration.microPerCycle.first()./(2778.0).toInteger()] in workflow: Generator: generating 'template::GenerationCode FOR Autosar' => src-gen
3757 ERROR WorkflowRunner - ERROR in Component of type org.openarchitectureware.xpand2.Generator
Couldn't find operation 'toInteger()' for Real. [EXPRESSION: EcuConfiguration.microPerCycle.first()./(2778.0).toInteger()] in workflow: Generator: generating 'template::GenerationCode FOR Autosar' => src-gen
3757 ERROR WorkflowRunner - ERROR in Component of type org.openarchitectureware.xpand2.Generator
Couldn't find operation 'toInteger()' for Real. [org.openarchitectureware.xpand2.ast.LetStatement@8b2cc] in workflow: Generator: generating 'template::GenerationCode FOR Autosar' => src-gen
3757 ERROR WorkflowRunner - ERROR in Component of type org.openarchitectureware.xpand2.Generator
Couldn't find operation 'toInteger()' for Real. [org.openarchitectureware.xpand2.ast.LetStatement@1128ee5] in workflow: Generator: generating 'template::GenerationCode FOR Autosar' => src-gen
3757 ERROR WorkflowRunner - ERROR in Component of type org.openarchitectureware.xpand2.Generator
Couldn't find operation 'toInteger()' for Real. [org.openarchitectureware.xpand2.ast.LetStatement@1637381] in workflow: Generator: generating 'template::GenerationCode FOR Autosar' => src-gen
3757 ERROR WorkflowRunner - ERROR in Component of type org.openarchitectureware.xpand2.Generator
Couldn't find operation 'toInteger()' for Real. [org.openarchitectureware.xpand2.ast.FileStatement@342939] in workflow: Generator: generating 'template::GenerationCode FOR Autosar' => src-gen
3757 ERROR WorkflowRunner - ERROR in Component of type org.openarchitectureware.xpand2.Generator
Couldn't find operation 'toInteger()' for Real. [GenerationCode : Autosar] in workflow: Generator: generating 'template::GenerationCode FOR Autosar' => src-gen
3757 ERROR WorkflowRunner - ERROR in Component of type org.openarchitectureware.xpand2.Generator
Couldn't find operation 'toInteger()' for Real. [EXPAND template::GenerationCode FOR Autosar] in workflow: Generator: generating 'template::GenerationCode FOR Autosar' => src-gen
|
|
|
Re: [XPAND] Convert real to integer [message #836300 is a reply to message #836291] |
Wed, 04 April 2012 10:21   |
Eclipse User |
|
|
|
Hi,
hmmm seems => Real != Real. The Buildin Real type has a toInteger operation. i have no idea what your real type is since i do not know your xsd.
=> you have to write an (Java) Extension for the Conversion yourself
~Christian
|
|
|
|
|
Re: [XPAND] Convert real to integer [message #836333 is a reply to message #836323] |
Wed, 04 April 2012 11:04   |
Eclipse User |
|
|
|
of course you could use the things xpand/xtend offer an create an .ext file with an (java) extension that calls some java code
that does the conversion
e.g.
MyExtensions.ext
Integer toIntegerForGuysWhoUse5YearOldoAW(Real r) :
JAVA metamodel.MyExtensions.toIntegerForGuysWhoUse5YearOldoAW(java.lang.Double);
public class MyExtensions {
public static Integer toIntegerForGuysWhoUse5YearOldoAW(Double d) {
if (d == null) return null;
return (int)d.doubleValue();
}
}
«EXTENSION metamodel::MyExtensions»
...
«(1.0/2.0).toIntegerForGuysWhoUse5YearOldoAW()»
|
|
|
Re: [XPAND] Convert real to integer [message #836375 is a reply to message #836333] |
Wed, 04 April 2012 12:11   |
Eclipse User |
|
|
|
Hi,
And thanks for your explanation. I have no idea that we could do something like that. Actually, i'm beginin with XPAND et i work only with xpt langage.
I have any knowledge in java langage, could you please explain this parts in details :
Integer toIntegerForGuysWhoUse5YearOldoAW(Real r) :
JAVA metamodel.MyExtensions.toIntegerForGuysWhoUse5YearOldoAW(java.lang.Double);
I would like to understand the way to use java extension, if i had to create something else for my program.
And, i try to use your program, it have an error when i using it :
"missmatched input 'MyExtension' expecting '(' "
For using your program, i create an "MyExtensionq.ext" file and copy your code like this :
Integer toIntegerForGuysWhoUse5YearOldoAW(Real r) :
JAVA metamodel.MyExtensions.toIntegerForGuysWhoUse5YearOldoAW(java.lang.Double);
public class MyExtensions {
public static Integer toIntegerForGuysWhoUse5YearOldoAW(Double d) {
if (d == null) return null;
return (int)d.doubleValue();
}
}
|
|
|
|
Re: [XPAND] Convert real to integer [message #836510 is a reply to message #836381] |
Wed, 04 April 2012 15:20   |
Eclipse User |
|
|
|
I know this document and i work too with the Xtend User Guide. But really, i'm a little lost because i have to switch between XPAND/XTEND/JAVA... Today, I have some difficulties to assimilate everything...
About your reply
Quote:maybe toInteger is missing in your stoneage version of Xpand/Xtend
I have the last version of Eclipse OAW :
Eclipse platform version: 3.4.2
openArchitectureWare Version: 4.3.1
I think the expression toInteger has to be included, no?
|
|
|
|
Re: [XPAND] Convert real to integer [message #837225 is a reply to message #836519] |
Thu, 05 April 2012 12:15   |
Eclipse User |
|
|
|
Hi,
The function toInteger is not available now in my new version of Eclipse GALILEO. I do some researsch in forums. Must I include a library to have access to particular expression like this one : for example :
extension org::eclipse::xtend::util::stdlib::io
?
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07932 seconds