Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Restrict default cross reference scope.
Restrict default cross reference scope. [message #1242440] Sun, 09 February 2014 15:10 Go to next message
George P is currently offline George PFriend
Messages: 1
Registered: February 2014
Junior Member
Hello everybody,

I have an example myDsl Xtext grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl ""



	'for' '('(ID varName = VarName)')' 'where' typedVar = [VarName] '>' INT

	name = ID

The above Xtext grammar uses VarName as a cross reference for being able to refer only to variable names that were defined.

Example of myDsl file:
for (Integer s) where s > 10
for (Double b)	where b > 100
for (Long d) where //when content assist is invoked all VarName references are shown


1. In the example above, the last "for" should give as content assist suggestion only variable d. (not all variables) - I want to reduce the scope only per "for" declaration
2. Also if my project contains multiple myDsl files, I want to get suggestions for VarNames only from current file. - disable global scope of VarNames.

Can someone suggest an easy and clean way to achieve both requirements?

I was thinking to override the content assist for the VariabileName part (no use of cross references). However, in this case the functionality already provided by Xtext would be disabled and I have then to perform additional validation for VarNames that are used but not defined.

Many thanks!

Re: Restrict default cross reference scope. [message #1242855 is a reply to message #1242440] Mon, 10 February 2014 07:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13637
Registered: July 2009
Senior Member

i am not sure what your problem is. there are many examples, blogs,... out there


IScope scope_<RefDeclaringEClass>_<Reference>(
<ContextType> ctx, EReference ref)

IScope scope_<TypeToReturn>(<ContextType> ctx, EReference ref)

you can restrict specific cross refs scope by

scope_For_typedVar(For ctx, EReference r)

you can restrict the scope for a specific type and context by

scope_VarName(YourRoot ctx, EReference r)

collect the valid stuff to a list and your scopes.scopefor to wrap them into a scope

Need professional support for Xtext, Xpand, EMF?
Go to:
Twitter : @chrdietrich
Blog :
Re: Restrict default cross reference scope. [message #1243002 is a reply to message #1242855] Mon, 10 February 2014 11:24 Go to previous message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 248
Registered: June 2013
Senior Member
perhaps a look at: would be helpful.

There is a comment how to reduce scope to the DSL file only.
Previous Topic:Version of dependencies when using xtext
Next Topic:Retrieving / reverse engineering grammar file from existing JavaCC generated parser
Goto Forum:

Current Time: Sun Oct 25 06:13:23 GMT 2020

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

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

Back to the top