Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XText 2.9 Generated Scope Provider Class
XText 2.9 Generated Scope Provider Class [message #1727716] Fri, 25 March 2016 16:19 Go to next message
Jack Burns is currently offline Jack BurnsFriend
Messages: 4
Registered: March 2016
Junior Member
Hello everyone,

I'd like to know how the default generated scoping provider class is supposed to be used. Earlier versions of XText used AbstractDeclarativeScopeProvider and that was quite easy to understand and use.

Let's say I have the following grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.eclipse.org/example/mydsl/MyDsl"

Model:
	((things+=Thing) | (refs+=Reference))*
;
	
Thing:
	'thing' name=ID '{'
		stuff += Stuff* 
	'}'
;

Stuff:
	'stuff' name=ID
;

Reference:
	'reference' thing=[Thing] stuff=[Stuff] 
;


For the Reference clause to work, I need a scope provider.

XText 2.9 generates the following scope provider code for you (in MyDslScopeProvider.xtend):

class MyDslScopeProvider extends AbstractMyDslScopeProvider {
}


AbstractMyDslScopeProvider has no methods of it's own, it just inherits from DelegatingScopeProvider.

I can't wrap my head around how this works or where the code for the scope lookup should go. The "documentation" doesn't really help, because there's only useless code snippets instead of a complete working example.


Pre 2.9 it would have been:
class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
    def IScope scope_Reference_stuff(Reference reference, EReference ref) {
        scopeFor(reference.thing.stuff)
    }
}


Can someone please enlighten me on how the new scope provider mechanism is supposed to be used?
Re: XText 2.9 Generated Scope Provider Class [message #1727897 is a reply to message #1727716] Tue, 29 March 2016 07:16 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
"Simple" is always in the eye of the beholder Smile In the past we have experienced a lot of confusion with the declarative API, that's why we changed it to something we consider more straight forward, i.e. you have to implement the dispatching yourself.

The new way to implement custom scoping would be like

import static org.xtext.example.mydsl.myDsl.MyDslPackage.Literals.*

class MyDslScopeProvider extends AbstractMyDslScopeProvider {

	override getScope(EObject context, EReference reference) {
		switch reference {
			case MY_CLASS__MY_REF:
				return // create the scope as you did with the old API and return  
			case MY_CLASS2__MY_REF2:
				return // create the scope as you did with the old API and return  
			...
		}
		super.getScope(context, reference)
	}
}



---
Get professional support from the Xtext committers at www.typefox.io
Re: XText 2.9 Generated Scope Provider Class [message #1728088 is a reply to message #1727897] Wed, 30 March 2016 23:21 Go to previous messageGo to next message
Jack Burns is currently offline Jack BurnsFriend
Messages: 4
Registered: March 2016
Junior Member
Thank you very much for your answer.

Could you perhaps explain the idea behind the generated AbstractMyDslScopeProvider class? It has no methods of its own, it's just derived from DelegateScopeProvider. If the idea behind the new concept is "override getScope yourself", couldn't MyDslScopeProvider extend from DelegateScopeProvider directly?
Re: XText 2.9 Generated Scope Provider Class [message #1728145 is a reply to message #1728088] Thu, 31 March 2016 11:15 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
Hi Jack,
AFAIK, they just use the AbstractXxx way to separate generated Code from customised code and have a place to add fragments etc.
Re: XText 2.9 Generated Scope Provider Class [message #1728147 is a reply to message #1728145] Thu, 31 March 2016 11:17 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
By this xtext can change the super (grandparent) class even if MyDslScopeProvider is generated only once

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:XMIException when binding two languages
Next Topic:Formatter2: No GenPackage for NsURI http://www.eclipse.org/emf/2002/Ecore
Goto Forum:
  


Current Time: Tue Apr 23 06:37:34 GMT 2024

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

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

Back to the top