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
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 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: 14667
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 {

	@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)
	}
	
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:reference errors
Next Topic:Derived Type in xtext for Yang
Goto Forum:
  


Current Time: Fri Apr 26 17:59:04 GMT 2024

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

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

Back to the top