XtextResource loading with JvmTypes and importURI [message #885497] |
Wed, 13 June 2012 01:48  |
Eclipse User |
|
|
|
Hi,
I use Juno-RC3 and Xtext 2.3.0.v201206051055. I have a problem loading a resource
created with the Xtext editor. Everyting works fine in the editor (cross-references
are resolved, content completion works), but when loading the resources cross-references
are not resolved.
I have two languages, the first defines some (very) simple named objects:
MyDsl1.xtext:
grammar org.xtext.example.mydsl.MyDsl1 with org.eclipse.xtext.common.Terminals
generate myDsl1 "http://www.xtext.org/example/mydsl/MyDsl1"
Model:
greetings+=Greeting1*;
Greeting1:
'Hello' name=ID ';';
With this language I generate everything using the GenerateMyDsl1.mwe2 file and I have
an editor that works well and allows me to write things such as :
test1.mydsl1:
Hello g1 ;
Hello g2 ;
Hello g3 ;
Now, in the second language I want to be able to establish cross-reference to both .mydsl1
models and JvmTypes. So I defined it this way:
MyDsl2.xtext:
grammar org.xtext.example.mydsl.MyDsl2 with org.eclipse.xtext.common.Terminals
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "http://www.eclipse.org/xtext/common/JavaVMTypes"
import "http://www.xtext.org/example/mydsl/MyDsl1"
generate myDsl2 "http://www.xtext.org/example/mydsl/MyDsl2"
Model2:
imports+=ImportStatement*
greetings+=Greeting2*;
ImportStatement:
'import' importURI=EString ';'
;
EString returns ecore::EString:
STRING | ID;
Greeting2:
'Hello' name=ID 'from' object=[Greeting1|ID] 'and' type=[JvmType|QualifiedName] ';'
;
QualifiedName:
ID ( '.' ID )*
;
The GenerateMyDsl2.mwe2 file is only modified to reference the imported models and enable the
importURI mechanism:
bean = StandaloneSetup {
scanClassPath = true
platformUri = "${runtimeProject}/.."
registerGeneratedEPackage = "org.xtext.example.mydsl.myDsl1.MyDsl1Package"
registerGenModelFile = "platform:/resource/org.xtext.example.mydsl1/src-gen/org/xtext/example/mydsl/MyDsl1.genmodel"
registerGenModelFile = "platform:/resource/org.eclipse.xtext.common.types/model/JavaVMTypes.genmodel"
}
and :
// scoping and exporting API
fragment = scoping.ImportURIScopingFragment {}
// fragment = exporting.SimpleNamesFragment {}
// scoping and exporting API
fragment = scoping.ImportNamespacesScopingFragment {}
fragment = exporting.QualifiedNamesFragment {}
fragment = builder.BuilderIntegrationFragment {}
With this setup everything works well in the generated editor. I can write models like this:
import "test1.mydsl1" ;
Hello h1 from g2 and org.eclipse.emf.ecore.EObject ;
Hello h2 from g1 and org.xtext.example.mydsl.MyDsl2InjectorProvider;
Everything works fine, completion shows objects from the test1.mydsl1 resource, and also all types.
Now I want to load such a file in code written in another Eclipse plugin. I use the following code:
injector = new MyDsl2StandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSetProvider provider = injector.getInstance(XtextResourceSetProvider.class);
XtextResourceSet resourceSet = (XtextResourceSet) provider.get(null);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
URI uri2 = URI.createURI("platform:/plugin/org.xtext.example.mydsl2.tests/data/test1.mydsl2");
XtextResource resource2 = (XtextResource) resourceSet.getResource(uri2, true);
But now cross-references are not resolved. The resource set contains only two resources :
URI: platform:/plugin/org.xtext.example.mydsl2.tests/data/test1.mydsl2
URI: java:/Objects/org.eclipse.emf.ecore.EObject
And the errors are :
Error: XtextLinkingDiagnostic: null:2 Couldn't resolve reference to Greeting1 'g2'.
Error: XtextLinkingDiagnostic: null:3 Couldn't resolve reference to Greeting1 'g1'.
Error: XtextLinkingDiagnostic: null:3 Couldn't resolve reference to JvmType 'org.xtext.example.mydsl.MyDsl2InjectorProvider'.
Only the cross reference to the type org.eclipse.emf.ecore.EObject is resolved.
What happens here ? How to load such a resource in java code ?
Thanks for any hint,
Nicolas.
|
|
|
|
Re: XtextResource loading with JvmTypes and importURI [message #885538 is a reply to message #885517] |
Wed, 13 June 2012 03:53  |
Eclipse User |
|
|
|
On 06/13/2012 08:55 AM, Christian Dietrich wrote:
> Hi first I think import URI scoping and jvm types work together. I think name space based scoping will be used anyway. Never the less the
> global scope consists of the resource set when used standalone. Maybe you will face this problem too:
> http://www.eclipse.org/forums/index.php/t/361357/
Hi,
I also tried to load first the imported model (test1.mydsl1) in the resource set, then
the model (test2.mydsl2) that imports (via importURI) the first one. In this case, the cross
references to the first model are correctly resolved. But the references to the jvmType(s)
objects are not resolved.
Nicolas.
|
|
|
Powered by
FUDForum. Page generated in 0.03706 seconds