Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Qualify EReference before switching from Local to Global Scope
Qualify EReference before switching from Local to Global Scope [message #1768551] Wed, 19 July 2017 18:29 Go to next message
Eclipse UserFriend
Hi,

I'm currently working on a language that does namespace-based imports like in Java (incl. a package declaration at the beginning of the file).

Example Grammar:
File:
  'package' name=QualifiedName ';'

  (types += Type)*
;

Import:
  'import' importedNamespace=QualifiedNameWithWildcard ';'
;

Type:
  'type' name=ID (':' baseTypes += [Type|QualifiedName] (',' baseTypes += [Type|QualifiedName])*)? ';'
;


Let's consider the following files.

File1.mydsl
package a.b.c;

type FirstType;


File2.mydsl
package d.e.f;

type SecondType : a.b.c.FirstType;


File3.mydsl
package g.h.i;

import a.b.c.*;

type ThirdType : FirstType;


File4.mydsl
package a.b.c;

type FourthType : FirstType; // Couldn't resolve reference to Type 'FirstType'


Files 1-3 resolve fine as all EReferences are fully qualified when the resolution is attempted but File 4 fails. I guess it's because it uses the simple name to scan the index in the Global Scope. If so - how can I override the EReference's qualified name if it's not qualified?

If that's not the reason - what am I doing wrong?

Best regards and many thanks in advance for your help

[Updated on: Wed, 19 July 2017 18:34] by Moderator

Re: Qualify EReference before switching from Local to Global Scope [message #1768559 is a reply to message #1768551] Wed, 19 July 2017 23:53 Go to previous message
Eclipse UserFriend
looks like you missed the implicit import for the package

package org.xtext.example.mydsl.scoping;

import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.scoping.impl.ImportNormalizer;
import org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider;
import org.xtext.example.mydsl.myDsl.File;

public class MyDslImportedNamespaceAwareLocalScopeProvider extends ImportedNamespaceAwareLocalScopeProvider {

	@Override
	protected List<ImportNormalizer> getImportedNamespaceResolvers(EObject context, boolean ignoreCase) {
		 List<ImportNormalizer> importedNamespaceResolvers = super.getImportedNamespaceResolvers(context, ignoreCase);
		 if (context instanceof File) {
			 importedNamespaceResolvers.add(doCreateImportNormalizer(getQualifiedNameConverter().toQualifiedName(((File) context).getName()), true, ignoreCase));
		 }
		 return importedNamespaceResolvers;
	}
	
}
class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {
	
	override void configureIScopeProviderDelegate(Binder binder) {
		binder.bind(IScopeProvider).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(
			MyDslImportedNamespaceAwareLocalScopeProvider)
	}
	
}
Previous Topic:reference errors
Next Topic:Derived Type in xtext for Yang
Goto Forum:
  


Current Time: Fri Jul 04 22:33:27 EDT 2025

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

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

Back to the top