Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Generating code from multiple metamodels
[Acceleo] Generating code from multiple metamodels [message #522695] |
Tue, 23 March 2010 12:00  |
Eclipse User |
|
|
|
Dear all,
I would like to generate code from two models that have different metamodels. Is is possible with Acceleo?
As far as I know, it is not possible to append multiple metamodels to the [model ... /] tag. How can I bypass the problem?
If Acceleo does not allow code generation from multiple metamodels, is there a way to do it with XPAND?
I have only little experience with M2T technologies and am thankful for any help.
Thanks a lot!
Tobias
|
|
| | | | | | |
Re: [Acceleo] Generating code from multiple metamodels [message #523579 is a reply to message #523429] |
Fri, 26 March 2010 18:27   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------090809040906010608050901
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Tobias,
Indeed, that wasn't what I understood from your last post :).
If your two models are both required for the generation of a single
file, I believe one of the two references the other? The example of
Stéphane with the genmodel referencing the ecore is a good one : if your
model A has references towards model B, you can simply launch the
generation on A : references to B will be transparently resolved (much
like opening A in the EMF editor transparently loads B when needed if a
reference to it is visited). For example, a "GenPackage" element from
the genmodel has a reference "ecorePackage" that points to an "EPackage"
element from an ecore model.
However, if your two models are totally unrelated (A has no reference
whatsoever to B, B has no reference whatsoever to A), then the use case
cannot be handled through Acceleo (in fact, I fail to see how both could
be required for a single module if they don't share any reference to one
another).
I don't know if this helps, yet if not, I'll have to know a little more
about what you're trying to accomplish, the metamodels and models you
use and why loading both is mandatory.
Laurent Goubet
Obeo
Tobias R wrote:
> First thanks a lot for your information. However, I believe my question
> is somehow ambiguous --- at least if I regard the posting from Laurent
> Goubet. So, I don't know if we speak about the same thing.
>
> Let's try to state my problem again :)
>
> I have two models that conform to two different EMF metamodels. To
> generate a single source code file, both models are required. In other
> words, the contents of the two models are supposed to result in a single
> Java class by using Acceleo.
> To summarise: I don't need to generate multiple models at once, however,
> I need to generate a Java file from two given models!
>
> Is is possible to solve this problem by using a Genmodel?
>
> Thanks a lot!
>
> Tobias
--------------090809040906010608050901
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"
YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------090809040906010608050901--
|
|
| | | | |
Re: [Acceleo] Generating code from multiple metamodels [message #1691344 is a reply to message #1691266] |
Mon, 06 April 2015 06:46   |
Eclipse User |
|
|
|
Hello Ed and thank you for your reply,
Before I type anything else let me ask you, should I open a new thread to continue this conversation? I initially asked for more details here as my question is identical to the opener's one.
As of the 1st module loading emulation:
I guess by stepping in my code you mean stepping and editing the "Generate.java" that is automatically generated when I build a new Acceleo project? If yes, let me write down a concrete example, since to me this "emulating" step is not clear at all:
Assume that I have 2 meta-models, MMA and MMB and have already populated two respective models MA (conforming to MMA) and MB (conforming to MMB). And the way I wish my @main template to look is something like this:
[comment encoding = UTF-8 /]
[module generate('file:/...full path to/MMA.ecore', 'file:/...full path to /MMB.ecore')]
[template public generateElement(anMMAElement : MMAElement, anMMBElement : MMBElement)]
[comment @main/]
[file (.....)]
.....
[anMMAElement.name/] <-- Access MA model
....
[anMMBElement.name/] <-- Access MB model
[/file]
[/template]
I guess that I have to edit the main function in the generate.java file like this? (with a preceding arrow are the added lines):
public static void main(String[] args) {
try {
if (args.length < 2) {
System.out.println("Arguments not valid : {model, folder}.");
} else {
URI modelURI = URI.createFileURI(args[0]);
File folder = new File(args[1]);
--> URI modelMBURI = URI.createFileURI("full path to/modelMB.xmi");[/b]
List<String> arguments = new ArrayList<String>();
--> arguments.add("anMMBElement : MMB");
Generate generator = new Generate(modelURI, folder, arguments);
--> Generate modelMBGenerator = new Generate(modelMBURI, folder, arguments);
for (int i = 2; i < args.length; i++) {
generator.addPropertiesFile(args[i]);
}
generator.doGenerate(new BasicMonitor());
--> modelMBGenerator.doGenerate(new BasicMonitor());
}
(I do get an Argument types mismatch for module element generateElement exception at the line "generator.doGenerate(new BasicMonitor()); )
Thanks for your feedback,
Christoforos.
[Updated on: Mon, 06 April 2015 06:47] by Moderator
|
|
| |
Re: [Acceleo] Generating code from multiple metamodels [message #1693636 is a reply to message #1691344] |
Mon, 27 April 2015 03:45  |
Eclipse User |
|
|
|
Hi,
The list of arguments should just be the list of the objects that you want as arguments. Your template has the following signature:
[template public generateElement(anMMAElement : MMAElement, anMMBElement : MMBElement)]
Then the arguments list should be something like this:
List<MMBElement> arguments = new ArrayList<>();
arguments.add(yourMMBElement);
and not
List<String> arguments = new ArrayList<String>();
arguments.add("anMMBElement : MMB");
And on top of that, do not use the path of the ecore model in the declaration of your module, you should use the NsURI of your EPackages in those ecore model.
[module generate('file:/...full path to/MMA.ecore', 'file:/...full path to /MMB.ecore')]
Regards,
Stephane Bégaudeau, Obeo
|
|
|
Goto Forum:
Current Time: Sat May 10 16:59:10 EDT 2025
Powered by FUDForum. Page generated in 0.04426 seconds
|