Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Xtend java extensions with primitive type parameters
Xtend java extensions with primitive type parameters [message #545539] Thu, 08 July 2010 08:29 Go to next message
Matei Istoan is currently offline Matei IstoanFriend
Messages: 3
Registered: July 2010
Junior Member
As the title suggests, I would like to know if there is any way that I could have a java extension in Xtend that maps to a function which has an int parameter.
I've searched quite a lot on this topic and I can't seem to find anything useful on whether or not I can have a primitive type as parameter, and, if not, how to get around this problem. The documentation isn't of much help either.
Any help is welcomed, thanks.
Re: Xtend java extensions with primitive type parameters [message #545552 is a reply to message #545539] Thu, 08 July 2010 08:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hello,

no this is not possible directly. but you can solve this by using the famous adapter pattern:

guess you have a class like this

package template;

public class Helper {
	
	public static String test(int i) {
		return i + ">>";
	}

}


and want to pass an xpand/xtend Integer (which is a java.lang.Long actually)
to it you build an adaper class

package template;

public class Adapter {
	
	public static String test(Long l) {
		return Helper.test((int) l.longValue());
	}

}


and use it from your java extension

String test(Integer i) :
	JAVA template.Adapter.test(java.lang.Long);


note: the ranges of long and int differ and my Adaper impl cannot handle this. to be sure not to get unexpected behaviour you should change this.

Regards
Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtend java extensions with primitive type parameters [message #545556 is a reply to message #545552] Thu, 08 July 2010 09:00 Go to previous messageGo to next message
Matei Istoan is currently offline Matei IstoanFriend
Messages: 3
Registered: July 2010
Junior Member
Thank you for the reply and the solution.

After all the searching and looking on the internet for answers to this problem, this is what I also ended up doing. I was really hoping that there was a more elegant method for doing this, but well..

And just as a side note question, how come the primitive types haven't been interfaced from Xtend in some way? Would this pose to many problems, or am I among the few who ran into this problem? Plus, the documentation on extensions could mention more on the topic of java extensions.

Anyway, thank you again for the help and the really speedy reply.
Re: Xtend java extensions with primitive type parameters [message #545562 is a reply to message #545556] Thu, 08 July 2010 09:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

the most elegant way might be not to use java at all.

the missing support may have historic reasons and may be motivated cause one didn't want to blow up xpand just because javas typesystem is lousy regarding primitive types.

(see http://www.openarchitectureware.org/forum/viewtopic.php?foru m=2&showtopic=10798 for a similar discussion)

feel free to file an enhancement request for the primitive type support and a bug for the lack of documentation into the xpand bugzilla.

Regards Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 08 July 2010 09:12]

Report message to a moderator

Re: Xtend java extensions with primitive type parameters [message #545805 is a reply to message #545562] Fri, 09 July 2010 08:35 Go to previous message
Matei Istoan is currently offline Matei IstoanFriend
Messages: 3
Registered: July 2010
Junior Member
I totally agree about not wanting to make XPand bloated, but I don't think that masking this detail would cause too much problems.

Even when trying not to use Java at all, you have to agree that XPand and Xtend have some serious limitations which cannot be accounted for in any other way( I mean no offense).

I will file the bug report, maybe this way you won't have to carry this conversation with other users in the future.

Best regards,
Matei Istoan.
Previous Topic:[acceleo] Utilisation d 'enum
Next Topic:Problem with transformation UML to text with Atl query
Goto Forum:
  


Current Time: Sat Apr 13 03:35:55 GMT 2024

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

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

Back to the top