Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 22:29 Go to next message
Christian Schulze is currently offline Christian SchulzeFriend
Messages: 8
Registered: October 2011
Junior Member

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:
  'package' name=QualifiedName ';'

  (types += Type)*

  'import' importedNamespace=QualifiedNameWithWildcard ';'

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

Let's consider the following files.

package a.b.c;

type FirstType;

package d.e.f;

type SecondType : a.b.c.FirstType;

package g.h.i;

import a.b.c.*;

type ThirdType : FirstType;

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 22:34]

Report message to a moderator

Re: Qualify EReference before switching from Local to Global Scope [message #1768559 is a reply to message #1768551] Thu, 20 July 2017 03:53 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14285
Registered: July 2009
Senior Member
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 {

	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) {

Need professional support for Xtext, Xpand, EMF?
Go to:
Twitter : @chrdietrich
Blog :
Previous Topic:reference errors
Next Topic:Derived Type in xtext for Yang
Goto Forum:

Current Time: Fri Jul 01 13:45:33 GMT 2022

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

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

Back to the top