[Acceleo] Problem when generating methods with the same name [message #1060130] |
Thu, 23 May 2013 09:06 |
Javier García Messages: 129 Registered: April 2013 |
Senior Member |
|
|
Hi guys,
I recently run into some problems with my Acceleo transformation. It works mostly perfect, I transform an UML model into Java code and now I have in several classes two methods that have the same name, but different parameters (method overloading I believe it's called) and when Acceleo generates it, the weirdest thing happens, I get three methods generated. Now when I create the method I also copy any comments it has attached, so I can clearly see that one of the methods gets generated once, and the other method gets generated twice.
So why does this happen? does it get confused somehow due to both methods sharing the same name? is this a known bug?(I couldn't find any info). It's really the only case in which I get this error, every other method gets created just once.
I will just post here the code I use in case it's useful:
[template private operations(aClass : Class)]
[for (anOperation : Operation | aClass.getOperations()->union(aClass.getImplementedInterfaces().ownedOperation))]
/**
* The documentation of the method [anOperation.name.toLowerFirst()/].
*
[for (aParameter : Parameter | anOperation.ownedParameter) ? (aParameter.direction <> ParameterDirectionKind::return)]
* @param [aParameter.name/]
[/for]
[if (not anOperation.type.oclIsUndefined())]
* @return
[/if]
*
* @generated
*/
[anOperation.visibility/] [if (anOperation.type.oclIsUndefined())]void[else][anOperation.type.name/][/if] [anOperation.name.toLowerFirst()/]([anOperation.parameters()/]) {
//
/*
* This is the code from the former method:
* [for (aComment : Comment | anOperation.ownedComment)] [aComment._body/][/for]
*/
// TODO should be implemented
[if (anOperation.type.oclIsUndefined())]//return null;[else][/if] [comment it should be not anOperation... but for some reason it doesn't work properly if we do it that way. /]
//
}
[/for]
[/template]
Thanks in advance,
regards,
Javier
|
|
|
|
|
|
Re: [Acceleo] Problem when generating methods with the same name [message #1061644 is a reply to message #1061627] |
Mon, 03 June 2013 11:40 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi
My programs do impossible things too. Eventually after intense debugging
the problems become clear.
You may have found an Acceleo bug, but my experience is that this is an
area where it is very very easy for obscure user errors to creep in.
Regards
Ed Willink
On 03/06/2013 12:04, Javier García wrote:
> Hi Ed,
> thanks for your answer, I checked the model many times and I can tell
> you for sure that the object is not duplicated, I tested it with at
> least three different classes, and in the three of them the same thing
> happened. It also always seemed to copy twice the operation that was
> at the bottom instead of the top one, not sure if this might help.
> I will try further testing and do what you said this week if I have
> the time, but I know that the model doesn't have two objects that are
> the same, just two operations with the same name, but different content.
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02290 seconds