Skip to main content



      Home
Home » Modeling » TMF (Xtext) » importURI of ecore-only based model
importURI of ecore-only based model [message #1080984] Tue, 06 August 2013 12:43 Go to next message
Eclipse UserFriend
Hi,

I'm trying to get importURI working with another ecore model so that I can "reference elements of one ecore model from another dsl". Regarding this blog post ("reference elements of one dsl from another dsl") it seems to be be straigt forward.

My xtext grammer looks like this:

grammar company.mydsl.dsl.MyDSL with org.eclipse.xtext.common.Terminals

generate myDSL "http://www.company/mydsl/dsl/MyDSL"

import "http://www.company.com/model/mymodel.ecore" as mdl

Model:
   uses+=Usage* refs+=Reference*
;

Usage:
   "use" importURI=STRING ";"
;

Reference:
   "ref" extref=[mdl::Item|STRING] ";"
;


I think I also made all the necessary changes in the MWE2 workflow:

// ...

bean = StandaloneSetup {
    // ...
    
    // added this:
    registerEcoreFile = "platform:/resource/company/model/mymodel.ecore"
    registerGenModelFile = "platform:/resource/company/model/mymodel.genmodel"
}

// ...

// added:
// old scoping and exporting API
fragment = scoping.ImportURIScopingFragment auto-inject {}
fragment = exporting.SimpleNamesFragment auto-inject {}

// commented out:
// scoping and exporting API
//fragment = scoping.ImportNamespacesScopingFragment auto-inject {}
//fragment = exporting.QualifiedNamesFragment auto-inject {}
//fragment = builder.BuilderIntegrationFragment auto-inject {}

// ...


This is what I would like to achieve (let's say the file extension for my grammer is .mydsl and for my ecore-only based model .mymdl):

use "somemodelfile.mymdl";

ref "Name of the Item";


Unfortunately, this doesn't work. The editor complains "Couldn't resolve reference to Item 'Name of the Item'" even though the file "somemodelfile.mymdl" contains an element of type "Item" with the name "Name of the Item".

The import-mechanism itself does work (I tested this with a slightly changed grammer and importing a .mydsl instead of .mymdl file, which does work).

Altogether I can think of two reasons for my problem:

1. The .mymdl file is not loaded correctly.
2. The .mymdl file is loaded correctly, but the string "Name of the Item" is not sufficient to identify the actual Item (btw: i also tried using [mdl::Item|ID] instead of [mdl::Item|STRING]).

But now I'm rather lost. Actually, I would expect the 2nd case. I first thought that I have to implement custom Scope Providers, but the blog post above suggests that required mechanisms should be already available...

Any help would be appreciated... Smile

[Updated on: Tue, 06 August 2013 12:50] by Moderator

Re: importURI of ecore-only based model [message #1080990 is a reply to message #1080984] Tue, 06 August 2013 12:53 Go to previous messageGo to next message
Eclipse UserFriend
HI,

can you share the other grammar as well?
Re: importURI of ecore-only based model [message #1081010 is a reply to message #1080990] Tue, 06 August 2013 13:28 Go to previous messageGo to next message
Eclipse UserFriend
P.S: if the other model is not xtext based you have to write a resourceservice provider
http://christiandietrich.wordpress.com/2011/07/17/xtext-2-0-and-uml/
Re: importURI of ecore-only based model [message #1081569 is a reply to message #1080990] Wed, 07 August 2013 07:54 Go to previous messageGo to next message
Eclipse UserFriend
Christian Dietrich wrote on Tue, 06 August 2013 12:53
HI,

can you share the other grammar as well?


There is no other grammer, but I think you figured that out already Smile

If my post above was not clear: The other model is not xtext-based. I want to provide the possibility to reference elements of a plain ecore-based model in my custom language. This is different to the blog post I linked above, but I had hoped that it would be as simple to achieve.

Christian Dietrich wrote on Tue, 06 August 2013 13:28
P.S: if the other model is not xtext based you have to write a resourceservice provider
http://christiandietrich.wordpress.com/2011/07/17/xtext-2-0-and-uml/


This sounds like the correct answer. Thanks!
Re: importURI of ecore-only based model [message #1081722 is a reply to message #1081569] Wed, 07 August 2013 11:53 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian,

your blog post helped me a lot! But there are some things that are not covered in your post or comments there. Since my use-case is a bit different (not UML-related) I decided to ask here:

The way you provided the resourceServiceProvider for a custom model (.uml in your case) searches for any *.uml file in the project (or even workspace?) and adds any elements to the index of xtext (so that they can be referenced). This is ok to demonstrate that it is possible to reference other model items from a custom xtext language, but I think in reality you rather would like to "include" only certain files that have been selected explicitly by the user. I think the overriden "DefaultResourceDescriptionStrategy" is the right point to start, but for now I don't know how I could connect it with some statement in my custom language (e.g. "use" or "import"). "importURI" could be somehow useful, but I fear that I'm too new to xtext to find it out on my own Sad Do you have any examples / hints how to achieve this?

Another thing that took me some time to figure out was, that the resourceServiceProvider plugin is only started, if a new file for the custom language is *created*. I already had a .mydsl-file (.umlmodel in your case) in the workspace of my Eclipse runtime instance. Apparently the plugin wasn't called and existing .mymdl (.uml) files were ignored, scoping was not working. Only after creating a *new* .mydsl-file all .mymdl files were parsed and scoping in the xtext-editor suddenly worked. But when closing the Eclipse instance and restarting, references cannot be resolved again (I first have to create another .mydsl file), and so on. Any idea what's going wrong here?

Best regards,
Till
Re: importURI of ecore-only based model [message #1081740 is a reply to message #1081722] Wed, 07 August 2013 12:24 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

the import uri mechanism works on top of the resourceservice provider.
the files are indexed if the project has xtext nature (right click on project, configure, add xtext nature)

~Christian
Re: importURI of ecore-only based model [message #1082366 is a reply to message #1081740] Thu, 08 August 2013 09:19 Go to previous messageGo to next message
Eclipse UserFriend
Christian Dietrich wrote on Wed, 07 August 2013 12:24
Hi,

the import uri mechanism works on top of the resourceservice provider.
the files are indexed if the project has xtext nature (right click on project, configure, add xtext nature)

~Christian


Hi Christian,

thanks for your answer, but I meant something different... I think my question was confusing Smile

Xtext nature was already added and files are indexed correctly. What I want to achieve is that only those files are indexed that are imported explicitely (e.g. using importURI). Reason for this: I want to have something similar to the "import" statement of java for other packages. Anything the user wants to reference, must be brought into scope explicitely first.

The second problem is less important. Just let me describe the behavior I see after following your UML-example (altough "UML" is substituted by my own meta-model):

1. I start an Eclipse runtime for the DSL
2. I add a .model file (the equivalent to .uml)
3. I add a .dsl file
4. The .model file is indexed
5. Scoping of elements within .model does work; referenes are resolved
6. I save the .dsl file: one error per reference occurs: "Couldn't resolve reference to Item 'MyItem'", but in the same seconds the error markers in the xtext editor disappear (are replaced by that gray symbol for former errors).
7. If I close and reopen the .dsl file, corresponding lines are again marked with an error which go away as soon as I save the .dsl file.

[Updated on: Thu, 08 August 2013 09:22] by Moderator

Re: importURI of ecore-only based model [message #1082399 is a reply to message #1082366] Thu, 08 August 2013 10:18 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

i still do not understand your point.
if you use import uri based scoping you can only see stuff from resources that are imported.
(make sure you did remove xbase and typesgenerated fragment from the workflow as well)
Re: importURI of ecore-only based model [message #1082434 is a reply to message #1082399] Thu, 08 August 2013 11:05 Go to previous messageGo to next message
Eclipse UserFriend
Christian Dietrich wrote on Thu, 08 August 2013 10:18
(
make sure you did remove [...] typesgenerated fragment from the workflow as well)


Yeah! types.TypesGeneratorFragment was in my workflow. Don't know how I could have found out that by myself... Even now I have to admit that I don't really understand how this fragment could cause the strange behaviour I've seen.

But everything works now; both "problems" are solved. Now xtext only adds those resources to the index that are actually added using importURI

(But what the heck was indexed before - with the TypesGeneratorFragment? the generated java sources? And why was this dependent on the custom ResourceService provider? Because without it nothing was indexed...)

The other problem with the strange error markers etc. went away in the same moment.

Thanks a lot! I think you saved me horrible ours of seraching the totally wrong direction...
Re: importURI of ecore-only based model [message #1082445 is a reply to message #1082434] Thu, 08 August 2013 11:18 Go to previous message
Eclipse UserFriend
Hi,

the typesgenerator partially reenables global visibility.
it is for importing real java types, for that you would rather use name based imports than uri based imports.
Previous Topic:Implicit parameters
Next Topic:How to import an XSD into an Xtext model file
Goto Forum:
  


Current Time: Fri Nov 07 17:19:14 EST 2025

Powered by FUDForum. Page generated in 0.07216 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top