Xtext for composed metamodels [message #662647] |
Thu, 31 March 2011 12:29 |
Cedric Moonen Messages: 274 Registered: August 2009 |
Senior Member |
|
|
Hello,
I am trying to use Xtext to create a DSL for a composed metamodel. I already have my metamodels, which consist of two metamodels: a Type metamodel and my "real DSL metamodel" which references the Type metamodel.
My Types metamodel looks like:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="types"
nsURI="http://types/1.0" nsPrefix="types">
<eClassifiers xsi:type="ecore:EClass" name="Type">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="TypeManager">
<eStructuralFeatures xsi:type="ecore:EReference" name="types" upperBound="-1"
eType="#//Type" containment="true"/>
</eClassifiers>
</ecore:EPackage>
And the other metamodel using it looks like:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="orodsl"
nsURI="http://org.orocos.dsl/1.0" nsPrefix="orodsl">
<eClassifiers xsi:type="ecore:EClass" name="TaskContext">
<eStructuralFeatures xsi:type="ecore:EReference" name="ports" upperBound="-1"
eType="#//DataPort" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="DataPort">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="type" lowerBound="1" eType="ecore:EClass Types.ecore#//Type"/>
</eClassifiers>
</ecore:EPackage>
So basically, we have a list of types contained in a TypeManager, and in our second model we have a TaskContext which contains DataPort of a certain Type (so, it is referencing the Type defined in the other metamodel).
When I create an Xtext project based on this metamodel ("Xtext Project From Existing Ecore Models), everything is generated properly: the grammar which import the two packages, the worflow registering the two packages,... And there's no errors in the xtext editor.
When I want to generate the code (so, I didn't modify the generated code), I get an exception related to the Type referenced in the grammar. Here is the full output:
0 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Registering platform uri 'C:\Sources\modcos_gco\oroDSL'
16 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Adding generated EPackage 'types.TypesPackage'
16 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Adding generated EPackage 'orodsl.OrodslPackage'
391 [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher - Problems instantiating module org.orocos.dsl.xtext.OroDSL: java.lang.reflect.InvocationTargetException
java.lang.RuntimeException: Problems instantiating module org.orocos.dsl.xtext.OroDSL: java.lang.reflect.InvocationTargetException
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:73)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
Caused by: org.eclipse.emf.common.util.WrappedException: java.lang.reflect.InvocationTargetException
at org.eclipse.emf.mwe2.language.factory.SettingProviderImpl$1$1.setValue(SettingProviderImpl.java:56)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalApplyAssignments(Mwe2ExecutionEngine.java:127)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:102)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:272)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:56)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalApplyAssignments(Mwe2ExecutionEngine.java:126)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:102)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:272)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:56)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalApplyAssignments(Mwe2ExecutionEngine.java:126)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:102)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:272)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:56)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:272)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:56)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.create(Mwe2ExecutionEngine.java:52)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:71)
... 3 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.emf.mwe2.language.factory.SettingProviderImpl$1$1.setValue(SettingProviderImpl.java:54)
... 36 more
Caused by: java.lang.IllegalStateException: Problem parsing 'classpath:/org/orocos/dsl/xtext/OroDSL.xtext':[TransformationDiagnostic: null:30 Cannot find compatible feature type in sealed EClass DataPort from imported package http://org.orocos.dsl/1.0. (ErrorCode: CannotCreateTypeInSealedMetamodel), TransformationDiagnostic: null:38 Cannot find compatible feature returnType in sealed EClass Method from imported package http://org.orocos.dsl/1.0. (ErrorCode: CannotCreateTypeInSealedMetamodel), TransformationDiagnostic: null:65 Cannot find compatible feature type in sealed EClass BufferPort from imported package http://org.orocos.dsl/1.0. (ErrorCode: CannotCreateTypeInSealedMetamodel), TransformationDiagnostic: null:75 Cannot find compatible feature type in sealed EClass Parameter from imported package http://org.orocos.dsl/1.0. (ErrorCode: CannotCreateTypeInSealedMetamodel)]
at org.eclipse.xtext.generator.LanguageConfig.setUri(LanguageConfig.java:112)
... 41 more
Please note that the example that posted here is a simplified version of my metamodel and the stack trace I posted here is the one I have in my environment. It means that the errors displayed in the last exception shown in the stack do not reflect the example I posted here. But the principle is the same: an error is flagged each time a "Type" object is referenced in the grammar.
Do you have any idea what might be wrong ?
Thanks.
|
|
|
Re: Xtext for composed metamodels [message #662747 is a reply to message #662647] |
Thu, 31 March 2011 18:42 |
|
Hi,
i cannot reproduce this problem, but i have following questions
(1) how is/are your genmodel(s) structured
(2a) what did you select as root element for your grammar in the dialog?
(2b) can you post the grammar Xtext generated for you
(3) which Xtext version do you use.
~Christian
P.S:
here are my genmodels
<?xml version="1.0" encoding="UTF-8"?>
<genmodel:GenModel xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" modelDirectory="/test.emf/src"
modelPluginID="test.emf" modelName="Types" importerID="org.eclipse.emf.importer.ecore"
complianceLevel="6.0" copyrightFields="false">
<foreignModel>Types.ecore</foreignModel>
<genPackages prefix="Types" disposableProviderFactory="true" ecorePackage="Types.ecore#/">
<genClasses ecoreClass="Types.ecore#//Type">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute Types.ecore#//Type/name"/>
</genClasses>
<genClasses ecoreClass="Types.ecore#//TypeManager">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference Types.ecore#//TypeManager/types"/>
</genClasses>
</genPackages>
</genmodel:GenModel>
<?xml version="1.0" encoding="UTF-8"?>
<genmodel:GenModel xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" modelDirectory="/test.emf/src"
modelPluginID="test.emf" modelName="Orodsl" importerID="org.eclipse.emf.importer.ecore"
complianceLevel="6.0" copyrightFields="false" usedGenPackages="Types.genmodel#//types">
<foreignModel>Orodsl.ecore</foreignModel>
<genPackages prefix="Orodsl" disposableProviderFactory="true" ecorePackage="Orodsl.ecore#/">
<genClasses ecoreClass="Orodsl.ecore#//TaskContext">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference Orodsl.ecore#//TaskContext/ports"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute Orodsl.ecore#//TaskContext/name"/>
</genClasses>
<genClasses ecoreClass="Orodsl.ecore#//DataPort">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute Orodsl.ecore#//DataPort/name"/>
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference Orodsl.ecore#//DataPort/type"/>
</genClasses>
</genPackages>
</genmodel:GenModel>
and grammar
// automatically generated by Xtext
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
import "platform:/resource/test.emf/model/Orodsl.ecore"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "platform:/resource/test.emf/model/Types.ecore" as types
TaskContext returns TaskContext:
{TaskContext}
'TaskContext'
name=EString
'{'
('ports' '{' ports+=DataPort ( "," ports+=DataPort)* '}' )?
'}';
DataPort returns DataPort:
'DataPort'
name=EString
'{'
'type' type=[types::Type|EString]
'}';
EString returns ecore::EString:
STRING | ID;
Type returns types::Type:
{types::Type}
'Type'
name=EString
;
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Xtext for composed metamodels [message #662834 is a reply to message #662647] |
Fri, 01 April 2011 07:30 |
Cedric Moonen Messages: 274 Registered: August 2009 |
Senior Member |
|
|
Hello Christian,
Thanks for your reply. After reading your message, I deleted my existing genmodel file, created a new one and generated my model code.
At that point, generating the code for my Xtext bundle worked fine. I don't know what was wrong with my original genmodel file.
I didn't know that the genmodel was important for Xtext, I thought that only the resulting code was used.
Anyway, this works now fine. However I have a remark: in this precise case, I will need to have two Xtext plug-ins: one for the Types DSL and one for the "OroDSL" one. When I create my genmodel file, I need to select both packages, so that the genmodel will generate the code for both models. In order to be able to create a grammar for my Types DSL, I need to create an additional genmodel file targeting only the Types metamodel. Thus, I will end-up with some kind of "duplicate information" about the Types metamodel (it will be in both genmodel files). Is that ok ?
I generated the code for both DSL and added the import mechanism as described in the user manual and everything seems to work fine: I can create a "Types" file which can be imported inside a "OroDSL" file which is then referring to the types already declared.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03481 seconds