[Acceleo] Generation templates not working with run-time meta-models and dynamic instances [message #667521] |
Fri, 29 April 2011 10:42 |
Niels Brouwers Messages: 80 Registered: July 2009 |
Member |
|
|
Hi all,
I have created a dynamic instance model, based on the following meta-model:
module _'MyEcoreModel.ecore'
package myEcoreModel : myEcoreModel = 'http://nl.example.metamodel'
{
class SomeClass
{
attribute name : String[?] { ordered };
}
}
The contents of the instance model is as follows:
<?xml version="1.0" encoding="ASCII"?>
<myEcoreModel:SomeClass
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:myEcoreModel="http://nl.example.metamodel"
xsi:schemaLocation="http://nl.example.metamodel ../../model/MyEcoreModel.ecore"
name="someName"
/>
Next, I have create an Acceleo template to generate some text from the dynamic instance model:
[comment encoding = UTF-8 /]
[module generate('http://nl.example.metamodel')/]
[template public generate(a : SomeClass)]
[comment @main /]
[file ('output.txt', false, 'UTF-8')]
[a.name/]
[/file]
[/template]
Problem:
The Java class generated from the main generator module, Generate.java contains a compile error in the following code fragment:
/**
* This can be used to update the resource set's package registry with all needed EPackages.
*
* @param resourceSet
* The resource set which registry has to be updated.
* @generated
*/
@Override
public void registerPackages(ResourceSet resourceSet) {
super.registerPackages(resourceSet);
if (!isInWorkspace(org.eclipse.emf.ecore.impl.EPackageImpl.class)) {
resourceSet.getPackageRegistry().put(org.eclipse.emf.ecore.impl.EPackageImpl.eINSTANCE.getNsURI(), org.eclipse.emf.ecore.impl.EPackageImpl.eINSTANCE);
}
// TODO If you need additional package registrations, do them here. The following line is an example for UML.
// resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
}
The compile error is located on line 291, the line starting with: resourceSet..... and contains the following message:
Multiple markers at this line
- eINSTANCE cannot be resolved or is not
a field
- eINSTANCE cannot be resolved or is not
a field
Current environment: Eclipse Indigo M6a
Note: i've tested generation using the same meta-model, instance model and generation templates in a Eclipse Helios R2 distribution and experienced no problems there.
Is there something I am doing wrong or is this related to the following bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=337011?
Kind regards,
Niels Brouwers.
Kind regards,
Niels Brouwers.
[Updated on: Fri, 29 April 2011 10:42] Report message to a moderator
|
|
|
|
Re: [Acceleo] Generation templates not working with run-time meta-models and dynamic instances [message #667537 is a reply to message #667526] |
Fri, 29 April 2011 12:29 |
Niels Brouwers Messages: 80 Registered: July 2009 |
Member |
|
|
Hi Stephane,
I had already tried that, so I was confused why you suggested the same work-around. First, removing the errornous line did not result in any errors while running the generator, nor did it result in any output.
So, I looked further. The solution was to convert the project containing the meta-model into a plugin project and add this project as dependency to the generator project. This solved the problem. Strange why it did not produce any error somewhere. I've checked the console, problems and error log views.
I would like to suggest to report an error if, for some reason, the meta-model could not be found.
Stephane, thanx for your help!
Kind regards,
Niels Brouwers.
Kind regards,
Niels Brouwers.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05654 seconds