| ATL Helper Context Assignment [message #1852710] |
Wed, 01 June 2022 19:53  |
Eclipse User |
|
|
|
Dear all,
I managed to have some String operations in do {
thisModule.var2<-thisModule.var;
thisModule.var2<-thisModule.var.split('[.]');
thisModule.var2.debug();
}
How can I create a helper context rule that does the same assignment and operations? I inspected some helper contexts, but most of them run with if/else.
Thank you.
Best regards
|
|
|
|
| Re: ATL Helper Context Assignment [message #1852720 is a reply to message #1852717] |
Thu, 02 June 2022 04:34   |
Eclipse User |
|
|
|
Hi Dennis,
Thank you so much for your answer. Actually, I try to achieve some steps of string operation and I need to apply this to 4-5 transformations. Using their do {} blocks will not be reasonable because the code will be the same for all. Instead, a helper rule could help, but the declarative type limits my approach I think.
thisModule.var <-pim.eContainer().refGetValue('GetLine');
thisModule.var2<-thisModule.var;
thisModule.var2<-thisModule.var.split('[.]');
thisModule.var2<- thisModule.var2.insertAt(thisModule.var2.size(),thisModule.var2->last().toInteger()+1);
thisModule.count <- thisModule.count +1;
thisModule.var2<-thisModule.var2.insertAt(thisModule.var2.size(),thisModule.var2->last().toInteger()+thisModule.count).subSequence(1, thisModule.var2.size());
pim.Line<thisModule.var2.at(1).concat('.')+thisModule.var2.at(2).concat('.')+thisModule.var2.at(3).concat('.')+thisModule.var2.at(4);
The idea is that modify a string in form of 1.2.3.4, parsing it based on '.' then incrementing the last digit, which is 4 to 5 and merging it again as 1.2.3.5. However, even though I achieved this in the imperative do{} block. I think I used so helper context, otherwise, I have to repeat the same code for 4-5 transformations, which is not conventional.
Thank you.
Best regards.
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.25660 seconds