Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Restricting scope to variables in the current file + keep a crossfile scope for another type
Restricting scope to variables in the current file + keep a crossfile scope for another type [message #1810472] Mon, 12 August 2019 14:09 Go to next message
Martin BREUNEVAL is currently offline Martin BREUNEVALFriend
Messages: 17
Registered: July 2019
Junior Member
Hello,

So here's my grammar :

{VariableStatement} ('data') name=Variable ('TYPE') ('PACKAGE') varPack=package 

                      |	{VariableStatement}	('data') name=PackageVariable ('TYPE')  (ServicePackage)? 


Now i have lots of cross reference to this in multiple case whether it's used as a data:
SingleData:
		{SingleData} number
		|=>VariableArray
		| var=[VariableStatement]


or in statements :
ForeachStatement:  ('FOREACH') (packVar=[VariableStatement] ('INTO') var=VariableName
                          Statements
                          ('ENDFOR') ;



So far, the problem is that it references to all the variable of the project and i would like to have it restricted to only the variables declared in the current file.

I've tried multiple way like overriding the getScope but the problem is that it prevents my other typeof having a scope across files which i need.

I've also tried defining this kind of method :
	def IScope scope_VariableName(Model ctx,EReference r){
		val root = EcoreUtil2.getContainerOfType(ctx, Model)
		val allContentsCurrFile  = EcoreUtil2.getAllContentsOfType(root,VariableStatement)	
	return	 Scopes.scopeFor(allContentsCurrFile)
	}

but there are no changes to my issue which means variable will be validated even if they're declared in other files. And all variables of the project are in the content assist while i'd just like to have the local ones.

Does someone know how can i correct this issue?
Re: Restricting scope to variables in the current file + keep a crossfile scope for another type [message #1810558 is a reply to message #1810472] Tue, 13 August 2019 13:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13124
Registered: July 2009
Senior Member
Hi,

scope_*(_*) works only if you inherit from AbstractDeclarativeScopeProvider
otherwise you have to override getScope(EObject, EReference)
and if-else on context / Ereference (contants in MyDslPackage.Literals.....)


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Restricting scope to variables in the current file + keep a crossfile scope for another type [message #1810561 is a reply to message #1810558] Tue, 13 August 2019 13:42 Go to previous messageGo to next message
Martin BREUNEVAL is currently offline Martin BREUNEVALFriend
Messages: 17
Registered: July 2019
Junior Member
I do inherit from AbstractDeclarativeScopeProvider currently since i use this"scope_*(_*)" for other rules. But do you think i can use this form to for this problem? Because i tried many forms and there weren't any effects.

I've come up to this while trying with the getScope:

	override getScope(EObject context, EReference reference) {

		if (reference == EditorPackage.Literals.VARIABLE_STATEMENT__NAME) {
			return IScope.NULLSCOPE
		} else {
			return super.getScope(context, reference);
		}

	}


But i still have all the variables of the projects, am i going the right way?
Re: Restricting scope to variables in the current file + keep a crossfile scope for another type [message #1810564 is a reply to message #1810561] Tue, 13 August 2019 13:45 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13124
Registered: July 2009
Senior Member
please use a debugger

EditorPackage.Literals.VARIABLE_STATEMENT__NAME

is suspicious.

should be ForeachStatement_packVar or SingleData_var



Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Web editor code generation
Next Topic:Mwe2Launcher - Cannot create a resource with ANT
Goto Forum:
  


Current Time: Mon Sep 23 10:59:29 GMT 2019

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

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

Back to the top