Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Problem when generating methods with the same name
[Acceleo] Problem when generating methods with the same name [message #1060130] Thu, 23 May 2013 09:06 Go to next message
Javier García is currently offline Javier GarcíaFriend
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 #1061606 is a reply to message #1060130] Mon, 03 June 2013 09:21 Go to previous messageGo to next message
Javier García is currently offline Javier GarcíaFriend
Messages: 129
Registered: April 2013
Senior Member
I submitted a bug about this since nobody seems to have an answer and it does seem like a bug:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=409463
Re: [Acceleo] Problem when generating methods with the same name [message #1061617 is a reply to message #1061606] Mon, 03 June 2013 10:00 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

In my experience, this is an area where Acceleo is very good. The
problem is more often that Acceleo accurately does things once and you
need to force it to repeat with an extra disambiguation argument. So I
would very strongly suspect that you have duplicate objects that Acceleo
accurately transforms as duplicates.

Try debugging by doing a dummy M2T in which you just use a Java helper
to print out the hashCode of all your objects.

Regards

Ed Willink


On 03/06/2013 10:21, Javier García wrote:
> I submitted a bug about this since nobody seems to have an answer and
> it does seem like a bug:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=409463
Re: [Acceleo] Problem when generating methods with the same name [message #1061627 is a reply to message #1061617] Mon, 03 June 2013 11:04 Go to previous messageGo to next message
Javier García is currently offline Javier GarcíaFriend
Messages: 129
Registered: April 2013
Senior Member
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.
Re: [Acceleo] Problem when generating methods with the same name [message #1061644 is a reply to message #1061627] Mon, 03 June 2013 11:40 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
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.
Re: [Acceleo] Problem when generating methods with the same name [message #1062512 is a reply to message #1061644] Sat, 08 June 2013 07:40 Go to previous messageGo to next message
Low Coupling is currently offline Low CouplingFriend
Messages: 30
Registered: June 2013
Member
The set you create

self.getOperations()->union(self.getImplementedInterfaces().ownedOperation)


contains both the operations defined in the Interfaces and the operations defined in the implementing Class.
May it be the case you defined the same operation in the implementing class? If sos it will be generated twice as the two operations are different, from the point of view of the transformation, as contained into two different classifiers (namespace): the Interface and the Class.
Re: [Acceleo] Problem when generating methods with the same name [message #1062689 is a reply to message #1062512] Mon, 10 June 2013 11:50 Go to previous messageGo to next message
Javier García is currently offline Javier GarcíaFriend
Messages: 129
Registered: April 2013
Senior Member
Low Coupling wrote on Sat, 08 June 2013 03:40
The set you create

self.getOperations()->union(self.getImplementedInterfaces().ownedOperation)


contains both the operations defined in the Interfaces and the operations defined in the implementing Class.
May it be the case you defined the same operation in the implementing class? If sos it will be generated twice as the two operations are different, from the point of view of the transformation, as contained into two different classifiers (namespace): the Interface and the Class.


That didn't solve it but on some other classes I actually had the same operation four or five times and with this it got reduced to just three, so it did help, thanks Smile

I tried different models and the same thing happens so I don't know what it is, it's not the biggest problem but it is a problem.
Re: [Acceleo] Problem when generating methods with the same name [message #1065539 is a reply to message #1062689] Wed, 26 June 2013 12:13 Go to previous message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi,

On the UML generator that I wrote, I used a Java service to solve those issues.

Regards,

Stephane Begaudeau, Obeo

--
Twitter: @sbegaudeau
Google+: +stephane.begaudeau
Blog: http://stephanebegaudeau.tumblr.com | Eclipse Java Development Tools Tips and Tricks
Previous Topic:[Acceleo] Problems during code re-generation
Next Topic:[Acceleo] How to get "tagged values" from an attribute of class in UML2.0
Goto Forum:
  


Current Time: Fri Mar 29 15:31:41 GMT 2024

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

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

Back to the top