Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo]Inverting a String("example.com" into "com.example")
[Acceleo]Inverting a String [message #1232472] Fri, 17 January 2014 02:09 Go to next message
michel souza is currently offline michel souzaFriend
Messages: 18
Registered: December 2013
Junior Member
Hi guys.. I know this is supposed to be a simple action do a kind of reverse but I'm kinda lost.

1- I've tried to find a method that would do that directly to me... but I haven't found

2- I thought to break a string in a token and access from the last to the first element. I don't know how in Acceleo.

In fact, I found out that Sequence and OrderedSet have a method called reverse() that would help me. But I try to break the string in tokens using mystring.tokenize('.'). This method was supposed to return a Sequence.... but this doesn't happen.. it returns instead a Bag... ok.. I tried to mybag->asSequence()->reverse().. but turning a bag into a sequence is messing with the order.

So if you have any idea.. I would really appreciate.

I want to turn "http://example.com" into "com.example"

[Updated on: Fri, 17 January 2014 02:10]

Report message to a moderator

Re: [Acceleo] [message #1232615 is a reply to message #1232472] Fri, 17 January 2014 10:32 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Sequence{string.size()..1}->forAll(i | string.at(i))


On 17/01/2014 02:09, michel souza wrote:
> Hi guys.. I know this is supposed to be a simple action do a kind of
> reverse but I'm kinda lost.
>
> 1- I've tried to find a method that would do that directly to me...
> but I haven't found
> 2- I thought to break a string in a token and access from the last to
> the first element. I don't know how in Acceleo.
>
> In fact, I found out that Sequence and OrderedSet have a method called
> reverse() that would help me. But I try to break the string in tokens
> using mystring.tokenize('.'). This method was supposed to return a
> Sequence.... but this doesn't happen.. it returns instead a Bag...
> ok.. I tried to mybag->asSequence()->reverse().. but turning a bag
> into a sequence is messing with the order.
>
> So if you have any idea.. I would really appreciate.
>
> I want to turn "http://example.com" into "com.example"
Re: [Acceleo] [message #1232692 is a reply to message #1232615] Fri, 17 January 2014 14:12 Go to previous messageGo to next message
michel souza is currently offline michel souzaFriend
Messages: 18
Registered: December 2013
Junior Member
Hi Ed Willink,

thanks for you answer but it doesn't seem to work.

I tried [Sequence{'blue.example.com'.size()..1}->forAll(i | 'blue.example.com'.at(i))/]
and I receive the following message: Iterate Expression body type must be boolean (Sequence{'blue.example.com'.size()..1}->forAll(i | 'blue.example.com'.at(i))).

I tried to print Sequence{5..1}.. it prints 0.. it doesn't give me a range of 5,4,3,2,1 and the forAll return always a boolean... I don't see how can this work.
Re: [Acceleo] [message #1232719 is a reply to message #1232692] Fri, 17 January 2014 15:08 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
I was giving you clues, not spoon feeding.


On 17/01/2014 14:12, michel souza wrote:
> Hi Ed Willink,
>
> thanks for you answer but it doesn't seem to work.
>
> I tried [Sequence{'blue.example.com'.size()..1}->forAll(i |
> 'blue.example.com'.at(i))/]
> and I receive the following message: Iterate Expression body type must
> be boolean (Sequence{'blue.example.com'.size()..1}->forAll(i |
> 'blue.example.com'.at(i))).
>
> I tried to print Sequence{5..1}.. it prints 0.. it doesn't give me a
> range of 5,4,3,2,1 and the forAll return always a boolean... I don't
> see how can this work.
Re: [Acceleo] [message #1233916 is a reply to message #1232719] Mon, 20 January 2014 20:54 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi,

You should use something like ['example.com'.tokenize('.')->reverse()/]. When you say that tokenize returns a bag, are you sure that you did not use ''->tokenize('') instead of ''.tokenize('')?

Regards,

Stephane Begaudeau, Obeo

--
Twitter: @sbegaudeau
Google+: +stephane.begaudeau
Blog: http://stephanebegaudeau.tumblr.com | Eclipse Java Development Tools Tips and Tricks
Re: [Acceleo] [message #1234870 is a reply to message #1233916] Thu, 23 January 2014 02:15 Go to previous message
michel souza is currently offline michel souzaFriend
Messages: 18
Registered: December 2013
Junior Member
Hi Stephane,

I figured out the probleam. In fact, my string came from a search that I did with a 'select'.. this select was returning me a collection that wasn't a Sequence.. so I couldn't apply 'first()' operation. I was directly applying resultofsearch.name.tokenize('.')... instead of resultofsearch->asSequence->first().name.tokenize('.') to apply the operation to one single string.

I'm using the lastest versions, I guess.

Many thanks for your help. Merci vraiment pour votre aide!
Previous Topic:[Acceleo] tokenize method returning a Bag instead of Sequence
Next Topic:emtl files not created when the imported projects are not copied in the workspace
Goto Forum:
  


Current Time: Thu Apr 25 05:43:31 GMT 2024

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

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

Back to the top