Problems when referencing Ecore elements using an imported Ecore model [message #1754821] |
Wed, 22 February 2017 18:47  |
|
Hi
in a new DSL I started to work on, I refer to Ecore elements in the DSL, something like
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "http://www.eclipse.org/xtext/xbase/Xbase" as xbase
generate myDsl "...my uri..."
...
Program:
...
('metamodel' metamodels+=[ecore::EPackage|STRING])*
...
;
So far so good, everything works. Now I'd like to switch to a manually maintained ecore model. I performed the steps to switch to an imported ecore model (starting from the one that Xtext had previously generated).
As soon as I switch in the grammar:
...
import "...my uri..."
...
The grammar editor starts complaining with a warning for the import:
"The imported package refers to elements in the package registry
instead of using the instances from the workspace"
and for the assignment metamodels+=[ecore::EPackage|STRING]) I get an error:
"Cannot find compatible feature metamodels in sealed EClass
Program from imported package myuri:
The type 'EPackage' [org.eclipse.emf.ecore.EPackage] used in
the reference 'metamodels' is inconsistent. Probably this is
due to an unsupported kind of metamodel hierarchy."
However, the workflow mwe2 still runs (of course, I updated it so that it references my genmodel).
The warning (not the error) proposes a quickfix to "update the imported package". The quickfix transforms in my ecore the reference:
<eStructuralFeatures xsi:type="ecore:EReference" name="metamodels" unique="false"
upperBound="-1" eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EPackage"/>
into
<eStructuralFeatures xsi:type="ecore:EReference" name="metamodels" unique="false"
upperBound="-1" eType="ecore:EClass ../../../org.eclipse.emf.ecore/model/Ecore.ecore#//EPackage"/>
Now the editor is happy (no more errors nor warnings). However, now it is the mwe2 workflow that complains with the same error I used to have in the editor:
"Cannot find compatible feature metamodels in sealed EClass EdeltaProgram from imported package ...myuri...: The type 'EPackage' used in the reference 'metamodels' is inconsistent. Probably this is due to an unsupported kind of metamodel hierarchy. (ErrorCode: CannotCreateTypeInSealedMetamodel)"
is there anything I could do to make "everyone" happy?
Could this be related https://github.com/eclipse/xtext-core/issues/41?
thanks in advance
Lorenzo
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
|
Re: Problems when referencing Ecore elements using an imported Ecore model [message #1754823 is a reply to message #1754822] |
Wed, 22 February 2017 19:04   |
|
interestingly this xcore setup seems to work (i did not test if what comes out acutally runs
@GenModel(nsUri="http://www.example.com//zzz")
package zzz
import org.eclipse.emf.ecore.EPackage
class Model {
refers EPackage[] metamodels
}
grammar org.xtext.example.mydsl8.MyDsl with org.eclipse.xtext.common.Terminals
import "zzz"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Model returns Model:
{Model}
'Model'
'{'
('metamodels' '(' metamodels+=[ecore::EPackage|STRING] ( "," metamodels+=[ecore::EPackage|STRING])* ')' )?
'}';
language = StandardLanguage {
name = "org.xtext.example.mydsl8.MyDsl"
fileExtensions = "mydsl8"
referencedResource = "platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel"
referencedResource = "platform:/resource/zzz.xcore/model/zzz.xcore"
Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
Re: Problems when referencing Ecore elements using an imported Ecore model [message #1754867 is a reply to message #1754862] |
Thu, 23 February 2017 10:53   |
|
OK, I added that in the grammar:
import "platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore" as ecore
import "platform:/resource/org.eclipse.xtext.xbase/model/Xbase.ecore" as xbase
import "platform:/resource/org.eclipse.xtext.xbase/model/Xtype.ecore" as xtype
import "platform:/resource/org.eclipse.xtext.common.types/model/JavaVMTypes.ecore" as types
The Xtext editor still complains with errors and now also mwe2 fails with the same problems, so both now fail consistently.
If I now modify the ecore manually using platform uris for ecore references, the editor is happy but now the mwe2 fails with a different error:
java.lang.IllegalStateException: Validation Error in edelta.Edelta: The rule 'STRING' is not valid for a cross reference since it does not return an EString. You'll have to wrap it in a data type rule.
at org.eclipse.xtext.xtext.generator.XtextGeneratorLanguage$1.add(XtextGeneratorLanguage.java:300)
If I redefine the terminal rule STRING in my grammar
@Override
terminal STRING:
'"' ( '\\' . /* ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') */ | !('\\'|'"') )* '"'? |
"'" ( '\\' . /* ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') */ | !('\\'|"'") )* "'"?;
Then mwe2 throws another exception:
java.lang.RuntimeException: Problems running workflow edelta.GenerateEdelta: Problem parsing 'file:/home/bettini/work/xtext/edelta/edelta.parent/edelta/../edelta/src/edelta/Edelta.xtext':
TransformationDiagnostic: null:92 Cannot inherit from terminal rule and return another type. (ErrorCode: InvalidSupertype)
I guess there's no easy way to deceive the EMF registry...
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
|
|
|
|
|
Re: Problems when referencing Ecore elements using an imported Ecore model [message #1754880 is a reply to message #1754878] |
Thu, 23 February 2017 12:58   |
|
OK, I can answer myself:
class CustomGeneratorModule extends DefaultGeneratorModule {
def Class<? extends XtextGeneratorResourceSetInitializer> bindXtextGeneratorResourceSetInitializer() {
CustomXtextGeneratorResourceSetInitializer
}
}
Workflow {
component = XtextGenerator {
configuration = CustomGeneratorModule {
project = StandardProjectConfig {...
and (note the commented line):
@Log
class CustomXtextGeneratorResourceSetInitializer extends XtextGeneratorResourceSetInitializer {
override initialize(ResourceSet resourceSet, List<String> referencedResources) {
val delegate = new StandaloneSetup
delegate.resourceSet = resourceSet
// resourceSet.packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE)
referencedResources.forEach[
loadResource(resourceSet)
]
registerGenModels(resourceSet)
registerEPackages(resourceSet)
}
... everything else copied and pasted from the superclass since it's all private
This makes mwe2 finally work... (and tests are still green)
I don't know how this could be generalized for the bug...
I'll also try to revert the imports in the grammar with platform uris and see what happens
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02833 seconds