Skip to main content



      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 07:05 Go to next message
Eclipse UserFriend
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 07:22 Go to previous messageGo to next message
Eclipse UserFriend
how did you implement the includes?
Re: Registering both relative and fully qualified name in Scope [message #1785688 is a reply to message #1785687] Wed, 18 April 2018 07:26 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: Registering both relative and fully qualified name in Scope [message #1785689 is a reply to message #1785684] Wed, 18 April 2018 07:37 Go to previous messageGo to next message
Eclipse UserFriend
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 07:55 Go to previous messageGo to next message
Eclipse UserFriend
no the idea is that you wrap your scope into a import scope with an import "myModule.*"
Re: Registering both relative and fully qualified name in Scope [message #1785742 is a reply to message #1785684] Thu, 19 April 2018 05:07 Go to previous message
Eclipse UserFriend
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: Sun Jun 22 08:54:22 EDT 2025

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

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

Back to the top