Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Registering both relative and fully qualified name in Scope
Registering both relative and fully qualified name in Scope [message #1785684] Wed, 18 April 2018 11:05 Go to next message
Erwann Traisnel is currently offline Erwann TraisnelFriend
Messages: 14
Registered: June 2017
Junior Member
Hello ,

I am facing an issue with my scoping right now ,
Given 2 files

file1.myDSL
module myModule{
    typedef long myLong;
}


file2.myDSL
#include "file1.myDSL"

module myModule{
    typedef myLong myLong2;  //Not Working but should work
    typedef myModule.myLong myLong3; //Working
}


I would like to be able to reference an object from an imported file, both with its RelativeQualifiedName and FullyQualifiedName .

My idea was , given a context (here , typedef myLong myLong2)
if its container's full qualified name(FQN) is present in the scope,
then each element of the scope registered with a name starting with that fqn shall also be registered with their relative qname(container's FQN - object FQN)

Any tips on how to solve that ?

Erwann

Re: Registering both relative and fully qualified name in Scope [message #1785687 is a reply to message #1785684] Wed, 18 April 2018 11:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
how did you implement the includes?

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Registering both relative and fully qualified name in Scope [message #1785688 is a reply to message #1785687] Wed, 18 April 2018 11:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
or do you use it all all?

you might need to customize the scope provider delegate

so that what the following method does:
org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.getLocalElementsScope(IScope, EObject, EReference)

is done for the global scope too.


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Registering both relative and fully qualified name in Scope [message #1785689 is a reply to message #1785684] Wed, 18 April 2018 11:37 Go to previous messageGo to next message
Erwann Traisnel is currently offline Erwann TraisnelFriend
Messages: 14
Registered: June 2017
Junior Member
The includes use importURI

They are correctly resolved and when the scope is built, objects from the import are in a ImportScope , described with their FQN.


However I didn't completely understand you answer ,
Do you mean I would have to call
org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.getLocalElementsScope(IScope, EObject, EReference)

with IScope, the GlobalScope ?
Re: Registering both relative and fully qualified name in Scope [message #1785690 is a reply to message #1785689] Wed, 18 April 2018 11:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
no the idea is that you wrap your scope into a import scope with an import "myModule.*"

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Registering both relative and fully qualified name in Scope [message #1785742 is a reply to message #1785684] Thu, 19 April 2018 09:07 Go to previous message
Erwann Traisnel is currently offline Erwann TraisnelFriend
Messages: 14
Registered: June 2017
Junior Member
That worked , thanks a lot Christian !
Here I share the snippet of code, just in case someone looks for the same answer :

if(scope instanceof ImportScope){
			Module module = EcoreUtil2.getContainerOfType(context, Module.class);
			//Module is the qualifying element 
			if(module != null){
				QualifiedName qname = qualifiedNameProvider.getFullyQualifiedName(module);				
				if(qname != null){
					ImportNormalizer importNormalizer = new ImportNormalizer(qname, true, true);
					scope = new ImportScope(Collections.singletonList(importNormalizer), scope, null, reference.eClass(), false);
				}
			}
		}	
 }	


Thanks for your help !

Erwann
Previous Topic:Hover on Keyword and Token
Next Topic:Writing unit tests for a DSL that is referencing a DSL
Goto Forum:
  


Current Time: Sat Sep 22 00:22:08 GMT 2018

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

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

Back to the top