Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » ScopeProvider with imported Xcore
ScopeProvider with imported Xcore [message #1385584] Mon, 09 June 2014 17:56 Go to next message
Florian König is currently offline Florian KönigFriend
Messages: 30
Registered: June 2014
Member
Hi,

I need some help with a Xtext ScopeProvider for my DSL.
My goal is to create a cross reference to a Xcore file.


My example DSL looks like this:

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http ://www.xtext.org/example/mydsl/MyDsl"

import "http ://www.eclipse.org/emf/2011/Xcore" as xcore

Model:
	imports+=Import+
	selection=Selection;

Import:
	'import' importURI=STRING;

Selection:
	'selection' name=ID '{'
		selected=Select
	'}';

Select:
	'select' class=[xcore::XClass] name=ID;


With a simple Xcore file like:

package org.test

class RailCab {
	op void endOfTrackSectionReached()
}


I want do do something like this:

import "test.xcore"

selection test
{
	select RailCab rc
}


But I don't know how to get into the Xcore file in my ScopeProvider.
Can anyone help me with that?

Thanks for any suggestions,
Florian
Re: ScopeProvider with imported Xcore [message #1385613 is a reply to message #1385584] Tue, 10 June 2014 04:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13469
Registered: July 2009
Senior Member
Hmm afaik xcore only indexes EClasses. (Check this with the open
model element dialog) so you may change the grammar to

Xxx=[score::EClass] or change xcores resource service provider (
debug xvoreresourcedescriptionstrategy,)


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: ScopeProvider with imported Xcore [message #1385614 is a reply to message #1385613] Tue, 10 June 2014 04:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13469
Registered: July 2009
Senior Member
Sorry should read [ecore:: EClass|FQN]

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: ScopeProvider with imported Xcore [message #1385627 is a reply to message #1385613] Tue, 10 June 2014 07:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31161
Registered: July 2009
Senior Member
Christian,

The things in the GenModel are also indexed, so generally one should try
to reference the Gen* things (and then it will be possible to reference
a model regardless of whether it's in *.xcore or *.genmodel). Also,
with that approach, you could use qualified names to reference things,
without direct reference to a particular *.xcore or *.genmodel...

On 10/06/2014 6:09 AM, Christian Dietrich wrote:
> Hmm afaik xcore only indexes EClasses. (Check this with the open model
> element dialog) so you may change the grammar to
> Xxx=[score::EClass] or change xcores resource service provider (
> debug xvoreresourcedescriptionstrategy,)
Re: ScopeProvider with imported Xcore [message #1385711 is a reply to message #1385613] Tue, 10 June 2014 15:56 Go to previous messageGo to next message
Florian König is currently offline Florian KönigFriend
Messages: 30
Registered: June 2014
Member
Hi Christian,

Thanks for your suggestion! I tried that and changed some things, like this:

import "http ://www.eclipse.org/emf/2002/Ecore" as ecore

Import: 'import' importedNamespace=FqnWithWildCard;
FqnWithWildCard: Fqn('.*')?;
Fqn:ID('.'ID)*;

Select: 'select' class=[ecore::EClass | Fqn] name=ID;


This works, now I can select the classes I created in Xcore Smile
Like this:
selection test
{
	select org.test.RailCab
}


But I got two new Problems:


  1. I get a lot of items I can put in there (and my Xcore classes even without an import), but I only want to have those I imported earlier in my import section. How can I do that?
    index.php/fa/18244/0/
  2. When I select my RailCab class like the example above, I get this error: Quote:
    Couldn't resolve reference to EClass 'org.test.RailCab'.



How can I fix these?

@Ed: Thanks to you too, but I don't really know how I can do that... Could you be a bit more specific?
Re: ScopeProvider with imported Xcore [message #1385714 is a reply to message #1385711] Tue, 10 June 2014 16:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13469
Registered: July 2009
Senior Member
Change back the grammar to xxx=[XXX|ID]

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: ScopeProvider with imported Xcore [message #1385761 is a reply to message #1385711] Wed, 11 June 2014 05:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31161
Registered: July 2009
Senior Member
Florian,

Comments below.

On 10/06/2014 5:56 PM, Florian König wrote:
> Hi Christian,
>
> Thanks for your suggestion! I tried that and changed some things, like this:
>
> import "http ://www.eclipse.org/emf/2002/Ecore" as ecore
>
> Import: 'import' importedNamespace=FqnWithWildCard;
> FqnWithWildCard: Fqn('.*')?;
> Fqn:ID('.'ID)*;
>
> Select: 'select' class=[ecore::EClass | Fqn] name=ID;
>
> This works, now I can select the classes I created in Xcore :)
> Like this:
> selection test
> {
> select org.test.RailCab
> }
>
> But I got two new Problems:
>
>
> I get a lot of items I can put in there (and my Xcore classes even without an import), but I only want to have those I imported earlier in my import section. How can I do that?
>
> When I select my RailCab class like the example above, I get this error: Quote:
>> Couldn't resolve reference to EClass 'org.test.RailCab'.
>
>
> How can I fix these?
>
> @Ed: Thanks to you too, but I don't really know how I can do that... Could you be a bit more specific?
I can only suggest you look at the Xcore grammar. I don't really know
your ultimate intent, but something to keep in mind. Xext grammar
language uses Ecore directly and relies on imports that specify the
nsURI of the Ecore model and then further relies on the index to index
all the *.ecore models, including *.xcore representations. But Ecore
models don't know about a fully qualified name just the name of the
package and the name of the classifiers (and structural features/enum
literals). So I'd not expect that approach to let you specify names
like org.test.RailCab. Xcore relies on indexing of all *.genmodel,
including *.xcore representations, and a GenClassifier knows about fully
qualified names in the sense of the generated Java code. So if you rely
on Xcore, you likely want your reference to be to a GenClassifier (or
perhaps more restrictively to be a GenClass). So try that instead of
EClass in your grammar.
Re: ScopeProvider with imported Xcore [message #1385792 is a reply to message #1385761] Wed, 11 June 2014 08:53 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 672
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Just a comment on using qualified names for EClasses. Doesn't the
standard QualifiedNameProvider create qualified names from the name
features of ENamedElements up to the root. Hence, most elements in an
Ecore model will get the qualified name you'd expect.

Hallvard

On 11.06.14 07:56, Ed Merks wrote:
> But Ecore
> models don't know about a fully qualified name just the name of the
> package and the name of the classifiers (and structural features/enum
> literals). So I'd not expect that approach to let you specify names
> like org.test.RailCab. Xcore relies on indexing of all *.genmodel,
> including *.xcore representations, and a GenClassifier knows about fully
> qualified names in the sense of the generated Java code. So if you rely
> on Xcore, you likely want your reference to be to a GenClassifier (or
> perhaps more restrictively to be a GenClass). So try that instead of
> EClass in your grammar.
>
Re: ScopeProvider with imported Xcore [message #1385796 is a reply to message #1385792] Wed, 11 June 2014 09:19 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31161
Registered: July 2009
Senior Member
Hallvard,

That would be the work of
org.eclipse.xtext.ecore.EcoreQualifiedNameProvider. I know that
org.eclipse.emf.codegen.ecore.xtext.GenModelQualifiedNameProvider does a
good job giving the actual name you'll see when you generate the code,
but for Ecore, you can only get up to the EPackage and that's not
generally a qualified name. I suppose, if you included parent packages
all the way up to "org" it would give a qualified name, but otherwise,
it's not ideal. And besides, if the focus on on referencing Xcore, then
there is a GenModel and the information is definitely well supported for
that (and would also work for a normal *.genmodel)...


On 11/06/2014 10:53 AM, Hallvard Trætteberg wrote:
> Just a comment on using qualified names for EClasses. Doesn't the
> standard QualifiedNameProvider create qualified names from the name
> features of ENamedElements up to the root. Hence, most elements in an
> Ecore model will get the qualified name you'd expect.
>
> Hallvard
>
> On 11.06.14 07:56, Ed Merks wrote:
>> But Ecore
>> models don't know about a fully qualified name just the name of the
>> package and the name of the classifiers (and structural features/enum
>> literals). So I'd not expect that approach to let you specify names
>> like org.test.RailCab. Xcore relies on indexing of all *.genmodel,
>> including *.xcore representations, and a GenClassifier knows about fully
>> qualified names in the sense of the generated Java code. So if you rely
>> on Xcore, you likely want your reference to be to a GenClassifier (or
>> perhaps more restrictively to be a GenClass). So try that instead of
>> EClass in your grammar.
>>
>
Re: ScopeProvider with imported Xcore [message #1385845 is a reply to message #1385761] Wed, 11 June 2014 15:39 Go to previous message
Florian König is currently offline Florian KönigFriend
Messages: 30
Registered: June 2014
Member
Hi Ed,

Thank you very much! I would have been searching for this forever..
Now I changed some things, like this:

import "http://www.eclipse.org/emf/2002/GenModel" as genmodel 

Select: 'select' class=[genmodel::GenClass] name=ID;


This seems to work perfectly fine Smile

@Christian: Unfortunately changing it like xxx=[XXX|ID] did not work.
Previous Topic:Antlr update breaks workflow
Next Topic:proper way to enrich model
Goto Forum:
  


Current Time: Thu Jun 04 21:55:12 GMT 2020

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

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

Back to the top