Only one file for many classes, here my code. [message #780668] |
Wed, 18 January 2012 18:06  |
Eclipse User |
|
|
|
Hi all...
I am trying to generate only one file for model. (One model contains a class diagram with many classes).
For example, I want to create a txt file with all the names of the classes.
I have done this:
[comment encoding = UTF-8 /]
[module generate('.../uml2/3.0.0/UML')]
[template public Main(aClass : Class)]
[comment @main/]
[file (aClass.name.concat('.txt'), false)]
[printNameClass(aClass)/]
[/file]
If I have a model with 4 classes, this code generates four different file with the name of their class.
I want to create only one file with all the four names. How can I do it?
Thanks.
[Updated on: Wed, 18 January 2012 19:51] by Moderator
|
|
|
|
|
|
|
|
|
|
|
Re: Only one file for many classes, here my code. [message #780862 is a reply to message #780807] |
Thu, 19 January 2012 12:39   |
Eclipse User |
|
|
|
Christian Dietrich wrote on Thu, 19 January 2012 07:58
the properties go into the same file as the class does. what a miracle.
~Christian
For first thanks for the answer, I really appreciate your help but
that code does not solve the problem since it generates n file for n classes.
the code you have posted:
[template public umlToBeans(aPackage : Package)]
[comment @main /]
[for (aClass : Class | aPackage.packagedElement->filter(Class))]
[aClass.generate()/]
[/for]
[/template]
[template public generate(aClass : Class)]
[file (aClass.name.concat('.java'), false)]
public class [aClass.name.toUpperFirst()/] {
[for (p: Property | aClass.attribute) separator('\n')]
private [p.type.name/] [p.name/];
[/for]
[for (p: Property | aClass.attribute) separator('\n')]
public [p.type.name/] get[p.name.toUpperFirst()/]() {
return this.[p.name/];
}
[/for]
[for (o: Operation | aClass.ownedOperation) separator('\n')]
public [o.type.name/] [o.name/]() {
// TODO should be implemented
}
[/for]
}
[/file]
[/template]
generates exactly the same things that my original code generates with "different" requests.
This is my original code:
[template public Main(aClass : Class)]
[comment @main/]
[file (aClass.name.concat('.txt'), false, 'UTF-8')]
[print(aClass)/]
[/file]
[/template]
[template public print(aClass : Class)]
Class name = [aClass.name/]
[/template]
As I asked, I need to generate only one output file with the names of the classes contained in the model.
If my model have 4 classes for example, I need to create only one output file containing the name of the four classes.
With mine and yours code, acceleo generates four output file for four classes.
Any help is much appreciated.
Thanks.
[Updated on: Thu, 19 January 2012 12:40] by Moderator
|
|
|
|
Re: Only one file for many classes, here my code. [message #780870 is a reply to message #780864] |
Thu, 19 January 2012 13:36   |
Eclipse User |
|
|
|
Christian Dietrich wrote on Thu, 19 January 2012 12:48HI,
i wont do your homework. i wanted to tell you that you should create a file like
THIS IS A TEMPLATE FOR A UML::MODEL
FILE "FILENAME.TXT"
TRAVERSE THE MODEL AND SREACH THE CLASSES AND OOUTPUT THEIR NAME
ENDFILE
ENDOFTHETEMPLATE
I have a degree in computer science, don't call it homework 
The homework time is finished, now I need to choose if use acceleo in my company or not so I am studying it 
In any case, your suggestion is really much appreciated and I thank you for your help/patience.
I tought you gived me the solution but, I understood the code now and "adjusted" the shot.
Now I can print all the class names in one file. Thanks.
I will continue my excercise. I will post some more question here, if I'll have questions, hope you will be here 
Again, many thanks.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Only one file for many classes, here my code. [message #782460 is a reply to message #782152] |
Mon, 23 January 2012 13:46  |
Eclipse User |
|
|
|
Edward Willink wrote on Mon, 23 January 2012 04:15
[aEnumeration.eAllContents().eAllContents()/]
Is incredibly stupid, but fortunately enumerations only have limited
content so the N-squared usage is not catastrophic.>
Not catastrophic but it output anything.
There is not output at all from
[aEnumeration.eAllContents().eAllContents()/]
|
|
|