Skip to main content



      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 10:09 Go to next message
Eclipse UserFriend
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 09:20 Go to previous messageGo to next message
Eclipse UserFriend
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.....)
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 09:42 Go to previous messageGo to next message
Eclipse UserFriend
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 09:45 Go to previous message
Eclipse UserFriend
please use a debugger

EditorPackage.Literals.VARIABLE_STATEMENT__NAME

is suspicious.

should be ForeachStatement_packVar or SingleData_var

Previous Topic:Web editor code generation
Next Topic:Mwe2Launcher - Cannot create a resource with ANT
Goto Forum:
  


Current Time: Wed Mar 19 08:20:24 EDT 2025

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

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

Back to the top