0

I tried to use Acceleo to translate a model to a text in an Eclipse plugin. The model is fine and the loaded Acceleo module looks fine as well. Still, acceleo does not generate anything.

Here is my code:

    AcceleoService as = new AcceleoService(new PreviewStrategy());
    URI alfToSpecSharpTemplate;
    try {
        alfToSpecSharpTemplate = getTemplateURI("my-valid-uri", new Path("/path/to/generate.emtl"));
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }

    as.addListener(new IAcceleoTextGenerationListener() {/* print every method name on call */});

    ResourceSet mtlSet = new ResourceSetImpl();
    final Resource mtlRessource = mtlSet.getResource(alfToSpecSharpTemplate, true);
    final Module module = (Module) mtlRessource.getContents().get(0);
    List<Object> arguments = new ArrayList<Object>();
    Map<String, String> result = as.doGenerate(module, "generateElement", myModel, arguments, null, new BasicMonitor());

    System.out.println("Generation: " + as.hasGenerationOccurred());

The IAcceleoTextGenerationListener prints that listensToGenerationEnd() is called and nothing else. The loaded module looks fine in debug. It has the generateElement-template. The generate.mtl looks like this:

    [comment encoding = UTF-8 /]
    [module generate('http://www.eclipse.org/papyrus/alf/Alf')]

    [template public generateElement(test : Test) post (trim())]
    [file('expr.specs', true)]
    [test.block.generateElement() /]
    [/file]
    [/template]

My problem is that nothing is generated, i.e. result is an empty map. Also "Generation: false" is printed to console. Especially no error is printed.

Anyone have any idea on what is going wrong? I had it working once but I can't get it to work any more.

4

1 回答 1

0

通过Acceleo调试我终于发现了我的错误。Acceleo 只查看标有 的模板[comment @main /]。因为我没有这样的模板,Acceleo 什么也不做。所以解决方法是添加@main

[template public generateElement(test : Test) post (trim())]
[comment @main /]
[file('expr.specs', true)]
[test.block.generateElement() /]
[/file]
[/template]
于 2014-10-13T13:31:02.630 回答