Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using ImportURIScopingFragment instead of ImportNamespacesScopingFragment with the new MWE2
Using ImportURIScopingFragment instead of ImportNamespacesScopingFragment with the new MWE2 [message #1736350] Tue, 28 June 2016 17:20 Go to next message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
Hello,

I would like to restrict the visibility of model elements to those that are explicitly imported in my model.

To that end I found following links that explain how to do it:
http://www.cs.kun.nl/J.Hooman/DSL/AdvancedXtextManual.pdf
http://stackoverflow.com/questions/17034734/xtext-importuri-external-file

Unfortunately, they rely on the old way to configure Xtext using mwe2.
The problem is that using the new way (https://eclipse.org/Xtext/documentation/302_configuration.html#generator) I do find the fragment "ImportURIScopingFragment" or "ImportURIScopingFragment2".

Does anyone know how to configure the ImportURIScopingFragment using the new method?

Based on https://www.eclipse.org/forums/index.php/m/1728366/?srch=ImportURIScopingFragment#msg_1728366 and https://bugs.eclipse.org/bugs/show_bug.cgi?id=491110
I do understand that is it not the recommended way anymore.

Is there a way to limit the visibility of the references to the "imported" ones with name based scoping?

Many Thanks in advance for your help.

[Updated on: Tue, 28 June 2016 17:31]

Report message to a moderator

Re: Using ImportURIScopingFragment instead of ImportNamespacesScopingFragment with the new MWE2 [message #1736351 is a reply to message #1736350] Tue, 28 June 2016 17:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13768
Registered: July 2009
Senior Member
the use of import uri scoping is kind a discouraged. thus there is no new fragment supporting it.
what about leaving the workflow as it is and add the bindings to the module ?

// contributed by org.eclipse.xtext.generator.scoping.AbstractScopingFragment
	public void configureIScopeProviderDelegate(com.google.inject.Binder binder) {
		binder.bind(org.eclipse.xtext.scoping.IScopeProvider.class).annotatedWith(com.google.inject.name.Names.named(org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(org.eclipse.xtext.scoping.impl.SimpleLocalScopeProvider.class);
	}

	// contributed by org.eclipse.xtext.generator.scoping.AbstractScopingFragment
	public Class<? extends org.eclipse.xtext.scoping.IGlobalScopeProvider> bindIGlobalScopeProvider() {
		return org.eclipse.xtext.scoping.impl.ImportUriGlobalScopeProvider.class;
	}

// contributed by org.eclipse.xtext.generator.exporting.SimpleNamesFragment
	public Class<? extends org.eclipse.xtext.naming.IQualifiedNameProvider> bindIQualifiedNameProvider() {
		return org.eclipse.xtext.naming.SimpleNameProvider.class;
	}


what you do else depends on your rules and how the imports look like.

in a simple case you could adapt iQualifiedNAmeProvider to
give your elements the name

filename.extension.simplename (by looking at the eObjects eResources URI)

and for a import

import "filename.extension"

you create a actual name import filename.extension.*
e.g.
inside org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.getImportedNamespace(EObject)


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using ImportURIScopingFragment instead of ImportNamespacesScopingFragment with the new MWE2 [message #1736352 is a reply to message #1736351] Tue, 28 June 2016 18:13 Go to previous messageGo to next message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
Hello Christian,

thanks a lot for your help.
I made the proposed changes and it works ... almost.

The restriction to the imported files works but now the local name resolution does not work anymore.

Using
	override bindIGlobalScopeProvider() {
		ImportUriGlobalScopeProvider
	}

	override configureIScopeProviderDelegate(Binder binder) {
		binder.bind(IScopeProvider).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(
			SimpleLocalScopeProvider);
	}

	override bindIQualifiedNameProvider() {
		SimpleNameProvider
	}


I cannot use FQN "DSL.Position100.currency" in the model and I must use currency instead

import "DSL-1.0.0.dsl"

variables {
	DSL.Position100.currency as fact
}

rule RULE_ID {
       fact + fact
 }



but using

	override bindIGlobalScopeProvider() {
		ImportUriGlobalScopeProvider
	}

	override configureIScopeProviderDelegate(Binder binder) {
		binder.bind(IScopeProvider).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(
			SimpleLocalScopeProvider);
	}

	override bindIQualifiedNameProvider() {
		DefaultDeclarativeQualifiedNameProvider
	}


The local resolution does not work anymore: "fact" is not recognize while "DSL.Position100.currency as fact" is ok.
import "DSL-1.0.0.dsl"

variables {
	DSL.Position100.currency as fact
}

rule RULE_ID {
       fact + fact
 }


Any clue on the subject
Thanks in advance for your help
Re: Using ImportURIScopingFragment instead of ImportNamespacesScopingFragment with the new MWE2 [message #1736353 is a reply to message #1736352] Tue, 28 June 2016 18:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13768
Registered: July 2009
Senior Member
that is a combination that ususally is not used.
import uri means simple names usually

what happens if you remove configureIScopeProviderDelegate?


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 28 June 2016 18:18]

Report message to a moderator

Re: Using ImportURIScopingFragment instead of ImportNamespacesScopingFragment with the new MWE2 [message #1736384 is a reply to message #1736353] Wed, 29 June 2016 05:48 Go to previous messageGo to next message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
Hello Christian,


it does work as expected but... I honestly do not understand why?
Would you mind explaining it to me?

Another question on the same subject :
My basic use case is the following:
I want to have modularity and therefore are a global model that is the union of the other models in the workspace that I have explicitly imported/declared. If using URI is no more the recommended approach for that as mentioned by Sven in https://bugs.eclipse.org/bugs/show_bug.cgi?id=491110, what is the recommended way to do it?

Many thanks in advance for your help and you guys rock
Re: Using ImportURIScopingFragment instead of ImportNamespacesScopingFragment with the new MWE2 [message #1736385 is a reply to message #1736384] Wed, 29 June 2016 05:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13768
Registered: July 2009
Senior Member
override configureIScopeProviderDelegate(Binder binder) {
binder.bind(IScopeProvider).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(
SimpleLocalScopeProvider);
}

overrides

public void configureIScopeProviderDelegate(Binder binder) {
binder.bind(IScopeProvider.class).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(ImportedNamespaceAwareLocalScopeProvider.class);
}


ImportedNamespaceAwareLocalScopeProvider can do the local relative name import magic.
SimpleLocalScopeProvider cant.

for 2 i cannot follow you. the old fragments are inside org.eclipse.xtext.generator plugin. (the old generator)
maybe your manifest contains org.eclipse.xtext.xtext.generator only (the new generator)
=> add the old one as well


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using ImportURIScopingFragment instead of ImportNamespacesScopingFragment with the new MWE2 [message #1736388 is a reply to message #1736385] Wed, 29 June 2016 06:18 Go to previous messageGo to next message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
Thanks for the explanation about the configureIScopeProviderDelegate.

Concerning the second point, my question was not about MWE but about the new strategy. In the referenced bug ticket, Sven mentioned that
Quote:

We changed the API of the generator. ImportURI mechanism is discouraged (name based scoping being the better alternative) so we haven't reimplemented it for the new generator infrastructure.

However for backward compatibility we have the FragmentAdapter, so you can write

fragment = org.eclipse.xtext.generator.adapter.FragmentAdapter {
fragment = org.eclipse.xtext.generator.scoping.ImportURIScopingFragment {}
}


So if the "ImportURI mechanism" is discouraged what should we use instead to limit the visibility to a subset of the files in the workspace.
Re: Using ImportURIScopingFragment instead of ImportNamespacesScopingFragment with the new MWE2 [message #1736389 is a reply to message #1736388] Wed, 29 June 2016 06:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13768
Registered: July 2009
Senior Member
this i answered already here https://www.eclipse.org/forums/index.php?t=msg&th=1078818&goto=1736351&#msg_1736351

(adapting nameprovider and ImportedNamespaceAwareLocalScopeProvider)

and by default only stuff from the same project and ref. projects are visible


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using ImportURIScopingFragment instead of ImportNamespacesScopingFragment with the new MWE2 [message #1736616 is a reply to message #1736389] Thu, 30 June 2016 15:04 Go to previous message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
Thanks a lot for your help
Previous Topic:Obtainign the classpath from a XtextResource
Next Topic:Suppress or Override Quickfix for Unresolved Definition
Goto Forum:
  


Current Time: Thu Mar 04 19:57:09 GMT 2021

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

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

Back to the top