How to transform xText to XMI [message #666060] |
Mon, 18 April 2011 16:29  |
Eclipse User |
|
|
|
Hi,
xText comes with a snazzy ecore inference model that can take a grammar and guess a suitable eCore model for it. However, after I write a short program conforming to this grammar, I found that I still needed to write xpand templates to transform this to text!
Is there a way to turn the textual program in my specified grammar into an XMI (or similar) file conforming to the inferred ecore model?
Thanks!
|
|
|
|
|
Re: How to transform xText to XMI [message #666121 is a reply to message #666101] |
Tue, 19 April 2011 04:13   |
Eclipse User |
|
|
|
Hi Ed,
this seems to be a bug in the sample Ecore editor, which renames the
resource's URI rather than creating a new one with the extension from
the new URI, if it's not a conversion between "ecore" and "emof":
(EcoreEditor.doSaveAs)
if (currentExtension.equals(ECORE_FILE_EXTENSION) &&
newExtension.equals(EMOF_FILE_EXTENSION) ||
currentExtension.equals(EMOF_FILE_EXTENSION) &&
newExtension.equals(ECORE_FILE_EXTENSION))
{
Resource newResource = resourceSet.createResource(newURI);
newResource.getContents().addAll(currentResource.getContents ());
resourceSet.getResources().remove(0);
resourceSet.getResources().move(0, newResource);
}
else
{
currentResource.setURI(newURI);
}
Regards
Jan
Am 19.04.11 09:07, schrieb Ed Willink:
> Hi Christian
>
> This is an area where I feel that Xtext has been too clever.
>
> You can open an Xtext CS file in the Sample Ecore Editor and see the
> tree view, but if you then do SaveAs *.xmi, the result is saved as CS
> text rather than XMI text. Somehow Xtext has higher priority than XMI.
> It would be nice to have this interactive approach work fully.
>
> Regards
>
> Ed Willink
>
> On 19/04/2011 06:44, Christian Dietrich wrote:
>> Hi,
>>
>> if you work e.g. with a programmatically read model it is actually an
>> model instance based on the generated ecore.
>>
>> How you can read in the model files standalone you can find in the
>> docs section Processing Xtext Models.
>>
>> If you still need an XMI Feel free to move the contents of the read
>> Xtext Resource to and XMI Resource.
>>
>>
>> ResourceSet rs = new ResourceSetImpl();
>> Resource resource = rs.getResource(URI.createURI("./mymodel.dmodel"),
>> true);
>> EObject eobject = resource.getContents().get(0);
>> Resource xmiResource = ....
>> xmiResource.getContents.add(eobject);
>> ...
>>
>>
>> ~Christian
>
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
|
|
|
|
|
Re: How to transform xText to XMI [message #697619 is a reply to message #666310] |
Sun, 17 July 2011 09:08   |
Eclipse User |
|
|
|
Currently I too use this approach, save it as .xmi, which is then read by eg. ATL (in an ant based transformation sequence).
Christian, do you still think there is need for m2m transformations, that read the xtext-generated xmi model, and transform it, followed by an eventual XPand transformation to text?
Because this is my current approach (ie. I have an MDA that generates webapps). Allthough I don't use any expressions in my model, just declarative structural stuff, and generate 'defaults' in terms of behaviours, so for that purpose I'd say the XTend thing is very useful.
I wonder what your opinion is about this.
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.27409 seconds