Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [XPAND] Convert real to integer
[XPAND] Convert real to integer [message #836192] Wed, 04 April 2012 07:27 Go to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
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 #836202 is a reply to message #836192] Wed, 04 April 2012 07:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
Hi,

what about calling toInteger in the value?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: [XPAND] Convert real to integer [message #836267 is a reply to message #836202] Wed, 04 April 2012 09:48 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
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 #836274 is a reply to message #836267] Wed, 04 April 2012 09:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
Hi,

i do not understand your question. if you have a real in your hand you can call toInteger on it e.g.

<<(10.4/3.1).toInteger()>>

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: [XPAND] Convert real to integer [message #836283 is a reply to message #836274] Wed, 04 April 2012 10:06 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
When i try to use this expression, there is an error.
Can you look at the image following, that I had include.
Re: [XPAND] Convert real to integer [message #836284 is a reply to message #836283] Wed, 04 April 2012 10:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
Hmmmm which metamodel do you use? maybe it is simply a bug in the editor. does it work if you execute the template?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: [XPAND] Convert real to integer [message #836291 is a reply to message #836284] Wed, 04 April 2012 10:11 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
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 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: [XPAND] Convert real to integer [message #836308 is a reply to message #836300] Wed, 04 April 2012 10:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
p.s: maybe toInteger is missing in your stoneage version of Xpand/Xtend

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: [XPAND] Convert real to integer [message #836323 is a reply to message #836308] Wed, 04 April 2012 10:55 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
Could I add an file extension which include this expression?
Re: [XPAND] Convert real to integer [message #836333 is a reply to message #836323] Wed, 04 April 2012 11:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
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()»


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: [XPAND] Convert real to integer [message #836375 is a reply to message #836333] Wed, 04 April 2012 12:11 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
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 #836381 is a reply to message #836375] Wed, 04 April 2012 12:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
Hi,

the classical answer to this question is RTFM.
http://www.openarchitectureware.org/pub/documentation/4.3.1/html/contents/core_reference.html#Xtend_language

of course the Java Class goes to a java file Wink

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: [XPAND] Convert real to integer [message #836510 is a reply to message #836381] Wed, 04 April 2012 15:20 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
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 #836519 is a reply to message #836510] Wed, 04 April 2012 15:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
Hi Xpand has moved to eclipse M2T see www.openarchitectureware.org

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: [XPAND] Convert real to integer [message #837225 is a reply to message #836519] Thu, 05 April 2012 12:15 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
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

?
Re: [XPAND] Convert real to integer [message #837230 is a reply to message #837225] Thu, 05 April 2012 12:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
same as before: you have to write the libary YOURSELF or update to the newest Version of Xpand at Eclipse

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: [XPAND] Convert real to integer [message #837242 is a reply to message #837230] Thu, 05 April 2012 12:39 Go to previous message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
Hi,

It works Smile. Thank you so much Christian Dietrich for your explanation and your help.
Previous Topic:Migration OAW4 to OAW5
Next Topic:[QVTo] get the path of the in model
Goto Forum:
  


Current Time: Mon Dec 09 01:29:25 GMT 2024

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

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

Back to the top