I am trying to custom scoping, such that if I have something like function in my language that get parameters, I want that those parameters will be visible only until there is semicolon, and out of this scope, I want it to not be visible.
I tried redefine the method getScope() in the file MyDslScopeProvider.xtend
In getScope I did something like this:
if (EclassName=="TypedParam" && EFeatureName=="type" && contextType == "TypedParam"){
return Scopes.scopeFor(Collections.singleton(context),IScope.NULLSCOPE)
}
This is abviosly doesn't working (It doesn't recognize the parameters). How can I do it?
Moreover, I have another question: I tried implements methods like:
def IScope scope_<EClass name>_<EFeature name>(<context type> context, EReference)
Although I printed the names and I made sure I am writing the name correct, those method simply never called. (I copied what was printed from the following code)
class DomainmodelScopeProvider extends AbstractDomainmodelScopeProvider {
override def IScope getScope(EObject context, EReference reference)
{
System.out.println("scope_" + reference.getEContainingClass().getName()
+ "_" + reference.getName()
+ "(" + context.eClass().getName() + ", ..)"
);
return super.getScope(context,reference);
}
What am I doing wrong?
Thanks!!!
The Problem is that with Xtext 2.9+
AbstractDeclarativeScopeProvider
is no longer the default superclass ofYourdslScopeProvider
. You are expected to overridegetScope(EObject context, EReference ref)
and do if elsing there. Or you change the superclass manually. Btw you can use the Constants inYourdslPackage.Literals
instead of using manual string constants.